public Node_NegativeScale(List <string> imageList) { var baseColorTextureImage = UseTexture(imageList, "BaseColor_Nodes"); var normalImage = UseTexture(imageList, "Normal_Nodes"); var metallicRoughnessTextureImage = UseTexture(imageList, "MetallicRoughness_Nodes"); // Track the common properties for use in the readme. var translationValue = new Vector3(0, 2, 0); var matrixTranslationValue = Matrix4x4.CreateTranslation(translationValue); CommonProperties.Add(new Property(PropertyName.Translation, translationValue)); CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTextureImage)); CommonProperties.Add(new Property(PropertyName.NormalTexture, normalImage)); CommonProperties.Add(new Property(PropertyName.MetallicRoughnessTexture, metallicRoughnessTextureImage)); Model CreateModel(Action <List <Property>, Runtime.Node, Runtime.Node> setProperties) { var properties = new List <Property>(); var gltf = Gltf.CreateMultiNode(); var nodes = new[] { gltf.Scenes.First().Nodes.First(), gltf.Scenes.First().Nodes.First().Children.First(), }; // Apply the common properties to the gltf. foreach (var node in nodes) { node.Mesh.MeshPrimitives.First().Material = new Runtime.Material() { NormalTexture = new Runtime.Texture() { Source = normalImage }, MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness() { BaseColorTexture = new Runtime.Texture() { Source = baseColorTextureImage }, MetallicRoughnessTexture = new Runtime.Texture() { Source = metallicRoughnessTextureImage }, }, }; } // Apply the properties that are specific to this gltf. setProperties(properties, nodes[0], nodes[1]); // Applies a translation to avoid clippine the other node. // Models with a matrix applied have the translation applied in that matrix. if (properties.Find(e => e.Name == PropertyName.Matrix) == null) { nodes[1].Translation = translationValue; } // Create the gltf object return(new Model { Properties = properties, GLTF = CreateGLTF(() => gltf.Scenes.First()), }); } void SetMatrixScaleX(List <Property> properties, Runtime.Node node) { node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, 1, 1)), matrixTranslationValue); properties.Add(new Property(PropertyName.Matrix, node.Matrix)); } void SetMatrixScaleXY(List <Property> properties, Runtime.Node node) { node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, -1, 1)), matrixTranslationValue); properties.Add(new Property(PropertyName.Matrix, node.Matrix)); } void SetMatrixScaleXYZ(List <Property> properties, Runtime.Node node) { node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, -1, -1)), matrixTranslationValue); properties.Add(new Property(PropertyName.Matrix, node.Matrix)); } void SetScaleX(List <Property> properties, Runtime.Node node) { node.Scale = new Vector3(-1, 1, 1); properties.Add(new Property(PropertyName.Scale, node.Scale)); } void SetScaleXY(List <Property> properties, Runtime.Node node) { node.Scale = new Vector3(-1, -1, 1); properties.Add(new Property(PropertyName.Scale, node.Scale)); } void SetScaleXYZ(List <Property> properties, Runtime.Node node) { node.Scale = new Vector3(-1, -1, -1); properties.Add(new Property(PropertyName.Scale, node.Scale)); } void SetVertexNormal(List <Property> properties, Runtime.Node nodeZero, Runtime.Node nodeOne) { var normals = Gltf.GetMultiNodeNormals(); nodeZero.Mesh.MeshPrimitives.First().Normals = normals; nodeOne.Mesh.MeshPrimitives.First().Normals = normals; properties.Add(new Property(PropertyName.VertexNormal, ":white_check_mark:")); } void SetVertexTangent(List <Property> properties, Runtime.Node nodeZero, Runtime.Node nodeOne) { var tangents = Gltf.GetMultiNodeTangents(); nodeZero.Mesh.MeshPrimitives.First().Tangents = tangents; nodeOne.Mesh.MeshPrimitives.First().Tangents = tangents; properties.Add(new Property(PropertyName.VertexTangent, ":white_check_mark:")); } this.Models = new List <Model> { CreateModel((properties, nodeZero, nodeOne) => { // There are no properties set on this model. }), CreateModel((properties, nodeZero, nodeOne) => { SetMatrixScaleX(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetMatrixScaleXY(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetMatrixScaleXYZ(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleX(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXY(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXYZ(properties, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleX(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXY(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXYZ(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleX(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); SetVertexTangent(properties, nodeZero, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXY(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); SetVertexTangent(properties, nodeZero, nodeOne); }), CreateModel((properties, nodeZero, nodeOne) => { SetScaleXYZ(properties, nodeOne); SetVertexNormal(properties, nodeZero, nodeOne); SetVertexTangent(properties, nodeZero, nodeOne); }), }; GenerateUsedPropertiesList(); }
public Node_Attribute(List <string> imageList) { var baseColorTextureImage = UseTexture(imageList, "BaseColor_Nodes"); // There are no common properties in this model group that are reported in the readme. Model CreateModel(Action <List <Property>, Runtime.Node> setProperties) { var properties = new List <Property>(); var gltf = Gltf.CreateMultiNode(); var nodes = new[] { gltf.Scenes.First().Nodes.First(), gltf.Scenes.First().Nodes.First().Children.First(), }; // Apply the common properties to the gltf. foreach (var node in nodes) { node.Mesh.MeshPrimitives.First().Material = new Runtime.Material() { MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness() { BaseColorTexture = new Runtime.Texture() { Source = baseColorTextureImage }, }, }; node.Mesh.MeshPrimitives.First().Normals = null; node.Mesh.MeshPrimitives.First().Tangents = null; } // Apply the properties that are specific to this gltf. setProperties(properties, nodes[1]); // Create the gltf object return(new Model { Properties = properties, GLTF = CreateGLTF(() => gltf.Scenes.First()), }); } void SetTranslation(List <Property> properties, Runtime.Node node) { node.Translation = new Vector3(-2, 2, -2); properties.Add(new Property(PropertyName.Translation, node.Translation)); } void SetTranslationX(List <Property> properties, Runtime.Node node) { node.Translation = new Vector3(-2, 0, 0); properties.Add(new Property(PropertyName.Translation, node.Translation)); } void SetTranslationY(List <Property> properties, Runtime.Node node) { node.Translation = new Vector3(0, 2, 0); properties.Add(new Property(PropertyName.Translation, node.Translation)); } void SetTranslationZ(List <Property> properties, Runtime.Node node) { node.Translation = new Vector3(0, 0, -2); properties.Add(new Property(PropertyName.Translation, node.Translation)); } void SetRotation(List <Property> properties, Runtime.Node node) { var rotation = new Quaternion(0.0f, 1.0f, 0.0f, 0.0f); node.Rotation = rotation; properties.Add(new Property(PropertyName.Rotation, rotation)); } void SetScale(List <Property> properties, Runtime.Node node) { node.Scale = new Vector3(1.2f, 1.2f, 1.2f); properties.Add(new Property(PropertyName.Scale, node.Scale)); } void SetMatrix(List <Property> properties, Runtime.Node node) { var matrixT = Matrix4x4.CreateTranslation(new Vector3(-2, 2, -2)); var matrixR = Matrix4x4.CreateRotationY(FloatMath.Pi); var matrixS = Matrix4x4.CreateScale(1.2f); var matrixTRS = Matrix4x4.Multiply(Matrix4x4.Multiply(matrixS, matrixR), matrixT); node.Matrix = matrixTRS; properties.Add(new Property(PropertyName.Matrix, matrixTRS)); } this.Models = new List <Model> { CreateModel((properties, node) => { // There are no properties set on this model. }), CreateModel((properties, node) => { SetTranslation(properties, node); }), CreateModel((properties, node) => { SetTranslationX(properties, node); }), CreateModel((properties, node) => { SetTranslationY(properties, node); }), CreateModel((properties, node) => { SetTranslationZ(properties, node); }), CreateModel((properties, node) => { SetRotation(properties, node); }), CreateModel((properties, node) => { SetScale(properties, node); }), CreateModel((properties, node) => { SetTranslation(properties, node); SetRotation(properties, node); SetScale(properties, node); }), CreateModel((properties, node) => { SetMatrix(properties, node); }), }; GenerateUsedPropertiesList(); }