meshComponent.h
Engine/source/T3D/components/render/meshComponent.h
Classes:
Detailed Description
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 STATIC_MESH_COMPONENT_H 25#define STATIC_MESH_COMPONENT_H 26 27#ifndef COMPONENT_H 28#include "T3D/components/component.h" 29#endif 30#ifndef __RESOURCE_H__ 31#include "core/resource.h" 32#endif 33#ifndef _TSSHAPE_H_ 34#include "ts/tsShape.h" 35#endif 36#ifndef _SCENERENDERSTATE_H_ 37#include "scene/sceneRenderState.h" 38#endif 39#ifndef _MBOX_H_ 40#include "math/mBox.h" 41#endif 42#ifndef ENTITY_H 43#include "T3D/entity.h" 44#endif 45#ifndef _NETSTRINGTABLE_H_ 46 #include "sim/netStringTable.h" 47#endif 48#ifndef CORE_INTERFACES_H 49#include "T3D/components/coreInterfaces.h" 50#endif 51#ifndef RENDER_COMPONENT_INTERFACE_H 52#include "T3D/components/render/renderComponentInterface.h" 53#endif 54#ifndef _ASSET_PTR_H_ 55#include "assets/assetPtr.h" 56#endif 57#ifndef _SHAPE_ASSET_H_ 58#include "T3D/assets/ShapeAsset.h" 59#endif 60#ifndef _GFXVERTEXFORMAT_H_ 61#include "gfx/gfxVertexFormat.h" 62#endif 63 64class TSShapeInstance; 65class SceneRenderState; 66////////////////////////////////////////////////////////////////////////// 67/// 68/// 69////////////////////////////////////////////////////////////////////////// 70class MeshComponent : public Component, 71 public RenderComponentInterface, 72 public CastRayRenderedInterface, 73 public EditorInspectInterface 74{ 75 typedef Component Parent; 76 77protected: 78 enum 79 { 80 ShapeMask = Parent::NextFreeMask, 81 MaterialMask = Parent::NextFreeMask << 1, 82 NextFreeMask = Parent::NextFreeMask << 2, 83 }; 84 85 StringTableEntry mShapeName; 86 StringTableEntry mShapeAsset; 87 TSShape* mShape; 88 Box3F mShapeBounds; 89 Point3F mCenterOffset; 90 91 struct matMap 92 { 93 String matName; 94 U32 slot; 95 }; 96 97 Vector<matMap> mChangingMaterials; 98 Vector<matMap> mMaterials; 99 100 class boneObject : public SimGroup 101 { 102 MeshComponent *mOwner; 103 public: 104 boneObject(MeshComponent *owner){ mOwner = owner; } 105 106 StringTableEntry mBoneName; 107 S32 mItemID; 108 109 virtual void addObject(SimObject *obj); 110 }; 111 112 Vector<boneObject*> mNodesList; 113 114public: 115 StringTableEntry mMeshAssetId; 116 AssetPtr<ShapeAsset> mMeshAsset; 117 118 TSShapeInstance* mShapeInstance; 119 120public: 121 MeshComponent(); 122 virtual ~MeshComponent(); 123 DECLARE_CONOBJECT(MeshComponent); 124 125 virtual bool onAdd(); 126 virtual void onRemove(); 127 static void initPersistFields(); 128 129 virtual void inspectPostApply(); 130 131 virtual void prepRenderImage(SceneRenderState *state); 132 133 virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream); 134 virtual void unpackUpdate(NetConnection *con, BitStream *stream); 135 136 Box3F getShapeBounds() { return mShapeBounds; } 137 138 virtual MatrixF getNodeTransform(S32 nodeIdx); 139 S32 getNodeByName(String nodeName); 140 141 void setupShape(); 142 void updateShape(); 143 void updateMaterials(); 144 145 virtual void onComponentRemove(); 146 virtual void onComponentAdd(); 147 148 static bool _setMesh(void *object, const char *index, const char *data); 149 static bool _setShape(void *object, const char *index, const char *data); 150 const char* _getShape(void *object, const char *data); 151 152 bool setMeshAsset(const char* assetName); 153 154 virtual TSShape* getShape() { if (mMeshAsset) return mMeshAsset->getShape(); else return NULL; } 155 virtual TSShapeInstance* getShapeInstance() { return mShapeInstance; } 156 157 Resource<TSShape> getShapeResource() { return mMeshAsset->getShapeResource(); } 158 159 void _onResourceChanged(const Torque::Path &path); 160 161 virtual bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info); 162 163 void mountObjectToNode(SceneObject* objB, String node, MatrixF txfm); 164 165 virtual void onDynamicModified(const char* slotName, const char* newValue); 166 167 void changeMaterial(U32 slot, const char* newMat); 168 169 virtual void onInspect(); 170 virtual void onEndInspect(); 171 172 virtual Vector<MatrixF> getNodeTransforms() 173 { 174 Vector<MatrixF> bob; 175 return bob; 176 } 177 178 virtual void setNodeTransforms(Vector<MatrixF> transforms) 179 { 180 return; 181 } 182}; 183 184#endif 185
