mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
streamline shape asset
shape asset now has the same import "@" as image asset cut out extra filename parameters that arent needed refresh hopefully fixed
This commit is contained in:
parent
542563feaf
commit
fd7342668c
15 changed files with 185 additions and 465 deletions
|
|
@ -60,12 +60,20 @@ StringTableEntry ShapeAsset::smNoShapeAssetFallback = NULL;
|
|||
|
||||
IMPLEMENT_CONOBJECT(ShapeAsset);
|
||||
|
||||
ConsoleType(assetIdString, TypeShapeAssetPtr, String, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// REFACTOR
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_STRUCT(AssetPtr<ShapeAsset>, AssetPtrShapeAsset, , "")
|
||||
END_IMPLEMENT_STRUCT
|
||||
|
||||
ConsoleType(ShapeAssetPtr, TypeShapeAssetPtr, AssetPtr<ShapeAsset>, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
|
||||
ConsoleGetType(TypeShapeAssetPtr)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
//return *((StringTableEntry*)dptr);
|
||||
return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId();
|
||||
}
|
||||
|
||||
|
|
@ -77,17 +85,24 @@ ConsoleSetType(TypeShapeAssetPtr)
|
|||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
// Fetch asset pointer.
|
||||
AssetPtr<ShapeAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAsset>*>((AssetPtrBase*)(dptr));
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
// Is the asset pointer the correct type?
|
||||
if (pAssetPtr == NULL)
|
||||
{
|
||||
Con::warnf("(TypeShapeAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset.
|
||||
pAssetPtr->setAssetId(pFieldValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
|
||||
Con::warnf("(TypeShapeAssetPtr) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -115,52 +130,6 @@ ConsoleSetType(TypeShapeAssetId)
|
|||
Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// REFACTOR
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_STRUCT(AssetPtr<ShapeAsset>, AssetPtrShapeAsset, , "")
|
||||
END_IMPLEMENT_STRUCT
|
||||
|
||||
ConsoleType(ShapeAssetPtrRefactor, TypeShapeAssetPtrRefactor, AssetPtr<ShapeAsset>, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
|
||||
ConsoleGetType(TypeShapeAssetPtrRefactor)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId();
|
||||
}
|
||||
|
||||
ConsoleSetType(TypeShapeAssetPtrRefactor)
|
||||
{
|
||||
// Was a single argument specified?
|
||||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset pointer.
|
||||
AssetPtr<ShapeAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAsset>*>((AssetPtrBase*)(dptr));
|
||||
|
||||
// Is the asset pointer the correct type?
|
||||
if (pAssetPtr == NULL)
|
||||
{
|
||||
Con::warnf("(TypeShapeAssetPtrRefactor) - Failed to set asset Id '%d'.", pFieldValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset.
|
||||
pAssetPtr->setAssetId(pFieldValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf("(TypeShapeAssetPtrRefactor) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// REFACTOR END
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -176,15 +145,11 @@ const String ShapeAsset::mErrCodeStrings[] =
|
|||
|
||||
ShapeAsset::ShapeAsset()
|
||||
{
|
||||
mFileName = StringTable->EmptyString();
|
||||
mShapeFile = StringTable->EmptyString();
|
||||
mConstructorFileName = StringTable->EmptyString();
|
||||
mFilePath = StringTable->EmptyString();
|
||||
mConstructorFilePath = StringTable->EmptyString();
|
||||
|
||||
mDiffuseImposterFileName = StringTable->EmptyString();
|
||||
mDiffuseImposterPath = StringTable->EmptyString();
|
||||
mNormalImposterFileName = StringTable->EmptyString();
|
||||
mNormalImposterPath = StringTable->EmptyString();
|
||||
|
||||
|
||||
mLoadedState = AssetErrCode::NotLoaded;
|
||||
|
|
@ -217,7 +182,7 @@ void ShapeAsset::initPersistFields()
|
|||
// Call parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
addProtectedField("fileName", TypeAssetLooseFilePath, Offset(mFileName, ShapeAsset),
|
||||
addProtectedField("fileName", TypeAssetLooseFilePath, Offset(mShapeFile, ShapeAsset),
|
||||
&setShapeFile, &getShapeFile, "Path to the shape file we want to render");
|
||||
addProtectedField("constuctorFileName", TypeAssetLooseFilePath, Offset(mConstructorFileName, ShapeAsset),
|
||||
&setShapeConstructorFile, &getShapeConstructorFile, "Path to the shape file we want to render");
|
||||
|
|
@ -225,7 +190,7 @@ void ShapeAsset::initPersistFields()
|
|||
addProtectedField("diffuseImposterFileName", TypeAssetLooseFilePath, Offset(mDiffuseImposterFileName, ShapeAsset),
|
||||
&setDiffuseImposterFile, &getDiffuseImposterFile, "Path to the diffuse imposter file we want to render");
|
||||
addProtectedField("normalImposterFileName", TypeAssetLooseFilePath, Offset(mNormalImposterFileName, ShapeAsset),
|
||||
&setNormalImposterFile, &getNormalImposterFile, "Path to the normal imposter file we want to render");
|
||||
&setNormalImposterFile, &getNormalImposterFilePath, "Path to the normal imposter file we want to render");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -248,29 +213,31 @@ void ShapeAsset::initializeAsset()
|
|||
// Call parent.
|
||||
Parent::initializeAsset();
|
||||
|
||||
if (mFileName == StringTable->EmptyString())
|
||||
if (mShapeFile == StringTable->EmptyString())
|
||||
return;
|
||||
|
||||
ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged);
|
||||
|
||||
//Ensure our path is expando'd if it isn't already
|
||||
mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath;
|
||||
mShapeFile = getOwned() ? expandAssetFilePath(mShapeFile) : mShapeFile;
|
||||
|
||||
mConstructorFilePath = getOwned() ? expandAssetFilePath(mConstructorFileName) : mConstructorFilePath;
|
||||
if (!Torque::FS::IsFile(mConstructorFilePath))
|
||||
Con::errorf("ShapeAsset::initializeAsset (%s) could not find %s!", getAssetName(), mConstructorFilePath);
|
||||
mDiffuseImposterPath = getOwned() ? expandAssetFilePath(mDiffuseImposterFileName) : mDiffuseImposterFileName;
|
||||
if (mDiffuseImposterPath == StringTable->EmptyString())
|
||||
mConstructorFileName = getOwned() ? expandAssetFilePath(mConstructorFileName) : mConstructorFileName;
|
||||
if (!Torque::FS::IsFile(mConstructorFileName))
|
||||
Con::errorf("ShapeAsset::initializeAsset (%s) could not find %s!", getAssetName(), mConstructorFileName);
|
||||
|
||||
|
||||
mDiffuseImposterFileName = getOwned() ? expandAssetFilePath(mDiffuseImposterFileName) : mDiffuseImposterFileName;
|
||||
if (mDiffuseImposterFileName == StringTable->EmptyString())
|
||||
{
|
||||
String diffusePath = String(mFilePath) + "_imposter.dds";
|
||||
mDiffuseImposterPath = StringTable->insert(diffusePath.c_str());
|
||||
String diffusePath = String(mShapeFile) + "_imposter.dds";
|
||||
mDiffuseImposterFileName = StringTable->insert(diffusePath.c_str());
|
||||
}
|
||||
|
||||
mNormalImposterPath = getOwned() ? expandAssetFilePath(mNormalImposterFileName) : mNormalImposterFileName;
|
||||
if (mNormalImposterPath == StringTable->EmptyString())
|
||||
mNormalImposterFileName = getOwned() ? expandAssetFilePath(mNormalImposterFileName) : mNormalImposterFileName;
|
||||
if (mNormalImposterFileName == StringTable->EmptyString())
|
||||
{
|
||||
String normalPath = String(mFilePath) + "_imposter_normals.dds";
|
||||
mNormalImposterPath = StringTable->insert(normalPath.c_str());
|
||||
String normalPath = String(mShapeFile) + "_imposter_normals.dds";
|
||||
mNormalImposterFileName = StringTable->insert(normalPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -283,10 +250,10 @@ void ShapeAsset::setShapeFile(const char* pShapeFile)
|
|||
pShapeFile = StringTable->insert(pShapeFile, true);
|
||||
|
||||
// Ignore no change,
|
||||
if (pShapeFile == mFileName)
|
||||
if (pShapeFile == mShapeFile)
|
||||
return;
|
||||
|
||||
mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : pShapeFile;
|
||||
mShapeFile = getOwned() ? expandAssetFilePath(pShapeFile) : pShapeFile;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
|
|
@ -348,7 +315,7 @@ void ShapeAsset::setNormalImposterFile(const char* pImageFile)
|
|||
|
||||
void ShapeAsset::_onResourceChanged(const Torque::Path &path)
|
||||
{
|
||||
if (path != Torque::Path(mFilePath) )
|
||||
if (path != Torque::Path(mShapeFile) )
|
||||
return;
|
||||
|
||||
refreshAsset();
|
||||
|
|
@ -397,17 +364,17 @@ U32 ShapeAsset::load()
|
|||
}
|
||||
}
|
||||
|
||||
mShape = ResourceManager::get().load(mFilePath);
|
||||
mShape = ResourceManager::get().load(mShapeFile);
|
||||
|
||||
if (!mShape)
|
||||
{
|
||||
Con::errorf("ShapeAsset::loadShape : failed to load shape file %s (%s)!", getAssetName(), mFilePath);
|
||||
Con::errorf("ShapeAsset::loadShape : failed to load shape file %s (%s)!", getAssetName(), mShapeFile);
|
||||
mLoadedState = BadFileReference;
|
||||
return mLoadedState; //if it failed to load, bail out
|
||||
}
|
||||
// Construct billboards if not done already
|
||||
if (GFXDevice::devicePresent())
|
||||
mShape->setupBillboardDetails(mFilePath, mDiffuseImposterPath, mNormalImposterPath);
|
||||
mShape->setupBillboardDetails(mShapeFile, mDiffuseImposterFileName, mNormalImposterFileName);
|
||||
|
||||
//If they exist, grab our imposters here and bind them to our shapeAsset
|
||||
|
||||
|
|
@ -467,8 +434,6 @@ U32 ShapeAsset::load()
|
|||
|
||||
mLoadedState = Ok;
|
||||
|
||||
mChangeSignal.trigger();
|
||||
|
||||
return mLoadedState;
|
||||
}
|
||||
|
||||
|
|
@ -536,13 +501,13 @@ StringTableEntry ShapeAsset::getAssetIdByFilename(StringTableEntry fileName)
|
|||
AssetPtr<ShapeAsset> temp = shapeAsset;
|
||||
if (temp.notNull())
|
||||
{
|
||||
if (temp->getShapePath() == fileName)
|
||||
if (temp->getShapeFile() == fileName)
|
||||
{
|
||||
return shapeAsset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Torque::Path temp1 = temp->getShapePath();
|
||||
Torque::Path temp1 = temp->getShapeFile();
|
||||
Torque::Path temp2 = fileName;
|
||||
|
||||
if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName())
|
||||
|
|
@ -606,16 +571,43 @@ void ShapeAsset::copyTo(SimObject* object)
|
|||
|
||||
void ShapeAsset::onAssetRefresh(void)
|
||||
{
|
||||
if (mFileName == StringTable->EmptyString())
|
||||
// Ignore if not yet added to the sim.
|
||||
if (!isProperlyAdded())
|
||||
return;
|
||||
|
||||
// Update.
|
||||
if(!Platform::isFullPath(mFileName))
|
||||
mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath;
|
||||
if (mShapeFile == StringTable->EmptyString())
|
||||
return;
|
||||
|
||||
// Call parent.
|
||||
Parent::onAssetRefresh();
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
void ShapeAsset::onTamlPreWrite(void)
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlPreWrite();
|
||||
|
||||
// ensure paths are collapsed.
|
||||
mShapeFile = collapseAssetFilePath(mShapeFile);
|
||||
mConstructorFileName = collapseAssetFilePath(mConstructorFileName);
|
||||
mDiffuseImposterFileName = collapseAssetFilePath(mDiffuseImposterFileName);
|
||||
mNormalImposterFileName = collapseAssetFilePath(mNormalImposterFileName);
|
||||
}
|
||||
|
||||
void ShapeAsset::onTamlPostWrite(void)
|
||||
{
|
||||
// Call parent.
|
||||
Parent::onTamlPostWrite();
|
||||
|
||||
// ensure paths are expanded.
|
||||
mShapeFile = expandAssetFilePath(mShapeFile);
|
||||
mConstructorFileName = expandAssetFilePath(mConstructorFileName);
|
||||
mDiffuseImposterFileName = expandAssetFilePath(mDiffuseImposterFileName);
|
||||
mNormalImposterFileName = expandAssetFilePath(mNormalImposterFileName);
|
||||
}
|
||||
|
||||
void ShapeAsset::SplitSequencePathAndName(String& srcPath, String& srcName)
|
||||
{
|
||||
srcName = "";
|
||||
|
|
@ -705,7 +697,7 @@ const char* ShapeAsset::generateCachedPreviewImage(S32 resolution, String overri
|
|||
delete imposterCap;
|
||||
delete shape;
|
||||
|
||||
String dumpPath = String(mFilePath) + ".png";
|
||||
String dumpPath = String(mShapeFile) + ".png";
|
||||
|
||||
char* returnBuffer = Con::getReturnBuffer(128);
|
||||
dSprintf(returnBuffer, 128, "%s", dumpPath.c_str());
|
||||
|
|
@ -749,14 +741,14 @@ DefineEngineMethod(ShapeAsset, getShapePath, const char*, (), ,
|
|||
"Gets the shape's file path\n"
|
||||
"@return The filename of the shape file")
|
||||
{
|
||||
return object->getShapeFilePath();
|
||||
return object->getShapeFile();
|
||||
}
|
||||
|
||||
DefineEngineMethod(ShapeAsset, getShapeConstructorFilePath, const char*, (), ,
|
||||
"Gets the shape's constructor file.\n"
|
||||
"@return The filename of the shape constructor file")
|
||||
{
|
||||
return object->getShapeConstructorFilePath();
|
||||
return object->getShapeConstructorFile();
|
||||
}
|
||||
|
||||
DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string")\
|
||||
|
|
@ -992,5 +984,4 @@ void GuiInspectorTypeShapeAssetId::consoleInit()
|
|||
|
||||
ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue