Beispiel #1
0
        public void MorphColor_MultiplePrimitives()
        {
            // create material
            var material = new MaterialBuilder("mat1")
                           .WithDoubleSide(true)
                           .WithMetallicRoughnessShader();
            var material2 = new MaterialBuilder("mat2")
                            .WithDoubleSide(true)
                            .WithMetallicRoughnessShader();

            // create a mesh with two primitives, one for each material

            var mesh = new MeshBuilder <VertexPosition, VertexColor1>("mesh");

            var prim1    = mesh.UsePrimitive(material);
            var redColor = new Vector4(1f, 0f, 0f, 1f);

            prim1.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));

            var prim2 = mesh.UsePrimitive(material2);

            prim2.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));

            var tri2 = new MeshBuilder <VertexPosition, VertexColor1>("mesh2");

            prim1 = tri2.UsePrimitive(material);
            prim1.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 morph target that will change the color from red to green only for prim2
            var greenColor = new Vector4(0f, 1f, 0f, 1f);

            foreach (var p in mesh.Primitives)
            {
                if (p is not IPrimitiveBuilder pb)
                {
                    continue;
                }

                for (var i = 0; i < p.Vertices.Count; ++i)
                {
                    var oldVertexPosition = p.Vertices[i];
                    var greenMat          = new VertexColor1(greenColor);

                    pb.SetVertexDelta(0, i, default,
Beispiel #2
0
        public void TestMorphColorTargets2()
        {
            // create material
            var material = new MaterialBuilder("mat1")
                           .WithDoubleSide(true)
                           .WithMetallicRoughnessShader();
            var material2 = new MaterialBuilder("mat2")
                            .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));

            var prim2 = triangle.UsePrimitive(material2);

            prim2.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 morph target that will change the color from red to green only for prim2
            var greenColor = new Vector4(0f, 1f, 0f, 1f);

            foreach (var p in triangle.Primitives)
            {
                for (var i = 0; i < p.Vertices.Count; ++i)
                {
                    var oldVertexPosition = p.Vertices[i];
                    var greenMat          = new VertexColor1(greenColor);

                    ((IPrimitiveBuilder)p).SetVertexDelta(0, i, default,