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_LIMITBONEWEIGHTSPROCESS_H_INC
44#define AI_LIMITBONEWEIGHTSPROCESS_H_INC
45
46#include "BaseProcess.h"
47
48struct aiMesh;
49
50class LimitBoneWeightsTest;
51
52namespace Assimp
53{
54
55// NOTE: If you change these limits, don't forget to change the
56// corresponding values in all Assimp ports
57
58// **********************************************************
59// Java: ConfigProperty.java,
60// ConfigProperty.DEFAULT_BONE_WEIGHT_LIMIT
61// **********************************************************
62
63#if (!defined AI_LMW_MAX_WEIGHTS)
64# define AI_LMW_MAX_WEIGHTS 0x4
65#endif // !! AI_LMW_MAX_WEIGHTS
66
67// ---------------------------------------------------------------------------
68/** This post processing step limits the number of bones affecting a vertex
69* to a certain maximum value. If a vertex is affected by more than that number
70* of bones, the bone weight with the least influence on this vertex are removed.
71* The other weights on this bone are then renormalized to assure the sum weight
72* to be 1.
73*/
74class ASSIMP_API LimitBoneWeightsProcess : public BaseProcess
75{
76public:
77
78 LimitBoneWeightsProcess();
79 ~LimitBoneWeightsProcess();
80
81public:
82 // -------------------------------------------------------------------
83 /** Returns whether the processing step is present in the given flag.
84 * @param pFlags The processing flags the importer was called with.
85 * A bitwise combination of #aiPostProcessSteps.
86 * @return true if the process is present in this flag fields,
87 * false if not.
88 */
89 bool IsActive( unsigned int pFlags) const;
90
91 // -------------------------------------------------------------------
92 /** Called prior to ExecuteOnScene().
93 * The function is a request to the process to update its configuration
94 * basing on the Importer's configuration property list.
95 */
96 void SetupProperties(const Importer* pImp);
97
98public:
99
100 // -------------------------------------------------------------------
101 /** Limits the bone weight count for all vertices in the given mesh.
102 * @param pMesh The mesh to process.
103 */
104 void ProcessMesh( aiMesh* pMesh);
105
106 // -------------------------------------------------------------------
107 /** Executes the post processing step on the given imported data.
108 * At the moment a process is not supposed to fail.
109 * @param pScene The imported data to work at.
110 */
111 void Execute( aiScene* pScene);
112
113
114public:
115
116 // -------------------------------------------------------------------
117 /** Describes a bone weight on a vertex */
118 struct Weight
119 {
120 unsigned int mBone; ///< Index of the bone
121 float mWeight; ///< Weight of that bone on this vertex
122 Weight() { }
123 Weight( unsigned int pBone, float pWeight)
124 {
125 mBone = pBone;
126 mWeight = pWeight;
127 }
128
129 /** Comparison operator to sort bone weights by descending weight */
130 bool operator < (const Weight& pWeight) const
131 {
132 return mWeight > pWeight.mWeight;
133 }
134 };
135
136public:
137 /** Maximum number of bones influencing any single vertex. */
138 unsigned int mMaxWeights;
139};
140
141} // end of namespace Assimp
142
143#endif // AI_LIMITBONEWEIGHTSPROCESS_H_INC
144