コード例 #1
0
        private bool HasNonTransparentBlock(ChunkSectionCompactStorage storage, Vector3Int position, NeighborSections neighbor)
        {
            var target = storage;

            for (int i = 0; i < 3; i++)
            {
                if (position[i] < 0)
                {
                    target       = neighbor[i * 2];
                    position[i] += ChunkConstants.BlockEdgeWidthInSection;
                }
                else if (position[i] >= ChunkConstants.BlockEdgeWidthInSection)
                {
                    target       = neighbor[i * 2 + 1];
                    position[i] -= ChunkConstants.BlockEdgeWidthInSection;
                }
            }

            if (target == null)
            {
                return(false);
            }

            return(!_transparentBlockIds.Contains(target.Data[position.x, position.y, position.z].Id));
        }
コード例 #2
0
        public int CalculatePlanesCount(Vector3Int offset, ChunkSectionCompactStorage section, NeighborSections neighbor)
        {
            if (!HasNonTransparentBlock(section.Data[offset.x, offset.y, offset.z]))
            {
                return(0);
            }

            int count = 0;

            for (int i = 0; i < 6; i++)
            {
                if (HasNonTransparentBlock(section, offset + _normals[i], neighbor))
                {
                    continue;
                }
                count++;
            }

            return(count);
        }
コード例 #3
0
        public void CreateMesh(Vector3[] vertices, Vector3[] normals, Vector2[] uvs, int[] triangles, ref int planeIndex, Vector3Int offset, ChunkSectionCompactStorage section, NeighborSections neighbor)
        {
            if (!HasNonTransparentBlock(section.Data[offset.x, offset.y, offset.z]))
            {
                return;
            }

            for (int i = 0; i < 6; i++)
            {
                if (HasNonTransparentBlock(section, offset + _normals[i], neighbor))
                {
                    continue;
                }

                for (int n = planeIndex * 4, k = 0; k < 4; k++, n++)
                {
                    var v = _positions[i, k] * 0.5f;
                    v          += offset;
                    vertices[n] = v;
                    normals[n]  = _normals[i];
                    uvs[n]      = GetUVOffset((BlockFace)i, k);
                }

                for (int n = planeIndex * 6, k = 0; k < 6; k++, n++)
                {
                    triangles[n] = planeIndex * 4 + _indices[i, k];
                }

                planeIndex++;
            }
        }