Пример #1
0
        private void OnDrawGizmosSelected()
        {
            if (m_chunks != null)
            {
                foreach (Chunk chunk in m_chunks.Values)
                {
                    if (ShowGeomBounds && chunk.IsFinalized())
                    {
                        Gizmos.color = Color.white;

                        if (chunk.Visible && chunk.BBoxVertices.Count > 0)
                        {
                            Gizmos.DrawWireCube(chunk.GeometryBounds.center, chunk.GeometryBounds.size);
                        }
                    }

                    if (ShowMapBounds)
                    {
                        ChunkClipmapItem item = m_clipmap[chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z];

                        int sizeX = EngineSettings.ChunkConfig.Size << VoxelLogScaleX;
                        int sizeY = EngineSettings.ChunkConfig.Size << VoxelLogScaleY;
                        int sizeZ = EngineSettings.ChunkConfig.Size << VoxelLogScaleZ;

                        if (!m_clipmap.IsInsideBounds(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z))
                        {
                            Gizmos.color = Color.red;
                            Gizmos.DrawWireCube(
                                new Vector3(
                                    chunk.Pos.X * sizeX + sizeX / 2,
                                    chunk.Pos.Y * sizeY + sizeY / 2 + 0.05f,
                                    chunk.Pos.Z * sizeZ + sizeZ / 2),
                                new Vector3(sizeX - 0.05f, 0, sizeZ - 0.05f)
                                );
                        }
                        else if (item.IsWithinVisibleRange)
                        {
                            Gizmos.color = Color.green;
                            Gizmos.DrawWireCube(
                                new Vector3(
                                    chunk.Pos.X * sizeX + sizeX / 2,
                                    chunk.Pos.Y * sizeY + sizeY / 2 + 0.05f,
                                    chunk.Pos.Z * sizeZ + sizeZ / 2),
                                new Vector3(sizeX - 0.05f, 0, sizeZ - 0.05f)
                                );
                        }
                        else// if (item.IsWithinCachedRange)
                        {
                            Gizmos.color = Color.yellow;
                            Gizmos.DrawWireCube(
                                new Vector3(
                                    chunk.Pos.X * sizeX + sizeX / 2,
                                    chunk.Pos.Y * sizeY + sizeY / 2 + 0.05f,
                                    chunk.Pos.Z * sizeZ + sizeZ / 2),
                                new Vector3(sizeX - 0.05f, 0, sizeZ - 0.05f)
                                );
                        }
                    }
                }
            }
        }
Пример #2
0
        protected override void OnProcessChunk(Chunk chunk)
        {
            bool removeChunk = false;

            // Chunk is within view frustum
            if (IsChunkInViewFrustum(chunk))
            {
                ChunkClipmapItem item = m_clipmap[chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z];

                // Chunk is too far away. Remove it
                if (!m_clipmap.IsInsideBounds(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z))
                {
                    removeChunk = true;
                }
                // Chunk is within visibilty range. Full update with geometry generation is possible
                else if (item.IsWithinVisibleRange)
                {
                    chunk.LOD             = item.LOD;
                    chunk.PossiblyVisible = true;

                    // If occlusion culling is enabled we need to register it
                    if (EngineSettings.CoreConfig.OcclusionCulling && Occlusion != null)
                    {
                        chunk.Visible = false;
                        if (chunk.IsFinalized())
                        {
                            Occlusion.RegisterEntity(chunk);
                        }
                    }
                    else
                    {
                        chunk.Visible = true;
                    }
                }
                // Chunk is within cached range. Full update except for geometry generation
                else// if (item.IsWithinCachedRange)
                {
                    chunk.LOD             = item.LOD;
                    chunk.PossiblyVisible = false;
                    chunk.Visible         = false;
                }
            }
            else
            {
                ChunkClipmapItem item = m_clipmap[chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z];

                // Chunk is not visible and too far away. Remote it
                if (!m_clipmap.IsInsideBounds(chunk.Pos.X, chunk.Pos.Y, chunk.Pos.Z))
                {
                    removeChunk = true;
                }
                // Chunk is not in viewfrustum but still within cached range
                else if (item.IsWithinCachedRange)
                {
                    chunk.LOD             = item.LOD;
                    chunk.PossiblyVisible = false;
                    chunk.Visible         = false;
                }
            }

            if (removeChunk)
            {
                chunk.Finish();
            }
        }