예제 #1
0
        public static void PrepareTexture(Chunk chunk, ref Vector3Int localPos, Vector2[] data, Direction direction, TextureCollection textureCollection, bool rotated)
        {
            Rect texture  = textureCollection.GetTexture(chunk, ref localPos, direction);
            bool backface = DirectionUtils.IsBackface(direction);

            PrepareTexture(data, ref texture, rotated, backface);
        }
예제 #2
0
        public static void PrepareTexture(Chunk chunk, Vector3Int localPos, VertexData[] vertexData, Direction direction, TextureCollection textureCollection)
        {
            Rect texture = textureCollection.GetTexture(chunk, localPos, direction);

            vertexData[0].UV = new Vector2(texture.x + texture.width, texture.y);
            vertexData[1].UV = new Vector2(texture.x + texture.width, texture.y + texture.height);
            vertexData[2].UV = new Vector2(texture.x, texture.y + texture.height);
            vertexData[3].UV = new Vector2(texture.x, texture.y);
        }
예제 #3
0
    public static void BuildTexture(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, TextureCollection textureCollection)
    {
        Rect texture = textureCollection.GetTexture(chunk, pos, direction);

        Vector2[] UVs = new Vector2[4];

        UVs[0] = new Vector2(texture.x + texture.width, texture.y);
        UVs[1] = new Vector2(texture.x + texture.width, texture.y + texture.height);
        UVs[2] = new Vector2(texture.x, texture.y + texture.height);
        UVs[3] = new Vector2(texture.x, texture.y);

        meshData.uv.AddRange(UVs);
    }
예제 #4
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount = meshData.vertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);

            if (uvs.Length == 0)
            {
                meshData.uv.Add(new Vector2(0, 0));
            }

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            Rect texture;
            if (collection != null)
            {
                texture = collection.GetTexture(chunk, pos, Direction.down);
            }
            else
            {
                texture = new Rect();
            }


            foreach (var uv in uvs)
            {
                meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
            }
        }

        foreach (var tri in tris)
        {
            meshData.AddTriangle(tri + initialVertCount);
        }
    }
예제 #5
0
        public static void PrepareTexture(Chunk chunk, ref Vector3Int localPos, Vector2[] data, Direction direction, TextureCollection textureCollection, bool rotated)
        {
            Rect texture = textureCollection.GetTexture(chunk, ref localPos, direction);

            if (!rotated)
            {
                data[0] = new Vector2(texture.x, texture.y);
                data[1] = new Vector2(texture.x, texture.y + texture.height);
                data[2] = new Vector2(texture.x + texture.width, texture.y + texture.height);
                data[3] = new Vector2(texture.x + texture.width, texture.y);
            }
            else
            {
                data[0] = new Vector2(texture.x, texture.y + texture.height);
                data[1] = new Vector2(texture.x + texture.width, texture.y + texture.height);
                data[2] = new Vector2(texture.x + texture.width, texture.y);
                data[3] = new Vector2(texture.x, texture.y);
            }
        }
예제 #6
0
    public static void BuildTexture(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction, TextureCollection textureCollection)
    {
        Rect texture = textureCollection.GetTexture(chunk, pos, direction);
        Vector2[] UVs = new Vector2[4];

        UVs[0] = new Vector2(texture.x + texture.width, texture.y);
        UVs[1] = new Vector2(texture.x + texture.width, texture.y + texture.height);
        UVs[2] = new Vector2(texture.x, texture.y + texture.height);
        UVs[3] = new Vector2(texture.x, texture.y);

        meshData.uv.AddRange(UVs);
    }
예제 #7
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount    = meshData.vertices.Count;
        int colInitialVertCount = meshData.colVertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);
            meshData.colVertices.Add(vert + (Vector3)pos);

            if (uvs.Length == 0)
            {
                meshData.uv.Add(new Vector2(0, 0));
            }

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            Rect texture;
            if (collection != null)
            {
                texture = collection.GetTexture(chunk, pos, Direction.down);
            }
            else
            {
                texture = new Rect();
            }


            foreach (var uv in uvs)
            {
                meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.up)).controller.IsSolid(Direction.down))
        {
            foreach (var tri in trisUp)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.down)).controller.IsSolid(Direction.up))
        {
            foreach (var tri in trisDown)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.north)).controller.IsSolid(Direction.south))
        {
            foreach (var tri in trisNorth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.south)).controller.IsSolid(Direction.north))
        {
            foreach (var tri in trisSouth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.west)).controller.IsSolid(Direction.east))
        {
            foreach (var tri in trisWest)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.east)).controller.IsSolid(Direction.west))
        {
            foreach (var tri in trisEast)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }
        foreach (var tri in trisOther)
        {
            meshData.AddTriangle(tri + initialVertCount);
            meshData.colTriangles.Add(tri + colInitialVertCount);
        }
    }