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:
marauder2k7 2025-06-20 15:58:20 +01:00
parent 542563feaf
commit fd7342668c
15 changed files with 185 additions and 465 deletions

View file

@ -60,12 +60,20 @@ StringTableEntry ShapeAsset::smNoShapeAssetFallback = NULL;
IMPLEMENT_CONOBJECT(ShapeAsset); 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) ConsoleGetType(TypeShapeAssetPtr)
{ {
// Fetch asset Id. // Fetch asset Id.
//return *((StringTableEntry*)dptr);
return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId(); return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId();
} }
@ -77,17 +85,24 @@ ConsoleSetType(TypeShapeAssetPtr)
// Yes, so fetch field value. // Yes, so fetch field value.
const char* pFieldValue = argv[0]; const char* pFieldValue = argv[0];
// Fetch asset Id. // Fetch asset pointer.
StringTableEntry* assetId = (StringTableEntry*)(dptr); AssetPtr<ShapeAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAsset>*>((AssetPtrBase*)(dptr));
// Update asset value. // Is the asset pointer the correct type?
*assetId = StringTable->insert(pFieldValue); if (pAssetPtr == NULL)
{
Con::warnf("(TypeShapeAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
// Set asset.
pAssetPtr->setAssetId(pFieldValue);
return; return;
} }
// Warn. // 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."); 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 // REFACTOR END
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -176,15 +145,11 @@ const String ShapeAsset::mErrCodeStrings[] =
ShapeAsset::ShapeAsset() ShapeAsset::ShapeAsset()
{ {
mFileName = StringTable->EmptyString(); mShapeFile = StringTable->EmptyString();
mConstructorFileName = StringTable->EmptyString(); mConstructorFileName = StringTable->EmptyString();
mFilePath = StringTable->EmptyString();
mConstructorFilePath = StringTable->EmptyString();
mDiffuseImposterFileName = StringTable->EmptyString(); mDiffuseImposterFileName = StringTable->EmptyString();
mDiffuseImposterPath = StringTable->EmptyString();
mNormalImposterFileName = StringTable->EmptyString(); mNormalImposterFileName = StringTable->EmptyString();
mNormalImposterPath = StringTable->EmptyString();
mLoadedState = AssetErrCode::NotLoaded; mLoadedState = AssetErrCode::NotLoaded;
@ -217,7 +182,7 @@ void ShapeAsset::initPersistFields()
// Call parent. // Call parent.
Parent::initPersistFields(); 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"); &setShapeFile, &getShapeFile, "Path to the shape file we want to render");
addProtectedField("constuctorFileName", TypeAssetLooseFilePath, Offset(mConstructorFileName, ShapeAsset), addProtectedField("constuctorFileName", TypeAssetLooseFilePath, Offset(mConstructorFileName, ShapeAsset),
&setShapeConstructorFile, &getShapeConstructorFile, "Path to the shape file we want to render"); &setShapeConstructorFile, &getShapeConstructorFile, "Path to the shape file we want to render");
@ -225,7 +190,7 @@ void ShapeAsset::initPersistFields()
addProtectedField("diffuseImposterFileName", TypeAssetLooseFilePath, Offset(mDiffuseImposterFileName, ShapeAsset), addProtectedField("diffuseImposterFileName", TypeAssetLooseFilePath, Offset(mDiffuseImposterFileName, ShapeAsset),
&setDiffuseImposterFile, &getDiffuseImposterFile, "Path to the diffuse imposter file we want to render"); &setDiffuseImposterFile, &getDiffuseImposterFile, "Path to the diffuse imposter file we want to render");
addProtectedField("normalImposterFileName", TypeAssetLooseFilePath, Offset(mNormalImposterFileName, ShapeAsset), 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. // Call parent.
Parent::initializeAsset(); Parent::initializeAsset();
if (mFileName == StringTable->EmptyString()) if (mShapeFile == StringTable->EmptyString())
return; return;
ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged); ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged);
//Ensure our path is expando'd if it isn't already //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; mConstructorFileName = getOwned() ? expandAssetFilePath(mConstructorFileName) : mConstructorFileName;
if (!Torque::FS::IsFile(mConstructorFilePath)) if (!Torque::FS::IsFile(mConstructorFileName))
Con::errorf("ShapeAsset::initializeAsset (%s) could not find %s!", getAssetName(), mConstructorFilePath); Con::errorf("ShapeAsset::initializeAsset (%s) could not find %s!", getAssetName(), mConstructorFileName);
mDiffuseImposterPath = getOwned() ? expandAssetFilePath(mDiffuseImposterFileName) : mDiffuseImposterFileName;
if (mDiffuseImposterPath == StringTable->EmptyString())
mDiffuseImposterFileName = getOwned() ? expandAssetFilePath(mDiffuseImposterFileName) : mDiffuseImposterFileName;
if (mDiffuseImposterFileName == StringTable->EmptyString())
{ {
String diffusePath = String(mFilePath) + "_imposter.dds"; String diffusePath = String(mShapeFile) + "_imposter.dds";
mDiffuseImposterPath = StringTable->insert(diffusePath.c_str()); mDiffuseImposterFileName = StringTable->insert(diffusePath.c_str());
} }
mNormalImposterPath = getOwned() ? expandAssetFilePath(mNormalImposterFileName) : mNormalImposterFileName; mNormalImposterFileName = getOwned() ? expandAssetFilePath(mNormalImposterFileName) : mNormalImposterFileName;
if (mNormalImposterPath == StringTable->EmptyString()) if (mNormalImposterFileName == StringTable->EmptyString())
{ {
String normalPath = String(mFilePath) + "_imposter_normals.dds"; String normalPath = String(mShapeFile) + "_imposter_normals.dds";
mNormalImposterPath = StringTable->insert(normalPath.c_str()); mNormalImposterFileName = StringTable->insert(normalPath.c_str());
} }
} }
@ -283,10 +250,10 @@ void ShapeAsset::setShapeFile(const char* pShapeFile)
pShapeFile = StringTable->insert(pShapeFile, true); pShapeFile = StringTable->insert(pShapeFile, true);
// Ignore no change, // Ignore no change,
if (pShapeFile == mFileName) if (pShapeFile == mShapeFile)
return; return;
mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : pShapeFile; mShapeFile = getOwned() ? expandAssetFilePath(pShapeFile) : pShapeFile;
// Refresh the asset. // Refresh the asset.
refreshAsset(); refreshAsset();
@ -348,7 +315,7 @@ void ShapeAsset::setNormalImposterFile(const char* pImageFile)
void ShapeAsset::_onResourceChanged(const Torque::Path &path) void ShapeAsset::_onResourceChanged(const Torque::Path &path)
{ {
if (path != Torque::Path(mFilePath) ) if (path != Torque::Path(mShapeFile) )
return; return;
refreshAsset(); refreshAsset();
@ -397,17 +364,17 @@ U32 ShapeAsset::load()
} }
} }
mShape = ResourceManager::get().load(mFilePath); mShape = ResourceManager::get().load(mShapeFile);
if (!mShape) 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; mLoadedState = BadFileReference;
return mLoadedState; //if it failed to load, bail out return mLoadedState; //if it failed to load, bail out
} }
// Construct billboards if not done already // Construct billboards if not done already
if (GFXDevice::devicePresent()) 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 //If they exist, grab our imposters here and bind them to our shapeAsset
@ -467,8 +434,6 @@ U32 ShapeAsset::load()
mLoadedState = Ok; mLoadedState = Ok;
mChangeSignal.trigger();
return mLoadedState; return mLoadedState;
} }
@ -536,13 +501,13 @@ StringTableEntry ShapeAsset::getAssetIdByFilename(StringTableEntry fileName)
AssetPtr<ShapeAsset> temp = shapeAsset; AssetPtr<ShapeAsset> temp = shapeAsset;
if (temp.notNull()) if (temp.notNull())
{ {
if (temp->getShapePath() == fileName) if (temp->getShapeFile() == fileName)
{ {
return shapeAsset; return shapeAsset;
} }
else else
{ {
Torque::Path temp1 = temp->getShapePath(); Torque::Path temp1 = temp->getShapeFile();
Torque::Path temp2 = fileName; Torque::Path temp2 = fileName;
if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName()) if (temp1.getPath() == temp2.getPath() && temp1.getFileName() == temp2.getFileName())
@ -606,16 +571,43 @@ void ShapeAsset::copyTo(SimObject* object)
void ShapeAsset::onAssetRefresh(void) void ShapeAsset::onAssetRefresh(void)
{ {
if (mFileName == StringTable->EmptyString()) // Ignore if not yet added to the sim.
if (!isProperlyAdded())
return; return;
// Update. if (mShapeFile == StringTable->EmptyString())
if(!Platform::isFullPath(mFileName)) return;
mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath;
// Call parent.
Parent::onAssetRefresh();
load(); 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) void ShapeAsset::SplitSequencePathAndName(String& srcPath, String& srcName)
{ {
srcName = ""; srcName = "";
@ -705,7 +697,7 @@ const char* ShapeAsset::generateCachedPreviewImage(S32 resolution, String overri
delete imposterCap; delete imposterCap;
delete shape; delete shape;
String dumpPath = String(mFilePath) + ".png"; String dumpPath = String(mShapeFile) + ".png";
char* returnBuffer = Con::getReturnBuffer(128); char* returnBuffer = Con::getReturnBuffer(128);
dSprintf(returnBuffer, 128, "%s", dumpPath.c_str()); dSprintf(returnBuffer, 128, "%s", dumpPath.c_str());
@ -749,14 +741,14 @@ DefineEngineMethod(ShapeAsset, getShapePath, const char*, (), ,
"Gets the shape's file path\n" "Gets the shape's file path\n"
"@return The filename of the shape file") "@return The filename of the shape file")
{ {
return object->getShapeFilePath(); return object->getShapeFile();
} }
DefineEngineMethod(ShapeAsset, getShapeConstructorFilePath, const char*, (), , DefineEngineMethod(ShapeAsset, getShapeConstructorFilePath, const char*, (), ,
"Gets the shape's constructor file.\n" "Gets the shape's constructor file.\n"
"@return The filename of the shape constructor file") "@return The filename of the shape constructor file")
{ {
return object->getShapeConstructorFilePath(); return object->getShapeConstructorFile();
} }
DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string")\ DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string")\
@ -992,5 +984,4 @@ void GuiInspectorTypeShapeAssetId::consoleInit()
ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId"); ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId");
} }
#endif #endif

View file

@ -67,33 +67,6 @@ class ShapeAsset : public AssetBase
typedef AssetBase Parent; typedef AssetBase Parent;
typedef AssetPtr<ShapeAsset> ConcreteAssetPtr; typedef AssetPtr<ShapeAsset> ConcreteAssetPtr;
protected:
StringTableEntry mFileName;
StringTableEntry mConstructorFileName;
StringTableEntry mFilePath;
StringTableEntry mConstructorFilePath;
Resource<TSShape> mShape;
StringTableEntry mDiffuseImposterFileName;
StringTableEntry mDiffuseImposterPath;
StringTableEntry mNormalImposterFileName;
StringTableEntry mNormalImposterPath;
//Material assets we're dependent on and use
Vector<StringTableEntry> mMaterialAssetIds;
Vector<AssetPtr<MaterialAsset>> mMaterialAssets;
//Animation assets we're dependent on and use
Vector<StringTableEntry> mAnimationAssetIds;
Vector<AssetPtr<ShapeAnimationAsset>> mAnimationAssets;
typedef Signal<void()> ShapeAssetChanged;
ShapeAssetChanged mChangeSignal;
typedef Signal<void(S32 index)> ShapeAssetArrayChanged;
ShapeAssetArrayChanged mChangeArraySignal;
public: public:
enum ShapeAssetErrCode enum ShapeAssetErrCode
{ {
@ -115,6 +88,23 @@ public:
return mErrCodeStrings[errCode - Parent::Extended]; return mErrCodeStrings[errCode - Parent::Extended];
}; };
private:
StringTableEntry mShapeFile;
StringTableEntry mConstructorFileName;
StringTableEntry mDiffuseImposterFileName;
StringTableEntry mNormalImposterFileName;
//Material assets we're dependent on and use
Vector<StringTableEntry> mMaterialAssetIds;
Vector<AssetPtr<MaterialAsset>> mMaterialAssets;
//Animation assets we're dependent on and use
Vector<StringTableEntry> mAnimationAssetIds;
Vector<AssetPtr<ShapeAnimationAsset>> mAnimationAssets;
Resource<TSShape> mShape;
public:
ShapeAsset(); ShapeAsset();
virtual ~ShapeAsset(); virtual ~ShapeAsset();
@ -127,8 +117,6 @@ public:
virtual void setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value); virtual void setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value);
void initializeAsset() override;
/// Declare Console Object. /// Declare Console Object.
DECLARE_CONOBJECT(ShapeAsset); DECLARE_CONOBJECT(ShapeAsset);
@ -139,10 +127,8 @@ public:
Resource<TSShape> getShapeResource() { load(); return mShape; } Resource<TSShape> getShapeResource() { load(); return mShape; }
void SplitSequencePathAndName(String& srcPath, String& srcName); void SplitSequencePathAndName(String& srcPath, String& srcName);
StringTableEntry getShapeFileName() { return mFileName; }
StringTableEntry getShapePath() { return mFilePath; }
U32 getShapeFilenameHash() { return _StringTable::hashString(mFilePath); } U32 getShapeFilenameHash() { return _StringTable::hashString(mShapeFile); }
Vector<AssetPtr<MaterialAsset>> getMaterialAssets() { return mMaterialAssets; } Vector<AssetPtr<MaterialAsset>> getMaterialAssets() { return mMaterialAssets; }
@ -164,26 +150,18 @@ public:
void _onResourceChanged(const Torque::Path& path); void _onResourceChanged(const Torque::Path& path);
ShapeAssetChanged& getChangedSignal() { return mChangeSignal; }
ShapeAssetArrayChanged& getChangedArraySignal() { return mChangeArraySignal; }
void setShapeFile(const char* pScriptFile); void setShapeFile(const char* pScriptFile);
inline StringTableEntry getShapeFile(void) const { return mFileName; }; inline StringTableEntry getShapeFile(void) const { return mShapeFile; };
void setShapeConstructorFile(const char* pScriptFile); void setShapeConstructorFile(const char* pScriptFile);
inline StringTableEntry getShapeConstructorFile(void) const { return mConstructorFileName; }; inline StringTableEntry getShapeConstructorFile(void) const { return mConstructorFileName; };
inline StringTableEntry getShapeFilePath(void) const { return mFilePath; };
inline StringTableEntry getShapeConstructorFilePath(void) const { return mConstructorFilePath; };
//Imposter images //Imposter images
void setDiffuseImposterFile(const char* pImageFile); void setDiffuseImposterFile(const char* pImageFile);
inline StringTableEntry getDiffuseImposterFile(void) const { return mDiffuseImposterFileName; }; inline StringTableEntry getDiffuseImposterFile(void) const { return mDiffuseImposterFileName; };
inline StringTableEntry getDiffuseImposterFilePath(void) const { return mDiffuseImposterPath; };
void setNormalImposterFile(const char* pImageFile); void setNormalImposterFile(const char* pImageFile);
inline StringTableEntry getNormalImposterFile(void) const { return mNormalImposterFileName; }; inline StringTableEntry getNormalImposterFilePath(void) const { return mNormalImposterFileName; };
inline StringTableEntry getNormalImposterFilePath(void) const { return mNormalImposterPath; };
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset); static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset);
@ -195,25 +173,33 @@ public:
#endif #endif
protected: protected:
void onAssetRefresh(void) override; // Asset Base callback
void initializeAsset(void) override;
void onAssetRefresh(void) override;
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
protected:
static bool setShapeFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setShapeFile(data); return false; } static bool setShapeFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setShapeFile(data); return false; }
static const char* getShapeFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeFile(); } static const char* getShapeFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeFile(); }
static bool writeShapeFile(void* obj, StringTableEntry pFieldName) { return static_cast<ShapeAsset*>(obj)->getShapeFile() != StringTable->EmptyString(); }
static bool setShapeConstructorFile(void* obj, const char* index, const char* data) { static_cast<ShapeAsset*>(obj)->setShapeConstructorFile(data); return false; } static bool setShapeConstructorFile(void* obj, const char* index, const char* data) { static_cast<ShapeAsset*>(obj)->setShapeConstructorFile(data); return false; }
static const char* getShapeConstructorFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeConstructorFile(); } static const char* getShapeConstructorFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeConstructorFile(); }
static bool setDiffuseImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setDiffuseImposterFile(data); return false; } static bool setDiffuseImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setDiffuseImposterFile(data); return false; }
static const char* getDiffuseImposterFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getDiffuseImposterFile(); } static const char* getDiffuseImposterFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getDiffuseImposterFile(); }
static bool setNormalImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setNormalImposterFile(data); return false; } static bool setNormalImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setNormalImposterFile(data); return false; }
static const char* getNormalImposterFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getNormalImposterFile(); } static const char* getNormalImposterFilePath(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getNormalImposterFilePath(); }
}; };
DefineConsoleType(TypeShapeAssetPtr, S32)
DefineConsoleType(TypeShapeAssetId, String) DefineConsoleType(TypeShapeAssetId, String)
DECLARE_STRUCT(AssetPtr<ShapeAsset>) DECLARE_STRUCT(AssetPtr<ShapeAsset>)
DefineConsoleType(TypeShapeAssetPtrRefactor, AssetPtr<ShapeAsset>) DefineConsoleType(TypeShapeAssetPtr, AssetPtr<ShapeAsset>)
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -249,254 +235,9 @@ public:
DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetId); DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetId);
static void consoleInit(); static void consoleInit();
}; };
#endif #endif
#pragma region Singular Asset Macros
#define DECLARE_SHAPEASSET(className,name,changeFunc) public: \
Resource<TSShape>m##name;\
StringTableEntry m##name##Name; \
StringTableEntry m##name##AssetId;\
AssetPtr<ShapeAsset> m##name##Asset;\
public: \
const StringTableEntry get##name##File() const { return StringTable->insert(m##name##Name); }\
void set##name##Name(const FileName &_in) { m##name##Name = _in;}\
const AssetPtr<ShapeAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(const AssetPtr<ShapeAsset> &_in) { m##name##Asset = _in;}\
\
bool _set##name(StringTableEntry _in)\
{\
if(m##name##AssetId != _in || m##name##Name != _in)\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
}\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name = StringTable->EmptyString();\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
m##name = NULL;\
return true;\
}\
\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId = _in;\
\
U32 assetState = ShapeAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
\
if (ShapeAsset::Ok == assetState)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(_in);\
if (assetId != StringTable->EmptyString())\
{\
m##name##AssetId = assetId;\
if (ShapeAsset::getAssetById(m##name##AssetId, &m##name##Asset) == ShapeAsset::Ok)\
{\
m##name##Name = StringTable->EmptyString();\
}\
}\
else\
{\
m##name##Name = _in;\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
}\
}\
}\
if (get##name() != StringTable->EmptyString() && m##name##Asset.notNull())\
{\
m##name = m##name##Asset->getShapeResource();\
\
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
}\
else\
{\
m##name = NULL;\
}\
\
if(get##name() == StringTable->EmptyString())\
return true;\
\
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != ShapeAsset::Ok)\
{\
Con::errorf("%s(%s)::_set%s() - shape asset failure \"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ShapeAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
return false; \
}\
else if (!m##name)\
{\
Con::errorf("%s(%s)::_set%s() - Couldn't load shape \"%s\"", macroText(className), getName(), macroText(name), _in);\
return false;\
}\
return true;\
}\
\
const StringTableEntry get##name() const\
{\
if (m##name##Asset && (m##name##Asset->getShapePath() != StringTable->EmptyString()))\
return m##name##Asset->getShapePath();\
else if (m##name##AssetId != StringTable->EmptyString())\
return m##name##AssetId;\
else if (m##name##Name != StringTable->EmptyString())\
return m##name##Name;\
else\
return StringTable->EmptyString();\
}\
Resource<TSShape> get##name##Resource() \
{\
return m##name;\
}\
bool is##name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
#define INITPERSISTFIELD_SHAPEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, docs)); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, asset reference.));
#else
#define INITPERSISTFIELD_SHAPEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, asset reference.));
#endif // SHOW_LEGACY_FILE_FIELDS
#pragma endregion
#pragma region Arrayed Asset Macros
#define DECLARE_SHAPEASSET_ARRAY(className,name,max,changeFunc) public: \
static const U32 sm##name##Count = max;\
Resource<TSShape>m##name[max];\
StringTableEntry m##name##Name[max]; \
StringTableEntry m##name##AssetId[max];\
AssetPtr<ShapeAsset> m##name##Asset[max];\
public: \
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
void set##name##Name(const FileName &_in, const U32& index) { m##name##Name[index] = _in;}\
const AssetPtr<ShapeAsset> & get##name##Asset(const U32& index) const { return m##name##Asset[index]; }\
void set##name##Asset(const AssetPtr<ShapeAsset> &_in, const U32& index) { m##name##Asset[index] = _in;}\
\
bool _set##name(StringTableEntry _in, const U32& index)\
{\
if (m##name##Asset[index].notNull())\
{\
m##name##Asset[index]->getChangedSignal().remove(this, &className::changeFunc);\
}\
if(m##name##AssetId[index] != _in || m##name##Name[index] != _in)\
{\
if(index >= sm##name##Count || index < 0)\
return false;\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##Name[index] = StringTable->EmptyString();\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
m##name[index] = NULL;\
return true;\
}\
\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId[index] = _in;\
\
U32 assetState = ShapeAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]);\
\
if (ShapeAsset::Ok == assetState)\
{\
m##name##Name[index] = StringTable->EmptyString();\
}\
}\
else\
{\
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(_in);\
if (assetId != StringTable->EmptyString())\
{\
m##name##AssetId[index] = assetId;\
if (ShapeAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]) == ShapeAsset::Ok)\
{\
m##name##Name[index] = StringTable->EmptyString();\
}\
}\
else\
{\
m##name##Name[index] = _in;\
m##name##AssetId[index] = StringTable->EmptyString();\
m##name##Asset[index] = NULL;\
}\
}\
}\
if (get##name(index) != StringTable->EmptyString() && m##name##Asset[index].notNull())\
{\
m##name[index] = m##name##Asset[index]->getShapeResource();\
\
m##name##Asset[index]->getChangedSignal().notify(this, &className::changeFunc);\
}\
else\
{\
m##name[index] = NULL;\
}\
\
if(get##name(index) == StringTable->EmptyString())\
return true;\
\
if (m##name##Asset[index].notNull() && m##name##Asset[index]->getStatus() != ShapeAsset::Ok)\
{\
Con::errorf("%s(%s)::_set%s(%i) - shape asset failure \"%s\" due to [%s]", macroText(className), getName(), macroText(name), index, _in, ShapeAsset::getAssetErrstrn(m##name##Asset[index]->getStatus()).c_str());\
return false; \
}\
else if (!m##name[index])\
{\
Con::errorf("%s(%s)::_set%s(%i) - Couldn't load shape \"%s\"", macroText(className), getName(), macroText(name), index, _in);\
return false; \
}\
return true;\
}\
\
const StringTableEntry get##name(const U32& index) const\
{\
if (m##name##Asset[index] && (m##name##Asset[index]->getShapePath() != StringTable->EmptyString()))\
return m##name##Asset[index]->getShapePath();\
else if (m##name##AssetId[index] != StringTable->EmptyString())\
return m##name##AssetId[index];\
else if (m##name##Name[index] != StringTable->EmptyString())\
return StringTable->insert(m##name##Name[index]);\
else\
return StringTable->EmptyString();\
}\
Resource<TSShape> get##name##Resource(const U32& index) \
{\
if(index >= sm##name##Count || index < 0)\
return ResourceManager::get().load( "" );\
return m##name[index];\
}\
bool is##name##Valid(const U32& id) {return (get##name(id) != StringTable->EmptyString() && m##name##Asset[id]->getStatus() == AssetBase::Ok); }
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
#define INITPERSISTFIELD_SHAPEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, arraySize, assetText(name, docs)); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, arraySize, assetText(name, asset reference.));
#else
#define INITPERSISTFIELD_SHAPEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, arraySize, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, arraySize,assetText(name, asset reference.));
#endif // SHOW_LEGACY_FILE_FIELDS
#pragma endregion
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// REFACTOR // REFACTOR
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -557,7 +298,7 @@ public:
Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \ Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \
AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \ AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \ static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapePath() : ""; } StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }
#define DECLARE_SHAPEASSET_NET_REFACTOR(className, name, mask) \ #define DECLARE_SHAPEASSET_NET_REFACTOR(className, name, mask) \
private: \ private: \
@ -615,10 +356,10 @@ public:
Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \ Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); } \
AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \ AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \ static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; } \
StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapePath() : ""; } StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }
#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs) \ #define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeShapeAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \ addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.)); addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.));
@ -676,7 +417,7 @@ public:
Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \ Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \ AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\ static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapePath() : ""; } StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }
#define DECLARE_SHAPEASSET_ARRAY_NET_REFACTOR(className, name, max, mask) \ #define DECLARE_SHAPEASSET_ARRAY_NET_REFACTOR(className, name, max, mask) \
private: \ private: \
@ -734,10 +475,10 @@ public:
Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \ Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \ AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\ static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapePath() : ""; } StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }
#define INITPERSISTFIELD_SHAPEASSET_ARRAY_REFACTOR(name, arraySize, consoleClass, docs) \ #define INITPERSISTFIELD_SHAPEASSET_ARRAY_REFACTOR(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeShapeAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));\ addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));\
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.)); addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#pragma endregion #pragma endregion

View file

@ -3035,31 +3035,15 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str()); StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
String shapeFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension(); String shapeFileName = "@" + assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
String constructorFileName = assetItem->filePath.getFileName() + "." TORQUE_SCRIPT_EXTENSION; String constructorFileName = assetItem->filePath.getFileName() + "." TORQUE_SCRIPT_EXTENSION;
String assetPath = targetPath + "/" + shapeFileName; String assetPath = targetPath + "/" + shapeFileName;
String constructorPath = targetPath + "/" + constructorFileName; String constructorPath = targetPath + "/" + constructorFileName;
constructorFileName = "@" + constructorFileName;
String tamlPath = targetPath + "/" + assetName + ".asset.taml"; String tamlPath = targetPath + "/" + assetName + ".asset.taml";
String originalPath = assetItem->filePath.getFullPath().c_str(); String originalPath = assetItem->filePath.getFullPath().c_str();
String originalConstructorPath = assetItem->filePath.getPath() + "/" + constructorFileName; String originalConstructorPath = assetItem->filePath.getPath() + "/" + constructorFileName;
char qualifiedFromFile[2048];
char qualifiedToFile[2048];
char qualifiedFromCSFile[2048];
char qualifiedToCSFile[2048];
#ifndef TORQUE_SECURE_VFS
Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
Platform::makeFullPathName(assetPath.c_str(), qualifiedToFile, sizeof(qualifiedToFile));
Platform::makeFullPathName(originalConstructorPath.c_str(), qualifiedFromCSFile, sizeof(qualifiedFromCSFile));
Platform::makeFullPathName(constructorPath.c_str(), qualifiedToCSFile, sizeof(qualifiedToCSFile));
#else
dStrcpy(qualifiedFromFile, originalPath.c_str(), sizeof(qualifiedFromFile));
dStrcpy(qualifiedToFile, assetPath.c_str(), sizeof(qualifiedToFile));
dStrcpy(qualifiedFromCSFile, originalConstructorPath.c_str(), sizeof(qualifiedFromCSFile));
dStrcpy(qualifiedToCSFile, constructorPath.c_str(), sizeof(qualifiedToCSFile));
#endif
newAsset->setAssetName(assetName); newAsset->setAssetName(assetName);
newAsset->setShapeFile(shapeFileName.c_str()); newAsset->setShapeFile(shapeFileName.c_str());
newAsset->setShapeConstructorFile(constructorFileName.c_str()); newAsset->setShapeConstructorFile(constructorFileName.c_str());
@ -3076,9 +3060,9 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
//If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
//file path for reimporting support later //file path for reimporting support later
if (!isReimport && String::compare(qualifiedFromFile, qualifiedToFile) && Torque::FS::IsFile(qualifiedFromFile)) if (!isReimport && Torque::FS::IsFile(originalPath))
{ {
newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile); newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, originalPath.c_str());
} }
//iterate through and write out the material maps dependencies //iterate through and write out the material maps dependencies
@ -3118,8 +3102,8 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
if (Con::getBoolVariable("$TSLastDetail::dumpImposters", false)) if (Con::getBoolVariable("$TSLastDetail::dumpImposters", false))
{ {
String imposterPath = assetItem->assetName + "_imposter.png"; String imposterPath = "@" + assetItem->assetName + "_imposter.png";
String normalsPath = assetItem->assetName + "_imposter_normals.png"; String normalsPath = "@" + assetItem->assetName + "_imposter_normals.png";
newAsset->setDiffuseImposterFile(imposterPath.c_str()); newAsset->setDiffuseImposterFile(imposterPath.c_str());
newAsset->setNormalImposterFile(normalsPath.c_str()); newAsset->setNormalImposterFile(normalsPath.c_str());
@ -3138,67 +3122,37 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
bool makeNewConstructor = true; bool makeNewConstructor = true;
if (!isReimport) if (!isReimport)
{ {
bool isInPlace = !String::compare(qualifiedFromFile, qualifiedToFile); //We're doing an in-place import, so double check we've already got a constructor file in the expected spot
if (Torque::FS::IsFile(constructorPath))
if (!isInPlace && !Torque::FS::CopyFile(qualifiedFromFile, qualifiedToFile, !isReimport))
{ {
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromFile); //Yup, found it, we're good to go
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", constructorPath.c_str());
activityLog.push_back(importLogBuffer); activityLog.push_back(importLogBuffer);
return "";
}
if (!isInPlace)
{
if (Torque::FS::IsFile(qualifiedFromCSFile))
{
if (!Torque::FS::CopyFile(qualifiedFromCSFile, qualifiedToCSFile, !isReimport))
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
}
else
{
//We successfully copied the original constructor file, so no extra work required
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Successfully copied original TSShape Constructor file %s", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
}
}
} }
else else
{ {
//We're doing an in-place import, so double check we've already got a constructor file in the expected spot //Didn't work, but it's possible it's using the old .cs extension when our extension variable is set to something else, so check that one as well just to be sure
if (Torque::FS::IsFile(qualifiedFromCSFile)) Torque::Path constrFilePath = constructorPath;
constrFilePath.setExtension("cs");
if (Torque::FS::IsFile(constrFilePath.getFullPath().c_str()))
{ {
//Yup, found it, we're good to go //Yup, found it, we're good to go
makeNewConstructor = false; makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", qualifiedFromCSFile); dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", constrFilePath.getFullPath().c_str());
activityLog.push_back(importLogBuffer); activityLog.push_back(importLogBuffer);
} }
else
{
//Didn't work, but it's possible it's using the old .cs extension when our extension variable is set to something else, so check that one as well just to be sure
Torque::Path constrFilePath = qualifiedFromCSFile;
constrFilePath.setExtension("cs");
if (Torque::FS::IsFile(constrFilePath.getFullPath().c_str()))
{
//Yup, found it, we're good to go
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", constrFilePath.getFullPath().c_str());
activityLog.push_back(importLogBuffer);
}
}
} }
} }
if (makeNewConstructor) if (makeNewConstructor)
{ {
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning creation of new TSShapeConstructor file: %s", qualifiedToCSFile); dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning creation of new TSShapeConstructor file: %s", constructorPath.c_str());
activityLog.push_back(importLogBuffer); activityLog.push_back(importLogBuffer);
//find/create shape constructor //find/create shape constructor
TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructorByFilename(Torque::Path(qualifiedToFile).getFullPath()); TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructorByFilename(Torque::Path(constructorPath).getFullPath());
if (constructor == nullptr) if (constructor == nullptr)
{ {
String fullAssetName = assetItem->moduleName + ":" + assetItem->assetName; String fullAssetName = assetItem->moduleName + ":" + assetItem->assetName;
@ -3302,7 +3256,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
PersistenceManager* constructorPersist = new PersistenceManager(); PersistenceManager* constructorPersist = new PersistenceManager();
constructorPersist->registerObject(); constructorPersist->registerObject();
constructorPersist->setDirty(constructor, qualifiedToCSFile); constructorPersist->setDirty(constructor, constructorPath);
if (!constructorPersist->saveDirtyObject(constructor)) if (!constructorPersist->saveDirtyObject(constructor))
{ {

View file

@ -357,7 +357,7 @@ bool GuiObjectView::setObjectModel( const String& modelName )
mModelInstance->reSkin( mSkinName ); mModelInstance->reSkin( mSkinName );
TSMaterialList* pMatList = mModelInstance->getMaterialList(); TSMaterialList* pMatList = mModelInstance->getMaterialList();
pMatList->setTextureLookupPath(mModelAsset->getShapeFileName()); pMatList->setTextureLookupPath(mModelAsset->getShapeFile());
mModelInstance->initMaterialList(); mModelInstance->initMaterialList();
// Initialize camera values. // Initialize camera values.

View file

@ -119,7 +119,7 @@ void PhysicsDebrisData::initPersistFields()
addGroup( "Shapes" ); addGroup( "Shapes" );
INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, PhysicsDebrisData, "@brief Shape to use with this debris.\n\n" INITPERSISTFIELD_SHAPEASSET_REFACTOR(Shape, PhysicsDebrisData, "@brief Shape to use with this debris.\n\n"
"Compatable with Live-Asset Reloading."); "Compatable with Live-Asset Reloading.");
endGroup( "Shapes" ); endGroup( "Shapes" );

View file

@ -247,7 +247,7 @@ void PhysicsShapeData::_onResourceChanged( const Torque::Path &path )
{ {
return; return;
} }
if ( path != Path(mShapeAsset->getShapeFilePath()) ) if ( path != Path(mShapeAsset->getShapeFile()) )
return; return;
_setShape(_getShapeAssetId()); _setShape(_getShapeAssetId());

View file

@ -363,7 +363,7 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
{ {
Con::printf("Validation required for shape asset: %s", mShapeAsset.getAssetId()); Con::printf("Validation required for shape asset: %s", mShapeAsset.getAssetId());
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(mShapeAsset->getShapePath()); Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(mShapeAsset->getShapeFile());
if (!fileRef) if (!fileRef)
{ {

View file

@ -1587,7 +1587,7 @@ void TSStatic::updateMaterials()
String path; String path;
if (mShapeAsset->isAssetValid()) if (mShapeAsset->isAssetValid())
path = mShapeAsset->getShapeFileName(); path = mShapeAsset->getShapeFile();
else else
path = mShapeFile; path = mShapeFile;

View file

@ -420,7 +420,7 @@ bool GuiShapeEdPreview::setObjectShapeAsset(const char* assetId)
if (assetType == StringTable->insert("ShapeAsset")) if (assetType == StringTable->insert("ShapeAsset"))
{ {
ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(id); ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(id);
modelName = asset->getShapeFilePath(); modelName = asset->getShapeFile();
AssetDatabase.releaseAsset(id); AssetDatabase.releaseAsset(id);
} }
else if (assetType == StringTable->insert("ShapeAnimationAsset")) else if (assetType == StringTable->insert("ShapeAnimationAsset"))

View file

@ -665,7 +665,7 @@ void GuiInspectorGroup::addInspectorField(StringTableEntry name, StringTableEntr
else if (typeName == StringTable->insert("image")) else if (typeName == StringTable->insert("image"))
fieldType = TypeImageAssetPtr; fieldType = TypeImageAssetPtr;
else if (typeName == StringTable->insert("shape")) else if (typeName == StringTable->insert("shape"))
fieldType = TypeShapeAssetId; fieldType = TypeShapeAssetPtr;
else if (typeName == StringTable->insert("sound")) else if (typeName == StringTable->insert("sound"))
fieldType = TypeSoundAssetId; fieldType = TypeSoundAssetId;
else if (typeName == StringTable->insert("bool")) else if (typeName == StringTable->insert("bool"))

View file

@ -205,7 +205,7 @@ void GuiVariableInspector::addField(const char* name, const char* label, const c
else if (newField->mFieldTypeName == StringTable->insert("image")) else if (newField->mFieldTypeName == StringTable->insert("image"))
fieldTypeMask = TypeImageAssetPtr; fieldTypeMask = TypeImageAssetPtr;
else if (newField->mFieldTypeName == StringTable->insert("shape")) else if (newField->mFieldTypeName == StringTable->insert("shape"))
fieldTypeMask = TypeShapeAssetId; fieldTypeMask = TypeShapeAssetPtr;
else if (newField->mFieldTypeName == StringTable->insert("bool")) else if (newField->mFieldTypeName == StringTable->insert("bool"))
fieldTypeMask = TypeBool; fieldTypeMask = TypeBool;
else if (newField->mFieldTypeName == StringTable->insert("object")) else if (newField->mFieldTypeName == StringTable->insert("object"))

View file

@ -993,6 +993,23 @@ TSShape* assimpLoadShape(const Torque::Path &path)
tss->write(&dtsStream); tss->write(&dtsStream);
} }
Torque::Path dsqPath(cachedPath);
dsqPath.setExtension("dsq");
FileStream animOutStream;
for (S32 i = 0; i < tss->sequences.size(); i++)
{
const String& seqName = tss->getName(tss->sequences[i].nameIndex);
Con::printf("Writing DSQ Animation File for sequence '%s'", seqName.c_str());
dsqPath.setFileName(cachedPath.getFileName() + "_" + seqName);
if (animOutStream.open(dsqPath.getFullPath(), Torque::FS::File::Write))
{
tss->exportSequence(&animOutStream, tss->sequences[i], false);
animOutStream.close();
}
}
loader.updateMaterialsScript(path); loader.updateMaterialsScript(path);
} }
loader.releaseImport(); loader.releaseImport();

View file

@ -737,6 +737,23 @@ TSShape* loadColladaShape(const Torque::Path &path)
tss->write(&dtsStream); tss->write(&dtsStream);
} }
Torque::Path dsqPath(cachedPath);
dsqPath.setExtension("dsq");
FileStream animOutStream;
for (S32 i = 0; i < tss->sequences.size(); i++)
{
const String& seqName = tss->getName(tss->sequences[i].nameIndex);
Con::printf("Writing DSQ Animation File for sequence '%s'", seqName.c_str());
dsqPath.setFileName(cachedPath.getFileName() + "_" + seqName);
if (animOutStream.open(dsqPath.getFullPath(), Torque::FS::File::Write))
{
tss->exportSequence(&animOutStream, tss->sequences[i], false);
animOutStream.close();
}
}
#endif // DAE2DTS_TOOL #endif // DAE2DTS_TOOL
// Add collada materials to materials.tscript // Add collada materials to materials.tscript

View file

@ -2138,7 +2138,7 @@ DefineTSShapeConstructorMethod(addSequence, bool,
if (assetType == StringTable->insert("ShapeAsset")) if (assetType == StringTable->insert("ShapeAsset"))
{ {
ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(assetId); ShapeAsset* asset = AssetDatabase.acquireAsset<ShapeAsset>(assetId);
srcPath = asset->getShapeFilePath(); srcPath = asset->getShapeFile();
AssetDatabase.releaseAsset(assetId); AssetDatabase.releaseAsset(assetId);
} }
else if (assetType == StringTable->insert("ShapeAnimationAsset")) else if (assetType == StringTable->insert("ShapeAnimationAsset"))

View file

@ -236,7 +236,7 @@ public:
StringTableEntry getShapePath() const StringTableEntry getShapePath() const
{ {
if (mShapeAsset.notNull()) if (mShapeAsset.notNull())
return mShapeAsset->getShapeFilePath(); return mShapeAsset->getShapeFile();
else else
return StringTable->EmptyString(); return StringTable->EmptyString();
} }