public static Mesh CreateMesh <TvP, TvM, TvJ>(this ModelRoot root, Geometry.MeshBuilder <Material, TvP, TvM, TvJ> meshBuilder) where TvP : struct, Geometry.VertexTypes.IVertexPosition where TvM : struct, Geometry.VertexTypes.IVertexMaterial where TvJ : struct, Geometry.VertexTypes.IVertexJoints { return(root.CreateMeshes(meshBuilder).First()); }
public static Mesh CreateMesh <TvP, TvM, TvS>(this ModelRoot root, Geometry.MeshBuilder <Materials.MaterialBuilder, TvP, TvM, TvS> meshBuilder) where TvP : struct, Geometry.VertexTypes.IVertexPosition where TvM : struct, Geometry.VertexTypes.IVertexMaterial where TvS : struct, Geometry.VertexTypes.IVertexSkinning { return(root.CreateMeshes(meshBuilder).First()); }
public void CreateSceneWithCamera() { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLinks(); var mesh = new Geometry.MeshBuilder <Geometry.VertexTypes.VertexPositionNormal>(); mesh.AddCube(new Materials.MaterialBuilder(), Matrix4x4.Identity); var model = ModelRoot.CreateModel(); model.CreateMeshes(mesh); model.UseScene(0) .CreateNode() .WithMesh(model.LogicalMeshes[0]); model.UseScene(0) .CreateNode() .WithLocalTranslation(new Vector3(0, 3, 10)) .WithPerspectiveCamera(null, 1, 0.1f); model.AttachToCurrentTest("result.glb"); model.AttachToCurrentTest("result.gltf"); }
public void CreateSceneWithsSheenExtension() { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLinks(); var basePath = System.IO.Path.Combine(TestFiles.RootDirectory, "glTF-Sample-Models", "2.0", "SpecGlossVsMetalRough", "glTF"); var material = new Materials.MaterialBuilder("material") .WithMetallicRoughnessShader() .WithChannelImage(Materials.KnownChannel.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannel.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannel.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannel.BaseColor, System.IO.Path.Combine(basePath, "WaterBottle_baseColor.png")) .WithChannelImage(Materials.KnownChannel.MetallicRoughness, System.IO.Path.Combine(basePath, "WaterBottle_roughnessMetallic.png")) .WithChannelImage(Materials.KnownChannel.SheenColor, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelParam(Materials.KnownChannel.SheenColor, new Vector4(1, 1, 1, 0)) .WithChannelImage(Materials.KnownChannel.SheenRoughness, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelParam(Materials.KnownChannel.SheenRoughness, new Vector4(0.5f, 0, 0, 0)); var mesh = new Geometry.MeshBuilder <VPOS, VTEX>("mesh1"); mesh.UsePrimitive(material).AddQuadrangle ((new Vector3(-10, 10, 0), new Vector2(1, 0)) , (new Vector3(10, 10, 0), new Vector2(0, 0)) , (new Vector3(10, -10, 0), new Vector2(0, 1)) , (new Vector3(-10, -10, 0), new Vector2(1, 1)) ); var scene = new Scenes.SceneBuilder(); scene.AddRigidMesh(mesh, Matrix4x4.Identity); var gltf2 = scene.ToGltf2(); var sheenColorFactor = gltf2.LogicalMaterials[0].FindChannel("SheenColor").Value.Parameter; Assert.AreEqual(new Vector4(1, 1, 1, 0), sheenColorFactor); var sheenRoughnessFactor = gltf2.LogicalMaterials[0].FindChannel("SheenRoughness").Value.Parameter; Assert.AreEqual(new Vector4(0.5f, 0, 0, 0), sheenRoughnessFactor); scene.AttachToCurrentTest("result.glb"); scene.AttachToCurrentTest("result.gltf"); }
public void CreateFallbackMaterialScene() { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLink(); var basePath = System.IO.Path.Combine(TestContext.CurrentContext.WorkDirectory, "glTF-Sample-Models", "2.0", "SpecGlossVsMetalRough", "glTF"); // first, create a default material var material = new Materials.MaterialBuilder("material1 fallback") .WithMetallicRoughnessShader() .WithChannelImage(Materials.KnownChannels.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannels.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannels.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannels.BaseColor, System.IO.Path.Combine(basePath, "WaterBottle_baseColor.png")) .WithChannelImage(Materials.KnownChannels.MetallicRoughness, System.IO.Path.Combine(basePath, "WaterBottle_roughnessMetallic.png")); // wrap the fallback material with a PBR Specular Glossiness material. material = new Materials.MaterialBuilder("material1") .WithFallback(material) .WithSpecularGlossinessShader() .WithChannelImage(Materials.KnownChannels.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannels.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannels.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannels.Diffuse, System.IO.Path.Combine(basePath, "WaterBottle_diffuse.png")) .WithChannelImage(Materials.KnownChannels.SpecularGlossiness, System.IO.Path.Combine(basePath, "WaterBottle_specularGlossiness.png")); var mesh = new Geometry.MeshBuilder <VPOS, VTEX>("mesh1"); mesh.UsePrimitive(material).AddPolygon ((new Vector3(-10, 10, 0), new Vector2(1, 0)) , (new Vector3(10, 10, 0), new Vector2(0, 0)) , (new Vector3(10, -10, 0), new Vector2(0, 1)) , (new Vector3(-10, -10, 0), new Vector2(1, 1)) ); var model = ModelRoot.CreateModel(); var scene = model.UseScene("Default"); var rnode = scene.CreateNode("RootNode").WithMesh(model.CreateMesh(mesh)); model.AttachToCurrentTest("result.glb"); model.AttachToCurrentTest("result.gltf"); }
public void CreateSceneWithSpecularGlossinessExtension() { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLinks(); var basePath = System.IO.Path.Combine(TestFiles.RootDirectory, "glTF-Sample-Models", "2.0", "SpecGlossVsMetalRough", "glTF"); // first, create a default material var material = new Materials.MaterialBuilder("material1 fallback") .WithMetallicRoughnessShader() .WithChannelImage(Materials.KnownChannel.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannel.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannel.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannel.BaseColor, System.IO.Path.Combine(basePath, "WaterBottle_baseColor.png")) .WithChannelImage(Materials.KnownChannel.MetallicRoughness, System.IO.Path.Combine(basePath, "WaterBottle_roughnessMetallic.png")); // wrap the fallback material with a PBR Specular Glossiness material. material = new Materials.MaterialBuilder("material1") .WithFallback(material) .WithSpecularGlossinessShader() .WithChannelImage(Materials.KnownChannel.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannel.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannel.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannel.Diffuse, System.IO.Path.Combine(basePath, "WaterBottle_diffuse.png")) .WithChannelImage(Materials.KnownChannel.SpecularGlossiness, System.IO.Path.Combine(basePath, "WaterBottle_specularGlossiness.png")); var mesh = new Geometry.MeshBuilder <VPOS, VTEX>("mesh1"); mesh.UsePrimitive(material).AddQuadrangle ((new Vector3(-10, 10, 0), new Vector2(1, 0)) , (new Vector3(10, 10, 0), new Vector2(0, 0)) , (new Vector3(10, -10, 0), new Vector2(0, 1)) , (new Vector3(-10, -10, 0), new Vector2(1, 1)) ); var scene = new Scenes.SceneBuilder(); scene.AddMesh(mesh, Matrix4x4.Identity); scene.AttachToCurrentTest("result.glb"); scene.AttachToCurrentTest("result.gltf"); }
public void CreateSceneWithTextureImageExtension(string textureFileName) { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLinks(); var basePath = System.IO.Path.Combine(TestContext.CurrentContext.WorkDirectory, "Assets"); // first, create a default material var material = new Materials.MaterialBuilder("material1") .WithDoubleSide(true) .WithMetallicRoughnessShader() .WithChannelImage ( Materials.KnownChannel.BaseColor, System.IO.Path.Combine(basePath, textureFileName) ); var mesh = new Geometry.MeshBuilder <VPOS, VTEX>("mesh1"); mesh .UsePrimitive(material) .AddQuadrangle ((new Vector3(-10, 10, 0), new Vector2(1, 0)) , (new Vector3(10, 10, 0), new Vector2(0, 0)) , (new Vector3(10, -10, 0), new Vector2(0, 1)) , (new Vector3(-10, -10, 0), new Vector2(1, 1)) ); var model = ModelRoot.CreateModel(); model.CreateMeshes(mesh); model.UseScene("Default") .CreateNode("RootNode") .WithMesh(model.LogicalMeshes[0]); model.AttachToCurrentTest("result_wf.obj"); model.AttachToCurrentTest("result_glb.glb"); model.AttachToCurrentTest("result_gltf.gltf"); }
public void CreateSceneWithClearCoatExtension() { TestContext.CurrentContext.AttachGltfValidatorLinks(); var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF"); // first, create a default material var material = new Materials.MaterialBuilder("material") .WithMetallicRoughnessShader() .WithChannelImage(Materials.KnownChannel.Normal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")) .WithChannelImage(Materials.KnownChannel.Emissive, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelImage(Materials.KnownChannel.Occlusion, System.IO.Path.Combine(basePath, "WaterBottle_occlusion.png")) .WithChannelImage(Materials.KnownChannel.BaseColor, System.IO.Path.Combine(basePath, "WaterBottle_baseColor.png")) .WithChannelImage(Materials.KnownChannel.MetallicRoughness, System.IO.Path.Combine(basePath, "WaterBottle_roughnessMetallic.png")) .WithChannelImage(Materials.KnownChannel.ClearCoat, System.IO.Path.Combine(basePath, "WaterBottle_emissive.png")) .WithChannelParam(Materials.KnownChannel.ClearCoat, Materials.KnownProperty.ClearCoatFactor, 0.5f) .WithChannelImage(Materials.KnownChannel.ClearCoatRoughness, System.IO.Path.Combine(basePath, "WaterBottle_roughnessMetallic.png")) .WithChannelImage(Materials.KnownChannel.ClearCoatNormal, System.IO.Path.Combine(basePath, "WaterBottle_normal.png")); var mesh = new Geometry.MeshBuilder <VPOS, VTEX>("mesh1"); mesh.UsePrimitive(material).AddQuadrangle ((new Vector3(-10, 10, 0), new Vector2(1, 0)) , (new Vector3(10, 10, 0), new Vector2(0, 0)) , (new Vector3(10, -10, 0), new Vector2(0, 1)) , (new Vector3(-10, -10, 0), new Vector2(1, 1)) ); var scene = new Scenes.SceneBuilder(); scene.AddRigidMesh(mesh, Matrix4x4.Identity); var gltf2 = scene.ToGltf2(); var clearCoatFactor = gltf2.LogicalMaterials[0].FindChannel("ClearCoat").Value.GetFactor("ClearCoatFactor"); Assert.AreEqual(0.5f, clearCoatFactor); scene.AttachToCurrentTest("result.glb"); scene.AttachToCurrentTest("result.gltf"); }
public static Mesh CreateMesh <TMaterial, TvP, TvM, TvS>(this ModelRoot root, Func <TMaterial, Material> materialEvaluator, Geometry.MeshBuilder <TMaterial, TvP, TvM, TvS> meshBuilder) where TvP : struct, Geometry.VertexTypes.IVertexPosition where TvM : struct, Geometry.VertexTypes.IVertexMaterial where TvS : struct, Geometry.VertexTypes.IVertexSkinning { return(root.CreateMeshes(materialEvaluator, meshBuilder).First()); }