2
0

ColladaHelper.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /** Helper structures for the Collada loader */
  2. /*
  3. Open Asset Import Library (ASSIMP)
  4. ----------------------------------------------------------------------
  5. Copyright (c) 2006-2008, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the
  9. following conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ----------------------------------------------------------------------
  33. */
  34. #ifndef AI_COLLADAHELPER_H_INC
  35. #define AI_COLLADAHELPER_H_INC
  36. namespace Assimp
  37. {
  38. namespace Collada
  39. {
  40. /** Transformation types that can be applied to a node */
  41. enum TransformType
  42. {
  43. TF_LOOKAT,
  44. TF_ROTATE,
  45. TF_TRANSLATE,
  46. TF_SCALE,
  47. TF_SKEW,
  48. TF_MATRIX
  49. };
  50. /** Contains all data for one of the different transformation types */
  51. struct Transform
  52. {
  53. TransformType mType;
  54. float f[16]; ///< Interpretation of data depends on the type of the transformation
  55. };
  56. /** A reference to a mesh inside a node, including materials assigned to the various subgroups */
  57. struct MeshInstance
  58. {
  59. std::string mMesh; ///< ID of the mesh
  60. std::map<std::string, std::string> mMaterials; ///< Map of materials by the subgroup ID they're applied to
  61. };
  62. /** A node in a scene hierarchy */
  63. struct Node
  64. {
  65. std::string mName;
  66. std::string mID;
  67. Node* mParent;
  68. std::vector<Node*> mChildren;
  69. /** Operations in order to calculate the resulting transformation to parent. */
  70. std::vector<Transform> mTransforms;
  71. std::vector<MeshInstance> mMeshes; ///< Meshes at this node
  72. Node() { mParent = NULL; }
  73. ~Node() { for( std::vector<Node*>::iterator it = mChildren.begin(); it != mChildren.end(); ++it) delete *it; }
  74. };
  75. /** Data source array */
  76. struct Data
  77. {
  78. std::vector<float> mValues;
  79. };
  80. /** Accessor to a data array */
  81. struct Accessor
  82. {
  83. size_t mCount; // in number of objects
  84. size_t mOffset; // in number of values
  85. size_t mStride; // Stride in number of values
  86. std::vector<std::string> mParams; // names of the data streams in the accessors. Empty string tells to ignore.
  87. size_t mSubOffset[4]; // Suboffset inside the object for the common 4 elements. For a vector, thats XYZ, for a color RGBA and so on.
  88. // For example, SubOffset[0] denotes which of the values inside the object is the vector X component.
  89. std::string mSource; // URL of the source array
  90. mutable const Data* mData; // Pointer to the source array, if resolved. NULL else
  91. Accessor()
  92. {
  93. mCount = 0; mOffset = 0; mStride = 0; mData = NULL;
  94. mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0;
  95. }
  96. };
  97. /** A single face in a mesh */
  98. struct Face
  99. {
  100. std::vector<size_t> mIndices;
  101. };
  102. /** Different types of input data to a vertex or face */
  103. enum InputType
  104. {
  105. IT_Invalid,
  106. IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data.
  107. IT_Position,
  108. IT_Normal,
  109. IT_Texcoord,
  110. IT_Color
  111. };
  112. /** An input channel for mesh data, referring to a single accessor */
  113. struct InputChannel
  114. {
  115. InputType mType; // Type of the data
  116. size_t mIndex; // Optional index, if multiple sets of the same data type are given
  117. size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better.
  118. std::string mAccessor; // ID of the accessor where to read the actual values from.
  119. mutable const Accessor* mResolved; // Pointer to the accessor, if resolved. NULL else
  120. InputChannel() { mType = IT_Invalid; mIndex = 0; mOffset = 0; mResolved = NULL; }
  121. };
  122. /** Contains data for a single mesh */
  123. struct Mesh
  124. {
  125. std::string mVertexID; // just to check if there's some sophisticated addressing involved... which we don't support, and therefore should warn about.
  126. std::vector<InputChannel> mPerVertexData; // Vertex data addressed by vertex indices
  127. // actual mesh data, assembled on encounter of a <p> element. Verbose format, not indexed
  128. std::vector<aiVector3D> mPositions;
  129. std::vector<aiVector3D> mNormals;
  130. std::vector<aiVector2D> mTexCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  131. std::vector<aiColor4D> mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  132. // Faces. Stored are only the number of vertices for each face. 1 == point, 2 == line, 3 == triangle, 4+ == poly
  133. std::vector<size_t> mFaceSize;
  134. };
  135. /** Which type of primitives the ReadPrimitives() function is going to read */
  136. enum PrimitiveType
  137. {
  138. Prim_Invalid,
  139. Prim_Lines,
  140. Prim_LineStrip,
  141. Prim_Triangles,
  142. Prim_TriStrips,
  143. Prim_TriFans,
  144. Prim_Polylist,
  145. Prim_Polygon
  146. };
  147. /** A collada material. Pretty much the only member is a reference to an effect. */
  148. struct Material
  149. {
  150. std::string mEffect;
  151. };
  152. /** Shading type supported by the standard effect spec of Collada */
  153. enum ShadeType
  154. {
  155. Shade_Invalid,
  156. Shade_Constant,
  157. Shade_Lambert,
  158. Shade_Phong,
  159. Shade_Blinn
  160. };
  161. /** A collada effect. Can contain about anything according to the Collada spec, but we limit our version to a reasonable subset. */
  162. struct Effect
  163. {
  164. ShadeType mShadeType;
  165. aiColor4D mEmmisive, mAmbient, mDiffuse, mSpecular;
  166. aiColor4D mReflectivity, mRefractivity;
  167. std::string mTexEmmisive, mTexAmbient, mTexDiffuse, mTexSpecular;
  168. float mShininess, mRefractIndex;
  169. Effect() : mEmmisive( 0, 0, 0, 1), mAmbient( 0.1f, 0.1f, 0.1f, 1),
  170. mDiffuse( 0.6f, 0.6f, 0.6f, 1), mSpecular( 0.4f, 0.4f, 0.4f, 1),
  171. mReflectivity( 0, 0, 0, 0), mRefractivity( 0, 0, 0, 0)
  172. {
  173. mShadeType = Shade_Phong;
  174. mShininess = 10;
  175. mRefractIndex = 1;
  176. }
  177. };
  178. /** An image, meaning texture */
  179. struct Image
  180. {
  181. std::string mFileName;
  182. };
  183. } // end of namespace Collada
  184. } // end of namespace Assimp
  185. #endif // AI_COLLADAHELPER_H_INC