interiorSimpleMesh.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 _INTERIORSIMPLEMESH_H_
  23. #define _INTERIORSIMPLEMESH_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _MBOX_H_
  28. #include "math/mBox.h"
  29. #endif
  30. #ifndef _TSMATERIALLIST_H_
  31. #include "ts/tsMaterialList.h"
  32. #endif
  33. #ifndef _RENDERPASSMANAGER_H_
  34. #include "renderInstance/renderPassManager.h"
  35. #endif
  36. #ifndef _GFXPRIMITIVEBUFFER_H_
  37. #include "gfx/gfxPrimitiveBuffer.h"
  38. #endif
  39. #ifndef _GFXVERTEXBUFFER_H_
  40. #include "gfx/gfxVertexBuffer.h"
  41. #endif
  42. class InteriorInstance;
  43. class InteriorSimpleMesh
  44. {
  45. public:
  46. class primitive
  47. {
  48. public:
  49. bool alpha;
  50. U32 texS;
  51. U32 texT;
  52. S32 diffuseIndex;
  53. S32 lightMapIndex;
  54. U32 start;
  55. U32 count;
  56. // used to relight the surface in-engine...
  57. PlaneF lightMapEquationX;
  58. PlaneF lightMapEquationY;
  59. Point2I lightMapOffset;
  60. Point2I lightMapSize;
  61. primitive()
  62. {
  63. alpha = false;
  64. texS = GFXAddressWrap;
  65. texT = GFXAddressWrap;
  66. diffuseIndex = 0;
  67. lightMapIndex = 0;
  68. start = 0;
  69. count = 0;
  70. lightMapEquationX = PlaneF(0, 0, 0, 0);
  71. lightMapEquationY = PlaneF(0, 0, 0, 0);
  72. lightMapOffset = Point2I(0, 0);
  73. lightMapSize = Point2I(0, 0);
  74. }
  75. };
  76. InteriorSimpleMesh()
  77. {
  78. VECTOR_SET_ASSOCIATION( packedIndices );
  79. VECTOR_SET_ASSOCIATION( packedPrimitives );
  80. VECTOR_SET_ASSOCIATION( indices );
  81. VECTOR_SET_ASSOCIATION( verts );
  82. VECTOR_SET_ASSOCIATION( norms );
  83. VECTOR_SET_ASSOCIATION( diffuseUVs );
  84. VECTOR_SET_ASSOCIATION( lightmapUVs );
  85. materialList = NULL;
  86. clear();
  87. }
  88. ~InteriorSimpleMesh(){clear();}
  89. void clear(bool wipeMaterials = true)
  90. {
  91. vertBuff = NULL;
  92. primBuff = NULL;
  93. packedIndices.clear();
  94. packedPrimitives.clear();
  95. hasSolid = false;
  96. hasTranslucency = false;
  97. bounds = Box3F(-1, -1, -1, 1, 1, 1);
  98. transform.identity();
  99. scale.set(1.0f, 1.0f, 1.0f);
  100. primitives.clear();
  101. indices.clear();
  102. verts.clear();
  103. norms.clear();
  104. diffuseUVs.clear();
  105. lightmapUVs.clear();
  106. if(wipeMaterials && materialList)
  107. delete materialList;
  108. if (wipeMaterials)
  109. materialList = NULL;
  110. }
  111. void render( SceneRenderState* state,
  112. const MeshRenderInst &copyinst,
  113. U32 interiorlmhandle,
  114. U32 instancelmhandle,
  115. InteriorInstance* intInst );
  116. void calculateBounds()
  117. {
  118. bounds = Box3F(F32_MAX, F32_MAX, F32_MAX, -F32_MAX, -F32_MAX, -F32_MAX);
  119. for(U32 i=0; i<verts.size(); i++)
  120. {
  121. bounds.maxExtents.setMax(verts[i]);
  122. bounds.minExtents.setMin(verts[i]);
  123. }
  124. }
  125. Vector<U16> packedIndices;
  126. Vector<primitive> packedPrimitives;/// tri-list instead of strips
  127. GFXVertexBufferHandle<GFXVertexPNTTB> vertBuff;
  128. GFXPrimitiveBufferHandle primBuff;
  129. void buildBuffers();
  130. void buildTangent(U32 i0, U32 i1, U32 i2, Vector<Point3F> &tang, Vector<Point3F> &binorm);
  131. void packPrimitive(primitive &primnew, const primitive &primold, Vector<U16> &indicesnew,
  132. bool flipped, Vector<Point3F> &tang, Vector<Point3F> &binorm);
  133. bool prepForRendering(const char *path);
  134. bool hasSolid;
  135. bool hasTranslucency;
  136. Box3F bounds;
  137. MatrixF transform;
  138. Point3F scale;
  139. Vector<primitive> primitives;
  140. // same index relationship...
  141. Vector<U16> indices;
  142. Vector<Point3F> verts;
  143. Vector<Point3F> norms;
  144. Vector<Point2F> diffuseUVs;
  145. Vector<Point2F> lightmapUVs;
  146. TSMaterialList *materialList;
  147. bool containsPrimitiveType(bool translucent)
  148. {
  149. for(U32 i=0; i<primitives.size(); i++)
  150. {
  151. if(primitives[i].alpha == translucent)
  152. return true;
  153. }
  154. return false;
  155. }
  156. void copyTo(InteriorSimpleMesh &dest)
  157. {
  158. dest.clear();
  159. dest.hasSolid = hasSolid;
  160. dest.hasTranslucency = hasTranslucency;
  161. dest.bounds = bounds;
  162. dest.transform = transform;
  163. dest.scale = scale;
  164. dest.primitives = primitives;
  165. dest.indices = indices;
  166. dest.verts = verts;
  167. dest.norms = norms;
  168. dest.diffuseUVs = diffuseUVs;
  169. dest.lightmapUVs = lightmapUVs;
  170. if(materialList)
  171. dest.materialList = new TSMaterialList(materialList);
  172. }
  173. //bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  174. bool castPlanes(PlaneF left, PlaneF right, PlaneF top, PlaneF bottom);
  175. bool read(Stream& stream);
  176. bool write(Stream& stream) const;
  177. private:
  178. static Vector<MeshRenderInst *> *renderInstList;
  179. };
  180. #endif //_INTERIORSIMPLEMESH_H_