1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF 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
53class DeboneTest;
54
55namespace 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*/
68class DeboneProcess : public BaseProcess
69{
70public:
71
72 DeboneProcess();
73 ~DeboneProcess();
74
75public:
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
92protected:
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
119public:
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