1 /* 2 Open Asset Import Library (assimp) 3 ---------------------------------------------------------------------- 4 5 Copyright (c) 2006-2021, assimp team 6 7 8 All rights reserved. 9 10 Redistribution and use of this software in source and binary forms, 11 with or without modification, are permitted provided that the 12 following conditions are met: 13 14 * Redistributions of source code must retain the above 15 copyright notice, this list of conditions and the 16 following disclaimer. 17 18 * Redistributions in binary form must reproduce the above 19 copyright notice, this list of conditions and the 20 following disclaimer in the documentation and/or other 21 materials provided with the distribution. 22 23 * Neither the name of the assimp team, nor the names of its 24 contributors may be used to endorse or promote products 25 derived from this software without specific prior 26 written permission of the assimp team. 27 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 40 ---------------------------------------------------------------------- 41 */ 42 43 /** @file PretransformVertices.h 44 * @brief Defines a post processing step to pretransform all 45 * vertices in the scenegraph 46 */ 47 #ifndef AI_PRETRANSFORMVERTICES_H_INC 48 #define AI_PRETRANSFORMVERTICES_H_INC 49 50 #include "Common/BaseProcess.h" 51 52 #include <assimp/mesh.h> 53 54 #include <list> 55 #include <vector> 56 57 // Forward declarations 58 struct aiNode; 59 60 class PretransformVerticesTest; 61 62 namespace Assimp { 63 64 // --------------------------------------------------------------------------- 65 /** The PretransformVertices pre-transforms all vertices in the node tree 66 * and removes the whole graph. The output is a list of meshes, one for 67 * each material. 68 */ 69 class ASSIMP_API PretransformVertices : public BaseProcess { 70 public: 71 PretransformVertices(); 72 ~PretransformVertices(); 73 74 // ------------------------------------------------------------------- 75 // Check whether step is active 76 bool IsActive(unsigned int pFlags) const override; 77 78 // ------------------------------------------------------------------- 79 // Execute step on a given scene 80 void Execute(aiScene *pScene) override; 81 82 // ------------------------------------------------------------------- 83 // Setup import settings 84 void SetupProperties(const Importer *pImp) override; 85 86 // ------------------------------------------------------------------- 87 /** @brief Toggle the 'keep hierarchy' option 88 * @param keep true for keep configuration. 89 */ KeepHierarchy(bool keep)90 void KeepHierarchy(bool keep) { 91 configKeepHierarchy = keep; 92 } 93 94 // ------------------------------------------------------------------- 95 /** @brief Check whether 'keep hierarchy' is currently enabled. 96 * @return ... 97 */ IsHierarchyKept()98 bool IsHierarchyKept() const { 99 return configKeepHierarchy; 100 } 101 102 private: 103 // ------------------------------------------------------------------- 104 // Count the number of nodes 105 unsigned int CountNodes(const aiNode *pcNode) const; 106 107 // ------------------------------------------------------------------- 108 // Get a bitwise combination identifying the vertex format of a mesh 109 unsigned int GetMeshVFormat(aiMesh *pcMesh) const; 110 111 // ------------------------------------------------------------------- 112 // Count the number of vertices in the whole scene and a given 113 // material index 114 void CountVerticesAndFaces(const aiScene *pcScene, const aiNode *pcNode, 115 unsigned int iMat, 116 unsigned int iVFormat, 117 unsigned int *piFaces, 118 unsigned int *piVertices) const; 119 120 // ------------------------------------------------------------------- 121 // Collect vertex/face data 122 void CollectData(const aiScene *pcScene, const aiNode *pcNode, 123 unsigned int iMat, 124 unsigned int iVFormat, 125 aiMesh *pcMeshOut, 126 unsigned int aiCurrent[2], 127 unsigned int *num_refs) const; 128 129 // ------------------------------------------------------------------- 130 // Get a list of all vertex formats that occur for a given material 131 // The output list contains duplicate elements 132 void GetVFormatList(const aiScene *pcScene, unsigned int iMat, 133 std::list<unsigned int> &aiOut) const; 134 135 // ------------------------------------------------------------------- 136 // Compute the absolute transformation matrices of each node 137 void ComputeAbsoluteTransform(aiNode *pcNode); 138 139 // ------------------------------------------------------------------- 140 // Simple routine to build meshes in worldspace, no further optimization 141 void BuildWCSMeshes(std::vector<aiMesh *> &out, aiMesh **in, 142 unsigned int numIn, aiNode *node) const; 143 144 // ------------------------------------------------------------------- 145 // Apply the node transformation to a mesh 146 void ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat) const; 147 148 // ------------------------------------------------------------------- 149 // Reset transformation matrices to identity 150 void MakeIdentityTransform(aiNode *nd) const; 151 152 // ------------------------------------------------------------------- 153 // Build reference counters for all meshes 154 void BuildMeshRefCountArray(const aiNode *nd, unsigned int *refs) const; 155 156 //! Configuration option: keep scene hierarchy as long as possible 157 bool configKeepHierarchy; 158 bool configNormalize; 159 bool configTransform; 160 aiMatrix4x4 configTransformation; 161 bool mConfigPointCloud; 162 }; 163 164 } // end of namespace Assimp 165 166 #endif // !!AI_GENFACENORMALPROCESS_H_INC 167