decalData.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _DECALDATA_H_
  23. #define _DECALDATA_H_
  24. #ifndef _SIMDATABLOCK_H_
  25. #include "console/simDatablock.h"
  26. #endif
  27. #ifndef _MATERIALDEFINITION_H_
  28. #include "materials/materialDefinition.h"
  29. #endif
  30. #ifndef _MRECT_H_
  31. #include "math/mRect.h"
  32. #endif
  33. #ifndef _DYNAMIC_CONSOLETYPES_H_
  34. #include "console/dynamicTypes.h"
  35. #endif
  36. #include "T3D/assets/MaterialAsset.h"
  37. GFXDeclareVertexFormat( DecalVertex )
  38. {
  39. // .xyz = coords
  40. Point3F point;
  41. Point3F normal;
  42. Point3F tangent;
  43. GFXVertexColor color;
  44. Point2F texCoord;
  45. };
  46. /// DataBlock implementation for decals.
  47. class DecalData : public SimDataBlock
  48. {
  49. typedef SimDataBlock Parent;
  50. public:
  51. enum { MAX_TEXCOORD_COUNT = 16 };
  52. F32 size;
  53. /// Milliseconds for decal to expire.
  54. U32 lifeSpan;
  55. /// Milliseconds for decal to fade after expiration.
  56. U32 fadeTime;
  57. S32 texCoordCount;
  58. RectF texRect[MAX_TEXCOORD_COUNT];
  59. ///
  60. S32 frame;
  61. bool randomize;
  62. S32 texRows;
  63. S32 texCols;
  64. F32 fadeStartPixelSize;
  65. F32 fadeEndPixelSize;
  66. DECLARE_MATERIALASSET(DecalData, Material);
  67. DECLARE_ASSET_SETGET(DecalData, Material);
  68. /// Material instance for decal.
  69. BaseMatInstance *matInst;
  70. String lookupName;
  71. U8 renderPriority;
  72. S32 clippingMasks;
  73. /// The angle in degress used to clip geometry
  74. /// that faces away from the decal projection.
  75. F32 clippingAngle;
  76. /// Skip generating and collecting vertex normals for decals.
  77. bool skipVertexNormals;
  78. public:
  79. DecalData();
  80. ~DecalData();
  81. DECLARE_CONOBJECT(DecalData);
  82. static void initPersistFields();
  83. virtual void onStaticModified( const char *slotName, const char *newValue = NULL );
  84. virtual bool onAdd();
  85. virtual void onRemove();
  86. virtual bool preload( bool server, String &errorStr );
  87. virtual void packData( BitStream* );
  88. virtual void unpackData( BitStream* );
  89. Material* getMaterialDefinition();
  90. BaseMatInstance* getMaterialInstance();
  91. static SimSet* getSet();
  92. static DecalData* findDatablock( String lookupName );
  93. virtual void inspectPostApply();
  94. void reloadRects();
  95. protected:
  96. void _initMaterial();
  97. void _updateMaterial();
  98. };
  99. inline SimSet* DecalData::getSet()
  100. {
  101. SimSet *set = NULL;
  102. if ( !Sim::findObject( "DecalDataSet", set ) )
  103. {
  104. set = new SimSet;
  105. set->registerObject( "DecalDataSet" );
  106. Sim::getRootGroup()->addObject( set );
  107. }
  108. return set;
  109. }
  110. #endif // _DECALDATA_H_