示例#1
0
        public void CreateAnimatedCubeScene()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            var mesh = new Cube <MaterialBuilder>(MaterialBuilder.CreateDefault())
                       .ToMesh(Matrix4x4.Identity);

            var pivot = new NodeBuilder();

            pivot.UseTranslation("track1")
            .WithPoint(0, Vector3.Zero)
            .WithPoint(1, Vector3.One);

            pivot.UseRotation("track1")
            .WithPoint(0, Quaternion.Identity)
            .WithPoint(1, Quaternion.CreateFromAxisAngle(Vector3.UnitY, 1.5f));

            pivot.UseScale("track1")
            .WithPoint(0, Vector3.One)
            .WithPoint(1, new Vector3(0.5f));

            var scene = new SceneBuilder();

            scene.AddMesh(mesh, pivot);

            scene.AttachToCurrentTest("animated.glb");
            scene.AttachToCurrentTest("animated.gltf");
        }
示例#2
0
        public void CreateSceneWithMixedVertexFormats()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            var scene = new SceneBuilder();

            var mesh1 = new MeshBuilder <VertexPosition, VertexEmpty, VertexEmpty>();
            var mesh2 = new MeshBuilder <VertexPositionNormal, VertexEmpty, VertexEmpty>();

            mesh1.AddCube(MaterialBuilder.CreateDefault(), Matrix4x4.Identity);
            mesh2.AddCube(MaterialBuilder.CreateDefault(), Matrix4x4.Identity);

            scene.AddMesh(mesh1, Matrix4x4.CreateTranslation(-2, 0, 0));
            scene.AddMesh(mesh2, Matrix4x4.CreateTranslation(2, 0, 0));

            scene.AttachToCurrentTest("scene.glb");
        }
示例#3
0
        public void CreateSceneWithRandomShapes()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            var rnd = new Random(177);

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

            // create scene

            var scene = new SceneBuilder();

            for (int i = 0; i < 100; ++i)
            {
                // create mesh
                var mat  = materials[rnd.Next(0, 10)];
                var mesh = VPOSNRM.CreateCompatibleMesh("shape");

                #if DEBUG
                mesh.VertexPreprocessor.SetDebugPreprocessors();
                #else
                mesh.VertexPreprocessor.SetSanitizerPreprocessors();
                #endif

                if ((i & 1) == 0)
                {
                    mesh.AddCube(mat, Matrix4x4.Identity);
                }
                else
                {
                    mesh.AddSphere(mat, 0.5f, Matrix4x4.Identity);
                }

                mesh.Validate();

                // create random transform
                var r     = rnd.NextVector3() * 5;
                var xform = Matrix4x4.CreateFromYawPitchRoll(r.X, r.Y, r.Z) * Matrix4x4.CreateTranslation(rnd.NextVector3() * 25);

                scene.AddMesh(mesh, xform);
            }

            // save the model as GLB

            scene.AttachToCurrentTest("shapes.glb");
        }
示例#4
0
        public void CreateCubeScene()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            var mesh = new Cube <MaterialBuilder>(MaterialBuilder.CreateDefault())
                       .ToMesh(Matrix4x4.Identity);

            var scene = new SceneBuilder();

            scene.AddMesh(mesh, Matrix4x4.Identity);

            scene.AttachToCurrentTest("cube.glb");
        }
示例#5
0
        public void TestCreateEmptyMesh()
        {
            // create a scenebuilder with an empty mesh
            var sb = new SceneBuilder();

            sb.AddMesh(VPOSNRM.CreateCompatibleMesh("Empty"), Matrix4x4.Identity);

            var schema = sb.ToGltf2();

            Assert.AreEqual(0, schema.LogicalMeshes.Count, "SceneBuilder should detect empty meshes and remove them.");

            schema.CreateMesh("Empty2");

            var fileName = TestContext.CurrentContext.GetAttachmentPath("empty.glb", true);

            Assert.Throws <SharpGLTF.Validation.SchemaException>(() => schema.SaveGLB(fileName));
        }
示例#6
0
        public void CreateQuadsScene()
        {
            TestContext.CurrentContext.AttachShowDirLink();
            TestContext.CurrentContext.AttachGltfValidatorLinks();

            // this test checks that non convex quads are created correctly.

            var mesh = new MeshBuilder <VertexPosition>();
            var prim = mesh.UsePrimitive(MaterialBuilder.CreateDefault());

            var idx = prim.AddQuadrangle(new VertexPosition(0, -1, 0), new VertexPosition(1, 0, 0), new VertexPosition(0, 1, 0), new VertexPosition(-1, 0, 0));

            Assert.AreEqual((0, 1, 2, 3), idx);

            idx = prim.AddQuadrangle(new VertexPosition(0, -1, 1), new VertexPosition(1, 0, 1), new VertexPosition(0, 1, 1), new VertexPosition(0.5f, 0, 1));
            Assert.AreEqual((4, 5, 6, 7), idx);

            idx = prim.AddQuadrangle(new VertexPosition(0, 0.5f, 2), new VertexPosition(1, 0, 2), new VertexPosition(0, 1, 2), new VertexPosition(-1, 0, 2));
            Assert.AreEqual((8, 9, 10, 11), idx);

            idx = prim.AddQuadrangle(new VertexPosition(1, 0, 3), new VertexPosition(0, 1, 3), new VertexPosition(0.5f, 0, 3), new VertexPosition(0, -1, 3));
            Assert.AreEqual((12, 13, 14, 15), idx);

            idx = prim.AddQuadrangle(new VertexPosition(1, 0, 4), new VertexPosition(1, 0, 4), new VertexPosition(0, 1, 4), new VertexPosition(-1, 0, 4));
            Assert.AreEqual((-1, 16, 17, 18), idx);

            idx = prim.AddQuadrangle(new VertexPosition(1, 0, 4), new VertexPosition(1, 0, 4), new VertexPosition(0, 1, 4), new VertexPosition(0, 1, 4));
            Assert.AreEqual((-1, -1, -1, -1), idx);

            idx = prim.AddQuadrangle(new VertexPosition(0, 0, 5), new VertexPosition(10, -1, 5), new VertexPosition(9, 0, 5), new VertexPosition(10, 1, 5));
            Assert.AreEqual((19, 20, 21, 22), idx);

            idx = prim.AddQuadrangle(new VertexPosition(10, -1, 6), new VertexPosition(9, 0, 6), new VertexPosition(10, 1, 6), new VertexPosition(0, 0, 6));
            Assert.AreEqual((23, 24, 25, 26), idx);

            var scene = new SceneBuilder();

            scene.AddMesh(mesh, Matrix4x4.Identity);

            scene.AttachToCurrentTest("cube.glb");
        }
        private static void _AddMeshInstances(SceneBuilder dstScene, IReadOnlyDictionary <Node, NodeBuilder> dstNodes, IReadOnlyList <Node> srcInstances)
        {
            var dstMeshes = srcInstances
                            .Select(item => item.Mesh)
                            .Distinct()
                            .ToDictionary(item => item, item => item.ToMeshBuilder());

            foreach (var srcInstance in srcInstances)
            {
                var dstMesh = dstMeshes[srcInstance.Mesh];

                if (srcInstance.Skin == null)
                {
                    var dstNode = dstNodes[srcInstance];
                    var dstInst = dstScene.AddMesh(dstMesh, dstNode);

                    _CopyMorphingAnimation(dstInst, srcInstance);
                }
                else
                {
                    var joints = new (NodeBuilder, Matrix4x4)[srcInstance.Skin.JointsCount];