public static IReadOnlyList <Mesh> CreateMeshes(this ModelRoot root, params IMeshBuilder <Materials.MaterialBuilder>[] meshBuilders) { // until this point, even if the multiple material instances used by the meshes have the same content definition, // we must handling material equality by its object reference and nothing else, because Materials.MaterialBuilder // is a mutable object, and we cannot guarantee two material instances will keep having the same content. // it is at this point where we can coalesce materials with the same content. // TODO: in order to coalesce MaterialBuilder instances with same content // an IMeshBuilder could wrap the incoming mesh, and merge primitives with shared meshes. // MaterialBuilder instances can be grouped by their content, so we use this dictionary // to reduce the number of equal materials. This is specially useful for the default material. var materials = new Dictionary <Materials.MaterialBuilder, Material>(Materials.MaterialBuilder.ContentComparer); Material matFactory(Materials.MaterialBuilder srcMat) { if (materials.TryGetValue(srcMat, out Schema2.Material dstMat)) { return(dstMat); } return(materials[srcMat] = root.CreateMaterial(srcMat)); } return(root.CreateMeshes(matFactory, meshBuilders)); }
public static IReadOnlyList <Mesh> CreateMeshes <TvP, TvM, TvJ>(this ModelRoot root, params Geometry.MeshBuilder <Materials.MaterialBuilder, TvP, TvM, TvJ>[] meshBuilders) where TvP : struct, Geometry.VertexTypes.IVertexPosition where TvM : struct, Geometry.VertexTypes.IVertexMaterial where TvJ : struct, Geometry.VertexTypes.IVertexJoints { return(root.CreateMeshes(mb => root.CreateMaterial(mb), meshBuilders)); }
public static Material CreateMaterial(this ModelRoot root, Materials.MaterialBuilder mb) { var m = root.CreateMaterial(mb.Name); mb.CopyTo(m); return(m); }
private Material GetDefaultMaterial() { if (_DummyModel != null) { _DummyModel = ModelRoot.CreateModel(); _DummyModel.CreateMaterial("Default"); } return(_DummyModel.LogicalMaterials[0]); }
public static Material CreateMaterial(this ModelRoot root, MaterialBuilder mb) { Guard.NotNull(root, nameof(root)); Guard.NotNull(mb, nameof(mb)); var m = root.CreateMaterial(); mb.CopyTo(m); return(m); }