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_LIMITBONEWEIGHTSPROCESS_H_INC 44 #define AI_LIMITBONEWEIGHTSPROCESS_H_INC 45 46 #include "BaseProcess.h" 47 48 struct aiMesh; 49 50 class LimitBoneWeightsTest; 51 52 namespace 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 */ 74 class ASSIMP_API LimitBoneWeightsProcess : public BaseProcess 75 { 76 public: 77 78 LimitBoneWeightsProcess(); 79 ~LimitBoneWeightsProcess(); 80 81 public: 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 98 public: 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 114 public: 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 WeightWeight122 Weight() { } WeightWeight123 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 136 public: 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