mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
named targets for image assets
image assets can now be bound to a named texture target if used in a material the target needs to exist before the material is initialized
This commit is contained in:
parent
ad9da79e91
commit
85463c85ac
|
|
@ -111,7 +111,7 @@ ConsoleSetType(TypeImageAssetId)
|
|||
ImplementEnumType(ImageAssetType,
|
||||
"Type of mesh data available in a shape.\n"
|
||||
"@ingroup gameObjects")
|
||||
{ ImageAsset::Albedo, "Albedo", "" },
|
||||
{ ImageAsset::Albedo, "Albedo", "" },
|
||||
{ ImageAsset::Normal, "Normal", "" },
|
||||
{ ImageAsset::ORMConfig, "ORMConfig", "" },
|
||||
{ ImageAsset::GUI, "GUI", "" },
|
||||
|
|
@ -121,7 +121,8 @@ ImplementEnumType(ImageAssetType,
|
|||
{ ImageAsset::Glow, "Glow", "" },
|
||||
{ ImageAsset::Particle, "Particle", "" },
|
||||
{ ImageAsset::Decal, "Decal", "" },
|
||||
{ ImageAsset::Cubemap, "Cubemap", "" },
|
||||
{ ImageAsset::Cubemap, "Cubemap", "" },
|
||||
{ ImageAsset::Target, "Target", "" },
|
||||
|
||||
EndImplementEnumType;
|
||||
|
||||
|
|
@ -274,6 +275,21 @@ U32 ImageAsset::load()
|
|||
if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
|
||||
if (mImagePath)
|
||||
{
|
||||
// this is a target.
|
||||
if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
|
||||
{
|
||||
NamedTexTarget* namedTarget = NamedTexTarget::find(mImageFileName + 1);
|
||||
if (namedTarget) {
|
||||
mLoadedState = Ok;
|
||||
mIsValidImage = true;
|
||||
return mLoadedState;
|
||||
}
|
||||
else
|
||||
{
|
||||
Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Torque::FS::IsFile(mImagePath))
|
||||
{
|
||||
Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
|
||||
|
|
@ -295,12 +311,26 @@ void ImageAsset::initializeAsset()
|
|||
{
|
||||
ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
|
||||
|
||||
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
|
||||
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
|
||||
{
|
||||
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
mImagePath = mImageFileName;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageAsset::onAssetRefresh()
|
||||
{
|
||||
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
|
||||
if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
|
||||
{
|
||||
mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
mImagePath = mImageFileName;
|
||||
}
|
||||
|
||||
AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
|
||||
// Iterate all dependencies.
|
||||
|
|
@ -398,6 +428,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
|
|||
"Particle",
|
||||
"Decal",
|
||||
"Cubemap"
|
||||
"Target"
|
||||
};
|
||||
|
||||
if (type < 0 || type >= ImageTypeCount)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,11 @@
|
|||
#endif
|
||||
#ifndef _ASSET_PTR_H_
|
||||
#include "assets/assetPtr.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _MATTEXTURETARGET_H_
|
||||
#include "materials/matTextureTarget.h"
|
||||
#endif
|
||||
|
||||
#include "gfx/bitmap/gBitmap.h"
|
||||
#include "gfx/gfxTextureHandle.h"
|
||||
|
|
@ -71,7 +75,8 @@ public:
|
|||
Particle = 8,
|
||||
Decal = 9,
|
||||
Cubemap = 10,
|
||||
ImageTypeCount = 11
|
||||
Target = 11,
|
||||
ImageTypeCount = 12
|
||||
};
|
||||
|
||||
static StringTableEntry smNoImageAssetFallback;
|
||||
|
|
@ -205,8 +210,8 @@ public: \
|
|||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name = _in;\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
m##name##Name = _in;\
|
||||
m##name##AssetId = _in;\
|
||||
m##name##Asset = NULL;\
|
||||
m##name.free();\
|
||||
m##name = NULL;\
|
||||
|
|
@ -250,6 +255,16 @@ public: \
|
|||
m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
|
||||
}\
|
||||
\
|
||||
if (get##name()[0] == '$' || get##name()[0] == '#') {\
|
||||
NamedTexTarget* namedTarget = NamedTexTarget::find(get##name() + 1);\
|
||||
if (namedTarget)\
|
||||
{\
|
||||
m##name = namedTarget->getTexture(0);\
|
||||
m##name##Name = get##name();\
|
||||
m##name##AssetId = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
else\
|
||||
|
|
@ -278,7 +293,10 @@ public: \
|
|||
const StringTableEntry get##name() const\
|
||||
{\
|
||||
if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
|
||||
return Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
|
||||
if (m##name##Asset->getImageFileName()[0] == '#' || m##name##Asset->getImageFileName()[0] == '$')\
|
||||
return m##name##Asset->getImageFileName();\
|
||||
else\
|
||||
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())\
|
||||
|
|
@ -353,8 +371,8 @@ public: \
|
|||
}\
|
||||
else if(_in[0] == '$' || _in[0] == '#')\
|
||||
{\
|
||||
m##name##Name[index] = _in;\
|
||||
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||
m##name##Name[index] = _in;\
|
||||
m##name##AssetId[index] = _in;\
|
||||
m##name##Asset[index] = NULL;\
|
||||
m##name[index].free();\
|
||||
m##name[index] = NULL;\
|
||||
|
|
@ -393,6 +411,16 @@ public: \
|
|||
}\
|
||||
if (get##name(index) != StringTable->EmptyString() && m##name##Name[index] != StringTable->insert("texhandle"))\
|
||||
{\
|
||||
if (get##name(index)[0] == '$' || get##name(index)[0] == '#') {\
|
||||
NamedTexTarget* namedTarget = NamedTexTarget::find(get##name(index) + 1);\
|
||||
if (namedTarget)\
|
||||
{\
|
||||
m##name[index] = namedTarget->getTexture(0);\
|
||||
m##name##Name[index] = get##name(index);\
|
||||
m##name##AssetId[index] = StringTable->EmptyString();\
|
||||
}\
|
||||
}\
|
||||
else\
|
||||
m##name[index].set(get##name(index), m##name##Profile[index], avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
|
||||
}\
|
||||
else\
|
||||
|
|
@ -421,7 +449,10 @@ public: \
|
|||
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());\
|
||||
if (m##name##Asset[index]->getImageFileName()[0] == '#' || m##name##Asset[index]->getImageFileName()[0] == '$')\
|
||||
return m##name##Asset[index]->getImageFileName();\
|
||||
else\
|
||||
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())\
|
||||
|
|
|
|||
|
|
@ -410,12 +410,21 @@ void ProcessedMaterial::_setStageData()
|
|||
{
|
||||
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll
|
||||
//pass on the error rather than spamming the console
|
||||
if (!String(mMaterial->mDiffuseMapName[i]).startsWith("#"))
|
||||
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i);
|
||||
if (String(mMaterial->mDiffuseMapName[i]).startsWith("#") || String(mMaterial->mDiffuseMapName[i]).startsWith("$"))
|
||||
{
|
||||
NamedTexTarget* namedTarget = NamedTexTarget::find(mMaterial->mDiffuseMapName[i] + 1);
|
||||
if(namedTarget)
|
||||
mStages[i].setTex(MFT_DiffuseMap, namedTarget->getTexture(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String(mMaterial->mDiffuseMapName[i]).startsWith("#"))
|
||||
mMaterial->logError("Failed to load diffuse map %s for stage %i", mMaterial->mDiffuseMapName[i], i);
|
||||
|
||||
// Load a debug texture to make it clear to the user
|
||||
// that the texture for this stage was missing.
|
||||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||
// Load a debug texture to make it clear to the user
|
||||
// that the texture for this stage was missing.
|
||||
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue