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