From 22827ccb376957ef050b2a79a1cbe690e859ae06 Mon Sep 17 00:00:00 2001 From: Damien Pernuit Date: Wed, 26 Jun 2024 19:48:12 -0400 Subject: [PATCH] - Fixed material support when sending actors as reference. --- .../Private/HoudiniInputTranslator.cpp | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Source/HoudiniEngine/Private/HoudiniInputTranslator.cpp b/Source/HoudiniEngine/Private/HoudiniInputTranslator.cpp index b2106cdcec..9df480f881 100755 --- a/Source/HoudiniEngine/Private/HoudiniInputTranslator.cpp +++ b/Source/HoudiniEngine/Private/HoudiniInputTranslator.cpp @@ -2801,36 +2801,49 @@ FHoudiniInputTranslator::HapiCreateInputNodeForActorReference( // Material Reference String Array Attribute if (InInputSettings.bImportAsReferenceMaterialEnabled) { - /* - - // TODO - // Create point attribute info. HAPI_AttributeInfo AttributeInfoPoint; FHoudiniApi::AttributeInfo_Init(&AttributeInfoPoint); - AttributeInfoPoint.count = 1; + AttributeInfoPoint.count = NumPoints; AttributeInfoPoint.tupleSize = 1; AttributeInfoPoint.exists = true; AttributeInfoPoint.owner = HAPI_ATTROWNER_POINT; AttributeInfoPoint.storage = HAPI_STORAGETYPE_STRING; AttributeInfoPoint.originalOwner = HAPI_ATTROWNER_INVALID; + int32 MaxNumMaterials = 0; + for (int32 CompIdx = 0; CompIdx < ComponentMaterials.Num(); CompIdx++) + { + if (ComponentMaterials[CompIdx].Num() > MaxNumMaterials) + MaxNumMaterials = ComponentMaterials[CompIdx].Num(); + } + // We set it to be multiple string attributes rather than a single string array attribute to not conflict // with any existing HDA's that use the attribute name unreal_material - for (int i = 0; i < MaterialReferences.Num(); ++i) + for (int32 MatIdx = 0; MatIdx < MaxNumMaterials; MatIdx++) { FString AttributeName = HAPI_UNREAL_ATTRIB_MATERIAL; - if (i > 0) - AttributeName.AppendInt(i); + if (MatIdx > 0) + AttributeName.AppendInt(MatIdx); + + // Create an array for the current Material + TArray CurrentMaterials; + CurrentMaterials.SetNum(ComponentMaterials.Num()); + for (int32 CompIdx = 0; CompIdx < ComponentMaterials.Num(); CompIdx++) + { + if (ComponentMaterials[CompIdx].IsValidIndex(MatIdx)) + CurrentMaterials[CompIdx] = ComponentMaterials[CompIdx][MatIdx]; + else + CurrentMaterials[CompIdx] = FString(); + } HOUDINI_CHECK_ERROR_RETURN(FHoudiniApi::AddAttribute( FHoudiniEngine::Get().GetSession(), NewNodeId, 0, TCHAR_TO_ANSI(*AttributeName), &AttributeInfoPoint), false); - FHoudiniHapiAccessor Accessor(NewNodeId, 0, TCHAR_TO_ANSI(*AttributeName)); - HOUDINI_CHECK_RETURN(Accessor.SetAttributeUniqueData(AttributeInfoPoint, MaterialReferences[i]), false); + HOUDINI_CHECK_RETURN(FHoudiniEngineUtils::HapiSetAttributeStringData( + CurrentMaterials, NewNodeId, 0, AttributeName, AttributeInfoPoint), false); } - */ } // Unreal Reference String Attribute