ImageAsset.h
Engine/source/T3D/assets/ImageAsset.h
Classes:
Public Defines
define
assetText(x, suff) std::string(std::string(#x) + std::string(#suff)).c_str()
define
bindMapArraySlot(name, id) (m##name##AssetId[] != ) m##name##Asset[] = m##name##AssetId[];
define
bindMapSlot(name) (m##name##AssetId != ) m##name##Asset = m##name##AssetId;
define
DECLARE_TEXTUREARRAY(className, name, max) m##name##Filename[max];\ m##name##AssetId[max];\ <> m##name##Asset[max];\ static bool _set##name##AssetSlot(* obj, char* index, char* data)\ {\ className* mat = static_cast<className*>(obj);\ (!index) return false;\ = (index);\ ( >= max)\ return false;\ mat->m##name##AssetId[] = ->insert(data);\ ((mat->m##name##AssetId[], &mat->m##name##Asset[]))\ {\ (mat->m##name##Asset[].getAssetId() != ->insert("Core_Rendering:noMaterial"))\ {\ mat->m##name##Filename[] = ->EmptyString();\ }\ return true;\ }\ return true;\ }
define
DECLARE_TEXTUREMAP(className, name) protected: \ m##name##Filename;\ m##name##AssetId;\ <> m##name##Asset;\ public: \ & get##name() { return m##name##Filename; }\ set##name( _in) { m##name##Filename = _in; }\ <> & get##name##Asset() { return m##name##Asset; }\ set##name##Asset(<>_in) { m##name##Asset = _in; }\ static bool _set##name##Asset(* obj, char* index, char* data)\ {\ className* mat = static_cast<className*>(obj);\ mat->m##name##AssetId = ->insert(data);\ ((mat->m##name##AssetId, &mat->m##name##Asset))\ {\ (mat->m##name##Asset.getAssetId() != ->insert("Core_Rendering:noMaterial"))\ mat->m##name##Filename = ->EmptyString();\ return true;\ }\ return true;\ }
define
GET_TEXTUREASSET(name) get##name##Asset()
define
GET_TEXTUREMAP(name) get##name()
define
define
initMapArraySlot(name, id) m##name##Filename[] = ; m##name##AssetId[] = ->EmptyString(); m##name##Asset[] = ;
define
initMapSlot(name) m##name##Filename = ; m##name##AssetId = ->EmptyString(); m##name##Asset = ;
define
scriptBindMapArraySlot(name, arraySize, consoleClass, docs) addField(#name, TypeImageFilename, (m##name##Filename, consoleClass), arraySize, (name, docs)); \ addProtectedField((name,Asset), TypeImageAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##AssetSlot, &, arraySize, (name,asset reference.));
define
scriptBindMapSlot(name, consoleClass, docs) addField(#name, TypeImageFilename, (m##name##Filename, consoleClass), (name, docs)); \ addProtectedField((name, Asset), TypeImageAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & , (name, asset reference.));
define
SET_TEXTUREASSET(name, _in) set##name##Asset(_in)
define
SET_TEXTUREMAP(name, _in) set##name(_in)
Public Typedefs
ImageAssetType
Public Functions
DefineConsoleType(TypeImageAssetId , String )
DefineConsoleType(TypeImageAssetPtr , ImageAsset )
Detailed Description
Public Defines
assetText(x, suff) std::string(std::string(#x) + std::string(#suff)).c_str()
bindMapArraySlot(name, id) (m##name##AssetId[] != ) m##name##Asset[] = m##name##AssetId[];
bindMapSlot(name) (m##name##AssetId != ) m##name##Asset = m##name##AssetId;
DECLARE_TEXTUREARRAY(className, name, max) m##name##Filename[max];\ m##name##AssetId[max];\ <> m##name##Asset[max];\ static bool _set##name##AssetSlot(* obj, char* index, char* data)\ {\ className* mat = static_cast<className*>(obj);\ (!index) return false;\ = (index);\ ( >= max)\ return false;\ mat->m##name##AssetId[] = ->insert(data);\ ((mat->m##name##AssetId[], &mat->m##name##Asset[]))\ {\ (mat->m##name##Asset[].getAssetId() != ->insert("Core_Rendering:noMaterial"))\ {\ mat->m##name##Filename[] = ->EmptyString();\ }\ return true;\ }\ return true;\ }
DECLARE_TEXTUREMAP(className, name) protected: \ m##name##Filename;\ m##name##AssetId;\ <> m##name##Asset;\ public: \ & get##name() { return m##name##Filename; }\ set##name( _in) { m##name##Filename = _in; }\ <> & get##name##Asset() { return m##name##Asset; }\ set##name##Asset(<>_in) { m##name##Asset = _in; }\ static bool _set##name##Asset(* obj, char* index, char* data)\ {\ className* mat = static_cast<className*>(obj);\ mat->m##name##AssetId = ->insert(data);\ ((mat->m##name##AssetId, &mat->m##name##Asset))\ {\ (mat->m##name##Asset.getAssetId() != ->insert("Core_Rendering:noMaterial"))\ mat->m##name##Filename = ->EmptyString();\ return true;\ }\ return true;\ }
GET_TEXTUREASSET(name) get##name##Asset()
GET_TEXTUREMAP(name) get##name()
IMAGE_ASSET_H()
initMapArraySlot(name, id) m##name##Filename[] = ; m##name##AssetId[] = ->EmptyString(); m##name##Asset[] = ;
initMapSlot(name) m##name##Filename = ; m##name##AssetId = ->EmptyString(); m##name##Asset = ;
scriptBindMapArraySlot(name, arraySize, consoleClass, docs) addField(#name, TypeImageFilename, (m##name##Filename, consoleClass), arraySize, (name, docs)); \ addProtectedField((name,Asset), TypeImageAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##AssetSlot, &, arraySize, (name,asset reference.));
scriptBindMapSlot(name, consoleClass, docs) addField(#name, TypeImageFilename, (m##name##Filename, consoleClass), (name, docs)); \ addProtectedField((name, Asset), TypeImageAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & , (name, asset reference.));
SET_TEXTUREASSET(name, _in) set##name##Asset(_in)
SET_TEXTUREMAP(name, _in) set##name(_in)
Public Typedefs
typedef ImageAsset::ImageTypes ImageAssetType
Public Functions
DefineConsoleType(TypeImageAssetId , String )
DefineConsoleType(TypeImageAssetPtr , ImageAsset )
DefineEnumType(ImageAssetType )
1 2#pragma once 3//----------------------------------------------------------------------------- 4// Copyright (c) 2013 GarageGames, LLC 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#ifndef IMAGE_ASSET_H 25#define IMAGE_ASSET_H 26 27#ifndef _ASSET_BASE_H_ 28#include "assets/assetBase.h" 29#endif 30 31#ifndef _ASSET_DEFINITION_H_ 32#include "assets/assetDefinition.h" 33#endif 34 35#ifndef _STRINGUNIT_H_ 36#include "string/stringUnit.h" 37#endif 38 39#ifndef _ASSET_FIELD_TYPES_H_ 40#include "assets/assetFieldTypes.h" 41#endif 42#ifndef _ASSET_PTR_H_ 43#include "assets/assetPtr.h" 44#endif 45 46#include "gfx/bitmap/gBitmap.h" 47#include "gfx/gfxTextureHandle.h" 48 49#include "gui/editor/guiInspectorTypes.h" 50 51//----------------------------------------------------------------------------- 52class ImageAsset : public AssetBase 53{ 54 typedef AssetBase Parent; 55 56public: 57 /// The different types of image use cases 58 enum ImageTypes 59 { 60 Albedo = 0, 61 Normal = 1, 62 ORMConfig = 2, 63 GUI = 3, 64 Roughness = 4, 65 AO = 5, 66 Metalness = 6, 67 Glow = 7, 68 Particle = 8, 69 Decal = 9, 70 Cubemap = 10, 71 ImageTypeCount = 11 72 }; 73 74protected: 75 StringTableEntry mImageFileName; 76 StringTableEntry mImagePath; 77 78 GFXTexHandle mImage; 79 80 bool mIsValidImage; 81 bool mUseMips; 82 bool mIsHDRImage; 83 84 ImageTypes mImageType; 85 86 Map<GFXTextureProfile, GFXTexHandle> mResourceMap; 87 88public: 89 ImageAsset(); 90 virtual ~ImageAsset(); 91 92 /// Engine. 93 static void initPersistFields(); 94 virtual void copyTo(SimObject* object); 95 96 /// Declare Console Object. 97 DECLARE_CONOBJECT(ImageAsset); 98 99 void setImageFileName(const char* pScriptFile); 100 inline StringTableEntry getImageFileName(void) const { return mImageFileName; }; 101 102 inline StringTableEntry getImagePath(void) const { return mImagePath; }; 103 104 bool isValid() { return mIsValidImage; } 105 106 GFXTexHandle getImage(GFXTextureProfile requestedProfile); 107 108 const char* getImageInfo(); 109 110 static const char* getImageTypeNameFromType(ImageTypes type); 111 static ImageTypes getImageTypeFromName(const char* name); 112 113 void setImageType(ImageTypes type) { mImageType = type; } 114 115 static bool getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset); 116 static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); 117 static bool getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset); 118 119protected: 120 virtual void initializeAsset(void); 121 virtual void onAssetRefresh(void); 122 123 static bool setImageFileName(void* obj, const char* index, const char* data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; } 124 static const char* getImageFileName(void* obj, const char* data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); } 125 126 void loadImage(); 127}; 128 129DefineConsoleType(TypeImageAssetPtr, ImageAsset) 130DefineConsoleType(TypeImageAssetId, String) 131 132typedef ImageAsset::ImageTypes ImageAssetType; 133DefineEnumType(ImageAssetType); 134 135class GuiInspectorTypeImageAssetPtr : public GuiInspectorTypeFileName 136{ 137 typedef GuiInspectorTypeFileName Parent; 138public: 139 140 GuiBitmapButtonCtrl* mImageEdButton; 141 142 DECLARE_CONOBJECT(GuiInspectorTypeImageAssetPtr); 143 static void consoleInit(); 144 145 virtual GuiControl* constructEditControl(); 146 virtual bool updateRects(); 147}; 148 149class GuiInspectorTypeImageAssetId : public GuiInspectorTypeImageAssetPtr 150{ 151 typedef GuiInspectorTypeImageAssetPtr Parent; 152public: 153 154 DECLARE_CONOBJECT(GuiInspectorTypeImageAssetId); 155 static void consoleInit(); 156}; 157 158#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str() 159 160#define initMapSlot(name) m##name##Filename = String::EmptyString; m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL; 161#define bindMapSlot(name) if (m##name##AssetId != String::EmptyString) m##name##Asset = m##name##AssetId; 162 163#define scriptBindMapSlot(name, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), assetText(name, docs)); \ 164 addProtectedField(assetText(name, Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.)); 165 166#define initMapArraySlot(name,id) m##name##Filename[id] = String::EmptyString; m##name##AssetId[id] = StringTable->EmptyString(); m##name##Asset[id] = NULL; 167#define bindMapArraySlot(name,id) if (m##name##AssetId[id] != String::EmptyString) m##name##Asset[id] = m##name##AssetId[id]; 168#define scriptBindMapArraySlot(name, arraySize, consoleClass, docs) addField(#name, TypeImageFilename, Offset(m##name##Filename, consoleClass), arraySize, assetText(name, docs)); \ 169 addProtectedField(assetText(name,Asset), TypeImageAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##AssetSlot, &defaultProtectedGetFn, arraySize, assetText(name,asset reference.)); 170 171#define DECLARE_TEXTUREMAP(className,name) protected: \ 172 FileName m##name##Filename;\ 173 StringTableEntry m##name##AssetId;\ 174 AssetPtr<ImageAsset> m##name##Asset;\ 175 public: \ 176 const String& get##name() const { return m##name##Filename; }\ 177 void set##name(FileName _in) { m##name##Filename = _in; }\ 178 const AssetPtr<ImageAsset> & get##name##Asset() const { return m##name##Asset; }\ 179 void set##name##Asset(AssetPtr<ImageAsset>_in) { m##name##Asset = _in; }\ 180static bool _set##name##Asset(void* obj, const char* index, const char* data)\ 181{\ 182 className* mat = static_cast<className*>(obj);\ 183 mat->m##name##AssetId = StringTable->insert(data);\ 184 if (ImageAsset::getAssetById(mat->m##name##AssetId, &mat->m##name##Asset))\ 185 {\ 186 if (mat->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\ 187 mat->m##name##Filename = StringTable->EmptyString();\ 188 return true;\ 189 }\ 190 return true;\ 191} 192 193#define GET_TEXTUREMAP(name) get##name() 194#define SET_TEXTUREMAP(name,_in) set##name(_in) 195#define GET_TEXTUREASSET(name) get##name##Asset() 196#define SET_TEXTUREASSET(name,_in) set##name##Asset(_in) 197 198#define DECLARE_TEXTUREARRAY(className,name,max) FileName m##name##Filename[max];\ 199 StringTableEntry m##name##AssetId[max];\ 200 AssetPtr<ImageAsset> m##name##Asset[max];\ 201static bool _set##name##AssetSlot(void* obj, const char* index, const char* data)\ 202{\ 203 className* mat = static_cast<className*>(obj);\ 204 if (!index) return false;\ 205 U32 idx = dAtoi(index);\ 206 if (idx >= max)\ 207 return false;\ 208 mat->m##name##AssetId[idx] = StringTable->insert(data);\ 209 if (ImageAsset::getAssetById(mat->m##name##AssetId[idx], &mat->m##name##Asset[idx]))\ 210 {\ 211 if (mat->m##name##Asset[idx].getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\ 212 {\ 213 mat->m##name##Filename[idx] = StringTable->EmptyString();\ 214 }\ 215 return true;\ 216 }\ 217 return true;\ 218} 219#endif 220 221