コード例 #1
0
 void TryAddFace(MeshBuilder activeBuilder, Vector3Int pos, int dir, ChunkSection c)
 {
     if (ShouldMakeFace(pos, dir, c))
     {
         activeBuilder.AddQuad(BlockMesh.Vertices, pos, dir, UVs);
     }
 }
コード例 #2
0
        public override void Generate(MeshBuilder activeBuilder, Vector3Int pos, ChunkSection c)
        {
            Vector3Int top      = pos - BlockMesh.Offset[BlockMesh.Up];
            BlockType  topBlock = (c != null) ? c.GetBlock(top.x, top.y, top.z) : BlockType.Air;

            Vector3[][] vertices;

            if (topBlock != Type)
            {
                vertices = FluidMesh.Vertices;
            }
            else
            {
                vertices = BlockMesh.Vertices;
            }

            TryAddFace(activeBuilder, pos, BlockMesh.East, c, vertices);
            TryAddFace(activeBuilder, pos, BlockMesh.West, c, vertices);

            TryAddFace(activeBuilder, pos, BlockMesh.South, c, vertices);
            TryAddFace(activeBuilder, pos, BlockMesh.North, c, vertices);

            TryAddFace(activeBuilder, pos, BlockMesh.Down, c, vertices);
            TryAddFace(activeBuilder, pos, BlockMesh.Up, c, vertices);
        }
コード例 #3
0
        public override void Generate(MeshBuilder activeBuilder, Vector3Int pos, ChunkSection c)
        {
            var verts = (Vector3[])mesh.vertices.Clone();

            for (int i = 0; i < verts.Length; i++)
            {
                verts[i] += pos;
            }
            activeBuilder.AddData(verts, mesh.normals, mesh.uv, mesh.triangles, mesh.triangles.Max() + 1);
        }
コード例 #4
0
        public override void Generate(MeshBuilder activeBuilder, Vector3Int pos, ChunkSection c)
        {
            TryAddFace(activeBuilder, pos, BlockMesh.Down, c);
            TryAddFace(activeBuilder, pos, BlockMesh.Up, c);

            TryAddFace(activeBuilder, pos, BlockMesh.East, c);
            TryAddFace(activeBuilder, pos, BlockMesh.West, c);

            TryAddFace(activeBuilder, pos, BlockMesh.South, c);
            TryAddFace(activeBuilder, pos, BlockMesh.North, c);
        }
コード例 #5
0
        public ChunkSection Copy()
        {
            ChunkSection other = (ChunkSection)MemberwiseClone();

            other.Meshed = Meshed;
            other.Pos    = new Vector3Int(Pos.x, Pos.y, Pos.z);
            other.blocks = (BlockType[])blocks.Clone();
            other.layers = (Layer[])layers.Clone();
            other.parent = parent;
            return(other);
        }
コード例 #6
0
        public Chunk(Vector2Int pos)
        {
            Pos       = pos;
            HeightMap = new HeightMap(pos);

            sections = new ChunkSection[Settings.ChunkSectionsPerChunk];
            for (int i = 0; i < sections.Length; i++)
            {
                sections[i] = new ChunkSection(new Vector3Int(Pos.x, i, Pos.y), this);
            }
        }
コード例 #7
0
 public void UpdateSection(ChunkSection section)
 {
     if (chunkRenderer.ContainsKey(section.Pos))
     {
         if (section.Meshed)
         {
             LoadedData data = new ChunkMeshBuilder(section).BuildChunk();
             chunkRenderer[section.Pos].CommitMesh(data);
         }
     }
 }
コード例 #8
0
        public static ChunkSection Decode(Chunk parent, Vector3Int pos, byte[] blockData, bool encoded)
        {
            ChunkSection c = new ChunkSection(pos, parent);

            try
            {
                if (!encoded)
                {
                    for (int i = 0; i < Settings.ChunkSectionVolume; i++)
                    {
                        c.blocks[i] = (BlockType)blockData[i];
                    }
                }
                else
                {
                    int index      = 0;
                    int blockIndex = 0;

                    while (blockIndex < Settings.ChunkSectionVolume)
                    {
                        BlockType type  = (BlockType)blockData[index++];
                        byte      count = blockData[index++];

                        for (int i = 0; i < count; i++)
                        {
                            c.blocks[blockIndex++] = type;
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Debug.Log("Error on Chunk Parse, Did not recieve all Data, Exception: " + e.Message);
                // TODO if ! assert, discard, request it again
                return(null);
            }

            for (int y = 0; y < Settings.ChunkSectionSize.y; y++)
            {
                for (int z = 0; z < Settings.ChunkSectionSize.z; z++)
                {
                    for (int x = 0; x < Settings.ChunkSectionSize.x; x++)
                    {
                        c.layers[y].Set(c.blocks[Util.ToLin(x, y, z)]);
                    }
                }
            }

            return(c);
        }
コード例 #9
0
        void Process(ChunkSection section)
        {
            Vector3Int pos = section.Pos;

            sectionsToMesh.Add(section);

            TryToLoad(new Vector3Int(pos.x - 1, pos.y, pos.z));
            TryToLoad(new Vector3Int(pos.x + 1, pos.y, pos.z));
            TryToLoad(new Vector3Int(pos.x, pos.y - 1, pos.z));
            TryToLoad(new Vector3Int(pos.x, pos.y + 1, pos.z));
            TryToLoad(new Vector3Int(pos.x, pos.y, pos.z - 1));
            TryToLoad(new Vector3Int(pos.x, pos.y, pos.z + 1));

            TryToLoad(pos);
        }
コード例 #10
0
        void TryAddFace(MeshBuilder activeBuilder, Vector3 pos, int dir, ChunkSection c, Vector3[][] vertices)
        {
            if (c == null)
            {
                activeBuilder.AddQuad(vertices, pos, dir, UVs);
                return;
            }

            Vector3Int adj      = (pos - BlockMesh.Offset[dir]).ToIntVec();
            BlockType  adjBlock = c.GetBlock(adj.x, adj.y, adj.z);

            if (Type != adjBlock && !BlockDictionary.Get(adjBlock).Opaque)
            {
                activeBuilder.AddQuad(vertices, pos, dir, UVs);
            }
        }
コード例 #11
0
        bool ShouldMakeFace(Vector3Int pos, int dir, ChunkSection c)
        {
            Vector3Int adj      = pos - BlockMesh.Offset[dir];
            BlockType  adjBlock = BlockType.Air;

            if (c != null)
            {
                adjBlock = c.GetBlock(adj.x, adj.y, adj.z);
            }

            if (Order == MeshOrder.Fluid && Type == adjBlock)
            {
                return(false);
            }

            if (!BlockDictionary.Get(adjBlock).Opaque)
            {
                return(true);
            }

            return(false);
        }