Beispiel #1
0
        public void CreateSceneWithAnimatedVisibility()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            // create a mesh
            var cube = new MeshBuilder <VPOSNRM>("cube");

            cube.VertexPreprocessor.SetDebugPreprocessors();
            cube.AddCube(MaterialBuilder.CreateDefault(), Matrix4x4.Identity);
            cube.Validate();

            // create a node and animate it
            var pivot = new NodeBuilder();

            var flatx = new Vector3(0, 1, 1);
            var flaty = new Vector3(1, 0, 1);
            var flatz = new Vector3(1, 1, 0);

            pivot.UseScale("Track1")
            .WithPoint(0, Vector3.One)
            .WithPoint(1 - 0.0001f, Vector3.One)
            .WithPoint(1, Vector3.Zero)
            .WithPoint(2 - 0.0001f, Vector3.Zero)
            .WithPoint(2, Vector3.One)
            .WithPoint(3, Vector3.One)
            .WithPoint(4, -Vector3.One)
            .WithPoint(5, -Vector3.One)
            .WithPoint(6, Vector3.One)
            .WithPoint(7, flatx)
            .WithPoint(8, flatx)
            .WithPoint(9, flaty)
            .WithPoint(10, flaty)
            .WithPoint(11, flatz)
            .WithPoint(12, flatz)
            .WithPoint(13, Vector3.One);

            // create the scene
            var scene = new SceneBuilder();

            scene.AddRigidMesh(cube, pivot);

            // save the model
            scene.AttachToCurrentTest("animatedvisibility.glb");
            scene.AttachToCurrentTest("animatedvisibility.gltf");
        }
        public void CreateSceneWithAnimatedMeshBuilder()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            // create a material
            var material1 = new MaterialBuilder("material1").WithChannelParam(KnownChannel.BaseColor, Vector4.One);

            // create a mesh
            var meshBuilder = new MeshBuilder <VPOSNRM>("mesh1");

            meshBuilder.VertexPreprocessor.SetValidationPreprocessors();

            meshBuilder.AddCube(material1, Matrix4x4.Identity);
            meshBuilder.Validate();

            // create an animated node

            var keyframes = new Dictionary <Single, Vector3>()
            {
                [1] = new Vector3(0, 0, 0),
                [2] = new Vector3(50, 0, 0),
                [3] = new Vector3(0, 50, 0),
                [4] = new Vector3(0, 0, 0),
            };

            var pivot = new NodeBuilder("RootNode").WithLocalTranslation("track1", keyframes);

            Assert.AreEqual(4, pivot.UseTranslation("track1").Keys.Count);

            // create scene

            var scene = new SceneBuilder();

            scene.AddRigidMesh(meshBuilder, pivot);

            scene.AttachToCurrentTest("result.glb");
            scene.AttachToCurrentTest("result.gltf");
        }
        public void CreateMeshWithRandomCubes()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            var rnd = new Random();

            var materials = Enumerable
                            .Range(0, 10)
                            .Select(idx => MaterialBuilder.CreateDefault()
                                    .WithChannelParam("BaseColor", new Vector4(rnd.NextVector3(), 1)))
                            .ToList();

            // create a mesh
            var cubes = new MeshBuilder <VPOSNRM>("cube");

            cubes.VertexPreprocessor.SetValidationPreprocessors();

            for (int i = 0; i < 100; ++i)
            {
                var r     = rnd.NextVector3() * 5;
                var m     = materials[rnd.Next(0, 10)];
                var xform = Matrix4x4.CreateFromYawPitchRoll(r.X, r.Y, r.Z) * Matrix4x4.CreateTranslation(rnd.NextVector3() * 25);
                cubes.AddCube(m, xform);
            }

            cubes.Validate();

            var scene = new SceneBuilder();

            scene.AddRigidMesh(cubes, Matrix4x4.Identity);

            // save the model as GLB
            scene.AttachToCurrentTest("cubes.glb");
            scene.AttachToCurrentTest("cubes.gltf");
            scene.AttachToCurrentTest("cubes.plotly");
        }
Beispiel #4
0
        public void CreateSceneWithSharedBuffers()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            // create materials
            var material1 = new MaterialBuilder("material1")
                            .WithChannelParam(KnownChannel.BaseColor, new Vector4(1, 1, 0, 1));

            var material2 = new MaterialBuilder("material1")
                            .WithChannelParam(KnownChannel.BaseColor, new Vector4(1, 0, 1, 1));

            // create several meshes
            var meshBuilder1 = new MeshBuilder <VPOSNRM>("mesh1");

            meshBuilder1.VertexPreprocessor.SetDebugPreprocessors();
            var meshBuilder2 = new MeshBuilder <VPOSNRM>("mesh2");

            meshBuilder2.VertexPreprocessor.SetDebugPreprocessors();
            var meshBuilder3 = new MeshBuilder <VPOSNRM>("mesh3");

            meshBuilder3.VertexPreprocessor.SetDebugPreprocessors();
            var meshBuilder4 = new MeshBuilder <VPOSNRM>("mesh4");

            meshBuilder4.VertexPreprocessor.SetDebugPreprocessors();

            meshBuilder1.AddCube(material1, Matrix4x4.Identity);
            meshBuilder2.AddCube(material2, Matrix4x4.Identity);
            meshBuilder3.AddSphere(material1, 0.5f, Matrix4x4.Identity);
            meshBuilder4.AddSphere(material2, 0.5f, Matrix4x4.Identity);

            meshBuilder1.Validate();
            meshBuilder2.Validate();
            meshBuilder3.Validate();
            meshBuilder4.Validate();

            // create scene nodes
            var pivot1 = new NodeBuilder("Cube1").WithLocalTranslation(new Vector3(-5, 0, 0));
            var pivot2 = new NodeBuilder("Cube2").WithLocalTranslation(new Vector3(0, 5, 0));
            var pivot3 = new NodeBuilder("SPhere1").WithLocalTranslation(new Vector3(+5, 0, 0));
            var pivot4 = new NodeBuilder("SPhere2").WithLocalTranslation(new Vector3(0, -5, 0));

            // create the scene:

            var scene = new SceneBuilder();

            scene.AddRigidMesh(meshBuilder1, pivot1);
            scene.AddRigidMesh(meshBuilder2, pivot2);
            scene.AddRigidMesh(meshBuilder3, pivot3);
            scene.AddRigidMesh(meshBuilder4, pivot4);

            // convert to gltf2

            var model = scene.ToGltf2();

            model.MergeBuffers();

            // checks
            Assert.AreEqual(1, model.LogicalBuffers.Count);
            Assert.AreEqual(2, model.LogicalBufferViews.Count);
            Assert.IsTrue(model.LogicalBufferViews[0].IsVertexBuffer);
            Assert.IsTrue(model.LogicalBufferViews[1].IsIndexBuffer);
            Assert.AreEqual(2, model.LogicalMaterials.Count);

            model.AttachToCurrentTest("result.glb");
            model.AttachToCurrentTest("result.gltf");
        }