public void CreateOneKey() { var node = new Scenes.NodeBuilder("someNode"); var tb = node.UseTranslation().UseTrackBuilder("track1"); tb.SetPoint(0, new Vector3(1, 2, 3)); var scene = new Scenes.SceneBuilder(); scene.AddNode(node); var glTF = scene.ToGltf2(); var options = new Runtime.RuntimeOptions { IsolateMemory = true }; var runtime = Runtime.SceneTemplate.Create(glTF.DefaultScene, options); var instance = runtime.CreateInstance(); var instanceNode = instance.Armature.LogicalNodes.First(n => n.Name == "someNode"); instanceNode.SetAnimationFrame(0, 7); var nodeMatrix = instanceNode.LocalMatrix; Assert.AreEqual(new Vector3(1, 2, 3), nodeMatrix.Translation); }
public void TestVertexEquality() { var material1 = new MaterialBuilder() .WithDoubleSide(true) .WithMetallicRoughnessShader() .WithChannelParam(KnownChannel.BaseColor, KnownProperty.RGBA, new Vector4(1, 0, 0, 1)); var mesh = new MeshBuilder <VERTEX>("mesh"); var v0 = new VERTEX(15, 5, 0, 1, 0, 0); var v1 = new VERTEX(15, 5, 10, 1, 0, 0); var v2 = new VERTEX(15, 0, 10, 1, 0, 0); var v3 = new VERTEX(15, 0, 0, 1, 0, 0); var prim = mesh.UsePrimitive(material1); prim.AddTriangle(v0, v1, v3); prim.AddTriangle(v3, v1, v2); v0 = new VERTEX(15, 5, 10, 0, 0, 1); v1 = new VERTEX(0, 5, 10, 0, 0, 1); v2 = new VERTEX(0, 0, 10, 0, 0, 1); v3 = new VERTEX(15, 0, 10, 0, 0, 1); prim.AddTriangle(v0, v1, v3); prim.AddTriangle(v3, v1, v2); Assert.AreEqual(8, prim.Vertices.Count); // create a scene var scene = new Scenes.SceneBuilder(); scene.AddRigidMesh(mesh, Matrix4x4.Identity); // save the model in different formats AttachmentInfo .From("mesh.glb") .WriteObject(f => scene.ToGltf2().Save(f.FullName)); AttachmentInfo .From("mesh.gltf") .WriteObject(f => scene.ToGltf2().Save(f.FullName)); }
public void LoadGeneratedTangetsTest(string fileName) { var path = TestFiles.GetSampleModelsPaths().FirstOrDefault(item => item.EndsWith(fileName)); var model = ModelRoot.Load(path); var mesh = model.DefaultScene .EvaluateTriangles <Geometry.VertexTypes.VertexPositionNormalTangent, Geometry.VertexTypes.VertexTexture1>() .ToMeshBuilder(); var editableScene = new Scenes.SceneBuilder(); editableScene.AddRigidMesh(mesh, Matrix4x4.Identity); model.AttachToCurrentTest("original.glb"); editableScene.ToGltf2().AttachToCurrentTest("WithTangents.glb"); }
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 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 void TestMorphColorTargets() { // create material var material = new MaterialBuilder() .WithDoubleSide(true) .WithMetallicRoughnessShader(); // create a mesh with two primitives, one for each material var triangle = new MeshBuilder <VertexPosition, VertexColor1>("mesh"); var prim = triangle.UsePrimitive(material); var redColor = new Vector4(1f, 0f, 0f, 1f); prim.AddTriangle(new VBColor1(new VertexPosition(-10, 0, 0), redColor), new VBColor1(new VertexPosition(10, 0, 0), redColor), new VBColor1(new VertexPosition(0, 10, 0), redColor)); // create a scene var scene = new Scenes.SceneBuilder(); scene.AddRigidMesh(triangle, Matrix4x4.Identity); var greenColor = new Vector4(0f, 1f, 0f, 1f); // create a morph target that will move the triangle in X axis by 1 unit // and change the color from red to green var morphTargetBuilder = triangle.UseMorphTarget(0); foreach (var vertexPosition in morphTargetBuilder.Vertices) { var newVertexPosition = vertexPosition; // new vertex position is moved in X direction by 1 unit newVertexPosition.Position.X += 1; morphTargetBuilder.SetVertex(vertexPosition, new VBColor1(newVertexPosition, // morph to green color greenColor)); } Assert.AreEqual(3, morphTargetBuilder.Vertices.Count); // save the model in different formats var model = scene.ToGltf2(); var animation = model.CreateAnimation(); // create a morph channel animation.CreateMorphChannel(model.LogicalNodes[0], new Dictionary <float, float[]> { { 0f, new[] { 0f } }, { 1f, new[] { 1f } } }, 1); // evaluate triangles at animation 0.5, and get the color of the first pixel of the first triangle var triangles = Schema2.Toolkit .EvaluateTriangles(model.DefaultScene, null, model.LogicalAnimations[0], 0.5f) .ToArray(); var morphedColor = triangles[0].A.GetMaterial().GetColor(0); Assert.AreEqual(0.5f, morphedColor.X); Assert.AreEqual(0.5f, morphedColor.Y); Assert.AreEqual(0, morphedColor.Z); Assert.AreEqual(1, morphedColor.W); // save the model in different formats // model.AttachToCurrentTest("ColorAndTextureMorphing.glb"); // model.AttachToCurrentTest("ColorAndTextureMorphing.gltf"); // bypassing AttachToCurrentTest until glTFValidator is fixed. AttachmentInfo .From("ColorMorphing.glb") .WriteObject(f => model.Save(f.FullName)); AttachmentInfo .From("ColorMorphing.gltf") .WriteObject(f => model.Save(f.FullName)); }