public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Open Window"))
            {
                BlendShapeBuilderWindow.Open();
            }

            EditorGUILayout.Space();
        }
예제 #2
0
        public static void ConvertToComposeData(UnityEngine.Object targetObject)
        {
            var targetMesh = Utils.ExtractMesh(targetObject);

            if (targetMesh == null)
            {
                return;
            }
            var materials = Utils.ExtractMaterials(targetObject);

            int numBS = targetMesh.blendShapeCount;

            if (numBS == 0)
            {
                Debug.Log("BlendShapeInspector: This mesh has no BlendShape.");
                return;
            }

            var baseMesh = Instantiate(targetMesh);

            baseMesh.name = targetMesh.name;
            baseMesh.ClearBlendShapes();
            var baseGO = Utils.MeshToGameObject(baseMesh, Vector3.zero, materials);

            var builder = baseGO.AddComponent <BlendShapeBuilder>();
            var data    = builder.data.blendShapeData;

            data.Clear();

            for (int bi = 0; bi < numBS; ++bi)
            {
                var name      = targetMesh.GetBlendShapeName(bi);
                int numFrames = targetMesh.GetBlendShapeFrameCount(bi);
                var gos       = ExtractBlendShapeFrames(targetMesh, bi, -1, materials);

                float step   = 100.0f / numFrames;
                float weight = step;
                var   bsd    = new BlendShapeData();
                data.Add(bsd);
                bsd.name = name;
                foreach (var go in gos)
                {
                    var fd = new BlendShapeFrameData();
                    bsd.frames.Add(fd);
                    fd.mesh   = go;
                    fd.weight = weight;
                    weight   += step;
                }
            }
            Undo.RegisterCreatedObjectUndo(baseGO, "BlendShapeBuilder");

            Selection.activeObject = baseGO;
            BlendShapeBuilderWindow.Open();
        }