/// <summary> /// Recalculates the bone indexes. /// </summary> private BoneWeight RecalculateBoneIndexes(BoneWeight bw, SharedBoneBindposeGroups sharedGroups, Transform[] smBones, Matrix4x4[] smBindposes) { Func<Transform, Matrix4x4, int> GetBoneIdx = (bone, bindpose) => { SharedBoneBindpose shareBoneBindpose = sharedGroups.Find(bone, bindpose); if (shareBoneBindpose != null) return shareBoneBindpose.index; return 0; }; BoneWeight retBw = bw; retBw.boneIndex0 = GetBoneIdx(smBones[bw.boneIndex0], smBindposes[bw.boneIndex0]); retBw.boneIndex1 = GetBoneIdx(smBones[bw.boneIndex1], smBindposes[bw.boneIndex1]); retBw.boneIndex2 = GetBoneIdx(smBones[bw.boneIndex2], smBindposes[bw.boneIndex2]); retBw.boneIndex3 = GetBoneIdx(smBones[bw.boneIndex3], smBindposes[bw.boneIndex3]); //retBw.boneIndex0 = 0; //retBw.weight0 = 1; //retBw.weight1 = retBw.weight2 = retBw.weight3 = 0; //Debug.Log(bw.boneIndex0+ " " + bw.boneIndex1+ " " + bw.boneIndex2+ " " + bw.boneIndex3+ " " + ">" + // retBw.boneIndex0 + " " + retBw.boneIndex1 + " " + retBw.boneIndex2 + " " + retBw.boneIndex3 + " " + ">" + // retBw.weight0 + " " + retBw.weight1 + " " + retBw.weight2 + " " + retBw.weight3); return retBw; }
/// <summary> /// Initializes a new instance of the <see cref="SkinnedMeshCombineUtility"/> class. /// </summary> public SkinnedMeshCombinerUtility(CombineMode optimizeType, EndCombine endCombine, int maxVertexHint, int maxBoneHint) { this.optimizeType = optimizeType; this.endCombine = endCombine; if (this.optimizeType == CombineMode.CalculateOverlappedBoneBindpose) sharedGroups = new SharedBoneBindposeGroups(); else if (this.optimizeType == CombineMode.SharedBoneBindpose) boneIndexLookup = new Dictionary<Transform, int>(); this.bones = new List<Transform>(maxBoneHint); this.bindposes = new List<Matrix4x4>(maxBoneHint); this.boneWeights = new List<BoneWeight>(maxVertexHint); this.meshInstances = new List<MeshInstance>(); this.materials = new List<Material>(); }