meshComponent.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 STATIC_MESH_COMPONENT_H
  23. #define STATIC_MESH_COMPONENT_H
  24. #ifndef COMPONENT_H
  25. #include "T3D/components/component.h"
  26. #endif
  27. #ifndef __RESOURCE_H__
  28. #include "core/resource.h"
  29. #endif
  30. #ifndef _TSSHAPE_H_
  31. #include "ts/tsShape.h"
  32. #endif
  33. #ifndef _SCENERENDERSTATE_H_
  34. #include "scene/sceneRenderState.h"
  35. #endif
  36. #ifndef _MBOX_H_
  37. #include "math/mBox.h"
  38. #endif
  39. #ifndef ENTITY_H
  40. #include "T3D/entity.h"
  41. #endif
  42. #ifndef _NETSTRINGTABLE_H_
  43. #include "sim/netStringTable.h"
  44. #endif
  45. #ifndef CORE_INTERFACES_H
  46. #include "T3D/components/coreInterfaces.h"
  47. #endif
  48. #ifndef RENDER_COMPONENT_INTERFACE_H
  49. #include "T3D/components/render/renderComponentInterface.h"
  50. #endif
  51. #ifndef _ASSET_PTR_H_
  52. #include "assets/assetPtr.h"
  53. #endif
  54. #ifndef _SHAPE_ASSET_H_
  55. #include "T3D/assets/ShapeAsset.h"
  56. #endif
  57. #ifndef _GFXVERTEXFORMAT_H_
  58. #include "gfx/gfxVertexFormat.h"
  59. #endif
  60. #include "T3D/systems/render/meshRenderSystem.h"
  61. class TSShapeInstance;
  62. class SceneRenderState;
  63. //////////////////////////////////////////////////////////////////////////
  64. ///
  65. ///
  66. //////////////////////////////////////////////////////////////////////////
  67. class MeshComponent : public Component,
  68. public RenderComponentInterface,
  69. public CastRayRenderedInterface,
  70. public EditorInspectInterface
  71. {
  72. typedef Component Parent;
  73. protected:
  74. enum
  75. {
  76. ShapeMask = Parent::NextFreeMask,
  77. MaterialMask = Parent::NextFreeMask << 1,
  78. NextFreeMask = Parent::NextFreeMask << 2,
  79. };
  80. StringTableEntry mShapeName;
  81. StringTableEntry mShapeAsset;
  82. TSShape* mShape;
  83. //Box3F mShapeBounds;
  84. Point3F mCenterOffset;
  85. MeshRenderSystemInterface* mInterfaceData;
  86. struct matMap
  87. {
  88. MaterialAsset* matAsset;
  89. String assetId;
  90. U32 slot;
  91. };
  92. Vector<matMap> mChangingMaterials;
  93. Vector<matMap> mMaterials;
  94. public:
  95. StringTableEntry mMeshAssetId;
  96. AssetPtr<ShapeAsset> mMeshAsset;
  97. //TSShapeInstance* mShapeInstance;
  98. public:
  99. MeshComponent();
  100. virtual ~MeshComponent();
  101. DECLARE_CONOBJECT(MeshComponent);
  102. virtual bool onAdd();
  103. virtual void onRemove();
  104. static void initPersistFields();
  105. virtual void inspectPostApply();
  106. virtual void prepRenderImage(SceneRenderState *state);
  107. virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
  108. virtual void unpackUpdate(NetConnection *con, BitStream *stream);
  109. Box3F getShapeBounds() { return mInterfaceData->mBounds; }
  110. virtual MatrixF getNodeTransform(S32 nodeIdx);
  111. S32 getNodeByName(String nodeName);
  112. void setupShape();
  113. void updateShape();
  114. void updateMaterials();
  115. void _shapeAssetUpdated(ShapeAsset* asset);
  116. virtual void onComponentRemove();
  117. virtual void onComponentAdd();
  118. virtual void ownerTransformSet(MatrixF *mat);
  119. static bool _setMesh(void *object, const char *index, const char *data);
  120. static bool _setShape(void *object, const char *index, const char *data);
  121. const char* _getShape(void *object, const char *data);
  122. static bool writeShape(void* obj, StringTableEntry pFieldName) { return static_cast<MeshComponent*>(obj)->mMeshAsset.notNull(); }
  123. bool setMeshAsset(const char* assetName);
  124. virtual TSShape* getShape() { if (mMeshAsset) return mMeshAsset->getShape(); else return NULL; }
  125. virtual TSShapeInstance* getShapeInstance() { return mInterfaceData->mShapeInstance; }
  126. Resource<TSShape> getShapeResource() { return mMeshAsset->getShapeResource(); }
  127. void _onResourceChanged(const Torque::Path &path);
  128. virtual bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info);
  129. void mountObjectToNode(SceneObject* objB, String node, MatrixF txfm);
  130. virtual void onDynamicModified(const char* slotName, const char* newValue);
  131. void changeMaterial(U32 slot, MaterialAsset* newMat);
  132. bool setMatInstField(U32 slot, const char* field, const char* value);
  133. virtual void onInspect();
  134. virtual void onEndInspect();
  135. virtual Vector<MatrixF> getNodeTransforms()
  136. {
  137. Vector<MatrixF> bob;
  138. return bob;
  139. }
  140. virtual void setNodeTransforms(Vector<MatrixF> transforms)
  141. {
  142. return;
  143. }
  144. };
  145. #endif