/src/assimp/code/PostProcessing/LimitBoneWeightsProcess.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2025, 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_LIMITBONEWEIGHTSPROCESS_H_INC |
44 | | #define AI_LIMITBONEWEIGHTSPROCESS_H_INC |
45 | | |
46 | | #include "Common/BaseProcess.h" |
47 | | |
48 | | // Forward declarations |
49 | | struct aiMesh; |
50 | | |
51 | | class LimitBoneWeightsTest; |
52 | | |
53 | | namespace Assimp { |
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 | | */ |
74 | | class ASSIMP_API LimitBoneWeightsProcess : public BaseProcess { |
75 | | public: |
76 | | // ------------------------------------------------------------------- |
77 | | /// The default class constructor / destructor. |
78 | | LimitBoneWeightsProcess(); |
79 | | ~LimitBoneWeightsProcess() override = default; |
80 | | |
81 | | // ------------------------------------------------------------------- |
82 | | /** Returns whether the processing step is present in the given flag. |
83 | | * @param pFlags The processing flags the importer was called with. |
84 | | * A bitwise combination of #aiPostProcessSteps. |
85 | | * @return true if the process is present in this flag fields, |
86 | | * false if not. |
87 | | */ |
88 | | bool IsActive( unsigned int pFlags) const override; |
89 | | |
90 | | // ------------------------------------------------------------------- |
91 | | /** Called prior to ExecuteOnScene(). |
92 | | * The function is a request to the process to update its configuration |
93 | | * basing on the Importer's configuration property list. |
94 | | */ |
95 | | void SetupProperties(const Importer* pImp) override; |
96 | | |
97 | | // ------------------------------------------------------------------- |
98 | | /** Executes the post processing step on the given imported data. |
99 | | * At the moment a process is not supposed to fail. |
100 | | * @param pScene The imported data to work at. |
101 | | */ |
102 | | void Execute( aiScene* pScene) override; |
103 | | |
104 | | // ------------------------------------------------------------------- |
105 | | /** Limits the bone weight count for all vertices in the given mesh. |
106 | | * @param pMesh The mesh to process. |
107 | | */ |
108 | | void ProcessMesh( aiMesh* pMesh); |
109 | | |
110 | | // ------------------------------------------------------------------- |
111 | | /** Describes a bone weight on a vertex */ |
112 | | struct Weight { |
113 | | unsigned int mBone; ///< Index of the bone |
114 | | float mWeight; ///< Weight of that bone on this vertex |
115 | | Weight() AI_NO_EXCEPT |
116 | 33.2k | : mBone(0) |
117 | 33.2k | , mWeight(0.0f) { |
118 | | // empty |
119 | 33.2k | } |
120 | | |
121 | | Weight( unsigned int pBone, float pWeight) |
122 | 1.58k | : mBone(pBone) |
123 | 1.58k | , mWeight(pWeight) { |
124 | | // empty |
125 | 1.58k | } |
126 | | |
127 | | /** Comparison operator to sort bone weights by descending weight */ |
128 | 2.89k | bool operator < (const Weight& pWeight) const { |
129 | 2.89k | return mWeight > pWeight.mWeight; |
130 | 2.89k | } |
131 | | }; |
132 | | |
133 | | /** Maximum number of bones influencing any single vertex. */ |
134 | | unsigned int mMaxWeights; |
135 | | bool mRemoveEmptyBones; |
136 | | }; |
137 | | |
138 | | } // end of namespace Assimp |
139 | | |
140 | | #endif // AI_LIMITBONEWEIGHTSPROCESS_H_INC |