Torque3D Documentation / _generateds / tsShapeLoader.h

tsShapeLoader.h

Engine/source/ts/loader/tsShapeLoader.h

More...

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 _TSSHAPE_LOADER_H_
 25#define _TSSHAPE_LOADER_H_
 26
 27#ifndef _MMATH_H_
 28#include "math/mMath.h"
 29#endif
 30#ifndef _TVECTOR_H_
 31#include "core/util/tVector.h"
 32#endif
 33#ifndef _TSSHAPE_H_
 34#include "ts/tsShape.h"
 35#endif
 36#ifndef _APPNODE_H_
 37#include "ts/loader/appNode.h"
 38#endif
 39#ifndef _APPMESH_H_
 40#include "ts/loader/appMesh.h"
 41#endif
 42#ifndef _APPSEQUENCE_H_
 43#include "ts/loader/appSequence.h"
 44#endif
 45
 46class TSShapeLoader
 47{
 48
 49// Supported Format List
 50protected:
 51   struct ShapeFormat
 52   {
 53      String mName;
 54      String mExtension;
 55   };
 56   static Vector<ShapeFormat> smFormats;
 57public:
 58   static void addFormat(String name, String extension);
 59   static String getFormatExtensions();
 60   static String getFormatFilters();
 61   static bool isSupportedFormat(String extension);
 62
 63public:
 64   enum eLoadPhases
 65   {
 66      Load_ReadFile = 0,
 67      Load_ParseFile,
 68      Load_ExternalRefs,
 69      Load_EnumerateScene,
 70      Load_GenerateSubshapes,
 71      Load_GenerateObjects,
 72      Load_GenerateDefaultStates,
 73      Load_GenerateSkins,
 74      Load_GenerateMaterials,
 75      Load_GenerateSequences,
 76      Load_InitShape,
 77      NumLoadPhases,
 78      Load_Complete = NumLoadPhases
 79   };
 80
 81   static void updateProgress(S32 major, const char* msg, S32 numMinor=0, S32 minor=0);
 82
 83protected:
 84   struct Subshape
 85   {
 86      Vector<AppNode*>           branches;         ///< Shape branches
 87      Vector<AppMesh*>           objMeshes;        ///< Object meshes for this subshape
 88      Vector<S32>                objNodes;         ///< AppNode indices with objects attached
 89
 90      ~Subshape()
 91      {
 92         // Delete children
 93         for (S32 i = 0; i < branches.size(); i++)
 94            delete branches[i];
 95      }
 96   };
 97
 98public:
 99   static const F32 DefaultTime;
100   static const F64 MinFrameRate;
101   static const F64 MaxFrameRate;
102   static const F64 AppGroundFrameRate;
103
104protected:
105   // Variables used during loading that must be held until the shape is deleted
106   TSShape*                      shape;
107   Vector<AppMesh*>              appMeshes;
108
109   // Variables used during loading, but that can be discarded afterwards
110   static Torque::Path           shapePath;
111
112   AppNode*                      boundsNode;
113   Vector<AppNode*>              appNodes;            ///< Nodes in the loaded shape
114   Vector<AppSequence*>          appSequences;
115
116   Vector<Subshape*>             subshapes;
117
118   Vector<QuatF*>                nodeRotCache;
119   Vector<Point3F*>              nodeTransCache;
120   Vector<QuatF*>                nodeScaleRotCache;
121   Vector<Point3F*>              nodeScaleCache;
122
123   //--------------------------------------------------------------------------
124
125   // Collect the nodes, objects and sequences for the scene
126   virtual void enumerateScene() = 0;
127   bool processNode(AppNode* node);
128   virtual bool ignoreNode(const String& name) { return false; }
129   virtual bool ignoreMesh(const String& name) { return false; }
130
131   void addSkin(AppMesh* mesh);
132   void addDetailMesh(AppMesh* mesh);
133   void addSubshape(AppNode* node);
134   void addObject(AppMesh* mesh, S32 nodeIndex, S32 subShapeNum);
135
136   // Node transform methods
137   MatrixF getLocalNodeMatrix(AppNode* node, F32 t);
138   void generateNodeTransform(AppNode* node, F32 t, bool blend, F32 referenceTime,
139                              QuatF& rot, Point3F& trans, QuatF& srot, Point3F& scale);
140
141   virtual void computeBounds(Box3F& bounds);
142
143   // Create objects, materials and sequences
144   void recurseSubshape(AppNode* appNode, S32 parentIndex, bool recurseChildren);
145
146   void generateSubshapes();
147   void generateObjects();
148   void generateSkins();
149   void generateDefaultStates();
150   void generateObjectState(TSShape::Object& obj, F32 t, bool addFrame, bool addMatFrame);
151   void generateFrame(TSShape::Object& obj, F32 t, bool addFrame, bool addMatFrame);
152
153   void generateMaterialList();
154
155   void generateSequences();
156
157   // Determine what is actually animated in the sequence
158   void setNodeMembership(TSShape::Sequence& seq, const AppSequence* appSeq);
159   void setRotationMembership(TSShape::Sequence& seq);
160   void setTranslationMembership(TSShape::Sequence& seq);
161   void setScaleMembership(TSShape::Sequence& seq);
162   void setObjectMembership(TSShape::Sequence& seq, const AppSequence* appSeq);
163
164   // Manage a cache of all node transform elements for the sequence
165   void clearNodeTransformCache();
166   void fillNodeTransformCache(TSShape::Sequence& seq, const AppSequence* appSeq);
167
168   // Add node transform elements
169   void addNodeRotation(QuatF& rot, bool defaultVal);
170   void addNodeTranslation(Point3F& trans, bool defaultVal);
171   void addNodeUniformScale(F32 scale);
172   void addNodeAlignedScale(Point3F& scale);
173   void addNodeArbitraryScale(QuatF& qrot, Point3F& scale);
174
175   // Generate animation data
176   void generateNodeAnimation(TSShape::Sequence& seq);
177   void generateObjectAnimation(TSShape::Sequence& seq, const AppSequence* appSeq);
178   void generateGroundAnimation(TSShape::Sequence& seq, const AppSequence* appSeq);
179   void generateFrameTriggers(TSShape::Sequence& seq, const AppSequence* appSeq);
180
181   // Shape construction
182   void sortDetails();
183   void install();
184
185public:
186   TSShapeLoader() : boundsNode(0), shape(NULL) { }
187   virtual ~TSShapeLoader();
188
189   static const Torque::Path& getShapePath() { return shapePath; }
190
191   static void zapScale(MatrixF& mat);
192
193   TSShape* generateShape(const Torque::Path& path);
194};
195
196#endif // _TSSHAPE_LOADER_H_
197