예제 #1
0
            /// <summary>
            /// Imports material texture data to image dictionary
            /// </summary>
            /// <param name="material">Material content</param>
            /// <remarks>Replaces texture path with assigned name</remarks>
            public void Import(ref MaterialContent material)
            {
                if (!string.IsNullOrEmpty(material.AmbientTexture))
                {
                    string imageName = this.NextImageName;

                    this.Add(imageName, ImageContent.Texture("", material.AmbientTexture));

                    material.AmbientTexture = imageName;
                }

                if (!string.IsNullOrEmpty(material.DiffuseTexture))
                {
                    string imageName = this.NextImageName;

                    this.Add(imageName, ImageContent.Texture("", material.DiffuseTexture));

                    material.DiffuseTexture = imageName;
                }

                if (!string.IsNullOrEmpty(material.EmissionTexture))
                {
                    string imageName = this.NextImageName;

                    this.Add(imageName, ImageContent.Texture("", material.EmissionTexture));

                    material.EmissionTexture = imageName;
                }

                if (!string.IsNullOrEmpty(material.NormalMapTexture))
                {
                    string imageName = this.NextImageName;

                    this.Add(imageName, ImageContent.Texture("", material.NormalMapTexture));

                    material.NormalMapTexture = imageName;
                }

                if (!string.IsNullOrEmpty(material.SpecularTexture))
                {
                    string imageName = this.NextImageName;

                    this.Add(imageName, ImageContent.Texture("", material.SpecularTexture));

                    material.SpecularTexture = imageName;
                }
            }
예제 #2
0
        /// <summary>
        /// Generates a new model content from an height map
        /// </summary>
        /// <param name="contentFolder">Content folder</param>
        /// <param name="heightMap">Height map</param>
        /// <param name="textures">Texture list</param>
        /// <param name="cellSize">Cell size</param>
        /// <param name="cellHeight">Cell height</param>
        /// <returns>Returns a new model content</returns>
        public static ModelContent FromHeightmap(string contentFolder, string heightMap, IEnumerable <string> textures, float cellSize, float cellHeight)
        {
            ModelContent modelContent = new ModelContent();

            string texureName   = "texture";
            string materialName = "material";
            string geoName      = "geometry";

            ImageContent heightMapImage = new ImageContent()
            {
                Streams = ContentManager.FindContent(contentFolder, heightMap),
            };

            ImageContent textureImage = new ImageContent()
            {
                Streams = ContentManager.FindContent(contentFolder, textures),
            };

            MaterialContent material = MaterialContent.Default;

            material.DiffuseTexture = texureName;

            HeightMap hm = HeightMap.FromStream(heightMapImage.Stream, null);

            hm.BuildGeometry(cellSize, cellHeight, out var vertices, out var indices);

            SubMeshContent geo = new SubMeshContent(Topology.TriangleList, materialName, true, false);

            geo.SetVertices(vertices);
            geo.SetIndices(indices);

            modelContent.Images.Add(texureName, textureImage);
            modelContent.Materials.Add(materialName, material);
            modelContent.Geometry.Add(geoName, materialName, geo);

            return(modelContent);
        }
예제 #3
0
        /// <summary>
        /// Generate model content from scratch
        /// </summary>
        /// <param name="topology">Topology</param>
        /// <param name="vertices">Vertex list</param>
        /// <param name="indices">Index list</param>
        /// <param name="material">Material</param>
        /// <returns>Returns new model content</returns>
        private static ModelContent Generate(Topology topology, IEnumerable <VertexData> vertices, IEnumerable <uint> indices, MaterialContent material = null)
        {
            ModelContent modelContent = new ModelContent();

            if (material != null)
            {
                modelContent.Images.Import(ref material);

                modelContent.Materials.Add(ModelContent.DefaultMaterial, material);
            }

            var materialName = material != null ? ModelContent.DefaultMaterial : ModelContent.NoMaterial;
            var textured     = modelContent.Materials[materialName].DiffuseTexture != null;

            SubMeshContent geo = new SubMeshContent(topology, materialName, textured, false);

            geo.SetVertices(vertices);
            geo.SetIndices(indices);

            modelContent.Geometry.Add(ModelContent.StaticMesh, material != null ? ModelContent.DefaultMaterial : ModelContent.NoMaterial, geo);
            modelContent.Optimize();

            return(modelContent);
        }
예제 #4
0
 /// <summary>
 /// Generate triangle list model content from scratch
 /// </summary>
 /// <param name="vertices">Vertex list</param>
 /// <param name="indices">Index list</param>
 /// <param name="material">Material</param>
 /// <returns>Returns new model content</returns>
 public static ModelContent GenerateTriangleList(IEnumerable <VertexData> vertices, IEnumerable <uint> indices, MaterialContent material = null)
 {
     return(Generate(Topology.TriangleList, vertices, indices, material));
 }