Exemplo n.º 1
0
        protected override Mesh DoProcessing(MeshSemplifierData data)
        {
            MeshSimplifier simplifier = new MeshSimplifier(data.mesh);

            simplifier.SimplifyMesh(data.Force);
            return(simplifier.ToMesh());
        }
Exemplo n.º 2
0
        public void SimplifyMesh(Transform t, float mean)
        {
            MeshSimplifier meshSimplifier = new MeshSimplifier();
            float          diff           = t.GetComponent <MeshFilter>().mesh.triangles.Length / mean;
            float          quality        = 2 / diff;
            Mesh           originalMesh;

            if (t.GetComponent <MeshFilter>().mesh.triangles.Length / mean >= 3)
            {
                originalMesh = t.gameObject.GetComponent <MeshFilter>().mesh;
                meshSimplifier.Initialize(originalMesh);
                meshSimplifier.SimplifyMesh(quality);
                Mesh destMesh = meshSimplifier.ToMesh();
                t.gameObject.GetComponent <MeshFilter>().mesh = destMesh;
            }
        }
Exemplo n.º 3
0
    private void _generate_lod_versions(Mesh mesh, List <Mesh> list, int lod_count)
    {
        // The first instance in the LOD array is the default mesh.
        list.Add(mesh);

        // Initialize the mesh simplifier.
        MeshSimplifier simplifier = new MeshSimplifier();

        // Iterate through each LOD version.
        for (int i = 1; i < lod_count; i++)
        {
            // Initialize the mesh simplifier with the previous LOD version mesh.
            simplifier.Initialize(list[i - 1]);

            // Simplify by a given percentage (0.5 = 50% by default).
            simplifier.SimplifyMesh(0.5f);

            // Get the resulting mesh.
            Mesh destMesh = simplifier.ToMesh();

            // Set the resulting mesh to the current LOD version.
            list.Add(destMesh);
        }
    }
Exemplo n.º 4
0
    // before artwork starts, standardize all meshes to have the same number of triangles
    // * equal to the number of triangles in the least complex mesh
    public void PreprocessMeshes()
    {
        Mesh  conMesh      = constellationList.First().Value.GetComponentInChildren <MeshFilter>().sharedMesh;
        float minTriangles = conMesh.triangles.Length;

        // first, identify the mesh with the smallest number of triangles and get that number
        // float minTriangles = constellationList[0].GetComponent<MeshFilter>().sharedMesh.triangles.Length;

        foreach (GameObject c in constellationList.Values)
        {
            if (c.GetComponentInChildren <MeshFilter>().sharedMesh.triangles.Length < minTriangles)
            {
                minTriangles = c.GetComponentInChildren <MeshFilter>().sharedMesh.triangles.Length;
            }
        }

        // create Base folder for standardized meshes (1.0f quality)
        if (!Directory.Exists("Assets/Meshes/1.0"))
        {
            Directory.CreateDirectory("Assets/Meshes/1.0");
        }

        // next, standardize all meshes to have that number of triangles
        foreach (var c in constellationList)
        {
            float conTriangles = c.Value.GetComponentInChildren <MeshFilter>().sharedMesh.triangles.Length;
            float meshQuality  = minTriangles / conTriangles;

            // simplify the copy
            meshSimplifier.Initialize(c.Value.GetComponentInChildren <MeshFilter>().sharedMesh);
            meshSimplifier.SimplifyMesh(meshQuality);

            string conName = c.Value.name;

            // save base meshes to Assets/Meshes/1.0
            var savePathBase = "Assets/Meshes/1.0/" + conName + ".asset";
            Debug.Log("Saved base mesh to: " + savePathBase);
            AssetDatabase.CreateAsset(meshSimplifier.ToMesh(), savePathBase);

            // set constellation mesh to new base mesh
            c.Value.GetComponentInChildren <MeshFilter>().sharedMesh = AssetDatabase.LoadAssetAtPath <Mesh>(savePathBase);

            // Finally, create meshes at varying complexities so they don't have to be calculated in-game
            // NOTE: only creates new meshes if directory doesn't exist
            // >> i.e. if new constellations added, NEED TO RETHINK THIS
            for (float i = 0; i < 1.0; i += 0.1f)
            {
                // create folders for each complexity meshes
                if (!Directory.Exists("Assets/Meshes/" + i.ToString("F1")))
                {
                    Directory.CreateDirectory("Assets/Meshes/" + i.ToString("F1"));
                }

                // e.g. Assets/Meshes/0.1/Ursa.asset"
                var savePath = "Assets/Meshes/" + i.ToString("F1") + "/" + conName + ".asset";

                meshSimplifier.Initialize(c.Value.GetComponentInChildren <MeshFilter>().sharedMesh);
                meshSimplifier.SimplifyMesh(i);

                Debug.Log("Saved " + i.ToString("F1") + " quality mesh to: " + savePath);
                AssetDatabase.CreateAsset(meshSimplifier.ToMesh(), savePath);
            }
        }

        // save changes made
        AssetDatabase.SaveAssets();
    }