예제 #1
0
        // Mesh chunk
        private GameObject CreateMeshObj(_16x256x16VoxChunk chunk, MeshingMaterial meshingMaterial, MeshingMaterial coliderMeshingMaterial)
        {
            Mesh mesh        = meshingMaterial.ToMesh();
            Mesh coliderMesh = coliderMeshingMaterial.ToMesh();

            return(CreateMeshObj(chunk, mesh, coliderMesh));
        }
예제 #2
0
        // 更新指定Chunk
        private void UpdateChunk(_16x256x16VoxChunk chunk)
        {
            if (!HasTheChunk(chunk))
            {
                return;
            }

            MeshingMaterial meshMat        = VoxTerrainMeshingTool.GreedyMeshing(chunk);
            MeshingMaterial coliderMeshMat = VoxTerrainMeshingTool.GreedyMeshing_ColiderMesh(chunk);
            Mesh            mesh           = meshMat.ToMesh();
            Mesh            coliderMesh    = coliderMeshMat.ToMesh();

            var oldMeshObj = GetMeshObj(chunk.UniqueID);

            DestroyImmediate(oldMeshObj);
            CreateMeshObj(chunk, mesh, coliderMesh);
        }
예제 #3
0
        // 区域更新:加载未加载区域内的chunks
        private IEnumerator LoadChunks()
        {
            List <_16x256x16VoxChunk> loadChunks = new List <_16x256x16VoxChunk>();

            foreach (var uniqueID in uniqueIDsInArea)
            {
                bool equal = false;

                foreach (var chunk in chunksInLastArea)
                {
                    if (uniqueID == chunk.UniqueID)
                    {
                        equal = true;
                    }
                }

                if (!equal) // 若uniqueID不在老区域内,则被加载
                {
                    _16x256x16VoxChunk loadChunk = wtAsset.GetChunk(uniqueID);
                    if (loadChunk == null)   // 若在wt文件中不存在,则重新创建一个
                    {
                        loadChunk = rule.GenerateVoxChunk(uniqueID);
                    }

                    loadChunks.Add(loadChunk);
                }
            }

            foreach (var loadChunk in loadChunks)
            {
                chunksInLastArea.Add(loadChunk);
            }

            if (meshingThread == null)
            {
                meshingThread = new MeshingThread();
            }

            meshingThread.MeshingChunk = loadChunks;
            meshingThread.Run();

            int cur = 0;

            while (cur < meshingThread.MeshingChunk.Count)
            {
                MeshingMaterial meshingMaterial        = meshingThread.MeshingMaterials[cur];
                MeshingMaterial coliderMeshingMaterial = meshingThread.ColiderMeshMaterials[cur];

                if (meshingMaterial == null || coliderMeshingMaterial == null)
                {
                    yield return(null);
                }
                else
                {
                    CreateMeshObj(meshingThread.MeshingChunk[cur], meshingMaterial, coliderMeshingMaterial);
                    cur++;
                }
            }

            IsMeshing = false;
        }