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

491 lines
48 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
#ifndef SHAPE_ASSET_H
#define SHAPE_ASSET_H
#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
#ifndef _TSSHAPE_H_
#include "ts/tsShape.h"
#endif
#ifndef __RESOURCE_H__
#include "core/resource.h"
#endif
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
#ifndef MATERIALASSET_H
#include "MaterialAsset.h"
#endif
#ifndef SHAPE_ANIMATION_ASSET_H
#include "ShapeAnimationAsset.h"
#endif
#ifdef TORQUE_TOOLS
#include "gui/editor/guiInspectorTypes.h"
#endif
#ifndef _BITSTREAM_H_
#include "core/stream/bitStream.h"
#endif
#include "assetMacroHelpers.h"
//-----------------------------------------------------------------------------
class ShapeAsset : public AssetBase
{
typedef AssetBase Parent;
typedef AssetPtr<ShapeAsset> ConcreteAssetPtr;
public:
enum ShapeAssetErrCode
{
TooManyVerts = AssetErrCode::Extended,
TooManyBones,
MissingAnimatons,
Extended
};
static StringTableEntry smNoShapeAssetFallback;
static const String mErrCodeStrings[U32(ShapeAssetErrCode::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 > ShapeAssetErrCode::Extended) return "undefined error";
return mErrCodeStrings[errCode - Parent::Extended];
};
private:
StringTableEntry mShapeFile;
StringTableEntry mConstructorFileName;
StringTableEntry mDiffuseImposterFileName;
StringTableEntry mNormalImposterFileName;
//Material assets we're dependent on and use
Vector<StringTableEntry> mMaterialAssetIds;
Vector<AssetPtr<MaterialAsset>> mMaterialAssets;
//Animation assets we're dependent on and use
Vector<StringTableEntry> mAnimationAssetIds;
Vector<AssetPtr<ShapeAnimationAsset>> mAnimationAssets;
Resource<TSShape> mShape;
public:
ShapeAsset();
virtual ~ShapeAsset();
/// Set up some global script interface stuff.
static void consoleInit();
/// Engine.
static void initPersistFields();
void copyTo(SimObject* object) override;
virtual void setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value);
/// Declare Console Object.
DECLARE_CONOBJECT(ShapeAsset);
U32 load() override;
TSShape* getShape() { load(); return mShape; }
Resource<TSShape> getShapeResource() { load(); return mShape; }
void SplitSequencePathAndName(String& srcPath, String& srcName);
U32 getShapeFilenameHash() { return _StringTable::hashString(mShapeFile); }
Vector<AssetPtr<MaterialAsset>> getMaterialAssets() { return mMaterialAssets; }
inline AssetPtr<MaterialAsset> getMaterialAsset(U32 matId)
{
if (matId >= mMaterialAssets.size())
return NULL;
else
return mMaterialAssets[matId];
}
void clearMaterialAssets() { mMaterialAssets.clear(); }
void addMaterialAssets(AssetPtr<MaterialAsset> matPtr) { mMaterialAssets.push_back(matPtr); }
S32 getMaterialCount() { return mMaterialAssets.size(); }
S32 getAnimationCount() { return mAnimationAssets.size(); }
ShapeAnimationAsset* getAnimation(S32 index);
void _onResourceChanged(const Torque::Path& path);
void setShapeFile(const char* pScriptFile);
inline StringTableEntry getShapeFile(void) const { return mShapeFile; };
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector Adjusted expand behavior of guiTree to be more reliable Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields Removed redundant PreMult translucency type code Added setting of feature so probes work when in forward/basic lit mode Corrected indexing error in SQLiteObject class so it properly parses with the updated console API Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy Fixed var when trying to bind the camera to the client Added project setting field to dictate the default render mode between Forward or Deferred Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field Integrated DOF PostFX into updated PostFX Editor paradigm Updated setting group name for vignette postFX Shifted shaderCache to be in data/cache along with other cached files Added helper function to replace strings in a file Fixed ExampleCppObject asset to have correct loose file references Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default Fixed verve reference to root scene group Adjusted location of a nonmodal gui profile so it loads at the correct time Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful Initial work into zip and folder drag-and-drop asset importing support Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions Updated example asset type file Ensured all asset types have proper handling for move, rename and delete actions Fixed double-click behavior on folders in the AB Fixed CPP asset preview Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser Added ability to convert a non-module top-level folder in the AB into a module Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake Fixed convex editor's material handling to work with AB and reference back properly Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open Added some additional common text gui profiles Disabled calls to old editor settings logic in various editors to remove spam Added callOnModules call so tools can initialize properly when the world editor is opened Fixed logic test for visualizers Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 01:47:28 -06:00
void setShapeConstructorFile(const char* pScriptFile);
inline StringTableEntry getShapeConstructorFile(void) const { return mConstructorFileName; };
//Imposter images
void setDiffuseImposterFile(const char* pImageFile);
inline StringTableEntry getDiffuseImposterFile(void) const { return mDiffuseImposterFileName; };
void setNormalImposterFile(const char* pImageFile);
2025-06-20 17:13:20 +01:00
inline StringTableEntry getNormalImposterFile(void) const { return mNormalImposterFileName; };
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset);
static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
static U32 getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset);
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 09:47:38 -05:00
#ifdef TORQUE_TOOLS
const char* generateCachedPreviewImage(S32 resolution, String overrideMaterial = "");
#endif
protected:
// Asset Base callback
void initializeAsset(void) override;
void onAssetRefresh(void) override;
/// Taml callbacks.
void onTamlPreWrite(void) override;
void onTamlPostWrite(void) override;
protected:
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 writeShapeFile(void* obj, StringTableEntry pFieldName) { return static_cast<ShapeAsset*>(obj)->getShapeFile() != StringTable->EmptyString(); }
Updated path handling for loose asset files for CPP, Image, Level, Material, PostFX, Shape, Terrain, TerrainMat and StateMachine assets to be more predictable in when and how they expando the loose file path into a full, useable path Fixed loose file bindings for all associated slots in level asset, such as postFX file, decals, etc Expanded TSStatic onInspect testcase to parse materialSlots and hook-in a specialized material field for editing/quick reference from the inspector Adjusted expand behavior of guiTree to be more reliable Added internal name 'stack' to inspectorGroup's stack child objects for easier access to add programatic fields Removed redundant PreMult translucency type code Added setting of feature so probes work when in forward/basic lit mode Corrected indexing error in SQLiteObject class so it properly parses with the updated console API Tweaked the FOV setting logic in GameConnection::onControlObjectChange to not be spammy Fixed var when trying to bind the camera to the client Added project setting field to dictate the default render mode between Forward or Deferred Integrated MotionBlur PostFX into updated PostFX Editor paradigm and exposed the samples uniform as an editable field Integrated DOF PostFX into updated PostFX Editor paradigm Updated setting group name for vignette postFX Shifted shaderCache to be in data/cache along with other cached files Added helper function to replace strings in a file Fixed ExampleCppObject asset to have correct loose file references Adjusted editor default level logic so it can be modifed and then stored, as well as reset back to the original default Fixed verve reference to root scene group Adjusted location of a nonmodal gui profile so it loads at the correct time Reorganized AssetBrowser loading and refresh logic so it doesn't stack multiple refresh requests back-to-back causing lag Updated the search behavior to search not just the current address, but all child folders as well, making it far more useful Initial work into zip and folder drag-and-drop asset importing support Removed the import config setting for 'always display material maps' as it is redundant with the new importer context menu actions Updated example asset type file Ensured all asset types have proper handling for move, rename and delete actions Fixed double-click behavior on folders in the AB Fixed CPP asset preview Added better logic to discern if a top-level folder belongs to a module or not in the AB directory browser Added ability to convert a non-module top-level folder in the AB into a module Added initial hooks for being able to generate a new Editor Tool, similar to how the AB can generate modules Renamed CPP asset template files to have the .template so they aren't accidentally picked up by cmake Fixed convex editor's material handling to work with AB and reference back properly Updated AB images for folder up/down navigation buttons, and the breadcrumb divider arrow Made PostFX Editor properly allow for input pass-through so you can still edit the level with it open Added some additional common text gui profiles Disabled calls to old editor settings logic in various editors to remove spam Added callOnModules call so tools can initialize properly when the world editor is opened Fixed logic test for visualizers Added ability for cmake to scan tools directory for any tools that add source files
2020-02-04 01:47:28 -06:00
static bool setShapeConstructorFile(void* obj, const char* index, const char* data) { static_cast<ShapeAsset*>(obj)->setShapeConstructorFile(data); return false; }
static const char* getShapeConstructorFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeConstructorFile(); }
static bool setDiffuseImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setDiffuseImposterFile(data); return false; }
static const char* getDiffuseImposterFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getDiffuseImposterFile(); }
static bool setNormalImposterFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ShapeAsset*>(obj)->setNormalImposterFile(data); return false; }
2025-06-20 17:13:20 +01:00
static const char* getNormalImposterFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getNormalImposterFile(); }
};
DefineConsoleType(TypeShapeAssetId, String)
DECLARE_STRUCT(AssetPtr<ShapeAsset>)
DefineConsoleType(TypeShapeAssetPtr, AssetPtr<ShapeAsset>)
2022-06-13 12:38:08 -05:00
#ifdef TORQUE_TOOLS
//-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class
//-----------------------------------------------------------------------------
class GuiInspectorTypeShapeAssetPtr : public GuiInspectorTypeFileName
{
typedef GuiInspectorTypeFileName Parent;
public:
GuiTextCtrl* mLabel;
GuiBitmapButtonCtrl* mPreviewBorderButton;
GuiBitmapCtrl* mPreviewImage;
GuiButtonCtrl* mEditButton;
DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetPtr);
static void consoleInit();
GuiControl* constructEditControl() override;
bool updateRects() override;
void updateValue() override;
void updatePreviewImage();
void setPreviewImage(StringTableEntry assetId);
};
class GuiInspectorTypeShapeAssetId : public GuiInspectorTypeShapeAssetPtr
{
typedef GuiInspectorTypeShapeAssetPtr Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetId);
static void consoleInit();
};
#endif
//-----------------------------------------------------------------------------
// REFACTOR
//-----------------------------------------------------------------------------
#pragma region Refactor Asset Macros
#define DECLARE_SHAPEASSET_REFACTOR(className, name) \
private: \
AssetPtr<ShapeAsset> 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 shapeAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
shapeAssetId = query.mAssetList[0]; \
} \
else if (Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
shapeAssetId = ShapeAsset::getAssetIdByFilename(_in); \
if (shapeAssetId == ShapeAsset::smNoShapeAssetFallback) \
{ \
ShapeAsset* privateShape = new ShapeAsset(); \
privateShape->setShapeFile(_in); \
shapeAssetId = AssetDatabase.addPrivateAsset(privateShape); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
shapeAssetId = ShapeAsset::smNoShapeAssetFallback; \
} \
m##name##Asset = shapeAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
}; \
\
inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); } \
TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> 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->getShapeFile() : ""; }
#define DECLARE_SHAPEASSET_NET_REFACTOR(className, name, mask) \
private: \
AssetPtr<ShapeAsset> 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 shapeAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
shapeAssetId = query.mAssetList[0]; \
} \
else if (Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
shapeAssetId = ShapeAsset::getAssetIdByFilename(_in); \
if (shapeAssetId == ShapeAsset::smNoShapeAssetFallback) \
{ \
ShapeAsset* privateShape = new ShapeAsset(); \
privateShape->setShapeFile(_in); \
shapeAssetId = AssetDatabase.addPrivateAsset(privateShape); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
shapeAssetId = ShapeAsset::smNoShapeAssetFallback; \
} \
m##name##Asset = shapeAssetId; \
m##name##File = _in; \
} \
else \
{ \
m##name##Asset = _in; \
m##name##File = get##name##File(); \
} \
setMaskBits(mask); \
}; \
\
inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); } \
TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> 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->getShapeFile() : ""; }
#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
- Fixes the display of the preview in the MaterialAsset fields - Hides the special-case direct filepath field for ShapeAsset persist fields macro - Shifts the handling of TSStatics so the shape instance will load materials on the server as well as the client. This opens gameplay options as well as allowing rebaking of meshes functionality more easily - Expands AssetBase's isValidAsset utility function to actually check validity instead of just returning true - Adds isValid utility function to AssetPtr - Added new field flag that makes the field not write out to file - Removed legacy iconBitmap field from GuiIconButtonCtrl because it was causing errors - Fixed group filtering check of guiInspector to ignore case - Removed unneeded isFile checks for common datablock script files in Prototyping module script - Removed test datablocks from Prototyping module - Removed unnecessary container control from AssetBrowser - Adjusted preview regen logic of AssetBrowser so it doesn't trip if you're simply resizing the window - Fixed issue where row-vs-column layout logic for AssetBrowser when resizing window was fiddly - Added handling for when Dragging and Dropping datablock from AssetBrowser to spawn, it'll prompt if it spawns the actual object, or a spawnsphere that spawns said object. In the event of an PlayerData will also prompt if it should spawn an AIPlayer - Added ability to take a TSStatic that uses a baked down mesh and are able to restore it to the cache prefab, or trigger and in-place rebake to refresh it if something has changed in the original contents via RMB menu on the scene tree - Added ability to explode prefab to RMB menu on scene tree - Added ability to convert selection to prefab or bake to mesh in RMB menu on scene tree - Tweaked sizing of the DatablockEditorCreatePrompt window to not have cut off elements and easier to see/work with - Added sanity check to datablock editor creation - Fixed preview display of material in Decal Editor - Made compositeTextureEditor use the cached preview of images - Fixed sizing/spacing of gui selection dropdown as well as resolution dropdown of GuiEditor - Fixes MaterialEditor to properly save the group collapse state when editing - Adds ability to in-flow edit and create datablocks in the NavMesh Editor for the testing panel, and makes the datablock dropdown searchable - Fixed issue where opening the ShapeEditor via the edit button on a ShapeAsset field would cause the action buttons on the top bar to not show - Fixed error in shape editor where when exiting it was erroneously checking for a clear value of -1 rather than 0 - Removed unneeded top tabbook and tab page for main editor panel - Fixed issue where reset button of TerrainBrush Softness Curve editor didn't actually reset - Resized Object Builder window to not cut off elements and have enough width to show more data - Added a TypeCommand field type to Object Builder and changed spawnscript field of SpawnSphere to use it rather than a simple text edit field - Allow SpawnSphere in ObjectBuilder to be passed in spawn class and spawn datablock default info - Injects button to controllable objects when Inspecting them to make it easy to toggle if you're in control of it or not -
2025-08-25 23:35:28 -05:00
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.), AbstractClassRep::FIELD_HideInInspectors);
#define DECLARE_SHAPEASSET_ARRAY_REFACTOR(className, name, max) \
private: \
AssetPtr<ShapeAsset> 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 shapeAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
shapeAssetId = query.mAssetList[0]; \
} \
else if (Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
shapeAssetId = ShapeAsset::getAssetIdByFilename(_in); \
if (shapeAssetId == ShapeAsset::smNoShapeAssetFallback) \
{ \
ShapeAsset* privateShape = new ShapeAsset(); \
privateShape->setShapeFile(_in); \
shapeAssetId = AssetDatabase.addPrivateAsset(privateShape); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
shapeAssetId = ShapeAsset::smNoShapeAssetFallback; \
} \
m##name##Asset[index] = shapeAssetId; \
m##name##File[index] = _in; \
} \
else \
{ \
m##name##Asset[index] = _in; \
m##name##File[index] = get##name##File(index); \
} \
2025-06-19 14:10:00 +01:00
}; \
\
inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; } \
2025-06-19 14:10:00 +01:00
AssetPtr<ShapeAsset> 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]->getShapeFile() : ""; }
2025-06-19 14:10:00 +01:00
#define DECLARE_SHAPEASSET_ARRAY_NET_REFACTOR(className, name, max, mask) \
private: \
AssetPtr<ShapeAsset> 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())) \
2025-06-19 14:10:00 +01:00
{ \
m##name##Asset[index] = NULL; \
m##name##File[index] = ""; \
setMaskBits(mask); \
return; \
} \
if (!AssetDatabase.isDeclaredAsset(_in)) \
{ \
StringTableEntry shapeAssetId = StringTable->EmptyString(); \
AssetQuery query; \
S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); \
if (foundAssetcount != 0) \
{ \
shapeAssetId = query.mAssetList[0]; \
} \
else if (Torque::FS::IsFile(_in) || (_in[0] == '$' || _in[0] == '#')) \
{ \
shapeAssetId = ShapeAsset::getAssetIdByFilename(_in); \
if (shapeAssetId == ShapeAsset::smNoShapeAssetFallback) \
{ \
ShapeAsset* privateShape = new ShapeAsset(); \
privateShape->setShapeFile(_in); \
shapeAssetId = AssetDatabase.addPrivateAsset(privateShape); \
} \
} \
else \
{ \
Con::warnf("%s::%s: Could not find asset for: %s using fallback", #className, #name, _in); \
shapeAssetId = ShapeAsset::smNoShapeAssetFallback; \
} \
m##name##Asset[index] = shapeAssetId; \
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##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); } \
TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; } \
AssetPtr<ShapeAsset> 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]->getShapeFile() : ""; }
#define INITPERSISTFIELD_SHAPEASSET_ARRAY_REFACTOR(name, arraySize, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));\
addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, arraySize, assetDoc(name, asset docs.));
#pragma endregion
//-----------------------------------------------------------------------------
// REFACTOR END
//-----------------------------------------------------------------------------
#endif