mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-19 19:35:26 +00:00
Shifts handling of material and terrain material definitions to be written into the asset definition taml file instead of having an extra loose file
Also updates importers to correctly handle this change Adds ability for taml XML serialization to properly assign array'd fields Adds 'inheritFrom' field to simobjects for when objects with parent objects are serialized AssetBase how inherits from SimGroup so it can have objects like material definitions embedded in them for save/load in the taml definition file Updated loading/handling logic in terrain material asset to be more similar to regular material assets
This commit is contained in:
parent
656475deaf
commit
630285def6
20 changed files with 791 additions and 318 deletions
|
|
@ -154,8 +154,9 @@ void MaterialAsset::initPersistFields()
|
|||
Parent::initPersistFields();
|
||||
|
||||
//addField("shaderGraph", TypeRealString, Offset(mShaderGraphFile, MaterialAsset), "");
|
||||
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset),
|
||||
&setScriptFile, &getScriptFile, "Path to the file containing the material definition.");
|
||||
//addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset),
|
||||
// &setScriptFile, &getScriptFile, "Path to the file containing the material definition.");
|
||||
addField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset), "");
|
||||
|
||||
addField("materialDefinitionName", TypeString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for.");
|
||||
}
|
||||
|
|
@ -173,7 +174,16 @@ void MaterialAsset::initializeAsset()
|
|||
return;
|
||||
}
|
||||
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
if (mMatDefinitionName == StringTable->insert("DetailBlue"))
|
||||
{
|
||||
bool asdfsd = true;
|
||||
}
|
||||
|
||||
if (size() != 0 && mScriptPath == StringTable->EmptyString())
|
||||
{
|
||||
mLoadedState = EmbeddedDefinition;
|
||||
}
|
||||
else if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
{
|
||||
if (!Sim::findObject(mMatDefinitionName))
|
||||
{
|
||||
|
|
@ -230,7 +240,6 @@ void MaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
// Sanity!
|
||||
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
|
||||
|
||||
// Fetch image file.
|
||||
pScriptFile = StringTable->insert(pScriptFile, true);
|
||||
|
||||
// Update.
|
||||
|
|
@ -245,9 +254,28 @@ void MaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
void MaterialAsset::loadMaterial()
|
||||
{
|
||||
if (mMaterialDefinition)
|
||||
SAFE_DELETE(mMaterialDefinition);
|
||||
{
|
||||
mMaterialDefinition->safeDeleteObject();
|
||||
}
|
||||
|
||||
if ((mLoadedState == ScriptLoaded || mLoadedState == DefinitionAlreadyExists) && mMatDefinitionName != StringTable->EmptyString())
|
||||
if (mLoadedState == EmbeddedDefinition)
|
||||
{
|
||||
if (size() != 0)
|
||||
{
|
||||
for (U32 i = 0; i < size(); i++)
|
||||
{
|
||||
mMaterialDefinition = dynamic_cast<Material*>(getObject(i));
|
||||
if (mMaterialDefinition)
|
||||
{
|
||||
mLoadedState = Ok;
|
||||
mMaterialDefinition->setInternalName(getAssetId());
|
||||
mMaterialDefinition->reload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((mLoadedState == ScriptLoaded || mLoadedState == DefinitionAlreadyExists) && mMatDefinitionName != StringTable->EmptyString())
|
||||
{
|
||||
Material* matDef;
|
||||
if (!Sim::findObject(mMatDefinitionName, matDef))
|
||||
|
|
@ -260,7 +288,7 @@ void MaterialAsset::loadMaterial()
|
|||
mMaterialDefinition = matDef;
|
||||
|
||||
mLoadedState = Ok;
|
||||
|
||||
mMaterialDefinition->setInternalName(getAssetId());
|
||||
mMaterialDefinition->reload();
|
||||
return;
|
||||
}
|
||||
|
|
@ -296,11 +324,11 @@ U32 MaterialAsset::getAssetByMaterialName(StringTableEntry matName, AssetPtr<Mat
|
|||
//handle noshape not being loaded itself
|
||||
if ((*matAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
Con::warnf("ShapeAsset::getAssetByMaterialName - Finding of associated with aterial name %s failed, and fallback asset reported error of Bad File Reference.", matName);
|
||||
Con::warnf("MaterialAsset::getAssetByMaterialName - Finding of associated with aterial name %s failed, and fallback asset reported error of Bad File Reference.", matName);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
Con::warnf("ShapeAsset::getAssetByMaterialName - Finding of associated with aterial name %s failed, utilizing fallback asset", matName);
|
||||
Con::warnf("MaterialAsset::getAssetByMaterialName - Finding of associated with aterial name %s failed, utilizing fallback asset", matName);
|
||||
|
||||
(*matAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
|
|
@ -388,6 +416,17 @@ U32 MaterialAsset::getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset
|
|||
}
|
||||
}
|
||||
|
||||
SimObjectPtr<Material> MaterialAsset::findMaterialDefinitionByAssetId(StringTableEntry assetId)
|
||||
{
|
||||
SimSet* matSet = MATMGR->getMaterialSet();
|
||||
if (matSet)
|
||||
{
|
||||
SimObjectPtr<Material> matDef = dynamic_cast<Material*>(matSet->findObjectByInternalName(assetId));
|
||||
return matDef;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineStaticMethod(MaterialAsset, getAssetIdByMaterialName, const char*, (const char* materialName), (""),
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n"
|
||||
|
|
@ -396,6 +435,19 @@ DefineEngineStaticMethod(MaterialAsset, getAssetIdByMaterialName, const char*, (
|
|||
return MaterialAsset::getAssetIdByMaterialName(StringTable->insert(materialName));
|
||||
}
|
||||
|
||||
//MaterialAsset::findMaterialDefinitionByAssetId("Prototyping:Detail")
|
||||
DefineEngineStaticMethod(MaterialAsset, findMaterialDefinitionByAssetId, S32, (const char* assetId), (""),
|
||||
"Queries the MaterialSet to see if any MaterialDefinition exists that is associated to the provided assetId.\n"
|
||||
"@return The MaterialDefinition Id associated to the assetId, if any")
|
||||
{
|
||||
SimObjectPtr<Material> matDef = MaterialAsset::findMaterialDefinitionByAssetId(StringTable->insert(assetId));
|
||||
if (matDef.isNull())
|
||||
return SimObjectId(0);
|
||||
else
|
||||
return matDef->getId();
|
||||
}
|
||||
|
||||
|
||||
DefineEngineMethod(MaterialAsset, getScriptPath, const char*, (), ,
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided material name.\n"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue