scene.h 13 KB

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