Exemplo n.º 1
0
    private void SubdivideMesh()
    {
        var current = GetComponent <MeshFilter>().sharedMesh;
        var newMesh = Instantiate(current);

        newMesh.name = current.name;
        MeshSubdivider.Subdivide4(newMesh);
        GetComponent <MeshFilter>().sharedMesh = newMesh;
    }
Exemplo n.º 2
0
        public void Subdivide()
        {
            Deformer meshDeformer = m_editor.Selection.activeGameObject.GetComponentInParent <Deformer>();

            MeshFilter meshFilter = meshDeformer.GetComponent <MeshFilter>();

            MeshCollider meshCollider = meshDeformer.GetComponent <MeshCollider>();

            if (meshFilter.sharedMesh != null)
            {
                Mesh newMesh = MeshSubdivider.Subdivide(meshFilter.sharedMesh, 2);
                Mesh oldMesh = Instantiate(meshFilter.sharedMesh);
                oldMesh.name          = meshFilter.sharedMesh.name;
                newMesh.name          = meshFilter.sharedMesh.name;
                meshFilter.sharedMesh = null;
                meshFilter.sharedMesh = Instantiate(newMesh);
                if (meshCollider != null)
                {
                    meshCollider.sharedMesh = null;
                    meshCollider.sharedMesh = meshFilter.sharedMesh;
                }
                meshDeformer.Refresh();

                GameObject go = meshDeformer.gameObject;
                m_editor.Undo.CreateRecord(redo =>
                {
                    Mesh newMeshInstance = Instantiate(newMesh);
                    newMeshInstance.name = newMesh.name;

                    MeshFilter filter = go.GetComponent <MeshFilter>();
                    Destroy(filter.sharedMesh);
                    filter.sharedMesh = newMeshInstance;

                    MeshCollider collider = go.GetComponent <MeshCollider>();
                    if (collider != null)
                    {
                        Destroy(collider.sharedMesh);
                        collider.sharedMesh = newMeshInstance;
                    }

                    Deformer deformer = go.GetComponent <Deformer>();
                    deformer.Refresh();

                    return(true);
                }, undo =>
                {
                    Mesh oldMeshInstance = Instantiate(oldMesh);
                    oldMeshInstance.name = oldMesh.name;

                    MeshFilter filter = go.GetComponent <MeshFilter>();
                    Destroy(filter.sharedMesh);
                    filter.sharedMesh = oldMeshInstance;

                    MeshCollider collider = go.GetComponent <MeshCollider>();
                    if (collider != null)
                    {
                        Destroy(collider.sharedMesh);
                        collider.sharedMesh = oldMeshInstance;
                    }

                    Deformer deformer = go.GetComponent <Deformer>();
                    deformer.Refresh();

                    return(true);
                },
                                           purge =>
                {
                    Destroy(newMesh);
                    Destroy(oldMesh);
                });
            }
        }