Exemple #1
0
 // Update is called once per frame
 void Update()
 {
     Debug.Log(counter);
     div20++;
     firstRun = false;
     if (counter < meshNum - 1 && firstRun)
     {
         float quality        = 0.95f;
         var   meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
         meshSimplifier.Initialize(GetComponent <MeshFilter> ().mesh);
         meshSimplifier.SimplifyMesh(quality);
         var destMesh = meshSimplifier.ToMesh();
         GetComponent <MeshFilter> ().mesh = destMesh;
         ms [counter] = destMesh;
         counter++;
     }
     else if (counter == meshNum - 1 && firstRun)
     {
         firstRun = false;
         increase = false;
         float quality        = 0.95f;
         var   meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
         meshSimplifier.Initialize(GetComponent <MeshFilter> ().mesh);
         meshSimplifier.SimplifyMesh(quality);
         var destMesh = meshSimplifier.ToMesh();
         GetComponent <MeshFilter> ().mesh = destMesh;
         ms [counter] = destMesh;
         counter--;
     }
     else if (!firstRun && div20 % 20 == 0)
     {
         GetComponent <MeshFilter> ().mesh = ms [counter];
         if (increase)
         {
             if (counter == meshNum - 1)
             {
                 increase = false;
                 counter--;
             }
             else
             {
                 counter++;
             }
         }
         else
         {
             if (counter == 0)
             {
                 increase = true;
                 counter++;
             }
             else
             {
                 counter--;
             }
         }
     }
 }
    void SimplifyMesh()
    {
        UnityEngine.Mesh sourceMesh = GetComponent <MeshFilter>().mesh;
        var meshSimplifier          = new UnityMeshSimplifier.MeshSimplifier();

        meshSimplifier.Initialize(sourceMesh);
        meshSimplifier.SimplifyMesh(quality);
        GetComponent <MeshFilter>().mesh = meshSimplifier.ToMesh();
    }
Exemple #3
0
 public void DecimateMesh()
 {
     if (!EditorApplication.isPlaying)
     {
         var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
         meshSimplifier.Initialize(_mesh);
         meshSimplifier.SimplifyMesh(_quality);
         var destMesh = meshSimplifier.ToMesh();
         _renderer.sharedMesh = destMesh;
     }
 }
    public void Simplify()
    {
        mesh.name = "Terrain Mesh";
        var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();

        meshSimplifier.Initialize(mesh);
        meshSimplifier.SimplifyMesh(quality);
        var destMesh = meshSimplifier.ToMesh();

        mesh = destMesh;
        meshFilter.sharedMesh = mesh;
    }
Exemple #5
0
        private static Mesh SimplifyMesh(Mesh mesh, float quality, SimplificationOptions options)
        {
            var meshSimplifier = new MeshSimplifier();

            meshSimplifier.SimplificationOptions = options;
            meshSimplifier.Initialize(mesh);
            meshSimplifier.SimplifyMesh(quality);

            var simplifiedMesh = meshSimplifier.ToMesh();

            simplifiedMesh.bindposes = mesh.bindposes;
            return(simplifiedMesh);
        }
Exemple #6
0
    public void SimplifyAllMeshes()
    {
        MeshFilter[] meshArray = GetComponentsInChildren <MeshFilter>();
        foreach (MeshFilter childMesh in meshArray)
        {
            var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
            meshSimplifier.Initialize(childMesh.sharedMesh);
            meshSimplifier.SimplifyMesh(meshQualityDivider);
            var destMesh = meshSimplifier.ToMesh();

            childMesh.mesh = destMesh;
        }
        Debug.Log("All Children Meshes Simplified");
    }
Exemple #7
0
    public void SimplifyMesh(float quality = 0.5f)
    {
        var meshFilter = GetComponent <MeshFilter>();

        if (meshFilter == null)
        {
            meshFilter = GetComponentInChildren <MeshFilter>();
        }
        var sourceMesh     = meshFilter.sharedMesh;
        var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();

        meshSimplifier.Initialize(sourceMesh);
        meshSimplifier.SimplifyMesh(quality);
        var destMesh = meshSimplifier.ToMesh();

        meshFilter.sharedMesh = destMesh;
    }
        private static Mesh SimplifyMesh(Mesh mesh, float quality, SimplificationOptions options)
        {
            var meshSimplifier = new MeshSimplifier();

            meshSimplifier.PreserveBorderEdges     = options.PreserveBorderEdges;
            meshSimplifier.PreserveUVSeamEdges     = options.PreserveUVSeamEdges;
            meshSimplifier.PreserveUVFoldoverEdges = options.PreserveUVFoldoverEdges;
            meshSimplifier.EnableSmartLink         = options.EnableSmartLink;
            meshSimplifier.VertexLinkDistance      = options.VertexLinkDistance;
            meshSimplifier.MaxIterationCount       = options.MaxIterationCount;
            meshSimplifier.Agressiveness           = options.Agressiveness;

            meshSimplifier.Initialize(mesh);
            meshSimplifier.SimplifyMesh(quality);

            var simplifiedMesh = meshSimplifier.ToMesh();

            simplifiedMesh.bindposes = mesh.bindposes;
            return(simplifiedMesh);
        }
Exemple #9
0
    static void SimplifyMesh()
    {
        // Get mesh
        GameObject          go         = Selection.activeGameObject;
        SkinnedMeshRenderer smRenderer = go.GetComponentInChildren <SkinnedMeshRenderer>();
        Mesh sourceMesh = smRenderer.sharedMesh;

        // Simplify
        float quality        = 0.7f;
        var   meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();

        meshSimplifier.Initialize(sourceMesh);
        meshSimplifier.SimplifyMesh(quality);
        var destMesh = meshSimplifier.ToMesh();

        destMesh.bindposes = sourceMesh.bindposes;

        destMesh.Optimize();

        // Save to asset
        string path     = AssetHelper.GetStoragePath("SimplifiedMeshes");
        string meshPath = AssetDatabase.GenerateUniqueAssetPath(path + "/" + go.name + "_LOD.asset");

        AssetHelper.SaveAsset(destMesh, meshPath);

        // Add the new mesh as sibling
        GameObject lodGo = new GameObject("New LOD");

        lodGo.transform.parent = go.transform;

        SkinnedMeshRenderer lodRenderer = lodGo.AddComponent <SkinnedMeshRenderer>();

        UnityEditorInternal.ComponentUtility.CopyComponent(smRenderer);
        UnityEditorInternal.ComponentUtility.PasteComponentValues(lodRenderer);

        lodRenderer.sharedMesh = destMesh;

        Debug.Log("Simplified mesh saved to " + meshPath);
    }
Exemple #10
0
    public void SimplifyMesh()
    {
        myMeshFilter = GetComponent <MeshFilter>();

        var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();

        meshSimplifier.Initialize(myMeshFilter.sharedMesh);
        meshSimplifier.SimplifyMesh(meshQualityDivider);
        var destMesh = meshSimplifier.ToMesh();

        myMeshFilter.sharedMesh = destMesh;
        myMeshFilter.sharedMesh.RecalculateBounds();

        /*
         *
         *
         *
         *
         * destMesh.name = baseMesh + "_optimized";
         *
         * string myPath = AssetDatabase.GetAssetPath(PrefabUtility.FindPrefabRoot(gameObject));
         * Debug.Log(myPath);
         *
         * AssetDatabase.CreateAsset(destMesh, myPath);
         * AssetDatabase.SaveAssets();
         * AssetDatabase.Refresh();
         *
         *
         *
         * var emptyPrefab = PrefabUtility.CreateEmptyPrefab(myPath + PrefabUtility.FindPrefabRoot(gameObject).name);
         *
         * PrefabUtility.ReplacePrefab(PrefabUtility.FindPrefabRoot(gameObject), emptyPrefab);
         */

        MeshInfo();
        Debug.Log("Mesh Simplified");
    }