Esempio n. 1
0
        private QuadMesh GenerateTerrain(Vector2 center, Vector2 dimensions)
        {
            var quadMesh = QuadMesh.CreatePlane(dimensions, new IntVector2(SubdivisionsX, SubdivisionsY));

            quadMesh.ForEachQuad((quad, index) => {
                float height = GenerateHeight(center, quad.vertices[0].x, quad.vertices[0].z);

                if (height == 0.0f)
                {
                    return;
                }
                quadMesh.Extrude(index, quad.Normal, height);
            });

            quadMesh.Optimize();
            return(quadMesh);
        }
Esempio n. 2
0
        private Mesh GenerateTerrain()
        {
            var quadMesh = QuadMesh.CreatePlane(Dimensions, new IntVector2(SubdivisionsX, SubdivisionsY));

            quadMesh.ForEachQuad((quad, index) => {
                float height = GenerateHeight(quad.vertices[0].x, quad.vertices[0].z);

                if (height == 0.0f)
                {
                    return;
                }
                quadMesh.Extrude(index, quad.Normal, height);
            });

            quadMesh.Optimize();
            return(quadMesh.ToMesh(!FlatShading, ConvertToTris));
        }
Esempio n. 3
0
        public static QuadMesh CreatePlane(Vector2 dimensions, IntVector2 faces)
        {
            QuadMesh mesh = new QuadMesh();

            IntVector2 numVertices = faces + IntVector2.one;

            Vector2    step  = dimensions / faces;
            IntVector2 index = IntVector2.zero;

            // vertices
            for (index.x = 0; index.x < numVertices.x; ++index.x)
            {
                for (index.y = 0; index.y < numVertices.y; ++index.y)
                {
                    Vector2 position = index * step;

                    mesh.Vertices.Add(new Vector3(position[0], 0.0f, position[1]));
                    mesh.UVs.Add(position.ElementwiseDivide(dimensions));
                }
            }

            // indices
            for (index.x = 0; index.x < faces.x; ++index.x)
            {
                for (index.y = 0; index.y < faces.y; ++index.y)
                {
                    IntVector4 quad = IntVector4.zero;
                    quad[0] = LinearizeIndex(index, numVertices);
                    quad[1] = LinearizeIndex(index + new IntVector2(1, 0), numVertices);
                    quad[2] = LinearizeIndex(index + new IntVector2(1, 1), numVertices);
                    quad[3] = LinearizeIndex(index + new IntVector2(0, 1), numVertices);

                    mesh.Indices.Add(quad);
                }
            }

            return(mesh);
        }