FBXDocument.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file FBXDocument.h
  34. * @brief FBX DOM
  35. */
  36. #ifndef INCLUDED_AI_FBX_DOCUMENT_H
  37. #define INCLUDED_AI_FBX_DOCUMENT_H
  38. #include <vector>
  39. #include <map>
  40. #include <string>
  41. namespace Assimp {
  42. namespace FBX {
  43. class Parser;
  44. class Object;
  45. /** Represents a delay-parsed FBX objects. Many objects in the scene
  46. * are not needed by assimp, so it makes no sense to parse them
  47. * upfront. */
  48. class LazyObject
  49. {
  50. public:
  51. LazyObject(const Element& element);
  52. ~LazyObject();
  53. public:
  54. const Object* Get();
  55. template <typename T>
  56. T* Get() {
  57. const Object* const ob = Get();
  58. return ob ? dynamic_cast<T*>(ob) : NULL;
  59. }
  60. private:
  61. const Element& element;
  62. boost::scoped_ptr<const Object> object;
  63. };
  64. /** Base class for in-memory (DOM) representations of FBX objects */
  65. class Object
  66. {
  67. public:
  68. Object(const Element& element);
  69. ~Object();
  70. public:
  71. protected:
  72. const Element& element;
  73. };
  74. /** DOM base class for all kinds of FBX geometry */
  75. class Geometry : public Object
  76. {
  77. public:
  78. Geometry(const Element& element);
  79. ~Geometry();
  80. };
  81. /** DOM class for FBX geometry of type "Mesh"*/
  82. class MeshGeometry : public Geometry
  83. {
  84. public:
  85. MeshGeometry(const Element& element);
  86. ~MeshGeometry();
  87. public:
  88. /** Get a list of all vertex points, non-unique*/
  89. const std::vector<aiVector3D>& GetVertices() const {
  90. return vertices;
  91. }
  92. /** Get a list of all vertex normals or an empty array if
  93. * no normals are specified. */
  94. const std::vector<aiVector3D>& GetNormals() const {
  95. return normals;
  96. }
  97. /** Get a list of all vertex tangents or an empty array
  98. * if no tangents are specified */
  99. const std::vector<aiVector3D>& GetTangents() const {
  100. return tangents;
  101. }
  102. /** Return list of faces - each entry denotes a face and specifies
  103. * how many vertices it has. Vertices are taken from the
  104. * vertex data arrays in sequential order. */
  105. const std::vector<unsigned int>& GetFaceIndexCounts() const {
  106. return faces;
  107. }
  108. /** Get a UV coordinate slot, returns an empty array if
  109. * the requested slot does not exist. */
  110. const std::vector<aiVector3D>& GetTextureCoords(unsigned int index) const {
  111. static const std::vector<aiVector3D> empty;
  112. return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? empty : uvs[index];
  113. }
  114. /** Get a vertex color coordinate slot, returns an empty array if
  115. * the requested slot does not exist. */
  116. const std::vector<aiColor4D>& GetVertexColors(unsigned int index) const {
  117. static const std::vector<aiColor4D> empty;
  118. return index >= AI_MAX_NUMBER_OF_COLOR_SETS ? empty : colors[index];
  119. }
  120. /** Get per-face-vertex material assignments */
  121. const std::vector<unsigned int>& GetMaterialIndices() const {
  122. return materials;
  123. }
  124. public:
  125. private:
  126. // cached data arrays
  127. std::vector<unsigned int> materials;
  128. std::vector<aiVector3D> vertices;
  129. std::vector<unsigned int> faces;
  130. std::vector<aiVector3D> tangents;
  131. std::vector<aiVector3D> normals;
  132. std::vector<aiVector3D> uvs[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  133. std::vector<aiColor4D> colors[AI_MAX_NUMBER_OF_COLOR_SETS];
  134. };
  135. // XXX again, unique_ptr would be useful. shared_ptr is too
  136. // bloated since the objects have a well-defined single owner
  137. // during their entire lifetime (Document). FBX files have
  138. // up to many thousands of objects (most of which we never use),
  139. // so the memory overhead for them should be kept at a minimum.
  140. typedef std::map<uint64_t, LazyObject*> ObjectMap;
  141. /** DOM root for a FBX file */
  142. class Document
  143. {
  144. public:
  145. Document(const Parser& parser);
  146. ~Document();
  147. public:
  148. const ObjectMap& Objects() const {
  149. return objects;
  150. }
  151. private:
  152. ObjectMap objects;
  153. const Parser& parser;
  154. };
  155. }
  156. }
  157. #endif