Ejemplo n.º 1
0
    void Benchmark()
    {
        Chunks.Chunk chunk = new Chunks.Chunk();
        chunk.Position = new Vector3Int(0, 0, 0);
        chunk.LOD      = 0;
        SE.MC.Algorithm.BenchmarkResult totals = new SE.MC.Algorithm.BenchmarkResult();

        for (int i = 0; i < BenchmarkTrials; i++)
        {
            chunk.Position.x += Resolution;
            chunk.LODCode     = 0;         //(chunk.LODCode + 1) % 64;
            SE.MC.Algorithm.BenchmarkResult result = SE.MC.Algorithm.PolygonizeAreaBenchmarked(BenchmarkResolution, UtilFuncs.Sample, chunk, testData);
            totals.createVerticesMs += result.createVerticesMs;
            totals.fillDataMs       += result.fillDataMs;
            totals.transitionCellMs += result.transitionCellMs;
            totals.triangulateMs    += result.triangulateMs;
        }

        totals.createVerticesMs /= (float)BenchmarkTrials;
        totals.fillDataMs       /= (float)BenchmarkTrials;
        totals.transitionCellMs /= (float)BenchmarkTrials;
        totals.triangulateMs    /= (float)BenchmarkTrials;

        string result2 = "Done benchmark. Res: " + BenchmarkResolution + ", Trials: " + BenchmarkTrials + ", Average FillData ms: " + totals.fillDataMs + ", CreateVertices ms: " + totals.createVerticesMs + ", Triangulate ms: " + totals.triangulateMs + ", TransitionCell ms: " + totals.transitionCellMs + " (Total: " + (totals.transitionCellMs + totals.triangulateMs + totals.createVerticesMs + totals.fillDataMs) + "ms. )";

        Debug.Log(result2);
        UConsole.Print(result2);
    }
Ejemplo n.º 2
0
    void CreateTestChunk(bool decked)
    {
        if (testChunk != null)
        {
            Object.Destroy(testChunk.UnityObject);
        }

        Chunks.Chunk chunk = new Chunks.Chunk();
        chunk.Position = new Vector3Int(0, 0, 0);
        //chunk.LOD = 1;
        chunk.LODCode = 0;         //3 + 16 + 32;

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        UnityEngine.Profiling.Profiler.BeginSample("PolyganizeArea");

        if (decked)
        {
            SE.MC.Algorithm.PolygonizeAreaDecked(Resolution, chunk, testData);
        }
        else
        {
            SE.MC.Algorithm.PolygonizeArea(Resolution, UtilFuncs.Sample, chunk);
        }

        UnityEngine.Profiling.Profiler.EndSample();

        sw.Stop();
        Debug.Log("Time to mesh " + Resolution + "^3 chunk: " + sw.Elapsed.Milliseconds + " ms");

        testChunk = chunk;
        Meshify(chunk);
    }
Ejemplo n.º 3
0
    GameObject Meshify(Chunks.Chunk chunk)
    {
        GameObject clone = Object.Instantiate(ChunkPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        Color      c     = UtilFuncs.SinColor(chunk.LOD * 3f);

        clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f);
        clone.GetComponent <MeshRenderer>().material.SetInt("_LOD", chunk.LOD);
        clone.GetComponent <MeshRenderer>().material.SetVector("_ChunkPosition", new Vector4(chunk.Position.x, chunk.Position.y, chunk.Position.z));

        clone.name = "BENCHMARK test Node " + chunk.Key + ", LOD " + chunk.LOD;

        MeshFilter mf = clone.GetComponent <MeshFilter>();

        mf.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
        mf.mesh.SetVertices(chunk.Vertices);
        mf.mesh.SetNormals(chunk.Normals);
        //mf.mesh.SetUVs(0, chunk.LOD1Vertices);
        //mf.mesh.SetUVs(1, chunk.LOD1Normals);
        mf.mesh.triangles = chunk.Triangles;

        clone.GetComponent <Transform>().SetPositionAndRotation(chunk.Position, Quaternion.identity);
        clone.GetComponent <Transform>().localScale = Vector3.one * ((float)MinimumChunkSize / (float)Resolution) * Mathf.Pow(2, chunk.LOD);
        chunk.UnityObject = clone;
        return(clone);
    }