RecalculateBoneWeights() публичный Метод

public RecalculateBoneWeights ( ) : void
Результат void
Пример #1
0
    public override void OnInspectorGUI()
    {
        Skin2D skin = (Skin2D)target;

        DrawDefaultInspector();

        EditorGUILayout.Separator();

        /* Moved to skeleton for multiple Skin2D
         * if (skin.selectedBones != null && skin.GetComponent<MeshFilter>().sharedMesh != null && GUILayout.Button("Calculate weights")) {
         * skin.CalculateBoneWeights();
         * }*/

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Save as Prefab"))
        {
            skin.SaveAsPrefab();
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Recalculate Bone Weights"))
        {
            skin.RecalculateBoneWeights();
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Create Control Points"))
        {
            ControlPoint.CreateControlPoints(skin.GetComponent <SkinnedMeshRenderer>());
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Reset Control Points"))
        {
            skin.ResetControlPointPositions();
        }
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        Skin2D skin = (Skin2D)target;

        DrawDefaultInspector();

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Save as Prefab"))
        {
            skin.SaveAsPrefab();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Recalculate Bone Weights"))
        {
            skin.RecalculateBoneWeights();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Create Control Points"))
        {
            ControlPoint.CreateControlPoints(skin.GetComponent <SkinnedMeshRenderer>());
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Reset Control Points"))
        {
            skin.ResetControlPointPositions();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Generate Mesh Asset"))
        {
            #if UNITY_EDITOR
            ScriptableObjectUtility.CreateAsset(skin.GetComponent <SkinnedMeshRenderer>().sharedMesh);
                        #endif
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial != null && GUILayout.Button("Generate Material Asset"))
        {
            #if UNITY_EDITOR
            Material material = new Material(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            material.CopyPropertiesFromMaterial(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial = material;
            AssetDatabase.CreateAsset(material, "Assets/" + material.mainTexture.name + ".mat");
                        #endif
        }
    }
Пример #3
0
 public static void Create()
 {
     if (Selection.activeGameObject != null)
     {
         GameObject          o              = Selection.activeGameObject;
         SkinnedMeshRenderer skin           = o.GetComponent <SkinnedMeshRenderer>();
         SpriteRenderer      spriteRenderer = o.GetComponent <SpriteRenderer>();
         if (skin == null && spriteRenderer != null)
         {
             Sprite     thisSprite = spriteRenderer.sprite;
             SpriteMesh spriteMesh = new SpriteMesh();
             spriteMesh.spriteRenderer = spriteRenderer;
             spriteMesh.CreateSpriteMesh();
             Texture2D spriteTexture  = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(spriteRenderer.sprite, false);
             Material  spriteMaterial = new Material(spriteRenderer.sharedMaterial);
             spriteMaterial.CopyPropertiesFromMaterial(spriteRenderer.sharedMaterial);
             spriteMaterial.mainTexture = spriteTexture;
             string sortLayerName = spriteRenderer.sortingLayerName;
             int    sortOrder     = spriteRenderer.sortingOrder;
             DestroyImmediate(spriteRenderer);
             Skin2D skin2D = o.AddComponent <Skin2D>();
             skin2D.sprite = thisSprite;
             skin          = o.GetComponent <SkinnedMeshRenderer>();
             MeshFilter filter = o.GetComponent <MeshFilter>();
             skin.material         = spriteMaterial;
             skin.sortingLayerName = sortLayerName;
             skin.sortingOrder     = sortOrder;
             filter.mesh           = (Mesh)Selection.activeObject;
             if (filter.sharedMesh != null && skin.sharedMesh == null)
             {
                 skin.sharedMesh = filter.sharedMesh;
             }
             // Recalculate the bone weights for the new mesh
             skin2D.RecalculateBoneWeights();
         }
         else
         {
             o = new GameObject("Skin2D");
             Undo.RegisterCreatedObjectUndo(o, "Create Skin2D");
             o.AddComponent <Skin2D> ();
         }
     }
     else
     {
         GameObject o = new GameObject("Skin2D");
         Undo.RegisterCreatedObjectUndo(o, "Create Skin2D");
         o.AddComponent <Skin2D> ();
     }
 }
Пример #4
0
    public static void Create()
    {
        if (Selection.activeGameObject != null)
        {
            GameObject          o              = Selection.activeGameObject;
            SkinnedMeshRenderer skin           = o.GetComponent <SkinnedMeshRenderer>();
            SpriteRenderer      spriteRenderer = o.GetComponent <SpriteRenderer>();
            if (skin == null && spriteRenderer != null)
            {
                Sprite     thisSprite = spriteRenderer.sprite;
                SpriteMesh spriteMesh = new SpriteMesh();
                spriteMesh.spriteRenderer = spriteRenderer;
                spriteMesh.CreateSpriteMesh();
                Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(spriteRenderer.sprite, false);

                // Copy the sprite material
                Material spriteMaterial = new Material(spriteRenderer.sharedMaterial);
                spriteMaterial.CopyPropertiesFromMaterial(spriteRenderer.sharedMaterial);
                spriteMaterial.mainTexture = spriteTexture;
                string sortLayerName = spriteRenderer.sortingLayerName;
                int    sortOrder     = spriteRenderer.sortingOrder;
                DestroyImmediate(spriteRenderer);
                Skin2D skin2D = o.AddComponent <Skin2D>();
                skin2D.sprite = thisSprite;
                skin          = o.GetComponent <SkinnedMeshRenderer>();
                MeshFilter filter = o.GetComponent <MeshFilter>();
                skin.material = spriteMaterial;

                // Save out the material from the sprite so we have a default material
                if (!Directory.Exists("Assets/Materials"))
                {
                    AssetDatabase.CreateFolder("Assets", "Materials");
                    AssetDatabase.Refresh();
                }
                AssetDatabase.CreateAsset(spriteMaterial, "Assets/Materials/" + spriteMaterial.mainTexture.name + ".mat");
                Debug.Log("Created material " + spriteMaterial.mainTexture.name + " for " + skin.gameObject.name);
                skin2D.referenceMaterial = spriteMaterial;
                skin.sortingLayerName    = sortLayerName;
                skin.sortingOrder        = sortOrder;

                // Create the mesh from the selection
                filter.mesh = (Mesh)Selection.activeObject;
                if (filter.sharedMesh != null && skin.sharedMesh == null)
                {
                    skin.sharedMesh = filter.sharedMesh;
                }
                // Recalculate the bone weights for the new mesh
                skin2D.RecalculateBoneWeights();
            }
            else
            {
                o = new GameObject("Skin2D");
                Undo.RegisterCreatedObjectUndo(o, "Create Skin2D");
                o.AddComponent <Skin2D> ();
            }
        }
        else
        {
            GameObject o = new GameObject("Skin2D");
            Undo.RegisterCreatedObjectUndo(o, "Create Skin2D");
            o.AddComponent <Skin2D> ();
        }
    }
Пример #5
0
    public override void OnInspectorGUI()
    {
        Skin2D skin = (Skin2D)target;

        DrawDefaultInspector();

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Save as Prefab"))
        {
            skin.SaveAsPrefab();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Recalculate Bone Weights"))
        {
            skin.RecalculateBoneWeights();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Create Control Points"))
        {
            ControlPoint.CreateControlPoints(skin.GetComponent <SkinnedMeshRenderer>());
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Reset Control Points"))
        {
            skin.ResetControlPointPositions();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Generate Mesh Asset"))
        {
            #if UNITY_EDITOR
            // Check if the Meshes directory exists, if not, create it.
            if (!Directory.Exists("Assets/Meshes"))
            {
                AssetDatabase.CreateFolder("Assets", "Meshes");
                AssetDatabase.Refresh();
            }
            ScriptableObjectUtility.CreateAsset(skin.GetComponent <SkinnedMeshRenderer>().sharedMesh, "Meshes/" + skin.gameObject.name + ".Mesh");
                        #endif
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial != null && GUILayout.Button("Generate Material Asset"))
        {
            #if UNITY_EDITOR
            Material material = new Material(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            material.CopyPropertiesFromMaterial(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial = material;
            if (!Directory.Exists("Assets/Materials"))
            {
                AssetDatabase.CreateFolder("Assets", "Materials");
                AssetDatabase.Refresh();
            }
            AssetDatabase.CreateAsset(material, "Assets/Materials/" + material.mainTexture.name + ".mat");
            Debug.Log("Created material " + material.mainTexture.name + " for " + skin.gameObject.name);
                        #endif
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.Separator();

        if (GUILayout.Button("Toggle Mesh Outline"))
        {
            Skin2D.showMeshOutline = !Skin2D.showMeshOutline;
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Save as Prefab"))
        {
            skin.SaveAsPrefab();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Recalculate Bone Weights"))
        {
            skin.RecalculateBoneWeights();
        }

        EditorGUILayout.Separator();
        handleColor = EditorGUILayout.ColorField("Handle Color", handleColor);
        changedBaseSelectDistance = EditorGUILayout.Slider("Handle Size", baseSelectDistance, 0, 1);
        if (baseSelectDistance != changedBaseSelectDistance)
        {
            baseSelectDistance = changedBaseSelectDistance;
            EditorUtility.SetDirty(this);
            SceneView.RepaintAll();
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Create Control Points"))
        {
            skin.CreateControlPoints(skin.GetComponent <SkinnedMeshRenderer>());
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Reset Control Points"))
        {
            skin.ResetControlPointPositions();
        }

        if (skin.points != null && skin.controlPoints != null && skin.controlPoints.Length > 0 &&
            selectedIndex != -1 && GUILayout.Button("Reset Selected Control Point"))
        {
            skin.controlPoints[selectedIndex].ResetPosition();
            skin.points.SetPoint(skin.controlPoints[selectedIndex]);
        }

        if (GUILayout.Button("Remove Control Points"))
        {
            skin.RemoveControlPoints();
        }

        EditorGUILayout.Separator();

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMesh != null && GUILayout.Button("Generate Mesh Asset"))
        {
            #if UNITY_EDITOR
            // Check if the Meshes directory exists, if not, create it.
            if (!Directory.Exists("Assets/Meshes"))
            {
                AssetDatabase.CreateFolder("Assets", "Meshes");
                AssetDatabase.Refresh();
            }
            Mesh mesh = new Mesh();
            mesh.name      = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.name.Replace(".SkinnedMesh", ".Mesh");;
            mesh.vertices  = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.vertices;
            mesh.triangles = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.triangles;
            mesh.normals   = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.normals;
            mesh.uv        = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.uv;
            mesh.uv2       = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.uv2;
            mesh.bounds    = skin.GetComponent <SkinnedMeshRenderer>().sharedMesh.bounds;
            ScriptableObjectUtility.CreateAsset(mesh, "Meshes/" + skin.gameObject.name + ".Mesh");
                        #endif
        }

        if (skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial != null && GUILayout.Button("Generate Material Asset"))
        {
            #if UNITY_EDITOR
            Material material = new Material(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            material.CopyPropertiesFromMaterial(skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial);
            skin.GetComponent <SkinnedMeshRenderer>().sharedMaterial = material;
            if (!Directory.Exists("Assets/Materials"))
            {
                AssetDatabase.CreateFolder("Assets", "Materials");
                AssetDatabase.Refresh();
            }
            AssetDatabase.CreateAsset(material, "Assets/Materials/" + material.mainTexture.name + ".mat");
            Debug.Log("Created material " + material.mainTexture.name + " for " + skin.gameObject.name);
                        #endif
        }
    }