![]() |
|
|||
File indexing completed on 2025-02-21 09:30:10
0001 /* 0002 --------------------------------------------------------------------------- 0003 Open Asset Import Library (assimp) 0004 --------------------------------------------------------------------------- 0005 0006 Copyright (c) 2006-2024, assimp team 0007 0008 All rights reserved. 0009 0010 Redistribution and use of this software in source and binary forms, 0011 with or without modification, are permitted provided that the following 0012 conditions are met: 0013 0014 * Redistributions of source code must retain the above 0015 copyright notice, this list of conditions and the 0016 following disclaimer. 0017 0018 * Redistributions in binary form must reproduce the above 0019 copyright notice, this list of conditions and the 0020 following disclaimer in the documentation and/or other 0021 materials provided with the distribution. 0022 0023 * Neither the name of the assimp team, nor the names of its 0024 contributors may be used to endorse or promote products 0025 derived from this software without specific prior 0026 written permission of the assimp team. 0027 0028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0032 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0039 --------------------------------------------------------------------------- 0040 */ 0041 0042 /** @file scene.h 0043 * @brief Defines the data structures in which the imported scene is returned. 0044 */ 0045 #pragma once 0046 #ifndef AI_SCENE_H_INC 0047 #define AI_SCENE_H_INC 0048 0049 #ifdef __GNUC__ 0050 # pragma GCC system_header 0051 #endif 0052 0053 #include <assimp/types.h> 0054 #include <assimp/texture.h> 0055 #include <assimp/mesh.h> 0056 #include <assimp/light.h> 0057 #include <assimp/camera.h> 0058 #include <assimp/material.h> 0059 #include <assimp/anim.h> 0060 #include <assimp/metadata.h> 0061 0062 #ifdef __cplusplus 0063 # include <cstdlib> 0064 extern "C" { 0065 #endif 0066 0067 #ifdef __GNUC__ 0068 #pragma GCC diagnostic push 0069 #pragma GCC diagnostic ignored "-Wattributes" 0070 #endif 0071 0072 // ------------------------------------------------------------------------------- 0073 /** 0074 * A node in the imported hierarchy. 0075 * 0076 * Each node has name, a parent node (except for the root node), 0077 * a transformation relative to its parent and possibly several child nodes. 0078 * Simple file formats don't support hierarchical structures - for these formats 0079 * the imported scene does consist of only a single root node without children. 0080 */ 0081 // ------------------------------------------------------------------------------- 0082 struct ASSIMP_API aiNode { 0083 /** The name of the node. 0084 * 0085 * The name might be empty (length of zero) but all nodes which 0086 * need to be referenced by either bones or animations are named. 0087 * Multiple nodes may have the same name, except for nodes which are referenced 0088 * by bones (see #aiBone and #aiMesh::mBones). Their names *must* be unique. 0089 * 0090 * Cameras and lights reference a specific node by name - if there 0091 * are multiple nodes with this name, they are assigned to each of them. 0092 * <br> 0093 * There are no limitations with regard to the characters contained in 0094 * the name string as it is usually taken directly from the source file. 0095 * 0096 * Implementations should be able to handle tokens such as whitespace, tabs, 0097 * line feeds, quotation marks, ampersands etc. 0098 * 0099 * Sometimes assimp introduces new nodes not present in the source file 0100 * into the hierarchy (usually out of necessity because sometimes the 0101 * source hierarchy format is simply not compatible). Their names are 0102 * surrounded by @verbatim <> @endverbatim e.g. 0103 * @verbatim<DummyRootNode> @endverbatim. 0104 */ 0105 C_STRUCT aiString mName; 0106 0107 /** The transformation relative to the node's parent. */ 0108 C_STRUCT aiMatrix4x4 mTransformation; 0109 0110 /** Parent node. nullptr if this node is the root node. */ 0111 C_STRUCT aiNode* mParent; 0112 0113 /** The number of child nodes of this node. */ 0114 unsigned int mNumChildren; 0115 0116 /** The child nodes of this node. nullptr if mNumChildren is 0. */ 0117 C_STRUCT aiNode** mChildren; 0118 0119 /** The number of meshes of this node. */ 0120 unsigned int mNumMeshes; 0121 0122 /** The meshes of this node. Each entry is an index into the 0123 * mesh list of the #aiScene. 0124 */ 0125 unsigned int* mMeshes; 0126 0127 /** Metadata associated with this node or nullptr if there is no metadata. 0128 * Whether any metadata is generated depends on the source file format. See the 0129 * @link importer_notes @endlink page for more information on every source file 0130 * format. Importers that don't document any metadata don't write any. 0131 */ 0132 C_STRUCT aiMetadata* mMetaData; 0133 0134 #ifdef __cplusplus 0135 /** Constructor */ 0136 aiNode(); 0137 0138 /** Construction from a specific name */ 0139 explicit aiNode(const std::string& name); 0140 0141 /** Destructor */ 0142 ~aiNode(); 0143 0144 /** 0145 * @brief Searches for a node with a specific name, beginning at this 0146 * nodes. Normally you will call this method on the root node 0147 * of the scene. 0148 * 0149 * @param name Name to search for 0150 * @return nullptr or a valid Node if the search was successful. 0151 */ 0152 inline const aiNode* FindNode(const aiString& name) const { 0153 return FindNode(name.data); 0154 } 0155 0156 inline aiNode* FindNode(const aiString& name) { 0157 return FindNode(name.data); 0158 } 0159 0160 /** 0161 * @brief Will search for a node described by its name. 0162 * @param[in] name The name for the node to look for. 0163 * @return Pointer showing to the node or nullptr if not found. 0164 */ 0165 const aiNode* FindNode(const char* name) const; 0166 aiNode* FindNode(const char* name); 0167 0168 /** 0169 * @brief Will add new children. 0170 * @param numChildren Number of children to add. 0171 * @param children The array with pointers showing to the children. 0172 */ 0173 void addChildren(unsigned int numChildren, aiNode **children); 0174 #endif // __cplusplus 0175 }; 0176 0177 #ifdef __GNUC__ 0178 #pragma GCC diagnostic pop 0179 #endif 0180 0181 // ------------------------------------------------------------------------------- 0182 /** 0183 * Specifies that the scene data structure that was imported is not complete. 0184 * This flag bypasses some internal validations and allows the import 0185 * of animation skeletons, material libraries or camera animation paths 0186 * using Assimp. Most applications won't support such data. 0187 */ 0188 #define AI_SCENE_FLAGS_INCOMPLETE 0x1 0189 0190 /** 0191 * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS) 0192 * if the validation is successful. In a validated scene you can be sure that 0193 * any cross references in the data structure (e.g. vertex indices) are valid. 0194 */ 0195 #define AI_SCENE_FLAGS_VALIDATED 0x2 0196 0197 /** 0198 * This flag is set by the validation postprocess-step (aiPostProcess_ValidateDS) 0199 * if the validation is successful but some issues have been found. 0200 * This can for example mean that a texture that does not exist is referenced 0201 * by a material or that the bone weights for a vertex don't sum to 1.0 ... . 0202 * In most cases you should still be able to use the import. This flag could 0203 * be useful for applications which don't capture Assimp's log output. 0204 */ 0205 #define AI_SCENE_FLAGS_VALIDATION_WARNING 0x4 0206 0207 /** 0208 * This flag is currently only set by the aiProcess_JoinIdenticalVertices step. 0209 * It indicates that the vertices of the output meshes aren't in the internal 0210 * verbose format anymore. In the verbose format all vertices are unique, 0211 * no vertex is ever referenced by more than one face. 0212 */ 0213 #define AI_SCENE_FLAGS_NON_VERBOSE_FORMAT 0x8 0214 0215 /** 0216 * Denotes pure height-map terrain data. Pure terrains usually consist of quads, 0217 * sometimes triangles, in a regular grid. The x,y coordinates of all vertex 0218 * positions refer to the x,y coordinates on the terrain height map, the z-axis 0219 * stores the elevation at a specific point. 0220 * 0221 * TER (Terragen) and HMP (3D Game Studio) are height map formats. 0222 * @note Assimp is probably not the best choice for loading *huge* terrains - 0223 * fully triangulated data takes extremely much free store and should be avoided 0224 * as long as possible (typically you'll do the triangulation when you actually 0225 * need to render it). 0226 */ 0227 #define AI_SCENE_FLAGS_TERRAIN 0x10 0228 0229 /** 0230 * Specifies that the scene data can be shared between structures. For example: 0231 * one vertex in few faces. \ref AI_SCENE_FLAGS_NON_VERBOSE_FORMAT can not be 0232 * used for this because \ref AI_SCENE_FLAGS_NON_VERBOSE_FORMAT has internal 0233 * meaning about postprocessing steps. 0234 */ 0235 #define AI_SCENE_FLAGS_ALLOW_SHARED 0x20 0236 0237 // ------------------------------------------------------------------------------- 0238 /** The root structure of the imported data. 0239 * 0240 * Everything that was imported from the given file can be accessed from here. 0241 * Objects of this class are generally maintained and owned by Assimp, not 0242 * by the caller. You shouldn't want to instance it, nor should you ever try to 0243 * delete a given scene on your own. 0244 */ 0245 // ------------------------------------------------------------------------------- 0246 struct ASSIMP_API aiScene { 0247 /** Any combination of the AI_SCENE_FLAGS_XXX flags. By default 0248 * this value is 0, no flags are set. Most applications will 0249 * want to reject all scenes with the AI_SCENE_FLAGS_INCOMPLETE 0250 * bit set. 0251 */ 0252 unsigned int mFlags; 0253 0254 /** The root node of the hierarchy. 0255 * 0256 * There will always be at least the root node if the import 0257 * was successful (and no special flags have been set). 0258 * Presence of further nodes depends on the format and content 0259 * of the imported file. 0260 */ 0261 C_STRUCT aiNode* mRootNode; 0262 0263 /** The number of meshes in the scene. */ 0264 unsigned int mNumMeshes; 0265 0266 /** The array of meshes. 0267 * 0268 * Use the indices given in the aiNode structure to access 0269 * this array. The array is mNumMeshes in size. If the 0270 * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always 0271 * be at least ONE material. 0272 */ 0273 C_STRUCT aiMesh** mMeshes; 0274 0275 /** The number of materials in the scene. */ 0276 unsigned int mNumMaterials; 0277 0278 /** The array of materials. 0279 * 0280 * Use the index given in each aiMesh structure to access this 0281 * array. The array is mNumMaterials in size. If the 0282 * AI_SCENE_FLAGS_INCOMPLETE flag is not set there will always 0283 * be at least ONE material. 0284 */ 0285 C_STRUCT aiMaterial** mMaterials; 0286 0287 /** The number of animations in the scene. */ 0288 unsigned int mNumAnimations; 0289 0290 /** The array of animations. 0291 * 0292 * All animations imported from the given file are listed here. 0293 * The array is mNumAnimations in size. 0294 */ 0295 C_STRUCT aiAnimation** mAnimations; 0296 0297 /** The number of textures embedded into the file */ 0298 unsigned int mNumTextures; 0299 0300 /** The array of embedded textures. 0301 * 0302 * Not many file formats embed their textures into the file. 0303 * An example is Quake's MDL format (which is also used by 0304 * some GameStudio versions) 0305 */ 0306 C_STRUCT aiTexture** mTextures; 0307 0308 /** The number of light sources in the scene. Light sources 0309 * are fully optional, in most cases this attribute will be 0 0310 */ 0311 unsigned int mNumLights; 0312 0313 /** The array of light sources. 0314 * 0315 * All light sources imported from the given file are 0316 * listed here. The array is mNumLights in size. 0317 */ 0318 C_STRUCT aiLight** mLights; 0319 0320 /** The number of cameras in the scene. Cameras 0321 * are fully optional, in most cases this attribute will be 0 0322 */ 0323 unsigned int mNumCameras; 0324 0325 /** The array of cameras. 0326 * 0327 * All cameras imported from the given file are listed here. 0328 * The array is mNumCameras in size. The first camera in the 0329 * array (if existing) is the default camera view into 0330 * the scene. 0331 */ 0332 C_STRUCT aiCamera** mCameras; 0333 0334 /** 0335 * @brief The global metadata assigned to the scene itself. 0336 * 0337 * This data contains global metadata which belongs to the scene like 0338 * unit-conversions, versions, vendors or other model-specific data. This 0339 * can be used to store format-specific metadata as well. 0340 */ 0341 C_STRUCT aiMetadata* mMetaData; 0342 0343 /** The name of the scene itself. 0344 */ 0345 C_STRUCT aiString mName; 0346 0347 /** 0348 * 0349 */ 0350 unsigned int mNumSkeletons; 0351 0352 /** 0353 * 0354 */ 0355 C_STRUCT aiSkeleton **mSkeletons; 0356 0357 #ifdef __cplusplus 0358 0359 //! Default constructor - set everything to 0/nullptr 0360 aiScene(); 0361 0362 //! Destructor 0363 ~aiScene(); 0364 0365 //! Check whether the scene contains meshes 0366 //! Unless no special scene flags are set this will always be true. 0367 inline bool HasMeshes() const { 0368 return mMeshes != nullptr && mNumMeshes > 0; 0369 } 0370 0371 //! Check whether the scene contains materials 0372 //! Unless no special scene flags are set this will always be true. 0373 inline bool HasMaterials() const { 0374 return mMaterials != nullptr && mNumMaterials > 0; 0375 } 0376 0377 //! Check whether the scene contains lights 0378 inline bool HasLights() const { 0379 return mLights != nullptr && mNumLights > 0; 0380 } 0381 0382 //! Check whether the scene contains textures 0383 inline bool HasTextures() const { 0384 return mTextures != nullptr && mNumTextures > 0; 0385 } 0386 0387 //! Check whether the scene contains cameras 0388 inline bool HasCameras() const { 0389 return mCameras != nullptr && mNumCameras > 0; 0390 } 0391 0392 //! Check whether the scene contains animations 0393 inline bool HasAnimations() const { 0394 return mAnimations != nullptr && mNumAnimations > 0; 0395 } 0396 0397 bool hasSkeletons() const { 0398 return mSkeletons != nullptr && mNumSkeletons > 0; 0399 } 0400 0401 //! Returns a short filename from a full path 0402 static const char* GetShortFilename(const char* filename) { 0403 const char* lastSlash = strrchr(filename, '/'); 0404 const char* lastBackSlash = strrchr(filename, '\\'); 0405 if (lastSlash < lastBackSlash) { 0406 lastSlash = lastBackSlash; 0407 } 0408 const char* shortFilename = lastSlash != nullptr ? lastSlash + 1 : filename; 0409 return shortFilename; 0410 } 0411 0412 //! Returns an embedded texture 0413 const aiTexture* GetEmbeddedTexture(const char* filename) const { 0414 return GetEmbeddedTextureAndIndex(filename).first; 0415 } 0416 0417 //! Returns an embedded texture and its index 0418 std::pair<const aiTexture*, int> GetEmbeddedTextureAndIndex(const char* filename) const { 0419 if (nullptr==filename) { 0420 return std::make_pair(nullptr, -1); 0421 } 0422 // lookup using texture ID (if referenced like: "*1", "*2", etc.) 0423 if ('*' == *filename) { 0424 int index = std::atoi(filename + 1); 0425 if (0 > index || mNumTextures <= static_cast<unsigned>(index)) { 0426 return std::make_pair(nullptr, -1); 0427 } 0428 return std::make_pair(mTextures[index], index); 0429 } 0430 // lookup using filename 0431 const char* shortFilename = GetShortFilename(filename); 0432 if (nullptr == shortFilename) { 0433 return std::make_pair(nullptr, -1); 0434 } 0435 0436 for (unsigned int i = 0; i < mNumTextures; i++) { 0437 const char* shortTextureFilename = GetShortFilename(mTextures[i]->mFilename.C_Str()); 0438 if (strcmp(shortTextureFilename, shortFilename) == 0) { 0439 return std::make_pair(mTextures[i], static_cast<int>(i)); 0440 } 0441 } 0442 return std::make_pair(nullptr, -1); 0443 } 0444 #endif // __cplusplus 0445 0446 /** Internal data, do not touch */ 0447 #ifdef __cplusplus 0448 void* mPrivate; 0449 #else 0450 char* mPrivate; 0451 #endif 0452 0453 }; 0454 0455 #ifdef __cplusplus 0456 } 0457 #endif //! extern "C" 0458 0459 #endif // AI_SCENE_H_INC
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |