private void BuildBoxGeometry()
        {
            GeometryGenerator.MeshData box = GeometryGenerator.CreateBox(8.0f, 8.0f, 8.0f, 3);

            var boxSubmesh = new SubmeshGeometry
            {
                IndexCount         = box.Indices32.Count,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            Vertex[] vertices = box.Vertices.Select(x => new Vertex
            {
                Pos    = x.Position,
                Normal = x.Normal,
                TexC   = x.TexC
            }).ToArray();

            short[] indices = box.GetIndices16().ToArray();

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices, "boxGeo");

            geo.DrawArgs["box"] = boxSubmesh;

            _geometries[geo.Name] = geo;
        }
        private SubmeshGeometry AppendMeshData(GeometryGenerator.MeshData meshData, List <Vertex> vertices, List <short> indices)
        {
            //
            // Define the SubmeshGeometry that cover different
            // regions of the vertex/index buffers.
            //

            var submesh = new SubmeshGeometry
            {
                IndexCount         = meshData.Indices32.Count,
                StartIndexLocation = indices.Count,
                BaseVertexLocation = vertices.Count
            };

            //
            // Extract the vertex elements we are interested in and pack the
            // vertices and indices of all the meshes into one vertex/index buffer.
            //

            vertices.AddRange(meshData.Vertices.Select(vertex => new Vertex
            {
                Pos    = vertex.Position,
                Normal = vertex.Normal,
                TexC   = vertex.TexC
            }));
            indices.AddRange(meshData.GetIndices16());

            return(submesh);
        }
        private void BuildLandGeometry()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);

            //
            // Extract the vertex elements we are interested and apply the height function to
            // each vertex. In addition, color the vertices based on their height so we have
            // sandy looking beaches, grassy low hills, and snow mountain peaks.
            //

            var vertices = new Vertex[grid.Vertices.Count];

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                Vector3 p = grid.Vertices[i].Position;
                vertices[i].Pos    = p;
                vertices[i].Pos.Y  = GetHillsHeight(p.X, p.Z);
                vertices[i].Normal = GetHillsNormal(p.X, p.Z);
            }

            List <short> indices = grid.GetIndices16();

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices.ToArray(), "landGeo");

            var submesh = new SubmeshGeometry
            {
                IndexCount         = indices.Count,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            geo.DrawArgs["grid"] = submesh;

            _geometries["landGeo"] = geo;
        }
示例#4
0
        private void BuildLandGeometry()
        {
            GeometryGenerator.MeshData grid = GeometryGenerator.CreateGrid(160.0f, 160.0f, 50, 50);

            //
            // Extract the vertex elements we are interested and apply the height function to
            // each vertex. In addition, color the vertices based on their height so we have
            // sandy looking beaches, grassy low hills, and snow mountain peaks.
            //

            var vertices = new Vertex[grid.Vertices.Count];

            for (int i = 0; i < grid.Vertices.Count; i++)
            {
                Vector3 p = grid.Vertices[i].Position;
                vertices[i].Pos   = p;
                vertices[i].Pos.Y = GetHillsHeight(p.X, p.Z);

                // Color the vertex based on its height.
                if (vertices[i].Pos.Y < -10.0f)
                {
                    // Sandy beach color.
                    vertices[i].Color = new Vector4(1.0f, 0.96f, 0.62f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 5.0f)
                {
                    // Light yellow-green.
                    vertices[i].Color = new Vector4(0.48f, 0.77f, 0.46f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 12.0f)
                {
                    // Dark yellow-green.
                    vertices[i].Color = new Vector4(0.1f, 0.48f, 0.19f, 1.0f);
                }
                else if (vertices[i].Pos.Y < 20.0f)
                {
                    // Dark brown.
                    vertices[i].Color = new Vector4(0.45f, 0.39f, 0.34f, 1.0f);
                }
                else
                {
                    // White snow.
                    vertices[i].Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                }
            }

            List <short> indices = grid.GetIndices16();

            var geo = MeshGeometry.New(Device, CommandList, vertices, indices.ToArray(), "landGeo");

            var submesh = new SubmeshGeometry
            {
                IndexCount         = indices.Count,
                StartIndexLocation = 0,
                BaseVertexLocation = 0
            };

            geo.DrawArgs["grid"] = submesh;

            _geometries["landGeo"] = geo;
        }