Esempio n. 1
0
    void Update()
    {
        if (!interactive)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            _simp.CollapseEdge(_simp.costs.RemoveFront());
            UpdateMesh();
        }
    }
    void Simplify()
    {
        var rationAtLevel = 1f;
        var rScale        = 1.0f / scale;

        for (var level = 0; level < recursionLevel; level++)
        {
            rationAtLevel *= ratio;
            var target = (GameObject)Instantiate(prefab);
            target.transform.parent = parent;
            var meshfilters = target.GetComponentsInChildren <MeshFilter>();
            for (var i = 0; i < meshfilters.Length; i++)
            {
                var mesh            = meshfilters[i].mesh;
                var vertices        = mesh.vertices.Select((v) => v * scale).ToArray();
                var simp            = new Simplification(vertices, mesh.triangles);
                var targetFaceCount = (int)(rationAtLevel * mesh.triangles.Length / 3);
                while (targetFaceCount < simp.faceDb.FaceCount)
                {
                    var edge = simp.costs.RemoveFront();
                    simp.CollapseEdge(edge);
                }
                Vector3[] outVertices;
                int[]     outTriangles;
                simp.ToMesh(out outVertices, out outTriangles);
                Debug.Log(string.Format("Simplification step {0}/{1}, face {2}/{3}",
                                        i, meshfilters.Length, outTriangles.Length / 3, mesh.triangles.Length / 3));
                mesh.Clear();
                mesh.vertices  = outVertices.Select((v) => v * rScale).ToArray();
                mesh.triangles = outTriangles;
                mesh.RecalculateNormals();
            }
        }
    }
Esempio n. 3
0
 void Simplify()
 {
     var rationAtLevel = 1f;
     var rScale = 1.0f / scale;
     for (var level = 0; level < recursionLevel; level++) {
         rationAtLevel *= ratio;
         var target = (GameObject)Instantiate(prefab);
         target.transform.parent = parent;
         var meshfilters = target.GetComponentsInChildren<MeshFilter>();
         for (var i = 0; i < meshfilters.Length; i++) {
             var mesh = meshfilters[i].mesh;
             var vertices = mesh.vertices.Select((v) => v * scale).ToArray();
             var simp = new Simplification(vertices, mesh.triangles);
             var targetFaceCount = (int)(rationAtLevel * mesh.triangles.Length / 3);
             while (targetFaceCount < simp.faceDb.FaceCount) {
                 var edge = simp.costs.RemoveFront();
                 simp.CollapseEdge(edge);
             }
             Vector3[] outVertices;
             int[] outTriangles;
             simp.ToMesh(out outVertices, out outTriangles);
             Debug.Log(string.Format("Simplification step {0}/{1}, face {2}/{3}",
                 i, meshfilters.Length, outTriangles.Length / 3, mesh.triangles.Length / 3));
             mesh.Clear();
             mesh.vertices = outVertices.Select((v) => v * rScale).ToArray();
             mesh.triangles = outTriangles;
             mesh.RecalculateNormals();
         }
     }
 }
Esempio n. 4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            for (int i = 0; i < 1000; ++i)
            {
                var edgeCost = simp.costs.RemoveFront();
                simp.CollapseEdge(edgeCost);
            }

            simp.ToMesh(out data.vertices, out data.triangles);
            if (go.mf.sharedMesh != null)
            {
                Destroy(go.mf.sharedMesh);
            }
            data.CalculateNormals();

            if (Input.GetKey(KeyCode.LeftShift))
            {
                data.SplitEdgesCalcSmoothness();
            }

            mesh             = data.CreateMesh();
            go.mf.sharedMesh = mesh;
        }
    }
    void CollapseAnEdge()
    {
        var edgeCost = _simp.costs.RemoveFront();

        _simp.CollapseEdge(edgeCost);
    }