Example #1
0
        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 <Schema.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(Schema.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(Schema.Gltf gltf)
            {
                // Add an simulated feature into an existing property.
                var experimentalNode = (ExperimentalNode)gltf.Nodes[0];

                experimentalNode.Light = 0;
            }

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

            var experimentalSchemaTypeMapping = new Dictionary <Type, Type>
            {
                { typeof(Schema.Gltf), typeof(ExperimentalGltf) },
                { typeof(Schema.Node), typeof(ExperimentalNode) },
                { typeof(Schema.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 emptyTexture = new Texture();
                    var extension    = new FAKE_materials_quantumRendering
                    {
                        PlanckFactor      = new Vector4(0.2f, 0.2f, 0.2f, 0.8f),
                        CopenhagenTexture = new TextureInfo
                        {
                            Texture = emptyTexture
                        },
                        EntanglementFactor           = new Vector3(0.4f, 0.4f, 0.4f),
                        ProbabilisticFactor          = 0.3f,
                        SuperpositionCollapseTexture = new TextureInfo
                        {
                            Texture = emptyTexture
                        },
                    };

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

                    var extension = new KHR_materials_pbrSpecularGlossiness
                    {
                        SpecularFactor   = new Vector3(0.04f, 0.04f, 0.04f),
                        GlossinessFactor = 0.0f,
                    };

                    meshPrimitive.Material = new Runtime.Material
                    {
                        // Metallic-Roughness
                        PbrMetallicRoughness = new PbrMetallicRoughness
                        {
                            MetallicFactor = 0.0f
                        },
                        // Specular-Glossiness
                        Extensions = new[] { extension },
                    };

                    extensionsUsed.Add(extension.Name);

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

            GenerateUsedPropertiesList();
        }
        public Buffer_Interleaved(List <string> imageList)
        {
            var 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>();
                var 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 = Runtime.MeshPrimitive.TextureCoordsComponentTypeEnum.FLOAT;
                properties.Add(new Property(PropertyName.VertexUV0, "Float"));
            }

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

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

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

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

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

            this.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();
        }
Example #3
0
        public Buffer_Misc(List <string> imageList)
        {
            Model CreateModel(Action <List <Property>, AnimationChannel, Node> setProperties)
            {
                var properties = new List <Property>();

                // Apply the common properties to the glTF.
                var node = new Node
                {
                    Mesh = new Runtime.Mesh
                    {
                        MeshPrimitives = new[]
                        {
                            MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
                        }
                    },
                    Scale = new Vector3(0.8f)
                };

                var channel = new AnimationChannel();

                // Apply the proerties that are specific to this glTF
                setProperties(properties, channel, node);

                // Create the glTF object
                GLTF gltf = CreateGLTF(() => new Scene
                {
                    Nodes = new[]
                    {
                        node
                    },
                });

                gltf.Animations = new[]
                {
                    new Animation
                    {
                        Channels = new List <AnimationChannel>
                        {
                            channel
                        }
                    }
                };

                return(new Model
                {
                    Properties = properties,
                    GLTF = gltf,
                    Animated = true,
                    SeparateBuffers = true,
                });
            }

            void setTranslationChanneltarget(AnimationChannel channel, Node node)
            {
                channel.Target = new AnimationChannelTarget
                {
                    Node = node,
                    Path = AnimationChannelTargetPath.Translation,
                };
            }

            void SetLinearSamplerForTranslation(AnimationChannel channel)
            {
                channel.Sampler = new AnimationSampler
                {
                    Interpolation = AnimationSamplerInterpolation.Linear,
                    Input         = Data.Create(new[]
                    {
                        0.0f,
                        2.0f,
                        4.0f,
                    }),
                    Output = Data.Create(new[]
                    {
                        new Vector3(-0.1f, 0.0f, 0.0f),
                        new Vector3(0.1f, 0.0f, 0.0f),
                        new Vector3(-0.1f, 0.0f, 0.0f),
                    }),
                };
            }

            Models = new List <Model>
            {
                CreateModel((properties, channel, node) =>
                {
                    setTranslationChanneltarget(channel, node);
                    SetLinearSamplerForTranslation(channel);
                    properties.Add(new Property(PropertyName.Description, "The mesh primitive and animation data are stored in separate buffers."));
                })
            };

            GenerateUsedPropertiesList();
        }
        public Material_AlphaMask(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");

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

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

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

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

                // Apply the common properties to the gltf.
                meshPrimitive.Material.AlphaMode = alphaModeValue;
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture {
                    Source = baseColorTextureImage
                };

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitive.Material, 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 List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

            void SetAlphaCutoff_Low(List <Property> properties, Runtime.Material material)
            {
                material.AlphaCutoff = 0.4f;
                properties.Add(new Property(PropertyName.AlphaCutoff, material.AlphaCutoff));
            }

            void SetAlphaCutoff_High(List <Property> properties, Runtime.Material material)
            {
                material.AlphaCutoff = 0.7f;
                properties.Add(new Property(PropertyName.AlphaCutoff, material.AlphaCutoff));
            }

            void SetAlphaCutoff_Multiplied(List <Property> properties, Runtime.Material material)
            {
                material.AlphaCutoff = 0.6f;
                properties.Add(new Property(PropertyName.AlphaCutoff, material.AlphaCutoff));
            }

            void SetAlphaCutoff_All(List <Property> properties, Runtime.Material material)
            {
                material.AlphaCutoff = 1.1f;
                properties.Add(new Property(PropertyName.AlphaCutoff, material.AlphaCutoff));
            }

            void SetAlphaCutoff_None(List <Property> properties, Runtime.Material material)
            {
                material.AlphaCutoff = 0.0f;
                properties.Add(new Property(PropertyName.AlphaCutoff, material.AlphaCutoff));
            }

            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));
            }

            Models = new List <Model>
            {
                CreateModel((properties, material, metallicRoughness) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_Low(properties, material);
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_High(properties, material);
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_All(properties, material);
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_None(properties, material);
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_Low(properties, material);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, material, metallicRoughness) =>
                {
                    SetAlphaCutoff_Multiplied(properties, material);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
            };

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

            var colors = new[]
            {
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
            };

            Data <Vector3> GetColors3()
            {
                return(Data.Create(colors));
            }

            Data <Vector4> GetColors4()
            {
                return(Data.Create(colors.Select(color => new Vector4(color, 0.2f))));
            }

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

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

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

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

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors3();
                    meshPrimitive.Colors.OutputType = DataType.Float;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors3();
                    meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedByte;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors3();
                    meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedShort;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors4();
                    meshPrimitive.Colors.OutputType = DataType.Float;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector4 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors4();
                    meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedByte;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector4 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    meshPrimitive.Colors            = GetColors4();
                    meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedShort;
                    properties.Add(new Property(PropertyName.VertexColor, $"Vector4 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #6
0
        public Mesh_PrimitiveAttribute(List <string> imageList)
        {
            var baseColorTexture = new Texture {
                Source = UseTexture(imageList, "BaseColor_Plane")
            };
            var normalTexture = new Texture {
                Source = UseTexture(imageList, "Normal_Plane")
            };

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

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

                meshPrimitive.Material = new Runtime.Material();

                // Apply the common properties to the gltf.
                meshPrimitive.Material.PbrMetallicRoughness = new PbrMetallicRoughness
                {
                    BaseColorTexture = new TextureInfo {
                        Texture = baseColorTexture
                    },
                };

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

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

            void SetVertexUVFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.Float;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetVertexUVByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedByte;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetVertexUVShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedShort;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetVertexNormal(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var normals = MeshPrimitive.GetSinglePlaneNormals();

                meshPrimitive.Normals = Data.Create(normals);
                properties.Add(new Property(PropertyName.VertexNormal, normals.ToReadmeString()));
            }

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

                meshPrimitive.Tangents = Data.Create(tangents);
                properties.Add(new Property(PropertyName.VertexTangent, tangents.ToReadmeString()));
            }

            void SetNormalTexture(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.NormalTexture = new NormalTextureInfo {
                    Texture = normalTexture
                };
                properties.Add(new Property(PropertyName.NormalTexture, normalTexture.Source.ToReadmeString()));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVByte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVShort(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                    SetVertexTangent(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
            };

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

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

            Model CreateModel(Action <List <Property>, Runtime.GLTF> setProperties, Action <glTFLoader.Schema.Gltf> postRuntimeChanges = null, Dictionary <Type, Type> schemaTypeMapping = null)
            {
                var properties    = new List <Property>();
                var meshPrimitive = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);
                var gltf          = CreateGLTF(() => new Runtime.Scene
                {
                    Nodes = new List <Runtime.Node>
                    {
                        new Runtime.Node
                        {
                            Mesh = new Runtime.Mesh
                            {
                                MeshPrimitives = new List <Runtime.MeshPrimitive>
                                {
                                    meshPrimitive
                                }
                            },
                        },
                    },
                });

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

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

                // Create the gltf object
                var model = new Model
                {
                    Properties = properties,
                    GLTF       = gltf
                };

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

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

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

                return(model);
            }

            void SetMinVersion(List <Property> properties, Runtime.GLTF gltf)
            {
                gltf.Asset.MinVersion = "2.1";
                properties.Add(new Property(PropertyName.MinVersion, gltf.Asset.MinVersion));
            }

            void SetVersionCurrent(List <Property> properties, Runtime.GLTF gltf)
            {
                gltf.Asset.Version = "2.0";
                properties.Add(new Property(PropertyName.Version, gltf.Asset.Version));
            }

            void SetVersionFuture(List <Property> properties, Runtime.GLTF gltf)
            {
                gltf.Asset.Version = "2.1";
                properties.Add(new Property(PropertyName.Version, gltf.Asset.Version));
            }

            void SetDescription(List <Property> properties, string description)
            {
                properties.Add(new Property(PropertyName.Description, description));
            }

            void SetDescriptionExtensionRequired(List <Property> properties, Runtime.GLTF gltf)
            {
                var extension = new Runtime.Extensions.FAKE_materials_quantumRendering
                {
                    PlanckFactor                 = new Vector4(0.2f, 0.2f, 0.2f, 0.8f),
                    CopenhagenTexture            = new Runtime.Texture(),
                    EntanglementFactor           = new Vector3(0.4f, 0.4f, 0.4f),
                    ProbabilisticFactor          = 0.3f,
                    SuperpositionCollapseTexture = new Runtime.Texture(),
                };

                gltf.Scenes.First().Nodes.First().Mesh.MeshPrimitives.First().Material = new Runtime.Material()
                {
                    Extensions = new List <Runtime.Extensions.Extension>()
                    {
                        extension
                    }
                };

                gltf.ExtensionsRequired = new List <string>()
                {
                    extension.Name
                };

                properties.Add(new Property(PropertyName.Description, "Extension required"));
            }

            void SetModelShouldLoad(List <Property> properties, string loadableStatus = ":white_check_mark:")
            {
                properties.Add(new Property(PropertyName.ModelShouldLoad, loadableStatus));
            }

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

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

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

                experimentalNode.Light = 0;
            }

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

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

            this.Models = new List <Model>
            {
                CreateModel((properties, gltf) => {
                    SetVersionCurrent(properties, gltf);
                    SetModelShouldLoad(properties);
                }),
                CreateModel((properties, gltf) => {
                    SetVersionFuture(properties, gltf);
                    SetDescription(properties, "Light object added at root");
                    SetModelShouldLoad(properties);
                }, SetPostRuntimeAtRoot, experimentalSchemaTypeMapping),
                CreateModel((properties, gltf) => {
                    SetVersionFuture(properties, gltf);
                    SetDescription(properties, "Light property added to node object");
                    SetModelShouldLoad(properties);
                }, SetPostRuntimeInProperty, experimentalSchemaTypeMapping),
                CreateModel((properties, gltf) => {
                    SetVersionFuture(properties, gltf);
                    SetDescription(properties, "Alpha mode updated with a new enum value, and a fallback value");
                    SetModelShouldLoad(properties);
                }, SetPostRuntimeWithFallback, experimentalSchemaTypeMapping),
                CreateModel((properties, gltf) => {
                    SetMinVersion(properties, gltf);
                    SetVersionFuture(properties, gltf);
                    SetDescription(properties, "Requires a specific version or higher");
                    SetModelShouldLoad(properties, "Only in version 2.1 or higher");
                }),
                CreateModel((properties, gltf) => {
                    SetVersionCurrent(properties, gltf);
                    SetDescriptionExtensionRequired(properties, gltf);
                    SetModelShouldLoad(properties, ":x:");
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #8
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();
        }
Example #9
0
        public Material_AlphaBlend(List <string> imageList)
        {
            var baseColorTexture = new Texture {
                Source = UseTexture(imageList, "BaseColor_Plane")
            };

            // Track the common properties for use in the readme.
            CommonProperties.Add(new Property(PropertyName.AlphaMode, MaterialAlphaMode.Blend.ToReadmeString()));

            Model CreateModel(Action <List <Property>, Runtime.MeshPrimitive, 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
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        MetallicFactor = 0
                    },
                    AlphaMode = MaterialAlphaMode.Blend,
                };

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

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

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

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

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

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

            void SetVertexColor(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Colors = Data.Create
                                       (
                    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),
                }
                                       );

                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.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #10
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();
        }
Example #11
0
        public Material_MetallicRoughness(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage         = UseTexture(imageList, "BaseColor_Plane");
            Runtime.Image metallicRoughnessTextureImage = UseTexture(imageList, "MetallicRoughness_Plane");

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

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

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

                // 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 List <Runtime.MeshPrimitive>
                                    {
                                        meshPrimitive
                                    }
                                },
                            },
                        },
                    }),
                });
            }

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

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

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

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

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

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

            void SetMetallicRoughnessTexture(List <Property> properties, Runtime.PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.MetallicRoughnessTexture = new Runtime.Texture {
                    Source = metallicRoughnessTextureImage
                };
                properties.Add(new Property(PropertyName.MetallicRoughnessTexture, metallicRoughnessTextureImage));
            }

            void SetMetallicFactor(List <Property> properties, Runtime.PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.MetallicFactor = 0.0f;
                properties.Add(new Property(PropertyName.MetallicFactor, metallicRoughness.MetallicFactor));
            }

            void SetRoughnessFactor(List <Property> properties, Runtime.PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.RoughnessFactor = 0.0f;
                properties.Add(new Property(PropertyName.RoughnessFactor, metallicRoughness.RoughnessFactor));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetVertexColor(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetMetallicFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetMetallicFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) => {
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetMetallicFactor(properties, metallicRoughness);
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
            };

            GenerateUsedPropertiesList();
        }
        public Mesh_PrimitiveAttribute(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");
            Runtime.Image normalImage           = UseTexture(imageList, "Normal_Plane");

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

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

                meshPrimitive.Material = new Runtime.Material();

                // Apply the common properties to the gltf.
                meshPrimitive.Material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                {
                    BaseColorTexture = new Runtime.Texture
                    {
                        Source = baseColorTextureImage
                    }
                };

                // 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 SetVertexUVFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TextureCoordsComponentType = TextureCoordsComponentTypeEnum.FLOAT;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TextureCoordsComponentType.ToReadmeString()));
            }

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

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

            void SetVertexNormal(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var planeNormalsValue = MeshPrimitive.GetSinglePlaneNormals();

                meshPrimitive.Normals = planeNormalsValue;
                properties.Add(new Property(PropertyName.VertexNormal, planeNormalsValue.ToReadmeString()));
            }

            void SetVertexTangent(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var planeTangentValue = new List <Vector4>
                {
                    new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                    new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                    new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                    new Vector4(1.0f, 0.0f, 0.0f, 1.0f)
                };

                meshPrimitive.Tangents = planeTangentValue;
                properties.Add(new Property(PropertyName.VertexTangent, planeTangentValue.ToReadmeString()));
            }

            void SetNormalTexture(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.NormalTexture = new Runtime.Texture {
                    Source = normalImage
                };
                properties.Add(new Property(PropertyName.NormalTexture, normalImage.ToReadmeString()));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVByte(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVShort(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexUVFloat(properties, meshPrimitive);
                    SetVertexNormal(properties, meshPrimitive);
                    SetVertexTangent(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #13
0
        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
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        MetallicFactor = 0
                    },
                };

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Scene
                    {
                        Nodes = new List <Node>
                        {
                            new 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[]
                {
                    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      = MeshPrimitiveMode.Points;
                meshPrimitive.Positions = Data.Create(pointPositions);
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLines(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.Lines;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLineLoop(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.LineLoop;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeLineStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.LineStrip;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangleStrip(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.TriangleStrip;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangleFan(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.TriangleFan;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetModeTriangles(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                if (meshPrimitive.Indices == null)
                {
                    meshPrimitive.Positions.Values = new[]
                    {
                        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 = MeshPrimitiveMode.Triangles;
                properties.Add(new Property(PropertyName.Mode, meshPrimitive.Mode.ToReadmeString()));
            }

            void SetIndicesPoints(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var indices = new List <int>();
                var count   = meshPrimitive.Positions.Values.Count();

                for (int index = 0; index < count; index++)
                {
                    indices.Add(index);
                }
                meshPrimitive.Indices = Data.Create(indices);
                properties.Add(new Property(PropertyName.IndicesValues, $"[0 - {count - 1}]"));
            }

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

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

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

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

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

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

            void SetIndicesComponentTypeInt(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Indices.OutputType = DataType.UnsignedInt;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.Indices.OutputType.ToReadmeString()));
            }

            void SetIndicesComponentTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Indices.OutputType = DataType.UnsignedByte;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.Indices.OutputType.ToReadmeString()));
            }

            void SetIndicesComponentTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Indices.OutputType = DataType.UnsignedShort;
                properties.Add(new Property(PropertyName.IndicesComponentType, meshPrimitive.Indices.OutputType.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();
        }
Example #14
0
        public Texture_Sampler(List <string> imageList)
        {
            var baseColorImage = UseTexture(imageList, "BaseColor_Plane");

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

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

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

                // Apply the common properties to the gltf.
                meshPrimitive.TexCoords0 = Runtime.Data.Create
                                           (
                    new[]
                {
                    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.PbrMetallicRoughness.BaseColorTexture.Texture.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, Runtime.SamplerWrap enumValue)
            {
                sampler.WrapT = enumValue;
                properties.Add(new Property(PropertyName.WrapT, enumValue.ToReadmeString()));
            }

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

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

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

            Models = new List <Model>
            {
                CreateModel((properties, sampler) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, Runtime.SamplerWrap.MirroredRepeat);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapS(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapS(properties, sampler, Runtime.SamplerWrap.MirroredRepeat);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Nearest);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Linear);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Nearest);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Linear);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.NearestMipmapNearest);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.LinearMipmapNearest);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.NearestMipmapLinear);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.LinearMipmapLinear);
                }),
                CreateModel((properties, sampler) =>
                {
                    SetWrapT(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
                    SetWrapS(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
                    SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Nearest);
                    SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Nearest);
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #15
0
        public Material_DoubleSided(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");
            Runtime.Image normalImage           = UseTexture(imageList, "Normal_Plane");

            // Track the common properties for use in the readme.
            var doubleSidedValue = true;

            CommonProperties.Add(new Property(PropertyName.DoubleSided, doubleSidedValue.ToString()));
            CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage.ToReadmeString()));

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

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

                // Apply the common properties to the gltf.
                meshPrimitive.Material.DoubleSided = doubleSidedValue;
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture {
                    Source = baseColorTextureImage
                };

                // 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 SetVertexNormal(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var planeNormalsValue = MeshPrimitive.GetSinglePlaneNormals();

                meshPrimitive.Normals = planeNormalsValue;
                properties.Add(new Property(PropertyName.VertexNormal, planeNormalsValue.ToReadmeString()));
            }

            void SetVertexTangent(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                var planeTangentValue = MeshPrimitive.GetSinglePlaneTangents();

                meshPrimitive.Tangents = planeTangentValue;
                properties.Add(new Property(PropertyName.VertexTangent, planeTangentValue.ToReadmeString()));
            }

            void SetNormalTexture(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.NormalTexture = new Runtime.Texture {
                    Source = normalImage
                };
                properties.Add(new Property(PropertyName.NormalTexture, normalImage.ToReadmeString()));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexNormal(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexNormal(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetVertexNormal(properties, meshPrimitive);
                    SetVertexTangent(properties, meshPrimitive);
                    SetNormalTexture(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetNormalTexture(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #16
0
        public Accessor_Sparse(List <string> imageList)
        {
            var baseColorTextureA = new Texture {
                Source = UseTexture(imageList, "BaseColor_A")
            };
            var baseColorTextureB = new Texture {
                Source = UseTexture(imageList, "BaseColor_B")
            };

            UseFigure(imageList, "SparseAccessor_Input");
            UseFigure(imageList, "SparseAccessor_Output-Translation");

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

            Model CreateModel(Action <List <Property>, Animation, List <Node> > setProperties)
            {
                var properties     = new List <Property>();
                var animated       = true;
                var meshPrimitive0 = MeshPrimitive.CreateSinglePlane();
                var meshPrimitive1 = MeshPrimitive.CreateSinglePlane();

                var nodes = new List <Node>
                {
                    new Node
                    {
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitive0
                            }
                        }
                    },
                    new Node
                    {
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitive1
                            }
                        }
                    }
                };

                SetTexture(nodes);
                var animation  = new Animation();
                var animations = new List <Animation>
                {
                    animation
                };

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

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

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF
                           (
                        () => new Scene
                    {
                        Nodes = nodes
                    },
                        animations: animations
                           ),
                    Animated = animated,
                    Camera = new Manifest.Camera(new Vector3(0.0f, 0.0f, 2.75f))
                });
            }

            var samplerInputLinear = new[]
            {
                0.0f,
                1.0f,
                2.0f,
            };

            var samplerOutputTranslation = new[]
            {
                new Vector3(0.0f, 0.3f, 0.0f),
                new Vector3(0.0f, -0.3f, 0.0f),
                new Vector3(0.0f, 0.3f, 0.0f),
            };

            void SetTexture(List <Node> nodes)
            {
                nodes[0].Mesh.MeshPrimitives.First().Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTextureA
                        },
                    }
                };
                nodes[1].Mesh.MeshPrimitives.First().Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTextureB
                        }
                    }
                };
            }

            void OffsetPositions(List <Node> nodes)
            {
                // Offsets the positions of the mesh primitives so they don't overlap. This is done because animation translations override node translations.
                nodes[0].Mesh.MeshPrimitives.First().Positions.Values = ((Vector3[])nodes[0].Mesh.MeshPrimitives.First().Positions.Values).Select(position => { return(new Vector3(position.X - 0.6f, position.Y, position.Z)); });
                nodes[1].Mesh.MeshPrimitives.First().Positions.Values = ((Vector3[])nodes[1].Mesh.MeshPrimitives.First().Positions.Values).Select(position => { return(new Vector3(position.X + 0.6f, position.Y, position.Z)); });
            }

            void OffsetNodeTranslations(List <Node> nodes)
            {
                // Gives each node a translation so they don't overlap, but can have the same values for position.
                nodes[0].Translation = new Vector3(-0.6f, 0.0f, 0.0f);
                nodes[1].Translation = new Vector3(0.6f, 0.0f, 0.0f);
            }

            List <AnimationChannel> CreateChannels(List <Node> nodes, AnimationSampler sampler0, AnimationSampler sampler1)
            {
                return(new List <AnimationChannel>
                {
                    new AnimationChannel
                    {
                        Target = new AnimationChannelTarget
                        {
                            Node = nodes[0],
                        },
                        Sampler = sampler0
                    },
                    new AnimationChannel
                    {
                        Target = new AnimationChannelTarget
                        {
                            Node = nodes[1],
                        },
                        Sampler = sampler1
                    },
                });
            }

            void SetAnimationPaths(List <AnimationChannel> channels, AnimationChannelTargetPath path, List <Property> properties)
            {
                foreach (var channel in channels)
                {
                    channel.Target.Path = path;
                }
            }

            Models = new List <Model>
            {
                CreateModel((properties, animation, nodes) =>
                {
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputTranslation),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear, DataSparse.Create
                                                    (
                                                        new Dictionary <int, float>
                        {
                            { 1, 1.5f }
                        }
                                                    )),
                        Output = Data.Create(samplerOutputTranslation),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Translation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Animation Sampler Input"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 1"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputTranslation),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputTranslation, DataSparse.Create
                                                    (
                                                        new Dictionary <int, Vector3>
                        {
                            { 1, new Vector3(0.0f, 0.2f, 0.0f) },
                        }
                                                    )),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Translation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Animation Sampler Output"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 2"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    OffsetNodeTranslations(nodes);

                    nodes[1].Mesh.MeshPrimitives.First().Positions.Values = nodes[0].Mesh.MeshPrimitives.First().Positions.Values;

                    nodes[1].Mesh.MeshPrimitives.First().Positions.Sparse = DataSparse.Create
                                                                            (
                        new Dictionary <int, Vector3>
                    {
                        { 0, new Vector3(0.25f, -0.5f, 0.0f) },
                        { 2, new Vector3(-0.25f, 0.5f, 0.0f) },
                    }
                                                                            );

                    properties.Add(new Property(PropertyName.SparseAccessor, "Positions"));
                    properties.Add(new Property(PropertyName.Description, "Mesh B's sparse accessor overwrites the values of the top left and bottom right vertexes."));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    // Add extra vertexes that will be used by the sparse accessor.
                    var positions = MeshPrimitive.GetSinglePlanePositions().Concat(new[]
                    {
                        new Vector3(0.25f, -0.5f, 0.0f),
                        new Vector3(-0.25f, 0.5f, 0.0f),
                    });
                    var textureCoords = MeshPrimitive.GetSinglePlaneTexCoords().Concat(new[]
                    {
                        new Vector2(1.0f, 1.0f),
                        new Vector2(0.0f, 0.0f),
                    });
                    foreach (var node in nodes)
                    {
                        node.Mesh.MeshPrimitives.First().Positions.Values  = positions;
                        node.Mesh.MeshPrimitives.First().TexCoords0.Values = textureCoords;
                    }
                    OffsetNodeTranslations(nodes);

                    nodes[1].Mesh.MeshPrimitives.First().Indices.Values = nodes[0].Mesh.MeshPrimitives.First().Indices.Values;

                    nodes[1].Mesh.MeshPrimitives.First().Indices.Sparse = DataSparse.Create
                                                                          (
                        new Dictionary <int, int>
                    {
                        { 1, 4 },
                        { 5, 5 },
                    }
                                                                          );

                    properties.Add(new Property(PropertyName.SparseAccessor, "Mesh Primitive Indices"));
                    properties.Add(new Property(PropertyName.Description, "Both meshes have six vertexes, but only four are used to make the visible mesh. " +
                                                "Mesh B's sparse accessor replaces the indices pointing at the top left and bottom right vertexes with ones pointing at the unused vertexes."));
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #17
0
        public Material_MetallicRoughness(List <string> imageList)
        {
            var baseColorTexture = new Texture {
                Source = UseTexture(imageList, "BaseColor_Plane")
            };
            var metallicRoughnessTexture = new Texture {
                Source = UseTexture(imageList, "MetallicRoughness_Plane")
            };

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

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

                // Apply the properties that are specific to this gltf.
                meshPrimitive.Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness()
                };

                setProperties(properties, meshPrimitive, meshPrimitive.Material.PbrMetallicRoughness);

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

            void SetVertexColor(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Colors = Data.Create
                                       (
                    new[]
                {
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(1.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 0.0f, 1.0f),
                    new Vector3(1.0f, 0.0f, 0.0f),
                }
                                       );

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

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

            void SetBaseColorFactor(List <Property> properties, PbrMetallicRoughness metallicRoughness)
            {
                var baseColorFactorValue = new Vector4(0.2f, 0.2f, 0.2f, 0.8f);

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

            void SetMetallicRoughnessTexture(List <Property> properties, PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.MetallicRoughnessTexture = new TextureInfo {
                    Texture = metallicRoughnessTexture
                };
                properties.Add(new Property(PropertyName.MetallicRoughnessTexture, metallicRoughnessTexture.Source.ToReadmeString()));
            }

            void SetMetallicFactor(List <Property> properties, PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.MetallicFactor = 0.0f;
                properties.Add(new Property(PropertyName.MetallicFactor, metallicRoughness.MetallicFactor.ToReadmeString()));
            }

            void SetRoughnessFactor(List <Property> properties, PbrMetallicRoughness metallicRoughness)
            {
                metallicRoughness.RoughnessFactor = 0.0f;
                properties.Add(new Property(PropertyName.RoughnessFactor, metallicRoughness.RoughnessFactor.ToReadmeString()));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetMetallicFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetMetallicFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
                CreateModel((properties, meshPrimitive, metallicRoughness) =>
                {
                    meshPrimitive.TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                    SetVertexColor(properties, meshPrimitive);
                    SetBaseColorTexture(properties, metallicRoughness);
                    SetBaseColorFactor(properties, metallicRoughness);
                    SetMetallicRoughnessTexture(properties, metallicRoughness);
                    SetMetallicFactor(properties, metallicRoughness);
                    SetRoughnessFactor(properties, metallicRoughness);
                }),
            };

            GenerateUsedPropertiesList();
        }
Example #18
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();
        }
        public Instancing(List <string> imageList)
        {
            var baseColorImageA    = UseTexture(imageList, "BaseColor_A");
            var baseColorImageB    = UseTexture(imageList, "BaseColor_B");
            var baseColorImageCube = UseTexture(imageList, "BaseColor_Cube");
            var distantCamera      = new Manifest.Camera(new Vector3(0.0f, 0.0f, 2.7f));

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

            TextureInfo CreateTextureInfo(Image source)
            {
                return(new TextureInfo
                {
                    Texture = new Texture
                    {
                        Source = source,
                    }
                });
            }

            Model CreateModel(Action <List <Property>, List <Node>, List <Animation> > setProperties, Action <Model> setCamera)
            {
                var properties = new List <Property>();
                var animations = new List <Animation>();
                var animated   = true;
                var nodes      = new List <Node>();

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

                // 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 Scene {
                        Nodes = nodes
                    }, animations: animations),
                    Animated = animated,
                };

                setCamera(model);

                return(model);
            }

            var samplerInputLinear = Data.Create(new[]
            {
                0.0f,
                1.0f,
                2.0f,
                3.0f,
                4.0f,
            });

            var samplerInputCurve = Data.Create(new[]
            {
                0.0f,
                0.5f,
                1.0f,
                2.0f,
                4.0f,
            });

            var samplerOutput = Data.Create(new[]
            {
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90.0f), 0.0f),
                Quaternion.Identity,
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-90.0f), 0.0f),
                Quaternion.Identity,
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90.0f), 0.0f),
            });

            var samplerOutputReverse = Data.Create(new[]
            {
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-90.0f), 0.0f),
                Quaternion.Identity,
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(90.0f), 0.0f),
                Quaternion.Identity,
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-90.0f), 0.0f),
            });

            Runtime.Material CreateMaterial(TextureInfo textureInfo)
            {
                return(new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = textureInfo
                    }
                });
            }

            void AddMeshPrimitivesToSingleNode(List <Node> nodes, List <Runtime.MeshPrimitive> meshPrimitives)
            {
                // If there are multiple mesh primitives, offset their position so they don't overlap.
                if (meshPrimitives.Count > 1)
                {
                    meshPrimitives[0].Positions.Values = meshPrimitives[0].Positions.Values.Select(position => { return(new Vector3(position.X - 0.6f, position.Y, position.Z)); });
                    meshPrimitives[1].Positions.Values = meshPrimitives[1].Positions.Values.Select(position => { return(new Vector3(position.X + 0.6f, position.Y, position.Z)); });
                }

                nodes.Add(
                    new Node
                {
                    Mesh = new Runtime.Mesh
                    {
                        MeshPrimitives = meshPrimitives
                    }
                }
                    );
            }

            void AddMeshPrimitivesToMultipleNodes(List <Node> nodes, Runtime.MeshPrimitive meshPrimitives0, Runtime.MeshPrimitive meshPrimitives1)
            {
                nodes.AddRange(new[]
                {
                    new Node
                    {
                        Translation = new Vector3(-0.6f, 0.0f, 0.0f),
                        Mesh        = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitives0
                            }
                        }
                    },
                    new Node
                    {
                        Translation = new Vector3(0.6f, 0.0f, 0.0f),
                        Mesh        = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitives1
                            }
                        }
                    }
                }
                               );
            }

            void AddAnimation(List <Animation> animations, List <Node> nodes, AnimationSampler sampler0, AnimationSampler sampler1, bool samplerInstanced)
            {
                animations.Add(new Animation
                {
                    Channels = new List <AnimationChannel>
                    {
                        new AnimationChannel
                        {
                            Target = new AnimationChannelTarget
                            {
                                Node = nodes[0],
                                Path = AnimationChannelTargetPath.Rotation,
                            },
                            Sampler = sampler0
                        },
                        new AnimationChannel
                        {
                            Target = new AnimationChannelTarget
                            {
                                Node = nodes[1],
                                Path = AnimationChannelTargetPath.Rotation,
                            },
                            Sampler = sampler1
                        },
                    }
                });
            }

            Models = new List <Model>
            {
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitives = new List <Runtime.MeshPrimitive>
                    {
                        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false),
                        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
                    };

                    foreach (Runtime.MeshPrimitive meshPrimitive in meshPrimitives)
                    {
                        // This non-standard set of texture coordinates is larger than the texture but not an exact multiple, so it allows texture sampler settings to be visible.
                        meshPrimitive.TexCoords0 = Data.Create <Vector2>
                                                   (
                            new[]
                        {
                            new Vector2(1.3f, 1.3f),
                            new Vector2(-0.3f, 1.3f),
                            new Vector2(-0.3f, -0.3f),
                            new Vector2(1.3f, -0.3f),
                        }
                                                   );
                    }

                    meshPrimitives[0].Material = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    meshPrimitives[1].Material = CreateMaterial(CreateTextureInfo(baseColorImageA));

                    meshPrimitives[0].Material.PbrMetallicRoughness.BaseColorTexture.Texture.Sampler = new Sampler
                    {
                        WrapT = SamplerWrap.ClampToEdge,
                        WrapS = SamplerWrap.ClampToEdge
                    };
                    meshPrimitives[1].Material.PbrMetallicRoughness.BaseColorTexture.Texture.Sampler = new Sampler
                    {
                        WrapT = SamplerWrap.MirroredRepeat,
                        WrapS = SamplerWrap.MirroredRepeat
                    };

                    AddMeshPrimitivesToSingleNode(nodes, meshPrimitives);

                    properties.Add(new Property(PropertyName.Description, "Two textures using the same image as their source."));
                    properties.Add(new Property(PropertyName.Difference, "The texture sampler `WrapT` and `WrapS` are set to `CLAMP_TO_EDGE` for one and `MIRRORED_REPEAT` for the other."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitives = new List <Runtime.MeshPrimitive>
                    {
                        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false),
                        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
                    };

                    meshPrimitives[0].Material = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    meshPrimitives[1].Material = CreateMaterial(CreateTextureInfo(baseColorImageB));

                    var sampler = new Sampler
                    {
                        WrapT = SamplerWrap.ClampToEdge,
                        WrapS = SamplerWrap.ClampToEdge
                    };
                    foreach (Runtime.MeshPrimitive meshPrimitive in meshPrimitives)
                    {
                        meshPrimitive.Material.PbrMetallicRoughness.BaseColorTexture.Texture.Sampler = sampler;
                        // This non-standard set of texture coordinates is larger than the texture but not an exact multiple, so it allows texture sampler settings to be visible.
                        meshPrimitive.TexCoords0 = Data.Create <Vector2>
                                                   (
                            new[]
                        {
                            new Vector2(1.3f, 1.3f),
                            new Vector2(-0.3f, 1.3f),
                            new Vector2(-0.3f, -0.3f),
                            new Vector2(1.3f, -0.3f),
                        }
                                                   );
                    }

                    AddMeshPrimitivesToSingleNode(nodes, meshPrimitives);

                    properties.Add(new Property(PropertyName.Description, "Two textures using the same sampler."));
                    properties.Add(new Property(PropertyName.Difference, "One texture uses image A while the other uses image B."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitives = new List <Runtime.MeshPrimitive>
                    {
                        MeshPrimitive.CreateSinglePlane(),
                        MeshPrimitive.CreateSinglePlane()
                    };

                    var texture = CreateTextureInfo(baseColorImageA);
                    foreach (Runtime.MeshPrimitive meshPrimitive in meshPrimitives)
                    {
                        meshPrimitive.Material = CreateMaterial(texture);
                    }
                    meshPrimitives[0].Material.PbrMetallicRoughness.BaseColorTexture = meshPrimitives[1].Material.PbrMetallicRoughness.BaseColorTexture;
                    meshPrimitives[1].Material.PbrMetallicRoughness.BaseColorFactor  = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);

                    AddMeshPrimitivesToSingleNode(nodes, meshPrimitives);

                    properties.Add(new Property(PropertyName.Description, "Two textures using the same source image."));
                    properties.Add(new Property(PropertyName.Difference, "One material does not have a baseColorFactor and the other has a blue baseColorFactor."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitives = new List <Runtime.MeshPrimitive>
                    {
                        MeshPrimitive.CreateSinglePlane(),
                        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
                    };
                    var material = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    foreach (Runtime.MeshPrimitive meshPrimitive in meshPrimitives)
                    {
                        meshPrimitive.Material = material;
                    }

                    // One of the primitives has a 'zoomed in' texture coordinate set.
                    meshPrimitives[1].TexCoords0 = Data.Create <Vector2>
                                                   (
                        new[]
                    {
                        new Vector2(0.9f, 0.9f),
                        new Vector2(0.1f, 0.9f),
                        new Vector2(0.1f, 0.1f),
                        new Vector2(0.9f, 0.1f),
                    }
                                                   );

                    AddMeshPrimitivesToSingleNode(nodes, meshPrimitives);

                    properties.Add(new Property(PropertyName.Description, "Two primitives using the same material."));
                    properties.Add(new Property(PropertyName.Difference, "One primitive has texture coordinates that displays all of texture A, while the other primitive has textures coordinates that don't display the border."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive0      = MeshPrimitive.CreateSinglePlane();
                    var meshPrimitive1      = MeshPrimitive.CreateSinglePlane();
                    meshPrimitive0.Material = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    meshPrimitive1.Material = CreateMaterial(CreateTextureInfo(baseColorImageB));

                    meshPrimitive0.Positions = meshPrimitive1.Positions;

                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive0, meshPrimitive1);

                    properties.Add(new Property(PropertyName.Description, "Two primitives using the same accessors for the `POSITION` attribute."));
                    properties.Add(new Property(PropertyName.Difference, "One primitive uses texture A while the other primitive uses texture B."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive0      = MeshPrimitive.CreateSinglePlane(includeIndices: false);
                    var meshPrimitive1      = MeshPrimitive.CreateSinglePlane();
                    meshPrimitive0.Material = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    meshPrimitive1.Material = CreateMaterial(CreateTextureInfo(baseColorImageB));

                    meshPrimitive0.Indices = meshPrimitive1.Indices;

                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive0, meshPrimitive1);

                    properties.Add(new Property(PropertyName.Description, "Two primitives using the same accessors for indices."));
                    properties.Add(new Property(PropertyName.Difference, "One primitive uses texture A while the other primitive uses texture B."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive      = MeshPrimitive.CreateSinglePlane();
                    meshPrimitive.Material = CreateMaterial(CreateTextureInfo(baseColorImageA));

                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive, meshPrimitive);
                    nodes[1].Mesh = nodes[0].Mesh;

                    properties.Add(new Property(PropertyName.Description, "Two nodes using the same mesh."));
                    properties.Add(new Property(PropertyName.Difference, "The two nodes have different translations."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    nodes.AddRange(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3));
                    nodes[0].Name = "plane0";
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());

                    // Adds just the node containing the mesh, dropping the data for a second set of joints.
                    nodes.Add(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3)[0]);
                    nodes[2].Name = "plane1";
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageB));
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());
                    nodes[2].Skin = nodes[0].Skin;

                    // Offsets the position of both meshes so they don't overlap.
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).Positions.Values = nodes[0].Mesh.MeshPrimitives.ElementAt(0).Positions.Values.Select(position => { return(new Vector3(position.X - 0.3f, position.Y, position.Z)); });
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).Positions.Values = nodes[2].Mesh.MeshPrimitives.ElementAt(0).Positions.Values.Select(position => { return(new Vector3(position.X + 0.3f, position.Y, position.Z)); });

                    properties.Add(new Property(PropertyName.Description, "Two nodes using the same skin."));
                    properties.Add(new Property(PropertyName.Difference, "The two mesh primitives have different `POSITION` values."));
                }, (model) => { model.Camera = null; }),
                CreateModel((properties, nodes, animations) =>
                {
                    nodes.AddRange(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3));
                    nodes[0].Name = "plane0";
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());

                    // Adds just the node containing the mesh, dropping the data for a second set of joints.
                    nodes.Add(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3)[0]);
                    nodes[2].Name = "plane1";
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageB));
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());
                    nodes[2].Skin.Joints = nodes[0].Skin.Joints;

                    // Creates new inverseBindMatrices for the second skin, rotating the flap further than the default value would.
                    nodes[2].Skin.InverseBindMatrices = Data.Create(new[]
                    {
                        nodes[2].Skin.InverseBindMatrices.Values.First(),
                        Matrix4x4.Multiply(nodes[2].Skin.InverseBindMatrices.Values.ElementAt(1), Matrix4x4.CreateRotationX(FloatMath.ToRadians(-30))),
                    });

                    // Offsets the position of both meshes so they don't overlap.
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).Positions.Values = nodes[0].Mesh.MeshPrimitives.ElementAt(0).Positions.Values.Select(position => new Vector3(position.X - 0.3f, position.Y, position.Z));
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).Positions.Values = nodes[2].Mesh.MeshPrimitives.ElementAt(0).Positions.Values.Select(position => new Vector3(position.X + 0.3f, position.Y, position.Z));

                    properties.Add(new Property(PropertyName.Description, "Two skins using the same joints."));
                    properties.Add(new Property(PropertyName.Difference, "The skin with texture B has inverseBindMatrices that fold twice as far as the skin with texture A."));
                }, (model) => { model.Camera = null; }),
                CreateModel((properties, nodes, animations) =>
                {
                    nodes.AddRange(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3));
                    nodes[0].Name = "plane0";
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageA));
                    nodes[0].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());
                    nodes[1].Translation = Vector3.Add((Vector3)nodes[1].Translation, new Vector3(-0.3f, 0.0f, 0.0f));

                    nodes.AddRange(Nodes.CreateFoldingPlaneSkin("skinA", 2, 3));
                    nodes[2].Name = "plane1";
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).Material   = CreateMaterial(CreateTextureInfo(baseColorImageB));
                    nodes[2].Mesh.MeshPrimitives.ElementAt(0).TexCoords0 = Data.Create(Nodes.GetSkinATexCoords());
                    nodes[3].Translation = Vector3.Add((Vector3)nodes[3].Translation, new Vector3(0.3f, 0.0f, 0.0f));

                    nodes[2].Skin.InverseBindMatrices = nodes[0].Skin.InverseBindMatrices;

                    properties.Add(new Property(PropertyName.Description, "Two skins using the same inverseBindMatrices."));
                    properties.Add(new Property(PropertyName.Difference, "The base joint for the two skins have different translations."));
                }, (model) => { model.Camera = null; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive0      = MeshPrimitive.CreateCube();
                    var meshPrimitive1      = MeshPrimitive.CreateCube();
                    var textureInfo         = CreateTextureInfo(baseColorImageCube);
                    meshPrimitive0.Material = CreateMaterial(textureInfo);
                    meshPrimitive1.Material = CreateMaterial(textureInfo);
                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive0, meshPrimitive1);

                    var sampler = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = samplerInputLinear,
                        Output        = samplerOutput,
                    };

                    AddAnimation(animations, nodes, sampler, sampler, true);

                    properties.Add(new Property(PropertyName.Description, "Two animation channels using the same sampler."));
                    properties.Add(new Property(PropertyName.Difference, "The two animation channels target different nodes."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive0      = MeshPrimitive.CreateCube();
                    var meshPrimitive1      = MeshPrimitive.CreateCube();
                    var textureInfo         = CreateTextureInfo(baseColorImageCube);
                    meshPrimitive0.Material = CreateMaterial(textureInfo);
                    meshPrimitive1.Material = CreateMaterial(textureInfo);
                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive0, meshPrimitive1);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = samplerInputLinear,
                        Output        = samplerOutput,
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = samplerInputLinear,
                        Output        = samplerOutputReverse,
                    };

                    AddAnimation(animations, nodes, sampler0, sampler1, false);

                    properties.Add(new Property(PropertyName.Description, "Two animation samplers using the same input accessors."));
                    properties.Add(new Property(PropertyName.Difference, "The two animation samplers have different output values."));
                }, (model) => { model.Camera = distantCamera; }),
                CreateModel((properties, nodes, animations) =>
                {
                    var meshPrimitive0      = MeshPrimitive.CreateCube();
                    var meshPrimitive1      = MeshPrimitive.CreateCube();
                    var textureInfo         = CreateTextureInfo(baseColorImageCube);
                    meshPrimitive0.Material = CreateMaterial(textureInfo);
                    meshPrimitive1.Material = CreateMaterial(textureInfo);
                    AddMeshPrimitivesToMultipleNodes(nodes, meshPrimitive0, meshPrimitive1);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = samplerInputLinear,
                        Output        = samplerOutput,
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = samplerInputCurve,
                        Output        = samplerOutput,
                    };

                    AddAnimation(animations, nodes, sampler0, sampler1, false);

                    properties.Add(new Property(PropertyName.Description, "Two animation samplers using the same output accessors."));
                    properties.Add(new Property(PropertyName.Difference, "The two animation samplers have different input values."));
                }, (model) => { model.Camera = distantCamera; }),
                // To be implemented later. Needs to work as a type of interleaving.
                //CreateModel((properties, nodes, animations) =>
                //{
                //    var meshPrimitives = new List<Runtime.MeshPrimitive>
                //    {
                //        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false),
                //        MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
                //    };
                //    meshPrimitives[0].TexCoords0 = meshPrimitives[1].TexCoords0 = MeshPrimitive.GetSinglePlaneTextureCoordSets();
                //    meshPrimitives[0].Normals = meshPrimitives[1].Normals = MeshPrimitive.GetSinglePlaneNormals();

                //   foreach (Runtime.MeshPrimitive meshPrimitive in meshPrimitives)
                //    {
                //        meshPrimitive.BufferViewsInstanced = true;
                //        meshPrimitive.Material = CreateMaterial();
                //    }
                //    AddMeshPrimitivesToSingleNode(nodes, meshPrimitives);

                //    properties.Add(new Property(PropertyName.Description, "Two accessors using the same buffer view."));
                //}, (model) => { model.Camera = null; }),
            };

            GenerateUsedPropertiesList();
        }
        public Material_SpecularGlossiness(List <string> imageList)
        {
            Runtime.Image diffuseTextureImage            = UseTexture(imageList, "Diffuse_Plane");
            Runtime.Image specularGlossinessTextureImage = UseTexture(imageList, "SpecularGlossiness_Plane");
            Runtime.Image baseColorTextureImage          = UseTexture(imageList, "BaseColor_X");

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

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

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

                // Apply the common properties to the gltf.
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture {
                    Source = baseColorTextureImage
                };

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

                // 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
                                    }
                                },
                            },
                        },
                    },
                                      extensionsUsed: new List <string> {
                        "KHR_materials_pbrSpecularGlossiness"
                    },
                                      extensionsRequired: new List <string> {
                        "KHR_materials_pbrSpecularGlossiness"
                    }),
                });
            }

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

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

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

            void SetDiffuseTexture(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                extension.DiffuseTexture = new Runtime.Texture {
                    Source = diffuseTextureImage
                };
                properties.Add(new Property(PropertyName.DiffuseTexture, diffuseTextureImage));
            }

            void SetDiffuseFactor(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                var diffuseFactorValue = new Vector4(0.2f, 0.2f, 0.2f, 0.8f);

                extension.DiffuseFactor = diffuseFactorValue;
                properties.Add(new Property(PropertyName.DiffuseFactor, diffuseFactorValue));
            }

            void SetSpecularGlossinessTexture(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                extension.SpecularGlossinessTexture = new Runtime.Texture {
                    Source = specularGlossinessTextureImage
                };
                properties.Add(new Property(PropertyName.SpecularGlossinessTexture, specularGlossinessTextureImage));
            }

            void SetSpecularFactor(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                var specularFactorValue = new Vector3(0.4f, 0.4f, 0.4f);

                extension.SpecularFactor = specularFactorValue;
                properties.Add(new Property(PropertyName.SpecularFactor, specularFactorValue));
            }

            void SetSpecularFactorToZero(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                var specularFactorValue = new Vector3(0.0f, 0.0f, 0.0f);

                extension.SpecularFactor = specularFactorValue;
                properties.Add(new Property(PropertyName.SpecularFactor, specularFactorValue));
            }

            void SetGlossinessFactor(List <Property> properties, KHR_materials_pbrSpecularGlossiness extension)
            {
                extension.GlossinessFactor = 0.3f;
                properties.Add(new Property(PropertyName.GlossinessFactor, extension.GlossinessFactor));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    // There are no properties set on this model.
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetSpecularFactorToZero(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetDiffuseTexture(properties, extension);
                    SetSpecularFactorToZero(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetDiffuseFactor(properties, extension);
                    SetSpecularFactorToZero(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetSpecularGlossinessTexture(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetSpecularFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetGlossinessFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetDiffuseTexture(properties, extension);
                    SetSpecularFactorToZero(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetDiffuseTexture(properties, extension);
                    SetDiffuseFactor(properties, extension);
                    SetSpecularFactorToZero(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetDiffuseTexture(properties, extension);
                    SetGlossinessFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetSpecularGlossinessTexture(properties, extension);
                    SetSpecularFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetSpecularGlossinessTexture(properties, extension);
                    SetGlossinessFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetDiffuseTexture(properties, extension);
                    SetSpecularFactor(properties, extension);
                    SetGlossinessFactor(properties, extension);
                }),
                CreateModel((properties, meshPrimitive, material, extension) =>
                {
                    SetVertexColor(properties, meshPrimitive);
                    SetDiffuseTexture(properties, extension);
                    SetDiffuseFactor(properties, extension);
                    SetSpecularGlossinessTexture(properties, extension);
                    SetSpecularFactor(properties, extension);
                    SetGlossinessFactor(properties, extension);
                }),
            };

            GenerateUsedPropertiesList();
        }
        public Mesh_PrimitiveVertexColor(List <string> imageList)
        {
            // There are no common properties in this model group that are reported in the readme.
            List <Vector4> 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>();
                var meshPrimitive = MeshPrimitive.CreateSinglePlane();

                meshPrimitive.Material = new Runtime.Material();

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

                // 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 = Runtime.MeshPrimitive.ColorComponentTypeEnum.FLOAT;
                meshPrimitive.ColorType          = Runtime.MeshPrimitive.ColorTypeEnum.VEC3;

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

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

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

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

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

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

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

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

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

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

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

            this.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();
        }
Example #22
0
        public Accessor_SparseType(List <string> imageList)
        {
            var baseColorTextureA = new Texture {
                Source = UseTexture(imageList, "BaseColor_A")
            };
            var baseColorTextureB = new Texture {
                Source = UseTexture(imageList, "BaseColor_B")
            };

            UseFigure(imageList, "SparseAccessor_Input");
            UseFigure(imageList, "SparseAccessor_Output-Rotation");
            UseFigure(imageList, "SparseAccessor_NoBufferView");

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

            Model CreateModel(Action <List <Property>, Animation, List <Node> > setProperties)
            {
                var properties     = new List <Property>();
                var animated       = true;
                var meshPrimitive0 = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);
                var meshPrimitive1 = MeshPrimitive.CreateSinglePlane(includeTextureCoords: false);

                var nodes = new List <Node>
                {
                    new Node
                    {
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitive0
                            }
                        }
                    },
                    new Node
                    {
                        Mesh = new Runtime.Mesh
                        {
                            MeshPrimitives = new List <Runtime.MeshPrimitive>
                            {
                                meshPrimitive1
                            }
                        }
                    }
                };

                var animation  = new Animation();
                var animations = new List <Animation>
                {
                    animation
                };

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

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

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF
                           (
                        () => new Scene
                    {
                        Nodes = nodes
                    },
                        animations: animations
                           ),
                    Animated = animated,
                    Camera = new Manifest.Camera(new Vector3(0.0f, 0.0f, 2.75f))
                });
            }

            var samplerInputLinear = new[]
            {
                0.0f,
                1.0f,
                2.0f,
            };

            var samplerInputSparse = 1.5f;

            var samplerOutputTranslationSparse = new Vector3(0.0f, 0.2f, 0.0f);

            var samplerOutputRotation = new[]
            {
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-45.0f), 0.0f),
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(45.0f), 0.0f),
                Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-45.0f), 0.0f),
            };

            var samplerOutputRotationSparse = Quaternion.CreateFromYawPitchRoll(0.0f, FloatMath.ToRadians(-90.0f), 0.0f);

            List <AnimationChannel> CreateChannels(List <Node> nodes, AnimationSampler sampler0, AnimationSampler sampler1)
            {
                return(new List <AnimationChannel>
                {
                    new AnimationChannel
                    {
                        Target = new AnimationChannelTarget
                        {
                            Node = nodes[0],
                        },
                        Sampler = sampler0
                    },
                    new AnimationChannel
                    {
                        Target = new AnimationChannelTarget
                        {
                            Node = nodes[1],
                        },
                        Sampler = sampler1
                    },
                });
            }

            void SetAnimationPaths(List <AnimationChannel> channels, AnimationChannelTargetPath path, List <Property> properties)
            {
                foreach (var channel in channels)
                {
                    channel.Target.Path = path;
                }
            }

            void OffsetPositions(List <Node> nodes)
            {
                // Offsets the positions of the mesh primitives so they don't overlap. This is done because animation translations override node translations.
                nodes[0].Mesh.MeshPrimitives.First().Positions.Values = nodes[0].Mesh.MeshPrimitives.First().Positions.Values.Select(position => { return(new Vector3(position.X - 0.6f, position.Y, position.Z)); });
                nodes[1].Mesh.MeshPrimitives.First().Positions.Values = nodes[1].Mesh.MeshPrimitives.First().Positions.Values.Select(position => { return(new Vector3(position.X + 0.6f, position.Y, position.Z)); });
            }

            void SetTexture(List <Node> nodes)
            {
                nodes[0].Mesh.MeshPrimitives.First().Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTextureA
                        }
                    }
                };
                nodes[1].Mesh.MeshPrimitives.First().Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTextureB
                        }
                    }
                };

                nodes[0].Mesh.MeshPrimitives.First().TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
                nodes[1].Mesh.MeshPrimitives.First().TexCoords0 = Data.Create(MeshPrimitive.GetSinglePlaneTexCoords());
            }

            Models = new List <Model>
            {
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear, DataSparse.Create
                                                    (
                                                        DataType.UnsignedByte,
                                                        new Dictionary <int, float>
                        {
                            { 1, samplerInputSparse }
                        }
                                                    )),
                        Output = Data.Create(samplerOutputRotation),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Rotation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Input"));
                    properties.Add(new Property(PropertyName.IndicesType, sampler1.Input.Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, sampler1.Input.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 1"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear, DataSparse.Create
                                                    (
                                                        DataType.UnsignedShort,
                                                        new Dictionary <int, float>
                        {
                            { 1, samplerInputSparse }
                        }
                                                    )),
                        Output = Data.Create(samplerOutputRotation),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Rotation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Input"));
                    properties.Add(new Property(PropertyName.IndicesType, sampler1.Input.Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, sampler1.Input.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 1"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear, DataSparse.Create
                                                    (
                                                        DataType.UnsignedInt,
                                                        new Dictionary <int, float>
                        {
                            { 1, samplerInputSparse }
                        }
                                                    )),
                        Output = Data.Create(samplerOutputRotation),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Rotation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Input"));
                    properties.Add(new Property(PropertyName.IndicesType, sampler1.Input.Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, sampler1.Input.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 1"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation, DataType.NormalizedByte),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation, DataType.NormalizedByte, DataSparse.Create
                                                    (
                                                        DataType.UnsignedByte,
                                                        new Dictionary <int, Quaternion>
                        {
                            { 1, samplerOutputRotationSparse }
                        }
                                                    )),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Rotation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Output"));
                    properties.Add(new Property(PropertyName.IndicesType, ((Data <Quaternion>)sampler1.Output).Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, sampler1.Output.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 2"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    OffsetPositions(nodes);

                    var sampler0 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation, DataType.NormalizedShort),
                    };

                    var sampler1 = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(samplerOutputRotation, DataType.NormalizedShort, DataSparse.Create
                                                    (
                                                        DataType.UnsignedByte,
                                                        new Dictionary <int, Quaternion>
                        {
                            { 1, samplerOutputRotationSparse }
                        }
                                                    )),
                    };

                    var channels       = CreateChannels(nodes, sampler0, sampler1);
                    animation.Channels = channels;
                    SetAnimationPaths(channels, AnimationChannelTargetPath.Rotation, properties);

                    properties.Add(new Property(PropertyName.SparseAccessor, "Output"));
                    properties.Add(new Property(PropertyName.IndicesType, ((Data <Quaternion>)sampler1.Output).Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, sampler1.Output.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See Figure 2"));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    // Add extra vertexes that will be used by the sparse accessor.
                    SetTexture(nodes);
                    var positions = MeshPrimitive.GetSinglePlanePositions().Concat(new[]
                    {
                        new Vector3(0.25f, -0.5f, 0.0f),
                        new Vector3(-0.25f, 0.5f, 0.0f),
                    });
                    var texCoords = MeshPrimitive.GetSinglePlaneTexCoords().Concat(new[]
                    {
                        new Vector2(1.0f, 1.0f),
                        new Vector2(0.0f, 0.0f),
                    });

                    foreach (var node in nodes)
                    {
                        node.Mesh.MeshPrimitives.First().Positions.Values  = positions;
                        node.Mesh.MeshPrimitives.First().TexCoords0.Values = texCoords;
                    }
                    OffsetPositions(nodes);

                    var meshPrimitiveIndices    = nodes[1].Mesh.MeshPrimitives.First().Indices;
                    meshPrimitiveIndices.Values = nodes[0].Mesh.MeshPrimitives.First().Indices.Values;
                    meshPrimitiveIndices.Sparse = DataSparse.Create
                                                  (
                        DataType.UnsignedByte,
                        new Dictionary <int, int>
                    {
                        { 1, 4 },
                        { 5, 5 },
                    }
                                                  );

                    properties.Add(new Property(PropertyName.SparseAccessor, "Mesh Primitive Indices"));
                    properties.Add(new Property(PropertyName.IndicesType, meshPrimitiveIndices.Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, meshPrimitiveIndices.OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ":white_check_mark:"));
                    properties.Add(new Property(PropertyName.Description, "See the description for the Mesh Primitive Indices model in [Accessor_Sparse](../Accessor_Sparse/README.md)."));
                }),
                CreateModel((properties, animation, nodes) =>
                {
                    SetTexture(nodes);
                    nodes.RemoveAt(0);

                    var sampler = new AnimationSampler
                    {
                        Interpolation = AnimationSamplerInterpolation.Linear,
                        Input         = Data.Create(samplerInputLinear),
                        Output        = Data.Create(Enumerable.Repeat(default(Vector3), 3), DataSparse.Create
                                                    (
                                                        DataType.UnsignedByte,
                                                        new Dictionary <int, Vector3>
                        {
                            { 1, samplerOutputTranslationSparse }
                        }
                                                    )),
                    };

                    var channels = new List <AnimationChannel>
                    {
                        new AnimationChannel
                        {
                            Target = new AnimationChannelTarget
                            {
                                Node = nodes[0],
                                Path = AnimationChannelTargetPath.Translation
                            },
                            Sampler = sampler
                        },
                    };
                    animation.Channels = channels;

                    properties.Add(new Property(PropertyName.SparseAccessor, "Output"));
                    properties.Add(new Property(PropertyName.IndicesType, ((Data <Vector3>)sampler.Output).Sparse.IndicesOutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.ValueType, ((Data <Vector3>)sampler.Output).OutputType.ToReadmeString()));
                    properties.Add(new Property(PropertyName.BufferView, ""));
                    properties.Add(new Property(PropertyName.Description, "See Figure 3"));
                }),
            };

            GenerateUsedPropertiesList();
        }
        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();
        }
Example #24
0
        public Buffer_Interleaved(List <string> imageList)
        {
            var baseColorTexture = new Texture {
                Source = UseTexture(imageList, "BaseColor_Grey")
            };

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

            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     = Data.Create
                                           (
                    new[]
                {
                    new Vector3(0.0f, 1.0f, 0.0f),
                    new Vector3(1.0f, 0.0f, 0.0f),
                    new Vector3(1.0f, 1.0f, 0.0f),
                    new Vector3(0.0f, 0.0f, 1.0f),
                }
                                           );
                meshPrimitive.Material = new Runtime.Material
                {
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTexture
                        },
                    },
                };

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

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

            void SetUvTypeFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.Float;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetUvTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedByte;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetUvTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedShort;
                properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
            }

            void SetColorTypeFloat(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Colors.OutputType = DataType.Float;
                properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
            }

            void SetColorTypeByte(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedByte;
                properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
            }

            void SetColorTypeShort(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedShort;
                properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
            }

            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) =>
                {
                    SetUvTypeByte(properties, meshPrimitive);
                    SetColorTypeFloat(properties, meshPrimitive);
                }),
                CreateModel((properties, meshPrimitive) =>
                {
                    SetUvTypeShort(properties, meshPrimitive);
                    SetColorTypeFloat(properties, meshPrimitive);
                }),
            };

            GenerateUsedPropertiesList();
        }