scene.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp 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 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. /** @file aiScene.h
  35. * @brief Defines the data structures in which the imported scene is returned.
  36. */
  37. #ifndef __AI_SCENE_H_INC__
  38. #define __AI_SCENE_H_INC__
  39. #include "types.h"
  40. #include "texture.h"
  41. #include "mesh.h"
  42. #include "light.h"
  43. #include "camera.h"
  44. #include "material.h"
  45. #include "anim.h"
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. // -------------------------------------------------------------------------------
  50. /** A node in the imported hierarchy.
  51. *
  52. * Each node has name, a parent node (except for the root node),
  53. * a transformation relative to its parent and possibly several child nodes.
  54. * Simple file formats don't support hierarchical structures - for these formats
  55. * the imported scene does consist of only a single root node without children.
  56. */
  57. // -------------------------------------------------------------------------------
  58. struct aiNode
  59. {
  60. /** The name of the node.
  61. *
  62. * The name might be empty (length of zero) but all nodes which
  63. * need to be accessed afterwards by bones or anims are usually named.
  64. * Multiple nodes may have the same name, but nodes which are accessed
  65. * by bones (see #aiBone and #aiMesh::mBones) *must* be unique.
  66. *
  67. * Cameras and lights are assigned to a specific node name - if there
  68. * are multiple nodes with this name, they're assigned to each of them.
  69. * <br>
  70. * There are no limitations regarding the characters contained in
  71. * this text. You should be able to handle stuff like whitespace, tabs,
  72. * linefeeds, quotation marks, ampersands, ... .
  73. */
  74. C_STRUCT aiString mName;
  75. /** The transformation relative to the node's parent. */
  76. C_STRUCT aiMatrix4x4 mTransformation;
  77. /** Parent node. NULL if this node is the root node. */
  78. C_STRUCT aiNode* mParent;
  79. /** The number of child nodes of this node. */
  80. unsigned int mNumChildren;
  81. /** The child nodes of this node. NULL if mNumChildren is 0. */
  82. C_STRUCT aiNode** mChildren;
  83. /** The number of meshes of this node. */
  84. unsigned int mNumMeshes;
  85. /** The meshes of this node. Each entry is an index into the mesh */
  86. unsigned int* mMeshes;
  87. #ifdef __cplusplus
  88. /** Constructor */
  89. aiNode()
  90. {
  91. // set all members to zero by default
  92. mParent = NULL;
  93. mNumChildren = 0; mChildren = NULL;
  94. mNumMeshes = 0; mMeshes = NULL;
  95. }
  96. /** Construction from a specific name */
  97. aiNode(const std::string& name)
  98. {
  99. // set all members to zero by default
  100. mParent = NULL;
  101. mNumChildren = 0; mChildren = NULL;
  102. mNumMeshes = 0; mMeshes = NULL;
  103. mName = name;
  104. }
  105. /** Destructor */
  106. ~aiNode()
  107. {
  108. // delete all children recursively
  109. // to make sure we won't crash if the data is invalid ...
  110. if (mChildren && mNumChildren)
  111. {
  112. for( unsigned int a = 0; a < mNumChildren; a++)
  113. delete mChildren[a];
  114. }
  115. delete [] mChildren;
  116. delete [] mMeshes;
  117. }
  118. /** Searches for a node with a specific name, beginning at this
  119. * nodes. Normally you will call this method on the root node
  120. * of the scene.
  121. *
  122. * @param name Name to search for
  123. * @return NULL or a valid Node if the search was successful.
  124. */
  125. inline aiNode* FindNode(const aiString& name)
  126. {
  127. return FindNode(name.data);
  128. }
  129. /** @override
  130. */
  131. inline aiNode* FindNode(const char* name)
  132. {
  133. if (!::strcmp( mName.data,name))return this;
  134. for (unsigned int i = 0; i < mNumChildren;++i)
  135. {
  136. aiNode* p = mChildren[i]->FindNode(name);
  137. if (p)return p;
  138. }
  139. // there is definitely no sub node with this name
  140. return NULL;
  141. }
  142. #endif // __cplusplus
  143. };
  144. // -------------------------------------------------------------------------------
  145. /** @def AI_SCENE_FLAGS_INCOMPLETE
  146. * Specifies that the scene data structure that was imported is not complete.
  147. * This flag bypasses some internal validations and allows the import
  148. * of animation skeletons, material libraries or camera animation paths
  149. * using Assimp. Most applications won't support such data.
  150. */
  151. #define AI_SCENE_FLAGS_INCOMPLETE 0x1
  152. /** @def AI_SCENE_FLAGS_VALIDATED
  153. * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS)
  154. * if the validation is successful. In a validated scene you can be sure that
  155. * any cross references in the data structure (e.g. vertex indices) are valid.
  156. */
  157. #define AI_SCENE_FLAGS_VALIDATED 0x2
  158. /** @def AI_SCENE_FLAGS_VALIDATION_WARNING
  159. * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS)
  160. * if the validation is successful but some issues have been found.
  161. * This can for example mean that a texture that does not exist is referenced
  162. * by a material or that the bone weights for a vertex don't sum to 1.0 ... .
  163. * In most cases you should still be able to use the import. This flag could
  164. * be useful for applications which don't capture Assimp's log output.
  165. */
  166. #define AI_SCENE_FLAGS_VALIDATION_WARNING 0x4
  167. /** @def AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  168. * This flag is currently only set by the aiProcess_JoinIdenticalVertices step.
  169. * It indicates that the vertices of the output meshes aren't in the internal
  170. * verbose format anymore. In the verbose format all vertices are unique,
  171. * no vertex is ever referenced by more than one face.
  172. */
  173. #define AI_SCENE_FLAGS_NON_VERBOSE_FORMAT 0x8
  174. /** @def AI_SCENE_FLAGS_TERRAIN
  175. * Denotes pure height-map terrain data. Pure terrains usually consist of quads,
  176. * sometimes triangles, in a regular grid. The x,y coordinates of all vertex
  177. * positions refer to the x,y coordinates on the terrain height map, the z-axis
  178. * stores the elevation at a specific point.
  179. *
  180. * TER (Terragen) and HMP (3D Game Studio) are height map formats.
  181. * @note Assimp is probably not the best choice for loading *huge* terrains -
  182. * fully triangulated data takes extremely much free store and should be avoided
  183. * as long as possible (typically you'll do the triangulation when you actually
  184. * need to render it).
  185. */
  186. #define AI_SCENE_FLAGS_TERRAIN 0x10
  187. // -------------------------------------------------------------------------------
  188. /** The root structure of the imported data.
  189. *
  190. * Everything that was imported from the given file can be accessed from here.
  191. * Objects of this class are generally maintained and owned by Assimp, not
  192. * by the caller. You shouldn't want to instance it, nor should you ever try to
  193. * delete a given scene on your own.
  194. */
  195. // -------------------------------------------------------------------------------
  196. struct aiScene
  197. {
  198. /** Any combination of the AI_SCENE_FLAGS_XXX flags. By default
  199. * this value is 0, no flags are set. Most applications will
  200. * want to reject all scenes with the AI_SCENE_FLAGS_INCOMPLETE
  201. * bit set.
  202. */
  203. unsigned int mFlags;
  204. /** The root node of the hierarchy.
  205. *
  206. * There will always be at least the root node if the import
  207. * was successful (and no special flags have been set).
  208. * Presence of further nodes depends on the format and content
  209. * of the imported file.
  210. */
  211. C_STRUCT aiNode* mRootNode;
  212. /** The number of meshes in the scene. */
  213. unsigned int mNumMeshes;
  214. /** The array of meshes.
  215. *
  216. * Use the indices given in the aiNode structure to access
  217. * this array. The array is mNumMeshes in size. If the
  218. * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always
  219. * be at least ONE material.
  220. */
  221. C_STRUCT aiMesh** mMeshes;
  222. /** The number of materials in the scene. */
  223. unsigned int mNumMaterials;
  224. /** The array of materials.
  225. *
  226. * Use the index given in each aiMesh structure to access this
  227. * array. The array is mNumMaterials in size. If the
  228. * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always
  229. * be at least ONE material.
  230. */
  231. C_STRUCT aiMaterial** mMaterials;
  232. /** The number of animations in the scene. */
  233. unsigned int mNumAnimations;
  234. /** The array of animations.
  235. *
  236. * All animations imported from the given file are listed here.
  237. * The array is mNumAnimations in size.
  238. */
  239. C_STRUCT aiAnimation** mAnimations;
  240. /** The number of textures embedded into the file */
  241. unsigned int mNumTextures;
  242. /** The array of embedded textures.
  243. *
  244. * Not many file formats embed their textures into the file.
  245. * An example is Quake's MDL format (which is also used by
  246. * some GameStudio versions)
  247. */
  248. C_STRUCT aiTexture** mTextures;
  249. /** The number of light sources in the scene. Light sources
  250. * are fully optional, in most cases this attribute will be 0
  251. */
  252. unsigned int mNumLights;
  253. /** The array of light sources.
  254. *
  255. * All light sources imported from the given file are
  256. * listed here. The array is mNumLights in size.
  257. */
  258. C_STRUCT aiLight** mLights;
  259. /** The number of cameras in the scene. Cameras
  260. * are fully optional, in most cases this attribute will be 0
  261. */
  262. unsigned int mNumCameras;
  263. /** The array of cameras.
  264. *
  265. * All cameras imported from the given file are listed here.
  266. * The array is mNumCameras in size. The first camera in the
  267. * array (if existing) is the default camera view into
  268. * the scene.
  269. */
  270. C_STRUCT aiCamera** mCameras;
  271. #ifdef __cplusplus
  272. //! Default constructor - set everything to 0/NULL
  273. aiScene();
  274. //! Destructor
  275. ~aiScene();
  276. //! Check whether the scene contains meshes
  277. //! Unless no special scene flags are set this will always be true.
  278. inline bool HasMeshes() const
  279. { return mMeshes != NULL && mNumMeshes > 0; }
  280. //! Check whether the scene contains materials
  281. //! Unless no special scene flags are set this will always be true.
  282. inline bool HasMaterials() const
  283. { return mMaterials != NULL && mNumMaterials > 0; }
  284. //! Check whether the scene contains lights
  285. inline bool HasLights() const
  286. { return mLights != NULL && mNumLights > 0; }
  287. //! Check whether the scene contains textures
  288. inline bool HasTextures() const
  289. { return mTextures != NULL && mNumTextures > 0; }
  290. //! Check whether the scene contains cameras
  291. inline bool HasCameras() const
  292. { return mCameras != NULL && mNumCameras > 0; }
  293. //! Check whether the scene contains animations
  294. inline bool HasAnimations() const
  295. { return mAnimations != NULL && mNumAnimations > 0; }
  296. #endif // __cplusplus
  297. /** Internal data, do not touch */
  298. #ifdef __cplusplus
  299. void* mPrivate;
  300. #else
  301. char* mPrivate;
  302. #endif
  303. };
  304. #ifdef __cplusplus
  305. } //! namespace Assimp
  306. #endif
  307. #endif // __AI_SCENE_H_INC__