コード例 #1
0
        // ---------------------------------------------------------------------------------------------
        // create single voxel
        // ---------------------------------------------------------------------------------------------
        private VoxelUtils.VoxelChunk createVoxelChunk(VoxelUtils.VoxelVector3Int p, int w, int h, int d)
        {
            GameObject cube = GameObject.Instantiate(_prefabChunk);

            cube.transform.SetParent(_voxelChunkContainer);
            _iCount++;
            cube.name = "cube_" + _iCount.ToString();

            float width  = w * VoxelUtils.CHUNK_SIZE;
            float height = h * VoxelUtils.CHUNK_SIZE;
            float depth  = d * VoxelUtils.CHUNK_SIZE;

            Vector3 pos = new Vector3((p.x * VoxelUtils.CHUNK_SIZE) + (width / 2f), (p.y * VoxelUtils.CHUNK_SIZE) + (height / 2f), (p.z * VoxelUtils.CHUNK_SIZE) + (depth / 2f));

            Bounds b = new Bounds();

            b.size   = new Vector3(width, height, depth);
            b.center = pos;

            VoxelUtils.VoxelChunk vs = new VoxelUtils.VoxelChunk();
            vs.go      = cube;
            vs.goPos   = pos;
            vs.pos     = p;
            vs.size    = new VoxelUtils.VoxelVector3Int(w, h, d);
            vs.bounds  = b;           //coll.bounds;
            vs.corners = VoxelUtils.createVoxelCorners(p, w, h, d);

            return(vs);
        }
コード例 #2
0
        // ---------------------------------------------------------------------------------------------
        public void reset()
        {
            foreach (Transform child in _voxelChunkContainer)
            {
                GameObject.Destroy(child.gameObject);
            }

            _aVoxelChunks.Clear();
            _iCount = 0;

            // create the full chunk voxel
            VoxelUtils.VoxelVector3Int pos = VoxelUtils.convertVector3ToVoxelVector3Int(Vector3.zero);
            VoxelUtils.VoxelChunk      vs  = createVoxelChunk(pos, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS, VoxelUtils.MAX_CHUNK_UNITS);
            _aVoxelChunks.Add(vs);
            setVoxelChunkMesh(_aVoxelChunks [0]);
        }
コード例 #3
0
        // ---------------------------------------------------------------------------------------------
        //
        // ---------------------------------------------------------------------------------------------
        private VoxelUtils.VoxelChunk createCutVoxelChunk(VoxelUtils.VoxelVector3Int p, int w, int h, int d)
        {
            float width  = w * VoxelUtils.CHUNK_SIZE;
            float height = h * VoxelUtils.CHUNK_SIZE;
            float depth  = d * VoxelUtils.CHUNK_SIZE;

            Vector3 pos = new Vector3((p.x * VoxelUtils.CHUNK_SIZE) + (width / 2f), (p.y * VoxelUtils.CHUNK_SIZE) + (height / 2f), (p.z * VoxelUtils.CHUNK_SIZE) + (depth / 2f));

            Bounds b = new Bounds();              //coll.bounds;

            b.size   = new Vector3(width - VoxelUtils.CHUNK_SIZE, height - VoxelUtils.CHUNK_SIZE, depth - VoxelUtils.CHUNK_SIZE);
            b.center = pos;

            VoxelUtils.VoxelChunk vs = new VoxelUtils.VoxelChunk();
            vs.pos     = p;
            vs.size    = new VoxelUtils.VoxelVector3Int(w, h, d);
            vs.bounds  = b;            //coll.bounds;
            vs.corners = VoxelUtils.createVoxelCorners(p, w, h, d);

            return(vs);
        }
コード例 #4
0
        // ---------------------------------------------------------------------------------------------
        // cut a hole!
        // ---------------------------------------------------------------------------------------------
        public bool subtractChunk(Vector3 v3Pos, Vector3 v3Size)
        {
            bool success = true;

            //float timer = Time.realtimeSinceStartup;

            VoxelUtils.VoxelVector3Int pos   = VoxelUtils.convertVector3ToVoxelVector3Int(v3Pos);
            VoxelUtils.VoxelChunk      vsCut = createCutVoxelChunk(pos, (int)v3Size.x, (int)v3Size.y, (int)v3Size.z);

            // does the new voxel intersect with any existing voxels?
            bool splittage = splitVoxels(vsCut);
            int  loops     = 0;

            while (splittage && loops < 1000)
            {
                splittage = splitVoxels(vsCut);
                loops++;
            }

            if (loops >= 1000)
            {
                Debug.LogWarning("looks like we got ourselves an endless loop here!");
                success = false;
            }
            else
            {
                int i, len = _aVoxelChunks.Count;
                for (i = 0; i < len; ++i)
                {
                    setVoxelChunkMesh(_aVoxelChunks [i]);
                }
            }

            //Debug.Log ("Time to create chunk(s): " + (Time.realtimeSinceStartup - timer).ToString ());

            return(success);
        }