Adds logic to correctly write out a shape's materials as fields to the asset taml file so they can register as dependencies with the assetdatabase

This commit is contained in:
JeffR 2026-05-31 11:14:54 -05:00
parent b44158cb89
commit de26f519f9
2 changed files with 27 additions and 0 deletions

View file

@ -626,6 +626,32 @@ void ShapeAsset::onTamlPostWrite(void)
mNormalImposterFileName = expandAssetFilePath(mNormalImposterFileName);
}
void ShapeAsset::onTamlCustomWrite(TamlCustomNodes& customNodes)
{
// Debug Profiling.
PROFILE_SCOPE(ShapeAsset_OnTamlCustomWrite);
// Call parent.
Parent::onTamlCustomWrite(customNodes);
if (!mShape)
return;
TamlCustomNode* materialsData = customNodes.addNode(StringTable->insert("Materials"));
U32 matCount = mShape->materialList->size();
Vector<String>& mat_names = const_cast<Vector<String>&>(mShape->materialList->getMaterialNameList());
for (U32 i=0; i < mat_names.size(); i++)
{
StringTableEntry matAssetId = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(mat_names[i].c_str()));
if (matAssetId != StringTable->EmptyString())
{
String fieldName = String::ToString("materialSlot%d", i);
String fieldData = String::ToString("%s%s", ASSET_ID_FIELD_PREFIX, matAssetId);
materialsData->addField(fieldName.c_str(), matAssetId);
}
}
}
#ifdef TORQUE_TOOLS
const char* ShapeAsset::generateCachedPreviewImage(S32 resolution, String overrideMaterial)
{

View file

@ -158,6 +158,7 @@ protected:
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
void onTamlCustomWrite(TamlCustomNodes& customNodes) override;
protected:
static bool setShapeFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setShapeFile(data); return false; }