Exemplo n.º 1
0
    public void generateNewTerrain()
    {
        var watch = System.Diagnostics.Stopwatch.StartNew();

        //Calculate density values
        mc.densityValues = calcualteNoiseValues3D();
        watch.Stop();
        Debug.Log("Density generation time: " + watch.ElapsedMilliseconds + " ms");

        watch.Reset();
        watch.Start();
        //For each point in terrain, except last, generate triangles
        for (int i = 0; i < TerrainSize - 1; i++)
        {
            for (int j = 0; j < TerrainSize - 1; j++)
            {
                for (int k = 0; k < TerrainSize - 1; k++)
                {
                    mc.march(i, j, k, vertexList, indexList);
                }
            }
        }
        Debug.Log("Number of vertex: " + vertexList.Count);
        //Split meshes and add it to game
        SplitMeshes();
        Camera.main.transform.position = new Vector3(0, 0, -TerrainSize - (TerrainSize / 2));
        watch.Stop();
        Debug.Log("Generation time: " + watch.ElapsedMilliseconds + " ms");
    }
Exemplo n.º 2
0
    public void process(Chunk chunk)
    {
        this.chunk = chunk;
        MarchingCube marchingCube = MarchingCube.getInstance();

        float[,,] density = chunk.getDensity();
        for (int x = 0; x < voxelCount; x++)
        {
            for (int y = 0; y < voxelCount; y++)
            {
                for (int z = 0; z < voxelCount; z++)
                {
                    Profiler.BeginSample("Marching:March");
                    marchingCube.march(x, y, z, density, this);
                    Profiler.EndSample();
                }
            }
        }
        Profiler.BeginSample("Proccessor:GenerateMesh");
        generateMesh();
        Profiler.EndSample();
        reset();
    }