colladaAppMesh.h
Engine/source/ts/collada/colladaAppMesh.h
Classes:
class
class
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 _COLLADA_APPMESH_H_ 25#define _COLLADA_APPMESH_H_ 26 27#ifndef _TDICTIONARY_H_ 28#include "core/util/tDictionary.h" 29#endif 30#ifndef _APPMESH_H_ 31#include "ts/loader/appMesh.h" 32#endif 33#ifndef _TSSHAPELOADER_H_ 34#include "ts/loader/tsShapeLoader.h" 35#endif 36#ifndef _COLLADA_APPNODE_H_ 37#include "ts/collada/colladaAppNode.h" 38#endif 39#ifndef _COLLADA_EXTENSIONS_H_ 40#include "ts/collada/colladaExtensions.h" 41#endif 42 43//----------------------------------------------------------------------------- 44// Torque unifies the vert position, normal and UV values, so that a single index 45// uniquely identifies all 3 elements. A triangle then contains just 3 indices, 46// and from that we can get the 3 positions, 3 normals and 3 UVs. 47// 48// for i=1:3 49// index = indices[triangle.start + i] 50// points[index], normals[index], uvs[index] 51// 52// Collada does not use unified vertex streams, (each triangle needs 9 indices), 53// so this structure is used to map a single VertTuple index to 3 indices into 54// the Collada streams. The Collada (and Torque) primitive index is also stored 55// because the Collada document may use different streams for different primitives. 56// 57// For morph geometry, we can use the same array of VertTuples to access the base 58// AND all of the target geometries because they MUST have the same topology. 59struct VertTuple 60{ 61 S32 prim, vertex, normal, color, uv, uv2; 62 63 Point3F dataVertex, dataNormal; 64 ColorI dataColor; 65 Point2F dataUV, dataUV2; 66 67 VertTuple(): prim(-1), vertex(-1), normal(-1), color(-1), uv(-1), uv2(-1) {} 68 bool operator==(const VertTuple& p) const 69 { 70 return dataVertex == p.dataVertex && 71 dataColor == p.dataColor && 72 dataNormal == p.dataNormal && 73 dataUV == p.dataUV && 74 dataUV2 == p.dataUV2; 75 } 76}; 77 78class ColladaAppMesh : public AppMesh 79{ 80 typedef AppMesh Parent; 81 82protected: 83 class ColladaAppNode* appNode; ///< Pointer to the node that owns this mesh 84 const domInstance_geometry* instanceGeom; 85 const domInstance_controller* instanceCtrl; 86 ColladaExtension_geometry* geomExt; ///< geometry extension 87 88 Vector<VertTuple> vertTuples; ///< 89 Map<StringTableEntry,U32> boundMaterials; ///< Local map of symbols to materials 90 91 static bool fixedSizeEnabled; ///< Set to true to fix the detail size to a particular value for all geometry 92 static S32 fixedSize; ///< The fixed detail size value for all geometry 93 94 //----------------------------------------------------------------------- 95 96 /// Get the morph controller for this mesh (if any) 97 const domMorph* getMorph() 98 { 99 if (instanceCtrl) { 100 const domController* ctrl = daeSafeCast<domController>(instanceCtrl->getUrl().getElement()); 101 if (ctrl && ctrl->getSkin()) 102 ctrl = daeSafeCast<domController>(ctrl->getSkin()->getSource().getElement()); 103 return ctrl ? ctrl->getMorph() : NULL; 104 } 105 return NULL; 106 } 107 108 S32 addMaterial(const char* symbol); 109 110 bool checkGeometryType(const daeElement* element); 111 void getPrimitives(const domGeometry* geometry); 112 113 void getVertexData( const domGeometry* geometry, F32 time, const MatrixF& objOffset, 114 Vector<Point3F>& points, Vector<Point3F>& norms, Vector<ColorI>& colors, 115 Vector<Point2F>& uvs, Vector<Point2F>& uv2s, bool appendValues); 116 117 void getMorphVertexData( const domMorph* morph, F32 time, const MatrixF& objOffset, 118 Vector<Point3F>& points, Vector<Point3F>& norms, Vector<ColorI>& colors, 119 Vector<Point2F>& uvs, Vector<Point2F>& uv2s ); 120 121public: 122 123 ColladaAppMesh(const domInstance_geometry* instance, ColladaAppNode* node); 124 ColladaAppMesh(const domInstance_controller* instance, ColladaAppNode* node); 125 ~ColladaAppMesh() 126 { 127 delete geomExt; 128 } 129 130 static void fixDetailSize(bool fixed, S32 size=2) 131 { 132 fixedSizeEnabled = fixed; 133 fixedSize = size; 134 } 135 136 /// Get the name of this mesh 137 /// 138 /// @return A string containing the name of this mesh 139 const char *getName(bool allowFixed=true); 140 141 //----------------------------------------------------------------------- 142 143 /// Get a floating point property value 144 /// 145 /// @param propName Name of the property to get 146 /// @param defaultVal Reference to variable to hold return value 147 /// 148 /// @return True if a value was set, false if not 149 bool getFloat(const char *propName, F32 &defaultVal) 150 { 151 return appNode->getFloat(propName,defaultVal); 152 } 153 154 /// Get an integer property value 155 /// 156 /// @param propName Name of the property to get 157 /// @param defaultVal Reference to variable to hold return value 158 /// 159 /// @return True if a value was set, false if not 160 bool getInt(const char *propName, S32 &defaultVal) 161 { 162 return appNode->getInt(propName,defaultVal); 163 } 164 165 /// Get a boolean property value 166 /// 167 /// @param propName Name of the property to get 168 /// @param defaultVal Reference to variable to hold return value 169 /// 170 /// @return True if a value was set, false if not 171 bool getBool(const char *propName, bool &defaultVal) 172 { 173 return appNode->getBool(propName,defaultVal); 174 } 175 176 /// Return true if this mesh is a skin 177 bool isSkin() 178 { 179 if (instanceCtrl) { 180 const domController* ctrl = daeSafeCast<domController>(instanceCtrl->getUrl().getElement()); 181 if (ctrl && ctrl->getSkin() && 182 (ctrl->getSkin()->getVertex_weights()->getV()->getValue().getCount() > 0)) 183 return true; 184 } 185 return false; 186 } 187 188 /// Get the skin data: bones, vertex weights etc 189 void lookupSkinData(); 190 191 /// Check if the mesh visibility is animated 192 /// 193 /// @param appSeq Start/end time to check 194 /// 195 /// @return True if the mesh visibility is animated, false if not 196 bool animatesVis(const AppSequence* appSeq); 197 198 /// Check if the material used by this mesh is animated 199 /// 200 /// @param appSeq Start/end time to check 201 /// 202 /// @return True if the material is animated, false if not 203 bool animatesMatFrame(const AppSequence* appSeq); 204 205 /// Check if the mesh is animated 206 /// 207 /// @param appSeq Start/end time to check 208 /// 209 /// @return True if the mesh is animated, false if not 210 bool animatesFrame(const AppSequence* appSeq); 211 212 /// Generate the vertex, normal and triangle data for the mesh. 213 /// 214 /// @param time Time at which to generate the mesh data 215 /// @param objOffset Transform to apply to the generated data (bounds transform) 216 void lockMesh(F32 time, const MatrixF& objOffset); 217 218 /// Get the transform of this mesh at a certain time 219 /// 220 /// @param time Time at which to get the transform 221 /// 222 /// @return The mesh transform at the specified time 223 MatrixF getMeshTransform(F32 time); 224 225 /// Get the visibility of this mesh at a certain time 226 /// 227 /// @param time Time at which to get visibility info 228 /// 229 /// @return Visibility from 0 (invisible) to 1 (opaque) 230 F32 getVisValue(F32 time); 231}; 232 233#endif // _COLLADA_APPMESH_H_ 234