// Copyright Epic Games, Inc. All Rights Reserved. #include "ChaosClothAsset/AttributeNode.h" #include "ChaosClothAsset/ClothCollectionGroup.h" #include "ChaosClothAsset/CollectionClothFacade.h" #include "ChaosClothAsset/ClothDataflowTools.h" #include "ChaosClothAsset/WeightedValue.h" #include "Dataflow/DataflowInputOutput.h" #include UE_INLINE_GENERATED_CPP_BY_NAME(AttributeNode) #define LOCTEXT_NAMESPACE "ChaosClothAssetAttributeNode" FChaosClothAssetAttributeNode_v2::FChaosClothAssetAttributeNode_v2(const UE::Dataflow::FNodeParameters& InParam, FGuid InGuid) : FDataflowNode(InParam, InGuid) { RegisterInputConnection(&Collection); RegisterInputConnection(&Name.StringValue, GET_MEMBER_NAME_CHECKED(FChaosClothAssetConnectableIOStringValue, StringValue)); RegisterOutputConnection(&Collection, &Collection); RegisterOutputConnection(&Name.StringValue, &Name.StringValue, GET_MEMBER_NAME_CHECKED(FChaosClothAssetConnectableIOStringValue, StringValue)); } void FChaosClothAssetAttributeNode_v2::Evaluate(UE::Dataflow::FContext& Context, const FDataflowOutput* Out) const { if (Out->IsA(&Collection)) { using namespace UE::Chaos::ClothAsset; // Evaluate in collection FManagedArrayCollection InCollection = GetValue(Context, &Collection); const TSharedRef ClothCollection = MakeShared(MoveTemp(InCollection)); FCollectionClothFacade Cloth(ClothCollection); const FName GroupName = *Group.Name; const FString& InName = GetValue(Context, &Name.StringValue); if (Cloth.IsValid() && !InName.IsEmpty()) { if (ClothCollection->HasGroup(GroupName)) { switch (Type) { case EChaosClothAssetNodeAttributeType::Integer: Cloth.AddUserDefinedAttribute(*InName, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*InName, GroupName); for (int32& Value : Values) { Value = IntValue; } } break; case EChaosClothAssetNodeAttributeType::Float: Cloth.AddUserDefinedAttribute(*InName, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*InName, GroupName); for (float& Value : Values) { Value = FloatValue; } } break; case EChaosClothAssetNodeAttributeType::Vector: Cloth.AddUserDefinedAttribute(*InName, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*InName, GroupName); for (FVector3f& Value : Values) { Value = VectorValue; } } break; } } else if (!GroupName.IsNone()) { FClothDataflowTools::LogAndToastWarning( *this, LOCTEXT("CreateAttributeHeadline", "Invalid Group"), FText::Format(LOCTEXT("CreateAttributeDetail", "No group \"{0}\" currently exists on the input collection"), FText::FromName(GroupName))); } } SetValue(Context, MoveTemp(*ClothCollection), &Collection); } else if (Out->IsA(&Name.StringValue)) { const FString& InName = GetValue(Context, &Name.StringValue); SetValue(Context, InName, &Name.StringValue); } } FChaosClothAssetAttributeNode::FChaosClothAssetAttributeNode(const UE::Dataflow::FNodeParameters& InParam, FGuid InGuid) : FDataflowNode(InParam, InGuid) { RegisterInputConnection(&Collection); RegisterOutputConnection(&Collection, &Collection); RegisterOutputConnection(&Name); } void FChaosClothAssetAttributeNode::Evaluate(UE::Dataflow::FContext& Context, const FDataflowOutput* Out) const { if (Out->IsA(&Collection)) { using namespace UE::Chaos::ClothAsset; // Evaluate in collection FManagedArrayCollection InCollection = GetValue(Context, &Collection); const TSharedRef ClothCollection = MakeShared(MoveTemp(InCollection)); FCollectionClothFacade Cloth(ClothCollection); const FName GroupName = *Group.Name; if (Cloth.IsValid() && !Name.IsEmpty()) { if (ClothCollection->HasGroup(GroupName)) { switch (Type) { case EChaosClothAssetNodeAttributeType::Integer: Cloth.AddUserDefinedAttribute(*Name, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*Name, GroupName); for (int32& Value : Values) { Value = IntValue; } } break; case EChaosClothAssetNodeAttributeType::Float: Cloth.AddUserDefinedAttribute(*Name, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*Name, GroupName); for (float& Value : Values) { Value = FloatValue; } } break; case EChaosClothAssetNodeAttributeType::Vector: Cloth.AddUserDefinedAttribute(*Name, GroupName); { TArrayView Values = Cloth.GetUserDefinedAttribute(*Name, GroupName); for (FVector3f& Value : Values) { Value = VectorValue; } } break; } } else if (!GroupName.IsNone()) { FClothDataflowTools::LogAndToastWarning( *this, LOCTEXT("CreateAttributeHeadline", "Invalid Group"), FText::Format(LOCTEXT("CreateAttributeDetail", "No group \"{0}\" currently exists on the input collection"), FText::FromName(GroupName))); } } SetValue(Context, MoveTemp(*ClothCollection), &Collection); } else if (Out->IsA(&Name)) { SetValue(Context, Name, &Name); } } #undef LOCTEXT_NAMESPACE