mesh.d 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2009, 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 following
  9. 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. /**
  35. * Contains the data structures in which the imported geometry is returned by
  36. * Assimp.
  37. */
  38. module assimp.mesh;
  39. import assimp.math;
  40. import assimp.types;
  41. extern ( C ) {
  42. /*
  43. * These limits are required to match the settings Assimp was compiled
  44. * against. Therfore, do not redefine them unless you build the library
  45. * from source using the same definitions.
  46. */
  47. /**
  48. * Maximum number of indices per face (polygon).
  49. */
  50. const AI_MAX_FACE_INDICES = 0x7fff;
  51. /**
  52. * Maximum number of indices per face (polygon).
  53. */
  54. const AI_MAX_BONE_WEIGHTS = 0x7fffffff;
  55. /**
  56. * Maximum number of vertices per mesh.
  57. */
  58. const AI_MAX_VERTICES = 0x7fffffff;
  59. /**
  60. * Maximum number of faces per mesh.
  61. */
  62. const AI_MAX_FACES = 0x7fffffff;
  63. /**
  64. * Supported number of vertex color sets per mesh.
  65. */
  66. const AI_MAX_NUMBER_OF_COLOR_SETS = 0x4;
  67. /**
  68. * Supported number of texture coord sets (UV(W) channels) per mesh.
  69. */
  70. const AI_MAX_NUMBER_OF_TEXTURECOORDS = 0x4;
  71. /**
  72. * A single face in a mesh, referring to multiple vertices.
  73. *
  74. * If <code>mNumIndices</code> is 3, we call the face <em>triangle</em>, for
  75. * for <code>mNumIndices > 3</code> it's called <em>polygon</em>.
  76. *
  77. * <code>aiMesh.mPrimitiveTypes</code> can be queried to quickly examine
  78. * which types of primitive are actually present in a mesh. The
  79. * <code>aiProcess.SortByPType</code> flag post-processing step splits
  80. * meshes containing different primitive types (e.g. lines and triangles) in
  81. * several "clean" submeshes.
  82. *
  83. * Furthermore, there is a configuration option
  84. * (<code>AI_CONFIG_PP_SBP_REMOVE</code>) to force <code>SortByPType</code>
  85. * to completely remove specific kinds of primitives from the imported scene.
  86. * In many cases you'll probably want to set this setting to
  87. * <code>aiPrimitiveType.LINE | aiPrimitiveType.POINT</code>. Together with
  88. * the <code>aiProcess.Triangulate</code> flag you can then be sure that
  89. * <code>mNumIndices</code> is always 3.
  90. */
  91. struct aiFace {
  92. /**
  93. * Number of indices defining this face.
  94. *
  95. * The maximum value for this member is <code>AI_MAX_FACE_INDICES</code>.
  96. */
  97. uint mNumIndices;
  98. /**
  99. * Array of the indices defining the face.
  100. *
  101. * The size is given in <code>mNumIndices</code>.
  102. */
  103. uint* mIndices;
  104. }
  105. /**
  106. * A single influence of a bone on a vertex.
  107. */
  108. struct aiVertexWeight {
  109. /**
  110. * Index of the vertex which is influenced by the bone.
  111. */
  112. uint mVertexId;
  113. /**
  114. * The strength of the influence in the range <code>[0..1]</code>.
  115. *
  116. * The influence from all bones at one vertex sums up to 1.
  117. */
  118. float mWeight;
  119. }
  120. /**
  121. * A single bone of a mesh.
  122. *
  123. * A bone has a name by which it can be found in the frame hierarchy and by
  124. * which it can be addressed by animations. In addition it has a number of
  125. * influences on vertices.
  126. */
  127. struct aiBone {
  128. /**
  129. * The name of the bone.
  130. */
  131. aiString mName;
  132. /**
  133. * The number of vertices affected by this bone.
  134. *
  135. * The maximum value for this member is <code>AI_MAX_BONE_WEIGHTS</code>.
  136. */
  137. uint mNumWeights;
  138. /**
  139. * The vertices affected by this bone.
  140. *
  141. * This array is <code>mNumWeights</code> entries in size.
  142. */
  143. aiVertexWeight* mWeights;
  144. /**
  145. * Matrix that transforms from mesh space to bone space (in the bind
  146. * pose).
  147. */
  148. aiMatrix4x4 mOffsetMatrix;
  149. }
  150. /**
  151. * Enumerates the types of geometric primitives supported by Assimp.
  152. *
  153. * See: <code>aiFace</code>, <code>aiProcess.SortByPType</code>,
  154. * <code>aiProcess.Triangulate</code>,
  155. * <code>AI_CONFIG_PP_SBP_REMOVE</code>.
  156. */
  157. enum aiPrimitiveType : uint {
  158. /** A point primitive.
  159. *
  160. * This is just a single vertex in the virtual world,
  161. * <code>aiFace</code> contains just one index for such a primitive.
  162. */
  163. POINT = 0x1,
  164. /** A line primitive.
  165. *
  166. * This is a line defined through a start and an end position.
  167. * <code>aiFace</code> contains exactly two indices for such a primitive.
  168. */
  169. LINE = 0x2,
  170. /** A triangular primitive.
  171. *
  172. * A triangle consists of three indices.
  173. */
  174. TRIANGLE = 0x4,
  175. /** A higher-level polygon with more than 3 edges.
  176. *
  177. * A triangle is a polygon, but in this context, polygon means
  178. * "all polygons that are not triangles". The <code>Triangulate</code>
  179. * post processing step is provided for your convenience, it splits all
  180. * polygons in triangles (which are much easier to handle).
  181. */
  182. POLYGON = 0x8
  183. }
  184. // Note: The AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) macro from the C headers is
  185. // missing since there is probably not much use for it when just reading
  186. // scene files.
  187. /**
  188. * NOT CURRENTLY IN USE. An AnimMesh is an attachment to an #aiMesh stores
  189. * per-vertex animations for a particular frame.
  190. *
  191. * You may think of an <code>aiAnimMesh</code> as a `patch` for the host
  192. * mesh, which replaces only certain vertex data streams at a particular
  193. * time.
  194. *
  195. * Each mesh stores n attached attached meshes (<code>aiMesh.mAnimMeshes</code>).
  196. * The actual relationship between the time line and anim meshes is
  197. * established by #aiMeshAnim, which references singular mesh attachments
  198. * by their ID and binds them to a time offset.
  199. */
  200. struct aiAnimMesh {
  201. /**
  202. * Replacement for aiMesh.mVertices.
  203. *
  204. * If this array is non-null, it *must* contain mNumVertices entries.
  205. * The corresponding array in the host mesh must be non-null as well -
  206. * animation meshes may neither add or nor remove vertex components (if
  207. * a replacement array is NULL and the corresponding source array is
  208. * not, the source data is taken instead).
  209. */
  210. aiVector3D* mVertices;
  211. /// Replacement for <code>aiMesh.mNormals</code>.
  212. aiVector3D* mNormals;
  213. /// Replacement for <code>aiMesh.mTangents</code>.
  214. aiVector3D* mTangents;
  215. /// Replacement for <code>aiMesh.mBitangents</code>.
  216. aiVector3D* mBitangents;
  217. /// Replacement for <code>aiMesh.mColors</code>.
  218. aiColor4D* mColors[ AI_MAX_NUMBER_OF_COLOR_SETS ];
  219. /// Replacement for <code>aiMesh.mTextureCoords</code>.
  220. aiVector3D* mTextureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  221. /**
  222. * The number of vertices in the aiAnimMesh, and thus the length of all
  223. * the member arrays.
  224. *
  225. * This has always the same value as the mNumVertices property in the
  226. * corresponding aiMesh. It is duplicated here merely to make the length
  227. * of the member arrays accessible even if the aiMesh is not known, e.g.
  228. * from language bindings.
  229. */
  230. uint mNumVertices;
  231. }
  232. /**
  233. * A mesh represents a geometry or model with a single material.
  234. *
  235. * It usually consists of a number of vertices and a series
  236. * primitives/faces referencing the vertices. In addition there might be a
  237. * series of bones, each of them addressing a number of vertices with a
  238. * certain weight. Vertex data is presented in channels with each channel
  239. * containing a single per-vertex information such as a set of texture
  240. * coords or a normal vector. If a data pointer is non-null, the
  241. * corresponding data stream is present.
  242. *
  243. * A mesh uses only a single material which is referenced by a material ID.
  244. *
  245. * Note: The <code>mPositions</code> member is usually not optional.
  246. * However, vertex positions <em>could</em> be missing if the
  247. * <code>AI_SCENE_FLAGS_INCOMPLETE</code> flag is set in
  248. * <code>aiScene.mFlags</code>.
  249. */
  250. struct aiMesh {
  251. /**
  252. * Bitwise combination of <code>aiPrimitiveType</code> members.
  253. *
  254. * This specifies which types of primitives are present in the mesh.
  255. * The <code>SortByPrimitiveType</code> post processing step can be used
  256. * to make sure the output meshes consist of one primitive type each.
  257. */
  258. uint mPrimitiveTypes;
  259. /**
  260. * The number of vertices in this mesh.
  261. *
  262. * This is also the size of all of the per-vertex data arrays. The
  263. * maximum value for this member is <code>AI_MAX_VERTICES</code>.
  264. */
  265. uint mNumVertices;
  266. /**
  267. * The number of primitives (triangles, polygons, lines) in this mesh.
  268. *
  269. * This is also the size of the <code>mFaces</code> array. The maximum
  270. * value for this member is <code>AI_MAX_FACES</code>.
  271. */
  272. uint mNumFaces;
  273. /**
  274. * Vertex positions.
  275. *
  276. * This array is always present in a mesh. The array is
  277. * <code>mNumVertices</code> in size.
  278. */
  279. aiVector3D* mVertices;
  280. /**
  281. * Vertex normals.
  282. *
  283. * The array contains normalized vectors, null if not present.
  284. * The array is <code>mNumVertices</code> in size.
  285. *
  286. * Normals are undefined for point and line primitives. A mesh
  287. * consisting of points and lines only may not have normal vectors.
  288. * Meshes with mixed primitive types (i.e. lines and triangles) may have
  289. * normals, but the normals for vertices that are only referenced by
  290. * point or line primitives are undefined and set to <code>QNAN</code>.
  291. *
  292. * Note: Normal vectors computed by Assimp are always unit-length.
  293. * However, this needn't apply for normals that have been taken
  294. * directly from the model file.
  295. */
  296. aiVector3D* mNormals;
  297. /**
  298. * Vertex tangents.
  299. *
  300. * The tangent of a vertex points in the direction of the positive x
  301. * texture axis. The array contains normalized vectors, null if
  302. * not present. The array is <code>mNumVertices</code> in size.
  303. *
  304. * A mesh consisting of points and lines only may not have normal
  305. * vectors. Meshes with mixed primitive types (i.e. lines and triangles)
  306. * may have normals, but the normals for vertices that are only
  307. * referenced by point or line primitives are undefined and set to
  308. * <code>QNAN</code>.
  309. *
  310. * Note: If the mesh contains tangents, it automatically also contains
  311. * bitangents (the bitangent is just the cross product of tangent and
  312. * normal vectors).
  313. */
  314. aiVector3D* mTangents;
  315. /**
  316. * Vertex bitangents.
  317. *
  318. * The bitangent of a vertex points in the direction of the positive Y
  319. * texture axis. The array contains normalized vectors, null if not
  320. * present. The array is <code>mNumVertices</code> in size.
  321. *
  322. * Note: If the mesh contains tangents, it automatically also contains
  323. * bitangents.
  324. */
  325. aiVector3D* mBitangents;
  326. /**
  327. * Vertex color sets.
  328. *
  329. * A mesh may contain 0 to <code>AI_MAX_NUMBER_OF_COLOR_SETS</code>
  330. * vertex colors per vertex. null if not present.
  331. *
  332. * Each array is <code>mNumVertices</code> in size if present.
  333. */
  334. aiColor4D* mColors[ AI_MAX_NUMBER_OF_COLOR_SETS ];
  335. /**
  336. * Vertex texture coords, also known as UV channels.
  337. * A mesh may contain 0 to <code>AI_MAX_NUMBER_OF_TEXTURECOORDS</code>
  338. * per vertex. null if not present.
  339. *
  340. * Each array is <code>mNumVertices</code> in size.
  341. */
  342. aiVector3D* mTextureCoords[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  343. /**
  344. * Specifies the number of components for a given UV channel.
  345. *
  346. * Up to three channels are supported (UVW, for accessing volume or cube
  347. * maps). If the value is 2 for a given channel <code>n</code>, the
  348. * component <code>p.z</code> of <code>mTextureCoords[n][p]</code> is set
  349. * to 0. If the value is 1 for a given channel, <code>p.y</code> is set
  350. * to 0, too. If this value is 0, 2 should be assumed.
  351. *
  352. * Note: 4D coords are not supported.
  353. */
  354. uint mNumUVComponents[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  355. /**
  356. * The faces the mesh is contstructed from.
  357. *
  358. * Each face refers to a number of vertices by their indices.
  359. * This array is always present in a mesh, its size is given
  360. * in <code>mNumFaces</code>. If the
  361. * <code>AI_SCENE_FLAGS_NON_VERBOSE_FORMAT</code> is <em>not</em> set,
  362. * each face references an unique set of vertices.
  363. */
  364. aiFace* mFaces;
  365. /**
  366. * The number of bones this mesh contains.
  367. *
  368. * Can be 0, in which case the <code>mBones</code> array is null.
  369. */
  370. uint mNumBones;
  371. /**
  372. * The bones of this mesh.
  373. *
  374. * A bone consists of a name by which it can be found in the frame
  375. * hierarchy and a set of vertex weights.
  376. */
  377. aiBone** mBones;
  378. /**
  379. * The material used by this mesh.
  380. *
  381. * A mesh does use only a single material. If an imported model uses
  382. * multiple materials, the import splits up the mesh. Use this value as
  383. * index into the scene's material list.
  384. */
  385. uint mMaterialIndex;
  386. /**
  387. * Name of the mesh.
  388. *
  389. * Meshes can be named, but this is not a requirement and leaving this
  390. * field empty is totally fine.
  391. *
  392. * There are mainly three uses for mesh names:
  393. * - Some formats name nodes and meshes independently.
  394. * - Importers tend to split meshes up to meet the one-material-per-mesh
  395. * requirement. Assigning the same (dummy) name to each of the result
  396. * meshes aids the caller at recovering the original mesh partitioning.
  397. * - Vertex animations refer to meshes by their names.
  398. */
  399. aiString mName;
  400. /// NOT CURRENTLY IN USE. The number of attachment meshes.
  401. uint mNumAnimMeshes;
  402. /**
  403. * NOT CURRENTLY IN USE. Attachment meshes for this mesh, for vertex-
  404. * based animation.
  405. *
  406. * Attachment meshes carry replacement data for some of the mesh's
  407. * vertex components (usually positions, normals).
  408. */
  409. aiAnimMesh** mAnimMeshes;
  410. }
  411. }