Exemplo n.º 1
0
        public static Runtime.GLTF SinglePlane()
        {
            List <Vector3> planePositions = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f)
            };

            // 1:1 UV mapping
            List <List <Vector2> > planeTextureCoordSets = new List <List <Vector2> >
            {
                new List <Vector2>
                {
                    new Vector2(1.0f, 1.0f),
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.0f, 0.0f),
                    new Vector2(1.0f, 0.0f)
                },
            };

            List <int> PlaneIndices = new List <int>
            {
                1, 0, 3, 1, 3, 2
            };

            Runtime.GLTF          wrapper  = new Runtime.GLTF();
            Runtime.Scene         scene    = new Runtime.Scene();
            Runtime.Mesh          mesh     = new Runtime.Mesh();
            Runtime.MeshPrimitive meshPrim = new Runtime.MeshPrimitive
            {
                Indices          = PlaneIndices,
                Positions        = planePositions,
                TextureCoordSets = planeTextureCoordSets
            };
            mesh.MeshPrimitives = new List <Runtime.MeshPrimitive>
            {
                meshPrim
            };
            scene.Nodes = new List <Runtime.Node>
            {
                new Runtime.Node
                {
                    Mesh = mesh
                }
            };

            wrapper.Scenes.Add(scene);

            return(wrapper);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a triangle model using the glTF wrapper
        /// </summary>
        /// <param name="gltf"></param>
        /// <param name="geometryData"></param>
        /// <returns>GLTFWrapper object</returns>
        public static Runtime.GLTF SingleTriangle()
        {
            List <Vector3> trianglePositions = new List <Vector3>()
            {
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(-1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f)
            };
            List <Vector3> triangleNormals = new List <Vector3>()
            {
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, 0.0f, -1.0f)
            };
            List <List <Vector2> > triangleTextureCoordSets = new List <List <Vector2> >
            {
                new List <Vector2>
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.5f, 1.0f),
                    new Vector2(0.25f, 0.0f)
                },
                new List <Vector2>
                {
                    new Vector2(0.5f, 1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(0.75f, 0.0f)
                }
            };

            Runtime.GLTF          wrapper  = new Runtime.GLTF();
            Runtime.Scene         scene    = new Runtime.Scene();
            Runtime.Mesh          mesh     = new Runtime.Mesh();
            Runtime.MeshPrimitive meshPrim = new Runtime.MeshPrimitive
            {
                Positions        = trianglePositions,
                Normals          = triangleNormals,
                TextureCoordSets = triangleTextureCoordSets
            };
            mesh.MeshPrimitives.Add(meshPrim);
            scene.Nodes = new List <Runtime.Node> {
                new Runtime.Node
                {
                    Mesh = mesh
                }
            };
            wrapper.Scenes.Add(scene);

            return(wrapper);
        }
        public Mesh_PrimitiveMode(List <string> imageList)
        {
            UseFigure(imageList, "Indices");
            UseFigure(imageList, "Indices_Points");

            // There are no common properties in this model group that are reported in the readme.

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false, includeIndices: false);

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive);

                meshPrimitive.Material = new Runtime.Material
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                    {
                        MetallicFactor = 0
                    },
                };

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene
                    {
                        Nodes = new List <Runtime.Node>
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetModePoints(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var pointPositions = new List <Vector3>();
                var cornerPoints   = new List <Vector3>
                {
                    new Vector3(0.5f, -0.5f, 0.0f),
                    new Vector3(-0.5f, -0.5f, 0.0f),
                    new Vector3(-0.5f, 0.5f, 0.0f),
                    new Vector3(0.5f, 0.3f, 0.0f),
                    new Vector3(0.5f, -0.5f, 0.0f)
                };

                for (var corner = 0; corner < 4; corner++)
                {
                    for (float x = 256; x > 0; x--)
                    {
                        Vector3 startPoint     = cornerPoints[corner];
                        Vector3 endPoint       = cornerPoints[corner + 1];
                        float   fractionOfLine = x / 256f;
                        pointPositions.Add(GetPointOnLine(startPoint, endPoint, fractionOfLine));
                    }
                }

                meshPrimitive.Mode      = ModeEnum.POINTS;
                meshPrimitive.Positions = pointPositions;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLines(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                        new Vector3(0.5f, 0.3f, 0.0f),
                        new Vector3(0.5f, 0.3f, 0.0f),
                        new Vector3(0.5f, -0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.LINES;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLineLoop(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.3f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.LINE_LOOP;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLineStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.3f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, -0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.LINE_STRIP;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangleStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.TRIANGLE_STRIP;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangleFan(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.TRIANGLE_FAN;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangles(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions = new List <Vector3>
                    {
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, -0.5f, 0.0f),
                        new Vector3(0.5f, 0.5f, 0.0f),
                        new Vector3(-0.5f, 0.5f, 0.0f),
                    };
                }
                meshPrimitive.Mode = ModeEnum.TRIANGLES;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetIndicesPoints(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var pointsIndices = new List <int>();

                for (var x = 0; x < meshPrimitive.Positions.Count(); x++)
                {
                    pointsIndices.Add(x);
                }
                meshPrimitive.Indices = pointsIndices;
                properties.Add(new Property(PropertyName.IndicesValues, $"[0 - {meshPrimitive.Positions.Count() - 1}]"));
            }

            void SetIndicesLines(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = GetSinglePlaneNonReversiblePositions();
                meshPrimitive.Indices   = new List <int>
                {
                    0, 3,
                    3, 2,
                    2, 1,
                    1, 0,
                };
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesLineLoop(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = GetSinglePlaneNonReversiblePositions();
                meshPrimitive.Indices   = new List <int>
                {
                    0, 3, 2, 1,
                };
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesTriangleFan(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = MeshPrimitive.GetSinglePlanePositions();
                meshPrimitive.Indices   = new List <int>
                {
                    0, 3, 2, 1,
                };
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesLineStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = GetSinglePlaneNonReversiblePositions();
                meshPrimitive.Indices   = new List <int>
                {
                    0, 3, 2, 1, 0,
                };
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesTriangleStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = MeshPrimitive.GetSinglePlanePositions();
                meshPrimitive.Indices   = new List <int>
                {
                    0, 3, 1, 2,
                };
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesTriangles(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Positions = MeshPrimitive.GetSinglePlanePositions();
                meshPrimitive.Indices   = MeshPrimitive.GetSinglePlaneIndices();
                properties.Add(new Property(PropertyName.IndicesValues, meshPrimitive.Indices.ToReadmeString()));
            }

            void SetIndicesComponentTypeInt(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.IndexComponentType = IndexComponentTypeEnum.UNSIGNED_INT;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.IndexComponentType.ToReadmeString()));
            }

            void SetIndicesComponentTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.IndexComponentType = IndexComponentTypeEnum.UNSIGNED_BYTE;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.IndexComponentType.ToReadmeString()));
            }

            void SetIndicesComponentTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.IndexComponentType = IndexComponentTypeEnum.UNSIGNED_SHORT;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.IndexComponentType.ToReadmeString()));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModePoints(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLines(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLineLoop(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLineStrip(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangleStrip(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangleFan(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangles(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModePoints(properties, meshPrimitive);
                    SetIndicesPoints(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLines(properties, meshPrimitive);
                    SetIndicesLines(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLineLoop(properties, meshPrimitive);
                    SetIndicesLineLoop(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeLineStrip(properties, meshPrimitive);
                    SetIndicesLineStrip(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangleStrip(properties, meshPrimitive);
                    SetIndicesTriangleStrip(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangleFan(properties, meshPrimitive);
                    SetIndicesTriangleFan(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangles(properties, meshPrimitive);
                    SetIndicesTriangles(properties, meshPrimitive);
                    SetIndicesComponentTypeInt(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangles(properties, meshPrimitive);
                    SetIndicesTriangles(properties, meshPrimitive);
                    SetIndicesComponentTypeByte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetModeTriangles(properties, meshPrimitive);
                    SetIndicesTriangles(properties, meshPrimitive);
                    SetIndicesComponentTypeShort(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }
        public Animation_SkinType(List <string> imageList)
        {
            // There are no common properties in this model group that are reported in the readme.

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive> setProperties)
            {
                var properties            = new List <Property>();
                List <Runtime.Node> nodes = Nodes.CreateFoldingPlaneSkin("skinA", 2, 3);
                var animations            = new List <Runtime.Animation>();

                Runtime.MeshPrimitive   meshPrimitive       = nodes[0].Mesh.MeshPrimitives.First();
                JointComponentTypeEnum  jointComponentType  = meshPrimitive.JointComponentType;
                WeightComponentTypeEnum weightComponentType = meshPrimitive.WeightComponentType;
                var closeCameraTranslation = new Manifest.Camera(new Vector3(0.5f, 0.0f, 0.6f));

                // Apply the common properties to the gltf.
                AnimateWithRotation(animations, nodes);

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene()
                    {
                        Nodes = nodes
                    }, animations: animations),
                    Camera = closeCameraTranslation
                });
            }

            void AnimateWithRotation(List <Runtime.Animation> animations, List <Runtime.Node> nodes)
            {
                animations = new List <Runtime.Animation>
                {
                    new Runtime.Animation
                    {
                        Channels = new List <Runtime.AnimationChannel>
                        {
                            new Runtime.AnimationChannel
                            {
                                Target = new Runtime.AnimationChannelTarget
                                {
                                    Node = nodes[1].Children.First(),
                                    Path = Runtime.AnimationChannelTarget.PathEnum.ROTATION,
                                }
                            }
                        }
                    }
                };
                float quarterTurn = (FloatMath.Pi / 2.0f);

                animations[0].Channels.First().Sampler = new Runtime.LinearAnimationSampler <Quaternion>(
                    new[]
                {
                    0.0f,
                    1.0f,
                    2.0f,
                },
                    new[]
                {
                    Quaternion.Identity,
                    Quaternion.CreateFromYawPitchRoll(0.0f, quarterTurn, 0.0f),
                    Quaternion.Identity,
                });
            }

            void JointsAreByte(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.JointComponentType = JointComponentTypeEnum.UNSIGNED_BYTE;
            }

            void JointsAreShort(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.JointComponentType = JointComponentTypeEnum.UNSIGNED_SHORT;
            }

            void WeightsAreFloat(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.WeightComponentType = WeightComponentTypeEnum.FLOAT;
            }

            void WeightsAreByte(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.WeightComponentType = WeightComponentTypeEnum.NORMALIZED_UNSIGNED_BYTE;
            }

            void WeightsAreShort(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.WeightComponentType = WeightComponentTypeEnum.NORMALIZED_UNSIGNED_SHORT;
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) => {
                    JointsAreByte(meshPrimitive);
                    WeightsAreFloat(meshPrimitive);
                    properties.Add(new Property(PropertyName.JointsComponentType, "Byte"));
                    properties.Add(new Property(PropertyName.WeightComponentType, "Float"));
                }),
                CreateModel((properties, meshPrimitive) => {
                    JointsAreByte(meshPrimitive);
                    WeightsAreByte(meshPrimitive);
                    properties.Add(new Property(PropertyName.JointsComponentType, "Byte"));
                    properties.Add(new Property(PropertyName.WeightComponentType, "Byte"));
                }),
                CreateModel((properties, meshPrimitive) => {
                    JointsAreByte(meshPrimitive);
                    WeightsAreShort(meshPrimitive);
                    properties.Add(new Property(PropertyName.JointsComponentType, "Byte"));
                    properties.Add(new Property(PropertyName.WeightComponentType, "Short"));
                }),
                CreateModel((properties, meshPrimitive) => {
                    JointsAreShort(meshPrimitive);
                    WeightsAreFloat(meshPrimitive);
                    properties.Add(new Property(PropertyName.JointsComponentType, "Short"));
                    properties.Add(new Property(PropertyName.WeightComponentType, "Float"));
                }),
            };

            GenerateUsedPropertiesList();
        }
Exemplo n.º 5
0
        public Animation_Skin(List <string> imageList)
        {
            UseFigure(imageList, "skinA");
            UseFigure(imageList, "skinB");
            UseFigure(imageList, "skinC");
            UseFigure(imageList, "skinD");
            UseFigure(imageList, "skinE");
            UseFigure(imageList, "skinF");
            var closeCamera   = new Manifest.Camera(new Vector3(0.5f, 0.0f, 0.6f));
            var distantCamera = new Manifest.Camera(new Vector3(1.5f, 0.0f, 1.0f));
            var skinBCamera   = new Manifest.Camera(new Vector3(0.5f, 0.6f, 1.1f));

            // There are no common properties in this model group that are reported in the readme.

            Model CreateModel(Action <List <Property>, List <Runtime.Animation>, List <Runtime.Node> > setProperties, Action <Model> setCamera, Action <glTFLoader.Schema.Gltf> postRuntimeChanges = null)
            {
                var properties = new List <Property>();
                var nodes      = new List <Runtime.Node>();
                var animations = new List <Runtime.Animation>();
                var animated   = true;

                // There are no common properties in this model group.

                // Apply the properties that are specific to this gltf.
                setProperties(properties, animations, nodes);

                // If no animations are used, null out that property.
                if (!animations.Any())
                {
                    animations = null;
                    animated   = false;
                }

                // Create the gltf object.
                var model = new Model
                {
                    Properties = properties,
                    GLTF       = CreateGLTF(() => new Runtime.Scene
                    {
                        Nodes = nodes
                    }, animations: animations),
                    Animated = animated,
                };

                if (postRuntimeChanges != null)
                {
                    model.PostRuntimeChanges = postRuntimeChanges;
                }

                setCamera(model);

                return(model);
            }

            void AddRotationAnimationChannel(List <Runtime.AnimationChannel> channelList, Runtime.Node targetNode, Quaternion pitchValue, Quaternion restValue)
            {
                channelList.Add(
                    new Runtime.AnimationChannel
                {
                    Target = new Runtime.AnimationChannelTarget
                    {
                        Node = targetNode,
                        Path = Runtime.AnimationChannelTarget.PathEnum.ROTATION,
                    },
                    Sampler = new Runtime.LinearAnimationSampler <Quaternion>
                              (
                        new[]
                    {
                        0.0f,
                        1.0f,
                        2.0f,
                    },
                        new[]
                    {
                        restValue,
                        pitchValue,
                        restValue,
                    }
                              )
                });
            }

            Runtime.Animation CreateFoldingAnimation(Runtime.Node jointRootNode, List <Runtime.AnimationChannel> channelList = null)
            {
                if (channelList == null)
                {
                    channelList = new List <Runtime.AnimationChannel>();
                }

                Runtime.Node nodeCheck  = jointRootNode;
                float        pitchValue = FloatMath.ToRadians(-90.0f);
                var          nodeList   = new List <Runtime.Node>
                {
                    jointRootNode,
                };

                while (nodeCheck.Children != null)
                {
                    foreach (var node in nodeCheck.Children)
                    {
                        nodeList.Add(node);
                    }
                    nodeCheck = nodeCheck.Children.First();
                }

                for (var nodeIndex = 1; nodeIndex < nodeList.Count(); nodeIndex++)
                {
                    float rotateValueModifier = 1.0f;
                    if (nodeIndex == 1)
                    {
                        rotateValueModifier = 0.5f;
                    }
                    else if (nodeIndex % 2 == 0)
                    {
                        rotateValueModifier = -1.0f;
                    }
                    AddRotationAnimationChannel(channelList, nodeList[nodeIndex], Quaternion.CreateFromYawPitchRoll(0.0f, pitchValue * rotateValueModifier, 0.0f), Quaternion.Identity);
                }
                return(new Runtime.Animation
                {
                    Channels = channelList
                });
            }

            Models = new List <Model>
            {
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }

                    properties.Add(new Property(PropertyName.Description, "`skinA`."));
                }, (model) => { model.Camera = closeCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }
                    animations.Add(CreateFoldingAnimation(nodes[1]));

                    properties.Add(new Property(PropertyName.Description, "`skinA` where `joint1` is animating with a rotation."));
                }, (model) => { model.Camera = closeCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    var tempNodeList = Nodes.CreateFoldingPlaneSkin("skinA", 2, 3);

                    // Give the skin node a rotation
                    tempNodeList[0].Rotation = Quaternion.CreateFromYawPitchRoll((FloatMath.Pi / 4.0f), 0.0f, 0.0f);

                    // Create a new parent node and give it a rotation
                    tempNodeList[0] = new Runtime.Node
                    {
                        Name     = "jointParent",
                        Rotation = Quaternion.CreateFromYawPitchRoll((FloatMath.Pi / 4.0f), 0.0f, 0.0f),
                        Children = new List <Runtime.Node>
                        {
                            tempNodeList[0]
                        }
                    };

                    foreach (Runtime.Node node in tempNodeList)
                    {
                        nodes.Add(node);
                    }

                    properties.Add(new Property(PropertyName.Description, "`skinA` where the skinned node has a transform and a parent node with a transform. Both transforms should be ignored."));
                }, (model) => { model.Camera = closeCamera; }),
                // Removed Animation_Skin_03 due to a change in the spec that disallows this situation.
                // Left commented out because this will likely be re-added as a negative test in the future.
                // CreateModel((properties, animations, nodes) =>
                //{
                //     foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                //     {
                //         nodes.Add(node);
                //     }

                //     properties.Add(new Property(PropertyName.Description, "`skinA`. The skin joints are not referenced by the scene nodes."));
                // }, (model) => { model.Camera = closeCamera; }, (gltf) => {gltf.Scenes.First().Nodes = new []{0,};}),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }
                    nodes[0].Skin.InverseBindMatrices = new[]
                    {
                        Matrix4x4.Identity,
                        Matrix4x4.Identity
                    };

                    properties.Add(new Property(PropertyName.Description, "`skinA` without inverse bind matrices."));
                }, (model) => { model.Camera = closeCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }
                    animations.Add(CreateFoldingAnimation(nodes[1]));

                    // Attach a node with a mesh to the end of the joint hierarchy
                    Runtime.Node nodeCheck = nodes[1];
                    while (nodeCheck.Children != null)
                    {
                        nodeCheck = nodeCheck.Children.First();
                    }

                    nodeCheck.Children = new List <Runtime.Node>
                    {
                        new Runtime.Node
                        {
                            Mesh = Mesh.CreateTriangle()
                        }
                    };

                    properties.Add(new Property(PropertyName.Description, "`skinA` where `joint1` is animated with a rotation and `joint1` has a triangle mesh attached to it."));
                }, (model) => { model.Camera = closeCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }

                    // Create a set of positions for the second mesh that are offset from the first mesh.
                    Runtime.MeshPrimitive originalMeshPrimitive = nodes[0].Mesh.MeshPrimitives.First();
                    var offsetPositions = new List <Vector3>();
                    foreach (Vector3 position in originalMeshPrimitive.Positions)
                    {
                        var offsetPosition = position;
                        offsetPosition.X  += 0.6f;
                        offsetPositions.Add(offsetPosition);
                    }

                    // Create a second mesh
                    nodes.Add(new Runtime.Node
                    {
                        Name = "plane2",
                        Skin = nodes[0].Skin,
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new[]
                            {
                                new Runtime.MeshPrimitive
                                {
                                    VertexJointWeights = originalMeshPrimitive.VertexJointWeights,
                                    Positions          = offsetPositions,
                                    Indices            = originalMeshPrimitive.Indices,
                                    Material           = new Runtime.Material
                                    {
                                        DoubleSided = true,
                                        MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                                        {
                                            BaseColorFactor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
                                        }
                                    }
                                }
                            }
                        }
                    });

                    properties.Add(new Property(PropertyName.Description, "`skinA` where there are two meshes sharing a single skin."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinA", 2, 3))
                    {
                        nodes.Add(node);
                    }

                    // Make joint1 a root joint
                    nodes.Add(nodes[1].Children.First());
                    nodes[1].Children = null;

                    // Compensate for no longer inheriting from joint0
                    nodes[2].Rotation    = Quaternion.Multiply((Quaternion)nodes[2].Rotation, (Quaternion)nodes[1].Rotation);
                    nodes[2].Translation = null;
                    nodes[0].Skin.InverseBindMatrices = new[]
                    {
                        nodes[0].Skin.InverseBindMatrices.First(),
                        Matrix4x4.Identity
                    };

                    properties.Add(new Property(PropertyName.Description, "`skinA` where `joint1` is a root node and not a child of `joint0`."));
                }, (model) => { model.Camera = closeCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreatePlaneWithSkinB())
                    {
                        nodes.Add(node);
                    }

                    // Animate the joints
                    Runtime.Node nodeJoint0 = nodes[1];
                    Runtime.Node nodeJoint1 = nodeJoint0.Children.First();
                    var channelList         = new List <Runtime.AnimationChannel>();
                    float rotationValue     = FloatMath.ToRadians(-15.0f);
                    AddRotationAnimationChannel(channelList, nodeJoint1, Quaternion.CreateFromYawPitchRoll(0.0f, 0.0f, rotationValue), Quaternion.CreateFromYawPitchRoll(0.0f, 0.0f, 0.0f));
                    animations.Add(new Runtime.Animation
                    {
                        Channels = channelList
                    });

                    properties.Add(new Property(PropertyName.Description, "`skinB` which is made up of two skins. `joint1` is referenced by both skins and is animating with a rotation."));
                }, (model) => { model.Camera = skinBCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinC", 5, 5))
                    {
                        nodes.Add(node);
                    }

                    // Rotate each joint node, except the root which already has the desired rotation
                    Runtime.Node nodeCheck = nodes[1].Children.First();
                    float rotationRadian   = FloatMath.ToRadians(-10.0f);
                    Quaternion rotation    = Quaternion.CreateFromYawPitchRoll(0.0f, rotationRadian, 0.0f);
                    nodeCheck.Rotation     = rotation;
                    while (nodeCheck.Children != null)
                    {
                        foreach (var node in nodeCheck.Children)
                        {
                            node.Rotation = rotation;
                        }
                        nodeCheck = nodeCheck.Children.First();
                    }

                    // Rebuild the inverseBindMatrix for each joint (except the root) to work with the new rotation
                    List <Matrix4x4> inverseBindMatrixList = (List <Matrix4x4>)nodes[0].Skin.InverseBindMatrices;
                    for (var i = 1; i < inverseBindMatrixList.Count; i++)
                    {
                        var translationInverseBindMatrix = inverseBindMatrixList[i];
                        Matrix4x4.Invert(Matrix4x4.CreateRotationX(rotationRadian * (i + 1)), out Matrix4x4 invertedRotation);
                        inverseBindMatrixList[i] = Matrix4x4.Multiply(translationInverseBindMatrix, invertedRotation);
                    }

                    properties.Add(new Property(PropertyName.Description, "`skinC` where all of the joints have a local rotation of -10 degrees, except the root which is rotated -90 degrees."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinD", 5, 6, 3, false))
                    {
                        nodes.Add(node);
                    }
                    animations.Add(CreateFoldingAnimation(nodes[1]));

                    // Remove animation for the transform node
                    animations[0].Channels = new List <Runtime.AnimationChannel>
                    {
                        animations[0].Channels.First(),
                        animations[0].Channels.ElementAt(1),
                        animations[0].Channels.ElementAt(3),
                    };

                    // Add the mesh to the transform node
                    nodes[1].Children.First().Children.First().Children.First().Mesh = Mesh.CreateTriangle();

                    properties.Add(new Property(PropertyName.Description, "`skinD` where each joint is animating with a rotation. There is a transform node in the joint hierarchy that is not a joint. That node has a mesh attached to it in order to show its location."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    foreach (Runtime.Node node in Nodes.CreatePlaneWithSkinE())
                    {
                        nodes.Add(node);
                    }

                    properties.Add(new Property(PropertyName.Description, "`skinE`."));
                }, (model) => { model.Camera = distantCamera; }),
                // Removing this model for now, since no viewer currently supports models that have >4 jointweights per vertex.
                //CreateModel((properties, animations, nodes) =>
                //{
                //    foreach (Runtime.Node node in Nodes.CreateFoldingPlaneSkin("skinF", 8, 9, vertexVerticalSpacingMultiplier: 0.5f))
                //    {
                //        nodes.Add(node);
                //    }

                //    // Rotate each joint node, except the root which already has the desired rotation
                //    Runtime.Node nodeCheck = nodes[1].Children.First();
                //    float rotationRadian = FloatMath.ConvertDegreesToRadians(-10.0f);
                //    Quaternion rotationQuaternion = Quaternion.CreateFromYawPitchRoll(0.0f, rotationRadian, 0.0f);
                //    nodeCheck.Rotation = rotationQuaternion;
                //    while (nodeCheck.Children != null)
                //    {
                //        foreach (Runtime.Node node in nodeCheck.Children)
                //        {
                //            node.Rotation = rotationQuaternion;
                //        }
                //        nodeCheck = nodeCheck.Children.First();
                //    }

                //    // Rebuild the inverseBindMatrix for each joint (except the root) to work with the new rotation
                //    var skinJointList = (List<Runtime.SkinJoint>)nodes[0].Skin.SkinJoints;
                //    for (var skinJointIndex = 1; skinJointIndex < skinJointList.Count(); skinJointIndex++)
                //    {
                //        Matrix4x4 translationInverseBindMatrix = skinJointList.ElementAt(skinJointIndex).InverseBindMatrix;
                //        Matrix4x4.Invert(Matrix4x4.CreateRotationX(rotationRadian * (skinJointIndex + 1)) , out Matrix4x4 invertedRotation);
                //        skinJointList.ElementAt(skinJointIndex).InverseBindMatrix = Matrix4x4.Multiply(translationInverseBindMatrix, invertedRotation);
                //    }

                //    // Rebuild weights to include every joint instead of just the ones with a weight > 0
                //    var weightList = (List<List<Runtime.JointWeight>>)nodes[0].Mesh.MeshPrimitives.First().VertexJointWeights;
                //    for (var weightIndex = 0; weightIndex < weightList.Count(); weightIndex++)
                //    {
                //        var jointWeight = new List<Runtime.JointWeight>();

                //        for (var skinJointIndex = 0; skinJointIndex < skinJointList.Count; skinJointIndex++)
                //        {
                //            int weightToUse = 0;
                //            // Set the weight to 1 if the skinJoint is at the same level as the vertex.
                //            // Or Set the weight to 1 if the vertex is further out than the last skinjoint and the last skinjoint is being set.
                //            if (skinJointIndex == (weightIndex / 2) || (((weightIndex / 2) > skinJointList.Count - 1) && (skinJointIndex == skinJointList.Count - 1)) )
                //            {
                //                weightToUse = 1;
                //            }

                //            jointWeight.Add(new Runtime.JointWeight
                //            {
                //                Joint = skinJointList[skinJointIndex],
                //                Weight = weightToUse,
                //            });
                //        }

                //        weightList[weightIndex] = jointWeight;
                //    }

                //    properties.Add(new Property(PropertyName.Description, "`skinF`. Each vertex has weights for more than four joints."));
                //}, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, animations, nodes) =>
                {
                    var skinA1 = Nodes.CreateFoldingPlaneSkin("skinA", 2, 3);
                    var skinA2 = Nodes.CreateFoldingPlaneSkin("skinA", 2, 3);

                    // Set the same mesh on both nodes.
                    skinA2[0].Mesh = skinA1[0].Mesh;

                    // Offset one of the models so they aren't overlapping.
                    Vector3 translation   = skinA2[1].Translation.Value;
                    skinA2[1].Translation = new Vector3(translation.X + 0.6f, translation.Y, translation.Z);

                    foreach (Runtime.Node node in skinA1)
                    {
                        nodes.Add(node);
                    }

                    foreach (Runtime.Node node in skinA2)
                    {
                        nodes.Add(node);
                    }

                    properties.Add(new Property(PropertyName.Description, "Two instances of `skinA` sharing a mesh but with separate skins."));
                }, (model) => { model.Camera = distantCamera; }),
            };

            GenerateUsedPropertiesList();
        }
        public Compatibility(List <string> imageList)
        {
            NoSampleImages = true;

            // There are no common properties in this model group.

            Model CreateModel(Action <List <Property>, Asset, List <string>, List <string>, Runtime.MeshPrimitive> setProperties,
                              Action <Loader.Gltf> postRuntimeChanges = null, Dictionary <Type, Type> schemaTypeMapping = null, bool?setLoadableTag = true)
            {
                var properties = new List <Property>();

                var gltf = CreateGLTF(() => new Scene());

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);
                var extensionsUsed     = new List <string>();
                var extensionsRequired = new List <string>();

                // Apply the properties that are specific to this gltf.
                setProperties(properties, gltf.Asset, extensionsUsed, extensionsRequired, meshPrimitive);

                // Create the gltf object.
                if (extensionsUsed.Any())
                {
                    gltf.ExtensionsUsed = extensionsUsed;
                }
                if (extensionsRequired.Any())
                {
                    gltf.ExtensionsRequired = extensionsRequired;
                }

                gltf.Scenes.First().Nodes = new List <Node>
                {
                    new Node
                    {
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitive
                            }
                        },
                    },
                };

                var model = new Model
                {
                    Properties = properties,
                    GLTF       = gltf
                };

                model.Loadable           = setLoadableTag;
                model.PostRuntimeChanges = postRuntimeChanges;

                if (schemaTypeMapping != null)
                {
                    model.CreateSchemaInstance = type =>
                    {
                        if (schemaTypeMapping.TryGetValue(type, out Type mappedType))
                        {
                            type = mappedType;
                        }

                        return(Activator.CreateInstance(type));
                    };
                }

                return(model);
            }

            Property SetMinVersion(Asset asset)
            {
                return(new Property(PropertyName.MinVersion, asset.MinVersion = "2.1"));
            }

            Property SetVersionCurrent(Asset asset)
            {
                return(new Property(PropertyName.Version, asset.Version = "2.0"));
            }

            Property SetVersionFuture(Asset asset)
            {
                return(new Property(PropertyName.Version, asset.Version = "2.1"));
            }

            void SetPostRuntimeAtRoot(Loader.Gltf gltf)
            {
                // Add an simulated feature at the root level.
                var experimentalGltf = (ExperimentalGltf)gltf;

                experimentalGltf.Lights = new[]
                {
                    new ExperimentalLight
                    {
                        Color = new[] { 0.3f, 0.4f, 0.5f }
                    }
                };
            }

            void SetPostRuntimeInProperty(Loader.Gltf gltf)
            {
                // Add an simulated feature into an existing property.
                var experimentalNode = (ExperimentalNode)gltf.Nodes[0];

                experimentalNode.Light = 0;
            }

            void SetPostRuntimeWithFallback(Loader.Gltf gltf)
            {
                // Add an simulated feature with a fallback option.
                gltf.Materials = new Loader.Material[]
                {
                    new ExperimentalMaterial
                    {
                        AlphaMode  = Loader.Material.AlphaModeEnum.BLEND,
                        AlphaMode2 = ExperimentalAlphaMode2.QUANTUM,
                    }
                };
            }

            var experimentalSchemaTypeMapping = new Dictionary <Type, Type>
            {
                { typeof(Loader.Gltf), typeof(ExperimentalGltf) },
                { typeof(Loader.Node), typeof(ExperimentalNode) },
                { typeof(Loader.Material), typeof(ExperimentalMaterial) },
            };

            var shouldLoad = ":white_check_mark:";

            Models = new List <Model>
            {
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionCurrent(asset));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, shouldLoad));
                }),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionFuture(asset));
                    properties.Add(new Property(PropertyName.Description, "Light object added at root"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, shouldLoad));
                }, SetPostRuntimeAtRoot, experimentalSchemaTypeMapping),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionFuture(asset));
                    properties.Add(new Property(PropertyName.Description, "Light property added to node object"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, shouldLoad));
                }, SetPostRuntimeInProperty, experimentalSchemaTypeMapping),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionFuture(asset));
                    properties.Add(new Property(PropertyName.Description, "Alpha mode updated with a new enum value, and a fallback value"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, shouldLoad));
                }, SetPostRuntimeWithFallback, experimentalSchemaTypeMapping),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetMinVersion(asset));
                    properties.Add(SetVersionFuture(asset));
                    properties.Add(new Property(PropertyName.Description, "Requires a specific version or higher"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, "Only in version 2.1 or higher"));
                }, null, null, setLoadableTag: false),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionCurrent(asset));

                    var extension = new FAKE_materials_quantumRendering
                    {
                        PlanckFactor                 = new Vector4(0.2f, 0.2f, 0.2f, 0.8f),
                        CopenhagenTexture            = new Texture(),
                        EntanglementFactor           = new Vector3(0.4f, 0.4f, 0.4f),
                        ProbabilisticFactor          = 0.3f,
                        SuperpositionCollapseTexture = new Texture(),
                    };

                    meshPrimitive.Material = new Runtime.Material()
                    {
                        Extensions = new List <Extension>()
                        {
                            extension
                        }
                    };

                    extensionsUsed.Add(extension.Name);
                    extensionsRequired.Add(extension.Name);

                    properties.Add(new Property(PropertyName.Description, "Extension required"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, ":x:"));
                }, null, null, setLoadableTag: false),
                CreateModel((properties, asset, extensionsUsed, extensionsRequired, meshPrimitive) => {
                    properties.Add(SetVersionCurrent(asset));

                    extensionsUsed.Add("KHR_materials_pbrSpecularGlossiness");

                    meshPrimitive.Material = new Runtime.Material()
                    {
                        // Specular-Glossiness
                        Extensions = new List <Extension>()
                        {
                            new KHR_materials_pbrSpecularGlossiness()
                            {
                                SpecularFactor   = new Vector3(0.04f, 0.04f, 0.04f),
                                GlossinessFactor = 0.0f,
                            }
                        },
                        // Metallic-Roughness Fallback
                        MetallicRoughnessMaterial = new PbrMetallicRoughness()
                        {
                            MetallicFactor = 0.0f
                        },
                    };

                    properties.Add(new Property(PropertyName.Description, "Specular Glossiness extension used but not required"));
                    properties.Add(new Property(PropertyName.ModelShouldLoad, shouldLoad));
                }),
            };

            GenerateUsedPropertiesList();
        }
Exemplo n.º 7
0
        public Material_AlphaBlend(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");

            // Track the common properties for use in the readme.
            var alphaModeValue = AlphaModeEnum.BLEND;

            CommonProperties.Add(new Property(PropertyName.AlphaMode, alphaModeValue));

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive, Runtime.PbrMetallicRoughness> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);

                // Apply the common properties to the gltf.
                meshPrimitive.Material = new Runtime.Material
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                    {
                        MetallicFactor = 0
                    },
                    AlphaMode = alphaModeValue,
                };

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive, meshPrimitive.Material.MetallicRoughnessMaterial);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene
                    {
                        Nodes = new[]
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new[]
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetNoMetallicRoughness(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.MetallicRoughnessMaterial = null;
            }

            void SetBaseColorFactor(List <Property> properties, Runtime.PbrMetallicRoughness metallicRoughness)
            {
                var baseColorFactorValue = new Vector4(1.0f, 1.0f, 1.0f, 0.7f);

                metallicRoughness.BaseColorFactor = baseColorFactorValue;
                properties.Add(new Property(PropertyName.BaseColorFactor, baseColorFactorValue));
            }

            void SetBaseColorTexture(List <Property> properties, Runtime.PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.BaseColorTexture = new Runtime.Texture {
                    Source = baseColorTextureImage
                };
                properties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage));
            }

            void SetVertexColor(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var vertexColors = new[]
                {
                    new Vector4(0.3f, 0.3f, 0.3f, 0.4f),
                    new Vector4(0.3f, 0.3f, 0.3f, 0.2f),
                    new Vector4(0.3f, 0.3f, 0.3f, 0.8f),
                    new Vector4(0.3f, 0.3f, 0.3f, 0.6f),
                };

                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.FLOAT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC4;
                meshPrimitive.Colors             = vertexColors;

                properties.Add(new Property(PropertyName.VertexColor, "Vector4 Float"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetNoMetallicRoughness(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TextureCoordSets = MeshPrimitive.GetSinglePlaneTextureCoordSets();
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TextureCoordSets = MeshPrimitive.GetSinglePlaneTextureCoordSets();
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TextureCoordSets = MeshPrimitive.GetSinglePlaneTextureCoordSets();
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TextureCoordSets = MeshPrimitive.GetSinglePlaneTextureCoordSets();
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
            };

            GenerateUsedPropertiesList();
        }
Exemplo n.º 8
0
        public static Runtime.GLTF MultiNode()
        {
            List <Vector3> vertexPositions = new List <Vector3>()
            {
                new Vector3(2.500000f, 2.500000f, 2.500000f),
                new Vector3(-2.500000f, 2.500000f, 2.500000f),
                new Vector3(-2.500000f, -2.500000f, 2.500000f),
                new Vector3(2.500000f, -2.500000f, 2.500000f),
                new Vector3(0.000000f, 2.500000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, 2.500000f),
                new Vector3(2.500000f, 2.500000f, 2.500000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(0.000000f, 7.500000f, 0.000000f),
                new Vector3(0.000000f, 7.500000f, -2.500000f),
                new Vector3(-2.500000f, 7.500000f, 0.000000f),
                new Vector3(-2.500000f, 7.500000f, -2.500000f),
                new Vector3(2.500000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 0.000000f, -7.500000f),
                new Vector3(-2.500000f, 0.000000f, -7.500000f),
                new Vector3(-2.500000f, 2.500000f, -7.500000f),
                new Vector3(0.000000f, 2.500000f, -7.500000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(2.500000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, -2.500000f, -2.500000f),
                new Vector3(2.500000f, -2.500000f, -2.500000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(2.500000f, -2.500000f, 2.500000f),
                new Vector3(-2.500000f, -2.500000f, 2.500000f),
                new Vector3(-2.500000f, -2.500000f, -2.500000f),
                new Vector3(2.500000f, -2.500000f, -2.500000f),
                new Vector3(2.500000f, 2.500000f, 2.500000f),
                new Vector3(2.500000f, -2.500000f, 2.500000f),
                new Vector3(2.500000f, 2.500000f, -2.500000f),
                new Vector3(2.500000f, -2.500000f, -2.500000f),
                new Vector3(-2.500000f, -2.500000f, -2.500000f),
                new Vector3(-2.500000f, -2.500000f, 2.500000f),
                new Vector3(-2.500000f, 0.000000f, 0.000000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, 2.500000f),
                new Vector3(-7.500000f, 2.500000f, 0.000000f),
                new Vector3(-7.500000f, 0.000000f, -2.500000f),
                new Vector3(-7.500000f, 0.000000f, 0.000000f),
                new Vector3(-7.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(-7.500000f, 0.000000f, 0.000000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, 0.000000f, 0.000000f),
                new Vector3(-7.500000f, 0.000000f, -2.500000f),
                new Vector3(-7.500000f, 2.500000f, 0.000000f),
                new Vector3(-2.500000f, 0.000000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(-7.500000f, 0.000000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-7.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(-7.500000f, 2.500000f, 0.000000f),
                new Vector3(-7.500000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(-7.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 7.500000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(0.000000f, 7.500000f, 0.000000f),
                new Vector3(0.000000f, 2.500000f, 0.000000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 7.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, 0.000000f),
                new Vector3(0.000000f, 7.500000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 7.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 7.500000f, -2.500000f),
                new Vector3(-2.500000f, 7.500000f, 0.000000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, 0.000000f),
                new Vector3(-2.500000f, 7.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, -7.500000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, -7.500000f),
                new Vector3(0.000000f, 0.000000f, -2.500000f),
                new Vector3(0.000000f, 0.000000f, -7.500000f),
                new Vector3(0.000000f, 2.500000f, -2.500000f),
                new Vector3(0.000000f, 2.500000f, -7.500000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, 0.000000f, -7.500000f),
                new Vector3(0.000000f, 0.000000f, -2.500000f),
                new Vector3(0.000000f, 0.000000f, -7.500000f),
                new Vector3(-2.500000f, 2.500000f, -2.500000f),
                new Vector3(-2.500000f, 2.500000f, -7.500000f),
                new Vector3(-2.500000f, 0.000000f, -2.500000f),
                new Vector3(-2.500000f, 0.000000f, -7.500000f),
                new Vector3(3.000000f, -1.000000f, 3.000000f),
                new Vector3(-7.500000f, -1.000000f, 7.500000f),
                new Vector3(3.000000f, -1.000000f, 7.500000f),
                new Vector3(-7.500000f, -1.000000f, 3.000000f),
                new Vector3(7.500000f, -1.000000f, 7.500000f),
                new Vector3(7.500000f, -1.000000f, 3.000000f),
                new Vector3(7.500000f, -1.000000f, -7.500000f),
                new Vector3(3.000000f, -1.000000f, -7.500000f),
            };


            List <List <Vector2> > textureCoordSets = new List <List <Vector2> >
            {
                new List <Vector2>
                {
                    new Vector2(0.788554f, 0.205935f),
                    new Vector2(0.584720f, 0.205900f),
                    new Vector2(0.584685f, 0.409734f),
                    new Vector2(0.788519f, 0.409769f),
                    new Vector2(0.471918f, 0.880496f),
                    new Vector2(0.369983f, 0.982396f),
                    new Vector2(0.573817f, 0.982430f),
                    new Vector2(0.370001f, 0.880479f),
                    new Vector2(0.232172f, 0.857846f),
                    new Vector2(0.232064f, 0.959100f),
                    new Vector2(0.333426f, 0.857955f),
                    new Vector2(0.333317f, 0.959208f),
                    new Vector2(0.573852f, 0.778596f),
                    new Vector2(0.471935f, 0.778579f),
                    new Vector2(0.249236f, 0.325688f),
                    new Vector2(0.249140f, 0.426797f),
                    new Vector2(0.350249f, 0.426892f),
                    new Vector2(0.350345f, 0.325783f),
                    new Vector2(0.573870f, 0.676679f),
                    new Vector2(0.573852f, 0.778596f),
                    new Vector2(0.675786f, 0.676697f),
                    new Vector2(0.777721f, 0.574797f),
                    new Vector2(0.777686f, 0.778631f),
                    new Vector2(0.675804f, 0.574780f),
                    new Vector2(0.777652f, 0.982465f),
                    new Vector2(0.981486f, 0.982500f),
                    new Vector2(0.981520f, 0.778666f),
                    new Vector2(0.777686f, 0.778631f),
                    new Vector2(0.573817f, 0.982430f),
                    new Vector2(0.777652f, 0.982465f),
                    new Vector2(0.573852f, 0.778596f),
                    new Vector2(0.777686f, 0.778631f),
                    new Vector2(0.380851f, 0.409699f),
                    new Vector2(0.584685f, 0.409734f),
                    new Vector2(0.482785f, 0.307799f),
                    new Vector2(0.380868f, 0.307782f),
                    new Vector2(0.584720f, 0.205900f),
                    new Vector2(0.225056f, 0.327032f),
                    new Vector2(0.124248f, 0.226196f),
                    new Vector2(0.124234f, 0.327018f),
                    new Vector2(0.225070f, 0.226211f),
                    new Vector2(0.482803f, 0.205882f),
                    new Vector2(0.023427f, 0.226182f),
                    new Vector2(0.124277f, 0.024553f),
                    new Vector2(0.023455f, 0.024539f),
                    new Vector2(0.124248f, 0.226196f),
                    new Vector2(0.325892f, 0.226224f),
                    new Vector2(0.426742f, 0.024595f),
                    new Vector2(0.325920f, 0.024581f),
                    new Vector2(0.426714f, 0.226239f),
                    new Vector2(0.225098f, 0.024567f),
                    new Vector2(0.225070f, 0.226211f),
                    new Vector2(0.325920f, 0.024581f),
                    new Vector2(0.325892f, 0.226224f),
                    new Vector2(0.124248f, 0.226196f),
                    new Vector2(0.225098f, 0.024567f),
                    new Vector2(0.124277f, 0.024553f),
                    new Vector2(0.225070f, 0.226211f),
                    new Vector2(0.333426f, 0.857955f),
                    new Vector2(0.333643f, 0.655447f),
                    new Vector2(0.232172f, 0.857846f),
                    new Vector2(0.232389f, 0.655338f),
                    new Vector2(0.131136f, 0.655230f),
                    new Vector2(0.130919f, 0.857737f),
                    new Vector2(0.232389f, 0.655338f),
                    new Vector2(0.232172f, 0.857846f),
                    new Vector2(0.029882f, 0.655121f),
                    new Vector2(0.029664f, 0.857629f),
                    new Vector2(0.131136f, 0.655230f),
                    new Vector2(0.130919f, 0.857737f),
                    new Vector2(0.333426f, 0.857955f),
                    new Vector2(0.434897f, 0.655555f),
                    new Vector2(0.333643f, 0.655447f),
                    new Vector2(0.434680f, 0.858063f),
                    new Vector2(0.451167f, 0.629205f),
                    new Vector2(0.451358f, 0.426988f),
                    new Vector2(0.350058f, 0.629110f),
                    new Vector2(0.350249f, 0.426892f),
                    new Vector2(0.552276f, 0.629301f),
                    new Vector2(0.552467f, 0.427083f),
                    new Vector2(0.451167f, 0.629205f),
                    new Vector2(0.451358f, 0.426988f),
                    new Vector2(0.248950f, 0.629014f),
                    new Vector2(0.249140f, 0.426797f),
                    new Vector2(0.147841f, 0.628919f),
                    new Vector2(0.148031f, 0.426701f),
                    new Vector2(0.350058f, 0.629110f),
                    new Vector2(0.350249f, 0.426892f),
                    new Vector2(0.248950f, 0.629014f),
                    new Vector2(0.249140f, 0.426797f),
                    new Vector2(0.820246f, 0.187538f),
                    new Vector2(0.979596f, 0.559354f),
                    new Vector2(0.979596f, 0.187538f),
                    new Vector2(0.820247f, 0.559354f),
                    new Vector2(0.979596f, 0.028188f),
                    new Vector2(0.820247f, 0.028188f),
                    new Vector2(0.448431f, 0.028188f),
                    new Vector2(0.448431f, 0.187538f),
                },
            };

            List <Vector3> vertexNormals = new List <Vector3>()
            {
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(0.000000f, 0.000000f, 1.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(0.000000f, 0.000000f, -1.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(1.000000f, 0.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(0.000000f, -1.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(-1.000000f, 0.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
                new Vector3(0.000000f, 1.000000f, 0.000000f),
            };

            List <Vector4> vertexTangents = new List <Vector4>()
            {
                new Vector4(1.000000f, 0.000170f, 0.000000f, 1.000000f),
                new Vector4(1.000000f, 0.000171f, 0.000000f, 1.000000f),
                new Vector4(1.000000f, 0.000172f, 0.000000f, 1.000000f),
                new Vector4(1.000000f, 0.000171f, 0.000000f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000170f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000170f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000170f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000171f, 1.000000f),
                new Vector4(-0.999999f, 0.000000f, 0.001072f, 1.000000f),
                new Vector4(-0.999999f, 0.000000f, 0.001072f, 1.000000f),
                new Vector4(-0.999999f, 0.000000f, 0.001071f, 1.000000f),
                new Vector4(-0.999999f, 0.000000f, 0.001072f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000171f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000171f, 1.000000f),
                new Vector4(0.000947f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000947f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000947f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000947f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000172f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000171f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000171f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000170f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000169f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.000172f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000169f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000170f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000171f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000170f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000170f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000171f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000169f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000170f, 1.000000f),
                new Vector4(0.000000f, 0.000169f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000172f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000170f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000168f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000172f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000140f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000141f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000140f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000140f, 1.000000f),
                new Vector4(0.000000f, 0.000170f, 1.000000f, 1.000000f),
                new Vector4(0.000140f, 0.000000f, -1.000000f, 1.000000f),
                new Vector4(0.000142f, 0.000000f, -1.000000f, 1.000000f),
                new Vector4(0.000141f, 0.000000f, -1.000000f, 1.000000f),
                new Vector4(0.000141f, 0.000000f, -1.000000f, 1.000000f),
                new Vector4(0.000140f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000140f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000140f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000140f, -1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000139f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000138f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000140f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000139f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000141f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000138f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000140f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(0.000140f, 1.000000f, 0.000000f, 1.000000f),
                new Vector4(-0.999999f, -0.001071f, 0.000000f, 1.000000f),
                new Vector4(-0.999999f, -0.001071f, 0.000000f, 1.000000f),
                new Vector4(-0.999999f, -0.001071f, 0.000000f, 1.000000f),
                new Vector4(-0.999999f, -0.001071f, 0.000000f, 1.000000f),
                new Vector4(0.000000f, -0.001073f, 0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001075f, 0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001071f, 0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001073f, 0.999999f, 1.000000f),
                new Vector4(0.999999f, -0.001073f, 0.000000f, 1.000000f),
                new Vector4(0.999999f, -0.001072f, 0.000000f, 1.000000f),
                new Vector4(0.999999f, -0.001074f, 0.000000f, 1.000000f),
                new Vector4(0.999999f, -0.001073f, 0.000000f, 1.000000f),
                new Vector4(0.000000f, -0.001071f, -0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001074f, -0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001073f, -0.999999f, 1.000000f),
                new Vector4(0.000000f, -0.001073f, -0.999999f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000942f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000943f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000941f, 1.000000f),
                new Vector4(1.000000f, 0.000000f, -0.000942f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000944f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000943f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000946f, 1.000000f),
                new Vector4(0.000000f, -1.000000f, -0.000944f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000941f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000941f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000942f, 1.000000f),
                new Vector4(-1.000000f, 0.000000f, -0.000941f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000946f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000947f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000945f, 1.000000f),
                new Vector4(0.000000f, 1.000000f, -0.000946f, 1.000000f),
                new Vector4(0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(-0.000001f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(-0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(-0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000000f, 1.000000f, 1.000000f),
                new Vector4(0.000000f, 0.000000f, 1.000000f, 1.000000f),
            };

            List <int> indices0 = new List <int>
            {
                90, 91, 92, 91, 90, 93, 94, 95, 92, 92, 95, 90, 96, 90, 95, 90, 96, 97,
            };
            List <int> indices1 = new List <int>
            {
                0, 1, 2, 0, 2, 3, 4, 5, 6, 5, 4, 7, 8, 9, 10, 10, 9, 11, 6, 12, 4, 4, 12, 13, 14, 15, 16, 14, 16, 17, 18, 19,
                20, 21, 20, 22, 20, 21, 23, 20, 19, 22, 24, 25, 26, 24, 26, 27, 28, 29, 30, 29, 31, 30, 32, 33, 34, 32, 34, 35,
                33, 36, 34, 37, 38, 39, 38, 37, 40, 34, 36, 41, 42, 43, 44, 43, 42, 45, 46, 47, 48, 47, 46, 49, 50, 51, 52, 53,
                52, 51, 54, 55, 56, 55, 54, 57, 58, 59, 60, 60, 59, 61, 62, 63, 64, 65, 64, 63, 66, 67, 68, 68, 67, 69, 70, 71,
                72, 71, 70, 73, 74, 75, 76, 76, 75, 77, 78, 79, 80, 80, 79, 81, 82, 83, 84, 84, 83, 85, 86, 87, 88, 88, 87, 89,
            };


            Runtime.GLTF  wrapper = new Runtime.GLTF();
            Runtime.Scene scene   = new Runtime.Scene();
            Runtime.Mesh  mesh0   = new Runtime.Mesh();
            Runtime.Mesh  mesh1   = new Runtime.Mesh();
            scene.Nodes = new List <Runtime.Node>();

            Runtime.MeshPrimitive meshPrim0 = new Runtime.MeshPrimitive
            {
                Positions        = vertexPositions,
                TextureCoordSets = textureCoordSets,
                Normals          = vertexNormals,
                Tangents         = vertexTangents,
                Indices          = indices0,
            };
            mesh0.MeshPrimitives = new List <Runtime.MeshPrimitive> {
                meshPrim0
            };
            scene.Nodes.Add(
                new Runtime.Node
            {
                Mesh = mesh0,
                Name = "Node0"
            });

            Runtime.MeshPrimitive meshPrim1 = new Runtime.MeshPrimitive
            {
                Positions        = vertexPositions,
                TextureCoordSets = textureCoordSets,
                Normals          = vertexNormals,
                Tangents         = vertexTangents,
                Indices          = indices1,
            };
            mesh1.MeshPrimitives = new List <Runtime.MeshPrimitive> {
                meshPrim1
            };
            scene.Nodes[0].Children = new List <Runtime.Node>();
            scene.Nodes[0].Children.Add(
                new Runtime.Node
            {
                Mesh = mesh1,
                Name = "Node1"
            });

            wrapper.Scenes.Add(scene);

            return(wrapper);
        }
Exemplo n.º 9
0
        public static Runtime.GLTF SingleCube()
        {
            List <Vector3> cubePositions = new List <Vector3>()
            {
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f)
            };
            List <Vector3> cubeNormals = new List <Vector3>()
            {
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, 0.0f, -1.0f),
                new Vector3(0.0f, -1.0f, 0.0f),
                new Vector3(0.0f, -1.0f, 0.0f),
                new Vector3(0.0f, -1.0f, 0.0f),
                new Vector3(0.0f, -1.0f, 0.0f)
            };

            List <List <Vector2> > cubeTextureCoordSets = new List <List <Vector2> >
            {
                new List <Vector2>
                {
                    new Vector2(0.125f, 1.0f),
                    new Vector2(0.375f, 1.0f),
                    new Vector2(0.375f, 0.75f),
                    new Vector2(0.125f, 0.75f),
                    new Vector2(0.375f, 1.00f),
                    new Vector2(0.625f, 1.00f),
                    new Vector2(0.625f, 0.75f),
                    new Vector2(0.375f, 0.75f),
                    new Vector2(0.625f, 1.00f),
                    new Vector2(0.875f, 1.00f),
                    new Vector2(0.875f, 0.75f),
                    new Vector2(0.625f, 0.75f),
                    new Vector2(0.375f, 0.75f),
                    new Vector2(0.625f, 0.75f),
                    new Vector2(0.625f, 0.5f),
                    new Vector2(0.375f, 0.5f),
                    new Vector2(0.375f, 0.5f),
                    new Vector2(0.625f, 0.5f),
                    new Vector2(0.625f, 0.25f),
                    new Vector2(0.375f, 0.25f),
                    new Vector2(0.375f, 0.25f),
                    new Vector2(0.625f, 0.25f),
                    new Vector2(0.625f, 0.0f),
                    new Vector2(0.375f, 0.0f)
                },
            };
            List <int> cubeIndices = new List <int>
            {
                0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23
            };

            Runtime.GLTF          wrapper  = new Runtime.GLTF();
            Runtime.Scene         scene    = new Runtime.Scene();
            Runtime.Mesh          mesh     = new Runtime.Mesh();
            Runtime.MeshPrimitive meshPrim = new Runtime.MeshPrimitive
            {
                Positions        = cubePositions,
                Normals          = cubeNormals,
                TextureCoordSets = cubeTextureCoordSets,
                Indices          = cubeIndices
            };
            mesh.MeshPrimitives = new List <Runtime.MeshPrimitive> {
                meshPrim
            };
            scene.Nodes = new List <Runtime.Node>
            {
                new Runtime.Node
                {
                    Mesh = mesh
                }
            };
            wrapper.Scenes.Add(scene);

            return(wrapper);
        }
        public Buffer_Interleaved(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Grey");

            // Track the common properties for use in the readme.
            CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage));

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane();

                // Apply the common properties to the gltf.
                meshPrimitive.Interleave = true;
                meshPrimitive.Colors     = new[]
                {
                    new Vector4(0.0f, 1.0f, 0.0f, 0.2f),
                    new Vector4(1.0f, 0.0f, 0.0f, 0.2f),
                    new Vector4(1.0f, 1.0f, 0.0f, 0.2f),
                    new Vector4(0.0f, 0.0f, 1.0f, 0.2f),
                };
                meshPrimitive.Material = new Runtime.Material()
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness()
                    {
                        BaseColorTexture = new Runtime.Texture()
                        {
                            Source  = baseColorTextureImage,
                            Sampler = new Runtime.Sampler(),
                        },
                    },
                };

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene()
                    {
                        Nodes = new[]
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new[]
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetUvTypeFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TextureCoordsComponentType = TextureCoordsComponentTypeEnum.FLOAT;
                properties.Add(new Property(PropertyName.VertexUV0, "Float"));
            }

            void SetUvTypeTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TextureCoordsComponentType = TextureCoordsComponentTypeEnum.NORMALIZED_UBYTE;
                properties.Add(new Property(PropertyName.VertexUV0, "Byte"));
            }

            void SetUvTypeTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TextureCoordsComponentType = TextureCoordsComponentTypeEnum.NORMALIZED_USHORT;
                properties.Add(new Property(PropertyName.VertexUV0, "Short"));
            }

            void SetColorTypeFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.FLOAT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;
                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Float"));
            }

            void SetColorTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_UBYTE;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;
                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Byte"));
            }

            void SetColorTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_USHORT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;
                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Short"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) => {
                    SetUvTypeFloat(properties, meshPrimitive);
                    SetColorTypeFloat(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetUvTypeFloat(properties, meshPrimitive);
                    SetColorTypeByte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetUvTypeFloat(properties, meshPrimitive);
                    SetColorTypeShort(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetUvTypeTypeByte(properties, meshPrimitive);
                    SetColorTypeFloat(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetUvTypeTypeShort(properties, meshPrimitive);
                    SetColorTypeFloat(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }
Exemplo n.º 11
0
        public Material(List <string> imageList)
        {
            Runtime.Image emissiveImage  = UseTexture(imageList, "Emissive_Plane");
            Runtime.Image normalImage    = UseTexture(imageList, "Normal_Plane");
            Runtime.Image occlusionImage = UseTexture(imageList, "Occlusion_Plane");

            // Track the common properties for use in the readme.
            var metallicFactorValue  = 0.0f;
            var baseColorFactorValue = new Vector4(0.2f, 0.2f, 0.2f, 1.0f);

            CommonProperties.Add(new Property(PropertyName.MetallicFactor, metallicFactorValue));
            CommonProperties.Add(new Property(PropertyName.BaseColorFactor, baseColorFactorValue));

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive, Runtime.Material> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane();
                meshPrimitive.Material = new Runtime.Material();
                meshPrimitive.Material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness();

                // Apply the common properties to the gltf.
                meshPrimitive.Material.MetallicRoughnessMaterial.MetallicFactor  = metallicFactorValue;
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorFactor = baseColorFactorValue;

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive, meshPrimitive.Material);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene()
                    {
                        Nodes = new List <Runtime.Node>
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetNormalTexture(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var planeNormalsValue = new[]
                {
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(0.0f, 0.0f, 1.0f),
                };

                meshPrimitive.Normals = planeNormalsValue;
                meshPrimitive.Material.NormalTexture = new Runtime.Texture {
                    Source = normalImage
                };
                properties.Add(new Property(PropertyName.NormalTexture, normalImage));
            }

            void SetNormalScale(List <Property> properties, Runtime.Material material)
            {
                material.NormalScale = 10.0f;
                properties.Add(new Property(PropertyName.NormalTextureScale, material.NormalScale));
            }

            void SetOcclusionTexture(List <Property> properties, Runtime.Material material)
            {
                material.OcclusionTexture = new Runtime.Texture {
                    Source = occlusionImage
                };
                properties.Add(new Property(PropertyName.OcclusionTexture, occlusionImage));
            }

            void SetOcclusionStrength(List <Property> properties, Runtime.Material material)
            {
                material.OcclusionStrength = 0.5f;
                properties.Add(new Property(PropertyName.OcclusionTextureStrength, material.OcclusionStrength));
            }

            void SetEmissiveTexture(List <Property> properties, Runtime.Material material)
            {
                material.EmissiveTexture = new Runtime.Texture {
                    Source = emissiveImage
                };
                properties.Add(new Property(PropertyName.EmissiveTexture, emissiveImage));
            }

            void SetEmissiveFactor(List <Property> properties, Runtime.Material material)
            {
                var emissiveFactorValue = new Vector3(1.0f, 1.0f, 1.0f);

                material.EmissiveFactor = emissiveFactorValue;
                properties.Add(new Property(PropertyName.EmissiveFactor, emissiveFactorValue));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive, material) => {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetOcclusionTexture(properties, material);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetEmissiveFactor(properties, material);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetNormalTexture(properties, meshPrimitive);
                    SetNormalScale(properties, material);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetOcclusionTexture(properties, material);
                    SetOcclusionStrength(properties, material);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetEmissiveTexture(properties, material);
                    SetEmissiveFactor(properties, material);
                }),
                CreateModel((properties, meshPrimitive, material) => {
                    SetNormalTexture(properties, meshPrimitive);
                    SetNormalScale(properties, material);
                    SetOcclusionTexture(properties, material);
                    SetOcclusionStrength(properties, material);
                    SetEmissiveTexture(properties, material);
                    SetEmissiveFactor(properties, material);
                }),
            };

            GenerateUsedPropertiesList();
        }
        public Mesh_PrimitiveVertexColor(List <string> imageList)
        {
            // There are no common properties in this model group that are reported in the readme.
            var vertexColors = new List <Vector4>()
            {
                new Vector4(0.0f, 1.0f, 0.0f, 0.2f),
                new Vector4(1.0f, 0.0f, 0.0f, 0.2f),
                new Vector4(1.0f, 1.0f, 0.0f, 0.2f),
                new Vector4(0.0f, 0.0f, 1.0f, 0.2f),
            };

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);

                // Apply the common properties to the gltf.
                meshPrimitive.Colors = vertexColors;

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene()
                    {
                        Nodes = new List <Runtime.Node>
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetVertexColorVec3Float(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.FLOAT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;

                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Float"));
            }

            void SetVertexColorVec3Byte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_UBYTE;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;

                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Byte"));
            }

            void SetVertexColorVec3Short(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_USHORT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC3;

                properties.Add(new Property(PropertyName.VertexColor, "Vector3 Short"));
            }

            void SetVertexColorVec4Float(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.FLOAT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC4;

                properties.Add(new Property(PropertyName.VertexColor, "Vector4 Float"));
            }

            void SetVertexColorVec4Byte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_UBYTE;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC4;

                properties.Add(new Property(PropertyName.VertexColor, "Vector4 Byte"));
            }

            void SetVertexColorVec4Short(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.ColorComponentType = ColorComponentTypeEnum.NORMALIZED_USHORT;
                meshPrimitive.ColorType          = ColorTypeEnum.VEC4;

                properties.Add(new Property(PropertyName.VertexColor, "Vector4 Short"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec3Float(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec3Byte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec3Short(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec4Float(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec4Byte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) => {
                    SetVertexColorVec4Short(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }
Exemplo n.º 13
0
        public Texture_Sampler(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");

            // Track the common properties for use in the readme.
            CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage));

            Model CreateModel(Action <List <Property>, Runtime.Sampler> setProperties)
            {
                var properties = new List <Property>();

                Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane();
                meshPrimitive.Material = new Runtime.Material
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                    {
                        BaseColorTexture = new Runtime.Texture
                        {
                            Source  = baseColorTextureImage,
                            Sampler = new Runtime.Sampler(),
                        },
                    },
                };

                // Apply the common properties to the gltf.
                meshPrimitive.TextureCoordSets = new List <List <Vector2> >
                {
                    new List <Vector2>()
                    {
                        new Vector2(1.3f, 1.3f),
                        new Vector2(-0.3f, 1.3f),
                        new Vector2(-0.3f, -0.3f),
                        new Vector2(1.3f, -0.3f),
                    }
                };

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture.Sampler);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene
                    {
                        Nodes = new List <Runtime.Node>
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = new List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetWrapT(List <Property> properties, Runtime.Sampler sampler, WrapTEnum enumValue)
            {
                sampler.WrapT = enumValue;
                properties.Add(new Property(PropertyName.WrapT, enumValue));
            }

            void SetWrapS(List <Property> properties, Runtime.Sampler sampler, WrapSEnum enumValue)
            {
                sampler.WrapS = enumValue;
                properties.Add(new Property(PropertyName.WrapS, sampler.WrapS));
            }

            void SetMagFilter(List <Property> properties, Runtime.Sampler sampler, MagFilterEnum enumValue)
            {
                sampler.MagFilter = enumValue;
                properties.Add(new Property(PropertyName.MagFilter, enumValue));
            }

            void SetMinFilter(List <Property> properties, Runtime.Sampler sampler, MinFilterEnum enumValue)
            {
                sampler.MinFilter = enumValue;
                properties.Add(new Property(PropertyName.MinFilter, enumValue));
            }

            Models = new List <Model>
            {
                CreateModel((properties, sampler) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, WrapTEnum.CLAMP_TO_EDGE);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, WrapTEnum.MIRRORED_REPEAT);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapS(properties, sampler, WrapSEnum.CLAMP_TO_EDGE);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapS(properties, sampler, WrapSEnum.MIRRORED_REPEAT);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMagFilter(properties, sampler, MagFilterEnum.NEAREST);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMagFilter(properties, sampler, MagFilterEnum.LINEAR);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.NEAREST);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.LINEAR);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.NEAREST_MIPMAP_NEAREST);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.LINEAR_MIPMAP_NEAREST);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.NEAREST_MIPMAP_LINEAR);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, MinFilterEnum.LINEAR_MIPMAP_LINEAR);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, WrapTEnum.CLAMP_TO_EDGE);
                    SetWrapS(properties, sampler, WrapSEnum.CLAMP_TO_EDGE);
                    SetMagFilter(properties, sampler, MagFilterEnum.NEAREST);
                    SetMinFilter(properties, sampler, MinFilterEnum.NEAREST);
                }),
            };

            GenerateUsedPropertiesList();
        }