ScummVM API documentation
MeshLoaderCollada.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_MESH_LOADER_COLLADA_H
29 #define HPL_MESH_LOADER_COLLADA_H
30 
31 #include "common/list.h"
32 #include "hpl1/engine/graphics/VertexBuffer.h"
33 #include "hpl1/engine/math/MathTypes.h"
34 #include "hpl1/engine/physics/PhysicsJoint.h"
35 #include "hpl1/engine/resources/MeshLoader.h"
36 #include "hpl1/engine/system/MemoryManager.h"
37 
38 class TiXmlElement;
39 
40 namespace hpl {
41 
42 class cMesh;
43 class cNode3D;
44 class iVertexBuffer;
45 class cBone;
46 class cAnimation;
47 class cAnimationTrack;
48 class cSkeleton;
49 class cWorld3D;
50 class cSector;
51 class cMeshEntity;
52 class iPhysicsBody;
53 class cColliderEntity;
54 class cMeshJoint;
55 class cSystem;
56 
58 // HELP CLASSES
59 
61 public:
62  tString msId;
63  tString msName;
64 
65  tString msSource;
66 };
67 
69 
70 //------------------------------------------------
71 
73 public:
74  tString msId;
75  tString msName;
76 
77  tString msImage;
78 };
79 
81 
82 //------------------------------------------------
83 
85 public:
86  tString msId;
87  tString msName;
88 
89  tString msTexture;
90  cColor mDiffuseColor;
91 };
92 
94 
95 //------------------------------------------------
96 
98 public:
99  tString msId;
100  tString msName;
101  tString msType;
102 
103  cColor mDiffuseColor;
104  float mfAngle;
105 };
106 
108 
109 //------------------------------------------------
110 
112 public:
113  cColladaVtxArray() : mbIsInVertex(false) {}
114 
115  tString msId;
116  tString msType;
117  bool mbIsInVertex;
118 
119  tVector3fVec mvArray;
120 };
121 
123 
125 public:
126  int mlVtx;
127  int mlNorm;
128  int mlTex;
129 };
130 
132 
133 //------------------------------------------------
134 
136 public:
137  cColladaExtraVtx(int alVtx, int alNorm, int alTex, int alNewVtx) {
138  mlVtx = alVtx;
139  mlNorm = alNorm;
140  mlTex = alTex;
141  mlNewVtx = alNewVtx;
142  }
143 
144  cColladaExtraVtx() {}
145 
146  int mlVtx;
147  int mlNorm;
148  int mlTex;
149 
150  int mlNewVtx;
151 
152  bool Equals(const cColladaVtxIndex &aData) {
153  if (mlVtx == aData.mlVtx && mlNorm == aData.mlNorm && mlTex == aData.mlTex) {
154  return true;
155  }
156 
157  return false;
158  }
159 };
160 
163 
165 
166 //------------------------------------------------
167 
169 public:
170  cColladaGeometry() : mlPosArrayIdx(-1), mlNormArrayIdx(-1), mlTexArrayIdx(-1),
171  mlPosIdxNum(-1), mlNormIdxNum(-1), mlTexIdxNum(-1) {}
172 
173  void Clear() {
174  mvIndices.clear();
175 
176  for (int i = 0; i < (int)mvArrayVec.size(); i++) {
177  mvArrayVec[i].mvArray.clear();
178  }
179  /*mvVertexVec.clear();
180  mvIndexVec.clear();
181  mvExtraVtxVec.clear();*/
182  }
183 
184  tString msId;
185  tString msName;
186 
187  tVertexVec mvVertexVec;
188  tUIntVec mvIndexVec;
189  tColladaExtraVtxListVec mvExtraVtxVec;
190  tFloatVec mvTangents;
191 
192  tString msMaterial;
193 
194  // THe following are ONLY used when loading from a geometry element.!!
195  tColladaVtxArrayVec mvArrayVec;
196  tColladaVtxIndexVec mvIndices;
197 
198  int mlPosIdxNum; // The position in the triangle element
199  int mlNormIdxNum; // for eternal use only
200  int mlTexIdxNum;
201 
202  int mlPosArrayIdx; // The index for array containing positions
203  int mlNormArrayIdx; // The index for array containing normals
204  int mlTexArrayIdx; // The index for array containing texcoords
205 };
206 
208 
209 //------------------------------------------------
210 
212 public:
213  cColladaJointPair() {}
214  cColladaJointPair(int alJoint, int alWeight) {
215  mlJoint = alJoint;
216  mlWeight = alWeight;
217  }
218 
219  int mlJoint;
220  int mlWeight;
221 };
222 
225 
227 
229 public:
230  cColladaController() : mlJointPairIdx(-1), mlWeightPairIdx(-1) {}
231 
232  tString msTarget;
233  tString msId;
234 
235  cMatrixf m_mtxBindShapeMatrix;
236 
237  int mlJointPairIdx;
238  int mlWeightPairIdx;
239 
240  tStringVec mvJoints;
241  tFloatVec mvWeights;
242  tMatrixfVec mvMatrices;
243 
244  tColladaJointPairListVec mvPairs;
245 };
246 
248 
249 //------------------------------------------------
250 
252 public:
253  tString msId;
254  tString msTarget;
255  tString msSource;
256 };
257 
259 
261 public:
262  tString msId;
263  tString msTimeArray;
264  tString msValueArray;
265 
266  tString msTarget;
267 };
268 
270 
272 public:
273  tString msId;
274  tFloatVec mvValues;
275 };
276 
278 
280 public:
281  tString msId;
282  // tString msName;
283  tString msTargetNode;
284 
285  tColladaChannelVec mvChannels;
286  tColladaSamplerVec mvSamplers;
287 
288  tColladaAnimSourceVec mvSources;
289 
290  tFloatVec *GetSourceVec(const tString &asId) {
291  for (size_t i = 0; i < mvSources.size(); i++) {
292  if (mvSources[i].msId == asId) {
293  return &mvSources[i].mvValues;
294  }
295  }
296 
297  return NULL;
298  }
299 };
300 
302 
303 //------------------------------------------------
304 
306 public:
307  tString msSid;
308  tString msType;
309  tFloatVec mvValues;
310 };
311 
314 
315 class cColladaNode;
318 
320 public:
321  cColladaNode() : mlCount(0), pParent(NULL), mvScale(1, 1, 1), mbSourceIsFile(false) {}
322 
323  tString msId;
324  tString msName;
325  tString msType;
326 
327  tString msSource;
328  bool mbSourceIsFile;
329 
330  cMatrixf m_mtxTransform;
331  cMatrixf m_mtxWorldTransform;
332 
333  cColladaNode *pParent;
334 
335  cVector3f mvScale;
336 
337  int mlCount;
338 
339  tColladaNodeList mlstChildren;
340 
341  tColladaTransformList mlstTransforms;
342 
343  /*void DeleteChildren()
344  {
345  STLDeleteAll(mlstChildren);
346  }*/
347 
348  cColladaNode *CreateChild() {
349  cColladaNode *pNode = hplNew(cColladaNode, ());
350  mlstChildren.push_back(pNode);
351  pNode->pParent = this;
352  return pNode;
353  }
354 
355  cColladaTransform *GetTransform(const tString &asSid) {
356  tColladaTransformListIt it = mlstTransforms.begin();
357  for (; it != mlstTransforms.end(); it++) {
358  cColladaTransform &Trans = *it;
359  if (Trans.msSid == asSid) {
360  return &Trans;
361  }
362  }
363  return NULL;
364  }
365 };
366 
368 public:
369  cColladaScene() {
370  mRoot.m_mtxTransform = cMatrixf::Identity;
371  mRoot.m_mtxWorldTransform = cMatrixf::Identity;
372 
373  mfDeltaTime = 0;
374  }
375 
376  ~cColladaScene() {
377  // mRoot.DeleteChildren();
378  STLDeleteAll(mlstNodes);
379  }
380 
381  void ResetNodes() {
382  STLDeleteAll(mlstNodes);
383  mRoot.mlstChildren.clear();
384  }
385 
386  cColladaNode *GetNode(const tString asId) {
387  tColladaNodeListIt it = mlstNodes.begin();
388  for (; it != mlstNodes.end(); ++it) {
389  cColladaNode *pNode = *it;
390  if (pNode->msId == asId || pNode->msName == asId) {
391  return pNode;
392  }
393  }
394 
395  return NULL;
396  }
397 
398  cColladaNode *GetNodeFromSource(const tString asSource) {
399  tColladaNodeListIt it = mlstNodes.begin();
400  for (; it != mlstNodes.end(); ++it) {
401  cColladaNode *pNode = *it;
402  if (pNode->msSource == asSource) {
403  return pNode;
404  }
405  }
406 
407  return NULL;
408  }
409 
410  float mfStartTime;
411  float mfEndTime;
412  float mfDeltaTime;
413 
414  cColladaNode mRoot;
415 
416  tColladaNodeList mlstNodes;
417 };
418 
419 //------------------------------------------------
420 
422 public:
423  cMeshLoaderCollada(iLowLevelGraphics *apLowLevelGraphics);
424  virtual ~cMeshLoaderCollada();
425 
426  cMesh *LoadMesh(const tString &asFile, tMeshLoadFlag aFlags);
427  bool SaveMesh(cMesh *apMesh, const tString &asFile) { return false; }
428 
429  cWorld3D *LoadWorld(const tString &asFile, cScene *apScene, tWorldLoadFlag aFlags);
430 
431  cAnimation *LoadAnimation(const tString &asFile);
432 
433  bool IsSupported(const tString asFileType);
434 
435  void AddSupportedTypes(tStringVec *avFileTypes);
436 
437 private:
438  bool mbZToY;
439 
440  tWorldLoadFlag mFlags;
441 
442  tString GetParentName(cColladaNode *apNode, tColladaGeometryVec *apColladaGeometries);
443 
444  void CreateMeshJoint(cMeshJoint *apJoint, ePhysicsJointType aJointType, cBoundingVolume &aBV,
445  tStringVec &avStrings, cColladaNode *apNode, cColladaScene &aColladaScene,
446  tColladaGeometryVec &avColladaGeom);
447 
448  void CreateHierarchyNodes(cMesh *apMesh, cNode3D *mpParentNode,
449  cColladaNode *apColladaNode,
450  tColladaGeometryVec &avColladaGeom);
451 
452  cColladaGeometry *GetGeometry(const tString &asId, tColladaGeometryVec &avGeomVec);
453  cColladaLight *GetLight(const tString &asId, tColladaLightVec &avLightVec);
454 
455  cMeshEntity *CreateStaticMeshEntity(cColladaNode *apNode, cWorld3D *apWorld,
456  cColladaGeometry *apGeom, bool abInRoomGroup,
457  tColladaMaterialVec &avColladaMaterials,
458  tColladaTextureVec &avColladaTextures,
459  tColladaImageVec &avColladaImages);
460 
461  cColliderEntity *CreateStaticCollider(cColladaNode *apNode, cWorld3D *apWorld,
462  cColladaGeometry *apGeom,
463  tColladaMaterialVec &avColladaMaterials,
464  tColladaTextureVec &avColladaTextures,
465  tColladaImageVec &avColladaImages,
466  bool abCharacterCollider);
467 
468  void AddSceneObjects(cColladaNode *apNode, cWorld3D *apWorld,
469  tColladaGeometryVec &avColladaGeometries, tColladaLightVec &avColladaLights,
470  tColladaMaterialVec &avColladaMaterials, tColladaTextureVec &avColladaTextures,
471  tColladaImageVec &avColladaImages, cColladaScene *apColladaScene);
472 
473  void AddSectorChildren(cColladaNode *apNode, tString asSector, cWorld3D *apWorld,
474  tColladaGeometryVec &avColladaGeometries, tColladaLightVec &avColladaLights,
475  tColladaMaterialVec &avColladaMaterials, tColladaTextureVec &avColladaTextures,
476  tColladaImageVec &avColladaImages);
477 
478  cAnimationTrack *CreateAnimTrack(cAnimation *apAnimation, cSkeleton *apSkeleton,
479  cColladaAnimation &aAnim, cColladaScene *apScene);
480 
481  void CalcLocalMatrixRec(cBone *apBone, cMatrixf a_mtxParentGlobal, int alDepth);
482 
483  void CreateSkeletonBone(cColladaNode *apColladaNode, cBone *apParentBone);
484 
485  iVertexBuffer *CreateVertexBuffer(cColladaGeometry &aGeometry,
486  eVertexBufferUsageType aUsageType);
487  // tColladaExtraVtxListVec &vExtraVtxVec);
488 
489  bool FillStructures(const tString &asFile,
490  tColladaImageVec *apColladaImageVec,
491  tColladaTextureVec *apColladaTextureVec,
492  tColladaMaterialVec *apColladaMaterialVec,
493  tColladaLightVec *apColladaLightVec,
494  tColladaGeometryVec *apColladaGeometryVec,
495  tColladaControllerVec *apColladaControllerVec,
496  tColladaAnimationVec *apColladaAnimVec,
497  cColladaScene *apColladaScene,
498  bool abCache);
499 
500  bool SaveStructures(const tString &asFile,
501  tColladaImageVec *apColladaImageVec,
502  tColladaTextureVec *apColladaTextureVec,
503  tColladaMaterialVec *apColladaMaterialVec,
504  tColladaLightVec *apColladaLightVec,
505  tColladaGeometryVec *apColladaGeometryVec,
506  tColladaControllerVec *apColladaControllerVec,
507  tColladaAnimationVec *apColladaAnimVec,
508  cColladaScene *apColladaScene);
509 
510  bool LoadStructures(const tString &asFile,
511  tColladaImageVec *apColladaImageVec,
512  tColladaTextureVec *apColladaTextureVec,
513  tColladaMaterialVec *apColladaMaterialVec,
514  tColladaLightVec *apColladaLightVec,
515  tColladaGeometryVec *apColladaGeometryVec,
516  tColladaControllerVec *apColladaControllerVec,
517  tColladaAnimationVec *apColladaAnimVec,
518  cColladaScene *apColladaScene);
519 
520  void LoadColladaScene(TiXmlElement *apRootElem, cColladaNode *apParentNode, cColladaScene *apScene,
521  tColladaLightVec *apColladaLightVec);
522 
523  void LoadAnimations(TiXmlElement *apRootElem, tColladaAnimationVec &avAnimations,
524  cColladaScene *apColladaScene);
525 
526  void LoadImages(TiXmlElement *apRootElem, tColladaImageVec &avColladaImageVec);
527 
528  void LoadTextures(TiXmlElement *apRootElem, tColladaTextureVec &avColladaTextureVec);
529 
530  void LoadMaterials(TiXmlElement *apRootElem, tColladaMaterialVec &avColladaMaterialVec);
531 
532  void LoadLights(TiXmlElement *apRootElem, tColladaLightVec &avColladaLightVec);
533 
534  void LoadGeometry(TiXmlElement *apRootElem, tColladaGeometryVec &avColladaGeometryVec, cColladaScene *apColladaScene);
535  void LoadVertexData(TiXmlElement *apSourceElem, tVector3fVec &avVtxVec);
536 
537  void LoadControllers(TiXmlElement *apRootElem, tColladaControllerVec &avColladaControllerVec,
538  tColladaGeometryVec *apColladaGeometryVec);
539  void LoadJointData(TiXmlElement *apSourceElem, cColladaController &aController);
540 
541  // Helpers
542  void SplitVertices(cColladaGeometry &aGeometry, tColladaExtraVtxListVec &avExtraVtxVec,
543  tVertexVec &avVertexVec, tUIntVec &avIndexVec);
544 
545  void FillVertexVec(const char *apChars, tVector3fVec &avVtxVec, int alElements, int alVtxCount);
546  tString GetTopString(const tString asPath);
547  tString GetMaterialTextureFile(const tString &asMaterial, tColladaMaterialVec &avColladaMaterialVec,
548  tColladaTextureVec &avColladaTextureVec,
549  tColladaImageVec &avColladaImageVec);
550 
551  cVector3f GetVectorPos(const cVector3f &avVec);
552  cVector3f GetVectorPosFromPtr(float *apVec);
553  cVector3f GetVectorScaleFromPtr(float *apVec);
554 };
555 
556 } // namespace hpl
557 
558 #endif // HPL_MESH_LOADER_COLLADA_H
Definition: AI.h:36
Definition: MeshLoaderCollada.h:228
Definition: AnimationTrack.h:40
Definition: str.h:59
Definition: MeshLoaderCollada.h:271
Definition: Skeleton.h:46
Definition: VertexBuffer.h:90
Definition: array.h:52
Definition: MeshLoaderCollada.h:168
Definition: list.h:44
Definition: MeshLoaderCollada.h:305
Definition: Mesh.h:215
Definition: BoundingVolume.h:71
Definition: MeshLoaderCollada.h:97
Definition: ColliderEntity.h:40
Definition: MeshLoaderCollada.h:111
Definition: Animation.h:44
Definition: Mesh.h:96
iterator end()
Definition: list.h:240
iterator begin()
Definition: list.h:227
Definition: Node3D.h:52
Definition: World3D.h:179
Definition: MeshLoaderCollada.h:211
size_type size() const
Definition: array.h:315
Definition: MeshLoaderCollada.h:421
Definition: MeshLoaderCollada.h:135
Definition: MeshLoaderCollada.h:260
Definition: MeshLoaderCollada.h:251
Definition: MeshLoaderCollada.h:124
Definition: Color.h:37
Definition: Bone.h:47
Definition: tinyxml.h:864
Definition: list_intern.h:51
Definition: Scene.h:61
Definition: MeshEntity.h:96
Definition: MeshLoader.h:60
void push_back(const t_T &element)
Definition: list.h:140
Definition: MeshLoaderCollada.h:319
Definition: MeshLoaderCollada.h:367
Definition: MeshLoaderCollada.h:60
Definition: MeshLoaderCollada.h:72
Definition: LowLevelGraphics.h:200
Definition: MeshLoaderCollada.h:84
Definition: MeshLoaderCollada.h:279