Beispiel #1
0
        void generateNextMapDisplay()
        {
            GameObject go = (GameObject)Instantiate(displayPrefab);

            go.transform.SetParent(transform);
            go.transform.localPosition = transform.localPosition + Vector3.Scale(mapOffset(offsetIndex), vGenConfig.ChunkSize) * size;
            MapDisplay md = go.GetComponent <MapDisplay>();

            md.initialize(
                //geometryShader, color, sprite,
                null, //// <--fake mapChunkMeshing.takeDisplayBuffers(),
                vGenConfig);
        }
Beispiel #2
0
        void Update()
        {
            if ((Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) && Input.GetKey(KeyCode.Q))
            {
                createChunks = false;
                mapChunkMeshing.releaseSolidVoxels();
                releaseTemporaryBuffers();
                releaseDisplayBuffers();
                Application.Quit();
            }

            if (createChunks)
            {
                Stopwatch timer = new Stopwatch();

                mapChunkMeshing.callFaceCopyKernel();

                if (createUnityTerrain && !createSponge)
                {
                    timer.Start();

                    GameObject terrain = mapChunkMeshing.getTerrain();

                    terrain.transform.SetParent(transform);
                    terrain.transform.localPosition = transform.localPosition + mapOffset(offsetIndex) * 4 * 256 * size - new Vector3(0, 256 * 6 * size, 0);

                    Terrain t = terrain.GetComponent <Terrain>();

                    t.drawHeightmap = true;
                    t.enabled       = true;
                    t.ApplyDelayedHeightmapModification();
                    t.Flush();

                    terrains.Add(mapOffset(offsetIndex), t);

                    timer.Stop();
                    print("terrain ms: " + timer.ElapsedMilliseconds);
                }


                if (createMesh)
                {
                    timer.Start();

                    Mesh[] m = mapChunkMeshing.getMeshes();

                    for (int i = 0; i < m.Length; i++)
                    {
                        GameObject mesh = (GameObject)Instantiate(meshPrefab);

                        mesh.transform.SetParent(transform);
                        mesh.transform.localPosition          = transform.localPosition + mapOffset(offsetIndex) * 2 * 256 * size - new Vector3(0, 256 * 2 * size, 0);
                        mesh.GetComponent <MeshFilter>().mesh = m[i];
                        mesh.transform.localScale             = new Vector3(2 * size, 2 * size, 2 * size);
                    }

                    timer.Stop();
                    print("mesh ms: " + timer.ElapsedMilliseconds);
                }


                if (showVoxels)
                {
                    GameObject go = (GameObject)Instantiate(displayPrefab);

                    go.transform.SetParent(transform);
                    go.transform.localPosition = transform.localPosition + mapOffset(offsetIndex) * 256 * size;

                    MapDisplay md = go.GetComponent <MapDisplay>();

                    md.initialize(geometryShader, color, size, sprite, mapChunkMeshing.takeSolidVoxels());
                }
                else
                {
                    mapChunkMeshing.releaseSolidVoxels();
                }


                if (++offsetIndex < chunkMax * chunkMax && !createSponge)
                {
                    mapChunkCreation.callPerlinMapGenKernel(mapOffset(offsetIndex));
                    mapChunkMeshing.callFaceGenKernel();
                    mapChunkMeshing.callFaceSumKernel();
                }
                else
                {
                    createChunks = false;
                    releaseTemporaryBuffers();

                    if (createUnityTerrain && !createSponge)
                    {
                        foreach (Vector3 tpos in terrains.Keys)
                        {
                            Terrain t = terrains[tpos];
                            Terrain left = null, top = null, right = null, bottom = null;

                            terrains.TryGetValue(tpos - new Vector3(1, 0, 0), out left);
                            terrains.TryGetValue(tpos + new Vector3(1, 0, 0), out right);
                            terrains.TryGetValue(tpos - new Vector3(0, 0, 1), out top);
                            terrains.TryGetValue(tpos + new Vector3(0, 0, 1), out bottom);

                            t.SetNeighbors(left, top, right, bottom);
                        }
                    }
                }
            }
        }