PageRenderTime 66ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/opencollada/COLLADAMax/include/COLLADAMaxGeometryImporter.h

https://github.com/AsherBond/MondocosmOS
C Header | 192 lines | 65 code | 51 blank | 76 comment | 0 complexity | 410c10daad6069768831de71e5574a71 MD5 | raw file
  1. /*
  2. Copyright (c) 2008-2009 NetAllied Systems GmbH
  3. This file is part of COLLADAMax.
  4. Portions of the code are:
  5. Copyright (c) 2005-2007 Feeling Software Inc.
  6. Copyright (c) 2005-2007 Sony Computer Entertainment America
  7. Based on the 3dsMax COLLADASW Tools:
  8. Copyright (c) 2005-2006 Autodesk Media Entertainment
  9. Licensed under the MIT Open Source License,
  10. for details please see LICENSE file or the website
  11. http://www.opensource.org/licenses/mit-license.php
  12. */
  13. #ifndef __COLLADAMAX_GEOMETRYIMPORTER_H__
  14. #define __COLLADAMAX_GEOMETRYIMPORTER_H__
  15. #include "COLLADAMaxPrerequisites.h"
  16. #include "COLLADAMaxImporterBase.h"
  17. #include "COLLADAFWMeshPrimitive.h"
  18. #include "COLLADAFWMeshVertexData.h"
  19. class MNMap;
  20. namespace COLLADAFW
  21. {
  22. class Geometry;
  23. class Mesh;
  24. };
  25. namespace COLLADAMax
  26. {
  27. /** Imports a geometry into the max scene.
  28. If the geometry is referenced by a node that has already been imported, the geometry
  29. is attached to that nodes, otherwise the geometry does not belong to a node.*/
  30. class GeometryImporter : public ImporterBase
  31. {
  32. private:
  33. /** Maps initial indices from index list of multiple texture or color inputs to the index of the source*/
  34. typedef std::map<size_t /* initial index*/, size_t /* Source index*/> InitialIndexSourceIndexMap;
  35. /** Maps index of the source to the initial indices from index list of multiple texture or color inputs*/
  36. typedef std::map<size_t /* Source index*/, size_t /* initial index*/> SourceIndexInitialIndexMap;
  37. /** set index -1 corresponds to color channel.*/
  38. typedef std::pair<long/*set index negative for color positive for uv*/,size_t /* initial index*/> SetSourcePair;
  39. typedef std::map<SetSourcePair, int /* max map channel*/> SetSourcePairMapChannelMap;
  40. private:
  41. /** The geometry that should be imported.*/
  42. const COLLADAFW::Geometry* mGeometry;
  43. /** The number of all triangles in all primitives that contain triangles (Triangles,
  44. Tristrips, Trisfans).*/
  45. size_t mTotalTrianglesCount;
  46. /** Maps a set index, source ( data source in MeshVertexData) pair to the max map channel.*/
  47. SetSourcePairMapChannelMap mSetSourcePairMapChannelMap;
  48. /** Maps initial indices from index list of multiple texture inputs to the index of the source*/
  49. InitialIndexSourceIndexMap mUVInitialIndexSourceIndexMap;
  50. /** Maps index of the source to the initial indices from index list of multiple texture inputs*/
  51. SourceIndexInitialIndexMap mUVSourceIndexInitialIndexMap;
  52. /** Maps initial indices from index list of multiple color inputs to the index of the source*/
  53. InitialIndexSourceIndexMap mColorInitialIndexSourceIndexMap;
  54. /** Maps index of the source to the initial indices from index list of multiple color inputs*/
  55. SourceIndexInitialIndexMap mColorSourceIndexInitialIndexMap;
  56. /** The number of the largest map channel used.*/
  57. int mLargestMapChannel;
  58. /** True, if the geometry has per vertex color.*/
  59. bool mHasVertexColor;
  60. public:
  61. /** Constructor. */
  62. GeometryImporter( DocumentImporter* documentImporter, const COLLADAFW::Geometry* geometry );
  63. /** Destructor. */
  64. virtual ~GeometryImporter();
  65. /** Performs the import of the geometry.
  66. @return True on success, false otherwise.*/
  67. bool import();
  68. /** Performs the import of the mesh.
  69. @return True on success, false otherwise.*/
  70. bool importMesh();
  71. /** Performs the import of a mesh that contains only triangles.
  72. @return True on success, false otherwise.*/
  73. bool importTriangleMesh();
  74. /** Performs the import of the mesh positions of a mesh that contains only triangles.
  75. @return True on success, false otherwise.*/
  76. bool importTriangleMeshPositions( TriObject* triangleObject );
  77. /** Performs the import of the mesh normals of a mesh that contains only triangles.
  78. @return True on success, false otherwise.*/
  79. bool importTriangleMeshNormals( TriObject* triangleObject );
  80. /** Performs the import of the mesh uv coordinates of a mesh that contains only triangles.
  81. @return True on success, false otherwise.*/
  82. bool importTriangleMeshUVCoords( TriObject* triangleObject );
  83. /** Performs the import of a mesh that contains polygons.
  84. @return True on success, false otherwise.*/
  85. bool importPolygonMesh();
  86. /** Performs the import of the mesh positions of a mesh that contains polygons.
  87. @return True on success, false otherwise.*/
  88. bool importPolygonMeshPositions( PolyObject* polygonObject );
  89. /** Performs the import of the mesh normals of a mesh that contains polygons.
  90. @return True on success, false otherwise.*/
  91. bool importPolygonMeshNormals( PolyObject* polygonObject );
  92. /** Performs the import of the mesh uv coordinates of a mesh that contains polygons.
  93. @return True on success, false otherwise.*/
  94. bool importPolygonMeshUVCoords( PolyObject* polygonObject );
  95. /** Fills the map with pair of frame work material ids of the used by primitives in @a primitiveArray
  96. and material ids used in Max. The max material ids start with 1 and are increased for each new
  97. framework material id.*/
  98. void createFWMaterialIdMaxMtlIdMap( const COLLADAFW::MeshPrimitiveArray& primitiveArray, DocumentImporter::FWMaterialIdMaxMtlIdMap& materialMap);
  99. private:
  100. /** Disable default copy ctor. */
  101. GeometryImporter( const GeometryImporter& pre );
  102. /** Disable default assignment operator. */
  103. const GeometryImporter& operator= ( const GeometryImporter& pre );
  104. /** Creates the SetSourcePairMapChannelMap using the current geometry.*/
  105. void createSetSourcePairMapChannelMap();
  106. /** assigns map channel to inputs in the indexlist array add inserts them to mSetSourcePairMapChannelMap.
  107. @return false if all map channel are used, true otherwise.*/
  108. template<bool isColorChannel, bool isFirstTry>
  109. bool assignMapChannels( const COLLADAFW::IndexListArray& indices,
  110. const InitialIndexSourceIndexMap& initialIndexSourceIndexMap,
  111. bool usedMapChannels[MAX_MESHMAPS + NUM_HIDDENMAPS]);
  112. /** Sets the uv vertices stored in uvArray into @a meshMap.
  113. @param uvArray The vertices source
  114. @param meshMap The mesh map to be filled
  115. @param stride The size of the uv vertex tuples
  116. @param startPosition The index of the first vertexs first component in the uvArray
  117. @param vertsCount the number of vertices to copy. Must be equal to the number set with MeshMap::setNumFaces()*/
  118. template<class NumberArray>
  119. void setTriangleMeshUVVertices(const NumberArray& uvArray, MeshMap& meshMap, size_t stride, size_t startPosition, size_t vertsCount);
  120. /** Sets the uv vertices stored in uvArray into @a meshMap.
  121. @param uvArray The vertices source
  122. @param meshMap The mesh map to be filled
  123. @param stride The size of the uv vertex tuples
  124. @param startPosition The index of the first vertexs first component in the uvArray
  125. @param vertsCount the number of vertices to copy. Must be equal to the number set with MeshMap::setNumFaces()*/
  126. template<class NumberArray>
  127. void setPolygonMeshUVVertices(const NumberArray& uvArray, MNMap* meshMap, size_t stride, size_t startPosition, size_t vertsCount);
  128. void setPolygonMeshUVVerticesPerPrimitiveAndChannel( const COLLADAFW::MeshPrimitive* meshPrimitive, MNMap* meshMap, const COLLADAFW::UIntValuesArray& uvIndices, unsigned int initialIndex, size_t& currentFaceIndex);
  129. void fillPolygonMeshMapPerSet( const COLLADAFW::MeshVertexData& uvCoordinates, const COLLADAFW::MeshVertexData::InputInfosArray& inputInfos, size_t sourceIndex, MNMap* meshMap);
  130. void setTriangleMeshUVVerticesPerPrimitiveAndChannel( const COLLADAFW::MeshPrimitive* meshPrimitive, MeshMap& meshMap, const COLLADAFW::UIntValuesArray& uvIndices, unsigned int initialIndex, size_t& currentFaceIndex);
  131. void fillTriangleMeshMapPerSet( const COLLADAFW::MeshVertexData& uvCoordinates, const COLLADAFW::MeshVertexData::InputInfosArray& inputInfos, size_t sourceIndex, MeshMap& meshMap);
  132. /** Checks if @a dataIndices contains data. If so, it returns false. Otherwise it returns true and increases @a faceIndex
  133. by the number of faces of @a meshPrimitive.*/
  134. bool skipMeshData( const COLLADAFW::MeshPrimitive* meshPrimitive, const COLLADAFW::UIntValuesArray& dataIndices, size_t& faceIndex);
  135. };
  136. } // namespace COLLADAMAX
  137. #endif // __COLLADAMAX_GEOMETRYIMPORTER_H__