private void CalculateVertexColors(Transform[] bones, Bone bone) { if (mesh == null) { return; } colors = new Color[mesh.vertexCount]; for (int i = 0; i < colors.Length; i++) { colors[i] = Color.black; } if (bones.Any(b => b.gameObject.GetInstanceID() == bone.gameObject.GetInstanceID())) { for (int i = 0; i < colors.Length; i++) { value = 0; if (mesh.boneWeights[i].boneIndex0 == boneIndex) { value = mesh.boneWeights[i].weight0; } else if (mesh.boneWeights[i].boneIndex1 == boneIndex) { value = mesh.boneWeights[i].weight1; } else if (mesh.boneWeights[i].boneIndex2 == boneIndex) { value = mesh.boneWeights[i].weight2; } else if (mesh.boneWeights[i].boneIndex3 == boneIndex) { value = mesh.boneWeights[i].weight3; } Util.HSBColor hsbColor = new Util.HSBColor(0.7f - value, 1.0f, 0.5f); hsbColor.a = colorTransparency; colors[i] = Util.HSBColor.ToColor(hsbColor); } } mesh.colors = colors; }
private void CalculateVertexColors(Transform[] bones, Bone bone) { if (mesh == null) { return; } colors = new Color[mesh.vertexCount]; for (int i = 0; i < colors.Length; i++) { colors[i] = Color.black; } if (bones.Any(b => b.gameObject.GetInstanceID() == bone.gameObject.GetInstanceID())) { #if UNITY_2019_1_OR_NEWER // Get all the bone weights, in vertex index order var boneWeights = mesh.GetAllBoneWeights(); // Keep track of where we are in the array of BoneWeights, as we iterate over the vertices var boneWeightIndex = 0; var bonesPerVertex = mesh.GetBonesPerVertex(); #endif for (int i = 0; i < colors.Length; i++) { value = 0; #if UNITY_2019_1_OR_NEWER var numberOfBonesForThisVertex = bonesPerVertex[i]; // For each vertex, iterate over its BoneWeights for (var v = 0; v < numberOfBonesForThisVertex; v++) { if (boneWeights[boneWeightIndex].boneIndex == boneIndex) { value = boneWeights[boneWeightIndex].weight; } boneWeightIndex++; } #else if (mesh.boneWeights[i].boneIndex0 == boneIndex) { value = mesh.boneWeights[i].weight0; } else if (mesh.boneWeights[i].boneIndex1 == boneIndex) { value = mesh.boneWeights[i].weight1; } else if (mesh.boneWeights[i].boneIndex2 == boneIndex) { value = mesh.boneWeights[i].weight2; } else if (mesh.boneWeights[i].boneIndex3 == boneIndex) { value = mesh.boneWeights[i].weight3; } #endif Util.HSBColor hsbColor = new Util.HSBColor(0.7f - value, 1.0f, 0.5f); hsbColor.a = colorTransparency; colors[i] = Util.HSBColor.ToColor(hsbColor); } } mesh.colors = colors; }