decalData.h

Engine/source/T3D/decal/decalData.h

More...

Classes:

class

DataBlock implementation for decals.

Public Functions

GFXDeclareVertexFormat(DecalVertex )

Detailed Description

Public Functions

GFXDeclareVertexFormat(DecalVertex )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 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
 24#ifndef _DECALDATA_H_
 25#define _DECALDATA_H_
 26
 27#ifndef _SIMDATABLOCK_H_
 28#include "console/simDatablock.h"
 29#endif
 30#ifndef _MATERIALDEFINITION_H_
 31#include "materials/materialDefinition.h"
 32#endif
 33#ifndef _MRECT_H_
 34#include "math/mRect.h"
 35#endif
 36#ifndef _DYNAMIC_CONSOLETYPES_H_
 37#include "console/dynamicTypes.h"
 38#endif
 39
 40GFXDeclareVertexFormat( DecalVertex )
 41{
 42   // .xyz = coords
 43   Point3F point;
 44   Point3F normal;
 45   Point3F tangent;
 46   GFXVertexColor color;
 47   Point2F texCoord;   
 48};
 49
 50/// DataBlock implementation for decals.
 51class DecalData : public SimDataBlock
 52{
 53      typedef SimDataBlock Parent;
 54
 55   public:
 56
 57      enum { MAX_TEXCOORD_COUNT = 16 };
 58
 59      F32 size;
 60      
 61      /// Milliseconds for decal to expire.
 62      U32 lifeSpan;
 63      
 64      /// Milliseconds for decal to fade after expiration.
 65      U32 fadeTime;
 66
 67      S32 texCoordCount;
 68      RectF texRect[MAX_TEXCOORD_COUNT];
 69
 70      ///
 71      S32 frame;
 72      bool randomize;
 73      S32 texRows;
 74      S32 texCols;
 75
 76      F32 fadeStartPixelSize;
 77      F32 fadeEndPixelSize;
 78
 79      /// Name of material to use.
 80      String materialName;
 81      
 82      /// Render material for decal.
 83      SimObjectPtr<Material> material;
 84      
 85      /// Material instance for decal.
 86      BaseMatInstance *matInst;
 87
 88      String lookupName;
 89
 90      U8 renderPriority;
 91      
 92      S32 clippingMasks;
 93
 94      /// The angle in degress used to clip geometry
 95      /// that faces away from the decal projection.
 96      F32 clippingAngle;
 97
 98      /// Skip generating and collecting vertex normals for decals.
 99      bool skipVertexNormals;
100
101   public:
102
103      DecalData();
104      ~DecalData();
105
106      DECLARE_CONOBJECT(DecalData);
107      static void initPersistFields();
108      virtual void onStaticModified( const char *slotName, const char *newValue = NULL );
109      
110      virtual bool onAdd();
111      virtual void onRemove();
112
113      virtual bool preload( bool server, String &errorStr );
114      virtual void packData( BitStream* );
115      virtual void unpackData( BitStream* );      
116      
117      Material* getMaterial();
118      BaseMatInstance* getMaterialInstance();
119
120      static SimSet* getSet();
121      static DecalData* findDatablock( String lookupName );
122
123      virtual void inspectPostApply();
124      void reloadRects();
125
126   protected:
127
128      void _initMaterial();
129      void _updateMaterial();
130};
131
132inline SimSet* DecalData::getSet()
133{   
134   SimSet *set = NULL;
135   if ( !Sim::findObject( "DecalDataSet", set ) )
136   {      
137      set = new SimSet;
138      set->registerObject( "DecalDataSet" );
139      Sim::getRootGroup()->addObject( set );
140   }
141   return set;
142}
143
144#endif // _DECALDATA_H_
145