Beispiel #1
0
        public Mesh_PrimitivesUV(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_Plane");
            Runtime.Image normalImage           = UseTexture(imageList, "Normal_Plane");
            UseFigure(imageList, "Indices_Primitive0");
            UseFigure(imageList, "Indices_Primitive1");
            UseFigure(imageList, "UVSpace2");
            UseFigure(imageList, "UVSpace3");
            UseFigure(imageList, "UVSpace4");
            UseFigure(imageList, "UVSpace5");

            // Track the common properties for use in the readme.
            var vertexNormalValue = new List <Vector3>
            {
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
            };
            var tangentValue = 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),
            };
            var vertexColorValue = 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(0.0f, 0.0f, 1.0f, 0.2f),
            };

            CommonProperties.Add(new Property(PropertyName.VertexNormal, vertexNormalValue));
            CommonProperties.Add(new Property(PropertyName.VertexTangent, tangentValue));
            CommonProperties.Add(new Property(PropertyName.VertexColor, vertexColorValue));
            CommonProperties.Add(new Property(PropertyName.NormalTexture, normalImage));
            CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage));

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

                // Apply the common properties to the gltf.
                foreach (var meshPrimitive in meshPrimitives)
                {
                    meshPrimitive.TextureCoordSets = new List <List <Vector2> >();
                    meshPrimitive.Material         = new Runtime.Material
                    {
                        MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness
                        {
                            MetallicFactor = 0
                        }
                    };
                }

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitives[0], meshPrimitives[1]);

                // 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 = meshPrimitives
                                },
                            },
                        },
                    }),
                });
            }

            void SetCommonProperties(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Normals  = vertexNormalValue;
                meshPrimitive.Tangents = tangentValue;
                meshPrimitive.Colors   = vertexColorValue;
                meshPrimitive.Material.NormalTexture = new Runtime.Texture {
                    Source = normalImage
                };
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture()
                {
                    Source = baseColorTextureImage
                };
            }

            void SetNullUV(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material         = null;
                meshPrimitive.TextureCoordSets = null;
            }

            void SetPrimitiveZeroVertexUVZero(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.TextureCoordSets = meshPrimitive.TextureCoordSets.Concat(
                    new[]
                {
                    new[]
                    {
                        new Vector2(0.0f, 1.0f),
                        new Vector2(1.0f, 0.0f),
                        new Vector2(0.0f, 0.0f),
                    }
                });
                properties.Add(new Property(PropertyName.Primitive0VertexUV0, ":white_check_mark:"));
            }

            void SetPrimitiveOneVertexUVZero(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.TextureCoordSets = meshPrimitive.TextureCoordSets.Concat(
                    new[]
                {
                    new[]
                    {
                        new Vector2(0.0f, 1.0f),
                        new Vector2(1.0f, 1.0f),
                        new Vector2(1.0f, 0.0f),
                    }
                });
                properties.Add(new Property(PropertyName.Primitive1VertexUV0, ":white_check_mark:"));
            }

            void SetPrimitiveZeroVertexUVOne(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 1;
                meshPrimitive.Material.NormalTexture.TexCoordIndex = 1;
                meshPrimitive.TextureCoordSets = meshPrimitive.TextureCoordSets.Concat(
                    new[]
                {
                    new[]
                    {
                        new Vector2(0.5f, 0.5f),
                        new Vector2(1.0f, 0.0f),
                        new Vector2(0.5f, 0.0f),
                    }
                });
                properties.Add(new Property(PropertyName.Primitive0VertexUV1, ":white_check_mark:"));
            }

            void SetPrimitiveOneVertexUVOne(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.Material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 1;
                meshPrimitive.Material.NormalTexture.TexCoordIndex = 1;
                meshPrimitive.TextureCoordSets = meshPrimitive.TextureCoordSets.Concat(
                    new[]
                {
                    new[]
                    {
                        new Vector2(0.5f, 0.5f),
                        new Vector2(1.0f, 0.5f),
                        new Vector2(1.0f, 0.0f),
                    }
                });
                properties.Add(new Property(PropertyName.Primitive1VertexUV1, ":white_check_mark:"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetNullUV(meshPrimitiveZero);
                    SetNullUV(meshPrimitiveOne);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetNullUV(meshPrimitiveOne);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                    SetNullUV(meshPrimitiveZero);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetPrimitiveZeroVertexUVOne(properties, meshPrimitiveZero);
                    SetNullUV(meshPrimitiveOne);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                    SetPrimitiveOneVertexUVOne(properties, meshPrimitiveOne);
                    SetNullUV(meshPrimitiveZero);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                    SetPrimitiveOneVertexUVOne(properties, meshPrimitiveOne);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                    SetPrimitiveZeroVertexUVOne(properties, meshPrimitiveZero);
                }),
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    SetPrimitiveZeroVertexUVZero(properties, meshPrimitiveZero);
                    SetPrimitiveOneVertexUVZero(properties, meshPrimitiveOne);
                    SetPrimitiveZeroVertexUVOne(properties, meshPrimitiveZero);
                    SetPrimitiveOneVertexUVOne(properties, meshPrimitiveOne);
                }),
            };

            GenerateUsedPropertiesList();
        }
Beispiel #2
0
        public Mesh_Primitives(List <string> imageList)
        {
            UseFigure(imageList, "Indices_Primitive0");
            UseFigure(imageList, "Indices_Primitive1");

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

            CommonProperties.Add(new Property(PropertyName.Material0WithBaseColorFactor, baseColorFactorGreen));
            CommonProperties.Add(new Property(PropertyName.Material1WithBaseColorFactor, baseColorFactorBlue));

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

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

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitives[0], meshPrimitives[1]);

                // 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 = meshPrimitives
                                },
                            },
                        },
                    }),
                });
            }

            void SetPrimitiveZeroGreen(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material = new Runtime.Material()
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness()
                    {
                        BaseColorFactor = baseColorFactorGreen
                    }
                };

                properties.Add(new Property(PropertyName.Primitive0, "Material 0"));
            }

            void SetPrimitiveOneBlue(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material = new Runtime.Material()
                {
                    MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness()
                    {
                        BaseColorFactor = baseColorFactorBlue
                    }
                };

                properties.Add(new Property(PropertyName.Primitive1, "Material 1"));
            }

            this.Models = new List <Model>
            {
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) => {
                    SetPrimitiveZeroGreen(properties, meshPrimitiveZero);
                    SetPrimitiveOneBlue(properties, meshPrimitiveOne);
                }),
            };

            GenerateUsedPropertiesList();
        }
        public Material_Mixed(List <string> imageList)
        {
            Runtime.Image baseColorTextureImage = UseTexture(imageList, "BaseColor_X");
            UseFigure(imageList, "UVSpace2");
            UseFigure(imageList, "UVSpace3");

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

            Model CreateModel(Action <List <Property>, Runtime.Material, Runtime.Material> setProperties)
            {
                var properties       = new List <Property>();
                var meshPrimitives   = MeshPrimitive.CreateMultiPrimitivePlane();
                var baseColorTexture = new Runtime.Texture {
                    Source = baseColorTextureImage
                };

                meshPrimitives[0].Material = new Runtime.Material();
                meshPrimitives[0].Material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness();
                meshPrimitives[1].Material = new Runtime.Material();
                meshPrimitives[1].Material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness();

                // Apply the common properties to the gltf.
                meshPrimitives[0].Material.MetallicRoughnessMaterial.BaseColorTexture = baseColorTexture;
                meshPrimitives[1].Material.MetallicRoughnessMaterial.BaseColorTexture = baseColorTexture;

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitives[0].Material, meshPrimitives[1].Material);

                // Create the gltf object.
                return(new Model
                {
                    Properties = properties,
                    GLTF = CreateGLTF(() => new Runtime.Scene()
                    {
                        Nodes = new[]
                        {
                            new Runtime.Node
                            {
                                Mesh = new Runtime.Mesh
                                {
                                    MeshPrimitives = meshPrimitives
                                },
                            },
                        },
                    }, extensionsUsed: new List <string>()
                    {
                        "KHR_materials_pbrSpecularGlossiness"
                    }),
                });
            }

            void SetSpecularGlossiness0(List <Property> properties, Runtime.Material material0)
            {
                material0.Extensions = new List <Runtime.Extensions.Extension>()
                {
                    new Runtime.Extensions.KHR_materials_pbrSpecularGlossiness()
                };
                properties.Add(new Property(PropertyName.SpecularGlossinessOnMaterial0, ":white_check_mark:"));
            }

            void SetSpecularGlossiness1(List <Property> properties, Runtime.Material material1)
            {
                material1.Extensions = new List <Runtime.Extensions.Extension>()
                {
                    new Runtime.Extensions.KHR_materials_pbrSpecularGlossiness()
                };
                properties.Add(new Property(PropertyName.SpecularGlossinessOnMaterial1, ":white_check_mark:"));
            }

            void NoSpecularGlossiness0(List <Property> properties)
            {
                properties.Add(new Property(PropertyName.SpecularGlossinessOnMaterial0, ":x:"));
            }

            void NoSpecularGlossiness1(List <Property> properties)
            {
                properties.Add(new Property(PropertyName.SpecularGlossinessOnMaterial1, ":x:"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, material0, material1) => {
                    SetSpecularGlossiness0(properties, material0);
                    SetSpecularGlossiness1(properties, material1);
                }),
                CreateModel((properties, material0, material1) => {
                    NoSpecularGlossiness0(properties);
                    NoSpecularGlossiness1(properties);
                }),
                CreateModel((properties, material0, material1) => {
                    SetSpecularGlossiness0(properties, material0);
                    NoSpecularGlossiness1(properties);
                }),
            };

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

            UseFigure(imageList, "Indices_Primitive0");
            UseFigure(imageList, "Indices_Primitive1");
            UseFigure(imageList, "UVSpace2");
            UseFigure(imageList, "UVSpace3");
            UseFigure(imageList, "UVSpace4");
            UseFigure(imageList, "UVSpace5");

            // Track the common properties for use in the readme.
            var normals = Data.Create(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),
            });
            var tangents = Data.Create(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),
            });
            var colors = Data.Create(new[]
            {
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
            });

            CommonProperties.Add(new Property(PropertyName.VertexNormal, normals.Values.ToReadmeString()));
            CommonProperties.Add(new Property(PropertyName.VertexTangent, tangents.Values.ToReadmeString()));
            CommonProperties.Add(new Property(PropertyName.VertexColor, colors.Values.ToReadmeString()));
            CommonProperties.Add(new Property(PropertyName.NormalTexture, normalTexture.Source.ToReadmeString()));
            CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTexture.Source.ToReadmeString()));

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

                // Apply the properties that are specific to this gltf.
                setProperties(properties, meshPrimitives[0], meshPrimitives[1]);

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

            void SetCommonProperties(Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Normals  = normals;
                meshPrimitive.Tangents = tangents;
                meshPrimitive.Colors   = colors;

                meshPrimitive.Material = new Runtime.Material
                {
                    NormalTexture = new NormalTextureInfo {
                        Texture = normalTexture
                    },
                    PbrMetallicRoughness = new PbrMetallicRoughness
                    {
                        BaseColorTexture = new TextureInfo {
                            Texture = baseColorTexture
                        },
                        MetallicFactor = 0,
                    }
                };
            }

            void SetPrimitive0VertexUV0(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.TexCoords0 = Data.Create
                                           (
                    new[]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                    new Vector2(0.0f, 0.0f),
                }
                                           );
                properties.Add(new Property(PropertyName.Primitive0VertexUV0, ":white_check_mark:"));
            }

            void SetPrimitive0VertexUV1(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.PbrMetallicRoughness.BaseColorTexture.TexCoord = 1;
                meshPrimitive.Material.NormalTexture.TexCoord = 1;
                meshPrimitive.TexCoords1 = Data.Create
                                           (
                    new[]
                {
                    new Vector2(0.5f, 0.5f),
                    new Vector2(1.0f, 0.0f),
                    new Vector2(0.5f, 0.0f),
                }
                                           );
                properties.Add(new Property(PropertyName.Primitive0VertexUV1, ":white_check_mark:"));
            }

            void SetPrimitive1VertexUV0(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                SetCommonProperties(meshPrimitive);
                meshPrimitive.TexCoords0 = Data.Create(new[]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                });
                properties.Add(new Property(PropertyName.Primitive1VertexUV0, ":white_check_mark:"));
            }

            void SetPrimitive1VertexUV1(List <Property> properties, Runtime.MeshPrimitive meshPrimitive)
            {
                meshPrimitive.Material.PbrMetallicRoughness.BaseColorTexture.TexCoord = 1;
                meshPrimitive.Material.NormalTexture.TexCoord = 1;
                meshPrimitive.TexCoords1 = Data.Create(new[]
                {
                    new Vector2(0.5f, 0.5f),
                    new Vector2(1.0f, 0.5f),
                    new Vector2(1.0f, 0.0f),
                });
                properties.Add(new Property(PropertyName.Primitive1VertexUV1, ":white_check_mark:"));
            }

            Models = new List <Model>
            {
                CreateModel((properties, meshPrimitiveZero, meshPrimitiveOne) =>
                {
                    // do nothing
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                    SetPrimitive0VertexUV1(properties, meshPrimitive0);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                    SetPrimitive1VertexUV1(properties, meshPrimitive1);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                    SetPrimitive1VertexUV1(properties, meshPrimitive1);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                    SetPrimitive0VertexUV1(properties, meshPrimitive0);
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                }),
                CreateModel((properties, meshPrimitive0, meshPrimitive1) =>
                {
                    SetPrimitive0VertexUV0(properties, meshPrimitive0);
                    SetPrimitive1VertexUV0(properties, meshPrimitive1);
                    SetPrimitive0VertexUV1(properties, meshPrimitive0);
                    SetPrimitive1VertexUV1(properties, meshPrimitive1);
                }),
            };

            GenerateUsedPropertiesList();
        }