private void DrawTwist()
        {
            if (null == mAppearData)
            {
                return;
            }

            GUILayout.BeginVertical();

            for (int i = 0; i < (int)EMorphItem.Max; i++)
            {
                if (i == (int)EMorphItem.LegBelly ||
                    i == (int)EMorphItem.LegWaist ||
                    i == (int)EMorphItem.Foot ||
                    i == (int)EMorphItem.Hand ||
                    i == (int)EMorphItem.TorsoUpperLeg)
                {
                    continue;
                }

                GUILayout.BeginHorizontal();
                EMorphItem eItem = (EMorphItem)i;
                GUILayout.Label(eItem.ToString());

                float weight = mAppearData.GetWeight(eItem);

                float newWeight = GUILayout.HorizontalSlider(weight, -1f, 1f);

                if (!Mathf.Approximately(weight, newWeight))
                {
                    mAppearData.SetWeight(eItem, newWeight);

                    Apply();
                }

                GUILayout.EndHorizontal();
            }

            DrawBuild();

            GUILayout.EndVertical();
        }
Exemple #2
0
        static Mesh BakeToMesh(CustomPartInfo partInfo, AppearData appearData)
        {
            SkinnedMeshRenderer smr = partInfo.Smr;

            if (string.IsNullOrEmpty(partInfo.ModelName) || smr.sharedMesh.blendShapeCount == 0)
            {
                return(smr.sharedMesh);
            }

            EMorphItem indexStart = EMorphItem.Max;
            EMorphItem indexEnd   = EMorphItem.Max;

            if (partInfo.ModelName.Contains("head"))
            {
                indexStart = EMorphItem.MinFace;
                indexEnd   = EMorphItem.MaxFace;
            }
            else if (partInfo.ModelName.Contains("torso"))
            {
                indexStart = EMorphItem.MinUpperbody;
                indexEnd   = EMorphItem.MaxUpperbody;
            }
            else if (partInfo.ModelName.Contains("legs"))
            {
                indexStart = EMorphItem.MinLowerbody;
                indexEnd   = EMorphItem.MaxLowerbody;
            }
            else if (partInfo.ModelName.Contains("feet"))
            {
                indexStart = EMorphItem.MinFoot;
                indexEnd   = EMorphItem.MaxFoot;
            }
            else if (partInfo.ModelName.Contains("hand"))
            {
                indexStart = EMorphItem.MinHand;
                indexEnd   = EMorphItem.MaxHand;
            }

            if (indexStart != indexEnd)
            {
                _tmpWeightIdxs.Clear();
                _tmpWeightVals.Clear();
                for (int i = (int)indexStart; i < (int)indexEnd; i++)
                {
                    float w     = appearData.GetWeight((EMorphItem)i) * 100f;
                    int   index = i - (int)indexStart;
                    if (w > 0f)
                    {
                        index = index * 2;
                    }
                    else
                    {
                        w     = -w;
                        index = index * 2 + 1;
                    }

                    if (smr.sharedMesh.blendShapeCount > index)
                    {
                        _tmpWeightIdxs.Add(index);
                        _tmpWeightVals.Add(smr.GetBlendShapeWeight(index));
                        smr.SetBlendShapeWeight(index, w);
                    }
                }
                Mesh msh = PeekTmpMesh();
                smr.BakeMesh(msh);
                msh.boneWeights = smr.sharedMesh.boneWeights;
                msh.bindposes   = smr.sharedMesh.bindposes;
                if (_tmpWeightIdxs.Count > 0)
                {
                    for (int i = 0; i < _tmpWeightIdxs.Count; i++)
                    {
                        smr.SetBlendShapeWeight(_tmpWeightIdxs[i], _tmpWeightVals[i]);
                    }
                }
                return(msh);
            }
            return(smr.sharedMesh);
        }