mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Merge remote-tracking branch 'devhead/Preview4_0' into tsneo
# Conflicts: # Templates/BaseGame/game/data/ui/guis/loadingGui.gui # Templates/BaseGame/game/data/ui/guis/mainMenu.gui # Templates/BaseGame/game/tools/MainEditor/guis/MainEditorWindow.gui # Templates/BaseGame/game/tools/assetBrowser/guis/assetPreviewButtonsTemplate.gui # Templates/BaseGame/game/tools/forestEditor/brushes.tscript
This commit is contained in:
commit
717c7acca9
2266 changed files with 48780 additions and 26034 deletions
|
|
@ -136,7 +136,7 @@ void CubemapAsset::initializeAsset()
|
|||
{
|
||||
mScriptFile = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if(Platform::isFile(mScriptFile))
|
||||
if(Torque::FS::IsScriptFile(mScriptFile))
|
||||
Con::executeFile(mScriptFile, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ void CubemapAsset::onAssetRefresh()
|
|||
{
|
||||
mScriptFile = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptFile))
|
||||
if (Torque::FS::IsScriptFile(mScriptFile))
|
||||
Con::executeFile(mScriptFile, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -207,8 +207,8 @@ GuiControl* GuiInspectorTypeCubemapAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "CubemapEditor.openCubemapAsset(%d.getText());", retCtrl->getId());
|
||||
mShapeEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mShapeEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:shape_editor_n_image";
|
||||
mShapeEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
|
|||
|
|
@ -47,14 +47,14 @@
|
|||
|
||||
IMPLEMENT_CONOBJECT(GUIAsset);
|
||||
|
||||
ConsoleType(GUIAssetPtr, TypeGUIAssetPtr, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(GUIAssetPtr, TypeGUIAssetPtr, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType(TypeGUIAssetPtr)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return *((StringTableEntry*)dptr);
|
||||
return *((const char**)(dptr));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -67,11 +67,7 @@ ConsoleSetType(TypeGUIAssetPtr)
|
|||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -123,12 +119,12 @@ void GUIAsset::initializeAsset()
|
|||
{
|
||||
mGUIPath = expandAssetFilePath(mGUIFile);
|
||||
|
||||
if (Platform::isFile(mGUIPath))
|
||||
if (Torque::FS::IsScriptFile(mGUIPath))
|
||||
Con::executeFile(mGUIPath, false, false);
|
||||
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -136,12 +132,12 @@ void GUIAsset::onAssetRefresh()
|
|||
{
|
||||
mGUIPath = expandAssetFilePath(mGUIFile);
|
||||
|
||||
if (Platform::isFile(mGUIPath))
|
||||
if (Torque::FS::IsScriptFile(mGUIPath))
|
||||
Con::executeFile(mGUIPath, false, false);
|
||||
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -183,6 +179,50 @@ void GUIAsset::setScriptFile(const char* pScriptFile)
|
|||
refreshAsset();
|
||||
}
|
||||
|
||||
StringTableEntry GUIAsset::getAssetIdByGUIName(StringTableEntry guiName)
|
||||
{
|
||||
StringTableEntry assetId = StringTable->EmptyString();
|
||||
|
||||
AssetQuery* query = new AssetQuery();
|
||||
U32 foundCount = AssetDatabase.findAssetType(query, "GUIAsset");
|
||||
if (foundCount == 0)
|
||||
{
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
assetId = StringTable->insert("Core_Rendering:noMaterial");
|
||||
}
|
||||
else
|
||||
{
|
||||
GuiControl* guiObject;
|
||||
if (!Sim::findObject(guiName, guiObject))
|
||||
return "";
|
||||
|
||||
StringTableEntry guiFile = guiObject->getFilename();
|
||||
|
||||
for (U32 i = 0; i < foundCount; i++)
|
||||
{
|
||||
GUIAsset* guiAsset = AssetDatabase.acquireAsset<GUIAsset>(query->mAssetList[i]);
|
||||
if (guiAsset && guiAsset->getGUIPath() == guiFile)
|
||||
{
|
||||
assetId = guiAsset->getAssetId();
|
||||
AssetDatabase.releaseAsset(query->mAssetList[i]);
|
||||
break;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query->mAssetList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return assetId;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineStaticMethod(GUIAsset, getAssetIdByGUIName, const char*, (const char* guiName), (""),
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided GUI Name.\n"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return GUIAsset::getAssetIdByGUIName(StringTable->insert(guiName));
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GuiInspectorTypeAssetId
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -221,13 +261,13 @@ GuiControl* GuiInspectorTypeGUIAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
|
||||
mSMEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mSMEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:GameTSCtrl_image";
|
||||
mSMEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
|
||||
mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor");
|
||||
mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the GUI Editor");
|
||||
|
||||
mSMEdButton->registerObject();
|
||||
addObject(mSMEdButton);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ public:
|
|||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
static StringTableEntry getAssetIdByGUIName(StringTableEntry guiName);
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(GUIAsset);
|
||||
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ void GameObjectAsset::initializeAsset()
|
|||
//Ensure we have an expanded filepath
|
||||
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
|
||||
mTAMLPath = getOwned() ? expandAssetFilePath(mTAMLFile) : mTAMLPath;
|
||||
|
|
@ -144,7 +144,7 @@ void GameObjectAsset::onAssetRefresh()
|
|||
//Ensure we have an expanded filepath
|
||||
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
|
||||
mTAMLPath = getOwned() ? expandAssetFilePath(mTAMLFile) : mTAMLPath;
|
||||
|
|
@ -192,7 +192,7 @@ void GameObjectAsset::setTAMLFile(const char* pTAMLFile)
|
|||
|
||||
const char* GameObjectAsset::create()
|
||||
{
|
||||
if (!Platform::isFile(mTAMLFile))
|
||||
if (!Torque::FS::IsFile(mTAMLFile))
|
||||
return "";
|
||||
|
||||
// Set the format mode.
|
||||
|
|
|
|||
|
|
@ -42,23 +42,30 @@
|
|||
|
||||
#include "gfx/gfxStringEnumTranslate.h"
|
||||
|
||||
#include "ImageAssetInspectors.h"
|
||||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
#include "T3D/assets/assetImporter.h"
|
||||
#include "gfx/gfxDrawUtil.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry ImageAsset::smNoImageAssetFallback(StringTable->insert(Con::getVariable("$Core::NoImageAssetFallback")));
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(ImageAsset);
|
||||
|
||||
ConsoleType(ImageAssetPtr, TypeImageAssetPtr, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(ImageAssetPtr, TypeImageAssetPtr, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType(TypeImageAssetPtr)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return *((StringTableEntry*)dptr);
|
||||
return *((const char**)(dptr));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -69,13 +76,7 @@ ConsoleSetType(TypeImageAssetPtr)
|
|||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -84,7 +85,7 @@ ConsoleSetType(TypeImageAssetPtr)
|
|||
Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
ConsoleType(assetIdString, TypeImageAssetId, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(assetIdString, TypeImageAssetId, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
ConsoleGetType(TypeImageAssetId)
|
||||
{
|
||||
|
|
@ -97,14 +98,7 @@ ConsoleSetType(TypeImageAssetId)
|
|||
// Was a single argument specified?
|
||||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -117,26 +111,27 @@ ConsoleSetType(TypeImageAssetId)
|
|||
ImplementEnumType(ImageAssetType,
|
||||
"Type of mesh data available in a shape.\n"
|
||||
"@ingroup gameObjects")
|
||||
{ ImageAsset::Albedo, "Albedo", "" },
|
||||
{ ImageAsset::Normal, "Normal", "" },
|
||||
{ ImageAsset::ORMConfig, "ORMConfig", "" },
|
||||
{ ImageAsset::GUI, "GUI", "" },
|
||||
{ ImageAsset::Roughness, "Roughness", "" },
|
||||
{ ImageAsset::AO, "AO", "" },
|
||||
{ ImageAsset::Metalness, "Metalness", "" },
|
||||
{ ImageAsset::Glow, "Glow", "" },
|
||||
{ ImageAsset::Particle, "Particle", "" },
|
||||
{ ImageAsset::Decal, "Decal", "" },
|
||||
{ ImageAsset::Cubemap, "Cubemap", "" },
|
||||
{ ImageAsset::Albedo, "Albedo", "" },
|
||||
{ ImageAsset::Normal, "Normal", "" },
|
||||
{ ImageAsset::ORMConfig, "ORMConfig", "" },
|
||||
{ ImageAsset::GUI, "GUI", "" },
|
||||
{ ImageAsset::Roughness, "Roughness", "" },
|
||||
{ ImageAsset::AO, "AO", "" },
|
||||
{ ImageAsset::Metalness, "Metalness", "" },
|
||||
{ ImageAsset::Glow, "Glow", "" },
|
||||
{ ImageAsset::Particle, "Particle", "" },
|
||||
{ ImageAsset::Decal, "Decal", "" },
|
||||
{ ImageAsset::Cubemap, "Cubemap", "" },
|
||||
|
||||
EndImplementEnumType;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageAsset::ImageAsset() : AssetBase(), mImage(nullptr), mUseMips(true), mIsHDRImage(false), mIsValidImage(false), mImageType(Albedo)
|
||||
ImageAsset::ImageAsset() : AssetBase(), mUseMips(true), mIsHDRImage(false), mIsValidImage(false), mImageType(Albedo)
|
||||
{
|
||||
mImageFileName = StringTable->EmptyString();
|
||||
mImagePath = StringTable->EmptyString();
|
||||
mLoadedState = AssetErrCode::NotLoaded;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -145,6 +140,15 @@ ImageAsset::~ImageAsset()
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
void ImageAsset::consoleInit()
|
||||
{
|
||||
Parent::consoleInit();
|
||||
Con::addVariable("$Core::NoImageAssetFallback", TypeString, &smNoImageAssetFallback,
|
||||
"The assetId of the texture to display when the requested image asset is missing.\n"
|
||||
"@ingroup GFX\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ImageAsset::initPersistFields()
|
||||
|
|
@ -163,85 +167,52 @@ void ImageAsset::initPersistFields()
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
//Utility function to 'fill out' bindings and resources with a matching asset if one exists
|
||||
bool ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
|
||||
U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
|
||||
{
|
||||
AssetQuery query;
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't find any assets
|
||||
//If possible, see if we can run an in-place import and the get the asset from that
|
||||
#if TORQUE_DEBUG
|
||||
Con::warnf("ImageAsset::getAssetByFilename - Attempted to in-place import a image file(%s) that had no associated asset", fileName);
|
||||
#endif
|
||||
|
||||
AssetImporter* autoAssetImporter;
|
||||
if (!Sim::findObject("autoAssetImporter", autoAssetImporter))
|
||||
{
|
||||
autoAssetImporter = new AssetImporter();
|
||||
autoAssetImporter->registerObject("autoAssetImporter");
|
||||
}
|
||||
|
||||
StringTableEntry resultingAssetId = autoAssetImporter->autoImportFile(fileName);
|
||||
|
||||
if (resultingAssetId != StringTable->EmptyString())
|
||||
{
|
||||
imageAsset->setAssetId(resultingAssetId);
|
||||
|
||||
if (!imageAsset->isNull())
|
||||
return true;
|
||||
}
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
imageAsset->setAssetId(StringTable->insert("Core_Rendering:noImage"));
|
||||
imageAsset->setAssetId(ImageAsset::smNoImageAssetFallback);
|
||||
|
||||
if (!imageAsset->isNull())
|
||||
return true;
|
||||
if (imageAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("ImageAsset::getAssetByFilename - Finding of asset associated with file %s failed with no fallback asset", fileName);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
//That didn't work, so fail out
|
||||
return false;
|
||||
//handle noshape not being loaded itself
|
||||
if ((*imageAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
Con::warnf("ImageAsset::getAssetByFilename - Finding of associated with file %s failed, and fallback asset reported error of Bad File Reference.", fileName);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
Con::warnf("ImageAsset::getAssetByFilename - Finding of associated with file %s failed, utilizing fallback asset", fileName);
|
||||
|
||||
(*imageAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
imageAsset->setAssetId(query.mAssetList[0]);
|
||||
return true;
|
||||
return (*imageAsset)->mLoadedState;
|
||||
}
|
||||
}
|
||||
|
||||
StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
|
||||
{
|
||||
StringTableEntry imageAssetId = StringTable->EmptyString();
|
||||
if (fileName == StringTable->EmptyString())
|
||||
return StringTable->EmptyString();
|
||||
|
||||
StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback;
|
||||
|
||||
AssetQuery query;
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't find any assets
|
||||
//If possible, see if we can run an in-place import and the get the asset from that
|
||||
#if TORQUE_DEBUG
|
||||
Con::warnf("ImageAsset::getAssetByFilename - Attempted to in-place import a image file(%s) that had no associated asset", fileName);
|
||||
#endif
|
||||
|
||||
AssetImporter* autoAssetImporter;
|
||||
if (!Sim::findObject("autoAssetImporter", autoAssetImporter))
|
||||
{
|
||||
autoAssetImporter = new AssetImporter();
|
||||
autoAssetImporter->registerObject("autoAssetImporter");
|
||||
}
|
||||
|
||||
StringTableEntry resultingAssetId = autoAssetImporter->autoImportFile(fileName);
|
||||
|
||||
if (resultingAssetId != StringTable->EmptyString())
|
||||
{
|
||||
imageAssetId = resultingAssetId;
|
||||
return imageAssetId;
|
||||
}
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
imageAssetId = StringTable->insert("Core_Rendering:noImage");
|
||||
}
|
||||
else
|
||||
if (foundAssetcount != 0)
|
||||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
imageAssetId = query.mAssetList[0];
|
||||
|
|
@ -250,22 +221,37 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
|
|||
return imageAssetId;
|
||||
}
|
||||
|
||||
bool ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset)
|
||||
U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset)
|
||||
{
|
||||
(*imageAsset) = assetId;
|
||||
|
||||
if (!imageAsset->isNull())
|
||||
return true;
|
||||
if (imageAsset->notNull())
|
||||
{
|
||||
return (*imageAsset)->mLoadedState;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (imageAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("ImageAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
StringTableEntry noImageId = StringTable->insert("Core_Rendering:noMaterial");
|
||||
imageAsset->setAssetId(noImageId);
|
||||
//handle noshape not being loaded itself
|
||||
if ((*imageAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
Con::warnf("ImageAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference.", assetId);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
if (!imageAsset->isNull())
|
||||
return true;
|
||||
Con::warnf("ImageAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset", assetId);
|
||||
|
||||
return false;
|
||||
(*imageAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ImageAsset::copyTo(SimObject* object)
|
||||
{
|
||||
|
|
@ -275,32 +261,49 @@ void ImageAsset::copyTo(SimObject* object)
|
|||
|
||||
void ImageAsset::loadImage()
|
||||
{
|
||||
SAFE_DELETE(mImage);
|
||||
|
||||
if (mImagePath)
|
||||
{
|
||||
if (!Platform::isFile(mImagePath))
|
||||
if (!Torque::FS::IsFile(mImagePath))
|
||||
{
|
||||
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
|
||||
mLoadedState = BadFileReference;
|
||||
return;
|
||||
}
|
||||
|
||||
mImage.set(mImagePath, &GFXStaticTextureSRGBProfile, avar("%s() - mImage (line %d)", __FUNCTION__, __LINE__));
|
||||
mLoadedState = Ok;
|
||||
mIsValidImage = true;
|
||||
return;
|
||||
|
||||
if (mImage)
|
||||
//GFXTexHandle texture = getTexture(&GFXStaticTextureSRGBProfile);
|
||||
|
||||
//mTexture.set(mImagePath, &GFXStaticTextureSRGBProfile, avar("%s() - mImage (line %d)", __FUNCTION__, __LINE__));
|
||||
|
||||
/*if (texture.isValid())
|
||||
{
|
||||
mIsValidImage = true;
|
||||
|
||||
//mBitmap = texture.getBitmap();
|
||||
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
mChangeSignal.trigger();
|
||||
}
|
||||
mLoadedState = BadFileReference;
|
||||
|
||||
mIsValidImage = false;
|
||||
}
|
||||
|
||||
void ImageAsset::initializeAsset()
|
||||
{
|
||||
mImagePath = expandAssetFilePath(mImageFileName);
|
||||
if (mImageFileName == StringTable->insert("z.png"))
|
||||
{
|
||||
Con::printf("Loaded z");
|
||||
}
|
||||
|
||||
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
|
||||
|
||||
mImagePath = expandAssetFilePath(mImageFileName);
|
||||
loadImage();
|
||||
}
|
||||
|
||||
|
|
@ -311,6 +314,16 @@ void ImageAsset::onAssetRefresh()
|
|||
loadImage();
|
||||
}
|
||||
|
||||
void ImageAsset::_onResourceChanged(const Torque::Path& path)
|
||||
{
|
||||
if (path != Torque::Path(mImagePath))
|
||||
return;
|
||||
|
||||
refreshAsset();
|
||||
|
||||
loadImage();
|
||||
}
|
||||
|
||||
void ImageAsset::setImageFileName(const char* pScriptFile)
|
||||
{
|
||||
// Sanity!
|
||||
|
|
@ -320,24 +333,34 @@ void ImageAsset::setImageFileName(const char* pScriptFile)
|
|||
mImageFileName = StringTable->insert(pScriptFile);
|
||||
}
|
||||
|
||||
GFXTexHandle ImageAsset::getImage(GFXTextureProfile requestedProfile)
|
||||
const GBitmap& ImageAsset::getImage()
|
||||
{
|
||||
/*if (mResourceMap.contains(requestedProfile))
|
||||
return GBitmap(); //TODO fix this
|
||||
}
|
||||
|
||||
GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
|
||||
{
|
||||
if (mResourceMap.contains(requestedProfile))
|
||||
{
|
||||
mLoadedState = Ok;
|
||||
return mResourceMap.find(requestedProfile)->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
//If we don't have an existing map case to the requested format, we'll just create it and insert it in
|
||||
GFXTexHandle newImage;
|
||||
newImage.set(mImageFileName, &requestedProfile, avar("%s() - mImage (line %d)", __FUNCTION__, __LINE__));
|
||||
mResourceMap.insert(requestedProfile, newImage);
|
||||
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
|
||||
if (newTex)
|
||||
{
|
||||
mResourceMap.insert(requestedProfile, newTex);
|
||||
mLoadedState = Ok;
|
||||
return newTex;
|
||||
}
|
||||
else
|
||||
mLoadedState = BadFileReference;
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}*/
|
||||
|
||||
if (mImage.isValid())
|
||||
return mImage;
|
||||
//if (mTexture.isValid())
|
||||
// return mTexture;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -348,7 +371,17 @@ const char* ImageAsset::getImageInfo()
|
|||
{
|
||||
static const U32 bufSize = 2048;
|
||||
char* returnBuffer = Con::getReturnBuffer(bufSize);
|
||||
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[mImage.getFormat()], mImage.getHeight(), mImage.getWidth(), mImage.getDepth());
|
||||
|
||||
GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, &GFXStaticTextureSRGBProfile);
|
||||
if (newTex)
|
||||
{
|
||||
dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
|
||||
newTex = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
|
||||
}
|
||||
|
||||
return returnBuffer;
|
||||
}
|
||||
|
|
@ -384,6 +417,11 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
|
|||
|
||||
ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
|
||||
{
|
||||
if (dStrIsEmpty(name))
|
||||
{
|
||||
return (ImageTypes)Albedo;
|
||||
}
|
||||
|
||||
S32 ret = -1;
|
||||
for (S32 i = 0; i < ImageTypeCount; i++)
|
||||
{
|
||||
|
|
@ -414,6 +452,15 @@ DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
|
|||
return object->getImageInfo();
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const char* filePath), (""),
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided file path.\n"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return ImageAsset::getAssetIdByFilename(StringTable->insert(filePath));
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GuiInspectorTypeAssetId
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -435,11 +482,16 @@ void GuiInspectorTypeImageAssetPtr::consoleInit()
|
|||
|
||||
GuiControl* GuiInspectorTypeImageAssetPtr::constructEditControl()
|
||||
{
|
||||
if (mInspector->getInspectObject() == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// Create base filename edit controls
|
||||
GuiControl* retCtrl = Parent::constructEditControl();
|
||||
if (retCtrl == NULL)
|
||||
return retCtrl;
|
||||
|
||||
retCtrl->getRenderTooltipDelegate().bind(this, &GuiInspectorTypeImageAssetPtr::renderTooltip);
|
||||
|
||||
// Change filespec
|
||||
char szBuffer[512];
|
||||
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"ImageAsset\", \"AssetBrowser.changeAsset\", %s, %s);",
|
||||
|
|
@ -456,8 +508,8 @@ GuiControl* GuiInspectorTypeImageAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "ShapeEditorPlugin.openShapeAssetId(%d.getText());", retCtrl->getId());
|
||||
mImageEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mImageEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:GameTSCtrl_image";
|
||||
mImageEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mImageEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mImageEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
@ -496,6 +548,66 @@ bool GuiInspectorTypeImageAssetPtr::updateRects()
|
|||
return resized;
|
||||
}
|
||||
|
||||
bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const Point2I& cursorPos, const char* tipText)
|
||||
{
|
||||
if (!mAwake)
|
||||
return false;
|
||||
|
||||
GuiCanvas* root = getRoot();
|
||||
if (!root)
|
||||
return false;
|
||||
|
||||
AssetPtr<ImageAsset> imgAsset;
|
||||
U32 assetState = ImageAsset::getAssetById(getData(), &imgAsset);
|
||||
if (imgAsset == NULL || assetState == ImageAsset::Failed)
|
||||
return false;
|
||||
|
||||
StringTableEntry filename = imgAsset->getImagePath();
|
||||
if (!filename || !filename[0])
|
||||
return false;
|
||||
|
||||
GFXTexHandle texture(filename, &GFXStaticTextureSRGBProfile, avar("%s() - tooltip texture (line %d)", __FUNCTION__, __LINE__));
|
||||
if (texture.isNull())
|
||||
return false;
|
||||
|
||||
// Render image at a reasonable screen size while
|
||||
// keeping its aspect ratio...
|
||||
Point2I screensize = getRoot()->getWindowSize();
|
||||
Point2I offset = hoverPos;
|
||||
Point2I tipBounds;
|
||||
|
||||
U32 texWidth = texture.getWidth();
|
||||
U32 texHeight = texture.getHeight();
|
||||
F32 aspect = (F32)texHeight / (F32)texWidth;
|
||||
|
||||
const F32 newWidth = 150.0f;
|
||||
F32 newHeight = aspect * newWidth;
|
||||
|
||||
// Offset below cursor image
|
||||
offset.y += 20; // TODO: Attempt to fix?: root->getCursorExtent().y;
|
||||
tipBounds.x = newWidth;
|
||||
tipBounds.y = newHeight;
|
||||
|
||||
// Make sure all of the tooltip will be rendered width the app window,
|
||||
// 5 is given as a buffer against the edge
|
||||
if (screensize.x < offset.x + tipBounds.x + 5)
|
||||
offset.x = screensize.x - tipBounds.x - 5;
|
||||
if (screensize.y < offset.y + tipBounds.y + 5)
|
||||
offset.y = hoverPos.y - tipBounds.y - 5;
|
||||
|
||||
RectI oldClip = GFX->getClipRect();
|
||||
RectI rect(offset, tipBounds);
|
||||
GFX->setClipRect(rect);
|
||||
|
||||
GFXDrawUtil* drawer = GFX->getDrawUtil();
|
||||
drawer->clearBitmapModulation();
|
||||
GFX->getDrawUtil()->drawBitmapStretch(texture, rect);
|
||||
|
||||
GFX->setClipRect(oldClip);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInspectorTypeImageAssetId);
|
||||
|
||||
ConsoleDocClass(GuiInspectorTypeImageAssetId,
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef IMAGE_ASSET_H
|
||||
#define IMAGE_ASSET_H
|
||||
#pragma once
|
||||
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assets/assetBase.h"
|
||||
|
|
@ -45,7 +44,9 @@
|
|||
#include "gfx/bitmap/gBitmap.h"
|
||||
#include "gfx/gfxTextureHandle.h"
|
||||
|
||||
#include "gui/editor/guiInspectorTypes.h"
|
||||
#include "sim/netConnection.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class ImageAsset : public AssetBase
|
||||
|
|
@ -70,24 +71,33 @@ public:
|
|||
ImageTypeCount = 11
|
||||
};
|
||||
|
||||
static StringTableEntry smNoImageAssetFallback;
|
||||
|
||||
protected:
|
||||
StringTableEntry mImageFileName;
|
||||
StringTableEntry mImagePath;
|
||||
|
||||
GFXTexHandle mImage;
|
||||
|
||||
bool mIsValidImage;
|
||||
bool mUseMips;
|
||||
bool mIsHDRImage;
|
||||
|
||||
ImageTypes mImageType;
|
||||
|
||||
Map<GFXTextureProfile, GFXTexHandle> mResourceMap;
|
||||
HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
|
||||
|
||||
typedef Signal<void()> ImageAssetChanged;
|
||||
ImageAssetChanged mChangeSignal;
|
||||
|
||||
typedef Signal<void(S32 index)> ImageAssetArrayChanged;
|
||||
ImageAssetArrayChanged mChangeArraySignal;
|
||||
|
||||
public:
|
||||
ImageAsset();
|
||||
virtual ~ImageAsset();
|
||||
|
||||
/// Set up some global script interface stuff.
|
||||
static void consoleInit();
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
|
@ -95,32 +105,40 @@ public:
|
|||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(ImageAsset);
|
||||
|
||||
void setImageFileName(const char* pScriptFile);
|
||||
void _onResourceChanged(const Torque::Path& path);
|
||||
|
||||
ImageAssetChanged& getChangedSignal() { return mChangeSignal; }
|
||||
ImageAssetArrayChanged& getChangedArraySignal() { return mChangeArraySignal; }
|
||||
|
||||
void setImageFileName(StringTableEntry pScriptFile);
|
||||
inline StringTableEntry getImageFileName(void) const { return mImageFileName; };
|
||||
|
||||
inline StringTableEntry getImagePath(void) const { return mImagePath; };
|
||||
|
||||
bool isValid() { return mIsValidImage; }
|
||||
|
||||
GFXTexHandle getImage(GFXTextureProfile requestedProfile);
|
||||
const GBitmap& getImage();
|
||||
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
|
||||
|
||||
const char* getImageInfo();
|
||||
StringTableEntry getImageInfo();
|
||||
|
||||
static const char* getImageTypeNameFromType(ImageTypes type);
|
||||
static ImageTypes getImageTypeFromName(const char* name);
|
||||
static StringTableEntry getImageTypeNameFromType(ImageTypes type);
|
||||
static ImageTypes getImageTypeFromName(StringTableEntry name);
|
||||
|
||||
void setImageType(ImageTypes type) { mImageType = type; }
|
||||
ImageTypes getImageType() { return mImageType; }
|
||||
|
||||
static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
|
||||
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
|
||||
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
|
||||
static bool getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
|
||||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
|
||||
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void);
|
||||
virtual void onAssetRefresh(void);
|
||||
|
||||
static bool setImageFileName(void* obj, const char* index, const char* data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
|
||||
static const char* getImageFileName(void* obj, const char* data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
|
||||
static bool setImageFileName(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
|
||||
static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
|
||||
|
||||
void loadImage();
|
||||
};
|
||||
|
|
@ -131,89 +149,468 @@ DefineConsoleType(TypeImageAssetId, String)
|
|||
typedef ImageAsset::ImageTypes ImageAssetType;
|
||||
DefineEnumType(ImageAssetType);
|
||||
|
||||
class GuiInspectorTypeImageAssetPtr : public GuiInspectorTypeFileName
|
||||
{
|
||||
typedef GuiInspectorTypeFileName Parent;
|
||||
public:
|
||||
#pragma region Singular Asset Macros
|
||||
|
||||
GuiBitmapButtonCtrl* mImageEdButton;
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetPtr);
|
||||
static void consoleInit();
|
||||
|
||||
virtual GuiControl* constructEditControl();
|
||||
virtual bool updateRects();
|
||||
};
|
||||
|
||||
class GuiInspectorTypeImageAssetId : public GuiInspectorTypeImageAssetPtr
|
||||
{
|
||||
typedef GuiInspectorTypeImageAssetPtr Parent;
|
||||
public:
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetId);
|
||||
static void consoleInit();
|
||||
};
|
||||
|
||||
#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
|
||||
|
||||
#define initMapSlot(name) m##name##Filename = String::EmptyString; m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
|
||||
#define bindMapSlot(name) if (m##name##AssetId != String::EmptyString) m##name##Asset = m##name##AssetId;
|
||||
|
||||
#define scriptBindMapSlot(name, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), assetText(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
|
||||
|
||||
#define initMapArraySlot(name,id) m##name##Filename[id] = String::EmptyString; m##name##AssetId[id] = StringTable->EmptyString(); m##name##Asset[id] = NULL;
|
||||
#define bindMapArraySlot(name,id) if (m##name##AssetId[id] != String::EmptyString) m##name##Asset[id] = m##name##AssetId[id];
|
||||
#define scriptBindMapArraySlot(name, arraySize, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), arraySize, assetText(name, docs)); \
|
||||
addProtectedField(assetText(name,Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##AssetSlot, &defaultProtectedGetFn, arraySize, assetText(name,asset reference.));
|
||||
|
||||
#define DECLARE_TEXTUREMAP(className,name) protected: \
|
||||
FileName m##name##Filename;\
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<ImageAsset> m##name##Asset;\
|
||||
public: \
|
||||
const String& get##name() const { return m##name##Filename; }\
|
||||
void set##name(FileName _in) { m##name##Filename = _in; }\
|
||||
const AssetPtr<ImageAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(AssetPtr<ImageAsset>_in) { m##name##Asset = _in; }\
|
||||
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* mat = static_cast<className*>(obj);\
|
||||
mat->m##name##AssetId = StringTable->insert(data);\
|
||||
if (ImageAsset::getAssetById(mat->m##name##AssetId, &mat->m##name##Asset))\
|
||||
//Singular assets
|
||||
/// <Summary>
|
||||
/// Declares an image asset
|
||||
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
|
||||
/// </Summary>
|
||||
#define DECLARE_IMAGEASSET(className, name, changeFunc, profile) public: \
|
||||
GFXTexHandle m##name = NULL;\
|
||||
StringTableEntry m##name##Name; \
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<ImageAsset> m##name##Asset;\
|
||||
GFXTextureProfile* m##name##Profile = &profile;\
|
||||
public: \
|
||||
const StringTableEntry get##name##File() const { return m##name##Name; }\
|
||||
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
||||
const AssetPtr<ImageAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(const AssetPtr<ImageAsset> &_in) { m##name##Asset = _in;}\
|
||||
\
|
||||
bool _set##name(StringTableEntry _in)\
|
||||
{\
|
||||
if (mat->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
mat->m##name##Filename = StringTable->EmptyString();\
|
||||
return true;\
|
||||
}\
|
||||
return true;\
|
||||
}
|
||||
|
||||
#define GET_TEXTUREMAP(name) get##name()
|
||||
#define SET_TEXTUREMAP(name,_in) set##name(_in)
|
||||
#define GET_TEXTUREASSET(name) get##name##Asset()
|
||||
#define SET_TEXTUREASSET(name,_in) set##name##Asset(_in)
|
||||
|
||||
#define DECLARE_TEXTUREARRAY(className,name,max) FileName m##name##Filename[max];\
|
||||
StringTableEntry m##name##AssetId[max];\
|
||||
AssetPtr<ImageAsset> m##name##Asset[max];\
|
||||
static bool _set##name##AssetSlot(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* mat = static_cast<className*>(obj);\
|
||||
if (!index) return false;\
|
||||
U32 idx = dAtoi(index);\
|
||||
if (idx >= max)\
|
||||
return false;\
|
||||
mat->m##name##AssetId[idx] = StringTable->insert(data);\
|
||||
if (ImageAsset::getAssetById(mat->m##name##AssetId[idx], &mat->m##name##Asset[idx]))\
|
||||
{\
|
||||
if (mat->m##name##Asset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
if(m##name##AssetId != _in || m##name##Name != _in)\
|
||||
{\
|
||||
mat->m##name##Filename[idx] = StringTable->EmptyString();\
|
||||
if (m##name##Asset.notNull())\
|
||||
{\
|
||||
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
|
||||
}\
|
||||
if (_in == StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
m##name##Asset = NULL;\
|
||||
m##name.free();\
|
||||
m##name = NULL;\
|
||||
return true;\
|
||||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name = _in;\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
m##name##Asset = NULL;\
|
||||
m##name.free();\
|
||||
m##name = NULL;\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
if (AssetDatabase.isDeclaredAsset(_in))\
|
||||
{\
|
||||
m##name##AssetId = _in;\
|
||||
\
|
||||
U32 assetState = ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
\
|
||||
if (ImageAsset::Ok == assetState)\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(_in);\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##AssetId = assetId;\
|
||||
if (ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset) == ImageAsset::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##Name != StringTable->insert("texhandle"))\
|
||||
{\
|
||||
if (m##name##Asset.notNull())\
|
||||
{\
|
||||
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
|
||||
}\
|
||||
\
|
||||
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
m##name.free();\
|
||||
m##name = NULL;\
|
||||
}\
|
||||
\
|
||||
if(get##name() == StringTable->EmptyString())\
|
||||
return true;\
|
||||
\
|
||||
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != ImageAsset::Ok)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - image asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ImageAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||
return false; \
|
||||
}\
|
||||
else if (bool(m##name) == NULL)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - Couldn't load image \"%s\"", macroText(className), getName(), macroText(name), _in);\
|
||||
return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
return true;\
|
||||
\
|
||||
const StringTableEntry get##name() const\
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
|
||||
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
|
||||
else if (m##name##AssetId != StringTable->EmptyString())\
|
||||
return m##name##AssetId;\
|
||||
else if (m##name##Name != StringTable->EmptyString())\
|
||||
return StringTable->insert(Platform::makeRelativePathName(m##name##Name, Platform::getMainDotCsDir()));\
|
||||
else\
|
||||
return StringTable->EmptyString();\
|
||||
}\
|
||||
GFXTexHandle get##name##Resource() \
|
||||
{\
|
||||
return m##name;\
|
||||
}
|
||||
|
||||
#define DECLARE_IMAGEASSET_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_IMAGEASSET_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_IMAGEASSET_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, const char*, (), , "get name")\
|
||||
{\
|
||||
return object->get##name(); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, const char*, (), , assetText(name, asset reference))\
|
||||
{\
|
||||
return object->m##name##AssetId; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* map), , assetText(name,assignment. first tries asset then flat file.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(map));\
|
||||
}
|
||||
|
||||
#define INIT_IMAGEASSET(name) \
|
||||
m##name##Name = StringTable->EmptyString(); \
|
||||
m##name##AssetId = StringTable->EmptyString(); \
|
||||
m##name##Asset = NULL;
|
||||
|
||||
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
|
||||
|
||||
#else
|
||||
|
||||
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
|
||||
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
|
||||
|
||||
#endif // SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define CLONE_IMAGEASSET(name) \
|
||||
m##name##Name = other.m##name##Name;\
|
||||
m##name##AssetId = other.m##name##AssetId;\
|
||||
m##name##Asset = other.m##name##Asset;
|
||||
|
||||
#define LOAD_IMAGEASSET(name)\
|
||||
if (m##name##AssetId != StringTable->EmptyString())\
|
||||
{\
|
||||
S32 assetState = ImageAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
if (assetState == ImageAsset::Ok )\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
else Con::warnf("Warning: %s::LOAD_IMAGEASSET(%s)-%s", mClassName, m##name##AssetId, ImageAsset::getAssetErrstrn(assetState).c_str());\
|
||||
}
|
||||
|
||||
#define PACKDATA_IMAGEASSET(name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset.getAssetId());\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACKDATA_IMAGEASSET(name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = stream->readSTString();\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#define PACK_IMAGEASSET(netconn, name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
|
||||
netconn->packNetStringHandleU(stream, assetIdStr);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACK_IMAGEASSET(netconn, name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Arrayed Asset Macros
|
||||
|
||||
//Arrayed Assets
|
||||
#define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) public: \
|
||||
static const U32 sm##name##Count = max;\
|
||||
GFXTexHandle m##name[max];\
|
||||
StringTableEntry m##name##Name[max]; \
|
||||
StringTableEntry m##name##AssetId[max];\
|
||||
AssetPtr<ImageAsset> m##name##Asset[max];\
|
||||
GFXTextureProfile * m##name##Profile = &profile;\
|
||||
public: \
|
||||
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
|
||||
void set##name##File(const FileName &_in, const U32& index) { m##name##Name[index] = StringTable->insert(_in.c_str());}\
|
||||
const AssetPtr<ImageAsset> & get##name##Asset(const U32& index) const { return m##name##Asset[index]; }\
|
||||
void set##name##Asset(const AssetPtr<ImageAsset> &_in, const U32& index) { m##name##Asset[index] = _in;}\
|
||||
\
|
||||
bool _set##name(StringTableEntry _in, const U32& index)\
|
||||
{\
|
||||
if(m##name##AssetId[index] != _in || m##name##Name[index] != _in)\
|
||||
{\
|
||||
if(index >= sm##name##Count || index < 0)\
|
||||
return false;\
|
||||
if (_in == StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##Name[index] = StringTable->EmptyString();\
|
||||
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||
m##name##Asset[index] = NULL;\
|
||||
m##name[index].free();\
|
||||
m##name[index] = NULL;\
|
||||
return true;\
|
||||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name[index] = _in;\
|
||||
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||
m##name##Asset[index] = NULL;\
|
||||
m##name[index].free();\
|
||||
m##name[index] = NULL;\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
if (AssetDatabase.isDeclaredAsset(_in))\
|
||||
{\
|
||||
m##name##AssetId[index] = _in;\
|
||||
\
|
||||
U32 assetState = ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]);\
|
||||
\
|
||||
if (ImageAsset::Ok == assetState)\
|
||||
{\
|
||||
m##name##Name[index] = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
StringTableEntry assetId = ImageAsset::getAssetIdByFilename(_in);\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##AssetId[index] = assetId;\
|
||||
if (ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]) == ImageAsset::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##Name[index] != StringTable->insert("texhandle"))\
|
||||
{\
|
||||
m##name[index].set(get##name(index), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
m##name[index].free();\
|
||||
m##name[index] = NULL;\
|
||||
}\
|
||||
\
|
||||
if(get##name(index) == StringTable->EmptyString())\
|
||||
return true;\
|
||||
\
|
||||
if (m##name##Asset[index].notNull() && m##name##Asset[index]->getStatus() != ImageAsset::Ok)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s(%i) - image asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), index, _in, ImageAsset::getAssetErrstrn(m##name##Asset[index]->getStatus()).c_str());\
|
||||
return false; \
|
||||
}\
|
||||
else if (bool(m##name[index]) == NULL)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s(%i) - Couldn't load image \"%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]->getImageFileName() != StringTable->EmptyString()))\
|
||||
return Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
|
||||
else if (m##name##AssetId[index] != StringTable->EmptyString())\
|
||||
return m##name##AssetId[index];\
|
||||
else if (m##name##Name[index] != StringTable->EmptyString())\
|
||||
return StringTable->insert(Platform::makeRelativePathName(m##name##Name[index], Platform::getMainDotCsDir()));\
|
||||
else\
|
||||
return StringTable->EmptyString();\
|
||||
}\
|
||||
GFXTexHandle get##name##Resource(const U32& index) \
|
||||
{\
|
||||
if(index >= sm##name##Count || index < 0)\
|
||||
return nullptr;\
|
||||
return m##name[index];\
|
||||
}
|
||||
|
||||
#define DECLARE_IMAGEASSET_ARRAY_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
if (!index) return false;\
|
||||
U32 idx = dAtoi(index);\
|
||||
if (idx >= sm##name##Count)\
|
||||
return false;\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data),idx);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_IMAGEASSET_ARRAY_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
if (!index) return false;\
|
||||
U32 idx = dAtoi(index);\
|
||||
if (idx >= sm##name##Count)\
|
||||
return false;\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data),idx);\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_IMAGEASSET_ARRAY_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, const char*, (S32 index), , "get name")\
|
||||
{\
|
||||
return object->get##name(index); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, const char*, (S32 index), , assetText(name, asset reference))\
|
||||
{\
|
||||
if(index >= className::sm##name##Count || index < 0)\
|
||||
return "";\
|
||||
return object->m##name##AssetId[index]; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* map, S32 index), , assetText(name,assignment. first tries asset then flat file.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(map), index);\
|
||||
}
|
||||
|
||||
#define INIT_IMAGEASSET_ARRAY(name, index) \
|
||||
{\
|
||||
m##name##Name[index] = StringTable->EmptyString(); \
|
||||
m##name##AssetId[index] = StringTable->EmptyString(); \
|
||||
m##name##Asset[index] = NULL;\
|
||||
}
|
||||
|
||||
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
|
||||
|
||||
#else
|
||||
|
||||
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeImageFilename, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
|
||||
addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
|
||||
|
||||
#endif
|
||||
|
||||
#define CLONE_IMAGEASSET_ARRAY(name, index) \
|
||||
{\
|
||||
m##name##Name[index] = other.m##name##Name[index];\
|
||||
m##name##AssetId[index] = other.m##name##AssetId[index];\
|
||||
m##name##Asset[index] = other.m##name##Asset[index];\
|
||||
}
|
||||
|
||||
#define LOAD_IMAGEASSET_ARRAY(name, index)\
|
||||
if (m##name##AssetId[index] != StringTable->EmptyString())\
|
||||
{\
|
||||
S32 assetState = ImageAsset::getAssetById(m##name##AssetId[index], &m##name##Asset[index]);\
|
||||
if (assetState == ImageAsset::Ok )\
|
||||
{\
|
||||
m##name##Name[index] = StringTable->EmptyString();\
|
||||
}\
|
||||
else Con::warnf("Warning: %s::LOAD_IMAGEASSET(%s)-%s", mClassName, m##name##AssetId[index], ImageAsset::getAssetErrstrn(assetState).c_str());\
|
||||
}
|
||||
|
||||
#define PACKDATA_IMAGEASSET_ARRAY(name, index)\
|
||||
if (stream->writeFlag(m##name##Asset[index].notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset[index].getAssetId());\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name[index]);
|
||||
|
||||
#define UNPACKDATA_IMAGEASSET_ARRAY(name, index)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId[index] = stream->readSTString();\
|
||||
_set##name(m##name##AssetId[index], index);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name[index] = stream->readSTString();
|
||||
|
||||
#define PACK_IMAGEASSET_ARRAY(netconn, name, index)\
|
||||
if (stream->writeFlag(m##name##Asset[index].notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset[index].getAssetId();\
|
||||
netconn->packNetStringHandleU(stream, assetIdStr);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name[index]);
|
||||
|
||||
#define UNPACK_IMAGEASSET_ARRAY(netconn, name, index)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId[index] = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
_set##name(m##name##AssetId[index], index);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name[index] = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
|
||||
|
|
|
|||
31
Engine/source/T3D/assets/ImageAssetInspectors.h
Normal file
31
Engine/source/T3D/assets/ImageAssetInspectors.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "ImageAsset.h"
|
||||
|
||||
#ifndef _GUI_INSPECTOR_TYPES_H_
|
||||
#include "gui/editor/guiInspectorTypes.h"
|
||||
#endif
|
||||
|
||||
class GuiInspectorTypeImageAssetPtr : public GuiInspectorTypeFileName
|
||||
{
|
||||
typedef GuiInspectorTypeFileName Parent;
|
||||
public:
|
||||
|
||||
GuiBitmapButtonCtrl* mImageEdButton;
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetPtr);
|
||||
static void consoleInit();
|
||||
|
||||
virtual GuiControl* constructEditControl();
|
||||
virtual bool updateRects();
|
||||
bool renderTooltip(const Point2I& hoverPos, const Point2I& cursorPos, const char* tipText = NULL);
|
||||
};
|
||||
|
||||
class GuiInspectorTypeImageAssetId : public GuiInspectorTypeImageAssetPtr
|
||||
{
|
||||
typedef GuiInspectorTypeImageAssetPtr Parent;
|
||||
public:
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetId);
|
||||
static void consoleInit();
|
||||
};
|
||||
|
|
@ -47,14 +47,14 @@
|
|||
|
||||
IMPLEMENT_CONOBJECT(LevelAsset);
|
||||
|
||||
ConsoleType(LevelAssetPtr, TypeLevelAssetPtr, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(LevelAssetPtr, TypeLevelAssetPtr, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType(TypeLevelAssetPtr)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return *((StringTableEntry*)dptr);
|
||||
return *((const char**)(dptr));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -65,13 +65,7 @@ ConsoleSetType(TypeLevelAssetPtr)
|
|||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -86,14 +80,12 @@ LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false)
|
|||
{
|
||||
mLevelName = StringTable->EmptyString();
|
||||
mLevelFile = StringTable->EmptyString();
|
||||
mPreviewImage = StringTable->EmptyString();
|
||||
mPostFXPresetFile = StringTable->EmptyString();
|
||||
mDecalsFile = StringTable->EmptyString();
|
||||
mForestFile = StringTable->EmptyString();
|
||||
mNavmeshFile = StringTable->EmptyString();
|
||||
|
||||
mLevelPath = StringTable->EmptyString();
|
||||
mPreviewImagePath = StringTable->EmptyString();
|
||||
mPostFXPresetPath = StringTable->EmptyString();
|
||||
mDecalsPath = StringTable->EmptyString();
|
||||
mForestPath = StringTable->EmptyString();
|
||||
|
|
@ -104,6 +96,9 @@ LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false)
|
|||
|
||||
mEditorFile = StringTable->EmptyString();
|
||||
mBakedSceneFile = StringTable->EmptyString();
|
||||
|
||||
mPreviewImageAssetId = StringTable->EmptyString();
|
||||
mPreviewImageAsset = StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -122,8 +117,6 @@ void LevelAsset::initPersistFields()
|
|||
addProtectedField("LevelFile", TypeAssetLooseFilePath, Offset(mLevelFile, LevelAsset),
|
||||
&setLevelFile, &getLevelFile, "Path to the actual level file.");
|
||||
addField("LevelName", TypeString, Offset(mLevelName, LevelAsset), "Human-friendly name for the level.");
|
||||
addProtectedField("PreviewImage", TypeAssetLooseFilePath, Offset(mPreviewImage, LevelAsset),
|
||||
&setPreviewImageFile, &getPreviewImageFile, "Path to the image used for selection preview.");
|
||||
|
||||
addProtectedField("PostFXPresetFile", TypeAssetLooseFilePath, Offset(mPostFXPresetFile, LevelAsset),
|
||||
&setPostFXPresetFile, &getPostFXPresetFile, "Path to the level's postFXPreset.");
|
||||
|
|
@ -157,24 +150,32 @@ void LevelAsset::initializeAsset()
|
|||
// Call parent.
|
||||
Parent::initializeAsset();
|
||||
|
||||
// Ensure the image-file is expanded.
|
||||
mPreviewImagePath = expandAssetFilePath(mPreviewImage);
|
||||
mLevelPath = expandAssetFilePath(mLevelFile);
|
||||
mPostFXPresetPath = expandAssetFilePath(mPostFXPresetFile);
|
||||
mDecalsPath = expandAssetFilePath(mDecalsFile);
|
||||
mForestPath = expandAssetFilePath(mForestFile);
|
||||
mNavmeshPath = expandAssetFilePath(mNavmeshFile);
|
||||
loadAsset();
|
||||
}
|
||||
|
||||
void LevelAsset::onAssetRefresh(void)
|
||||
{
|
||||
loadAsset();
|
||||
}
|
||||
|
||||
void LevelAsset::loadAsset()
|
||||
{
|
||||
// Ensure the image-file is expanded.
|
||||
mPreviewImagePath = expandAssetFilePath(mPreviewImage);
|
||||
mLevelPath = expandAssetFilePath(mLevelFile);
|
||||
mPostFXPresetPath = expandAssetFilePath(mPostFXPresetFile);
|
||||
mDecalsPath = expandAssetFilePath(mDecalsFile);
|
||||
mForestPath = expandAssetFilePath(mForestFile);
|
||||
mNavmeshPath = expandAssetFilePath(mNavmeshFile);
|
||||
|
||||
StringTableEntry previewImageAssetId = getAssetDependencyField("previewImageAsset");
|
||||
|
||||
if (previewImageAssetId != StringTable->EmptyString())
|
||||
{
|
||||
mPreviewImageAssetId = previewImageAssetId;
|
||||
|
||||
AssetPtr<ImageAsset> previewImgAsset = mPreviewImageAssetId;
|
||||
mPreviewImageAsset = previewImgAsset;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -197,23 +198,19 @@ void LevelAsset::setLevelFile(const char* pLevelFile)
|
|||
refreshAsset();
|
||||
}
|
||||
|
||||
void LevelAsset::setImageFile(const char* pImageFile)
|
||||
StringTableEntry LevelAsset::getPreviewImageAsset() const
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
|
||||
return mPreviewImageAssetId;
|
||||
}
|
||||
|
||||
// Fetch image file.
|
||||
pImageFile = StringTable->insert(pImageFile);
|
||||
StringTableEntry LevelAsset::getPreviewImagePath(void) const
|
||||
{
|
||||
if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid())
|
||||
{
|
||||
return mPreviewImageAsset->getImagePath();
|
||||
}
|
||||
|
||||
// Ignore no change,
|
||||
if (pImageFile == mPreviewImage)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mPreviewImage = pImageFile;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
void LevelAsset::setEditorFile(const char* pEditorFile)
|
||||
|
|
@ -368,11 +365,18 @@ DefineEngineMethod(LevelAsset, getLevelPath, const char*, (),,
|
|||
return object->getLevelPath();
|
||||
}
|
||||
|
||||
DefineEngineMethod(LevelAsset, getPreviewImageAsset, const char*, (), ,
|
||||
"Gets the full path of the asset's defined preview image file.\n"
|
||||
"@return The string result of the level preview image path")
|
||||
{
|
||||
return object->getPreviewImageAsset();
|
||||
}
|
||||
|
||||
DefineEngineMethod(LevelAsset, getPreviewImagePath, const char*, (), ,
|
||||
"Gets the full path of the asset's defined preview image file.\n"
|
||||
"@return The string result of the level preview image path")
|
||||
{
|
||||
return object->getImagePath();
|
||||
return object->getPreviewImagePath();
|
||||
}
|
||||
|
||||
DefineEngineMethod(LevelAsset, getPostFXPresetPath, const char*, (), ,
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
#include "T3D/assets/ImageAsset.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class LevelAsset : public AssetBase
|
||||
|
|
@ -50,14 +51,12 @@ class LevelAsset : public AssetBase
|
|||
StringTableEntry mDecalsFile;
|
||||
StringTableEntry mForestFile;
|
||||
StringTableEntry mNavmeshFile;
|
||||
StringTableEntry mPreviewImage;
|
||||
|
||||
StringTableEntry mLevelPath;
|
||||
StringTableEntry mPostFXPresetPath;
|
||||
StringTableEntry mDecalsPath;
|
||||
StringTableEntry mForestPath;
|
||||
StringTableEntry mNavmeshPath;
|
||||
StringTableEntry mPreviewImagePath;
|
||||
|
||||
StringTableEntry mEditorFile;
|
||||
StringTableEntry mBakedSceneFile;
|
||||
|
|
@ -69,6 +68,9 @@ class LevelAsset : public AssetBase
|
|||
|
||||
Vector<AssetBase*> mAssetDependencies;
|
||||
|
||||
StringTableEntry mPreviewImageAssetId;
|
||||
AssetPtr<ImageAsset> mPreviewImageAsset;
|
||||
|
||||
public:
|
||||
LevelAsset();
|
||||
virtual ~LevelAsset();
|
||||
|
|
@ -93,15 +95,16 @@ public:
|
|||
inline StringTableEntry getForestFile(void) const { return mForestFile; };
|
||||
void setNavmeshFile(const char* pNavmeshFile);
|
||||
inline StringTableEntry getNavmeshFile(void) const { return mNavmeshFile; };
|
||||
void setImageFile(const char* pImageFile);
|
||||
inline StringTableEntry getImageFile(void) const { return mPreviewImage; };
|
||||
|
||||
StringTableEntry getPreviewImageAsset(void) const;
|
||||
|
||||
inline StringTableEntry getLevelPath(void) const { return mLevelPath; };
|
||||
inline StringTableEntry getPostFXPresetPath(void) const { return mPostFXPresetPath; };
|
||||
inline StringTableEntry getDecalsPath(void) const { return mDecalsPath; };
|
||||
inline StringTableEntry getForestPath(void) const { return mForestPath; };
|
||||
inline StringTableEntry getNavmeshPath(void) const { return mNavmeshPath; };
|
||||
inline StringTableEntry getImagePath(void) const { return mPreviewImagePath; };
|
||||
|
||||
StringTableEntry getPreviewImagePath(void) const;
|
||||
|
||||
void setEditorFile(const char* pEditorFile);
|
||||
inline StringTableEntry getEditorFile(void) const { return mEditorFile; };
|
||||
|
|
@ -113,8 +116,6 @@ public:
|
|||
protected:
|
||||
static bool setLevelFile(void *obj, const char *index, const char *data) { static_cast<LevelAsset*>(obj)->setLevelFile(data); return false; }
|
||||
static const char* getLevelFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getLevelFile(); }
|
||||
static bool setPreviewImageFile(void *obj, const char *index, const char *data) { static_cast<LevelAsset*>(obj)->setImageFile(data); return false; }
|
||||
static const char* getPreviewImageFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getImageFile(); }
|
||||
|
||||
static bool setEditorFile(void* obj, const char* index, const char* data) { static_cast<LevelAsset*>(obj)->setEditorFile(data); return false; }
|
||||
static const char* getEditorFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getEditorFile(); }
|
||||
|
|
@ -134,6 +135,7 @@ protected:
|
|||
|
||||
virtual void initializeAsset(void);
|
||||
virtual void onAssetRefresh(void);
|
||||
void loadAsset();
|
||||
};
|
||||
|
||||
DefineConsoleType(TypeLevelAssetPtr, LevelAsset)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
|
||||
#include "T3D/assets/assetImporter.h"
|
||||
|
||||
StringTableEntry MaterialAsset::smNoMaterialAssetFallback(StringTable->insert(Con::getVariable("$Core::NoMaterialAssetFallback")));
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(MaterialAsset);
|
||||
|
|
@ -89,7 +91,7 @@ ConsoleSetType(TypeMaterialAssetPtr)
|
|||
}
|
||||
|
||||
|
||||
ConsoleType(assetIdString, TypeMaterialAssetId, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(assetIdString, TypeMaterialAssetId, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
ConsoleGetType(TypeMaterialAssetId)
|
||||
{
|
||||
|
|
@ -125,16 +127,26 @@ MaterialAsset::MaterialAsset()
|
|||
mScriptFile = StringTable->EmptyString();
|
||||
mScriptPath = StringTable->EmptyString();
|
||||
mMatDefinitionName = StringTable->EmptyString();
|
||||
mMaterialDefinition = nullptr;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
MaterialAsset::~MaterialAsset()
|
||||
{
|
||||
//SAFE_DELETE(mMaterialDefinition);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void MaterialAsset::consoleInit()
|
||||
{
|
||||
Parent::consoleInit();
|
||||
Con::addVariable("$Core::NoMaterialAssetFallback", TypeString, &smNoMaterialAssetFallback,
|
||||
"The assetId of the material to display when the requested material asset is missing.\n"
|
||||
"@ingroup GFX\n");
|
||||
}
|
||||
|
||||
void MaterialAsset::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
|
|
@ -152,32 +164,22 @@ void MaterialAsset::initializeAsset()
|
|||
// Call parent.
|
||||
Parent::initializeAsset();
|
||||
|
||||
compileShader();
|
||||
|
||||
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
|
||||
loadMaterial();
|
||||
}
|
||||
|
||||
void MaterialAsset::onAssetRefresh()
|
||||
{
|
||||
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath;
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
|
||||
if (mMatDefinitionName != StringTable->EmptyString())
|
||||
{
|
||||
Material* matDef;
|
||||
if (!Sim::findObject(mMatDefinitionName, matDef))
|
||||
{
|
||||
Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName);
|
||||
return;
|
||||
}
|
||||
|
||||
matDef->reload();
|
||||
}
|
||||
loadMaterial();
|
||||
}
|
||||
|
||||
void MaterialAsset::setScriptFile(const char* pScriptFile)
|
||||
|
|
@ -197,142 +199,162 @@ void MaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MaterialAsset::compileShader()
|
||||
void MaterialAsset::loadMaterial()
|
||||
{
|
||||
if (mMaterialDefinition)
|
||||
SAFE_DELETE(mMaterialDefinition);
|
||||
|
||||
if (mMatDefinitionName != StringTable->EmptyString())
|
||||
{
|
||||
Material* matDef;
|
||||
if (!Sim::findObject(mMatDefinitionName, matDef))
|
||||
{
|
||||
Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName);
|
||||
mLoadedState = BadFileReference;
|
||||
return;
|
||||
}
|
||||
|
||||
mMaterialDefinition = matDef;
|
||||
|
||||
mLoadedState = Ok;
|
||||
|
||||
mMaterialDefinition->reload();
|
||||
return;
|
||||
}
|
||||
|
||||
mLoadedState = Failed;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void MaterialAsset::copyTo(SimObject* object)
|
||||
{
|
||||
// Call to parent.
|
||||
Parent::copyTo(object);
|
||||
}
|
||||
|
||||
DefineEngineMethod(MaterialAsset, compileShader, void, (), , "Compiles the material's generated shader, if any. Not yet implemented\n")
|
||||
{
|
||||
object->compileShader();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
StringTableEntry MaterialAsset::getAssetIdByMaterialName(StringTableEntry matName)
|
||||
U32 MaterialAsset::getAssetByMaterialName(StringTableEntry matName, AssetPtr<MaterialAsset>* matAsset)
|
||||
{
|
||||
StringTableEntry materialAssetId = StringTable->EmptyString();
|
||||
|
||||
AssetQuery* query = new AssetQuery();
|
||||
U32 foundCount = AssetDatabase.findAssetType(query, "MaterialAsset");
|
||||
if (foundCount == 0)
|
||||
AssetQuery query;
|
||||
U32 foundAssetcount = AssetDatabase.findAssetType(&query, "MaterialAsset");
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
materialAssetId = StringTable->insert("Core_Rendering:noMaterial");
|
||||
matAsset->setAssetId(MaterialAsset::smNoMaterialAssetFallback);
|
||||
|
||||
if (matAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("MaterialAsset::getAssetByMaterialName - Finding of asset associated with material name %s failed with no fallback asset", matName);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
//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);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
Con::warnf("ShapeAsset::getAssetByMaterialName - Finding of associated with aterial name %s failed, utilizing fallback asset", matName);
|
||||
|
||||
(*matAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (U32 i = 0; i < foundAssetcount; i++)
|
||||
{
|
||||
MaterialAsset* tMatAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]);
|
||||
if (tMatAsset && tMatAsset->getMaterialDefinitionName() == matName)
|
||||
{
|
||||
matAsset->setAssetId(query.mAssetList[i]);
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
return (*matAsset)->mLoadedState;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]); //cleanup if that's not the one we needed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringTableEntry MaterialAsset::getAssetIdByMaterialName(StringTableEntry matName)
|
||||
{
|
||||
if (matName == StringTable->EmptyString())
|
||||
return StringTable->EmptyString();
|
||||
|
||||
StringTableEntry materialAssetId = MaterialAsset::smNoMaterialAssetFallback;
|
||||
|
||||
AssetQuery query;
|
||||
U32 foundCount = AssetDatabase.findAssetType(&query, "MaterialAsset");
|
||||
if (foundCount != 0)
|
||||
{
|
||||
for (U32 i = 0; i < foundCount; i++)
|
||||
{
|
||||
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(query->mAssetList[i]);
|
||||
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(query.mAssetList[i]);
|
||||
if (matAsset && matAsset->getMaterialDefinitionName() == matName)
|
||||
{
|
||||
materialAssetId = matAsset->getAssetId();
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
break;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query->mAssetList[i]); //cleanup if that's not the one we needed
|
||||
}
|
||||
|
||||
if (materialAssetId == StringTable->EmptyString())
|
||||
{
|
||||
//Try auto-importing it if it exists already
|
||||
BaseMaterialDefinition* baseMatDef;
|
||||
if (!Sim::findObject(matName, baseMatDef))
|
||||
{
|
||||
//Not even a real material, apparently?
|
||||
//return back a blank
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//Ok, a real mat def, we can work with this
|
||||
#if TORQUE_DEBUG
|
||||
Con::warnf("MaterialAsset::getAssetIdByMaterialName - Attempted to in-place import a material(%s) that had no associated asset", matName);
|
||||
#endif
|
||||
|
||||
AssetImporter* autoAssetImporter;
|
||||
if (!Sim::findObject("autoAssetImporter", autoAssetImporter))
|
||||
{
|
||||
autoAssetImporter = new AssetImporter();
|
||||
autoAssetImporter->registerObject("autoAssetImporter");
|
||||
}
|
||||
|
||||
autoAssetImporter->resetImportSession(true);
|
||||
|
||||
String originalMaterialDefFile = Torque::Path(baseMatDef->getFilename()).getPath();
|
||||
|
||||
autoAssetImporter->setTargetPath(originalMaterialDefFile);
|
||||
|
||||
autoAssetImporter->resetImportConfig();
|
||||
|
||||
AssetImportObject* assetObj = autoAssetImporter->addImportingAsset("MaterialAsset", originalMaterialDefFile, nullptr, matName);
|
||||
|
||||
//Find out if the filepath has an associated module to it. If we're importing in-place, it needs to be within a module's directory
|
||||
ModuleDefinition* targetModuleDef = AssetImporter::getModuleFromPath(originalMaterialDefFile);
|
||||
|
||||
if (targetModuleDef == nullptr)
|
||||
{
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
else
|
||||
{
|
||||
autoAssetImporter->setTargetModuleId(targetModuleDef->getModuleId());
|
||||
}
|
||||
|
||||
autoAssetImporter->processImportAssets();
|
||||
|
||||
bool hasIssues = autoAssetImporter->validateAssets();
|
||||
|
||||
if (hasIssues)
|
||||
{
|
||||
//log it
|
||||
Con::errorf("Error! Import process of Material(%s) has failed due to issues discovered during validation!", matName);
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
else
|
||||
{
|
||||
autoAssetImporter->importAssets();
|
||||
}
|
||||
|
||||
#if TORQUE_DEBUG
|
||||
autoAssetImporter->dumpActivityLog();
|
||||
#endif
|
||||
|
||||
if (hasIssues)
|
||||
{
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
else
|
||||
{
|
||||
String assetId = autoAssetImporter->getTargetModuleId() + ":" + assetObj->assetName;
|
||||
return StringTable->insert(assetId.c_str());
|
||||
}
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return materialAssetId;
|
||||
}
|
||||
|
||||
bool MaterialAsset::getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset>* materialAsset)
|
||||
U32 MaterialAsset::getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset>* materialAsset)
|
||||
{
|
||||
(*materialAsset) = assetId;
|
||||
|
||||
if (!materialAsset->isNull())
|
||||
return true;
|
||||
if (materialAsset->notNull())
|
||||
{
|
||||
return (*materialAsset)->mLoadedState;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
materialAsset->setAssetId(MaterialAsset::smNoMaterialAssetFallback);
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
StringTableEntry noImageId = StringTable->insert("Core_Rendering:noMaterial");
|
||||
materialAsset->setAssetId(noImageId);
|
||||
if (materialAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("MaterialAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
if (!materialAsset->isNull())
|
||||
return true;
|
||||
//handle noshape not being loaded itself
|
||||
if ((*materialAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
Con::warnf("MaterialAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference.", assetId);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
return false;
|
||||
Con::warnf("MaterialAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset", assetId);
|
||||
|
||||
(*materialAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
}
|
||||
|
||||
#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"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return MaterialAsset::getAssetIdByMaterialName(StringTable->insert(materialName));
|
||||
}
|
||||
|
||||
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.")
|
||||
{
|
||||
return object->getScriptPath();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GuiInspectorTypeAssetId
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -373,13 +395,13 @@ GuiControl* GuiInspectorTypeMaterialAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.editAsset(%d.getText());", retCtrl->getId());
|
||||
mEditButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/material-editor";
|
||||
mEditButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:material_editor_n_image";
|
||||
mEditButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
mEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
|
||||
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Material Editor");
|
||||
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this asset in the Material Editor");
|
||||
|
||||
mEditButton->registerObject();
|
||||
addObject(mEditButton);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
#include "materials/matTextureTarget.h"
|
||||
#include "materials/materialDefinition.h"
|
||||
#include "materials/customMaterialDefinition.h"
|
||||
#include "materials/materialManager.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class MaterialAsset : public AssetBase
|
||||
|
|
@ -64,25 +65,42 @@ class MaterialAsset : public AssetBase
|
|||
StringTableEntry mScriptPath;
|
||||
StringTableEntry mMatDefinitionName;
|
||||
|
||||
SimObjectPtr<Material> mMaterialDefinition;
|
||||
|
||||
public:
|
||||
static StringTableEntry smNoMaterialAssetFallback;
|
||||
|
||||
public:
|
||||
MaterialAsset();
|
||||
virtual ~MaterialAsset();
|
||||
|
||||
/// Set up some global script interface stuff.
|
||||
static void consoleInit();
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
void compileShader();
|
||||
void loadMaterial();
|
||||
|
||||
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
|
||||
SimObjectPtr<Material> getMaterialDefinition() { return mMaterialDefinition; }
|
||||
|
||||
void setScriptFile(const char* pScriptFile);
|
||||
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
|
||||
|
||||
inline StringTableEntry getScriptPath(void) const { return mScriptPath; };
|
||||
|
||||
static StringTableEntry getAssetIdByMaterialName(StringTableEntry fileName);
|
||||
static bool getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset>* materialAsset);
|
||||
/// <summary>
|
||||
/// Looks for any assets that uses the provided Material Definition name.
|
||||
/// If none are found, attempts to auto-import the material definition if the
|
||||
/// material definition exists.
|
||||
/// </summary>
|
||||
/// <param name="matName">Material Definition name to look for</param>
|
||||
/// <returns>AssetId of matching asset.</returns>
|
||||
static StringTableEntry getAssetIdByMaterialName(StringTableEntry matName);
|
||||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset>* materialAsset);
|
||||
static U32 getAssetByMaterialName(StringTableEntry matName, AssetPtr<MaterialAsset>* matAsset);
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(MaterialAsset);
|
||||
|
|
@ -124,159 +142,203 @@ public:
|
|||
static void consoleInit();
|
||||
};
|
||||
|
||||
#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
|
||||
#pragma region Singular Asset Macros
|
||||
|
||||
#define initMaterialAsset(name) m##name##Name = ""; m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
|
||||
#define bindMaterialAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId;
|
||||
|
||||
#define scriptBindMaterialAsset(name, consoleClass, docs)\
|
||||
addProtectedField(assetText(name, File), TypeMaterialName, Offset(m##name##Name, consoleClass), consoleClass::_set##name##Name, & defaultProtectedGetFn, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
|
||||
addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
|
||||
|
||||
#define DECLARE_MATERIALASSET(className,name) protected: \
|
||||
String m##name##Name;\
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<MaterialAsset> m##name##Asset;\
|
||||
public: \
|
||||
const String& get##name() const { return m##name##Name; }\
|
||||
void set##name(FileName _in) { m##name##Name = _in; }\
|
||||
const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(AssetPtr<MaterialAsset>_in) { m##name##Asset = _in; }\
|
||||
static bool _set##name##Name(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
//Singular assets
|
||||
/// <Summary>
|
||||
/// Declares an material asset
|
||||
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
|
||||
/// </Summary>
|
||||
#define DECLARE_MATERIALASSET(className, name) public: \
|
||||
StringTableEntry m##name##Name;\
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<MaterialAsset> m##name##Asset;\
|
||||
SimObjectPtr<Material> m##name;\
|
||||
public: \
|
||||
const StringTableEntry get##name##File() const { return m##name##Name; }\
|
||||
void set##name##Name(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
||||
const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(const AssetPtr<MaterialAsset> &_in) { m##name##Asset = _in;}\
|
||||
\
|
||||
StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(data));\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
bool _set##name(StringTableEntry _in)\
|
||||
{\
|
||||
if (shape->_set##name##Asset(obj, index, assetId))\
|
||||
if(m##name##AssetId != _in || m##name##Name != _in)\
|
||||
{\
|
||||
if (assetId == StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
if (_in == StringTable->EmptyString())\
|
||||
{\
|
||||
shape->m##name##Name = data;\
|
||||
shape->m##name##AssetId = 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 = MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
\
|
||||
if (MaterialAsset::Ok == assetState)\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
shape->m##name##AssetId = assetId;\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
\
|
||||
return false;\
|
||||
StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(_in);\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##AssetId = assetId;\
|
||||
if (MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset) == MaterialAsset::Ok)\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
m##name##Name = _in;\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
m##name##Asset = NULL;\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
shape->m##name##Asset = StringTable->EmptyString();\
|
||||
}\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
shape->m##name##AssetId = StringTable->insert(data);\
|
||||
if (MaterialAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
|
||||
{\
|
||||
if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
return false;\
|
||||
}\
|
||||
\
|
||||
static bool set##name##Asset(const char* assetId)\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(assetId);\
|
||||
if (m##name##AssetId != StringTable->EmptyString())\
|
||||
m##name##Asset = m##name##AssetId;\
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DECLARE_MATERIALASSET is a utility macro for MaterialAssets. It takes in the name of the class using it, the name of the field for the material, and a networking bitmask
|
||||
/// The first 2 are for setting up/filling out the fields and class member defines
|
||||
/// The bitmask is for when the material is changed, it can automatically kick a network update on the owner object to pass the changed asset to clients
|
||||
/// </summary>
|
||||
#define DECLARE_NET_MATERIALASSET(className,name,bitmask) protected: \
|
||||
String m##name##Name;\
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<MaterialAsset> m##name##Asset;\
|
||||
public: \
|
||||
const String& get##name() const { return m##name##Name; }\
|
||||
void set##name(FileName _in) { m##name##Name = _in; }\
|
||||
const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(AssetPtr<MaterialAsset>_in) { m##name##Asset = _in; }\
|
||||
static bool _set##name##Name(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
\
|
||||
StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(data));\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
if (shape->_set##name##Asset(obj, index, assetId))\
|
||||
if (get##name() != StringTable->EmptyString() && m##name##Asset.notNull())\
|
||||
{\
|
||||
if (assetId == StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
{\
|
||||
shape->m##name##Name = data;\
|
||||
shape->m##name##AssetId = StringTable->EmptyString();\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
shape->m##name##AssetId = assetId;\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
\
|
||||
if (m##name && String(m##name##Asset->getMaterialDefinitionName()).equal(m##name->getName(), String::NoCase))\
|
||||
return false;\
|
||||
}\
|
||||
\
|
||||
Material* tempMat = nullptr;\
|
||||
\
|
||||
if (!Sim::findObject(m##name##Asset->getMaterialDefinitionName(), tempMat))\
|
||||
Con::errorf("%s::_set%s() - Material %s was not found.", macroText(className), macroText(name), m##name##Asset->getMaterialDefinitionName());\
|
||||
m##name = tempMat;\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
m##name = NULL;\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
shape->m##name##Asset = StringTable->EmptyString();\
|
||||
}\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
shape->m##name##AssetId = StringTable->insert(data);\
|
||||
if (MaterialAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
|
||||
{\
|
||||
if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
\
|
||||
shape->setMaskBits(bitmask);\
|
||||
shape->inspectPostApply();\
|
||||
return true;\
|
||||
}\
|
||||
shape->inspectPostApply();\
|
||||
return false;\
|
||||
}\
|
||||
\
|
||||
bool set##name##AssetId(const char* _assetId)\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(_assetId);\
|
||||
if (m##name##AssetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##Asset = m##name##AssetId;\
|
||||
if(get##name() == StringTable->EmptyString())\
|
||||
return true;\
|
||||
\
|
||||
setMaskBits(bitmask);\
|
||||
inspectPostApply();\
|
||||
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != MaterialAsset::Ok)\
|
||||
{\
|
||||
Con::errorf("%s::_set%s() - material asset failure\"%s\" due to [%s]", macroText(className), macroText(name), _in, MaterialAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||
return false; \
|
||||
}\
|
||||
else if (bool(m##name) == NULL)\
|
||||
{\
|
||||
Con::errorf("%s::_set%s() - Couldn't load material \"%s\"", macroText(className), macroText(name), _in);\
|
||||
return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
return false;\
|
||||
const StringTableEntry get##name() const\
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getMaterialDefinitionName() != StringTable->EmptyString()))\
|
||||
return m##name##Asset->getMaterialDefinitionName();\
|
||||
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();\
|
||||
}\
|
||||
SimObjectPtr<Material> get##name##Resource() \
|
||||
{\
|
||||
return m##name;\
|
||||
}
|
||||
|
||||
#define DECLARE_MATERIALASSET_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_MATERIALASSET_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_MATERIALASSET_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, const char*, (), , "get name")\
|
||||
{\
|
||||
return object->get##name(); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, const char*, (), , assetText(name, asset reference))\
|
||||
{\
|
||||
return object->m##name##AssetId; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* mat), , assetText(name,assignment. first tries asset then material name.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(mat));\
|
||||
}
|
||||
|
||||
#define INIT_MATERIALASSET(name) \
|
||||
m##name##Name = StringTable->EmptyString(); \
|
||||
m##name##AssetId = StringTable->EmptyString(); \
|
||||
m##name##Asset = NULL;\
|
||||
m##name = NULL;
|
||||
|
||||
#define packMaterialAsset(netconn, name)\
|
||||
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define INITPERSISTFIELD_MATERIALASSET(name, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeMaterialName, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn,assetDoc(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
|
||||
|
||||
#else
|
||||
|
||||
#define INITPERSISTFIELD_MATERIALASSET(name, consoleClass, docs) \
|
||||
addProtectedField(#name, TypeMaterialName, Offset(m##name##Name, consoleClass), _set##name##Data, &defaultProtectedGetFn,assetDoc(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
|
||||
addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
|
||||
|
||||
#endif // SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define CLONE_MATERIALASSET(name) \
|
||||
m##name##Name = other.m##name##Name;\
|
||||
m##name##AssetId = other.m##name##AssetId;\
|
||||
m##name##Asset = other.m##name##Asset;
|
||||
|
||||
#define LOAD_MATERIALASSET(name)\
|
||||
if (m##name##AssetId != StringTable->EmptyString())\
|
||||
{\
|
||||
S32 assetState = MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
if (assetState == MaterialAsset::Ok )\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
else Con::warnf("Warning: %s::LOAD_MATERIALASSET(%s)-%s", mClassName, m##name##AssetId, MaterialAsset::getAssetErrstrn(assetState).c_str());\
|
||||
}
|
||||
|
||||
#define PACKDATA_MATERIALASSET(name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset.getAssetId());\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACKDATA_MATERIALASSET(name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = stream->readSTString();\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#define PACK_MATERIALASSET(netconn, name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
|
||||
|
|
@ -285,14 +347,16 @@ bool set##name##AssetId(const char* _assetId)\
|
|||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define unpackMaterialAsset(netconn, name)\
|
||||
#define UNPACK_MATERIALASSET(netconn, name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#endif // _ASSET_BASE_H_
|
||||
|
||||
|
|
|
|||
|
|
@ -160,8 +160,8 @@ GuiControl* GuiInspectorTypeParticleAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
|
||||
mSMEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mSMEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:shape_editor_n_image";
|
||||
mSMEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ void PostEffectAsset::initializeAsset()
|
|||
mHLSLShaderPath = expandAssetFilePath(mHLSLShaderFile);
|
||||
mGLSLShaderPath = expandAssetFilePath(mGLSLShaderFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ void PostEffectAsset::onAssetRefresh()
|
|||
mHLSLShaderPath = expandAssetFilePath(mHLSLShaderFile);
|
||||
mGLSLShaderPath = expandAssetFilePath(mGLSLShaderFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ void ScriptAsset::initializeAsset()
|
|||
{
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
{
|
||||
//We're initialized properly, so we'll go ahead and kick along any dependencies we may have as well
|
||||
AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
|
||||
|
|
@ -152,7 +152,7 @@ void ScriptAsset::onAssetRefresh()
|
|||
{
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
{
|
||||
//Refresh any dependencies we may have
|
||||
for (U32 i = 0; i < mScriptAssets.size(); i++)
|
||||
|
|
@ -192,7 +192,7 @@ bool ScriptAsset::execScript()
|
|||
|
||||
return false;
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
{
|
||||
return Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@
|
|||
#include "ts/tsLastDetail.h"
|
||||
#endif
|
||||
|
||||
StringTableEntry ShapeAsset::smNoShapeAssetFallback(StringTable->insert(Con::getVariable("$Core::NoShapeAssetFallback")));
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(ShapeAsset);
|
||||
|
|
@ -86,7 +88,7 @@ ConsoleSetType(TypeShapeAssetPtr)
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType(assetIdString, TypeShapeAssetId, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(assetIdString, TypeShapeAssetId, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
ConsoleGetType(TypeShapeAssetId)
|
||||
{
|
||||
|
|
@ -100,13 +102,7 @@ ConsoleSetType(TypeShapeAssetId)
|
|||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -143,6 +139,17 @@ ShapeAsset::~ShapeAsset()
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ShapeAsset::consoleInit()
|
||||
{
|
||||
Parent::consoleInit();
|
||||
|
||||
Con::addVariable("$Core::NoShapeAssetFallback", TypeString, &smNoShapeAssetFallback,
|
||||
"The assetId of the shape to display when the requested shape asset is missing.\n"
|
||||
"@ingroup GFX\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ShapeAsset::initPersistFields()
|
||||
{
|
||||
// Call parent.
|
||||
|
|
@ -154,7 +161,7 @@ void ShapeAsset::initPersistFields()
|
|||
&setShapeConstructorFile, &getShapeConstructorFile, "Path to the shape file we want to render");
|
||||
}
|
||||
|
||||
void ShapeAsset::setDataField(StringTableEntry slotName, const char *array, const char *value)
|
||||
void ShapeAsset::setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value)
|
||||
{
|
||||
Parent::setDataField(slotName, array, value);
|
||||
|
||||
|
|
@ -344,49 +351,39 @@ bool ShapeAsset::loadShape()
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
//Utility function to 'fill out' bindings and resources with a matching asset if one exists
|
||||
bool ShapeAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset)
|
||||
U32 ShapeAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset)
|
||||
{
|
||||
AssetQuery query;
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't find any assets
|
||||
//If possible, see if we can run an in-place import and the get the asset from that
|
||||
#if TORQUE_DEBUG
|
||||
Con::warnf("ShapeAsset::getAssetByFilename - Attempted to in-place import a shapefile(%s) that had no associated asset", fileName);
|
||||
#endif
|
||||
|
||||
AssetImporter* autoAssetImporter;
|
||||
if (!Sim::findObject("autoAssetImporter", autoAssetImporter))
|
||||
{
|
||||
autoAssetImporter = new AssetImporter();
|
||||
autoAssetImporter->registerObject("autoAssetImporter");
|
||||
}
|
||||
|
||||
StringTableEntry resultingAssetId = autoAssetImporter->autoImportFile(fileName);
|
||||
|
||||
if (resultingAssetId != StringTable->EmptyString())
|
||||
{
|
||||
shapeAsset->setAssetId(resultingAssetId);
|
||||
|
||||
if (!shapeAsset->isNull())
|
||||
return true;
|
||||
}
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
shapeAsset->setAssetId(StringTable->insert("Core_Rendering:noshape"));
|
||||
shapeAsset->setAssetId(ShapeAsset::smNoShapeAssetFallback);
|
||||
|
||||
if (!shapeAsset->isNull())
|
||||
return true;
|
||||
if (shapeAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("ShapeAsset::getAssetByFilename - Finding of asset associated with file %s failed with no fallback asset", fileName);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
//That didn't work, so fail out
|
||||
return false;
|
||||
//handle noshape not being loaded itself
|
||||
if ((*shapeAsset)->mLoadedState == BadFileReference)
|
||||
{
|
||||
Con::warnf("ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, and fallback asset reported error of Bad File Reference.", fileName);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
Con::warnf("ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, utilizing fallback asset", fileName);
|
||||
|
||||
(*shapeAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
else
|
||||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
shapeAsset->setAssetId(query.mAssetList[0]);
|
||||
return true;
|
||||
return (*shapeAsset)->mLoadedState;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -395,37 +392,11 @@ StringTableEntry ShapeAsset::getAssetIdByFilename(StringTableEntry fileName)
|
|||
if (fileName == StringTable->EmptyString())
|
||||
return StringTable->EmptyString();
|
||||
|
||||
StringTableEntry shapeAssetId = StringTable->EmptyString();
|
||||
StringTableEntry shapeAssetId = ShapeAsset::smNoShapeAssetFallback;
|
||||
|
||||
AssetQuery query;
|
||||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't find any assets
|
||||
//If possible, see if we can run an in-place import and the get the asset from that
|
||||
#if TORQUE_DEBUG
|
||||
Con::warnf("ShapeAsset::getAssetByFilename - Attempted to in-place import a shapefile(%s) that had no associated asset", fileName);
|
||||
#endif
|
||||
|
||||
AssetImporter* autoAssetImporter;
|
||||
if (!Sim::findObject("autoAssetImporter", autoAssetImporter))
|
||||
{
|
||||
autoAssetImporter = new AssetImporter();
|
||||
autoAssetImporter->registerObject("autoAssetImporter");
|
||||
}
|
||||
|
||||
StringTableEntry resultingAssetId = autoAssetImporter->autoImportFile(fileName);
|
||||
|
||||
if (resultingAssetId != StringTable->EmptyString())
|
||||
{
|
||||
shapeAssetId = resultingAssetId;
|
||||
return shapeAssetId;
|
||||
}
|
||||
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
shapeAssetId = StringTable->insert("Core_Rendering:noshape");
|
||||
}
|
||||
else
|
||||
if (foundAssetcount != 0)
|
||||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
shapeAssetId = query.mAssetList[0];
|
||||
|
|
@ -438,24 +409,34 @@ U32 ShapeAsset::getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* sha
|
|||
{
|
||||
(*shapeAsset) = assetId;
|
||||
|
||||
if ((*shapeAsset))
|
||||
return (*shapeAsset)->mLoadedState;
|
||||
|
||||
if (shapeAsset->notNull())
|
||||
{
|
||||
return (*shapeAsset)->mLoadedState;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
StringTableEntry noShapeId = StringTable->insert("Core_Rendering:noshape");
|
||||
shapeAsset->setAssetId(noShapeId);
|
||||
shapeAsset->setAssetId(ShapeAsset::smNoShapeAssetFallback);
|
||||
|
||||
if (shapeAsset->isNull())
|
||||
{
|
||||
//Well that's bad, loading the fallback failed.
|
||||
Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
//handle noshape not being loaded itself
|
||||
if ((*shapeAsset)->mLoadedState == BadFileReference)
|
||||
return AssetErrCode::Failed;
|
||||
{
|
||||
Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference.", assetId);
|
||||
return AssetErrCode::BadFileReference;
|
||||
}
|
||||
|
||||
Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset", assetId);
|
||||
|
||||
(*shapeAsset)->mLoadedState = AssetErrCode::UsingFallback;
|
||||
return AssetErrCode::UsingFallback;
|
||||
}
|
||||
|
||||
return AssetErrCode::Failed;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -555,17 +536,37 @@ DefineEngineMethod(ShapeAsset, getAnimation, ShapeAnimationAsset*, (S32 index),
|
|||
}
|
||||
|
||||
DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), ,
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
"Gets the shape's file path\n"
|
||||
"@return The filename of the shape file")
|
||||
{
|
||||
return object->getShapeFilePath();
|
||||
}
|
||||
|
||||
DefineEngineMethod(ShapeAsset, getShapeConstructorFilePath, const char*, (), ,
|
||||
"Gets the shape's constructor file.\n"
|
||||
"@return The filename of the shape constructor file")
|
||||
{
|
||||
return object->getShapeConstructorFilePath();
|
||||
}
|
||||
|
||||
DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string")\
|
||||
{
|
||||
return ShapeAsset::getAssetErrstrn(object->getStatus());
|
||||
}
|
||||
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 resolution), (256), "")
|
||||
{
|
||||
return object->generateCachedPreviewImage(resolution);
|
||||
}
|
||||
|
||||
DefineEngineStaticMethod(ShapeAsset, getAssetIdByFilename, const char*, (const char* filePath), (""),
|
||||
"Queries the Asset Database to see if any asset exists that is associated with the provided file path.\n"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return ShapeAsset::getAssetIdByFilename(StringTable->insert(filePath));
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -611,8 +612,8 @@ GuiControl* GuiInspectorTypeShapeAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "ShapeEditorPlugin.openShapeAssetId(%d.getText());", retCtrl->getId());
|
||||
mShapeEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mShapeEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:shape_editor_n_image";
|
||||
mShapeEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
|
|||
|
|
@ -81,9 +81,11 @@ protected:
|
|||
Vector<AssetPtr<ShapeAnimationAsset>> mAnimationAssets;
|
||||
|
||||
typedef Signal<void()> ShapeAssetChanged;
|
||||
|
||||
ShapeAssetChanged mChangeSignal;
|
||||
|
||||
typedef Signal<void(S32 index)> ShapeAssetArrayChanged;
|
||||
ShapeAssetArrayChanged mChangeArraySignal;
|
||||
|
||||
public:
|
||||
enum ShapeAssetErrCode
|
||||
{
|
||||
|
|
@ -93,7 +95,12 @@ public:
|
|||
Extended
|
||||
};
|
||||
|
||||
static StringTableEntry smNoShapeAssetFallback;
|
||||
|
||||
static const String mErrCodeStrings[ShapeAssetErrCode::Extended - Parent::Extended + 1];
|
||||
|
||||
static U32 getAssetErrCode(AssetPtr<ShapeAsset> shapeAsset) { if (shapeAsset) return shapeAsset->mLoadedState; else return 0; }
|
||||
|
||||
static String getAssetErrstrn(U32 errCode)
|
||||
{
|
||||
if (errCode < Parent::Extended) return Parent::getAssetErrstrn(errCode);
|
||||
|
|
@ -104,11 +111,14 @@ public:
|
|||
ShapeAsset();
|
||||
virtual ~ShapeAsset();
|
||||
|
||||
/// Set up some global script interface stuff.
|
||||
static void consoleInit();
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
virtual void setDataField(StringTableEntry slotName, const char *array, const char *value);
|
||||
virtual void setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value);
|
||||
|
||||
virtual void initializeAsset();
|
||||
|
||||
|
|
@ -116,25 +126,25 @@ public:
|
|||
DECLARE_CONOBJECT(ShapeAsset);
|
||||
|
||||
bool loadShape();
|
||||
U32 mLoadedState;
|
||||
|
||||
TSShape* getShape() { return mShape; }
|
||||
|
||||
Resource<TSShape> getShapeResource() { return mShape; }
|
||||
|
||||
void SplitSequencePathAndName(String& srcPath, String& srcName);
|
||||
StringTableEntry getShapeFilename() { return mFilePath; }
|
||||
|
||||
StringTableEntry getShapeFileName() { return mFileName; }
|
||||
StringTableEntry getShapePath() { return mFilePath; }
|
||||
|
||||
U32 getShapeFilenameHash() { return _StringTable::hashString(mFilePath); }
|
||||
|
||||
Vector<AssetPtr<MaterialAsset>> getMaterialAssets() { return mMaterialAssets; }
|
||||
|
||||
inline AssetPtr<MaterialAsset> getMaterialAsset(U32 matId)
|
||||
{
|
||||
if(matId >= mMaterialAssets.size())
|
||||
return nullptr;
|
||||
else
|
||||
return mMaterialAssets[matId];
|
||||
inline AssetPtr<MaterialAsset> getMaterialAsset(U32 matId)
|
||||
{
|
||||
if (matId >= mMaterialAssets.size())
|
||||
return nullptr;
|
||||
else
|
||||
return mMaterialAssets[matId];
|
||||
}
|
||||
|
||||
void clearMaterialAssets() { mMaterialAssets.clear(); }
|
||||
|
|
@ -145,9 +155,10 @@ public:
|
|||
S32 getAnimationCount() { return mAnimationAssets.size(); }
|
||||
ShapeAnimationAsset* getAnimation(S32 index);
|
||||
|
||||
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);
|
||||
inline StringTableEntry getShapeFile(void) const { return mFileName; };
|
||||
|
|
@ -158,13 +169,11 @@ public:
|
|||
inline StringTableEntry getShapeFilePath(void) const { return mFilePath; };
|
||||
inline StringTableEntry getShapeConstructorFilePath(void) const { return mConstructorFilePath; };
|
||||
|
||||
static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset);
|
||||
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset);
|
||||
|
||||
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
|
||||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset);
|
||||
|
||||
static StringTableEntry getNoShapeAssetId() { return StringTable->insert("Core_Rendering:noshape"); }
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
const char* generateCachedPreviewImage(S32 resolution);
|
||||
#endif
|
||||
|
|
@ -172,7 +181,7 @@ public:
|
|||
protected:
|
||||
virtual void onAssetRefresh(void);
|
||||
|
||||
static bool setShapeFile(void *obj, const char *index, const char *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 bool setShapeConstructorFile(void* obj, const char* index, const char* data) { static_cast<ShapeAsset*>(obj)->setShapeConstructorFile(data); return false; }
|
||||
|
|
@ -192,7 +201,7 @@ class GuiInspectorTypeShapeAssetPtr : public GuiInspectorTypeFileName
|
|||
typedef GuiInspectorTypeFileName Parent;
|
||||
public:
|
||||
|
||||
GuiBitmapButtonCtrl *mShapeEdButton;
|
||||
GuiBitmapButtonCtrl* mShapeEdButton;
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetPtr);
|
||||
static void consoleInit();
|
||||
|
|
@ -211,86 +220,415 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
|
||||
#pragma region Singular Asset Macros
|
||||
|
||||
#define initShapeAsset(name) m##name##Name = StringTable->EmptyString(); m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
|
||||
#define cloneShapeAsset(name) m##name##Name = other.m##name##Name; m##name##AssetId = other.m##name##AssetId; m##name##Asset = other.m##name##Asset;
|
||||
#define bindShapeAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId;
|
||||
|
||||
#define scriptBindShapeAsset(name, consoleClass, docs) addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), consoleClass::_set##name##Filename, & defaultProtectedGetFn, assetText(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
|
||||
|
||||
#define DECLARE_SHAPEASSET(className,name)\
|
||||
StringTableEntry m##name##Name;\
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<ShapeAsset> m##name##Asset;\
|
||||
const StringTableEntry& get##name() const { return m##name##Name; }\
|
||||
void set##name(FileName _in) { m##name##Name = _in; }\
|
||||
const AssetPtr<ShapeAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(AssetPtr<ShapeAsset>_in) { m##name##Asset = _in; }\
|
||||
static bool _set##name##Filename(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
#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;}\
|
||||
\
|
||||
StringTableEntry assetId = ShapeAsset::getAssetIdByFilename(StringTable->insert(data));\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
bool _set##name(StringTableEntry _in)\
|
||||
{\
|
||||
if (shape->_set##name##Asset(obj, index, assetId))\
|
||||
if(m##name##AssetId != _in || m##name##Name != _in)\
|
||||
{\
|
||||
if (assetId == StringTable->insert("Core_Rendering:noShape"))\
|
||||
if (m##name##Asset.notNull())\
|
||||
{\
|
||||
shape->m##name##Name = data;\
|
||||
shape->m##name##AssetId = StringTable->EmptyString();\
|
||||
\
|
||||
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
|
||||
}\
|
||||
if (_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\
|
||||
{\
|
||||
shape->m##name##AssetId = assetId;\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
\
|
||||
return false;\
|
||||
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;\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
shape->m##name##Asset = StringTable->EmptyString();\
|
||||
}\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
static bool _set##name##Asset(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
className* shape = static_cast<className*>(obj);\
|
||||
shape->m##name##AssetId = StringTable->insert(data);\
|
||||
if (ShapeAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
|
||||
{\
|
||||
if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noShape"))\
|
||||
shape->m##name##Name = StringTable->EmptyString();\
|
||||
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 (bool(m##name) == NULL)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - Couldn't load shape \"%s\"", macroText(className), getName(), macroText(name), _in);\
|
||||
return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
return false;\
|
||||
}\
|
||||
void pack##name##Asset(BitStream *stream)\
|
||||
\
|
||||
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;\
|
||||
}
|
||||
|
||||
#define DECLARE_SHAPEASSET_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_SHAPEASSET_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_SHAPEASSET_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, String, (), , "get name")\
|
||||
{\
|
||||
return object->get##name(); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, String, (), , assetText(name, asset reference))\
|
||||
{\
|
||||
return object->m##name##AssetId; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* shape), , assetText(name,assignment. first tries asset then flat file.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(shape));\
|
||||
}
|
||||
|
||||
#define INIT_SHAPEASSET(name) \
|
||||
m##name##Name = StringTable->EmptyString(); \
|
||||
m##name##AssetId = StringTable->EmptyString(); \
|
||||
m##name##Asset = NULL; \
|
||||
m##name = NULL;
|
||||
|
||||
#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
|
||||
|
||||
#define CLONE_SHAPEASSET(name) \
|
||||
m##name##Name = other.m##name##Name;\
|
||||
m##name##AssetId = other.m##name##AssetId;\
|
||||
m##name##Asset = other.m##name##Asset;\
|
||||
|
||||
#define PACKDATA_SHAPEASSET(name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset.getAssetId());\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);\
|
||||
}\
|
||||
void unpack##name##Asset(BitStream *stream)\
|
||||
{\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACKDATA_SHAPEASSET(name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = stream->readSTString();\
|
||||
ShapeAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
m##name##Name = m##name##Asset->getShapeFilename(); \
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#define PACK_SHAPEASSET(netconn, name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
|
||||
netconn->packNetStringHandleU(stream, assetIdStr);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACK_SHAPEASSET(netconn, name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Arrayed Asset Macros
|
||||
|
||||
#define DECLARE_SHAPEASSET_ARRAY(className,name,max) 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##AssetId[index] != _in || m##name##Name[index] != _in)\
|
||||
{\
|
||||
if(index >= sm##name##Count || index < 0)\
|
||||
return false;\
|
||||
if (_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();\
|
||||
}\
|
||||
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 (bool(m##name[index]) == NULL)\
|
||||
{\
|
||||
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];\
|
||||
}
|
||||
|
||||
#define DECLARE_SHAPEASSET_ARRAY_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
if (!index) return false;\
|
||||
U32 idx = dAtoi(index);\
|
||||
if (idx >= sm##name##Count)\
|
||||
return false;\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data), idx);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_SHAPEASSET_ARRAY_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
if (!index) return false;\
|
||||
U32 idx = dAtoi(index);\
|
||||
if (idx >= sm##name##Count)\
|
||||
return false;\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data), idx);\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_SHAPEASSET_ARRAY_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, String, (S32 index), , "get name")\
|
||||
{\
|
||||
return object->get##name(index); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, String, (S32 index), , assetText(name, asset reference))\
|
||||
{\
|
||||
if(index >= className::sm##name##Count || index < 0)\
|
||||
return "";\
|
||||
return object->m##name##AssetId[index]; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* shape, S32 index), , assetText(name,assignment. first tries asset then flat file.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(shape), index);\
|
||||
}
|
||||
|
||||
#endif
|
||||
#define INIT_SHAPEASSET_ARRAY(name, index) \
|
||||
{\
|
||||
m##name##Name[index] = StringTable->EmptyString(); \
|
||||
m##name##AssetId[index] = StringTable->EmptyString(); \
|
||||
m##name##Asset[index] = NULL; \
|
||||
m##name[index] = NULL;\
|
||||
}
|
||||
|
||||
#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
|
||||
|
||||
#define CLONE_SHAPEASSET_ARRAY(name, index) \
|
||||
{\
|
||||
m##name##Name[index] = other.m##name##Name[index];\
|
||||
m##name##AssetId[index] = other.m##name##AssetId[index];\
|
||||
m##name##Asset[index] = other.m##name##Asset[index];\
|
||||
}
|
||||
|
||||
#define PACKDATA_SHAPEASSET_ARRAY(name, index)\
|
||||
if (stream->writeFlag(m##name##Asset[index].notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset[index].getAssetId());\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name[index]);
|
||||
|
||||
#define UNPACKDATA_SHAPEASSET_ARRAY(name, index)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId[index] = stream->readSTString();\
|
||||
_set##name(m##name##AssetId[index], index);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name[index] = stream->readSTString();
|
||||
|
||||
#define PACK_SHAPEASSET_ARRAY(netconn, name, index)\
|
||||
if (stream->writeFlag(m##name##Asset[index].notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset[index].getAssetId();\
|
||||
netconn->packNetStringHandleU(stream, assetIdStr);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name[index]);
|
||||
|
||||
#define UNPACK_SHAPEASSET_ARRAY(netconn, name, index)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId[index] = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
_set##name(m##name##AssetId[index], index);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name[index] = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -42,19 +42,20 @@
|
|||
|
||||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
#include "sfx/sfxTypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(SoundAsset);
|
||||
|
||||
ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, SoundAsset, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleGetType(TypeSoundAssetPtr)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return (*((AssetPtr<SoundAsset>*)dptr)).getAssetId();
|
||||
return *((const char**)(dptr));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -65,21 +66,7 @@ ConsoleSetType(TypeSoundAssetPtr)
|
|||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset pointer.
|
||||
AssetPtr<SoundAsset>* pAssetPtr = dynamic_cast<AssetPtr<SoundAsset>*>((AssetPtrBase*)(dptr));
|
||||
|
||||
// Is the asset pointer the correct type?
|
||||
if (pAssetPtr == NULL)
|
||||
{
|
||||
// No, so fail.
|
||||
//Con::warnf("(TypeSoundAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set asset.
|
||||
pAssetPtr->setAssetId(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -90,15 +77,57 @@ ConsoleSetType(TypeSoundAssetPtr)
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleType(assetIdString, TypeSoundAssetId, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
ConsoleGetType(TypeSoundAssetId)
|
||||
{
|
||||
// Fetch asset Id.
|
||||
return *((const char**)(dptr));
|
||||
}
|
||||
|
||||
ConsoleSetType(TypeSoundAssetId)
|
||||
{
|
||||
// Was a single argument specified?
|
||||
if (argc == 1)
|
||||
{
|
||||
// Yes, so fetch field value.
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Warn.
|
||||
Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
SoundAsset::SoundAsset()
|
||||
{
|
||||
mSoundFile = StringTable->EmptyString();
|
||||
mSoundPath = StringTable->EmptyString();
|
||||
mSubtitleString = StringTable->EmptyString();
|
||||
|
||||
mPitchAdjust = 1;
|
||||
mVolumeAdjust = 1;
|
||||
mLoadedState = AssetErrCode::NotLoaded;
|
||||
mPreload = false;
|
||||
// SFX description inits
|
||||
// reverb is useless here, reverb is inacted on listener.
|
||||
mProfileDesc.mPitch = 1;
|
||||
mProfileDesc.mVolume = 1;
|
||||
mProfileDesc.mIs3D = false;
|
||||
mProfileDesc.mIsLooping = false;
|
||||
mProfileDesc.mIsStreaming = false;
|
||||
mProfileDesc.mUseHardware = false;
|
||||
mProfileDesc.mMinDistance = 1;
|
||||
mProfileDesc.mMaxDistance = 100;
|
||||
mProfileDesc.mConeInsideAngle = 360;
|
||||
mProfileDesc.mConeOutsideAngle = 360;
|
||||
mProfileDesc.mConeOutsideVolume = 1;
|
||||
mProfileDesc.mRolloffFactor = -1.0f;
|
||||
mProfileDesc.mScatterDistance = Point3F(0.f, 0.f, 0.f);
|
||||
mProfileDesc.mPriority = 1.0f;
|
||||
mProfileDesc.mSourceGroup = NULL;
|
||||
|
||||
//mSound = nullptr;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -117,8 +146,24 @@ void SoundAsset::initPersistFields()
|
|||
addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset),
|
||||
&setSoundFile, &getSoundFile, "Path to the sound file.");
|
||||
|
||||
addField("pitchAdjust", TypeF32, Offset(mPitchAdjust, SoundAsset), "Adjustment of the pitch value");
|
||||
addField("volumeAdjust", TypeF32, Offset(mVolumeAdjust, SoundAsset), "Adjustment to the volume.");
|
||||
addField("pitchAdjust", TypeF32, Offset(mProfileDesc.mPitch, SoundAsset), "Adjustment of the pitch value 1 is default.");
|
||||
addField("volumeAdjust", TypeF32, Offset(mProfileDesc.mVolume, SoundAsset), "Adjustment to the volume.");
|
||||
addField("is3D", TypeBool, Offset(mProfileDesc.mIs3D, SoundAsset), "Set this sound to 3D.");
|
||||
addField("isLooping", TypeBool, Offset(mProfileDesc.mIsLooping, SoundAsset), "Does this sound loop.");
|
||||
// if streaming, a default packet size should be chosen for all sounds.
|
||||
addField("isStreaming", TypeBool, Offset(mProfileDesc.mIsStreaming, SoundAsset), "Use streaming.");
|
||||
//....why?
|
||||
addField("useHardware", TypeBool, Offset(mProfileDesc.mUseHardware, SoundAsset), "Use hardware mixing for this sound.");
|
||||
addField("minDistance", TypeF32, Offset(mProfileDesc.mMinDistance, SoundAsset), "Minimum distance for sound.");
|
||||
// more like it.
|
||||
addField("maxDistance", TypeF32, Offset(mProfileDesc.mMaxDistance, SoundAsset), "Max distance for sound.");
|
||||
addField("coneInsideAngle", TypeS32, Offset(mProfileDesc.mConeInsideAngle, SoundAsset), "Cone inside angle.");
|
||||
addField("coneOutsideAngle", TypeS32, Offset(mProfileDesc.mConeOutsideAngle, SoundAsset), "Cone outside angle.");
|
||||
addField("coneOutsideVolume", TypeS32, Offset(mProfileDesc.mConeOutsideVolume, SoundAsset), "Cone outside volume.");
|
||||
addField("rolloffFactor", TypeF32, Offset(mProfileDesc.mRolloffFactor, SoundAsset), "Rolloff factor.");
|
||||
addField("scatterDistance", TypePoint3F, Offset(mProfileDesc.mScatterDistance, SoundAsset), "Randomization to the spacial position of the sound.");
|
||||
addField("sourceGroup", TypeSFXSourceName, Offset(mProfileDesc.mSourceGroup, SoundAsset), "Group that sources playing with this description should be put into.");
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
@ -131,20 +176,73 @@ void SoundAsset::copyTo(SimObject* object)
|
|||
|
||||
void SoundAsset::initializeAsset(void)
|
||||
{
|
||||
mSoundPath = expandAssetFilePath(mSoundFile);
|
||||
Parent::initializeAsset();
|
||||
|
||||
if (mSoundFile == StringTable->EmptyString())
|
||||
return;
|
||||
|
||||
//ResourceManager::get().getChangedSignal.notify(this, &SoundAsset::_onResourceChanged);
|
||||
|
||||
//Ensure our path is expando'd if it isn't already
|
||||
if (!Platform::isFullPath(mSoundPath))
|
||||
mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
|
||||
mSoundPath = expandAssetFilePath(mSoundPath);
|
||||
|
||||
loadSound();
|
||||
}
|
||||
|
||||
void SoundAsset::_onResourceChanged(const Torque::Path &path)
|
||||
{
|
||||
if (path != Torque::Path(mSoundPath))
|
||||
return;
|
||||
|
||||
refreshAsset();
|
||||
|
||||
loadSound();
|
||||
}
|
||||
|
||||
void SoundAsset::onAssetRefresh(void)
|
||||
{
|
||||
mSoundPath = expandAssetFilePath(mSoundFile);
|
||||
if (mSoundFile == StringTable->EmptyString())
|
||||
return;
|
||||
|
||||
//Update
|
||||
if (!Platform::isFullPath(mSoundFile))
|
||||
mSoundPath = getOwned() ? expandAssetFilePath(mSoundFile) : mSoundPath;
|
||||
|
||||
loadSound();
|
||||
}
|
||||
|
||||
bool SoundAsset::loadSound()
|
||||
{
|
||||
if (mSoundPath)
|
||||
{
|
||||
if (!Torque::FS::IsFile(mSoundPath))
|
||||
{
|
||||
Con::errorf("SoundAsset::initializeAsset: Attempted to load file %s but it was not valid!", mSoundFile);
|
||||
mLoadedState = BadFileReference;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{// = new SFXProfile(mProfileDesc, mSoundFile, mPreload);
|
||||
mSFXProfile.setDescription(&mProfileDesc);
|
||||
mSFXProfile.setSoundFileName(mSoundFile);
|
||||
mSFXProfile.setPreload(mPreload);
|
||||
}
|
||||
|
||||
}
|
||||
mChangeSignal.trigger();
|
||||
mLoadedState = Ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SoundAsset::setSoundFile(const char* pSoundFile)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pSoundFile != NULL, "Cannot use a NULL shape file.");
|
||||
AssertFatal(pSoundFile != NULL, "Cannot use a NULL sound file.");
|
||||
|
||||
// Fetch image file.
|
||||
// Fetch sound file.
|
||||
pSoundFile = StringTable->insert(pSoundFile);
|
||||
|
||||
// Ignore no change,
|
||||
|
|
@ -152,7 +250,7 @@ void SoundAsset::setSoundFile(const char* pSoundFile)
|
|||
return;
|
||||
|
||||
// Update.
|
||||
mSoundFile = StringTable->insert(pSoundFile);
|
||||
mSoundFile = pSoundFile;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
|
|
@ -162,3 +260,43 @@ DefineEngineMethod(SoundAsset, getSoundPath, const char*, (), , "")
|
|||
{
|
||||
return object->getSoundPath();
|
||||
}
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInspectorTypeSoundAssetPtr);
|
||||
|
||||
ConsoleDocClass(GuiInspectorTypeSoundAssetPtr,
|
||||
"@brief Inspector field type for Sounds\n\n"
|
||||
"Editor use only.\n\n"
|
||||
"@internal"
|
||||
);
|
||||
|
||||
void GuiInspectorTypeSoundAssetPtr::consoleInit()
|
||||
{
|
||||
Parent::consoleInit();
|
||||
|
||||
ConsoleBaseType::getType(TypeSoundAssetPtr)->setInspectorFieldType("GuiInspectorTypeSoundAssetPtr");
|
||||
}
|
||||
|
||||
GuiControl * GuiInspectorTypeSoundAssetPtr::constructEditControl()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool GuiInspectorTypeSoundAssetPtr::updateRects()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInspectorTypeSoundAssetId);
|
||||
|
||||
ConsoleDocClass(GuiInspectorTypeSoundAssetId,
|
||||
"@brief Inspector field type for Sounds\n\n"
|
||||
"Editor use only.\n\n"
|
||||
"@internal"
|
||||
);
|
||||
|
||||
void GuiInspectorTypeSoundAssetId::consoleInit()
|
||||
{
|
||||
Parent::consoleInit();
|
||||
|
||||
ConsoleBaseType::getType(TypeSoundAssetId)->setInspectorFieldType("GuiInspectorTypeSoundAssetId");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,25 @@
|
|||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
class SFXTrack;
|
||||
#include "gui/editor/guiInspectorTypes.h"
|
||||
|
||||
#ifndef _BITSTREAM_H_
|
||||
#include "core/stream/bitStream.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SFXRESOURCE_H_
|
||||
#include "sfx/sfxResource.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SFXDESCRIPTION_H_
|
||||
#include "sfx/sfxDescription.h"
|
||||
#endif // !_SFXDESCRIPTION_H_
|
||||
|
||||
#ifndef _SFXPROFILE_H_
|
||||
#include "sfx/sfxProfile.h"
|
||||
#endif // !_SFXPROFILE_H_
|
||||
|
||||
class SFXResource;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class SoundAsset : public AssetBase
|
||||
|
|
@ -49,8 +67,36 @@ class SoundAsset : public AssetBase
|
|||
protected:
|
||||
StringTableEntry mSoundFile;
|
||||
StringTableEntry mSoundPath;
|
||||
SFXProfile mSFXProfile;
|
||||
SFXDescription mProfileDesc;
|
||||
// subtitles
|
||||
StringTableEntry mSubtitleString;
|
||||
bool mPreload;
|
||||
|
||||
/*These will be needed in the refactor!
|
||||
Resource<SFXResource> mSoundResource;
|
||||
|
||||
|
||||
// SFXDesctriptions, some off these will be removed
|
||||
F32 mPitchAdjust;
|
||||
F32 mVolumeAdjust;
|
||||
bool mIs3D;
|
||||
bool mLoop;
|
||||
bool mIsStreaming;
|
||||
bool mUseHardware;
|
||||
|
||||
F32 mMinDistance;
|
||||
F32 mMaxDistance;
|
||||
U32 mConeInsideAngle;
|
||||
U32 mConeOutsideAngle;
|
||||
F32 mConeOutsideVolume;
|
||||
F32 mRolloffFactor;
|
||||
Point3F mScatterDistance;
|
||||
F32 mPriority;
|
||||
*/
|
||||
|
||||
typedef Signal<void()> SoundAssetChanged;
|
||||
SoundAssetChanged mChangeSignal;
|
||||
|
||||
public:
|
||||
SoundAsset();
|
||||
|
|
@ -60,16 +106,26 @@ public:
|
|||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
//SFXResource* getSound() { return mSoundResource; }
|
||||
Resource<SFXResource> getSoundResource() { return mSFXProfile.getResource(); }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(SoundAsset);
|
||||
|
||||
void setSoundFile(const char* pSoundFile);
|
||||
bool loadSound();
|
||||
inline StringTableEntry getSoundFile(void) const { return mSoundFile; };
|
||||
|
||||
inline StringTableEntry getSoundPath(void) const { return mSoundPath; };
|
||||
SFXProfile* getSfxProfile() { return &mSFXProfile; }
|
||||
SFXDescription* getSfxDescription() { return &mProfileDesc; }
|
||||
|
||||
bool isLoop() { return mProfileDesc.mIsLooping; }
|
||||
bool is3D() { return mProfileDesc.mIs3D; }
|
||||
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void);
|
||||
void _onResourceChanged(const Torque::Path & path);
|
||||
virtual void onAssetRefresh(void);
|
||||
|
||||
static bool setSoundFile(void *obj, const char *index, const char *data) { static_cast<SoundAsset*>(obj)->setSoundFile(data); return false; }
|
||||
|
|
@ -77,6 +133,229 @@ protected:
|
|||
};
|
||||
|
||||
DefineConsoleType(TypeSoundAssetPtr, SoundAsset)
|
||||
DefineConsoleType(TypeSoundAssetId, String)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// TypeAssetId GuiInspectorField Class
|
||||
//-----------------------------------------------------------------------------
|
||||
class GuiInspectorTypeSoundAssetPtr : public GuiInspectorTypeFileName
|
||||
{
|
||||
typedef GuiInspectorTypeFileName Parent;
|
||||
public:
|
||||
|
||||
GuiBitmapButtonCtrl* mSoundButton;
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeSoundAssetPtr);
|
||||
static void consoleInit();
|
||||
|
||||
virtual GuiControl* constructEditControl();
|
||||
virtual bool updateRects();
|
||||
};
|
||||
|
||||
class GuiInspectorTypeSoundAssetId : public GuiInspectorTypeSoundAssetPtr
|
||||
{
|
||||
typedef GuiInspectorTypeSoundAssetPtr Parent;
|
||||
public:
|
||||
|
||||
DECLARE_CONOBJECT(GuiInspectorTypeSoundAssetId);
|
||||
static void consoleInit();
|
||||
};
|
||||
|
||||
#pragma region Singular Asset Macros
|
||||
|
||||
//Singular assets
|
||||
/// <Summary>
|
||||
/// Declares a sound asset
|
||||
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
|
||||
/// </Summary>
|
||||
#define DECLARE_SOUNDASSET(className, name, profile) public: \
|
||||
Resource<SFXResource> m##name;\
|
||||
StringTableEntry m##name##Name; \
|
||||
StringTableEntry m##name##AssetId;\
|
||||
AssetPtr<SoundAsset> m##name##Asset = NULL;\
|
||||
SFXProfile* m##name##Profile = &profile;\
|
||||
public: \
|
||||
const StringTableEntry get##name##File() const { return m##name##Name); }\
|
||||
void set##name##File(const FileName &_in) { m##name##Name = StringTable->insert(_in.c_str());}\
|
||||
const AssetPtr<SoundAsset> & get##name##Asset() const { return m##name##Asset; }\
|
||||
void set##name##Asset(const AssetPtr<SoundAsset> &_in) { m##name##Asset = _in;}\
|
||||
\
|
||||
bool _set##name(StringTableEntry _in)\
|
||||
{\
|
||||
if(m##name##AssetId != _in || m##name##Name != _in)\
|
||||
{\
|
||||
if (_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 = SoundAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
|
||||
\
|
||||
if (SoundAsset::Ok == assetState)\
|
||||
{\
|
||||
m##name##Name = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
StringTableEntry assetId = SoundAsset::getAssetIdByFilename(_in);\
|
||||
if (assetId != StringTable->EmptyString())\
|
||||
{\
|
||||
m##name##AssetId = assetId;\
|
||||
if(SoundAsset::getAssetById(m##name##AssetId, &m##name##Asset) == SoundAsset::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->getSoundResource();\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
m##name = NULL;\
|
||||
}\
|
||||
\
|
||||
if (m##name##Asset.notNull() && m##name##Asset->getStatus() != ShapeAsset::Ok)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - sound asset failure\"%s\" due to [%s]", macroText(className), getName(), macroText(name), _in, ShapeAsset::getAssetErrstrn(m##name##Asset->getStatus()).c_str());\
|
||||
return false; \
|
||||
}\
|
||||
else if (bool(m##name) == NULL)\
|
||||
{\
|
||||
Con::errorf("%s(%s)::_set%s() - Couldn't load sound \"%s\"", macroText(className), getName(), macroText(name), _in);\
|
||||
return false;\
|
||||
}\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
const StringTableEntry get##name() const\
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getSoundPath() != StringTable->EmptyString()))\
|
||||
return m##name##Asset->getSoundPath();\
|
||||
else if (m##name##AssetId != StringTable->EmptyString())\
|
||||
return m##name##AssetId;\
|
||||
else if (m##name##Name != StringTable->EmptyString())\
|
||||
return StringTable->insert(m##name##Name);\
|
||||
else\
|
||||
return StringTable->EmptyString();\
|
||||
}\
|
||||
Resource<SFXResource> get##name##Resource() \
|
||||
{\
|
||||
return m##name;\
|
||||
}
|
||||
|
||||
#define DECLARE_SOUNDASSET_SETGET(className, name)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DECLARE_SOUNDASSET_NET_SETGET(className, name, bitmask)\
|
||||
static bool _set##name##Data(void* obj, const char* index, const char* data)\
|
||||
{\
|
||||
bool ret = false;\
|
||||
className* object = static_cast<className*>(obj);\
|
||||
ret = object->_set##name(StringTable->insert(data));\
|
||||
if(ret)\
|
||||
object->setMaskBits(bitmask);\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define DEF_SOUNDASSET_BINDS(className,name)\
|
||||
DefineEngineMethod(className, get##name, String, (), , "get name")\
|
||||
{\
|
||||
return object->get##name(); \
|
||||
}\
|
||||
DefineEngineMethod(className, get##name##Asset, String, (), , assetText(name, asset reference))\
|
||||
{\
|
||||
return object->m##name##AssetId; \
|
||||
}\
|
||||
DefineEngineMethod(className, set##name, bool, (const char* shape), , assetText(name,assignment. first tries asset then flat file.))\
|
||||
{\
|
||||
return object->_set##name(StringTable->insert(shape));\
|
||||
}
|
||||
|
||||
#define INIT_SOUNDASSET(name) \
|
||||
m##name##Name = StringTable->EmptyString(); \
|
||||
m##name##AssetId = StringTable->EmptyString(); \
|
||||
m##name##Asset = NULL; \
|
||||
m##name = NULL;\
|
||||
|
||||
#ifdef TORQUE_SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define INITPERSISTFIELD_SOUNDASSET(name, consoleClass, docs) \
|
||||
addProtectedField(assetText(name, File), TypeSoundFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, docs)); \
|
||||
addProtectedField(assetText(name, Asset), TypeSoundAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, asset reference.));
|
||||
|
||||
#else
|
||||
|
||||
#define INITPERSISTFIELD_SOUNDASSET(name, consoleClass, docs) \
|
||||
addProtectedField(assetText(name, File), TypeSoundFilename, Offset(m##name##Name, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
|
||||
addProtectedField(assetText(name, Asset), TypeSoundAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, & defaultProtectedGetFn, assetText(name, asset reference.));
|
||||
|
||||
#endif // TORQUE_SHOW_LEGACY_FILE_FIELDS
|
||||
|
||||
#define CLONE_SOUNDASSET(name) \
|
||||
m##name##Name = other.m##name##Name;\
|
||||
m##name##AssetId = other.m##name##AssetId;\
|
||||
m##name##Asset = other.m##name##Asset;\
|
||||
|
||||
#define PACKDATA_SOUNDASSET(name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
stream->writeString(m##name##Asset.getAssetId());\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACKDATA_SOUNDASSET(name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = stream->readSTString();\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#define PACK_SOUNDASSET(netconn, name)\
|
||||
if (stream->writeFlag(m##name##Asset.notNull()))\
|
||||
{\
|
||||
NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
|
||||
netconn->packNetStringHandleU(stream, assetIdStr);\
|
||||
}\
|
||||
else\
|
||||
stream->writeString(m##name##Name);
|
||||
|
||||
#define UNPACK_SOUNDASSET(netconn, name)\
|
||||
if (stream->readFlag())\
|
||||
{\
|
||||
m##name##AssetId = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
|
||||
_set##name(m##name##AssetId);\
|
||||
}\
|
||||
else\
|
||||
m##name##Name = stream->readSTString();
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#endif // _ASSET_BASE_H_
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ ConsoleSetType(TypeTerrainAssetPtr)
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ConsoleType(assetIdString, TypeTerrainAssetId, String, ASSET_ID_FIELD_PREFIX)
|
||||
ConsoleType(assetIdString, TypeTerrainAssetId, const char*, ASSET_ID_FIELD_PREFIX)
|
||||
|
||||
ConsoleGetType(TypeTerrainAssetId)
|
||||
{
|
||||
|
|
@ -107,11 +107,7 @@ ConsoleSetType(TypeTerrainAssetId)
|
|||
// Yes, so fetch field value.
|
||||
const char* pFieldValue = argv[0];
|
||||
|
||||
// Fetch asset Id.
|
||||
StringTableEntry* assetId = (StringTableEntry*)(dptr);
|
||||
|
||||
// Update asset value.
|
||||
*assetId = StringTable->insert(pFieldValue);
|
||||
*((const char**)dptr) = StringTable->insert(argv[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -194,7 +190,7 @@ void TerrainAsset::setTerrainFileName(const char* pScriptFile)
|
|||
|
||||
bool TerrainAsset::loadTerrain()
|
||||
{
|
||||
if (!Platform::isFile(mTerrainFilePath))
|
||||
if (!Torque::FS::IsFile(mTerrainFilePath))
|
||||
return false;
|
||||
|
||||
mTerrMaterialAssets.clear();
|
||||
|
|
@ -471,8 +467,8 @@ GuiControl* GuiInspectorTypeTerrainAssetPtr::constructEditControl()
|
|||
|
||||
mShapeEdButton->setField("Command", "EditorGui.setEditor(TerrainEditorPlugin);");
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mShapeEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:TerrainBlock_image";
|
||||
mShapeEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
|
|||
|
|
@ -119,11 +119,9 @@ void TerrainMaterialAsset::initializeAsset()
|
|||
// Call parent.
|
||||
Parent::initializeAsset();
|
||||
|
||||
compileShader();
|
||||
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +129,7 @@ void TerrainMaterialAsset::onAssetRefresh()
|
|||
{
|
||||
mScriptPath = expandAssetFilePath(mScriptFile);
|
||||
|
||||
if (Platform::isFile(mScriptPath))
|
||||
if (Torque::FS::IsScriptFile(mScriptPath))
|
||||
Con::executeFile(mScriptPath, false, false);
|
||||
|
||||
if (mMatDefinitionName != StringTable->EmptyString())
|
||||
|
|
@ -164,21 +162,49 @@ void TerrainMaterialAsset::setScriptFile(const char* pScriptFile)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void TerrainMaterialAsset::compileShader()
|
||||
{
|
||||
}
|
||||
|
||||
void TerrainMaterialAsset::copyTo(SimObject* object)
|
||||
{
|
||||
// Call to parent.
|
||||
Parent::copyTo(object);
|
||||
}
|
||||
|
||||
DefineEngineMethod(TerrainMaterialAsset, compileShader, void, (), , "Compiles the material's generated shader, if any. Not yet implemented\n")
|
||||
StringTableEntry TerrainMaterialAsset::getAssetIdByMaterialName(StringTableEntry matName)
|
||||
{
|
||||
object->compileShader();
|
||||
StringTableEntry materialAssetId = StringTable->EmptyString();
|
||||
|
||||
AssetQuery* query = new AssetQuery();
|
||||
U32 foundCount = AssetDatabase.findAssetType(query, "TerrainMaterialAsset");
|
||||
if (foundCount == 0)
|
||||
{
|
||||
//Didn't work, so have us fall back to a placeholder asset
|
||||
materialAssetId = StringTable->insert("Core_Rendering:noMaterial");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (U32 i = 0; i < foundCount; i++)
|
||||
{
|
||||
TerrainMaterialAsset* matAsset = AssetDatabase.acquireAsset<TerrainMaterialAsset>(query->mAssetList[i]);
|
||||
if (matAsset && matAsset->getMaterialDefinitionName() == matName)
|
||||
{
|
||||
materialAssetId = matAsset->getAssetId();
|
||||
AssetDatabase.releaseAsset(query->mAssetList[i]);
|
||||
break;
|
||||
}
|
||||
AssetDatabase.releaseAsset(query->mAssetList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return materialAssetId;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_TOOLS
|
||||
DefineEngineStaticMethod(TerrainMaterialAsset, 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"
|
||||
"@return The AssetId of the associated asset, if any.")
|
||||
{
|
||||
return TerrainMaterialAsset::getAssetIdByMaterialName(StringTable->insert(materialName));
|
||||
}
|
||||
#endif
|
||||
//-----------------------------------------------------------------------------
|
||||
// GuiInspectorTypeAssetId
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -218,7 +244,7 @@ GuiControl* GuiInspectorTypeTerrainMaterialAssetPtr::constructEditControl()
|
|||
|
||||
TerrainMaterial* materialDef = nullptr;
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
char bitmapName[512] = "ToolsModule:material_editor_n_image";
|
||||
|
||||
/*if (!Sim::findObject(matAsset->getMaterialDefinitionName(), materialDef))
|
||||
{
|
||||
|
|
@ -245,7 +271,7 @@ GuiControl* GuiInspectorTypeTerrainMaterialAssetPtr::constructEditControl()
|
|||
StringBuilder strbld;
|
||||
strbld.append(matAsset->getMaterialDefinitionName());
|
||||
strbld.append("\n");
|
||||
strbld.append("Open this file in the Material Editor");
|
||||
strbld.append("Open this asset in the Material Editor");
|
||||
|
||||
mMatPreviewButton->setDataField(StringTable->insert("tooltip"), NULL, strbld.data());
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public:
|
|||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
void compileShader();
|
||||
static StringTableEntry getAssetIdByMaterialName(StringTableEntry matName);
|
||||
|
||||
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
|
||||
|
||||
|
|
|
|||
|
|
@ -32,10 +32,11 @@ ConsoleDocClass(AssetImportConfig,
|
|||
IMPLEMENT_CONOBJECT(AssetImportConfig);
|
||||
|
||||
AssetImportConfig::AssetImportConfig() :
|
||||
DuplicatAutoResolution("AutoRename"),
|
||||
DuplicateAutoResolution("AutoRename"),
|
||||
WarningsAsErrors(false),
|
||||
PreventImportWithErrors(true),
|
||||
AutomaticallyPromptMissingFiles(false),
|
||||
AddDirectoryPrefixToAssetName(false),
|
||||
ImportMesh(true),
|
||||
AlwaysAddShapeSuffix(false),
|
||||
AddedShapeSuffix("_shape"),
|
||||
|
|
@ -89,7 +90,7 @@ AssetImportConfig::AssetImportConfig() :
|
|||
ImageType("GUI"),
|
||||
DiffuseTypeSuffixes("_ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL,_A,_C,-ALBEDO,-DIFFUSE,-ALB,-DIF,-COLOR,-COL,-A,-C"),
|
||||
NormalTypeSuffixes("_NORMAL,_NORM,_N,-NORMAL,-NORM,-N"),
|
||||
MetalnessTypeSuffixes("_METAL,_MET,_METALNESS,_METALLIC,_M,-METAL, -MET, -METALNESS, -METALLIC, -M"),
|
||||
MetalnessTypeSuffixes("_METAL,_MET,_METALNESS,_METALLIC,_M,-METAL,-MET,-METALNESS,-METALLIC,-M"),
|
||||
RoughnessTypeSuffixes("_ROUGH,_ROUGHNESS,_R,-ROUGH,-ROUGHNESS,-R"),
|
||||
SmoothnessTypeSuffixes("_SMOOTH,_SMOOTHNESS,_S,-SMOOTH,-SMOOTHNESS,-S"),
|
||||
AOTypeSuffixes("_AO,_AMBIENT,_AMBIENTOCCLUSION,-AO,-AMBIENT,-AMBIENTOCCLUSION"),
|
||||
|
|
@ -131,10 +132,11 @@ void AssetImportConfig::initPersistFields()
|
|||
Parent::initPersistFields();
|
||||
|
||||
addGroup("General");
|
||||
addField("DuplicatAutoResolution", TypeRealString, Offset(DuplicatAutoResolution, AssetImportConfig), "Duplicate Asset Auto-Resolution Action. Options are None, AutoPrune, AutoRename");
|
||||
addField("DuplicateAutoResolution", TypeRealString, Offset(DuplicateAutoResolution, AssetImportConfig), "Duplicate Asset Auto-Resolution Action. Options are None, AutoPrune, AutoRename, FolderPrefix");
|
||||
addField("WarningsAsErrors", TypeBool, Offset(WarningsAsErrors, AssetImportConfig), "Indicates if warnings should be treated as errors");
|
||||
addField("PreventImportWithErrors", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "Indicates if importing should be prevented from completing if any errors are detected at all");
|
||||
addField("AutomaticallyPromptMissingFiles", TypeBool, Offset(AutomaticallyPromptMissingFiles, AssetImportConfig), "Should the importer automatically prompt to find missing files if they are not detected automatically by the importer");
|
||||
addField("AddDirectoryPrefixToAssetName", TypeBool, Offset(AddDirectoryPrefixToAssetName, AssetImportConfig), "Should the importer add the folder name as a prefix to the assetName. Helps prevent name collisions.");
|
||||
endGroup("General");
|
||||
|
||||
addGroup("Meshes");
|
||||
|
|
@ -228,10 +230,11 @@ void AssetImportConfig::initPersistFields()
|
|||
void AssetImportConfig::loadImportConfig(Settings* configSettings, String configName)
|
||||
{
|
||||
//General
|
||||
DuplicatAutoResolution = configSettings->value(String(configName + "/General/DuplicatAutoResolution").c_str());
|
||||
DuplicateAutoResolution = configSettings->value(String(configName + "/General/DuplicateAutoResolution").c_str());
|
||||
WarningsAsErrors = dAtob(configSettings->value(String(configName + "/General/WarningsAsErrors").c_str()));
|
||||
PreventImportWithErrors = dAtob(configSettings->value(String(configName + "/General/PreventImportWithErrors").c_str()));
|
||||
AutomaticallyPromptMissingFiles = dAtob(configSettings->value(String(configName + "/General/AutomaticallyPromptMissingFiles").c_str()));
|
||||
AddDirectoryPrefixToAssetName = dAtob(configSettings->value(String(configName + "/General/AddDirectoryPrefixToAssetName").c_str()));
|
||||
|
||||
//Meshes
|
||||
ImportMesh = dAtob(configSettings->value(String(configName + "/Meshes/ImportMesh").c_str()));
|
||||
|
|
@ -317,10 +320,11 @@ void AssetImportConfig::loadImportConfig(Settings* configSettings, String config
|
|||
|
||||
void AssetImportConfig::CopyTo(AssetImportConfig* target) const
|
||||
{
|
||||
target->DuplicatAutoResolution = DuplicatAutoResolution;
|
||||
target->DuplicateAutoResolution = DuplicateAutoResolution;
|
||||
target->WarningsAsErrors = WarningsAsErrors;
|
||||
target->PreventImportWithErrors = PreventImportWithErrors;
|
||||
target->AutomaticallyPromptMissingFiles = AutomaticallyPromptMissingFiles;
|
||||
target->AddDirectoryPrefixToAssetName = AddDirectoryPrefixToAssetName;
|
||||
|
||||
//Meshes
|
||||
target->ImportMesh = ImportMesh;
|
||||
|
|
@ -698,11 +702,8 @@ AssetImportObject* AssetImporter::findImportingAssetByName(String assetName, Ass
|
|||
|
||||
ModuleDefinition* AssetImporter::getModuleFromPath(Torque::Path filePath)
|
||||
{
|
||||
//We want to ensure it's a full filepath, because the module system internally uses full paths for the module dirs
|
||||
char fullPath[2048];
|
||||
Platform::makeFullPathName(filePath.getFullPath().c_str(), fullPath, sizeof(fullPath));
|
||||
|
||||
ModuleDefinition* moduleDef = ModuleDatabase.findModuleByFilePath(StringTable->insert(fullPath));
|
||||
// Use a relative path so modules on mounted file systems will be found.
|
||||
ModuleDefinition* moduleDef = ModuleDatabase.findModuleByFilePath(Platform::makeRelativePathName(filePath.getFullPath().c_str(), NULL));
|
||||
|
||||
return moduleDef;
|
||||
}
|
||||
|
|
@ -1447,8 +1448,8 @@ void AssetImporter::processImportAssets(AssetImportObject* assetItem)
|
|||
if (!childItem->processed)
|
||||
{
|
||||
//Sanitize before modifying our asset name(suffix additions, etc)
|
||||
if (childItem->assetName != childItem->cleanAssetName)
|
||||
childItem->assetName = childItem->cleanAssetName;
|
||||
//if (childItem->assetName != childItem->cleanAssetName)
|
||||
// childItem->assetName = childItem->cleanAssetName;
|
||||
|
||||
//handle special pre-processing here for any types that need it
|
||||
|
||||
|
|
@ -1582,6 +1583,28 @@ void AssetImporter::processImageAsset(AssetImportObject* assetItem)
|
|||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//If we're processing an unaffiliated image without generating materials for it, we can check some other bits
|
||||
if (assetItem->parentAssetItem == nullptr)
|
||||
{
|
||||
if (assetItem->typeHint != String::EmptyString)
|
||||
{
|
||||
ImageAssetType type = ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str()));
|
||||
|
||||
if (type == ImageAssetType::GUI)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(assetItem->assetName == assetItem->cleanAssetName && activeImportConfig->AlwaysAddImageSuffix)
|
||||
{
|
||||
assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
|
||||
assetItem->cleanAssetName = assetItem->assetName;
|
||||
}
|
||||
|
||||
assetItem->processed = true;
|
||||
}
|
||||
|
|
@ -1615,174 +1638,214 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
|
|||
}
|
||||
}
|
||||
|
||||
if (activeImportConfig->AlwaysAddMaterialSuffix)
|
||||
if (activeImportConfig->UseExistingMaterials)
|
||||
{
|
||||
assetItem->assetName += activeImportConfig->AddedMaterialSuffix;
|
||||
}
|
||||
//So if the material already exists, we should just use that. So first, let's find out if it already exists
|
||||
|
||||
if (activeImportConfig->PopulateMaterialMaps)
|
||||
{
|
||||
//If we're trying to populate the rest of our material maps, we need to go looking
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Attempting to Auto-Populate Material Maps");
|
||||
activityLog.push_back(importLogBuffer);
|
||||
//check to see if the definition for this already exists
|
||||
StringTableEntry existingMatAsset = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(assetName));
|
||||
|
||||
AssetImportObject* matchedImageTypes[ImageAsset::ImageTypeCount] = { nullptr };
|
||||
|
||||
String materialImageNoSuffix;
|
||||
|
||||
for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
if (existingMatAsset != StringTable->EmptyString())
|
||||
{
|
||||
AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
||||
assetItem->skip = true;
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Material %s has been skipped because we already found an asset Id that uses that material definition. The found assetId is: %s", assetItem->assetName.c_str(), existingMatAsset);
|
||||
activityLog.push_back(importLogBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (childAssetItem->skip || childAssetItem->assetType != String("ImageAsset"))
|
||||
continue;
|
||||
//If there was no existing assetId, then lets see if it already exists in a legacy file, like a materials.cs or materials.tscript
|
||||
//If it does, we'll just make our asset point to that instead of a new file
|
||||
Material* mat = MATMGR->getMaterialDefinitionByName(assetName);
|
||||
|
||||
for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
||||
if (!mat)
|
||||
mat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
||||
|
||||
if (!mat && assetItem->assetName != assetItem->cleanAssetName)
|
||||
{
|
||||
mat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
|
||||
|
||||
if (!mat)
|
||||
mat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
|
||||
}
|
||||
|
||||
if(mat)
|
||||
{
|
||||
//We found a match, so just modify our asset item's info to point against it. This will create the asset definition, but otherwise leave the material definition as-is.
|
||||
assetItem->filePath = (Torque::Path)(mat->getFilename());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (activeImportConfig->AlwaysAddMaterialSuffix) //we only opt to force on the suffix if we're not obligating using the original material defs
|
||||
{
|
||||
assetItem->assetName += activeImportConfig->AddedMaterialSuffix;
|
||||
assetItem->cleanAssetName = assetItem->assetName;
|
||||
}
|
||||
|
||||
if (activeImportConfig->PopulateMaterialMaps)
|
||||
{
|
||||
//If we're trying to populate the rest of our material maps, we need to go looking
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Attempting to Auto-Populate Material Maps");
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
AssetImportObject* matchedImageTypes[ImageAsset::ImageTypeCount] = { nullptr };
|
||||
|
||||
String materialImageNoSuffix;
|
||||
|
||||
for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
{
|
||||
//If the imageType name and child asset image type match, check it off our list
|
||||
if (!dStricmp(ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t), childAssetItem->imageSuffixType.c_str()))
|
||||
AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
||||
|
||||
if (childAssetItem->skip || childAssetItem->assetType != String("ImageAsset"))
|
||||
continue;
|
||||
|
||||
for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
||||
{
|
||||
matchedImageTypes[t] = childAssetItem;
|
||||
|
||||
if (t == ImageAsset::ImageTypes::Albedo)
|
||||
//If the imageType name and child asset image type match, check it off our list
|
||||
if (!dStricmp(ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t), childAssetItem->imageSuffixType.c_str()))
|
||||
{
|
||||
String sufType;
|
||||
String suffix = parseImageSuffixes(childAssetItem->assetName, &sufType);
|
||||
matchedImageTypes[t] = childAssetItem;
|
||||
|
||||
String imageAssetName = childAssetItem->assetName;
|
||||
if (t == ImageAsset::ImageTypes::Albedo)
|
||||
{
|
||||
String sufType;
|
||||
String suffix = parseImageSuffixes(childAssetItem->assetName, &sufType);
|
||||
|
||||
if (suffix.isEmpty())
|
||||
materialImageNoSuffix = imageAssetName;
|
||||
else
|
||||
materialImageNoSuffix = imageAssetName.erase(imageAssetName.length() - suffix.length(), suffix.length());//cache this for later as we may need it for file association lookups
|
||||
String imageAssetName = childAssetItem->assetName;
|
||||
|
||||
if (suffix.isEmpty())
|
||||
materialImageNoSuffix = imageAssetName;
|
||||
else
|
||||
materialImageNoSuffix = imageAssetName.erase(imageAssetName.length() - suffix.length(), suffix.length());//cache this for later as we may need it for file association lookups
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Now that we've checked off any existingly matched image types, process through the unmatched to look for files that associate
|
||||
for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
||||
{
|
||||
//This type wasn't found, so try and find a match based on suffix
|
||||
String suffixList;
|
||||
|
||||
switch (t)
|
||||
//Now that we've checked off any existingly matched image types, process through the unmatched to look for files that associate
|
||||
for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
|
||||
{
|
||||
case ImageAsset::Albedo:
|
||||
suffixList = activeImportConfig->DiffuseTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Normal:
|
||||
suffixList = activeImportConfig->NormalTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::ORMConfig:
|
||||
suffixList = activeImportConfig->PBRTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Metalness:
|
||||
suffixList = activeImportConfig->MetalnessTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::AO:
|
||||
suffixList = activeImportConfig->AOTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Roughness:
|
||||
suffixList = activeImportConfig->RoughnessTypeSuffixes;
|
||||
break;
|
||||
//TODO: Glow map lookup too
|
||||
}
|
||||
//This type wasn't found, so try and find a match based on suffix
|
||||
String suffixList;
|
||||
|
||||
if (!matchedImageTypes[t])
|
||||
{
|
||||
U32 suffixCount = StringUnit::getUnitCount(suffixList.c_str(), ",;\t");
|
||||
for (U32 i = 0; i < suffixCount; i++)
|
||||
switch (t)
|
||||
{
|
||||
//First, try checking based on the material's assetName for our patternbase
|
||||
String testPath = assetItem->filePath.getRootAndPath();
|
||||
testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
||||
case ImageAsset::Albedo:
|
||||
suffixList = activeImportConfig->DiffuseTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Normal:
|
||||
suffixList = activeImportConfig->NormalTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::ORMConfig:
|
||||
suffixList = activeImportConfig->PBRTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Metalness:
|
||||
suffixList = activeImportConfig->MetalnessTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::AO:
|
||||
suffixList = activeImportConfig->AOTypeSuffixes;
|
||||
break;
|
||||
case ImageAsset::Roughness:
|
||||
suffixList = activeImportConfig->RoughnessTypeSuffixes;
|
||||
break;
|
||||
//TODO: Glow map lookup too
|
||||
}
|
||||
|
||||
String imagePath = AssetImporter::findImagePath(testPath);
|
||||
|
||||
if (imagePath.isNotEmpty())
|
||||
if (!matchedImageTypes[t])
|
||||
{
|
||||
U32 suffixCount = StringUnit::getUnitCount(suffixList.c_str(), ",;\t");
|
||||
for (U32 i = 0; i < suffixCount; i++)
|
||||
{
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
//First, try checking based on the material's assetName for our patternbase
|
||||
String testPath = assetItem->filePath.getRootAndPath();
|
||||
testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
||||
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
||||
String imagePath = AssetImporter::findImagePath(testPath);
|
||||
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(materialImageNoSuffix.isNotEmpty())
|
||||
if (imagePath.isNotEmpty())
|
||||
{
|
||||
testPath = assetItem->filePath.getRootAndPath();
|
||||
testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
|
||||
imagePath = AssetImporter::findImagePath(testPath);
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
||||
|
||||
if (imagePath.isNotEmpty())
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (materialImageNoSuffix.isNotEmpty())
|
||||
{
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
testPath = assetItem->filePath.getRootAndPath();
|
||||
testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
|
||||
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
||||
imagePath = AssetImporter::findImagePath(testPath);
|
||||
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
break;
|
||||
if (imagePath.isNotEmpty())
|
||||
{
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
|
||||
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If we're the abledo slot and after all that we didn't find anything, it probably is a suffixless image
|
||||
if (t == ImageAsset::Albedo && matchedImageTypes[t] == nullptr)
|
||||
{
|
||||
String testPath = assetItem->filePath.getRootAndPath() + "/" + assetItem->cleanAssetName;
|
||||
String imagePath = AssetImporter::findImagePath(testPath);
|
||||
|
||||
if (imagePath.isNotEmpty())
|
||||
//If we're the abledo slot and after all that we didn't find anything, it probably is a suffixless image
|
||||
if (t == ImageAsset::Albedo && matchedImageTypes[t] == nullptr)
|
||||
{
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
String testPath = assetItem->filePath.getRootAndPath() + "/" + assetItem->cleanAssetName;
|
||||
String imagePath = AssetImporter::findImagePath(testPath);
|
||||
|
||||
//In the event that the names match, we want to avoid duplications, so we'll go ahead and append a suffix onto our new image asset
|
||||
if (newImageAssetObj->assetName == assetItem->assetName)
|
||||
if (imagePath.isNotEmpty())
|
||||
{
|
||||
newImageAssetObj->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
||||
newImageAssetObj->cleanAssetName = newImageAssetObj->assetName;
|
||||
//got a match!
|
||||
AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
|
||||
|
||||
//In the event that the names match, we want to avoid duplications, so we'll go ahead and append a suffix onto our new image asset
|
||||
if (newImageAssetObj->assetName == assetItem->assetName)
|
||||
{
|
||||
newImageAssetObj->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
||||
newImageAssetObj->cleanAssetName = newImageAssetObj->assetName;
|
||||
}
|
||||
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes::Albedo);
|
||||
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
}
|
||||
|
||||
newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes::Albedo);
|
||||
|
||||
matchedImageTypes[t] = newImageAssetObj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//just a bit of cleanup and logical testing for matches
|
||||
//in the event we KNOW what the type is, but we don't have a suffix, such as a found image on a material lookup
|
||||
//that doesn't have a suffix, we assume it to be the albedo, so we'll just append the suffix to avoid collisions if
|
||||
//the name already matches our material name, similar to above logic
|
||||
if (matchedImageTypes[t]->assetName == assetItem->assetName)
|
||||
{
|
||||
matchedImageTypes[t]->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
||||
matchedImageTypes[t]->cleanAssetName = matchedImageTypes[t]->assetName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
/*for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
{
|
||||
//just a bit of cleanup and logical testing for matches
|
||||
//in the event we KNOW what the type is, but we don't have a suffix, such as a found image on a material lookup
|
||||
//that doesn't have a suffix, we assume it to be the albedo, so we'll just append the suffix to avoid collisions if
|
||||
//the name already matches our material name, similar to above logic
|
||||
if (matchedImageTypes[t]->assetName == assetItem->assetName)
|
||||
AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
||||
|
||||
if (childAssetItem->skip || childAssetItem->processed || childAssetItem->assetType != String("ImageAsset"))
|
||||
continue;
|
||||
|
||||
if (childAssetItem->imageSuffixType == String("Albedo"))
|
||||
{
|
||||
matchedImageTypes[t]->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
|
||||
matchedImageTypes[t]->cleanAssetName = matchedImageTypes[t]->assetName;
|
||||
assetItem->diffuseImageAsset = % childAssetItem;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/*for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
{
|
||||
AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
|
||||
|
||||
if (childAssetItem->skip || childAssetItem->processed || childAssetItem->assetType != String("ImageAsset"))
|
||||
continue;
|
||||
|
||||
if (childAssetItem->imageSuffixType == String("Albedo"))
|
||||
{
|
||||
assetItem->diffuseImageAsset = % childAssetItem;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
assetItem->processed = true;
|
||||
|
|
@ -1825,6 +1888,7 @@ void AssetImporter::processShapeAsset(AssetImportObject* assetItem)
|
|||
if (activeImportConfig->AlwaysAddShapeSuffix)
|
||||
{
|
||||
assetItem->assetName += activeImportConfig->AddedShapeSuffix;
|
||||
assetItem->cleanAssetName = assetItem->assetName;
|
||||
}
|
||||
|
||||
S32 meshCount = dAtoi(assetItem->shapeInfo->getDataField(StringTable->insert("_meshCount"), nullptr));
|
||||
|
|
@ -1891,7 +1955,7 @@ void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 m
|
|||
if (matName == assetItem->assetName)
|
||||
{
|
||||
//So apparently we managed to name the material the same as the shape. So we'll tweak the name
|
||||
matAssetName += activeImportConfig->AlwaysAddMaterialSuffix;
|
||||
matAssetName += activeImportConfig->AddedMaterialSuffix;
|
||||
}
|
||||
|
||||
//Do a check so we don't import materials that are on our ignore list
|
||||
|
|
@ -2281,18 +2345,18 @@ void AssetImporter::resolveAssetItemIssues(AssetImportObject* assetItem)
|
|||
String humanReadableReason = assetItem->statusType == String("DuplicateImportAsset") ? "Importing asset was duplicate of another importing asset" : "Importing asset was duplicate of an existing asset";
|
||||
|
||||
//get the config value for duplicateAutoResolution
|
||||
if (activeImportConfig->DuplicatAutoResolution == String("AutoPrune"))
|
||||
if (activeImportConfig->DuplicateAutoResolution == String("AutoPrune"))
|
||||
{
|
||||
//delete the item
|
||||
deleteImportingAsset(assetItem);
|
||||
|
||||
//log it's deletion
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was autoprined due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was autopruned due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
importIssues = false;
|
||||
}
|
||||
else if (activeImportConfig->DuplicatAutoResolution == String("AutoRename"))
|
||||
else if (activeImportConfig->DuplicateAutoResolution == String("AutoRename"))
|
||||
{
|
||||
//Set trailing number
|
||||
String renamedAssetName = assetItem->assetName;
|
||||
|
|
@ -2311,10 +2375,31 @@ void AssetImporter::resolveAssetItemIssues(AssetImportObject* assetItem)
|
|||
resetAssetValidationStatus(assetItem);
|
||||
importIssues = false;
|
||||
}
|
||||
else if (activeImportConfig->DuplicatAutoResolution == String("UseExisting"))
|
||||
else if (activeImportConfig->DuplicateAutoResolution == String("UseExisting"))
|
||||
{
|
||||
|
||||
}
|
||||
else if (activeImportConfig->DuplicateAutoResolution == String("FolderPrefix"))
|
||||
{
|
||||
//Set trailing number
|
||||
String renamedAssetName = assetItem->assetName;
|
||||
String owningFolder = assetItem->filePath.getDirectory(assetItem->filePath.getDirectoryCount() - 1);
|
||||
|
||||
renamedAssetName = owningFolder + "_" + renamedAssetName;
|
||||
|
||||
//Log it's renaming
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed to %s", assetItem->assetName.c_str(), renamedAssetName.c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
assetItem->assetName = renamedAssetName;
|
||||
|
||||
//Whatever status we had prior is no longer relevent, so reset the status
|
||||
resetAssetValidationStatus(assetItem);
|
||||
importIssues = false;
|
||||
}
|
||||
}
|
||||
else if (assetItem->statusType == String("MissingFile"))
|
||||
{
|
||||
|
|
@ -2351,7 +2436,7 @@ void AssetImporter::resetImportConfig()
|
|||
//
|
||||
// Importing
|
||||
//
|
||||
StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
||||
StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath, String typeHint)
|
||||
{
|
||||
//Just in case we're reusing the same importer object from another import session, nuke any existing files
|
||||
resetImportSession(true);
|
||||
|
|
@ -2362,6 +2447,8 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|||
{
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is a folder or zip.", filePath.getFullPath().c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
dumpActivityLog();
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
|
|
@ -2369,6 +2456,8 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|||
{
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is of an unrecognized/unsupported type.", filePath.getFullPath().c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
dumpActivityLog();
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
|
|
@ -2377,7 +2466,10 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|||
|
||||
if (targetModuleDef == nullptr)
|
||||
{
|
||||
//log it
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is not in a valid module folder.", filePath.getFullPath().c_str());
|
||||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
dumpActivityLog();
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
else
|
||||
|
|
@ -2407,14 +2499,7 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath)
|
|||
importAssets();
|
||||
}
|
||||
|
||||
#if TORQUE_DEBUG
|
||||
Con::printf("/***************/");
|
||||
for (U32 i = 0; i < activityLog.size(); i++)
|
||||
{
|
||||
Con::printf(activityLog[i].c_str());
|
||||
}
|
||||
Con::printf("/***************/");
|
||||
#endif
|
||||
dumpActivityLog();
|
||||
|
||||
if (hasIssues)
|
||||
{
|
||||
|
|
@ -2631,8 +2716,15 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
|
|||
newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
|
||||
}
|
||||
|
||||
ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(assetItem->imageSuffixType.c_str());
|
||||
newAsset->setImageType(imageType);
|
||||
if (assetItem->typeHint != String::EmptyString)
|
||||
{
|
||||
newAsset->setImageType(ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str())));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(assetItem->imageSuffixType.c_str());
|
||||
newAsset->setImageType(imageType);
|
||||
}
|
||||
|
||||
Taml tamlWriter;
|
||||
bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
|
||||
|
|
@ -2697,7 +2789,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
|
|||
dSprintf(dependencyFieldName, 64, "imageMap%i", dependencySlotId);
|
||||
|
||||
char dependencyFieldDef[512];
|
||||
dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
|
||||
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
||||
|
||||
|
|
@ -2755,74 +2847,96 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
|
|||
FileObject* file = new FileObject();
|
||||
file->registerObject();
|
||||
|
||||
//Now write the script file containing our material out
|
||||
//There's 2 ways to do this. If we're in-place importing an existing asset, we can see if the definition existed already, like in an old
|
||||
//materials.tscript file. if it does, we can just find the object by name, and save it out to our new file
|
||||
//If not, we'll just generate one
|
||||
Material* existingMat = MATMGR->getMaterialDefinitionByName(assetName);
|
||||
|
||||
//It's also possible that, for legacy models, the material hooks in via the material's mapTo field, and the material name is something completely different
|
||||
//So we'll check for that as well if we didn't find it by name up above
|
||||
if (existingMat == nullptr)
|
||||
if (activeImportConfig->UseExistingMaterials && Platform::isFile(qualifiedFromFile))
|
||||
{
|
||||
existingMat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
||||
}
|
||||
//Now write the script file containing our material out
|
||||
//There's 2 ways to do this. If we're in-place importing an existing asset, we can see if the definition existed already, like in an old
|
||||
//materials.tscript file. if it does, we can just find the object by name, and save it out to our new file
|
||||
//If not, we'll just generate one
|
||||
Material* existingMat = MATMGR->getMaterialDefinitionByName(assetName);
|
||||
|
||||
if (existingMat)
|
||||
{
|
||||
for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
//It's also possible that, for legacy models, the material hooks in via the material's mapTo field, and the material name is something completely different
|
||||
//So we'll check for that as well if we didn't find it by name up above
|
||||
if (existingMat == nullptr)
|
||||
existingMat = MATMGR->getMaterialDefinitionByMapTo(assetName);
|
||||
|
||||
if (existingMat == nullptr && assetItem->assetName != assetItem->cleanAssetName)
|
||||
{
|
||||
AssetImportObject* childItem = assetItem->childAssetItems[i];
|
||||
|
||||
if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
|
||||
continue;
|
||||
|
||||
String path = childItem->filePath.getFullFileName();
|
||||
|
||||
String mapFieldName = "";
|
||||
String assetFieldName = "";
|
||||
|
||||
ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
|
||||
|
||||
if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
|
||||
{
|
||||
mapFieldName = "DiffuseMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Normal)
|
||||
{
|
||||
mapFieldName = "NormalMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::ORMConfig)
|
||||
{
|
||||
mapFieldName = "ORMConfig";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Metalness)
|
||||
{
|
||||
mapFieldName = "MetalnessMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::AO)
|
||||
{
|
||||
mapFieldName = "AOMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Roughness)
|
||||
{
|
||||
mapFieldName = "RoughnessMap";
|
||||
}
|
||||
|
||||
assetFieldName = mapFieldName + "Asset[0]";
|
||||
mapFieldName += "[0]";
|
||||
|
||||
//If there's already an existing image map file on the material definition in this slot, don't override it
|
||||
if(!path.isEmpty())
|
||||
existingMat->writeField(mapFieldName.c_str(), path.c_str());
|
||||
|
||||
String targetAsset = targetModuleId + ":" + childItem->assetName;
|
||||
|
||||
existingMat->writeField(assetFieldName.c_str(), targetAsset.c_str());
|
||||
existingMat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
|
||||
if (existingMat == nullptr)
|
||||
existingMat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
|
||||
}
|
||||
|
||||
if (existingMat)
|
||||
{
|
||||
PersistenceManager* persistMgr;
|
||||
if (Sim::findObject("ImageAssetValidator", persistMgr))
|
||||
{
|
||||
for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
|
||||
{
|
||||
AssetImportObject* childItem = assetItem->childAssetItems[i];
|
||||
|
||||
if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
|
||||
continue;
|
||||
|
||||
String path = childItem->filePath.getFullFileName();
|
||||
|
||||
String mapFieldName = "";
|
||||
String assetFieldName = "";
|
||||
|
||||
ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
|
||||
|
||||
if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
|
||||
{
|
||||
mapFieldName = "DiffuseMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Normal)
|
||||
{
|
||||
mapFieldName = "NormalMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::ORMConfig)
|
||||
{
|
||||
mapFieldName = "ORMConfig";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Metalness)
|
||||
{
|
||||
mapFieldName = "MetalnessMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::AO)
|
||||
{
|
||||
mapFieldName = "AOMap";
|
||||
}
|
||||
else if (imageType == ImageAsset::ImageTypes::Roughness)
|
||||
{
|
||||
mapFieldName = "RoughnessMap";
|
||||
}
|
||||
|
||||
assetFieldName = mapFieldName + "Asset[0]";
|
||||
mapFieldName += "[0]";
|
||||
|
||||
//If there's already an existing image map file on the material definition in this slot, don't override it
|
||||
if (!path.isEmpty())
|
||||
existingMat->writeField(mapFieldName.c_str(), path.c_str());
|
||||
|
||||
String targetAsset = targetModuleId + ":" + childItem->assetName;
|
||||
|
||||
existingMat->writeField(assetFieldName.c_str(), targetAsset.c_str());
|
||||
}
|
||||
|
||||
persistMgr->setDirty(existingMat);
|
||||
}
|
||||
else
|
||||
{
|
||||
Con::errorf("ImageAssetValidator not found!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Failed to find original material definition %s!", assetName);
|
||||
activityLog.push_back(importLogBuffer);
|
||||
return tamlPath;
|
||||
}
|
||||
existingMat->save(scriptPath.c_str());
|
||||
}
|
||||
//However, if we didn't find any existing material, then we'll want to go ahead and just write out a new one
|
||||
else if (file->openForWrite(scriptPath.c_str()))
|
||||
{
|
||||
file->writeLine((U8*)"//--- OBJECT WRITE BEGIN ---");
|
||||
|
|
@ -2939,7 +3053,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
newAsset->setShapeFile(shapeFileName.c_str());
|
||||
newAsset->setShapeConstructorFile(constructorFileName.c_str());
|
||||
|
||||
AssetImportConfig* cachedConfig = new AssetImportConfig();;
|
||||
AssetImportConfig* cachedConfig = new AssetImportConfig();
|
||||
cachedConfig->registerObject();
|
||||
activeImportConfig->CopyTo(cachedConfig);
|
||||
|
||||
|
|
@ -2971,7 +3085,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
dSprintf(dependencyFieldName, 64, "materialSlot%i", dependencySlotId);
|
||||
|
||||
char dependencyFieldDef[512];
|
||||
dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
|
||||
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
||||
|
||||
|
|
@ -2983,7 +3097,7 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
dSprintf(dependencyFieldName, 64, "animationSequence%i", dependencySlotId);
|
||||
|
||||
char dependencyFieldDef[512];
|
||||
dSprintf(dependencyFieldDef, 512, "@Asset=%s:%s", targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
|
||||
|
||||
newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
|
||||
|
||||
|
|
@ -3013,19 +3127,47 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
return "";
|
||||
}
|
||||
|
||||
if (!isInPlace && Platform::isFile(qualifiedFromCSFile))
|
||||
if (!isInPlace)
|
||||
{
|
||||
if(!dPathCopy(qualifiedFromCSFile, qualifiedToCSFile, !isReimport))
|
||||
if (Platform::isFile(qualifiedFromCSFile))
|
||||
{
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromCSFile);
|
||||
if (!dPathCopy(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
|
||||
{
|
||||
//We're doing an in-place import, so double check we've already got a constructor file in the expected spot
|
||||
if (Platform::isFile(qualifiedFromCSFile))
|
||||
{
|
||||
//Yup, found it, we're good to go
|
||||
makeNewConstructor = false;
|
||||
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", 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);
|
||||
//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 (Platform::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3036,10 +3178,10 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
activityLog.push_back(importLogBuffer);
|
||||
|
||||
//find/create shape constructor
|
||||
TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructor(Torque::Path(qualifiedToFile).getFullPath());
|
||||
TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructorByFilename(Torque::Path(qualifiedToFile).getFullPath());
|
||||
if (constructor == nullptr)
|
||||
{
|
||||
constructor = new TSShapeConstructor(qualifiedToFile);
|
||||
constructor = new TSShapeConstructor(StringTable->insert(qualifiedToFile));
|
||||
|
||||
String constructorName = assetItem->filePath.getFileName() + assetItem->filePath.getExtension().substr(0, 3);
|
||||
constructorName.replace(" ", "_");
|
||||
|
|
@ -3049,7 +3191,6 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
|
|||
constructor->registerObject(constructorName.c_str());
|
||||
}
|
||||
|
||||
|
||||
//now we write the import config logic into the constructor itself to ensure we load like we wanted it to
|
||||
String neverImportMats;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public:
|
|||
/// <summary>
|
||||
/// Duplicate Asset Auto-Resolution Action. Options are None, AutoPrune, AutoRename
|
||||
/// </summary>
|
||||
String DuplicatAutoResolution;
|
||||
String DuplicateAutoResolution;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if warnings should be treated as errors.
|
||||
|
|
@ -40,6 +40,11 @@ public:
|
|||
bool AutomaticallyPromptMissingFiles;
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Should the importer add the folder name as a prefix to the assetName. Helps prevent name collisions.
|
||||
/// </summary>
|
||||
bool AddDirectoryPrefixToAssetName;
|
||||
//
|
||||
//
|
||||
//Mesh Settings
|
||||
/// <summary>
|
||||
|
|
@ -531,6 +536,13 @@ public:
|
|||
/// </summary>
|
||||
GuiTreeViewCtrl* shapeInfo;
|
||||
|
||||
//
|
||||
/// <summary>
|
||||
/// A string that can hold a hint string to help the auto-import ensure the correct asset subtype is assigned.
|
||||
/// e.g. "GUI" would inform an image asset being imported that it should be flagged as a GUI image type
|
||||
/// </summary>
|
||||
String typeHint;
|
||||
|
||||
public:
|
||||
AssetImportObject();
|
||||
virtual ~AssetImportObject();
|
||||
|
|
@ -820,9 +832,10 @@ public:
|
|||
/// <summary>
|
||||
/// Runs the import process on a single file in-place. Intended primarily for autoimporting a loose file that's in the game directory.
|
||||
/// <para>@param filePath, The filePath of the file to be imported in as an asset</para>
|
||||
/// <para>@param typeHint, Optional. A string that provides a hint of the intended asset type. Such as an image being intended for GUI use.</para>
|
||||
/// <para>@return AssetId of the asset that was imported. If import failed, it will be empty.</para>
|
||||
/// </summary>
|
||||
StringTableEntry autoImportFile(Torque::Path filePath);
|
||||
StringTableEntry autoImportFile(Torque::Path filePath, String typeHint);
|
||||
|
||||
/// <summary>
|
||||
/// Runs the import process in the current session
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ DefineEngineMethod(AssetImporter, getActivityLogLine, String, (S32 i), (0),
|
|||
return object->getActivityLogLine(0);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, autoImportFile, String, (String path), (""),
|
||||
DefineEngineMethod(AssetImporter, autoImportFile, String, (String path, String typeHint), ("", ""),
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
{
|
||||
return object->autoImportFile(path);
|
||||
return object->autoImportFile(path, typeHint);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, addImportingFile, AssetImportObject*, (String path), (""),
|
||||
|
|
|
|||
|
|
@ -195,8 +195,8 @@ GuiControl* GuiInspectorTypeStateMachineAssetPtr::constructEditControl()
|
|||
dSprintf(szBuffer, sizeof(szBuffer), "StateMachineEditor.loadStateMachineAsset(%d.getText()); Canvas.pushDialog(StateMachineEditor);", retCtrl->getId());
|
||||
mSMEdButton->setField("Command", szBuffer);
|
||||
|
||||
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
|
||||
mSMEdButton->setBitmap(bitmapName);
|
||||
char bitmapName[512] = "ToolsModule:shape_editor_n_image";
|
||||
mSMEdButton->setBitmap(StringTable->insert(bitmapName));
|
||||
|
||||
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
|
||||
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue