コード例 #1
0
ファイル: WeightEditor.cs プロジェクト: CarlosMeloStuff/Arx
        void DoWindow(int windowId)
        {
            Vertex selectedVertex = spriteMeshCache.selectedVertex;

            string[] names = GetBoneNames();

            EditorGUIUtility.wideMode = true;
            float labelWidth = EditorGUIUtility.labelWidth;

            if (selectedVertex != null)
            {
                BoneWeight2 boneWeight = selectedVertex.boneWeight;

                int index0 = boneWeight.boneIndex0;
                int index1 = boneWeight.boneIndex1;
                int index2 = boneWeight.boneIndex2;
                int index3 = boneWeight.boneIndex3;

                float weight0 = boneWeight.weight0;
                float weight1 = boneWeight.weight1;
                float weight2 = boneWeight.weight2;
                float weight3 = boneWeight.weight3;

                EditorGUIUtility.labelWidth = 30f;

                EditorGUILayout.BeginHorizontal();

                EditorGUI.BeginChangeCheck();

                index0  = EditorGUILayout.Popup(index0, names, GUILayout.Width(100f));
                weight0 = EditorGUILayout.Slider(weight0, 0f, 1f);

                if (boneWeight != null && EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights");
                    boneWeight.SetWeight(0, index0, weight0);
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();

                EditorGUI.BeginChangeCheck();

                index1  = EditorGUILayout.Popup(index1, names, GUILayout.Width(100f));
                weight1 = EditorGUILayout.Slider(weight1, 0f, 1f);

                if (boneWeight != null && EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights");
                    boneWeight.SetWeight(1, index1, weight1);
                }

                EditorGUILayout.EndHorizontal();


                EditorGUILayout.BeginHorizontal();

                EditorGUI.BeginChangeCheck();

                index2  = EditorGUILayout.Popup(index2, names, GUILayout.Width(100f));
                weight2 = EditorGUILayout.Slider(weight2, 0f, 1f);

                if (boneWeight != null && EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights");
                    boneWeight.SetWeight(2, index2, weight2);
                }

                EditorGUILayout.EndHorizontal();


                EditorGUILayout.BeginHorizontal();

                EditorGUI.BeginChangeCheck();

                index3  = EditorGUILayout.Popup(index3, names, GUILayout.Width(100f));
                weight3 = EditorGUILayout.Slider(weight3, 0f, 1f);

                if (boneWeight != null && EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights");
                    boneWeight.SetWeight(3, index3, weight3);
                }

                EditorGUILayout.EndHorizontal();
            }
            else
            {
                int index = spriteMeshCache.bindPoses.IndexOf(spriteMeshCache.selectedBone);

                EditorGUILayout.BeginHorizontal();

                EditorGUI.BeginChangeCheck();

                index = EditorGUILayout.Popup(index, names, GUILayout.Width(100f));

                if (index >= 0 && index < spriteMeshCache.bindPoses.Count)
                {
                    spriteMeshCache.selectedBone = spriteMeshCache.bindPoses[index];
                }

                EditorGUI.BeginDisabledGroup(spriteMeshCache.selectedBone == null);

                if (Event.current.type == EventType.MouseUp ||
                    Event.current.type == EventType.MouseDown)
                {
                    mLastWeight = 0f;
                    mWeight     = 0f;
                }

                mWeight = EditorGUILayout.Slider(mLastWeight, -1f, 1f);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Modify Weights");

                    float delta = mWeight - mLastWeight;
                    mLastWeight = mWeight;

                    List <Vertex> vertices = spriteMeshCache.selectedVertices;

                    if (vertices.Count == 0)
                    {
                        vertices = spriteMeshCache.texVertices;
                    }

                    foreach (Vertex vertex in vertices)
                    {
                        BoneWeight2 bw = vertex.boneWeight;
                        bw.SetBoneIndexWeight(index, bw.GetBoneWeight(index) + delta);
                    }
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.EndDisabledGroup();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Smooth"))
            {
                Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Smooth Weights");

                List <Vertex> targetVertices = spriteMeshCache.texVertices;

                if (spriteMeshCache.selectedVertices.Count > 0)
                {
                    targetVertices = spriteMeshCache.selectedVertices;
                }

                spriteMeshCache.SmoothVertices(targetVertices);
            }

            if (GUILayout.Button("Auto"))
            {
                Undo.RegisterCompleteObjectUndo(spriteMeshCache, "Calculate Weights");

                List <Vertex> targetVertices = spriteMeshCache.texVertices;

                if (spriteMeshCache.selectedVertices.Count > 0)
                {
                    targetVertices = spriteMeshCache.selectedVertices;
                }

                spriteMeshCache.CalculateAutomaticWeights(targetVertices);
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            EditorGUIUtility.labelWidth = 50f;

            overlayColors = EditorGUILayout.Toggle("Overlay", overlayColors);

            EditorGUIUtility.labelWidth = 30f;

            showPie = EditorGUILayout.Toggle("Pies", showPie);

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = labelWidth;

            /*
             * boneScrollListPosition = EditorGUILayout.BeginScrollView(boneScrollListPosition);
             *
             * boneList.DoLayoutList();
             *
             * EditorGUILayout.EndScrollView();
             */

            EatMouseInput(new Rect(0, 0, windowRect.width, windowRect.height));
        }