scene.h 14 KB

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