コード例 #1
0
ファイル: UvPlane.cs プロジェクト: kennyzhong/VoxelEngine
        public             Vector2[] getMeshUvs(Vector2[] uvs)
        {
            TexturePos tilePos = this.texturePos;
            float      x       = TexturePos.ATLAS_TILE_SIZE * tilePos.x;
            float      y       = TexturePos.ATLAS_TILE_SIZE * tilePos.y;

            uvs[0] = new Vector2(x, y) + (this.uv0 * TexturePos.PIXEL_SIZE);
            uvs[1] = new Vector2(x, y + TexturePos.PIXEL_SIZE) + (this.uv1 * TexturePos.PIXEL_SIZE);
            uvs[2] = new Vector2(x + TexturePos.PIXEL_SIZE, y + TexturePos.PIXEL_SIZE) + (this.uv2 * TexturePos.PIXEL_SIZE);
            uvs[3] = new Vector2(x + TexturePos.PIXEL_SIZE, y) + (this.uv3 * TexturePos.PIXEL_SIZE);
            if (tilePos.rotation != 0)
            {
                UvHelper.rotateUVs(uvs, tilePos.rotation);
            }
            if (tilePos.mirrorFlags != 0)
            {
                if ((tilePos.mirrorFlags & 1) == 1)
                {
                    UvHelper.mirrorUvsX(uvs);
                }
                if ((tilePos.mirrorFlags >> 1) == 1)
                {
                    UvHelper.mirrorUvsY(uvs);
                }
            }
            return(uvs);
        }
コード例 #2
0
ファイル: UvPlane.cs プロジェクト: kennyzhong/VoxelEngine
 public UvPlane(TexturePos texturePos, Vector2 pos1, Vector2 pos2)
 {
     this.texturePos = texturePos;
     this.uv0        = pos1;
     this.uv1        = new Vector2(pos1.x, pos2.y);
     this.uv2        = pos2;
     this.uv3        = new Vector2(pos2.x, pos1.y);
 }
コード例 #3
0
ファイル: Block.cs プロジェクト: dynamiquel/Tasman
    public Block(int itemId, int[] drops, /*bool physics, bool flammable, int harvestLevel, double hardness, double lumiance,*/ int[,] texturePos)
    {
        ItemId = itemId;
        Drops  = drops;

        /*Physics = physics;
         * Flammable = flammable;
         * HarvestLevel = harvestLevel;
         * Hardness = hardness;
         * Lumiance = lumiance;*/
        TexturePos = new TexturePos(texturePos);
    }
コード例 #4
0
ファイル: UvPlane.cs プロジェクト: kennyzhong/VoxelEngine
 /// <summary>
 /// Start is 0 based, with 0,0 being on texture.  1, 1, 32, 32 is an entire tile.
 /// </summary>
 public UvPlane(TexturePos texturePos, int xStart, int yStart, int pixelCountX, int pixelCountY)
 {
     this.texturePos = texturePos;
     xStart--;
     yStart--;
     pixelCountX--;
     pixelCountY--;
     this.uv0 = new Vector2(xStart, yStart);
     this.uv1 = new Vector2(xStart, yStart + pixelCountY);
     this.uv2 = new Vector2(xStart + pixelCountX, yStart + pixelCountY);
     this.uv3 = new Vector2(xStart + pixelCountX, yStart);
 }
コード例 #5
0
        /// <summary>
        /// Returns the uvs for an item's front and back.
        /// </summary>
        private Vector2[] getUvs(TexturePos textPos)
        {
            float x = TexturePos.ATLAS_TILE_SIZE * textPos.x;
            float y = TexturePos.ATLAS_TILE_SIZE * textPos.y;

            Vector2[] uvArray = new Vector2[4];
            uvArray[0] = new Vector2(x, y);
            uvArray[1] = new Vector2(x, y + TexturePos.ATLAS_TILE_SIZE);
            uvArray[2] = new Vector2(x + TexturePos.ATLAS_TILE_SIZE, y + TexturePos.ATLAS_TILE_SIZE);
            uvArray[3] = new Vector2(x + TexturePos.ATLAS_TILE_SIZE, y);

            return(uvArray);
        }
コード例 #6
0
        public Vector2[] generateUVsFromTP(TexturePos tilePos)
        {
            float x = TexturePos.ATLAS_TILE_SIZE * tilePos.x;
            float y = TexturePos.ATLAS_TILE_SIZE * tilePos.y;

            this.allocatedUvArray[0] = new Vector2(x, y);
            this.allocatedUvArray[1] = new Vector2(x, y + TexturePos.ATLAS_TILE_SIZE);
            this.allocatedUvArray[2] = new Vector2(x + TexturePos.ATLAS_TILE_SIZE, y + TexturePos.ATLAS_TILE_SIZE);
            this.allocatedUvArray[3] = new Vector2(x + TexturePos.ATLAS_TILE_SIZE, y);
            if (tilePos.rotation != 0)
            {
                UvHelper.rotateUVs(this.allocatedUvArray, tilePos.rotation);
            }
            return(this.allocatedUvArray);
        }
コード例 #7
0
ファイル: UvPlane.cs プロジェクト: kennyzhong/VoxelEngine
        // Used by slabs and stairs.
        /// <summary>
        /// Attempts to create the uvs based on the CubeComponent's faces.
        /// </summary>
        public UvPlane(TexturePos pos, CubeComponent cubeComponent, Direction faceDirection)
        {
            this.texturePos = pos;

            Vector2 v0;
            Vector2 v1;

            if (faceDirection == Direction.NORTH)
            {
                v0 = new Vector2(32 - cubeComponent.pos.x, cubeComponent.neg.y);
                v1 = new Vector2(32 - cubeComponent.neg.x, cubeComponent.pos.y);
            }
            else if (faceDirection == Direction.EAST)
            {
                v0 = new Vector2(cubeComponent.neg.z, cubeComponent.neg.y);
                v1 = new Vector2(cubeComponent.pos.z, cubeComponent.pos.y);
            }
            else if (faceDirection == Direction.SOUTH)
            {
                v0 = new Vector2(cubeComponent.neg.x, cubeComponent.neg.y);
                v1 = new Vector2(cubeComponent.pos.x, cubeComponent.pos.y);
            }
            else if (faceDirection == Direction.WEST)
            {
                v0 = new Vector2(32 - cubeComponent.pos.z, cubeComponent.neg.y);
                v1 = new Vector2(32 - cubeComponent.neg.z, cubeComponent.pos.y);
            }
            else if (faceDirection == Direction.UP)
            {
                v0 = new Vector2(cubeComponent.neg.x, cubeComponent.neg.z);
                v1 = new Vector2(cubeComponent.pos.x, cubeComponent.pos.z);
            }
            else     // d == Direction.DOWN
            {
                v0 = new Vector2(cubeComponent.neg.x, cubeComponent.neg.z);
                v1 = new Vector2(cubeComponent.pos.x, cubeComponent.pos.z);
            }

            v1.x -= 1;
            v1.y -= 1;

            this.uv0 = v0;
            this.uv1 = new Vector2(v0.x, v1.y);
            this.uv2 = v1;
            this.uv3 = new Vector2(v1.x, v0.y);
        }
コード例 #8
0
        private void addSide(Block block, int meta, Vector3 pos, MeshBuilder meshBuilder, Direction direction, bool isRight)
        {
            float   x          = (direction.vector / 2).x;
            Vector3 lowVert    = pos + new Vector3(x, -0.5f, -0.5f);
            Vector3 middleVert = pos + new Vector3(x, -0.5f, 0.5f);
            Vector3 highVert   = pos + new Vector3(x, 0.5f, 0.5f);

            // Verts
            meshBuilder.addRawVertex(lowVert);
            meshBuilder.addRawVertex(middleVert);
            meshBuilder.addRawVertex(highVert);

            meshBuilder.addRawVertexColor(Color.black);
            meshBuilder.addRawVertexColor(Color.black);
            meshBuilder.addRawVertexColor(Color.black);

            // Tris
            int i = meshBuilder.getVerticeCount();

            if (isRight)
            {
                meshBuilder.addRawTriangle(i - 3);
                meshBuilder.addRawTriangle(i - 2);
                meshBuilder.addRawTriangle(i - 1);
            }
            else
            {
                meshBuilder.addRawTriangle(i - 1);
                meshBuilder.addRawTriangle(i - 2);
                meshBuilder.addRawTriangle(i - 3);
            }

            // UVs
            TexturePos tilePos = block.getTexturePos(direction, meta);
            float      x1      = TexturePos.ATLAS_TILE_SIZE * tilePos.x;
            float      y1      = TexturePos.ATLAS_TILE_SIZE * tilePos.y;

            int sampleDir = direction.index;

            meshBuilder.addRawUv(new Vector2(x1 + TexturePos.ATLAS_TILE_SIZE, y1));
            meshBuilder.addRawUv(new Vector2(x1, y1));
            meshBuilder.addRawUv(new Vector2(x1, y1 + TexturePos.ATLAS_TILE_SIZE));
        }
コード例 #9
0
        public override UvPlane getUvPlane(Block block, int meta, Direction faceDirection, CubeComponent cubeComponent)
        {
            TexturePos pos = block.getTexturePos(faceDirection, meta);

            if (faceDirection.axis == EnumAxis.X || faceDirection.axis == EnumAxis.Z)
            {
                return(new UvPlane(pos, 15, 1, 4, 32));
            }
            else
            {
                // This must be the top face.
                return(new UvPlane(
                           pos,
                           new Vector2(
                               BitHelper.getBit(meta, 6) ? 0 : 14,
                               BitHelper.getBit(meta, 4) ? 0 : 14),
                           new Vector2(
                               BitHelper.getBit(meta, 2) ? 31 : 17,
                               BitHelper.getBit(meta, 0) ? 31 : 17)));
            }
        }
コード例 #10
0
        public override TexturePos getTexturePos(Direction direction, int meta)
        {
            TexturePos core = new TexturePos(2, 1);

            if (meta == 0)  // X
            {
                if (direction.axis == EnumAxis.X)
                {
                    return(core);
                }
                else
                {
                    return(new TexturePos(1, 1, 90));
                }
            }
            else if (meta == 1)    // Y
            {
                if (direction.axis == EnumAxis.Y)
                {
                    return(core);
                }
            }
            else if (meta == 2)    // Z
            {
                if (direction.axis == EnumAxis.Z)
                {
                    return(core);
                }
                else if (direction.axis == EnumAxis.X)
                {
                    return(new TexturePos(1, 1, 90));
                }
            }
            else if (meta == 3)    // All core.
            {
                return(core);
            }
            return(new TexturePos(1, 1));
        }
コード例 #11
0
ファイル: Item.cs プロジェクト: kennyzhong/VoxelEngine
 public Item setTexture(int x, int y)
 {
     this.texturePos = new TexturePos(x, y);
     return(this);
 }
コード例 #12
0
        public Mesh renderItem3d(Item item, int meta)
        {
            MeshBuilder meshBuilder = RenderManager.getMeshBuilder();

            meshBuilder.setMaxLight();
            TexturePos textPos       = item.getItemTexturePos(meta);
            float      halfPixelSize = 0.015625f;

            // Add the front and back.
            float zOffset = halfPixelSize;

            meshBuilder.addQuad(
                new Vector3(0.5f, -0.5f, zOffset),  // Bottom right
                new Vector3(0.5f, 0.5f, zOffset),   // Top right
                new Vector3(-0.5f, 0.5f, zOffset),  // Top left
                new Vector3(-0.5f, -0.5f, zOffset), // Bottom left
                UvHelper.mirrorUvsX(this.getUvs(textPos)),
                0);
            meshBuilder.addQuad(
                new Vector3(-0.5f, -0.5f, -zOffset),
                new Vector3(-0.5f, 0.5f, -zOffset),
                new Vector3(0.5f, 0.5f, -zOffset),
                new Vector3(0.5f, -0.5f, -zOffset),
                this.getUvs(textPos),
                0);

            // Add the side pixels
            int       pixelStartX = textPos.x * 32;
            int       pixelStartY = textPos.y * 32;
            Texture2D atlas       = References.list.textureAtlas;

            Vector2[] pixelUvs = new Vector2[4];
            float     pixelOrginX, pixelOrginY;

            for (int x = 1; x < 32; x++)
            {
                for (int y = 1; y < 32; y++)
                {
                    if (!(atlas.GetPixel(pixelStartX + x, pixelStartY + y).a == 0))  // Solid pixel.
                    {
                        pixelOrginX = (x - 15) * (halfPixelSize * 2) - halfPixelSize;
                        pixelOrginY = (y - 15) * (halfPixelSize * 2) - halfPixelSize;

                        // Right/+X
                        if (this.func(atlas, pixelStartX + x, pixelStartY + y, 1, 0, ref pixelUvs))
                        {
                            meshBuilder.addQuad(
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY - halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY + halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY + halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY - halfPixelSize, 0 + halfPixelSize),
                                pixelUvs,
                                0);
                        }
                        // Left/-X
                        if (this.func(atlas, pixelStartX + x, pixelStartY + y, -1, 0, ref pixelUvs))
                        {
                            meshBuilder.addQuad(
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY - halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY + halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY + halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY - halfPixelSize, 0 - halfPixelSize),
                                pixelUvs,
                                0);
                        }
                        // Up/+Y
                        if (this.func(atlas, pixelStartX + x, pixelStartY + y, 0, 1, ref pixelUvs))
                        {
                            meshBuilder.addQuad(
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY + halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY + halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY + halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY + halfPixelSize, 0 - halfPixelSize),
                                pixelUvs,
                                0);
                        }
                        // Down/-Y
                        if (this.func(atlas, pixelStartX + x, pixelStartY + y, 0, -1, ref pixelUvs))
                        {
                            meshBuilder.addQuad(
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY - halfPixelSize, 0 + halfPixelSize),
                                new Vector3(pixelOrginX - halfPixelSize, pixelOrginY - halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY - halfPixelSize, 0 - halfPixelSize),
                                new Vector3(pixelOrginX + halfPixelSize, pixelOrginY - halfPixelSize, 0 + halfPixelSize),
                                pixelUvs,
                                0);
                        }
                    }
                }
            }

            return(meshBuilder.getGraphicMesh());
        }