1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, assimp team |
6 | |
7 | All rights reserved. |
8 | |
9 | Redistribution and use of this software in source and binary forms, |
10 | with or without modification, are permitted provided that the |
11 | following conditions are met: |
12 | |
13 | * Redistributions of source code must retain the above |
14 | copyright notice, this list of conditions and the |
15 | following disclaimer. |
16 | |
17 | * Redistributions in binary form must reproduce the above |
18 | copyright notice, this list of conditions and the |
19 | following disclaimer in the documentation and/or other |
20 | materials provided with the distribution. |
21 | |
22 | * Neither the name of the assimp team, nor the names of its |
23 | contributors may be used to endorse or promote products |
24 | derived from this software without specific prior |
25 | written permission of the assimp team. |
26 | |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | |
39 | ---------------------------------------------------------------------- |
40 | */ |
41 | |
42 | /** Defines a post processing step to limit the number of bones affecting a single vertex. */ |
43 | #ifndef AI_DEBONEPROCESS_H_INC |
44 | #define AI_DEBONEPROCESS_H_INC |
45 | |
46 | #include <vector> |
47 | #include <utility> |
48 | #include "BaseProcess.h" |
49 | |
50 | #include <assimp/mesh.h> |
51 | #include <assimp/scene.h> |
52 | |
53 | class DeboneTest; |
54 | |
55 | namespace Assimp |
56 | { |
57 | |
58 | #if (!defined AI_DEBONE_THRESHOLD) |
59 | # define AI_DEBONE_THRESHOLD 1.0f |
60 | #endif // !! AI_DEBONE_THRESHOLD |
61 | |
62 | // --------------------------------------------------------------------------- |
63 | /** This post processing step removes bones nearly losslessly or according to |
64 | * a configured threshold. In order to remove the bone, the primitives affected by |
65 | * the bone are split from the mesh. The split off (new) mesh is boneless. At any |
66 | * point in time, bones without affect upon a given mesh are to be removed. |
67 | */ |
68 | class DeboneProcess : public BaseProcess |
69 | { |
70 | public: |
71 | |
72 | DeboneProcess(); |
73 | ~DeboneProcess(); |
74 | |
75 | public: |
76 | // ------------------------------------------------------------------- |
77 | /** Returns whether the processing step is present in the given flag. |
78 | * @param pFlags The processing flags the importer was called with. |
79 | * A bitwise combination of #aiPostProcessSteps. |
80 | * @return true if the process is present in this flag fields, |
81 | * false if not. |
82 | */ |
83 | bool IsActive( unsigned int pFlags) const; |
84 | |
85 | // ------------------------------------------------------------------- |
86 | /** Called prior to ExecuteOnScene(). |
87 | * The function is a request to the process to update its configuration |
88 | * basing on the Importer's configuration property list. |
89 | */ |
90 | void SetupProperties(const Importer* pImp); |
91 | |
92 | protected: |
93 | |
94 | // ------------------------------------------------------------------- |
95 | /** Executes the post processing step on the given imported data. |
96 | * At the moment a process is not supposed to fail. |
97 | * @param pScene The imported data to work at. |
98 | */ |
99 | void Execute( aiScene* pScene); |
100 | |
101 | // ------------------------------------------------------------------- |
102 | /** Counts bones total/removable in a given mesh. |
103 | * @param pMesh The mesh to process. |
104 | */ |
105 | bool ConsiderMesh( const aiMesh* pMesh); |
106 | |
107 | /// Splits the given mesh by bone count. |
108 | /// @param pMesh the Mesh to split. Is not changed at all, but might be superfluous in case it was split. |
109 | /// @param poNewMeshes Array of submeshes created in the process. Empty if splitting was not necessary. |
110 | void SplitMesh(const aiMesh* pMesh, std::vector< std::pair< aiMesh*,const aiBone* > >& poNewMeshes) const; |
111 | |
112 | /// Recursively updates the node's mesh list to account for the changed mesh list |
113 | void UpdateNode(aiNode* pNode) const; |
114 | |
115 | // ------------------------------------------------------------------- |
116 | // Apply transformation to a mesh |
117 | void ApplyTransform(aiMesh* mesh, const aiMatrix4x4& mat)const; |
118 | |
119 | public: |
120 | /** Number of bones present in the scene. */ |
121 | unsigned int mNumBones; |
122 | unsigned int mNumBonesCanDoWithout; |
123 | |
124 | float mThreshold; |
125 | bool mAllOrNone; |
126 | |
127 | /// Per mesh index: Array of indices of the new submeshes. |
128 | std::vector< std::vector< std::pair< unsigned int,aiNode* > > > mSubMeshIndices; |
129 | }; |
130 | |
131 | } // end of namespace Assimp |
132 | |
133 | #endif // AI_DEBONEPROCESS_H_INC |
134 | |