示例#1
0
        protected override void CreateGeometry()
        {
            var vertices = RectangleComposer.Create(1f, 1f);

            VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
            Geometry.AddVertices(vertices);
        }
示例#2
0
        private static EntityGeometry Billboard(EntityData data, Texture2D propTexture)
        {
            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                texture = new TextureRectangle(textures[0], propTexture);
            }

            var size     = data.Size2;
            var vertices = RectangleComposer.Create(1f, 1f, texture);

            VertexTransformer.Rotate(vertices, new Vector3(data.billboardTilt, 0, 0));
            VertexTransformer.Scale(vertices, new Vector3(size.X, size.Y, 1f));
            if (size.Y != 1f)
            {
                VertexTransformer.Offset(vertices, new Vector3(0, (size.Y - 1f) / 2f, 0));
            }

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

            return(geometry);
        }
示例#3
0
        private static EntityGeometry Plane(EntityData data, Texture2D propTexture)
        {
            var size = data.Size2;

            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                var rect = textures[0];
                if (data.tileTexture)
                {
                    rect.Width  = (int)(rect.Width * size.X);
                    rect.Height = (int)(rect.Height * size.Y);
                }
                texture = new TextureRectangle(rect, propTexture);
            }
            else
            {
                if (data.tileTexture)
                {
                    texture = new TextureRectangle(0, 0, size.X, size.Y);
                }
            }

            VertexPositionNormalTexture[] vertices;
            float[] heights;

            var floorOffset = -0.5f;

            if (data.elevation == null || data.elevation.Length < 4)
            {
                vertices = RectangleComposer.Create(size.X, size.Y, texture);
                VertexTransformer.Offset(vertices, new Vector3(0, floorOffset, 0));
                heights = new float[] { 0, 0, 0, 0 };
            }
            else
            {
                var halfWidth  = size.X / 2f;
                var halfHeight = size.Y / 2f;
                vertices = RectangleComposer.Create(new[]
                {
                    new Vector3(-halfWidth, data.elevation[0] + floorOffset, -halfHeight),
                    new Vector3(halfWidth, data.elevation[1] + floorOffset, -halfHeight),
                    new Vector3(-halfWidth, data.elevation[2] + floorOffset, halfHeight),
                    new Vector3(halfWidth, data.elevation[3] + floorOffset, halfHeight),
                }, texture);
                heights = new float[] { data.elevation[0], data.elevation[1], data.elevation[2], data.elevation[3] };
            }

            var geometry = new EntityGeometry
            {
                Vertices = vertices,
                Heights  = heights,
                Size     = new Vector3(size.X, 1, size.Y)
            };

            return(geometry);
        }
示例#4
0
 public void CreaseVerts()
 {
     for (int i = 0; i < this._Faces.Count; i++)
     {
         for (int j = i + 1; j < this._Faces.Count; j++)
         {
             List <int> SameVertices = new List <int>();
             List <int> F1Position   = new List <int>();
             List <int> F2Position   = new List <int>();
             for (int k = 0; k < this.Faces[i].Vertices.Count; k++)
             {
                 for (int l = 0; l < this.Faces[j].Vertices.Count; l++)
                 {
                     if (this.Faces[i].Vertices[k] == this.Faces[j].Vertices[l])
                     {
                         SameVertices.Add(this.Faces[i].Vertices[k]);
                         F1Position.Add(k);
                         F2Position.Add(l);
                     }
                 }
             }
             if (SameVertices.Count > 1)
             {
                 List <Vertex> Vertices1 = new List <Vertex>();
                 for (int k = 0; k < this.Faces[i].Vertices.Count; k++)
                 {
                     Vertices1.Add(this._Vertices[this.Faces[i].Vertices[k]]);
                 }
                 List <Vertex> Vertices2 = new List <Vertex>();
                 for (int l = 0; l < this.Faces[j].Vertices.Count; l++)
                 {
                     Vertices2.Add(this._Vertices[this.Faces[j].Vertices[l]]);
                 }
                 Vertex Normal1 = VertexTransformer.Normalize(VertexTransformer.CalculateNormal(Vertices1.ToArray()).ToVertex()).ToVertex();
                 Vertex Normal2 = VertexTransformer.Normalize(VertexTransformer.CalculateNormal(Vertices2.ToArray()).ToVertex()).ToVertex();
                 float  Angle   = VertexTransformer.Angle(Normal1, Normal2);
                 Angle *= (float)(180 / Math.PI);
                 if (Angle > 15)
                 {
                     for (int k = 0; k < SameVertices.Count; k++)
                     {
                         int Index = this._Vertices.Count;
                         this._Vertices.Add(this._Vertices[SameVertices[k]]);
                         if (this._Normals.Count > 0 && this.Faces[j].Normals.Count > 0)
                         {
                             this._Normals.Add(this._Normals[this._Faces[j].Normals[F2Position[k]]]);
                         }
                         this.Faces[j].Vertices[F2Position[k]] = Index;
                         if (this._Normals.Count > 0 && this.Faces[j].Normals.Count > 0)
                         {
                             this.Faces[j].Normals[F2Position[k]] = Index;
                         }
                     }
                 }
             }
         }
     }
 }
示例#5
0
        private static EntityGeometry HouseInside(EntityData data, Texture2D propTexture)
        {
            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                texture = new TextureRectangle(textures[0], propTexture);
            }

            var size        = data.Size3;
            var allVertices = new List <VertexPositionNormalTexture>();

            // back
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.X, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
                VertexTransformer.Offset(vertices, new Vector3(0, 0, -size.Z / 2f));
                allVertices.AddRange(vertices);
            }
            // left
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.Z, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, MathHelper.PiOver2, 0));
                VertexTransformer.Offset(vertices, new Vector3(-size.X / 2f, 0, 0));
                allVertices.AddRange(vertices);
            }
            // right
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.Z, size.Y, 1f));
                VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, -MathHelper.PiOver2, 0));
                VertexTransformer.Offset(vertices, new Vector3(size.X / 2f, 0, 0));
                allVertices.AddRange(vertices);
            }
            // floor
            {
                var vertices = RectangleComposer.Create(1f, 1f, texture);
                VertexTransformer.Scale(vertices, new Vector3(size.X, 1f, size.Z));
                VertexTransformer.Offset(vertices, new Vector3(0, -0.499f, 0)); // do not put 0.5 to not interfer with floors
                allVertices.AddRange(vertices);
            }

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

            return(geometry);
        }
示例#6
0
        protected override void CreateGeometry()
        {
            if (_fieldSize == Vector2.One)
            {
                var entityGeometry = EntityGeometry.Create(_data, Texture);
                _heights = entityGeometry.Heights;
                Size     = entityGeometry.Size;
                RotateSize();
                Geometry.AddVertices(entityGeometry.Vertices);
            }
            else
            {
                var entityGeometry = EntityGeometry.Create(_data, Texture);
                _heights = entityGeometry.Heights;

                Size = new Vector3(_steps.X * _fieldSize.X - (_steps.X - 1f) + (entityGeometry.Size.X - 1f),
                                   entityGeometry.Size.Y,
                                   _steps.Y * _fieldSize.Y - (_steps.Y - 1f) + (entityGeometry.Size.Z - 1f));

                RotateSize();

                var vertices = entityGeometry.Vertices;
                // center the field on the main position
                VertexTransformer.Offset(vertices, -new Vector3((_fieldSize.X - 1f) * _steps.X / 2f, 0,
                                                                (_fieldSize.Y - 1f) * _steps.Y / 2f));

                var indexOffset = 0;
                var vLength     = vertices.Length;

                for (var z = 0; z < _fieldSize.Y; z++)
                {
                    for (var x = 0; x < _fieldSize.X; x++)
                    {
                        // optimize field geometry for creation time
                        // do not index vertices
                        Geometry.AddIndexedVertices(vertices);
                        var indices = new int[vLength];
                        for (var i = 0; i < vLength; i++)
                        {
                            indices[i] = indexOffset + i;
                        }
                        Geometry.AddIndices(indices);
                        indices      = null;
                        indexOffset += vLength;

                        VertexTransformer.Offset(vertices, new Vector3(_steps.X, 0, 0));
                    }
                    VertexTransformer.Offset(vertices, new Vector3(-_fieldSize.X * _steps.X, 0, _steps.Y));
                }
            }
        }
示例#7
0
        protected override void CreateGeometry()
        {
            Geometry.AddVertices(CuboidComposer.Create(0.2f, 10f, 0.2f,
                                                       new GeometryTextureRectangle(new Rectangle(0, 4, 4, 4), _texture)));

            var sideTexture1  = new GeometryTextureRectangle(new Rectangle(0, 0, 8, 4), _texture);
            var sideTexture2  = new GeometryTextureRectangle(new Rectangle(12, 4, 4, 4), _texture);
            var bottomTexture = new GeometryTextureRectangle(new Rectangle(8, 0, 8, 4), _texture);
            var cuboidTexture = new GeometryTextureCuboidWrapper();

            cuboidTexture.AddSide(new[] { CuboidSide.Left, CuboidSide.Right }, sideTexture2);
            cuboidTexture.AddSide(new[] { CuboidSide.Front, CuboidSide.Back, CuboidSide.Top }, sideTexture1);
            cuboidTexture.AddSide(new[] { CuboidSide.Bottom }, bottomTexture);

            var topPart = CuboidComposer.Create(0.8f, 0.4f, 0.4f, cuboidTexture);

            VertexTransformer.Offset(topPart, new Vector3(0.25f, 5f, 0f));
            Geometry.AddVertices(topPart);
        }
示例#8
0
 public void RecalculateNormals()
 {
     this._Normals = new List <Vertex>();
     List <Vertex>[] Normals = new List <Vertex> [_Vertices.Count];
     for (int i = 0; i < this._Faces.Count; i++)
     {
         List <Vertex> Vertices = new List <Vertex>();
         for (int j = 0; j < this._Faces[i].Vertices.Count; j++)
         {
             Vertices.Add(this._Vertices[Faces[i].Vertices[j]]);
         }
         Vertex Normal = (VertexTransformer.Normalize(VertexTransformer.CalculateNormal(Vertices.ToArray()).ToVertex())).ToVertex();
         Faces[i].Normals.Clear();
         for (int j = 0; j < this._Faces[i].Vertices.Count; j++)
         {
             if (Normals[Faces[i].Vertices[j]] == null)
             {
                 Normals[Faces[i].Vertices[j]] = new List <Vertex>();
             }
             Normals[Faces[i].Vertices[j]].Add(Normal);
             Faces[i].Normals.Add(j);
         }
     }
     for (int i = 0; i < _Vertices.Count; i++)
     {
         if (Normals[i] == null)
         {
             this._Normals.Add(new Vertex(1, 0, 0));
         }
         else
         {
             this._Normals.Add(VertexTransformer.Average(Normals[i].ToArray()).ToVertex());
         }
     }
     for (int i = 0; i < this._Faces.Count; i++)
     {
         for (int j = 0; j < this._Faces[i].Vertices.Count; j++)
         {
             this._Faces[i].Normals[j] = this._Faces[i].Vertices[j];
         }
     }
 }
示例#9
0
        public static VertexInput[] Create(float radius, float height, int edgeCount,
                                           IGeometryTextureDefintion sideTexture, IGeometryTextureDefintion endTexture)
        {
            var vertices = new List <VertexInput>();

            var sides = TubeComposer.Create(radius, height, edgeCount, sideTexture);
            var end1  = CircleComposer.Create(radius, edgeCount, endTexture);
            var end2  = CircleComposer.Create(radius, edgeCount, endTexture);

            VertexTransformer.Rotate(end1, new Vector3(0, 0, MathHelper.PiOver2));
            VertexTransformer.Offset(end1, new Vector3(height / 2f, 0, 0));
            VertexTransformer.Rotate(end2, new Vector3(0, 0, MathHelper.PiOver2));
            VertexTransformer.Offset(end2, new Vector3(-height / 2f, 0, 0));

            vertices.AddRange(sides);
            vertices.AddRange(end1);
            vertices.AddRange(end2);

            return(vertices.ToArray());
        }
示例#10
0
        private static EntityGeometry Wall(EntityData data, Texture2D propTexture)
        {
            var size = data.Size3;

            ITextureDefintion texture = DefaultTextureDefinition.Instance;
            var textures = data.Textures;

            if (textures != null && textures.Length > 0)
            {
                var rect = textures[0];
                if (data.tileTexture)
                {
                    rect.Width  = (int)(rect.Width * size.X);
                    rect.Height = (int)(rect.Height * size.Y);
                }
                texture = new TextureRectangle(rect, propTexture);
            }
            else
            {
                if (data.tileTexture)
                {
                    texture = new TextureRectangle(0, 0, size.X, size.Y);
                }
            }

            var vertices = RectangleComposer.Create(size.X, size.Y, texture);

            VertexTransformer.Rotate(vertices, new Vector3(MathHelper.PiOver2, 0, 0));
            VertexTransformer.Offset(vertices, new Vector3(0, 0, 0.5f));

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

            return(geometry);
        }