mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-23 14:14:45 +00:00
Merge pull request #246 from Areloch/AssetImporterUpdate
Various improvements, fixes and expansions for Asset Importing
This commit is contained in:
commit
3cd5932cef
|
|
@ -45,6 +45,8 @@
|
|||
// Debug Profiling.
|
||||
#include "platform/profiler.h"
|
||||
|
||||
#include "T3D/assets/assetImporter.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(ImageAsset);
|
||||
|
|
@ -89,7 +91,7 @@ ImplementEnumType(ImageAssetType,
|
|||
"@ingroup gameObjects")
|
||||
{ ImageAsset::Albedo, "Albedo", "" },
|
||||
{ ImageAsset::Normal, "Normal", "" },
|
||||
{ ImageAsset::Composite, "Composite", "" },
|
||||
{ ImageAsset::PBRConfig, "PBRConfig", "" },
|
||||
{ ImageAsset::GUI, "GUI", "" },
|
||||
{ ImageAsset::Roughness, "Roughness", "" },
|
||||
{ ImageAsset::AO, "AO", "" },
|
||||
|
|
@ -138,8 +140,31 @@ bool ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAss
|
|||
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
|
||||
if (foundAssetcount == 0)
|
||||
{
|
||||
//Didn't find any assets, so have us fall back to a placeholder asset
|
||||
imageAsset->setAssetId(StringTable->insert("Core_Rendering:noshape"));
|
||||
//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"));
|
||||
|
||||
if (!imageAsset->isNull())
|
||||
return true;
|
||||
|
|
@ -154,6 +179,48 @@ bool ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAss
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
|
||||
{
|
||||
StringTableEntry imageAssetId = StringTable->EmptyString();
|
||||
|
||||
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
|
||||
{
|
||||
//acquire and bind the asset, and return it out
|
||||
imageAssetId = query.mAssetList[0];
|
||||
}
|
||||
|
||||
return imageAssetId;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void ImageAsset::copyTo(SimObject* object)
|
||||
{
|
||||
|
|
@ -243,16 +310,16 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
|
|||
{
|
||||
// must match ImageTypes order
|
||||
static const char* _names[] = {
|
||||
"Albedo"
|
||||
"Normal"
|
||||
"Composite"
|
||||
"GUI"
|
||||
"Roughness"
|
||||
"AO"
|
||||
"Metalness"
|
||||
"Glow"
|
||||
"Particle"
|
||||
"Decal"
|
||||
"Albedo",
|
||||
"Normal",
|
||||
"PBRConfig",
|
||||
"GUI",
|
||||
"Roughness",
|
||||
"AO",
|
||||
"Metalness",
|
||||
"Glow",
|
||||
"Particle",
|
||||
"Decal",
|
||||
"Cubemap"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public:
|
|||
{
|
||||
Albedo = 0,
|
||||
Normal = 1,
|
||||
Composite = 2,
|
||||
PBRConfig = 2,
|
||||
GUI = 3,
|
||||
Roughness = 4,
|
||||
AO = 5,
|
||||
|
|
@ -106,6 +106,9 @@ public:
|
|||
|
||||
void setImageType(ImageTypes type) { mImageType = type; }
|
||||
|
||||
bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
|
||||
StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
|
||||
|
||||
protected:
|
||||
virtual void initializeAsset(void);
|
||||
virtual void onAssetRefresh(void);
|
||||
|
|
@ -114,8 +117,6 @@ protected:
|
|||
static const char* getImageFileName(void* obj, const char* data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
|
||||
|
||||
void loadImage();
|
||||
|
||||
bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
|
||||
};
|
||||
|
||||
DefineConsoleType(TypeImageAssetPtr, ImageAsset)
|
||||
|
|
|
|||
|
|
@ -298,6 +298,19 @@ bool GuiInspectorTypeMaterialAssetPtr::updateRects()
|
|||
return resized;
|
||||
}
|
||||
|
||||
bool GuiInspectorTypeMaterialAssetPtr::resize(const Point2I& newPosition, const Point2I& newExtent)
|
||||
{
|
||||
if (!Parent::resize(newPosition, newExtent))
|
||||
return false;
|
||||
|
||||
if (mMatEdContainer != NULL)
|
||||
{
|
||||
return updateRects();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GuiInspectorTypeMaterialAssetPtr::setMaterialAsset(String assetId)
|
||||
{
|
||||
mTargetObject->setDataField(mCaption, "", assetId);
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ public:
|
|||
|
||||
virtual GuiControl* constructEditControl();
|
||||
virtual bool updateRects();
|
||||
virtual bool resize(const Point2I& newPosition, const Point2I& newExtent);
|
||||
void setMaterialAsset(String assetId);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ void ParticleAsset::copyTo(SimObject* object)
|
|||
IMPLEMENT_CONOBJECT(GuiInspectorTypeParticleAssetPtr);
|
||||
|
||||
ConsoleDocClass(GuiInspectorTypeParticleAssetPtr,
|
||||
"@brief Inspector field type for Partial Asset Objects\n\n"
|
||||
"@brief Inspector field type for Particle Asset Objects\n\n"
|
||||
"Editor use only.\n\n"
|
||||
"@internal"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ ConsoleSetType(TypePostEffectAssetPtr)
|
|||
PostEffectAsset::PostEffectAsset()
|
||||
{
|
||||
mScriptFile = StringTable->EmptyString();
|
||||
mHLSLShaderFile = StringTable->EmptyString();
|
||||
mGLSLShaderFile = StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -110,6 +112,10 @@ void PostEffectAsset::initPersistFields()
|
|||
|
||||
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, PostEffectAsset),
|
||||
&setScriptFile, &getScriptFile, "Path to the script file.");
|
||||
addProtectedField("hlslShader", TypeAssetLooseFilePath, Offset(mHLSLShaderFile, PostEffectAsset),
|
||||
&setHLSLShaderFile, &getHLSLShaderFile, "Path to the hlsl shader file.");
|
||||
addProtectedField("glslShader", TypeAssetLooseFilePath, Offset(mGLSLShaderFile, PostEffectAsset),
|
||||
&setGLSLShaderFile, &getGLSLShaderFile, "Path to the glsl shader file.");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
@ -123,6 +129,8 @@ void PostEffectAsset::copyTo(SimObject* object)
|
|||
void PostEffectAsset::initializeAsset()
|
||||
{
|
||||
mScriptFile = expandAssetFilePath(mScriptFile);
|
||||
mHLSLShaderFile = expandAssetFilePath(mHLSLShaderFile);
|
||||
mGLSLShaderFile = expandAssetFilePath(mGLSLShaderFile);
|
||||
|
||||
if (Platform::isFile(mScriptFile))
|
||||
Con::executeFile(mScriptFile, false, false);
|
||||
|
|
@ -131,6 +139,8 @@ void PostEffectAsset::initializeAsset()
|
|||
void PostEffectAsset::onAssetRefresh()
|
||||
{
|
||||
mScriptFile = expandAssetFilePath(mScriptFile);
|
||||
mHLSLShaderFile = expandAssetFilePath(mHLSLShaderFile);
|
||||
mGLSLShaderFile = expandAssetFilePath(mGLSLShaderFile);
|
||||
|
||||
if (Platform::isFile(mScriptFile))
|
||||
Con::executeFile(mScriptFile, false, false);
|
||||
|
|
@ -154,3 +164,41 @@ void PostEffectAsset::setScriptFile(const char* pScriptFile)
|
|||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
void PostEffectAsset::setHLSLShaderFile(const char* pShaderFile)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pShaderFile != NULL, "Cannot use a NULL shader file.");
|
||||
|
||||
// Fetch image file.
|
||||
pShaderFile = StringTable->insert(pShaderFile);
|
||||
|
||||
// Ignore no change,
|
||||
if (pShaderFile == mHLSLShaderFile)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mHLSLShaderFile = pShaderFile;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
||||
void PostEffectAsset::setGLSLShaderFile(const char* pShaderFile)
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal(pShaderFile != NULL, "Cannot use a NULL shader file.");
|
||||
|
||||
// Fetch image file.
|
||||
pShaderFile = StringTable->insert(pShaderFile);
|
||||
|
||||
// Ignore no change,
|
||||
if (pShaderFile == mGLSLShaderFile)
|
||||
return;
|
||||
|
||||
// Update.
|
||||
mGLSLShaderFile = pShaderFile;
|
||||
|
||||
// Refresh the asset.
|
||||
refreshAsset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ class PostEffectAsset : public AssetBase
|
|||
typedef AssetBase Parent;
|
||||
|
||||
StringTableEntry mScriptFile;
|
||||
StringTableEntry mHLSLShaderFile;
|
||||
StringTableEntry mGLSLShaderFile;
|
||||
|
||||
public:
|
||||
PostEffectAsset();
|
||||
|
|
@ -59,6 +61,11 @@ public:
|
|||
void setScriptFile(const char* pScriptFile);
|
||||
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
|
||||
|
||||
void setHLSLShaderFile(const char* pShaderFile);
|
||||
inline StringTableEntry getHLSLShaderFile(void) const { return mHLSLShaderFile; };
|
||||
void setGLSLShaderFile(const char* pShaderFile);
|
||||
inline StringTableEntry getGLSLShaderFile(void) const { return mGLSLShaderFile; };
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(PostEffectAsset);
|
||||
|
||||
|
|
@ -68,6 +75,11 @@ protected:
|
|||
|
||||
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<PostEffectAsset*>(obj)->setScriptFile(data); return false; }
|
||||
static const char* getScriptFile(void* obj, const char* data) { return static_cast<PostEffectAsset*>(obj)->getScriptFile(); }
|
||||
|
||||
static bool setHLSLShaderFile(void* obj, const char* index, const char* data) { static_cast<PostEffectAsset*>(obj)->setHLSLShaderFile(data); return false; }
|
||||
static const char* getHLSLShaderFile(void* obj, const char* data) { return static_cast<PostEffectAsset*>(obj)->getHLSLShaderFile(); }
|
||||
static bool setGLSLShaderFile(void* obj, const char* index, const char* data) { static_cast<PostEffectAsset*>(obj)->setGLSLShaderFile(data); return false; }
|
||||
static const char* getGLSLShaderFile(void* obj, const char* data) { return static_cast<PostEffectAsset*>(obj)->getGLSLShaderFile(); }
|
||||
};
|
||||
|
||||
DefineConsoleType(TypePostEffectAssetPtr, PostEffectAsset)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -403,6 +403,11 @@ public:
|
|||
/// </summary>
|
||||
Torque::Path filePath;
|
||||
|
||||
/// <summary>
|
||||
/// What is the source file path of the importing asset in string form
|
||||
/// </summary>
|
||||
StringTableEntry filePathString;
|
||||
|
||||
/// <summary>
|
||||
/// What is the asset's name
|
||||
/// </summary>
|
||||
|
|
@ -486,11 +491,23 @@ public:
|
|||
AssetImportObject();
|
||||
virtual ~AssetImportObject();
|
||||
|
||||
bool onAdd();
|
||||
void onRemove();
|
||||
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(AssetImportObject);
|
||||
|
||||
static bool _setFilePath(void* obj, const char* index, const char* data);
|
||||
|
||||
void setFilePath(StringTableEntry pFilePath);
|
||||
|
||||
bool operator == (const AssetImportObject& o) const
|
||||
{
|
||||
return o.getId() == this->getId();
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -551,6 +568,11 @@ class AssetImporter : public SimObject
|
|||
/// </summary>
|
||||
char importLogBuffer[1024];
|
||||
|
||||
/// <summary>
|
||||
/// only used for passing up the result of an import action for a script-side handled type
|
||||
/// </summary>
|
||||
String finalImportedAssetPath;
|
||||
|
||||
public:
|
||||
AssetImporter();
|
||||
virtual ~AssetImporter();
|
||||
|
|
@ -574,6 +596,13 @@ public:
|
|||
/// </summary>
|
||||
AssetImportObject* addImportingFile(Torque::Path filePath);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an existing AssetImportObject to our import session. Generally this would be created in a script somewhere
|
||||
/// <para>@param assetItem, The asset item to be added to the import session</para>
|
||||
/// <para>@param parentItem (Optional), The asset item that will be the parent of the assetItem being added</para>
|
||||
/// </summary>
|
||||
void addImportingAssetItem(AssetImportObject* assetItem, AssetImportObject* parentItem);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an importing asset to the current session
|
||||
/// <para>@param assetType, Type of the asset being imported</para>
|
||||
|
|
@ -623,8 +652,9 @@ public:
|
|||
/// <summary>
|
||||
/// Resets the import session to a clean slate. This will clear all existing AssetImportObjects and the activity log
|
||||
/// and then re-process the original filePaths again.
|
||||
/// <para>@param hardClearSession, Defaults to false. If true, will also clear the original filePaths</para>
|
||||
/// </summary>
|
||||
void resetImportSession();
|
||||
void resetImportSession(bool hardClearSession = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of lines in the activity log
|
||||
|
|
@ -774,4 +804,32 @@ public:
|
|||
/// <para>@return Current AssetImportConfig the importer is using</para>
|
||||
/// </summary>
|
||||
AssetImportConfig* getImportConfig() { return &activeImportConfig; }
|
||||
|
||||
//
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
static inline String findImagePath(const String &testPath)
|
||||
{
|
||||
|
||||
String imagePath;
|
||||
if (Platform::isFile(testPath + String(".jpg")))
|
||||
imagePath = testPath + String(".jpg");
|
||||
else if (Platform::isFile(testPath + String(".png")))
|
||||
imagePath = testPath + String(".png");
|
||||
else if (Platform::isFile(testPath + String(".dds")))
|
||||
imagePath = testPath + String(".dds");
|
||||
else if (Platform::isFile(testPath + String(".tif")))
|
||||
imagePath = testPath + String(".tif");
|
||||
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
static inline const char* makeFullPath(const String& path)
|
||||
{
|
||||
char qualifiedFilePath[2048];
|
||||
|
||||
Platform::makeFullPathName(path.c_str(), qualifiedFilePath, sizeof(qualifiedFilePath));
|
||||
|
||||
return qualifiedFilePath;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ DefineEngineMethod(AssetImporter, setTargetPath, void, (String path), (""),
|
|||
return object->setTargetPath(path);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, resetImportSession, void, (), ,
|
||||
DefineEngineMethod(AssetImporter, resetImportSession, void, (bool forceResetSession), (false),
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
{
|
||||
return object->resetImportSession();
|
||||
return object->resetImportSession(forceResetSession);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, dumpActivityLog, void, (), ,
|
||||
|
|
@ -61,6 +61,13 @@ DefineEngineMethod(AssetImporter, addImportingFile, AssetImportObject*, (String
|
|||
return object->addImportingFile(path);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, addImportingAssetItem, void, (AssetImportObject* assetItem, AssetImportObject* parentItem), (nullAsType< AssetImportObject*>(), nullAsType< AssetImportObject*>()),
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
{
|
||||
return object->addImportingAssetItem(assetItem, parentItem);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, processImportingAssets, void, (), ,
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
|
|
@ -123,6 +130,12 @@ DefineEngineMethod(AssetImporter, getAssetItemChild, AssetImportObject*, (AssetI
|
|||
return object->getAssetItemChild(assetItem, index);
|
||||
}
|
||||
|
||||
DefineEngineMethod(AssetImporter, deleteImportingAsset, void, (AssetImportObject* assetItem), (nullAsType< AssetImportObject*>()),
|
||||
"Creates a new script asset using the targetFilePath.\n"
|
||||
"@return The bool result of calling exec")
|
||||
{
|
||||
return object->deleteImportingAsset(assetItem);
|
||||
}
|
||||
|
||||
/*DefineEngineFunction(enumColladaForImport, bool, (const char* shapePath, const char* ctrl, bool loadCachedDts), ("", "", true),
|
||||
"(string shapePath, GuiTreeViewCtrl ctrl) Collect scene information from "
|
||||
|
|
|
|||
Loading…
Reference in a new issue