@@ -2801,36 +2801,49 @@ FHoudiniInputTranslator::HapiCreateInputNodeForActorReference(
28012801 // Material Reference String Array Attribute
28022802 if (InInputSettings.bImportAsReferenceMaterialEnabled )
28032803 {
2804- /*
2805-
2806- // TODO
2807-
28082804 // Create point attribute info.
28092805 HAPI_AttributeInfo AttributeInfoPoint;
28102806 FHoudiniApi::AttributeInfo_Init (&AttributeInfoPoint);
2811- AttributeInfoPoint.count = 1 ;
2807+ AttributeInfoPoint.count = NumPoints ;
28122808 AttributeInfoPoint.tupleSize = 1 ;
28132809 AttributeInfoPoint.exists = true ;
28142810 AttributeInfoPoint.owner = HAPI_ATTROWNER_POINT;
28152811 AttributeInfoPoint.storage = HAPI_STORAGETYPE_STRING;
28162812 AttributeInfoPoint.originalOwner = HAPI_ATTROWNER_INVALID;
28172813
2814+ int32 MaxNumMaterials = 0 ;
2815+ for (int32 CompIdx = 0 ; CompIdx < ComponentMaterials.Num (); CompIdx++)
2816+ {
2817+ if (ComponentMaterials[CompIdx].Num () > MaxNumMaterials)
2818+ MaxNumMaterials = ComponentMaterials[CompIdx].Num ();
2819+ }
2820+
28182821 // We set it to be multiple string attributes rather than a single string array attribute to not conflict
28192822 // with any existing HDA's that use the attribute name unreal_material
2820- for (int i = 0; i < MaterialReferences.Num(); ++i )
2823+ for (int32 MatIdx = 0 ; MatIdx < MaxNumMaterials; MatIdx++ )
28212824 {
28222825 FString AttributeName = HAPI_UNREAL_ATTRIB_MATERIAL;
2823- if (i > 0)
2824- AttributeName.AppendInt(i);
2826+ if (MatIdx > 0 )
2827+ AttributeName.AppendInt (MatIdx);
2828+
2829+ // Create an array for the current Material
2830+ TArray<FString> CurrentMaterials;
2831+ CurrentMaterials.SetNum (ComponentMaterials.Num ());
2832+ for (int32 CompIdx = 0 ; CompIdx < ComponentMaterials.Num (); CompIdx++)
2833+ {
2834+ if (ComponentMaterials[CompIdx].IsValidIndex (MatIdx))
2835+ CurrentMaterials[CompIdx] = ComponentMaterials[CompIdx][MatIdx];
2836+ else
2837+ CurrentMaterials[CompIdx] = FString ();
2838+ }
28252839
28262840 HOUDINI_CHECK_ERROR_RETURN (FHoudiniApi::AddAttribute (
28272841 FHoudiniEngine::Get ().GetSession (), NewNodeId, 0 ,
28282842 TCHAR_TO_ANSI (*AttributeName), &AttributeInfoPoint), false );
28292843
2830- FHoudiniHapiAccessor Accessor(NewNodeId, 0, TCHAR_TO_ANSI(*AttributeName));
2831- HOUDINI_CHECK_RETURN(Accessor.SetAttributeUniqueData(AttributeInfoPoint, MaterialReferences[i] ), false);
2844+ HOUDINI_CHECK_RETURN ( FHoudiniEngineUtils::HapiSetAttributeStringData (
2845+ CurrentMaterials, NewNodeId, 0 , AttributeName, AttributeInfoPoint ), false );
28322846 }
2833- */
28342847 }
28352848
28362849 // Unreal Reference String Attribute
0 commit comments