tsStatic.h
Classes:
class
A simple mesh shape with optional ambient animation.
Public Typedefs
TSMeshType
Public Functions
Detailed Description
Public Typedefs
typedef TSStatic::MeshType TSMeshType
Public Functions
DefineEnumType(TSMeshType )
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 _TSSTATIC_H_ 25#define _TSSTATIC_H_ 26 27#ifndef _SCENEOBJECT_H_ 28#include "scene/sceneObject.h" 29#endif 30#ifndef _CONVEX_H_ 31#include "collision/convex.h" 32#endif 33#ifndef __RESOURCE_H__ 34#include "core/resource.h" 35#endif 36#ifndef _NETSTRINGTABLE_H_ 37 #include "sim/netStringTable.h" 38#endif 39#ifndef _TSSHAPE_H_ 40#include "ts/tsShape.h" 41#endif 42 43#ifndef _REFLECTOR_H_ 44 #include "scene/reflector.h" 45#endif 46 47class TSShapeInstance; 48class TSThread; 49class TSStatic; 50class PhysicsBody; 51struct ObjectRenderInst; 52 53 54class TSStaticPolysoupConvex : public Convex 55{ 56 typedef Convex Parent; 57 friend class TSMesh; 58 59public: 60 TSStaticPolysoupConvex(); 61 ~TSStaticPolysoupConvex() {}; 62 63public: 64 Box3F box; 65 Point3F verts[4]; 66 PlaneF normal; 67 S32 idx; 68 TSMesh *mesh; 69 70 static SceneObject* smCurObject; 71 72public: 73 74 // Returns the bounding box in world coordinates 75 Box3F getBoundingBox() const; 76 Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const; 77 78 void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf); 79 80 // This returns a list of convex faces to collide against 81 void getPolyList(AbstractPolyList* list); 82 83 // This returns the furthest point from the input vector 84 Point3F support(const VectorF& v) const; 85}; 86 87 88/// A simple mesh shape with optional ambient animation. 89class TSStatic : public SceneObject 90{ 91 typedef SceneObject Parent; 92 93 static U32 smUniqueIdentifier; 94 95 enum MaskBits 96 { 97 TransformMask = Parent::NextFreeMask << 0, 98 AdvancedStaticOptionsMask = Parent::NextFreeMask << 1, 99 UpdateCollisionMask = Parent::NextFreeMask << 2, 100 SkinMask = Parent::NextFreeFlag << 3, 101 NextFreeMask = Parent::NextFreeMask << 4 102 }; 103 104public: 105 void setAlphaFade(bool enable, F32 start, F32 end, bool inverse) 106 { 107 mUseAlphaFade = enable; 108 mAlphaFadeStart = start; 109 mAlphaFadeEnd = end; 110 mInvertAlphaFade = inverse; 111 } 112 113 /// The different types of mesh data types 114 enum MeshType 115 { 116 None = 0, ///< No mesh 117 Bounds = 1, ///< Bounding box of the shape 118 CollisionMesh = 2, ///< Specifically designated collision meshes 119 VisibleMesh = 3 ///< Rendered mesh polygons 120 }; 121 122protected: 123 bool mUseAlphaFade; 124 F32 mAlphaFadeStart; 125 F32 mAlphaFadeEnd; 126 F32 mAlphaFade; 127 bool mInvertAlphaFade; 128 129 bool onAdd(); 130 void onRemove(); 131 132 // Collision 133 void prepCollision(); 134 bool castRay(const Point3F &start, const Point3F &end, RayInfo* info); 135 bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo* info); 136 bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere); 137 void buildConvex(const Box3F& box, Convex* convex); 138 139 bool _createShape(); 140 141 void _updatePhysics(); 142 143 void _renderNormals( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat ); 144 145 void _onResourceChanged( const Torque::Path &path ); 146 147 // ProcessObject 148 virtual void processTick( const Move *move ); 149 virtual void interpolateTick( F32 delta ); 150 virtual void advanceTime( F32 dt ); 151 152 /// Start or stop processing ticks depending on our state. 153 void _updateShouldTick(); 154 155 String cubeDescName; 156 U32 cubeDescId; 157 ReflectorDesc *reflectorDesc; 158 CubeReflector mCubeReflector; 159 160protected: 161 162 Convex *mConvexList; 163 164 StringTableEntry mShapeName; 165 U32 mShapeHash; 166 Resource<TSShape> mShape; 167 Vector<S32> mCollisionDetails; 168 Vector<S32> mLOSDetails; 169 TSShapeInstance *mShapeInstance; 170 171 NetStringHandle mSkinNameHandle; 172 String mAppliedSkinName; 173 174 bool mPlayAmbient; 175 TSThread* mAmbientThread; 176 177 /// The type of mesh data to return for collision queries. 178 MeshType mCollisionType; 179 180 /// The type of mesh data to return for decal polylist queries. 181 MeshType mDecalType; 182 183 bool mAllowPlayerStep; 184 185 /// If true each submesh within the TSShape is culled 186 /// against the object space frustum. 187 bool mMeshCulling; 188 189 /// If true the shape is sorted by the origin of the 190 /// model instead of the nearest point of the bounds. 191 bool mUseOriginSort; 192 193 PhysicsBody *mPhysicsRep; 194 195 // Debug stuff 196 F32 mRenderNormalScalar; 197 S32 mForceDetail; 198 199public: 200 201 TSStatic(); 202 ~TSStatic(); 203 204 DECLARE_CONOBJECT(TSStatic); 205 static void initPersistFields(); 206 static bool _setFieldSkin( void *object, const char* index, const char* data ); 207 static const char *_getFieldSkin( void *object, const char *data ); 208 209 // Skinning 210 void setSkinName( const char *name ); 211 void reSkin(); 212 213 // NetObject 214 U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); 215 void unpackUpdate( NetConnection *conn, BitStream *stream ); 216 217 // SceneObject 218 void setTransform( const MatrixF &mat ); 219 void onScaleChanged(); 220 void prepRenderImage( SceneRenderState *state ); 221 void inspectPostApply(); 222 virtual void onMount( SceneObject *obj, S32 node ); 223 virtual void onUnmount( SceneObject *obj, S32 node ); 224 225 /// The type of mesh data use for collision queries. 226 MeshType getCollisionType() const { return mCollisionType; } 227 228 bool allowPlayerStep() const { return mAllowPlayerStep; } 229 230 Resource<TSShape> getShape() const { return mShape; } 231 StringTableEntry getShapeFileName() { return mShapeName; } 232 void setShapeFileName(StringTableEntry shapeName) { mShapeName = shapeName; } 233 234 TSShapeInstance* getShapeInstance() const { return mShapeInstance; } 235 236 const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; } 237 238 const Vector<S32>& getLOSDetails() const { return mLOSDetails; } 239 240}; 241 242typedef TSStatic::MeshType TSMeshType; 243DefineEnumType( TSMeshType ); 244 245#endif // _H_TSSTATIC 246 247
