, , , . , , . , . , . / . .
, = > = > .
, , - . , , , . , , . 2 :
1) , . , .
2) - , . , Mesh.boneWeights. , , > 1 . ? SkinnedMeshRenderer.bones. , , , .
script, . SkinnedMeshRenderer ( ):
using UnityEngine;
using System.Collections;
public class BoneHiglighter : MonoBehaviour {
public Color32 highlightColor = Color.red;
public Color32 regularColor = Color.white;
public SkinnedMeshRenderer smr;
public Transform bone;
private Transform prevBone;
int GetBoneIndex(Transform bone) {
Debug.Assert(smr != null);
var bones = smr.bones;
for (int i = 0; i < bones.Length; ++i) {
if (bones[i] == bone) return i;
}
return -1;
}
void Highlight(Transform bone) {
Debug.Assert(smr != null);
var idx = GetBoneIndex(bone);
var mesh = smr.sharedMesh;
var weights = mesh.boneWeights;
var colors = new Color32[weights.Length];
for (int i = 0; i < colors.Length; ++i) {
float sum = 0;
if (weights[i].boneIndex0 == idx && weights[i].weight0 > 0)
sum += weights[i].weight0;
if (weights[i].boneIndex1 == idx && weights[i].weight1 > 0)
sum += weights[i].weight1;
if (weights[i].boneIndex2 == idx && weights[i].weight2 > 0)
sum += weights[i].weight2;
if (weights[i].boneIndex3 == idx && weights[i].weight3 > 0)
sum += weights[i].weight3;
colors[i] = Color32.Lerp(regularColor, highlightColor, sum);
}
mesh.colors32 = colors;
}
void Start() {
if (smr == null) smr = GetComponent<SkinnedMeshRenderer>();
smr.sharedMesh = (Mesh)Instantiate(smr.sharedMesh);
Highlight(bone);
}
void Update() {
if (prevBone != bone) {
prevBone = bone;
Highlight(bone);
}
}
}
. : https://www.dropbox.com/s/yfoqo44bubcr48s/HighlightBone.zip?dl=0
: https://dl.dropboxusercontent.com/u/16950335/bones/index.html - , .