tsStatic.h

Engine/source/T3D/tsStatic.h

More...

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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#ifndef _TSSTATIC_H_
 30#define _TSSTATIC_H_
 31
 32#ifndef _SCENEOBJECT_H_
 33#include "scene/sceneObject.h"
 34#endif
 35#ifndef _CONVEX_H_
 36#include "collision/convex.h"
 37#endif
 38#ifndef __RESOURCE_H__
 39#include "core/resource.h"
 40#endif
 41#ifndef _NETSTRINGTABLE_H_
 42#include "sim/netStringTable.h"
 43#endif
 44#ifndef _TSSHAPE_H_
 45#include "ts/tsShape.h"
 46#endif
 47
 48#ifndef _REFLECTOR_H_
 49#include "scene/reflector.h"
 50#endif
 51
 52#ifndef _COLLADA_UTILS_H_
 53#include "ts/collada/colladaUtils.h"
 54#endif
 55
 56#ifndef _ASSET_PTR_H_
 57#include "assets/assetPtr.h"
 58#endif 
 59#ifndef SHAPEASSET_H
 60#include "T3D/assets/ShapeAsset.h"
 61#endif 
 62
 63class TSShapeInstance;
 64class TSThread;
 65class TSStatic;
 66class PhysicsBody;
 67struct ObjectRenderInst;
 68
 69
 70class TSStaticPolysoupConvex : public Convex
 71{
 72   typedef Convex Parent;
 73   friend class TSMesh;
 74
 75public:
 76   TSStaticPolysoupConvex();
 77   ~TSStaticPolysoupConvex() {};
 78
 79public:
 80   Box3F                box;
 81   Point3F              verts[4];
 82   PlaneF               normal;
 83   S32                  idx;
 84   TSMesh* mesh;
 85
 86   static SceneObject* smCurObject;
 87
 88public:
 89
 90   // Returns the bounding box in world coordinates
 91   Box3F getBoundingBox() const;
 92   Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
 93
 94   void getFeatures(const MatrixF& mat, const VectorF& n, ConvexFeature* cf);
 95
 96   // This returns a list of convex faces to collide against
 97   void getPolyList(AbstractPolyList* list);
 98
 99   // This returns the furthest point from the input vector
100   Point3F support(const VectorF& v) const;
101};
102
103
104/// A simple mesh shape with optional ambient animation.
105class TSStatic : public SceneObject
106{
107   typedef SceneObject Parent;
108
109   static U32 smUniqueIdentifier;
110
111   enum MaskBits
112   {
113      TransformMask = Parent::NextFreeMask << 0,
114      AdvancedStaticOptionsMask = Parent::NextFreeMask << 1,
115      UpdateCollisionMask = Parent::NextFreeMask << 2,
116      SkinMask = Parent::NextFreeMask << 3,
117      MaterialMask = Parent::NextFreeMask << 4,
118      NextFreeMask = Parent::NextFreeMask << 5
119   };
120
121public:
122   void setAlphaFade(bool enable, F32 start, F32 end, bool inverse)
123   {
124      mUseAlphaFade = enable;
125      mAlphaFadeStart = start;
126      mAlphaFadeEnd = end;
127      mInvertAlphaFade = inverse;
128   }
129
130   /// The different types of mesh data types
131   enum MeshType
132   {
133      None = 0,            ///< No mesh
134      Bounds = 1,          ///< Bounding box of the shape
135      CollisionMesh = 2,   ///< Specifically designated collision meshes
136      VisibleMesh = 3      ///< Rendered mesh polygons
137   };
138
139protected:
140   bool mUseAlphaFade;
141   F32  mAlphaFadeStart;
142   F32  mAlphaFadeEnd;
143   F32  mAlphaFade;
144   bool mInvertAlphaFade;
145
146   struct matMap
147   {
148      MaterialAsset* matAsset;
149      String assetId;
150      U32 slot;
151   };
152
153   Vector<matMap>  mChangingMaterials;
154   Vector<matMap>  mMaterials;
155
156   bool onAdd();
157   void onRemove();
158
159   // Collision
160   void prepCollision();
161   bool castRay(const Point3F& start, const Point3F& end, RayInfo* info);
162   bool castRayRendered(const Point3F& start, const Point3F& end, RayInfo* info);
163   bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F& box, const SphereF& sphere);
164   bool buildExportPolyList(ColladaUtils::ExportData* exportData, const Box3F& box, const SphereF&);
165   void buildConvex(const Box3F& box, Convex* convex);
166
167   bool setShapeAsset(const StringTableEntry shapeAssetId);
168
169   bool _createShape();
170
171   void _updatePhysics();
172
173   void _renderNormals(ObjectRenderInst* ri, SceneRenderState* state, BaseMatInstance* overrideMat);
174
175   void _onResourceChanged(const Torque::Path& path);
176   void _onAssetChanged();
177
178   // ProcessObject
179   virtual void processTick(const Move* move);
180   virtual void interpolateTick(F32 delta);
181   virtual void advanceTime(F32 dt);
182
183   virtual void onDynamicModified(const char* slotName, const char* newValue);
184
185   /// Start or stop processing ticks depending on our state.
186   void _updateShouldTick();
187
188   String cubeDescName;
189   U32 cubeDescId;
190   ReflectorDesc* reflectorDesc;
191   CubeReflector mCubeReflector;
192
193protected:
194
195   Convex* mConvexList;
196
197   StringTableEntry  mShapeName;
198   U32               mShapeHash;
199   Resource<TSShape> mShape;
200   Vector<S32> mCollisionDetails;
201   Vector<S32> mLOSDetails;
202   TSShapeInstance* mShapeInstance;
203
204   AssetPtr<ShapeAsset> mShapeAsset;
205   StringTableEntry mShapeAssetId;
206
207   NetStringHandle   mSkinNameHandle;
208   String            mAppliedSkinName;
209
210   bool              mPlayAmbient;
211   TSThread*         mAmbientThread;
212   F32               mAnimOffset;
213   F32               mAnimSpeed;
214   /// The type of mesh data to return for collision queries.
215   MeshType mCollisionType;
216
217   /// The type of mesh data to return for decal polylist queries.
218   MeshType mDecalType;
219
220   bool mAllowPlayerStep;
221
222   /// If true each submesh within the TSShape is culled 
223   /// against the object space frustum.
224   bool mMeshCulling;
225
226   /// If true the shape is sorted by the origin of the
227   /// model instead of the nearest point of the bounds.
228   bool mUseOriginSort;
229
230   PhysicsBody* mPhysicsRep;
231
232   LinearColorF mOverrideColor;
233
234   // Debug stuff
235   F32 mRenderNormalScalar;
236   S32 mForceDetail;
237
238public:
239
240   TSStatic();
241   ~TSStatic();
242
243   DECLARE_CONOBJECT(TSStatic);
244   static void initPersistFields();
245   static void consoleInit();
246   static bool _setShapeAsset(void* obj, const char* index, const char* data);
247   static bool _setShapeName(void* obj, const char* index, const char* data);
248   static bool _setFieldSkin(void* object, const char* index, const char* data);
249   static const char* _getFieldSkin(void* object, const char* data);
250
251   // Skinning
252   void setSkinName(const char* name);
253   void reSkin();
254
255   // NetObject
256   U32 packUpdate(NetConnection* conn, U32 mask, BitStream* stream);
257   void unpackUpdate(NetConnection* conn, BitStream* stream);
258
259   // SceneObject
260   void setTransform(const MatrixF& mat);
261   void onScaleChanged();
262   void prepRenderImage(SceneRenderState* state);
263   void inspectPostApply();
264   virtual void onMount(SceneObject* obj, S32 node);
265   virtual void onUnmount(SceneObject* obj, S32 node);
266
267   /// The type of mesh data use for collision queries.
268   MeshType getCollisionType() const { return mCollisionType; }
269
270   bool allowPlayerStep() const { return mAllowPlayerStep; }
271
272   Resource<TSShape> getShape() const { return mShape; }
273   StringTableEntry getShapeFileName() { return mShapeName; }
274   void setShapeFileName(StringTableEntry shapeName) { mShapeName = shapeName; }
275
276   TSShapeInstance* getShapeInstance() const { return mShapeInstance; }
277
278   U32 getNumDetails();
279
280   const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
281
282   const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
283   bool hasAnim() { return mAmbientThread != NULL; }
284
285   virtual void onInspect(GuiInspector*);
286
287   void updateMaterials();
288
289   bool isAnimated() { return mPlayAmbient; }
290
291   virtual void getUtilizedAssets(Vector<StringTableEntry>* usedAssetsList);
292
293private:
294   virtual void   onStaticModified(const char* slotName, const char* newValue = NULL);
295protected:
296   Vector<S32>    mDecalDetails;
297   Vector<S32>* mDecalDetailsPtr;
298
299   ///Indicates if all statics should utilize the distance-based object fadeout logic
300   static bool    smUseStaticObjectFade;
301
302   ///Distance at which static object fading begins if smUseStaticObjectFade is on
303   static F32 smStaticObjectFadeStart;
304
305   ///Distance at which static object fading should have fully faded if smUseStaticObjectFade is on
306   static F32 smStaticObjectFadeEnd;
307
308   ///Size of object where if the bounds is at or bigger than this, it will be ignored in the smUseStaticObjectFade logic. Useful for very large, distance-important objects
309   static F32 smStaticObjectUnfadeableSize;
310public:
311   bool           mIgnoreZodiacs;
312   bool           mHasGradients;
313   bool           mInvertGradientRange;
314   Point2F        mGradientRangeUser;
315   Point2F        mGradientRange;
316private:
317   void           set_special_typing();
318   virtual void setSelectionFlags(U8 flags);
319};
320
321typedef TSStatic::MeshType TSMeshType;
322DefineEnumType(TSMeshType);
323
324#endif // _H_TSSTATIC
325
326