Torque3D/Engine/source/T3D/assets/ImageAsset.h

484 lines
45 KiB
C
Raw Normal View History

#pragma once
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#pragma once
#ifndef _ASSET_BASE_H_
#include "assets/assetBase.h"
#endif
#ifndef _ASSET_DEFINITION_H_
#include "assets/assetDefinition.h"
#endif
#ifndef _STRINGUNIT_H_
#include "string/stringUnit.h"
#endif
#ifndef _ASSET_FIELD_TYPES_H_
#include "assets/assetFieldTypes.h"
#endif
Updated Assimp Added initial behavior for ImageAssets to hold a list of GFX resources of different texture profiles to avoid mem leaks with incorrect-typed usages Added function to ImageAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Added function to ShapeAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Disabled fields for dynamic and static shadowmap refresh rates Moved noShape model to core/rendering/shapes to place it in a more logical module position Added an include to avoid undefined type compile error and removed unneeded semicolon from zone code Added call to reload probe textures when a reloadTextures call is made Adjusted default directional light shadowmap settings to not be as extreme Added utility function to probe manager to allow any class to request a 'best fit' list of probes that would affect a given location, allowing other classes such as fog or particles to utilize IBL. Also updated probeManager's forward rendering to utilize same function to reduce code duplication. Shifted shape loader code to utilize assimp for loader consistency and testing Changed render bin used for SSAO postfx so it runs at the right time Made Core_Rendering module scan for assets Updated loose file references to a number of assets to follow proper formatting Refactored asset import code to follow a more consistent object heirarchy structure on importing assets, allowing more reliable cross-referencing between inbound items Updated asset import logic for materials/images so that they properly utilize ImageType. Images correctly save out the assigned image type, materials reference the images' type to know what map slot they should be used in. Importer logic also updated to better find-and-add associated images based on type. Cleaned up a bunch of old, outdated code in the asset importer Added initial handling for in-place importing of files without needing to process them through the UI. Added ability to edit module script from RMB context menu if torsion path is set Updated list field code for variable inspector to utilize correct ownerObject field
2020-03-19 14:47:38 +00:00
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
2024-12-14 01:18:46 +00:00
#endif
#ifndef _GBITMAP_H_
#include "gfx/bitmap/gBitmap.h"
#endif
#ifndef _GFXTEXTUREHANDLE_H_
#include "gfx/gfxTextureHandle.h"
#endif
#ifndef _NETCONNECTION_H_
#include "sim/netConnection.h"
#endif
#ifndef _GFXDEVICE_H_
#include "gfx/gfxDevice.h"
#endif
2024-12-14 01:18:46 +00:00
#ifndef _MATTEXTURETARGET_H_
#include "materials/matTextureTarget.h"
#endif
#include "assetMacroHelpers.h"
//-----------------------------------------------------------------------------
class ImageAsset : public AssetBase
{
typedef AssetBase Parent;
typedef AssetPtr<ImageAsset> ConcreteAssetPtr;
public:
typedef HashMap<GFXTextureProfile*, GFXTexHandle> ImageTextureMap;
/// The different types of image use cases
enum ImageTypes
{
Albedo = 0,
Normal = 1,
2020-09-30 18:51:12 +00:00
ORMConfig = 2,
GUI = 3,
Roughness = 4,
AO = 5,
Metalness = 6,
Glow = 7,
Particle = 8,
Decal = 9,
Cubemap = 10,
2024-12-14 01:18:46 +00:00
ImageTypeCount = 11
};
2024-12-21 11:16:55 +00:00
class Frame
{
public:
Frame(const S32 pixelOffsetX, const S32 pixelOffsetY,
const U32 pixelWidth, const U32 pixelHeight,
const F32 texelWidthScale, const F32 texelHeightScale,
StringTableEntry inRegionName = StringTable->EmptyString())
: regionName(inRegionName)
{
pixelOffset.set(pixelOffsetY, pixelOffsetY);
pixelSize.set(pixelWidth, pixelHeight);
texelLower.set(pixelOffsetX * texelWidthScale, pixelOffsetY * texelHeightScale);
texelSize.set(pixelWidth * texelWidthScale, pixelHeight * texelHeightScale);
texelUpper.set(texelLower.x + texelSize.x, texelLower.y + texelSize.y);
}
void setFlip(bool flipX, bool flipY)
{
if (flipX) mSwap(texelLower.x, texelUpper.x);
if (flipY) mSwap(texelLower.y, texelUpper.y);
}
Point2I pixelOffset;
Point2I pixelSize;
Point2F texelLower;
Point2F texelUpper;
Point2F texelSize;
StringTableEntry regionName;
};
static StringTableEntry smNoImageAssetFallback;
static StringTableEntry smNamedTargetAssetFallback;
enum ImageAssetErrCode
{
TooManyMips = AssetErrCode::Extended,
Extended
};
static const String mErrCodeStrings[U32(ImageAssetErrCode::Extended) - U32(Parent::Extended) + 1];
static U32 getAssetErrCode(ConcreteAssetPtr checkAsset) { if (checkAsset) return checkAsset->mLoadedState; else return 0; }
static String getAssetErrstrn(U32 errCode)
{
if (errCode < Parent::Extended) return Parent::getAssetErrstrn(errCode);
if (errCode > ImageAssetErrCode::Extended) return "undefined error";
return mErrCodeStrings[errCode - Parent::Extended];
};
2024-12-21 11:16:55 +00:00
private:
2024-12-21 11:16:55 +00:00
StringTableEntry mImageFile;
bool mUseMips;
bool mIsHDRImage;
GFXTexHandle mTextureHandle;
ImageTypes mImageType;
ImageTextureMap mResourceMap;
2025-03-25 19:14:05 +00:00
bool mIsNamedTarget;
S32 mImageWidth;
S32 mImageHeight;
S32 mImageDepth;
S32 mImageChannels;
2024-12-21 11:16:55 +00:00
void generateTexture(void);
public:
ImageAsset();
virtual ~ImageAsset();
/// Set up some global script interface stuff.
static void consoleInit();
/// Engine.
static void initPersistFields();
2024-12-21 11:16:55 +00:00
/// Sim
bool onAdd() override;
void onRemove() override;
void copyTo(SimObject* object) override;
/// Declare Console Object.
DECLARE_CONOBJECT(ImageAsset);
void _onResourceChanged(const Torque::Path& path);
2024-12-21 11:16:55 +00:00
// asset Base load
U32 load() override;
2024-12-21 11:16:55 +00:00
void setImageFile(StringTableEntry pImageFile);
inline StringTableEntry getImageFile(void) const { return mImageFile; };
2025-03-27 18:33:37 +00:00
inline StringTableEntry getRelativeImageFile(void) const { return collapseAssetFilePath(mImageFile); };
2024-12-21 11:16:55 +00:00
void setGenMips(const bool pGenMips);
inline bool getGenMips(void) const { return mUseMips; };
2024-12-21 11:16:55 +00:00
void setTextureHDR(const bool pIsHDR);
inline bool getTextureHDR(void) const { return mIsHDRImage; };
Updated Assimp Added initial behavior for ImageAssets to hold a list of GFX resources of different texture profiles to avoid mem leaks with incorrect-typed usages Added function to ImageAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Added function to ShapeAsset to get best-fit asset, allowing for fallbacks if the requested assetID is not found Disabled fields for dynamic and static shadowmap refresh rates Moved noShape model to core/rendering/shapes to place it in a more logical module position Added an include to avoid undefined type compile error and removed unneeded semicolon from zone code Added call to reload probe textures when a reloadTextures call is made Adjusted default directional light shadowmap settings to not be as extreme Added utility function to probe manager to allow any class to request a 'best fit' list of probes that would affect a given location, allowing other classes such as fog or particles to utilize IBL. Also updated probeManager's forward rendering to utilize same function to reduce code duplication. Shifted shape loader code to utilize assimp for loader consistency and testing Changed render bin used for SSAO postfx so it runs at the right time Made Core_Rendering module scan for assets Updated loose file references to a number of assets to follow proper formatting Refactored asset import code to follow a more consistent object heirarchy structure on importing assets, allowing more reliable cross-referencing between inbound items Updated asset import logic for materials/images so that they properly utilize ImageType. Images correctly save out the assigned image type, materials reference the images' type to know what map slot they should be used in. Importer logic also updated to better find-and-add associated images based on type. Cleaned up a bunch of old, outdated code in the asset importer Added initial handling for in-place importing of files without needing to process them through the UI. Added ability to edit module script from RMB context menu if torsion path is set Updated list field code for variable inspector to utilize correct ownerObject field
2020-03-19 14:47:38 +00:00
inline GFXTexHandle& getTexture(void) { load(); generateTexture(); return mTextureHandle; }
2024-12-21 11:16:55 +00:00
GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
static StringTableEntry getImageTypeNameFromType(ImageTypes type);
2024-12-21 11:16:55 +00:00
static ImageTypes getImageTypeFromName(StringTableEntry name);
2024-12-21 11:16:55 +00:00
void setImageType(ImageTypes type) { mImageType = type; }
ImageTypes getImageType() { return mImageType; }
inline U32 getTextureWidth(void) const { return isAssetValid() ? mTextureHandle->getWidth() : 0; }
inline U32 getTextureHeight(void) const { return isAssetValid() ? mTextureHandle->getHeight() : 0; }
inline U32 getTextureDepth(void) const { return isAssetValid() ? mTextureHandle->getDepth() : 0; }
2024-12-21 11:16:55 +00:00
inline U32 getTextureBitmapWidth(void) const { return mImageWidth; }
inline U32 getTextureBitmapHeight(void) const { return mImageHeight; }
inline U32 getTextureBitmapDepth(void) const { return mImageDepth; }
2024-12-21 11:16:55 +00:00
bool isAssetValid(void) const override { return !mTextureHandle.isNull(); }
2025-03-25 19:14:05 +00:00
bool isNamedTarget(void) const { return mIsNamedTarget; }
2025-03-25 18:22:26 +00:00
NamedTexTargetRef getNamedTarget(void) const { return NamedTexTarget::find(mImageFile + 1); }
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
Corrects lookup/in-place auto import logic for ImageAssets Fixed sizing issue for material asset ptr fields Fixed type of comment in Particle Asset Hooked GLSL and HLSL shader files to be proper asset loose files for PostEffectAsset Adjusted some default values for default ImportConfig Corrected field type of multiple fields for the importConfig Corrected loading of PopulateMaterialMaps config setting from config file Corrected field types of multiple fields for AssetImportObjects Exposed several utility fields for the Importer to script Added ability to create an AssetImportObject in script and add it to the Importer's current session Ensured stable naming behavior(replacing spaces, -, and . in names with _ Improved getAssetTypeByFile logical lookup so it doesn't accidentally grab cached.dts files Added ability to hard reset an import session, wiping all inbound files for a full reset Added ability to process DTS files to shape import so it can parse out content such as materials for associated asset imports Added better handling for shape materials that are just colors Added callback hook-in so if the importer doesn't have a defined function for importing a given asset type, it'll try calling down into the editor Stabilized imageAsset processing logic when generating a material for it Improved imageType lookup/processing logic in Importer Improved logic for binding in associated image files to materialAssets Improved logic for processing shapes to get related materials and images, ensuring better likelyhood of finding and associating related assets Cleaned up validation logic Added ability to properly look up the editor's default import config if it's set to be used for autoimport Improved handling of originalFilePath logic, so if it's an in-place import, it doesn't bother populating the field Set default UP axis value on shape importing to ensure better default behavior
2020-07-11 21:20:10 +00:00
2024-12-21 11:16:55 +00:00
const char* getImageInfo();
protected:
2024-12-21 11:16:55 +00:00
// Asset Base callback
void initializeAsset(void) override;
void onAssetRefresh(void) override;
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
void onTamlCustomWrite(TamlCustomNodes& customNodes) override;
void onTamlCustomRead(const TamlCustomNodes& customNodes) override;
2024-12-21 11:16:55 +00:00
protected:
// Texture file
static bool setImageFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFile(data); return false; }
static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFile(); }
static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getImageFile() != StringTable->EmptyString(); }
// Gen mips?
static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setGenMips(dAtob(data)); return false; }
static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getGenMips() == true; }
// Texture Is Hdr?
static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setTextureHDR(dAtob(data)); return false; }
static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getTextureHDR() == true; }
};
2024-12-21 11:16:55 +00:00
DECLARE_STRUCT(AssetPtr<ImageAsset>)
DefineConsoleType(TypeImageAssetPtr, AssetPtr<ImageAsset> )
2024-12-21 11:16:55 +00:00
typedef ImageAsset::ImageTypes ImageAssetType;
DefineEnumType(ImageAssetType);
2024-12-21 11:16:55 +00:00
#pragma region Refactor Asset Macros
#define DECLARE_IMAGEASSET(className, name, profile) \
2024-12-21 11:16:55 +00:00
private: \
AssetPtr<ImageAsset> m##name##Asset;\
String m##name##File;\
2024-12-21 11:16:55 +00:00
public: \
2024-12-21 12:23:57 +00:00
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
if(_in == NULL || _in == StringTable->EmptyString()) \
{ \
m##name##Asset = NULL; \
return; \
} \
2024-12-21 12:23:57 +00:00
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
2024-12-27 14:16:47 +00:00
StringTableEntry imageAssetId = StringTable->EmptyString(); \
2024-12-21 12:23:57 +00:00
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
imageAssetId = query.mAssetList[0]; \
} \
else if(Torque::FS::IsFile(_in)) \
{ \
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; \
} \
2024-12-21 12:23:57 +00:00
m##name##Asset = imageAssetId; \
} \
else \
{ \
m##name##Asset = _in; \
} \
}; \
2024-12-21 17:34:16 +00:00
\
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() : ""; }
2024-12-21 17:34:16 +00:00
#define DECLARE_IMAGEASSET_NET(className, name, profile, mask) \
2024-12-21 17:34:16 +00:00
private: \
AssetPtr<ImageAsset> m##name##Asset; \
String m##name##File;\
2024-12-21 17:34:16 +00:00
public: \
void _set##name(StringTableEntry _in){ \
if(m##name##Asset.getAssetId() == _in) \
return; \
if(_in == NULL || _in == StringTable->EmptyString()) \
{ \
m##name##Asset = NULL; \
setMaskBits(mask); \
return; \
} \
2024-12-21 17:34:16 +00:00
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
2024-12-27 14:16:47 +00:00
StringTableEntry imageAssetId = StringTable->EmptyString(); \
2024-12-21 17:34:16 +00:00
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; \
} \
2025-03-26 15:41:53 +00:00
m##name##Asset = imageAssetId; \
2024-12-21 17:34:16 +00:00
} \
else \
{ \
2025-03-26 15:41:53 +00:00
m##name##Asset = _in; \
2024-12-21 17:34:16 +00:00
} \
setMaskBits(mask); \
}; \
\
2024-12-21 11:16:55 +00:00
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() : ""; }
2024-12-21 11:16:55 +00:00
#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.));
2024-12-21 11:16:55 +00:00
#define DECLARE_IMAGEASSET_ARRAY(className, name, profile, max) \
private: \
AssetPtr<ImageAsset> m##name##Asset[max]; \
String m##name##File[max];\
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
return; \
if(_in == NULL || _in == StringTable->EmptyString()) \
{ \
m##name##Asset[index] = NULL; \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
2024-12-27 14:16:47 +00:00
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; \
} \
else \
{ \
m##name##Asset[index] = _in; \
} \
}; \
\
inline StringTableEntry _get##name(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
2025-03-25 19:14:05 +00:00
GFXTexHandle get##name(const U32& index) { return get##name(&profile, index); } \
2024-12-27 14:16:47 +00:00
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]; \
String m##name##File[max];\
public: \
void _set##name(StringTableEntry _in, const U32& index){ \
if(m##name##Asset[index].getAssetId() == _in) \
return; \
if(_in == NULL || _in == StringTable->EmptyString()) \
{ \
m##name##Asset[index] = NULL; \
setMaskBits(mask); \
return; \
} \
if(!AssetDatabase.isDeclaredAsset(_in)) \
{ \
2024-12-27 14:16:47 +00:00
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; \
} \
else \
{ \
m##name##Asset[index] = _in; \
} \
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; } \
2024-12-27 14:16:47 +00:00
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);\
}
2024-12-21 11:16:55 +00:00
#pragma endregion