Updates ImageAsset usage to utilize AssetRef, and standardizes the setter/getter functions and naming conventions, as well as the ability to use and bind named targets.

This commit is contained in:
JeffR 2026-06-16 17:39:30 -05:00
parent a858d8624e
commit 34e3f78a22
82 changed files with 1451 additions and 951 deletions

View file

@ -93,7 +93,9 @@ AccumulationVolume::~AccumulationVolume()
void AccumulationVolume::initPersistFields()
{
docsURL;
INITPERSISTFIELD_IMAGEASSET(Texture, AccumulationVolume, "Accumulation texture.")
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, AccumulationVolume))
.network(U32(-1))
.doc("Accumulation texture asset");
Parent::initPersistFields();
}
@ -229,7 +231,7 @@ U32 AccumulationVolume::packUpdate( NetConnection *connection, U32 mask, BitStre
if (stream->writeFlag(mask & InitialUpdateMask))
{
PACK_ASSET_REFACTOR(connection, Texture);
AssetDatabase.packUpdateAsset(connection, mask, stream, mTextureAssetRef.assetId);
}
return retMask;
@ -241,7 +243,7 @@ void AccumulationVolume::unpackUpdate( NetConnection *connection, BitStream *str
if (stream->readFlag())
{
UNPACK_ASSET_REFACTOR(connection, Texture);
mTextureAssetRef = AssetDatabase.unpackUpdateAsset(connection, stream);
//setTexture(mTextureName);
}
}
@ -256,7 +258,8 @@ void AccumulationVolume::inspectPostApply()
void AccumulationVolume::setTexture( const String& name )
{
_setTexture(StringTable->insert(name.c_str()));
mTextureAssetRef = StringTable->insert(name.c_str());
setMaskBits(-1);
refreshVolumes();
}

View file

@ -35,6 +35,8 @@
#include "gfx/gfxDevice.h"
#endif
#include "T3D/assets/ImageAsset.h"
/// A volume in space that blocks visibility.
class AccumulationVolume : public ScenePolyhedralSpace
{
@ -61,7 +63,7 @@ class AccumulationVolume : public ScenePolyhedralSpace
// SceneSpace.
void _renderObject( ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat ) override;
DECLARE_IMAGEASSET_NET(AccumulationVolume, Texture, GFXStaticTextureSRGBProfile, -1)
AssetRef<ImageAsset> mTextureAssetRef;
public:
@ -78,6 +80,8 @@ class AccumulationVolume : public ScenePolyhedralSpace
void inspectPostApply() override;
void setTexture( const String& name );
GFXTexHandle getTexture() { return mTextureAssetRef.notNull() ? mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
// Static Functions.
static void consoleInit();
static void initPersistFields();

View file

@ -65,7 +65,10 @@
//-----------------------------------------------------------------------------
StringTableEntry ImageAsset::smNoImageAssetFallback = NULL;
AssetPtr<ImageAsset> ImageAsset::smNoImageAssetFallbackAssetPtr = NULL;
StringTableEntry ImageAsset::smNamedTargetAssetFallback = NULL;
AssetPtr<ImageAsset> ImageAsset::smNamedTargetAssetFallbackAssetPtr = NULL;
//-----------------------------------------------------------------------------
@ -116,14 +119,93 @@ ConsoleSetType(TypeImageAssetPtr)
Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
IMPLEMENT_STRUCT(AssetRef<ImageAsset>, AssetRefImageAsset, , "")
END_IMPLEMENT_STRUCT
ConsoleType(ImageAssetRef, TypeImageAssetRef, AssetRef<ImageAsset>, ASSET_ID_FIELD_PREFIX)
ConsoleGetType(TypeImageAssetRef)
{
AssetRef<ImageAsset>& ref = *((AssetRef<ImageAsset>*)dptr);
if (ref.assetPtr.isNull())
return ref.assetId;
else
{
if ((ref.assetId[0] == '$' || ref.assetId[0] == '#'))
return ref.assetId;
return ref.assetPtr.getAssetId();
}
}
AssetPtr<ImageAsset> ImageAsset::getNamedTargetAssetPtr(StringTableEntry filePath)
{
// Do a lookup to see if we can find a hit on this path/id
// If not, then we'll register it as a private asset and keep going
// as if we're in this function, we're almost certainly dealing with
// a named target anyways and require the special case.
StringTableEntry imageAssetId = getAssetIdByFilename(filePath);
if (imageAssetId == smNoImageAssetFallback)
{
ImageAsset* privateImage = new ImageAsset();
privateImage->setImageFile(filePath);
imageAssetId = AssetDatabase.addPrivateAsset(privateImage);
}
AssetPtr<ImageAsset> assetPtr;
assetPtr = imageAssetId;
return assetPtr;
}
ConsoleSetType(TypeImageAssetRef)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
const char* pFieldValue = argv[0];
// Fetch asset pointer.
AssetRef<ImageAsset>* pAssetRef = (AssetRef<ImageAsset>*)(dptr);
// Is the asset pointer the correct type?
if (pAssetRef == NULL)
{
Con::warnf("(TypeImageAssetRef) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
StringTableEntry _in = StringTable->insert(pFieldValue);
if (ImageAsset::isNamedTarget(_in))
{
pAssetRef->assetId = _in;
pAssetRef->assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
return;
}
// Set asset.
*pAssetRef = _in;
return;
}
// Warn.
Con::warnf("(TypeImageAssetRef) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
// REFACTOR END
//-----------------------------------------------------------------------------
ImplementEnumType(ImageAssetType,
"Type of mesh data available in a shape.\n"
"Type of image data this asset describes.\n"
"@ingroup gameObjects")
{ ImageAsset::Albedo, "Albedo", "" },
{ ImageAsset::Albedo, "Albedo", "" },
{ ImageAsset::Normal, "Normal", "" },
{ ImageAsset::ORMConfig, "ORMConfig", "" },
{ ImageAsset::GUI, "GUI", "" },
@ -308,6 +390,26 @@ StringTableEntry ImageAsset::getAssetIdByFilename(StringTableEntry fileName)
return imageAssetId;
}
StringTableEntry ImageAsset::getAssetIdFromFilePath(StringTableEntry filePath)
{
if (filePath == StringTable->EmptyString())
return filePath;
// Already a valid asset id.
if (AssetDatabase.isDeclaredAsset(filePath))
return filePath;
StringTableEntry assetId = getAssetIdByFilename(filePath);
if (assetId == smNoImageAssetFallback)
{
ImageAsset* privateImage = new ImageAsset();
privateImage->setImageFile(filePath);
assetId = AssetDatabase.addPrivateAsset(privateImage);
}
return assetId;
}
U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset)
{
(*imageAsset) = assetId;
@ -318,8 +420,13 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
}
else
{
//Didn't work, so have us fall back to a placeholder asset
imageAsset->setAssetId(ImageAsset::smNoImageAssetFallback);
if (imageAsset->isNull())
{
//Well that's bad, loading the fallback failed.
Con::errorf("ImageAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
return AssetErrCode::Failed;
}
@ -352,6 +459,25 @@ void ImageAsset::initializeAsset(void)
Torque::FS::AddChangeNotification(mImageFile, this, &ImageAsset::_onResourceChanged);
populateImage();
//Make sure our fallbacks are valid
if (smNoImageAssetFallbackAssetPtr.isNull())
{
smNoImageAssetFallbackAssetPtr = smNoImageAssetFallback;
if (smNoImageAssetFallbackAssetPtr.isNull())
Con::errorf("ImageAsset::initializeAsset could not find fallback asset %s!", smNoImageAssetFallback);
else
smNoImageAssetFallbackAssetPtr->load();
}
if (smNamedTargetAssetFallbackAssetPtr.isNull())
{
smNamedTargetAssetFallbackAssetPtr = smNamedTargetAssetFallback;
if (smNamedTargetAssetFallbackAssetPtr.isNull())
Con::errorf("ImageAsset::initializeAsset could not find named target fallback asset %s!", smNamedTargetAssetFallback);
else
smNamedTargetAssetFallbackAssetPtr->load();
}
}
void ImageAsset::onAssetRefresh(void)
@ -470,23 +596,20 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
if (isNamedTarget())
{
GFXTexHandle tex;
AssetPtr<ImageAsset> fallbackAsset;
ImageAsset::getAssetById(smNamedTargetAssetFallback, &fallbackAsset);
if (getNamedTarget().isValid())
{
tex = getNamedTarget()->getTexture();
if (tex.isNull())
GFXTexHandle tex = getNamedTarget()->getTexture();
if (!tex.isNull())
{
return fallbackAsset->getTexture(requestedProfile);
mResourceMap.insert(requestedProfile, tex);
return tex;
}
mResourceMap.insert(requestedProfile, tex);
return tex;
}
else
{
return fallbackAsset->getTexture(requestedProfile);
}
if (smNamedTargetAssetFallbackAssetPtr.notNull())
return smNamedTargetAssetFallbackAssetPtr->getTexture(requestedProfile);
return NULL;
}
if (mLoadedState == Ok)
@ -501,6 +624,9 @@ GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
}
}
if (smNoImageAssetFallbackAssetPtr.notNull() && smNoImageAssetFallbackAssetPtr != this)
return smNoImageAssetFallbackAssetPtr->getTexture(requestedProfile);
return NULL;
}
@ -1047,4 +1173,21 @@ DefineEngineMethod(GuiInspectorTypeImageAssetPtr, setIsDeleteBtnVisible, void, (
{
object->setIsDeleteBtnVisible(isVisible);
}
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiInspectorTypeImageAssetRef);
ConsoleDocClass(GuiInspectorTypeImageAssetRef,
"@brief Inspector field type for AssetRef<ImageAsset> fields\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeImageAssetRef::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeImageAssetRef)->setInspectorFieldType("GuiInspectorTypeImageAssetRef");
}
#endif

View file

@ -114,7 +114,10 @@ public:
};
static StringTableEntry smNoImageAssetFallback;
static AssetPtr<ImageAsset> smNoImageAssetFallbackAssetPtr;
static StringTableEntry smNamedTargetAssetFallback;
static AssetPtr<ImageAsset> smNamedTargetAssetFallbackAssetPtr;
enum ImageAssetErrCode
{
@ -193,6 +196,17 @@ public:
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static StringTableEntry getAssetIdFromFilePath(StringTableEntry filePath);
/// Returns true if the given value follows the named target naming convention:
/// ($backBuffer, #color)
static bool isNamedTarget(StringTableEntry name) { return name != NULL && name != StringTable->EmptyString() && (name[0] == '$' || name[0] == '#'); }
/// Resolves a named render target ($backBuffer, #color) to an asset
/// pointer, binding/creating a private ImageAsset if needed.
static AssetPtr<ImageAsset> getNamedTargetAssetPtr(StringTableEntry filePath);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
@ -228,267 +242,8 @@ protected:
DECLARE_STRUCT(AssetPtr<ImageAsset>)
DefineConsoleType(TypeImageAssetPtr, AssetPtr<ImageAsset> )
DECLARE_STRUCT(AssetRef<ImageAsset>)
DefineConsoleType(TypeImageAssetRef, AssetRef<ImageAsset>)
typedef ImageAsset::ImageTypes ImageAssetType;
DefineEnumType(ImageAssetType);
#pragma region Refactor Asset Macros
#define DECLARE_IMAGEASSET(className, name, profile) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
StringTableEntry m##name##File = StringTable->EmptyString(); \
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
if(get##name##File() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset = NULL; \
m##name##File = ""; \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset = imageAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
}; \
\
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; } \
AssetPtr<ImageAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;} \
StringTableEntry get##name##File(){ return m##name##Asset.notNull() ? m##name##Asset->getImageFile() : ""; }
#define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset; \
StringTableEntry m##name##File = StringTable->EmptyString(); \
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
if(get##name##File() == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset = NULL; \
m##name##File = ""; \
setMaskBits(mask); \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset = imageAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
setMaskBits(mask); \
}; \
\
inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); } \
GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; } \
AssetPtr<ImageAsset> get##name##Asset(void) { return m##name##Asset; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;} \
StringTableEntry get##name##File(){ return m##name##Asset.notNull() ? m##name##Asset->getImageFile() : ""; }
#define INITPERSISTFIELD_IMAGEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.), AbstractClassRep::FIELD_HideInInspectors);
#define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
StringTableEntry m##name##File[max] = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
return; \
if(get##name##File(index) == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset[index] = NULL; \
m##name##File[index] = ""; \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset[index] = imageAssetId; \
m##name##File[index] = _in; \
} \
else \
{ \
m##name##Asset[index] = _in; \
m##name##File[index] = get##name##File(index); \
} \
}; \
\
inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
GFXTexHandle get##name(const U32& index) { return get##name(&profile, index); } \
GFXTexHandle get##name(GFXTextureProfile* requestedProfile, const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(requestedProfile) : NULL; }\
AssetPtr<ImageAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx){ return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getImageFile() : ""; }
#define DECLARE_IMAGEASSET_ARRAY_NET(className, name, profile, max, mask) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
StringTableEntry m##name##File[max] = {StringTable->EmptyString() }; \
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
return; \
if(get##name##File(index) == _in) \
return; \
if(_in == NULL || !String::compare(_in,StringTable->EmptyString())) \
{ \
m##name##Asset[index] = NULL; \
m##name##File[index] = ""; \
setMaskBits(mask); \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry imageAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
imageAssetId = ImageAsset::getAssetIdByFilename(_in); \
if (imageAssetId == ImageAsset::smNoImageAssetFallback) \
{ \
ImageAsset* privateImage = new ImageAsset(); \
privateImage->setImageFile(_in); \
imageAssetId = AssetDatabase.addPrivateAsset(privateImage); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
imageAssetId = ImageAsset::smNoImageAssetFallback; \
} \
m##name##Asset[index] = imageAssetId; \
m##name##File[index] = _in; \
} \
else \
{ \
m##name##Asset[index] = _in; \
m##name##File[index] = get##name##File(index); \
} \
setMaskBits(mask); \
}; \
\
inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
GFXTexHandle get##name(const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(&profile) : NULL; } \
GFXTexHandle get##name(GFXTextureProfile* requestedProfile, const U32& index) { return m##name##Asset[index].notNull() ? m##name##Asset[index]->getTexture(requestedProfile) : NULL; }\
AssetPtr<ImageAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; } \
static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
StringTableEntry get##name##File(const U32& idx){ return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getImageFile() : ""; }
#define INITPERSISTFIELD_IMAGEASSET_ARRAY(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeImageAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#define DEF_IMAGEASSET_ARRAY_BINDS(className,name, max)\
DefineEngineMethod(className, get##name, const char*, (S32 index), , "get name")\
{\
return object->get##name##Asset(index).notNull() ? object->get##name##Asset(index)->getImageFile() : ""; \
}\
DefineEngineMethod(className, get##name##Asset, const char*, (S32 index), , assetText(name, asset reference))\
{\
if(index >= max || index < 0)\
return "";\
return object->_get##name(index); \
}\
DefineEngineMethod(className, set##name, void, (const char* map, S32 index), , assetText(name,assignment. first tries asset then flat file.))\
{\
object->_set##name(StringTable->insert(map), index);\
}
#pragma endregion

View file

@ -51,4 +51,13 @@ public:
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetId);
static void consoleInit();
};
class GuiInspectorTypeImageAssetRef : public GuiInspectorTypeImageAssetPtr
{
typedef GuiInspectorTypeImageAssetPtr Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeImageAssetRef);
static void consoleInit();
};
#endif

View file

@ -685,7 +685,7 @@ void GuiInspectorTypeMaterialAssetPtr::setPreviewImage(StringTableEntry assetId)
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(assetId);
if (matAsset && matAsset->getMaterialDefinition())
{
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->_getDiffuseMap(0));
mPreviewImage->_setBitmap(matAsset->getMaterialDefinition()->getDiffuseMapAssetId(0));
}
}
}

View file

@ -2982,27 +2982,27 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
{
newMat->_setDiffuseMap(assetMapFillInStr,0);
newMat->setDiffuseMap(assetMapFillInStr,0);
}
else if (imageType == ImageAsset::ImageTypes::Normal)
{
newMat->_setNormalMap(assetMapFillInStr, 0);
newMat->setNormalMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::ORMConfig)
{
newMat->_setORMConfigMap(assetMapFillInStr, 0);
newMat->setORMConfigMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::Metalness)
{
newMat->_setMetalMap(assetMapFillInStr, 0);
newMat->setMetalMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::AO)
{
newMat->_setAOMap(assetMapFillInStr, 0);
newMat->setAOMap(assetMapFillInStr, 0);
}
else if (imageType == ImageAsset::ImageTypes::Roughness)
{
newMat->_setRoughMap(assetMapFillInStr, 0);
newMat->setRoughMap(assetMapFillInStr, 0);
hasRoughness = true;
}
}

View file

@ -149,7 +149,8 @@ void ParticleData::initPersistFields()
{
docsURL;
addGroup("Basic");
INITPERSISTFIELD_IMAGEASSET(Texture, ParticleData, "Texture to use for this particle.");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, ParticleData))
.doc("Texture asset to use for this particle");
addField("useInvAlpha", TYPEID< bool >(), Offset(useInvAlpha, ParticleData),
"@brief Controls how particles blend with the scene.\n\n"
"If true, particles blend like ParticleBlendStyle NORMAL, if false, "
@ -234,7 +235,8 @@ void ParticleData::initPersistFields()
endGroup("Over Time");
addGroup("AFX");
INITPERSISTFIELD_IMAGEASSET(TextureExt, ParticleData, "");
ADD_FIELD("textureExtAsset", TypeImageAssetRef, Offset(mTextureExtAssetRef, ParticleData))
.doc("");
addField("constrainPos", TypeBool, Offset(constrain_pos, ParticleData));
addFieldV("angle", TypeRangedF32, Offset(start_angle, ParticleData), &CommonValidators::DegreeRange);
addFieldV("angleVariance", TypeRangedF32, Offset(angle_variance, ParticleData), &CommonValidators::DegreeRange);
@ -299,7 +301,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeFloat( times[i], 8);
}
PACKDATA_ASSET_REFACTOR(Texture);
AssetDatabase.packDataAsset(stream, mTextureAssetRef.assetId);
for (i = 0; i < 4; i++)
mathWrite(*stream, texCoords[i]);
@ -313,7 +315,7 @@ void ParticleData::packData(BitStream* stream)
stream->writeInt(framesPerSec, 8);
}
PACKDATA_ASSET_REFACTOR(TextureExt);
AssetDatabase.packDataAsset(stream, mTextureExtAssetRef.assetId);
stream->writeFlag(constrain_pos);
stream->writeFloat(start_angle/360.0f, 11);
@ -384,7 +386,7 @@ void ParticleData::unpackData(BitStream* stream)
times[i] = stream->readFloat(8);
}
UNPACKDATA_ASSET_REFACTOR(Texture);
mTextureAssetRef = AssetDatabase.unpackDataAsset(stream);
for (i = 0; i < 4; i++)
mathRead(*stream, &texCoords[i]);
@ -397,7 +399,7 @@ void ParticleData::unpackData(BitStream* stream)
framesPerSec = stream->readInt(8);
}
UNPACKDATA_ASSET_REFACTOR(TextureExt);
mTextureExtAssetRef = AssetDatabase.unpackDataAsset(stream);
constrain_pos = stream->readFlag();
start_angle = 360.0f*stream->readFloat(11);
@ -669,6 +671,10 @@ bool ParticleData::preload(bool server, String &errorStr)
delete [] tokCopy;
numFrames = animTexFrames.size();
}
if (!mTextureAssetRef.isNull())
mTextureAssetRef.assetPtr->load();
}
return !error;
@ -773,12 +779,12 @@ ParticleData::ParticleData(const ParticleData& other, bool temp_clone) : SimData
animTexFramesString = other.animTexFramesString;
animTexFrames = other.animTexFrames; // -- parsed from animTexFramesString
CLONE_ASSET_REFACTOR(Texture);
mTextureAssetRef = other.mTextureAssetRef;
spinBias = other.spinBias;
randomizeSpinDir = other.randomizeSpinDir;
CLONE_ASSET_REFACTOR(TextureExt);
mTextureExtAssetRef = other.mTextureExtAssetRef;
constrain_pos = other.constrain_pos;
start_angle = other.start_angle;
@ -814,7 +820,16 @@ void ParticleData::onPerformSubstitutions()
reload(errorBuffer);
}
DEF_ASSET_BINDS_REFACTOR(ParticleData, Texture);
DefineEngineMethod(ParticleData, getTextureAsset, StringTableEntry, (), ,
"Texture asset reference")
{
return object->mTextureAssetRef.getAssetId();
}
DefineEngineMethod(ParticleData, setTexture, void, (const char* assetName), ,
"Texture assignment.")
{
object->mTextureAssetRef = StringTable->insert(assetName);
}
ConsoleType(stringList, TypeParticleList, Vector<StringTableEntry>, "")
@ -907,8 +922,8 @@ GuiControl* GuiInspectorTypeParticleDataList::constructEditControl()
mNewParticleBtn->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mNewParticleBtn->setDataField(StringTable->insert("tooltip"), NULL, "Add new particle slot");
mNewParticleBtn->setHorizSizing(horizResizeRight);
mNewParticleBtn->mMakeIconSquare = true;
mNewParticleBtn->mFitBitmapToButton = true;
mNewParticleBtn->setMakeIconSquare(true);
mNewParticleBtn->setFitBitmapToButton(true);
mNewParticleBtn->setExtent(20, 20);
char szBuffer[512];
@ -1003,8 +1018,8 @@ GuiControl* GuiInspectorTypeParticleDataList::_buildParticleEntryField(const S32
deleteSlotBtn->setDataField(StringTable->insert("tooltip"), NULL, "Delete this particle slot");
deleteSlotBtn->setHorizSizing(horizResizeRight);
deleteSlotBtn->setInternalName("deleteBtn");
deleteSlotBtn->mMakeIconSquare = true;
deleteSlotBtn->mFitBitmapToButton = true;
deleteSlotBtn->setMakeIconSquare(true);
deleteSlotBtn->setFitBitmapToButton(true);
deleteSlotBtn->setPosition(editExtent.x - 20, 0);
deleteSlotBtn->setExtent(20, 20);

View file

@ -87,7 +87,10 @@ class ParticleData : public SimDataBlock
StringTableEntry animTexFramesString;
Vector<U8> animTexFrames;
DECLARE_IMAGEASSET(ParticleData, Texture, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mTextureAssetRef;
GFXTexHandle getTexture() { return mTextureAssetRef.notNull() ? mTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getTextureAsset() { return mTextureAssetRef.assetPtr; }
static bool protectedSetSizes(void* object, const char* index, const char* data);
static bool protectedSetTimes(void* object, const char* index, const char* data);
@ -115,7 +118,9 @@ public:
F32 spinBias;
bool randomizeSpinDir;
public:
DECLARE_IMAGEASSET(ParticleData, TextureExt,GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mTextureExtAssetRef;
GFXTexHandle getTextureExt() { return mTextureExtAssetRef.notNull() ? mTextureExtAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
bool constrain_pos;
F32 start_angle;

View file

@ -142,7 +142,8 @@ void PrecipitationData::initPersistFields()
docsURL;
INITPERSISTFIELD_SOUNDASSET(Sound, PrecipitationData, "Looping SFXProfile effect to play while Precipitation is active.");
INITPERSISTFIELD_IMAGEASSET(Drop, PrecipitationData, "@brief Texture for drop particles.\n\n"
ADD_FIELD("DropAsset", TypeImageAssetRef, Offset(mDropAssetRef, PrecipitationData))
.doc("@brief Texture asset for drop particles.\n\n"
"The drop texture can contain several different drop sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each drop.");
@ -150,7 +151,8 @@ void PrecipitationData::initPersistFields()
addField( "dropShader", TypeString, Offset(mDropShaderName, PrecipitationData),
"The name of the shader used for raindrops." );
INITPERSISTFIELD_IMAGEASSET(Splash, PrecipitationData, "@brief Texture for splash particles.\n\n"
ADD_FIELD("SplashAsset", TypeImageAssetRef, Offset(mSplashAssetRef, PrecipitationData))
.doc("@brief Texture asset for splash particles.\n\n"
"The splash texture can contain several different splash sub-textures "
"arranged in a grid. There must be the same number of rows as columns. A "
"random frame will be chosen for each splash.");
@ -179,6 +181,12 @@ bool PrecipitationData::preload( bool server, String &errorStr )
{
//return false; -TODO: trigger asset download
}
if (!mDropAssetRef.isNull())
mDropAssetRef.assetPtr->load();
if (!mSplashAssetRef.isNull())
mSplashAssetRef.assetPtr->load();
}
return true;
@ -190,11 +198,11 @@ void PrecipitationData::packData(BitStream* stream)
PACKDATA_ASSET(Sound);
PACKDATA_ASSET_REFACTOR(Drop);
AssetDatabase.packDataAsset(stream, mDropAssetRef.assetId);
stream->writeString(mDropShaderName);
PACKDATA_ASSET_REFACTOR(Splash);
AssetDatabase.packDataAsset(stream, mSplashAssetRef.assetId);
stream->writeString(mSplashShaderName);
stream->write(mDropsPerSide);
@ -207,11 +215,11 @@ void PrecipitationData::unpackData(BitStream* stream)
UNPACKDATA_ASSET(Sound);
UNPACKDATA_ASSET_REFACTOR(Drop);
mDropAssetRef = AssetDatabase.unpackDataAsset(stream);
mDropShaderName = stream->readSTString();
UNPACKDATA_ASSET_REFACTOR(Splash);
mSplashAssetRef = AssetDatabase.unpackDataAsset(stream);
mSplashShaderName = stream->readSTString();
stream->read(&mDropsPerSide);

View file

@ -49,11 +49,17 @@ class PrecipitationData : public GameBaseData
DECLARE_SOUNDASSET(PrecipitationData, Sound);
DECLARE_ASSET_SETGET(PrecipitationData, Sound);
DECLARE_IMAGEASSET(PrecipitationData, Drop, GFXStaticTextureSRGBProfile) ///< Texture for drop particles
AssetRef<ImageAsset> mDropAssetRef;
GFXTexHandle getDrop() { return mDropAssetRef.notNull() ? mDropAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getDropAsset() { return mDropAssetRef.assetPtr; }
StringTableEntry mDropShaderName; ///< The name of the shader used for raindrops
DECLARE_IMAGEASSET(PrecipitationData, Splash, GFXStaticTextureSRGBProfile) ///< Texture for splash particles
AssetRef<ImageAsset> mSplashAssetRef;
GFXTexHandle getSplash() { return mSplashAssetRef.notNull() ? mSplashAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
AssetPtr<ImageAsset> getSplashAsset() { return mSplashAssetRef.assetPtr; }
StringTableEntry mSplashShaderName; ///< The name of the shader used for raindrops

View file

@ -128,7 +128,9 @@ void SplashData::initPersistFields()
addFieldV("times", TypeRangedF32, Offset(times, SplashData), &CommonValidators::NormalizedFloat, NUM_TIME_KEYS, "Times to transition through the splash effect. Up to 4 allowed. Values are 0.0 - 1.0, and corrispond to the life of the particle where 0 is first created and 1 is end of lifespace.\n" );
addField("colors", TypeColorF, Offset(colors, SplashData), NUM_TIME_KEYS, "Color values to set the splash effect, rgba. Up to 4 allowed. Will transition through colors based on values set in the times value. Example: colors[0] = \"0.6 1.0 1.0 0.5\".\n" );
INITPERSISTFIELD_IMAGEASSET_ARRAY(Texture, NUM_TEX, SplashData, "Image to use as the texture for the splash effect.\n");
ADD_FIELD("textureAsset", TypeImageAssetRef, Offset(mTextureAssetRef, SplashData))
.elements(NUM_TEX)
.doc("Image asset to use as the texture for the splash effect.\n");
addFieldV("texWrap", TypeRangedF32, Offset(texWrap, SplashData), &CommonValidators::NormalizedFloat, "Amount to wrap the texture around the splash ring, 0.0f - 1.0f.\n");
addFieldV("texFactor", TypeRangedF32, Offset(texFactor, SplashData), &CommonValidators::NormalizedFloat, "Factor in which to apply the texture to the splash ring, 0.0f - 1.0f.\n");
@ -195,7 +197,8 @@ void SplashData::packData(BitStream* stream)
stream->writeRangedU32(explosion->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
}
PACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
for (U32 i = 0; i < NUM_TEX; i++)
AssetDatabase.packDataAsset(stream, mTextureAssetRef[i].assetId);
S32 i;
for( i=0; i<NUM_EMITTERS; i++ )
@ -248,7 +251,8 @@ void SplashData::unpackData(BitStream* stream)
explosionId = stream->readRangedU32( DataBlockObjectIdFirst, DataBlockObjectIdLast );
}
UNPACKDATA_ASSET_ARRAY_REFACTOR(Texture, NUM_TEX);
for (U32 i = 0; i < NUM_TEX; i++)
mTextureAssetRef[i] = AssetDatabase.unpackDataAsset(stream);
U32 i;
for( i=0; i<NUM_EMITTERS; i++ )
@ -301,9 +305,9 @@ bool SplashData::preload(bool server, String &errorStr)
for( i=0; i<NUM_TEX; i++ )
{
if (mTextureAsset[i].isNull())
if (!mTextureAssetRef[i].isNull())
{
_setTexture(_getTexture(i), i);
mTextureAssetRef[i].assetPtr->load();
}
}
}

View file

@ -122,7 +122,7 @@ public:
F32 times[ NUM_TIME_KEYS ];
LinearColorF colors[ NUM_TIME_KEYS ];
DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, GFXStaticTextureSRGBProfile, NUM_TEX)
AssetRef<ImageAsset> mTextureAssetRef[NUM_TEX];
ExplosionData* explosion;
S32 explosionId;

View file

@ -62,7 +62,7 @@ void GameMode::initPersistFields()
addField("gameModeName", TypeString, Offset(mGameModeName, GameMode), "Human-readable name of the gamemode");
addField("description", TypeString, Offset(mGameModeDesc, GameMode), "Description of the gamemode");
INITPERSISTFIELD_IMAGEASSET(PreviewImage, GameMode, "Preview Image");
addField("previewImageAsset", TypeImageAssetRef, Offset(mPreviewImageAssetRef, GameMode), "Preview Image asset");
addField("active", TypeBool, Offset(mIsActive, GameMode), "Is the gamemode active");
addField("alwaysActive", TypeBool, Offset(mIsAlwaysActive, GameMode), "Is the gamemode always active");
@ -160,7 +160,7 @@ DefineEngineFunction(getGameModesList, ArrayObject*, (), , "")
GameMode* gm = dynamic_cast<GameMode*>(*itr);
if (gm)
{
dSprintf(activeValBuffer, 16, "%d", (gm->mIsActive || gm->mIsAlwaysActive));
dSprintf(activeValBuffer, 16, "%d", (gm->isActive() || gm->isAlwaysActive()));
dictionary->push_back(gm->getName(), activeValBuffer);
}
}

View file

@ -21,7 +21,7 @@ private:
StringTableEntry mGameModeName;
StringTableEntry mGameModeDesc;
DECLARE_IMAGEASSET(GameMode, PreviewImage, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mPreviewImageAssetRef;
bool mIsActive;
bool mIsAlwaysActive;
@ -40,6 +40,8 @@ public:
bool isAlwaysActive() { return mIsAlwaysActive; }
void setAlwaysActive(const bool& alwaysActive);
GFXTexHandle getPreviewImage() { return mPreviewImageAssetRef.notNull() ? mPreviewImageAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
DECLARE_CONOBJECT(GameMode);
static void findGameModes(const char* gameModeList, Vector<GameMode*>* outGameModes);

View file

@ -112,7 +112,7 @@ LevelInfo::LevelInfo()
LevelInfo::~LevelInfo()
{
LightManager::smActivateSignal.remove(this, &LevelInfo::_onLMActivate);
if (!mAccuTextureAsset.isNull())
if (!mAccuTextureAssetRef.isNull())
{
gLevelAccuMap.free();
}
@ -169,7 +169,8 @@ void LevelInfo::initPersistFields()
//addField( "advancedLightmapSupport", TypeBool, Offset( mAdvancedLightmapSupport, LevelInfo ),
// "Enable expanded support for mixing static and dynamic lighting (more costly)" );
INITPERSISTFIELD_IMAGEASSET(AccuTexture, LevelInfo, "Accumulation texture.");
ADD_FIELD("AccuTextureAsset", TypeImageAssetRef, Offset(mAccuTextureAssetRef, LevelInfo))
.doc("Accumulation texture asset");
endGroup( "Lighting" );
@ -219,7 +220,7 @@ U32 LevelInfo::packUpdate(NetConnection *conn, U32 mask, BitStream *stream)
sfxWrite( stream, mSoundAmbience );
stream->writeInt( mSoundDistanceModel, 4 );
PACK_ASSET_REFACTOR(conn, AccuTexture);
AssetDatabase.packUpdateAsset(conn, mask, stream, mAccuTextureAssetRef.assetId);
return retMask;
}
@ -268,7 +269,7 @@ void LevelInfo::unpackUpdate(NetConnection *conn, BitStream *stream)
SFX->setDistanceModel( mSoundDistanceModel );
}
UNPACK_ASSET_REFACTOR(conn, AccuTexture);
mAccuTextureAssetRef = AssetDatabase.unpackUpdateAsset(conn, stream);
setLevelAccuTexture();
}

View file

@ -106,7 +106,7 @@ class LevelInfo : public NetObject
void _onLMActivate(const char *lm, bool enable);
protected:
DECLARE_IMAGEASSET(LevelInfo, AccuTexture, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mAccuTextureAssetRef;
public:
@ -144,6 +144,8 @@ class LevelInfo : public NetObject
U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ) override;
void unpackUpdate( NetConnection *conn, BitStream *stream ) override;
void setLevelAccuTexture();
GFXTexHandle getAccuTexture() { return mAccuTextureAssetRef.notNull() ? mAccuTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
/// @}
};

View file

@ -159,7 +159,8 @@ void LightFlareData::initPersistFields()
addField( "flareEnabled", TypeBool, Offset( mFlareEnabled, LightFlareData ),
"Allows the user to disable this flare globally for any lights referencing it." );
INITPERSISTFIELD_IMAGEASSET(FlareTexture, LightFlareData, "The texture / sprite sheet for this flare.");
ADD_FIELD("flareTextureAsset", TypeImageAssetRef, Offset(mFlareTextureAssetRef, LightFlareData))
.doc("The texture / sprite sheet asset for this flare.");
addArray( "Elements", MAX_ELEMENTS );
@ -218,7 +219,7 @@ void LightFlareData::packData( BitStream *stream )
stream->writeFlag( mFlareEnabled );
PACKDATA_ASSET_REFACTOR(FlareTexture);
AssetDatabase.packDataAsset(stream, mFlareTextureAssetRef.assetId);
stream->write( mScale );
stream->write( mOcclusionRadius );
@ -243,7 +244,7 @@ void LightFlareData::unpackData( BitStream *stream )
mFlareEnabled = stream->readFlag();
UNPACKDATA_ASSET_REFACTOR(FlareTexture);
mFlareTextureAssetRef = AssetDatabase.unpackDataAsset(stream);
stream->read( &mScale );
stream->read( &mOcclusionRadius );

View file

@ -94,6 +94,8 @@ public:
void packData( BitStream *stream ) override;
void unpackData( BitStream *stream ) override;
GFXTexHandle getFlareTexture() { return mFlareTextureAssetRef.notNull() ? mFlareTextureAssetRef.assetPtr->getTexture(&GFXStaticTextureSRGBProfile) : NULL; }
/// Submits render instances for corona and flare effects.
void prepRender( SceneRenderState *state, LightFlareState *flareState );
@ -118,7 +120,7 @@ protected:
F32 mScale;
bool mFlareEnabled;
DECLARE_IMAGEASSET(LightFlareData, FlareTexture, GFXStaticTextureSRGBProfile)
AssetRef<ImageAsset> mFlareTextureAssetRef;
F32 mOcclusionRadius;
bool mRenderReflectPass;