Torque3D Documentation / _generateds / MaterialAsset.h

MaterialAsset.h

Engine/source/T3D/assets/MaterialAsset.h

More...

Classes:

Public Defines

define
assetText(x, suff) std::string(std::string(#x) + std::string(#suff)).c_str()
define
bindMaterialAsset(name)  (m##name##AssetId != ->EmptyString()) m##name##Asset = m##name##AssetId;
define
DECLARE_MATERIALASSET(className, name) 
define
DECLARE_NET_MATERIALASSET(className, name, bitmask) 

DECLARE_MATERIALASSET is a utility macro for MaterialAssets.

define
initMaterialAsset(name) m##name##Name = ""; m##name##AssetId = ->EmptyString(); m##name##Asset = ;
define
packMaterialAsset(netconn, name)     (stream->writeFlag(m##name##Asset.notNull()))\
   {\
       assetIdStr = m##name##Asset.getAssetId();\
      netconn->packNetStringHandleU(stream, assetIdStr);\
   }\
   else\
      stream->writeString(m##name##Name);
define
scriptBindMaterialAsset(name, consoleClass, docs)    addProtectedField((name, ), TypeMaterialName, (m##name##Name, consoleClass), consoleClass::_set##name##Name,  & , (name, docs), ); \
   addProtectedField((name, Asset), TypeMaterialAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & , (name, asset reference.));
define
unpackMaterialAsset(netconn, name)     (stream->readFlag())\
   {\
      m##name##AssetId = ->insert(netconn->unpackNetStringHandleU(stream).getString());\
      (m##name##AssetId, &m##name##Asset);\
   }\
   else\
      m##name##Name = stream->readSTString();\

Public Functions

DefineConsoleType(TypeMaterialAssetId , String )
DefineConsoleType(TypeMaterialAssetPtr , MaterialAsset )

Detailed Description

Public Defines

assetText(x, suff) std::string(std::string(#x) + std::string(#suff)).c_str()
bindMaterialAsset(name)  (m##name##AssetId != ->EmptyString()) m##name##Asset = m##name##AssetId;
DECLARE_MATERIALASSET(className, name) 
DECLARE_NET_MATERIALASSET(className, name, bitmask) 

DECLARE_MATERIALASSET is a utility macro for MaterialAssets.

It takes in the name of the class using it, the name of the field for the material, and a networking bitmask The first 2 are for setting up/filling out the fields and class member defines The bitmask is for when the material is changed, it can automatically kick a network update on the owner object to pass the changed asset to clients

initMaterialAsset(name) m##name##Name = ""; m##name##AssetId = ->EmptyString(); m##name##Asset = ;
MATERIALASSET_H() 
packMaterialAsset(netconn, name)     (stream->writeFlag(m##name##Asset.notNull()))\
   {\
       assetIdStr = m##name##Asset.getAssetId();\
      netconn->packNetStringHandleU(stream, assetIdStr);\
   }\
   else\
      stream->writeString(m##name##Name);
scriptBindMaterialAsset(name, consoleClass, docs)    addProtectedField((name, ), TypeMaterialName, (m##name##Name, consoleClass), consoleClass::_set##name##Name,  & , (name, docs), ); \
   addProtectedField((name, Asset), TypeMaterialAssetId, (m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & , (name, asset reference.));
unpackMaterialAsset(netconn, name)     (stream->readFlag())\
   {\
      m##name##AssetId = ->insert(netconn->unpackNetStringHandleU(stream).getString());\
      (m##name##AssetId, &m##name##Asset);\
   }\
   else\
      m##name##Name = stream->readSTString();\

Public Functions

DefineConsoleType(TypeMaterialAssetId , String )

DefineConsoleType(TypeMaterialAssetPtr , MaterialAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#pragma once
 24
 25#ifndef MATERIALASSET_H
 26#define MATERIALASSET_H
 27
 28#ifndef _ASSET_BASE_H_
 29#include "assets/assetBase.h"
 30#endif
 31
 32#ifndef _ASSET_DEFINITION_H_
 33#include "assets/assetDefinition.h"
 34#endif
 35
 36#ifndef _STRINGUNIT_H_
 37#include "string/stringUnit.h"
 38#endif
 39
 40#ifndef _ASSET_FIELD_TYPES_H_
 41#include "assets/assetFieldTypes.h"
 42#endif
 43
 44#ifndef _GFXDEVICE_H_
 45#include "gfx/gfxDevice.h"
 46#endif
 47
 48#ifndef _NETCONNECTION_H_
 49#include "sim/netConnection.h"
 50#endif
 51
 52#include "gui/editor/guiInspectorTypes.h"
 53
 54#include "materials/matTextureTarget.h"
 55#include "materials/materialDefinition.h"
 56#include "materials/customMaterialDefinition.h"
 57
 58//-----------------------------------------------------------------------------
 59class MaterialAsset : public AssetBase
 60{
 61   typedef AssetBase Parent;
 62
 63   String                  mShaderGraphFile;
 64   StringTableEntry        mScriptFile;
 65   StringTableEntry        mScriptPath;
 66   StringTableEntry        mMatDefinitionName;
 67
 68public:
 69   MaterialAsset();
 70   virtual ~MaterialAsset();
 71
 72   /// Engine.
 73   static void initPersistFields();
 74   virtual void copyTo(SimObject* object);
 75
 76   void compileShader();
 77
 78   StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
 79
 80   void                    setScriptFile(const char* pScriptFile);
 81   inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
 82
 83   inline StringTableEntry getScriptPath(void) const { return mScriptPath; };
 84
 85   static StringTableEntry getAssetIdByMaterialName(StringTableEntry fileName);
 86   static bool getAssetById(StringTableEntry assetId, AssetPtr<MaterialAsset>* materialAsset);
 87
 88   /// Declare Console Object.
 89   DECLARE_CONOBJECT(MaterialAsset);
 90
 91protected:
 92   virtual void initializeAsset();
 93   virtual void onAssetRefresh(void);
 94
 95   static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<MaterialAsset*>(obj)->setScriptFile(data); return false; }
 96   static const char* getScriptFile(void* obj, const char* data) { return static_cast<MaterialAsset*>(obj)->getScriptFile(); }
 97};
 98
 99DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset)
100DefineConsoleType(TypeMaterialAssetId, String)
101
102//-----------------------------------------------------------------------------
103// TypeAssetId GuiInspectorField Class
104//-----------------------------------------------------------------------------
105class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorTypeFileName
106{
107   typedef GuiInspectorTypeFileName Parent;
108public:
109
110   GuiBitmapButtonCtrl* mEditButton;
111
112   DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetPtr);
113   static void consoleInit();
114
115   virtual GuiControl* constructEditControl();
116   virtual bool updateRects();
117};
118
119class GuiInspectorTypeMaterialAssetId : public GuiInspectorTypeMaterialAssetPtr
120{
121   typedef GuiInspectorTypeMaterialAssetPtr Parent;
122public:
123
124   DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetId);
125   static void consoleInit();
126};
127
128#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
129
130#define initMaterialAsset(name) m##name##Name = ""; m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
131#define bindMaterialAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId;
132
133#define scriptBindMaterialAsset(name, consoleClass, docs)\
134   addProtectedField(assetText(name, File), TypeMaterialName, Offset(m##name##Name, consoleClass), consoleClass::_set##name##Name,  & defaultProtectedGetFn, assetText(name, docs), AbstractClassRep::FIELD_HideInInspectors); \
135   addProtectedField(assetText(name, Asset), TypeMaterialAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
136
137#define DECLARE_MATERIALASSET(className,name)      protected: \
138                                      String m##name##Name;\
139                                      StringTableEntry m##name##AssetId;\
140                                      AssetPtr<MaterialAsset>  m##name##Asset;\
141                                      public: \
142                                      const String& get##name() const { return m##name##Name; }\
143                                      void set##name(FileName _in) { m##name##Name = _in; }\
144                                      const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
145                                      void set##name##Asset(AssetPtr<MaterialAsset>_in) { m##name##Asset = _in; }\
146static bool _set##name##Name(void* obj, const char* index, const char* data)\
147{\
148   className* shape = static_cast<className*>(obj);\
149   \
150   StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(data));\
151   if (assetId != StringTable->EmptyString())\
152   {\
153      if (shape->_set##name##Asset(obj, index, assetId))\
154      {\
155         if (assetId == StringTable->insert("Core_Rendering:noMaterial"))\
156         {\
157            shape->m##name##Name = data;\
158            shape->m##name##AssetId = StringTable->EmptyString();\
159            \
160            return true;\
161         }\
162         else\
163         {\
164            shape->m##name##AssetId = assetId;\
165            shape->m##name##Name = StringTable->EmptyString();\
166            \
167            return false;\
168         }\
169      }\
170   }\
171   else\
172   {\
173      shape->m##name##Asset = StringTable->EmptyString();\
174   }\
175   \
176   return true;\
177}\
178\
179static bool _set##name##Asset(void* obj, const char* index, const char* data)\
180{\
181   className* shape = static_cast<className*>(obj);\
182   shape->m##name##AssetId = StringTable->insert(data);\
183   if (MaterialAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
184   {\
185      if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
186         shape->m##name##Name = StringTable->EmptyString();\
187      \
188      return true;\
189   }\
190   return false;\
191}\
192\
193static bool set##name##Asset(const char* assetId)\
194{\
195   m##name##AssetId = StringTable->insert(assetId);\
196   if (m##name##AssetId != StringTable->EmptyString())\
197      m##name##Asset = m##name##AssetId;\
198}
199
200/// <summary>
201/// DECLARE_MATERIALASSET is a utility macro for MaterialAssets. It takes in the name of the class using it, the name of the field for the material, and a networking bitmask
202/// The first 2 are for setting up/filling out the fields and class member defines
203/// The bitmask is for when the material is changed, it can automatically kick a network update on the owner object to pass the changed asset to clients
204/// </summary>
205#define DECLARE_NET_MATERIALASSET(className,name,bitmask)      protected: \
206                                      String m##name##Name;\
207                                      StringTableEntry m##name##AssetId;\
208                                      AssetPtr<MaterialAsset>  m##name##Asset;\
209                                      public: \
210                                      const String& get##name() const { return m##name##Name; }\
211                                      void set##name(FileName _in) { m##name##Name = _in; }\
212                                      const AssetPtr<MaterialAsset> & get##name##Asset() const { return m##name##Asset; }\
213                                      void set##name##Asset(AssetPtr<MaterialAsset>_in) { m##name##Asset = _in; }\
214static bool _set##name##Name(void* obj, const char* index, const char* data)\
215{\
216   className* shape = static_cast<className*>(obj);\
217   \
218   StringTableEntry assetId = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(data));\
219   if (assetId != StringTable->EmptyString())\
220   {\
221      if (shape->_set##name##Asset(obj, index, assetId))\
222      {\
223         if (assetId == StringTable->insert("Core_Rendering:noMaterial"))\
224         {\
225            shape->m##name##Name = data;\
226            shape->m##name##AssetId = StringTable->EmptyString();\
227            \
228            return true;\
229         }\
230         else\
231         {\
232            shape->m##name##AssetId = assetId;\
233            shape->m##name##Name = StringTable->EmptyString();\
234            \
235            return false;\
236         }\
237      }\
238   }\
239   else\
240   {\
241      shape->m##name##Asset = StringTable->EmptyString();\
242   }\
243   \
244   return true;\
245}\
246\
247static bool _set##name##Asset(void* obj, const char* index, const char* data)\
248{\
249   className* shape = static_cast<className*>(obj);\
250   shape->m##name##AssetId = StringTable->insert(data);\
251   if (MaterialAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
252   {\
253      if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noMaterial"))\
254         shape->m##name##Name = StringTable->EmptyString();\
255      \
256      shape->setMaskBits(bitmask);\
257      shape->inspectPostApply();\
258      return true;\
259   }\
260   shape->inspectPostApply();\
261   return false;\
262}\
263\
264bool set##name##AssetId(const char* _assetId)\
265{\
266   m##name##AssetId = StringTable->insert(_assetId);\
267   if (m##name##AssetId != StringTable->EmptyString())\
268   {\
269      m##name##Asset = m##name##AssetId;\
270      \
271      setMaskBits(bitmask);\
272      inspectPostApply();\
273      return true;\
274   }\
275   \
276   return false;\
277}
278
279
280#define packMaterialAsset(netconn, name)\
281   if (stream->writeFlag(m##name##Asset.notNull()))\
282   {\
283      NetStringHandle assetIdStr = m##name##Asset.getAssetId();\
284      netconn->packNetStringHandleU(stream, assetIdStr);\
285   }\
286   else\
287      stream->writeString(m##name##Name);
288
289#define unpackMaterialAsset(netconn, name)\
290   if (stream->readFlag())\
291   {\
292      m##name##AssetId = StringTable->insert(netconn->unpackNetStringHandleU(stream).getString());\
293      MaterialAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
294   }\
295   else\
296      m##name##Name = stream->readSTString();\
297
298#endif // _ASSET_BASE_H_
299
300