Ejemplo n.º 1
0
        private static EntityGeometry Cube(EntityData data, Texture2D propTexture)
        {
            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null)
            {
                if (textures.Length == 1)
                {
                    texture = new TextureRectangle(textures[0], propTexture);
                }
                else
                {
                    var cuboidTexture = new TextureCuboidWrapper();
                    for (var i = 0; i < 6; i++)
                    {
                        if (textures.Length > i)
                        {
                            cuboidTexture.AddSide((CuboidSide)(i + 1), new TextureRectangle(textures[i], propTexture));
                        }
                        else
                        {
                            cuboidTexture.AddSide((CuboidSide)(i + 1), DefaultTextureDefinition.Instance);
                        }
                    }
                    texture = cuboidTexture;
                }
            }

            var size = data.Size3;

            var geometry = new EntityGeometry
            {
                Vertices = CuboidComposer.Create(size.X, size.Y, size.Z, texture),
                Heights  = new[] { size.Y, size.Y, size.Y, size.Y },
                Size     = size
            };

            return(geometry);
        }
Ejemplo n.º 2
0
        private static EntityGeometry Walls(EntityData data, Texture2D propTexture)
        {
            var size = data.Size3;

            var textureDefs      = new ITextureDefintion[4];
            var textureDefsRects = new Rectangle[4];

            void setTexture(Rectangle rect, int dest)
            {
                if (data.tileTexture)
                {
                    if (dest % 2 == 1)
                    {
                        rect.Width = (int)(rect.Width * size.Z);
                    }
                    else
                    {
                        rect.Width = (int)(rect.Width * size.X);
                    }
                    rect.Height = (int)(rect.Height * size.Y);
                }
                textureDefs[dest]      = new TextureRectangle(rect, propTexture);
                textureDefsRects[dest] = rect;
            }

            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                if (textures.Length < 4)
                {
                    for (var i = 0; i < 4; i++)
                    {
                        setTexture(textures[0], i);
                    }
                }
                else
                {
                    for (var i = 0; i < 4; i++)
                    {
                        setTexture(textures[i], i);
                    }
                }
            }
            else
            {
                for (var i = 0; i < 4; i++)
                {
                    setTexture(propTexture.Bounds, i);
                }
            }

            var texture = new TextureCuboidWrapper();

            texture.AddSide(CuboidSide.Front, textureDefs[0]);
            texture.AddSide(CuboidSide.Left, textureDefs[1]);
            texture.AddSide(CuboidSide.Back, textureDefs[2]);
            texture.AddSide(CuboidSide.Right, textureDefs[3]);

            var vertices = CuboidComposer.Create(size.X, size.Y, size.Z, texture).ToList();

            // remove top and bottom vertices:
            vertices.RemoveRange(0, 6);
            vertices.RemoveRange(vertices.Count - 6, 6);

            // remove sides with 0, 0 textures:
            // shift the right vertices to th end of the list
            var right = vertices.Skip(12).Take(6).ToArray();

            vertices.RemoveRange(12, 6);
            vertices.AddRange(right);

            var removedOffset = 0;

            for (var i = 0; i < 4; i++)
            {
                if (textureDefsRects[i].Width == 0 && textureDefsRects[i].Height == 0)
                {
                    vertices.RemoveRange(removedOffset, 6);
                }
                else
                {
                    removedOffset += 6;
                }
            }

            var geometry = new EntityGeometry
            {
                Vertices = vertices.ToArray(),
                Heights  = new[] { size.Y, size.Y, size.Y, size.Y },
                Size     = size
            };

            return(geometry);
        }