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