meshComponent.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. class TSShapeInstance;
  61. class SceneRenderState;
  62. //////////////////////////////////////////////////////////////////////////
  63. ///
  64. ///
  65. //////////////////////////////////////////////////////////////////////////
  66. class MeshComponent : public Component,
  67. public RenderComponentInterface,
  68. public CastRayRenderedInterface,
  69. public EditorInspectInterface
  70. {
  71. typedef Component Parent;
  72. protected:
  73. enum
  74. {
  75. ShapeMask = Parent::NextFreeMask,
  76. MaterialMask = Parent::NextFreeMask << 1,
  77. NextFreeMask = Parent::NextFreeMask << 2,
  78. };
  79. StringTableEntry mShapeName;
  80. StringTableEntry mShapeAsset;
  81. TSShape* mShape;
  82. Box3F mShapeBounds;
  83. Point3F mCenterOffset;
  84. struct matMap
  85. {
  86. String matName;
  87. U32 slot;
  88. };
  89. Vector<matMap> mChangingMaterials;
  90. Vector<matMap> mMaterials;
  91. class boneObject : public SimGroup
  92. {
  93. MeshComponent *mOwner;
  94. public:
  95. boneObject(MeshComponent *owner){ mOwner = owner; }
  96. StringTableEntry mBoneName;
  97. S32 mItemID;
  98. virtual void addObject(SimObject *obj);
  99. };
  100. Vector<boneObject*> mNodesList;
  101. public:
  102. StringTableEntry mMeshAssetId;
  103. AssetPtr<ShapeAsset> mMeshAsset;
  104. TSShapeInstance* mShapeInstance;
  105. public:
  106. MeshComponent();
  107. virtual ~MeshComponent();
  108. DECLARE_CONOBJECT(MeshComponent);
  109. virtual bool onAdd();
  110. virtual void onRemove();
  111. static void initPersistFields();
  112. virtual void inspectPostApply();
  113. virtual void prepRenderImage(SceneRenderState *state);
  114. virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
  115. virtual void unpackUpdate(NetConnection *con, BitStream *stream);
  116. Box3F getShapeBounds() { return mShapeBounds; }
  117. virtual MatrixF getNodeTransform(S32 nodeIdx);
  118. S32 getNodeByName(String nodeName);
  119. void setupShape();
  120. void updateShape();
  121. void updateMaterials();
  122. virtual void onComponentRemove();
  123. virtual void onComponentAdd();
  124. static bool _setMesh(void *object, const char *index, const char *data);
  125. static bool _setShape(void *object, const char *index, const char *data);
  126. const char* _getShape(void *object, const char *data);
  127. bool setMeshAsset(const char* assetName);
  128. virtual TSShape* getShape() { if (mMeshAsset) return mMeshAsset->getShape(); else return NULL; }
  129. virtual TSShapeInstance* getShapeInstance() { return mShapeInstance; }
  130. Resource<TSShape> getShapeResource() { if (mMeshAsset) return mMeshAsset->getShapeResource(); else return NULL; }
  131. void _onResourceChanged(const Torque::Path &path);
  132. virtual bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info);
  133. void mountObjectToNode(SceneObject* objB, String node, MatrixF txfm);
  134. virtual void onDynamicModified(const char* slotName, const char* newValue);
  135. void changeMaterial(U32 slot, const char* newMat);
  136. virtual void onInspect();
  137. virtual void onEndInspect();
  138. virtual Vector<MatrixF> getNodeTransforms()
  139. {
  140. Vector<MatrixF> bob;
  141. return bob;
  142. }
  143. virtual void setNodeTransforms(Vector<MatrixF> transforms)
  144. {
  145. return;
  146. }
  147. };
  148. #endif