Esempio 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);
    }
Esempio n. 2
0
    public void UpdateLOD()
    {
        return;

        Loom.QueueAsyncTask("LODupdate", () => {
            if (canUpdateForLOD)
            {
                Vector3 worldPos      = VoxelConversions.ChunkCoordToWorld(chunkPosition);
                float distance        = Vector3.Distance(worldPos, TerrainController.Instance.LODtarget);
                float radius          = SmoothVoxelSettings.radius * SmoothVoxelSettings.MeterSizeX;
                double voxelsPerMeter = SmoothVoxelSettings.voxelsPerMeter;
                int LODlevel          = 1;
                if (distance > (radius / 10f) && distance < (radius / 10f) * 5)
                {
                    voxelsPerMeter /= 2;
                    LODlevel        = 2;
                }
                else if (distance > (radius / 10f) * 5 && distance < radius)
                {
                    voxelsPerMeter /= 4;
                    LODlevel        = 3;
                }

                /*else if (distance > (radius / 10f) * 6 && distance < radius) {
                 *  voxelsPerMeter /= 10;
                 *  LODlevel = 4;
                 * }*/
                else if (distance >= radius)
                {
                    return;
                }

                if (LODlevel != oldLODlevel)
                {
                    oldLODlevel = LODlevel;
                    builderInstance.CalculateVariables(voxelsPerMeter, SmoothVoxelSettings.MeterSizeX, SmoothVoxelSettings.MeterSizeY, SmoothVoxelSettings.MeterSizeZ);
                    builderInstance.Generate(surfaceModule,
                                             SmoothVoxelSettings.seed,
                                             SmoothVoxelSettings.enableCaves && (LODlevel <= 2),
                                             SmoothVoxelSettings.amplitude,
                                             SmoothVoxelSettings.caveDensity,
                                             SmoothVoxelSettings.grassOffset);
                    Render(false);
                }
            }
        });
    }
Esempio n. 3
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);
             * }*/
        });
    }