miniassimp
diff include/miniassimp/scene.h @ 0:879c81d94345
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Jan 2019 18:19:26 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/include/miniassimp/scene.h Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,407 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2018, assimp team 1.10 + 1.11 + 1.12 + 1.13 +All rights reserved. 1.14 + 1.15 +Redistribution and use of this software in source and binary forms, 1.16 +with or without modification, are permitted provided that the following 1.17 +conditions are met: 1.18 + 1.19 +* Redistributions of source code must retain the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer. 1.22 + 1.23 +* Redistributions in binary form must reproduce the above 1.24 + copyright notice, this list of conditions and the 1.25 + following disclaimer in the documentation and/or other 1.26 + materials provided with the distribution. 1.27 + 1.28 +* Neither the name of the assimp team, nor the names of its 1.29 + contributors may be used to endorse or promote products 1.30 + derived from this software without specific prior 1.31 + written permission of the assimp team. 1.32 + 1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.44 +--------------------------------------------------------------------------- 1.45 +*/ 1.46 + 1.47 +/** @file scene.h 1.48 + * @brief Defines the data structures in which the imported scene is returned. 1.49 + */ 1.50 +#pragma once 1.51 +#ifndef AI_SCENE_H_INC 1.52 +#define AI_SCENE_H_INC 1.53 + 1.54 +#include "types.h" 1.55 +#include "texture.h" 1.56 +#include "mesh.h" 1.57 +#include "light.h" 1.58 +#include "camera.h" 1.59 +#include "material.h" 1.60 +#include "anim.h" 1.61 +#include "metadata.h" 1.62 + 1.63 +#ifdef __cplusplus 1.64 +extern "C" { 1.65 +#endif 1.66 + 1.67 +// ------------------------------------------------------------------------------- 1.68 +/** 1.69 + * A node in the imported hierarchy. 1.70 + * 1.71 + * Each node has name, a parent node (except for the root node), 1.72 + * a transformation relative to its parent and possibly several child nodes. 1.73 + * Simple file formats don't support hierarchical structures - for these formats 1.74 + * the imported scene does consist of only a single root node without children. 1.75 + */ 1.76 +// ------------------------------------------------------------------------------- 1.77 +struct ASSIMP_API aiNode 1.78 +{ 1.79 + /** The name of the node. 1.80 + * 1.81 + * The name might be empty (length of zero) but all nodes which 1.82 + * need to be referenced by either bones or animations are named. 1.83 + * Multiple nodes may have the same name, except for nodes which are referenced 1.84 + * by bones (see #aiBone and #aiMesh::mBones). Their names *must* be unique. 1.85 + * 1.86 + * Cameras and lights reference a specific node by name - if there 1.87 + * are multiple nodes with this name, they are assigned to each of them. 1.88 + * <br> 1.89 + * There are no limitations with regard to the characters contained in 1.90 + * the name string as it is usually taken directly from the source file. 1.91 + * 1.92 + * Implementations should be able to handle tokens such as whitespace, tabs, 1.93 + * line feeds, quotation marks, ampersands etc. 1.94 + * 1.95 + * Sometimes assimp introduces new nodes not present in the source file 1.96 + * into the hierarchy (usually out of necessity because sometimes the 1.97 + * source hierarchy format is simply not compatible). Their names are 1.98 + * surrounded by @verbatim <> @endverbatim e.g. 1.99 + * @verbatim<DummyRootNode> @endverbatim. 1.100 + */ 1.101 + C_STRUCT aiString mName; 1.102 + 1.103 + /** The transformation relative to the node's parent. */ 1.104 + C_STRUCT aiMatrix4x4 mTransformation; 1.105 + 1.106 + /** Parent node. NULL if this node is the root node. */ 1.107 + C_STRUCT aiNode* mParent; 1.108 + 1.109 + /** The number of child nodes of this node. */ 1.110 + unsigned int mNumChildren; 1.111 + 1.112 + /** The child nodes of this node. NULL if mNumChildren is 0. */ 1.113 + C_STRUCT aiNode** mChildren; 1.114 + 1.115 + /** The number of meshes of this node. */ 1.116 + unsigned int mNumMeshes; 1.117 + 1.118 + /** The meshes of this node. Each entry is an index into the 1.119 + * mesh list of the #aiScene. 1.120 + */ 1.121 + unsigned int* mMeshes; 1.122 + 1.123 + /** Metadata associated with this node or NULL if there is no metadata. 1.124 + * Whether any metadata is generated depends on the source file format. See the 1.125 + * @link importer_notes @endlink page for more information on every source file 1.126 + * format. Importers that don't document any metadata don't write any. 1.127 + */ 1.128 + C_STRUCT aiMetadata* mMetaData; 1.129 + 1.130 +#ifdef __cplusplus 1.131 + /** Constructor */ 1.132 + aiNode(); 1.133 + 1.134 + /** Construction from a specific name */ 1.135 + explicit aiNode(const std::string& name); 1.136 + 1.137 + /** Destructor */ 1.138 + ~aiNode(); 1.139 + 1.140 + /** Searches for a node with a specific name, beginning at this 1.141 + * nodes. Normally you will call this method on the root node 1.142 + * of the scene. 1.143 + * 1.144 + * @param name Name to search for 1.145 + * @return NULL or a valid Node if the search was successful. 1.146 + */ 1.147 + inline 1.148 + const aiNode* FindNode(const aiString& name) const { 1.149 + return FindNode(name.data); 1.150 + } 1.151 + 1.152 + inline 1.153 + aiNode* FindNode(const aiString& name) { 1.154 + return FindNode(name.data); 1.155 + } 1.156 + 1.157 + const aiNode* FindNode(const char* name) const; 1.158 + 1.159 + aiNode* FindNode(const char* name); 1.160 + 1.161 + /** 1.162 + * @brief Will add new children. 1.163 + * @param numChildren Number of children to add. 1.164 + * @param children The array with pointers showing to the children. 1.165 + */ 1.166 + void addChildren(unsigned int numChildren, aiNode **children); 1.167 +#endif // __cplusplus 1.168 +}; 1.169 + 1.170 +// ------------------------------------------------------------------------------- 1.171 +/** 1.172 + * Specifies that the scene data structure that was imported is not complete. 1.173 + * This flag bypasses some internal validations and allows the import 1.174 + * of animation skeletons, material libraries or camera animation paths 1.175 + * using Assimp. Most applications won't support such data. 1.176 + */ 1.177 +#define AI_SCENE_FLAGS_INCOMPLETE 0x1 1.178 + 1.179 +/** 1.180 + * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS) 1.181 + * if the validation is successful. In a validated scene you can be sure that 1.182 + * any cross references in the data structure (e.g. vertex indices) are valid. 1.183 + */ 1.184 +#define AI_SCENE_FLAGS_VALIDATED 0x2 1.185 + 1.186 +/** 1.187 + * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS) 1.188 + * if the validation is successful but some issues have been found. 1.189 + * This can for example mean that a texture that does not exist is referenced 1.190 + * by a material or that the bone weights for a vertex don't sum to 1.0 ... . 1.191 + * In most cases you should still be able to use the import. This flag could 1.192 + * be useful for applications which don't capture Assimp's log output. 1.193 + */ 1.194 +#define AI_SCENE_FLAGS_VALIDATION_WARNING 0x4 1.195 + 1.196 +/** 1.197 + * This flag is currently only set by the aiProcess_JoinIdenticalVertices step. 1.198 + * It indicates that the vertices of the output meshes aren't in the internal 1.199 + * verbose format anymore. In the verbose format all vertices are unique, 1.200 + * no vertex is ever referenced by more than one face. 1.201 + */ 1.202 +#define AI_SCENE_FLAGS_NON_VERBOSE_FORMAT 0x8 1.203 + 1.204 + /** 1.205 + * Denotes pure height-map terrain data. Pure terrains usually consist of quads, 1.206 + * sometimes triangles, in a regular grid. The x,y coordinates of all vertex 1.207 + * positions refer to the x,y coordinates on the terrain height map, the z-axis 1.208 + * stores the elevation at a specific point. 1.209 + * 1.210 + * TER (Terragen) and HMP (3D Game Studio) are height map formats. 1.211 + * @note Assimp is probably not the best choice for loading *huge* terrains - 1.212 + * fully triangulated data takes extremely much free store and should be avoided 1.213 + * as long as possible (typically you'll do the triangulation when you actually 1.214 + * need to render it). 1.215 + */ 1.216 +#define AI_SCENE_FLAGS_TERRAIN 0x10 1.217 + 1.218 + /** 1.219 + * Specifies that the scene data can be shared between structures. For example: 1.220 + * one vertex in few faces. \ref AI_SCENE_FLAGS_NON_VERBOSE_FORMAT can not be 1.221 + * used for this because \ref AI_SCENE_FLAGS_NON_VERBOSE_FORMAT has internal 1.222 + * meaning about postprocessing steps. 1.223 + */ 1.224 +#define AI_SCENE_FLAGS_ALLOW_SHARED 0x20 1.225 + 1.226 +// ------------------------------------------------------------------------------- 1.227 +/** The root structure of the imported data. 1.228 + * 1.229 + * Everything that was imported from the given file can be accessed from here. 1.230 + * Objects of this class are generally maintained and owned by Assimp, not 1.231 + * by the caller. You shouldn't want to instance it, nor should you ever try to 1.232 + * delete a given scene on your own. 1.233 + */ 1.234 +// ------------------------------------------------------------------------------- 1.235 +struct aiScene 1.236 +{ 1.237 + /** Any combination of the AI_SCENE_FLAGS_XXX flags. By default 1.238 + * this value is 0, no flags are set. Most applications will 1.239 + * want to reject all scenes with the AI_SCENE_FLAGS_INCOMPLETE 1.240 + * bit set. 1.241 + */ 1.242 + unsigned int mFlags; 1.243 + 1.244 + /** The root node of the hierarchy. 1.245 + * 1.246 + * There will always be at least the root node if the import 1.247 + * was successful (and no special flags have been set). 1.248 + * Presence of further nodes depends on the format and content 1.249 + * of the imported file. 1.250 + */ 1.251 + C_STRUCT aiNode* mRootNode; 1.252 + 1.253 + /** The number of meshes in the scene. */ 1.254 + unsigned int mNumMeshes; 1.255 + 1.256 + /** The array of meshes. 1.257 + * 1.258 + * Use the indices given in the aiNode structure to access 1.259 + * this array. The array is mNumMeshes in size. If the 1.260 + * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always 1.261 + * be at least ONE material. 1.262 + */ 1.263 + C_STRUCT aiMesh** mMeshes; 1.264 + 1.265 + /** The number of materials in the scene. */ 1.266 + unsigned int mNumMaterials; 1.267 + 1.268 + /** The array of materials. 1.269 + * 1.270 + * Use the index given in each aiMesh structure to access this 1.271 + * array. The array is mNumMaterials in size. If the 1.272 + * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always 1.273 + * be at least ONE material. 1.274 + */ 1.275 + C_STRUCT aiMaterial** mMaterials; 1.276 + 1.277 + /** The number of animations in the scene. */ 1.278 + unsigned int mNumAnimations; 1.279 + 1.280 + /** The array of animations. 1.281 + * 1.282 + * All animations imported from the given file are listed here. 1.283 + * The array is mNumAnimations in size. 1.284 + */ 1.285 + C_STRUCT aiAnimation** mAnimations; 1.286 + 1.287 + /** The number of textures embedded into the file */ 1.288 + unsigned int mNumTextures; 1.289 + 1.290 + /** The array of embedded textures. 1.291 + * 1.292 + * Not many file formats embed their textures into the file. 1.293 + * An example is Quake's MDL format (which is also used by 1.294 + * some GameStudio versions) 1.295 + */ 1.296 + C_STRUCT aiTexture** mTextures; 1.297 + 1.298 + /** The number of light sources in the scene. Light sources 1.299 + * are fully optional, in most cases this attribute will be 0 1.300 + */ 1.301 + unsigned int mNumLights; 1.302 + 1.303 + /** The array of light sources. 1.304 + * 1.305 + * All light sources imported from the given file are 1.306 + * listed here. The array is mNumLights in size. 1.307 + */ 1.308 + C_STRUCT aiLight** mLights; 1.309 + 1.310 + /** The number of cameras in the scene. Cameras 1.311 + * are fully optional, in most cases this attribute will be 0 1.312 + */ 1.313 + unsigned int mNumCameras; 1.314 + 1.315 + /** The array of cameras. 1.316 + * 1.317 + * All cameras imported from the given file are listed here. 1.318 + * The array is mNumCameras in size. The first camera in the 1.319 + * array (if existing) is the default camera view into 1.320 + * the scene. 1.321 + */ 1.322 + C_STRUCT aiCamera** mCameras; 1.323 + 1.324 + /** 1.325 + * @brief The global metadata assigned to the scene itself. 1.326 + * 1.327 + * This data contains global metadata which belongs to the scene like 1.328 + * unit-conversions, versions, vendors or other model-specific data. This 1.329 + * can be used to store format-specific metadata as well. 1.330 + */ 1.331 + C_STRUCT aiMetadata* mMetaData; 1.332 + 1.333 + 1.334 +#ifdef __cplusplus 1.335 + 1.336 + //! Default constructor - set everything to 0/NULL 1.337 + ASSIMP_API aiScene(); 1.338 + 1.339 + //! Destructor 1.340 + ASSIMP_API ~aiScene(); 1.341 + 1.342 + //! Check whether the scene contains meshes 1.343 + //! Unless no special scene flags are set this will always be true. 1.344 + inline bool HasMeshes() const { 1.345 + return mMeshes != NULL && mNumMeshes > 0; 1.346 + } 1.347 + 1.348 + //! Check whether the scene contains materials 1.349 + //! Unless no special scene flags are set this will always be true. 1.350 + inline bool HasMaterials() const { 1.351 + return mMaterials != NULL && mNumMaterials > 0; 1.352 + } 1.353 + 1.354 + //! Check whether the scene contains lights 1.355 + inline bool HasLights() const { 1.356 + return mLights != NULL && mNumLights > 0; 1.357 + } 1.358 + 1.359 + //! Check whether the scene contains textures 1.360 + inline bool HasTextures() const { 1.361 + return mTextures != NULL && mNumTextures > 0; 1.362 + } 1.363 + 1.364 + //! Check whether the scene contains cameras 1.365 + inline bool HasCameras() const { 1.366 + return mCameras != NULL && mNumCameras > 0; 1.367 + } 1.368 + 1.369 + //! Check whether the scene contains animations 1.370 + inline bool HasAnimations() const { 1.371 + return mAnimations != NULL && mNumAnimations > 0; 1.372 + } 1.373 + 1.374 + //! Returns a short filename from a full path 1.375 + static const char* GetShortFilename(const char* filename) { 1.376 + const char* lastSlash = strrchr(filename, '/'); 1.377 + if (lastSlash == 0) { 1.378 + lastSlash = strrchr(filename, '\\'); 1.379 + } 1.380 + const char* shortFilename = lastSlash != 0 ? lastSlash + 1 : filename; 1.381 + return shortFilename; 1.382 + } 1.383 + 1.384 + //! Returns an embedded texture 1.385 + const aiTexture* GetEmbeddedTexture(const char* filename) const { 1.386 + const char* shortFilename = GetShortFilename(filename); 1.387 + for (unsigned int i = 0; i < mNumTextures; i++) { 1.388 + const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str()); 1.389 + if (strcmp(shortTextureFilename, shortFilename) == 0) { 1.390 + return mTextures[i]; 1.391 + } 1.392 + } 1.393 + return 0; 1.394 + } 1.395 +#endif // __cplusplus 1.396 + 1.397 + /** Internal data, do not touch */ 1.398 +#ifdef __cplusplus 1.399 + void* mPrivate; 1.400 +#else 1.401 + char* mPrivate; 1.402 +#endif 1.403 + 1.404 +}; 1.405 + 1.406 +#ifdef __cplusplus 1.407 +} //! namespace Assimp 1.408 +#endif 1.409 + 1.410 +#endif // AI_SCENE_H_INC