Ejemplo n.º 1
0
    public static void SpawnChunk(Vector3Int chunkPos, ISampler sampler, IPageController controller)
    {
        Vector3 worldPos       = VoxelConversions.ChunkCoordToWorld(chunkPos);
        double  voxelsPerMeter = SmoothVoxelSettings.voxelsPerMeter;

        SmoothVoxelBuilder builder = new SmoothVoxelBuilder(controller, chunkPos);

        builder.SetBlockTypes(controller.BlockTypes, null);
        builder.CalculateVariables(voxelsPerMeter, SmoothVoxelSettings.MeterSizeX, SmoothVoxelSettings.MeterSizeY, SmoothVoxelSettings.MeterSizeZ);
        builder.Generate(sampler);

        SmoothChunk chunk = GameObject.Instantiate(controller.ChunkPrefab).GetComponent <SmoothChunk>();

        chunk.name = string.Format("Chunk_{0}.{1}.{2}", chunkPos.x, chunkPos.y, chunkPos.z);
        chunk.Init(chunkPos, worldPos, null, controller, 1, builder);
    }
Ejemplo n.º 2
0
    public static void CreateChunk(Vector3Int chunkPos, ISampler sampler, IPageController controller)
    {
        Vector3 worldPos       = VoxelConversions.ChunkCoordToWorld(chunkPos);
        double  voxelsPerMeter = SmoothVoxelSettings.voxelsPerMeter;

        SmoothVoxelBuilder builder = new SmoothVoxelBuilder(controller, chunkPos);

        builder.SetBlockTypes(controller.BlockTypes, null);
        builder.CalculateVariables(voxelsPerMeter, SmoothVoxelSettings.MeterSizeX, SmoothVoxelSettings.MeterSizeY, SmoothVoxelSettings.MeterSizeZ);
        builder.Generate(sampler);

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

        MeshData meshData = builder.Render(false);

        watch.Stop();
        Debug.Log("Chunk Generated at " + watch.Elapsed);
        //if (meshData.vertices.Length == 0)
        //    return;

        Loom.QueueOnMainThread(() => {
            SmoothChunk chunk = GameObject.Instantiate(controller.ChunkPrefab).GetComponent <SmoothChunk>();
            chunk.name        = string.Format("Chunk_{0}.{1}.{2}", chunkPos.x, chunkPos.y, chunkPos.z);
            chunk.Init(chunkPos, worldPos, null, controller, 1, builder);
            chunk.Render(meshData, true);
            Loom.QueueAsyncTask("gen2", () => controller.AddChunk(chunkPos, chunk));

            /*if (!TerrainController.Instance.Chunks.ContainsKey(chunkPos))
             * {
             *  SmoothChunk chunk = GameObject.Instantiate(TerrainController.Instance.chunkPrefab).GetComponent<SmoothChunk>();
             *  chunk.name = string.Format("Chunk_{0}.{1}.{2}", chunkPos.x, chunkPos.y, chunkPos.z);
             *  chunk.Init(chunkPos, worldPos, null, controller, 1, builder);
             *  chunk.Render(meshData);
             *  TerrainController.Instance.AddChunk(chunkPos, chunk);
             * }*/
        });
    }