Exemplo n.º 1
0
        /// <summary>
        /// Creates a cube made up of pairs of triangles; stored as an indexed vertex array
        /// </summary>
        /// <param name="size">length of one side</param>
        /// <returns>
        /// Mesh with positions, ids, normals
        /// </returns>
        public static DefaultMesh CreateCubeWithNormals(float size = 1.0f)
        {
            var m = new DefaultMesh();

            void createPosition(float x, float y, float z) => m.Position.Add(new Vector3(x, y, z));
            void createID(uint index) => m.IDs.Add(index);
            void createNormal(float x, float y, float z) => m.Normal.Add(new Vector3(x, y, z));

            ShapeBuilder.Cube(createPosition, createID, size, createNormal);
            return(m);
        }
Exemplo n.º 2
0
        /// <summary>
        /// creates a sphere made up of pairs of triangles; stored as an indexed vertex array
        /// </summary>
        /// <param name="radius">radius</param>
        /// <param name="subdivision">subdivision count, each subdivision creates 4 times more faces</param>
        /// <returns>
        /// Mesh with positions, ids, normals
        /// </returns>
        public static DefaultMesh CreateSphere(float radius = 1.0f, uint subdivision = 1)
        {
            var m = new DefaultMesh();

            //var pos = m.AddAttribute<Vector3>(Mesh.PositionName);
            //var normal = m.AddAttribute<Vector3>(Mesh.NormalName);
            void createPosition(float x, float y, float z) => m.Position.Add(new Vector3(x, y, z));
            void createID(uint id) => m.IDs.Add(id);
            void createNormal(float x, float y, float z) => m.Normal.Add(new Vector3(x, y, z));

            ShapeBuilder.Sphere(createPosition, createID, radius, subdivision, createNormal);
            return(m);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a plane made up of pairs of triangles; stored as an indexed vertex array.
        /// </summary>
        /// <param name="sizeX">extent of the grid in the x-coordinate axis</param>
        /// <param name="sizeZ">extent of the grid in the z-coordinate axis</param>
        /// <param name="segmentsX">number of grid segments in the x-coordinate axis</param>
        /// <param name="segmentsZ">number of grid segments in the z-coordinate axis</param>
        /// <returns>
        /// Mesh with positions, ids, normals, and uvs
        /// </returns>
        public static DefaultMesh CreatePlane(float sizeX, float sizeZ, uint segmentsX, uint segmentsZ)
        {
            var m = new DefaultMesh();

            void CreateVertex(float x, float z) => m.Position.Add(new Vector3(x, 0.0f, z));
            void CreateID(uint id) => m.IDs.Add(id);
            void CreateNormal() => m.Normal.Add(Vector3.UnitY);
            void CreateUV(float u, float v) => m.TexCoord.Add(new Vector2(u, v));

            var startX = -sizeX / 2f;
            var startZ = -sizeZ / 2f;

            ShapeBuilder.Grid(startX, sizeX, startZ, sizeZ, segmentsX, segmentsZ, CreateVertex, CreateID
                              , CreateNormal, CreateUV);
            return(m);
        }