コード例 #1
0
        static void RefreshMeshColors()
        {
            SkinnedMeshRenderer smr = currentSelection.GetComponent <SkinnedMeshRenderer>();

            if (!BlackAndWhiteWeights)
            {
                Bone[] bones = FindObjectsOfType <Bone>();
                for (int j = 0; j < bones.Length; j++)
                {
                    int   boneIndx = smr.bones.ToList().IndexOf(bones[j].transform);
                    float hue      = ((float)boneIndx / smr.bones.Length);
                    Color col      = Color.HSVToRGB(hue * 1f, 1f, 1f);
                    if (hue >= 0)
                    {
                        bones[j].Color = col;
                    }
                }
            }

            if (currentSelection == null)
            {
                return;
            }

            GameObject c = Selection.activeGameObject;

            if (c && c.GetComponent <Bone>())
            {
                paintWeightsBone = c;
            }

            Vector3[]    vertices  = currentSelectionMesh.vertices;
            Color[]      colrs     = currentSelectionMesh.colors;
            BoneWeight[] bws       = currentSelectionMesh.boneWeights;
            int          boneIndex = smr.bones.ToList().IndexOf(paintWeightsBone.transform);

            //Debug.Log("pos is " +pos);
            if (BlackAndWhiteWeights && boneIndex > -1)
            {
                for (int i = 0; i < vertices.Length; i++)
                {
                    colrs[i] = Color.black;



                    if (bws[i].boneIndex0 == boneIndex)
                    {
                        float col = bws[i].weight0;
                        colrs[i] = new Color(col, col, col);
                    }
                    else if (bws[i].boneIndex1 == boneIndex)
                    {
                        float col = bws[i].weight1;
                        colrs[i] = new Color(col, col, col);
                    }
                }
            }
            if (Puppet3DEditor.BlackAndWhiteWeights)
            {
                Puppet3DEditor.currentSelectionMesh.colors = colrs;
            }
            else
            {
                Puppet3DEditor.currentSelectionMesh.colors = Skinning.SetColors(currentSelectionMesh.boneWeights);
            }
        }