Fixed physx asset when exported as convex or primitives. (#4414)

* Fixed physx asset when exported as convex or primitives. Before it was limited to 1 material for the entire object, now it correctly uses multiple materials by looking at the first material per node.

Signed-off-by: moraaar <moraaar@amazon.com>
This commit is contained in:
moraaar
2021-10-04 12:05:33 +01:00
committed by GitHub
parent d03273089e
commit 1c305c6402
2 changed files with 19 additions and 16 deletions
@@ -298,8 +298,10 @@ namespace PhysX
assetMaterialData.m_nodesToPerFaceMaterialIndices.emplace(nodeName, AZStd::vector<AZ::u16>(faceCount));
// Convex and primitive methods can only have 1 material
// Convex and primitive methods can only have 1 material per node.
const bool limitToOneMaterial = meshGroup.GetExportAsConvex() || meshGroup.GetExportAsPrimitive();
AZStd::string firstMaterial;
AZStd::set<AZStd::string> nodeMaterials;
for (AZ::u32 faceIndex = 0; faceIndex < faceCount; ++faceIndex)
{
@@ -318,18 +320,28 @@ namespace PhysX
materialName = localSourceSceneMaterialsList[materialId];
// Keep using the first material when it has to be limited to one.
if (limitToOneMaterial &&
assetMaterialData.m_sourceSceneMaterialNames.size() == 1 &&
assetMaterialData.m_sourceSceneMaterialNames[0] != materialName)
// Use the first material found in the mesh when it has to be limited to one.
if (limitToOneMaterial)
{
materialName = assetMaterialData.m_sourceSceneMaterialNames[0];
nodeMaterials.insert(materialName);
if (firstMaterial.empty())
{
firstMaterial = materialName;
}
materialName = firstMaterial;
}
}
const AZ::u16 materialIndex = InsertMaterialIndexByName(materialName, assetMaterialData);
assetMaterialData.m_nodesToPerFaceMaterialIndices[nodeName][faceIndex] = materialIndex;
}
if (limitToOneMaterial && nodeMaterials.size() > 1)
{
AZ_TracePrintf(AZ::SceneAPI::Utilities::WarningWindow,
"Node '%s' has %d materials, but cooking methods Convex and Primitive support one material per node. The first material '%s' will be used.",
sceneNodeSelectionList.GetSelectedNode(index).c_str(), nodeMaterials.size(), firstMaterial.c_str());
}
}
return assetMaterialData;
+1 -10
View File
@@ -852,16 +852,7 @@ namespace PhysX
{
if (index < m_materialSlots.size())
{
// When limited to one material, clarify in the label the material
// will be used for the entire object.
if (index == 0 && (GetExportAsConvex() || GetExportAsPrimitive()))
{
return m_materialSlots[index] + " (entire object)";
}
else
{
return m_materialSlots[index];
}
return m_materialSlots[index];
}
else
{