public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Sampler = new Runtime.Sampler(); foreach (Property req in requiredProperty) { if (req.name == Propertyname.BaseColorTexture) { material.MetallicRoughnessMaterial.BaseColorTexture.Source = req.value; } } foreach (Property req in specialProperties) { if (req.name == Propertyname.TexCoord) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets[0] = req.value; } } foreach (Property property in combo) { if (property.name == Propertyname.MagFilter_Nearest || property.name == Propertyname.MagFilter_Linear) { material.MetallicRoughnessMaterial.BaseColorTexture.Sampler.MagFilter = property.value; } else if (property.name == Propertyname.MinFilter_Nearest || property.name == Propertyname.MinFilter_Linear || property.name == Propertyname.MinFilter_NearestMipmapNearest || property.name == Propertyname.MinFilter_LinearMipmapNearest || property.name == Propertyname.MinFilter_NearestMipmapLinear || property.name == Propertyname.MinFilter_LinearMipmapLinear) { material.MetallicRoughnessMaterial.BaseColorTexture.Sampler.MinFilter = property.value; } else if (property.name == Propertyname.WrapS_ClampToEdge || property.name == Propertyname.WrapS_MirroredRepeat || property.name == Propertyname.WrapS_Repeat) { material.MetallicRoughnessMaterial.BaseColorTexture.Sampler.WrapS = property.value; } else if (property.name == Propertyname.WrapT_ClampToEdge || property.name == Propertyname.WrapT_MirroredRepeat || property.name == Propertyname.WrapT_Repeat) { material.MetallicRoughnessMaterial.BaseColorTexture.Sampler.WrapT = property.value; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Switch from the flat plane to a model with multiple nodes wrapper = Common.MultiNode(); var nodeList = new List <Runtime.Node>(); nodeList.Add(wrapper.Scenes[0].Nodes[0]); nodeList.Add(wrapper.Scenes[0].Nodes[0].Children[0]); // Add a new child node that will inherit the transformations nodeList.Add((DeepCopy.CloneObject(wrapper.Scenes[0].Nodes[0]))); nodeList[2].Name = "Node1"; nodeList[2].Children = null; nodeList[1].Children = new List <Runtime.Node>(); nodeList[1].Children.Add(nodeList[2]); // Clear the vertex normal and tangent values already in the model foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Normals = null; node.Mesh.MeshPrimitives[0].Tangents = null; } foreach (Property property in combo) { if (property.name == Propertyname.Matrix) { nodeList[1].Matrix = specialProperties[0].value; } else if (property.name == Propertyname.Translation || property.name == Propertyname.Translation_X || property.name == Propertyname.Translation_Y || property.name == Propertyname.Translation_Z) { nodeList[1].Translation = property.value; } else if (property.name == Propertyname.Rotation) { nodeList[1].Rotation = specialProperties[1].value; } else if (property.name == Propertyname.Scale) { nodeList[1].Scale = property.value; } } // Apply the material to each node foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Material = material; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Remove the base model's UV0 on the empty set if (combo.Count < 0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.RemoveAt(0); material.MetallicRoughnessMaterial = null; } foreach (Property property in combo) { if (property.name == Propertyname.BaseColorTexture) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); } material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 0; } else if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = property.value; } else if (property.name == Propertyname.NormalTexture) { material.NormalTexture = new Runtime.Texture(); material.NormalTexture.Source = property.value; material.NormalTexture.TexCoordIndex = 0; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = property.value; } else if (property.name == Propertyname.VertexUV0_Float || property.name == Propertyname.VertexUV0_Byte || property.name == Propertyname.VertexUV0_Short) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordsComponentType = property.value; } } if (combo.Count > 0) // Don't set the material on the empty set { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Remove the base model's UV0 wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.RemoveAt(0); material.MetallicRoughnessMaterial = null; foreach (Property property in combo) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorComponentType = property.value.componentType; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorType = property.value.type; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value.colors; } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (Property req in requiredProperty) { if (req.name == Propertyname.AlphaMode_Mask) { material.AlphaMode = req.value; } } foreach (Property property in combo) { if (property.propertyGroup == 3) // Alpha Cutoff { material.AlphaCutoff = property.value; } else if (property.name == Propertyname.BaseColorFactor) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); } material.MetallicRoughnessMaterial.BaseColorFactor = property.value; } else if (property.name == Propertyname.BaseColorTexture) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); } material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; } else if (property.name == Propertyname.VertexColor_Vector4_Float) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorComponentType = Runtime.MeshPrimitive.ColorComponentTypeEnum.FLOAT; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorType = Runtime.MeshPrimitive.ColorTypeEnum.VEC4; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (Property req in requiredProperty) { if (req.name == Propertyname.DoubleSided) { material.DoubleSided = req.value; } } foreach (Property property in combo) { if (property.name == Propertyname.DoubleSided) { material.DoubleSided = property.value; } else if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = property.value; } else if (property.name == Propertyname.NormalTexture) { material.NormalTexture = new Runtime.Texture(); material.NormalTexture.Source = property.value; material.NormalTexture.TexCoordIndex = 0; } else if (property.name == Propertyname.BaseColorTexture) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); } material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Remove the UVs wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; foreach (Property property in combo) { if (property.name == Propertyname.MinVersion) { wrapper.Asset.MinVersion = property.value; } else if (property.name == Propertyname.Version || property.name == Propertyname.Version_Current) { wrapper.Asset.Version = property.value; } else if (property.name == Propertyname.Description_ExtensionRequired) { wrapper.ExtensionsRequired = new List <string>(); wrapper.ExtensionsRequired.Add("EXT_QuantumRendering"); material.MetallicRoughnessMaterial = null; material.Extensions = new List <Runtime.Extensions.Extension>(); material.Extensions.Add(new Runtime.Extensions.EXT_QuantumRendering()); var extension = material.Extensions[0] as Runtime.Extensions.EXT_QuantumRendering; extension.PlanckFactor = new Vector4(0.2f, 0.2f, 0.2f, 0.8f); extension.CopenhagenTexture = new Runtime.Texture(); extension.EntanglementFactor = new Vector3(0.4f, 0.4f, 0.4f); extension.ProbabilisticFactor = 0.3f; extension.SuperpositionCollapseTexture = new Runtime.Texture(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; } else if (property.name == Propertyname.Description_WithFallback) { // Fallback alpha mode will be set in the PostRuntimeChanges function } } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Enabled interleaved buffers wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Interleave = true; foreach (Property req in requiredProperty) { if (req.name == Propertyname.BaseColorTexture) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Sampler = new Runtime.Sampler(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = req.value; } } foreach (Property property in combo) { if (property.name == Propertyname.VertexColor_Vector3_Float | property.name == Propertyname.VertexColor_Vector3_Byte | property.name == Propertyname.VertexColor_Vector3_Short) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorComponentType = property.value.componentType; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorType = property.value.type; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value.colors; } else if (property.name == Propertyname.VertexUV0_Float || property.name == Propertyname.VertexUV0_Byte || property.name == Propertyname.VertexUV0_Short) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordsComponentType = property.value; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Same plane, but split into two triangle primitives var primitive1 = specialProperties.Find(e => e.name == Propertyname.Primitives_Split1); var primitive2 = specialProperties.Find(e => e.name == Propertyname.Primitives_Split2); Runtime.MeshPrimitive prim0 = new Runtime.MeshPrimitive { Positions = primitive1.value.Positions, Indices = primitive1.value.Indices, }; Runtime.MeshPrimitive prim2 = new Runtime.MeshPrimitive { Positions = primitive2.value.Positions, Indices = primitive2.value.Indices, }; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives = new List <Runtime.MeshPrimitive> { prim0, prim2 }; foreach (Property property in combo) { if (property.name == Propertyname.BaseColorTexture) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); } material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 0; } if (property.name == Propertyname.NormalTexture) { if (material.NormalTexture == null) { material.NormalTexture = new Runtime.Texture(); } material.NormalTexture.Source = property.value; material.NormalTexture.TexCoordIndex = 0; } if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Tangents = property.value; } else if (property.name == Propertyname.VertexColor_Vector4_Float) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Colors = property.value; } else if (property.name == Propertyname.Primitive0VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV0).value); } else if (property.name == Propertyname.Primitive1VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV0).value); } } if (material.MetallicRoughnessMaterial != null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Material = material; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (Property property in combo) { if (property.name == Propertyname.Mode_Points || property.name == Propertyname.Mode_Lines || property.name == Propertyname.Mode_Line_Loop || property.name == Propertyname.Mode_Line_Strip || property.name == Propertyname.Mode_Triangles || property.name == Propertyname.Mode_Triangle_Strip || property.name == Propertyname.Mode_Triangle_Fan || property.name == Propertyname.Mode_Triangles) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Mode = property.value; // These modes need a different set of indices than provided by the default model Property indices = null; switch (property.name) { case Propertyname.Mode_Points: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_Points); break; } case Propertyname.Mode_Lines: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_Lines); break; } case Propertyname.Mode_Line_Loop: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_LineLoop); break; } case Propertyname.Mode_Line_Strip: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_LineStrip); break; } case Propertyname.Mode_Triangle_Strip: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_TriangleStrip); break; } case Propertyname.Mode_Triangle_Fan: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_TriangleFan); break; } case Propertyname.Mode_Triangles: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_Triangles); break; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Mode = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices = indices.value; } else if (property.name == Propertyname.IndicesComponentType_Byte || property.name == Propertyname.IndicesComponentType_Short || property.name == Propertyname.IndicesComponentType_Int) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].IndexComponentType = property.value; } else if (property.name == Propertyname.IndicesComponentType_None) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices = null; var mode = combo.Find(e => e.propertyGroup == 1); var modeVertexes = specialProperties.Find(e => e.name == mode.name); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Positions = modeVertexes.value; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; return(wrapper); }
public Node_NegativeScale(List <string> textures, List <string> figures) : base(textures, figures) { modelGroupName = ModelGroupName.Node_NegativeScale; onlyBinaryProperties = false; Runtime.Image normalTexture = new Runtime.Image { Uri = textures.Find(e => e.Contains("Normal_Nodes")) }; Runtime.Image baseColorTexture = new Runtime.Image { Uri = textures.Find(e => e.Contains("BaseColor_Nodes")) }; Runtime.Image metallicRoughnessTexture = new Runtime.Image { Uri = textures.Find(e => e.Contains("MetallicRoughness_Nodes")) }; usedTextures.Add(normalTexture); usedTextures.Add(baseColorTexture); usedTextures.Add(metallicRoughnessTexture); Runtime.GLTF defaultModel = Common.MultiNode(); // Only used to get the default tangent and normal values List <Vector3> normals = new List <Vector3>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals); List <Vector4> tangents = new List <Vector4>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents); var matrixNegScale = Matrix4x4.CreateScale(new Vector3(-2, 1, 1)); properties = new List <Property> { new Property(Propertyname.Scale, new Vector3(-2, 1, 1)), new Property(Propertyname.Matrix, matrixNegScale), new Property(Propertyname.VertexNormal, normals), new Property(Propertyname.VertexTangent, tangents), new Property(Propertyname.NormalTexture, normalTexture), new Property(Propertyname.BaseColorTexture, baseColorTexture), new Property(Propertyname.MetallicRoughnessTexture, metallicRoughnessTexture), }; specialProperties = new List <Property> { new Property(Propertyname.Matrix, matrixNegScale), }; var matrix = properties.Find(e => e.name == Propertyname.Matrix); var scale = properties.Find(e => e.name == Propertyname.Scale); var normal = properties.Find(e => e.name == Propertyname.VertexNormal); var tangent = properties.Find(e => e.name == Propertyname.VertexTangent); var normTex = properties.Find(e => e.name == Propertyname.NormalTexture); var colorTex = properties.Find(e => e.name == Propertyname.BaseColorTexture); var metallicRoughTex = properties.Find(e => e.name == Propertyname.MetallicRoughnessTexture); specialCombos.Add(new List <Property>() { normal, tangent, normTex, colorTex, metallicRoughTex }); specialCombos.Add(new List <Property>() { scale, normal, tangent, normTex, colorTex, metallicRoughTex }); specialCombos.Add(new List <Property>() { matrix, normal, tangent, normTex, colorTex, metallicRoughTex }); specialCombos.Add(new List <Property>() { normal, normTex, colorTex, metallicRoughTex }); specialCombos.Add(new List <Property>() { scale, normal, normTex, colorTex, metallicRoughTex }); specialCombos.Add(new List <Property>() { matrix, normal, normTex, colorTex, metallicRoughTex }); removeCombos.Add(new List <Property>() { normal }); removeCombos.Add(new List <Property>() { tangent }); removeCombos.Add(new List <Property>() { normTex }); removeCombos.Add(new List <Property>() { colorTex }); removeCombos.Add(new List <Property>() { metallicRoughTex }); removeCombos.Add(new List <Property>() { matrix, scale, normal, tangent, normTex, colorTex, metallicRoughTex }); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Switch from the flat plane to a model with multiple nodes wrapper = Common.MultiNode(); var nodeList = new List <Runtime.Node>(); nodeList.Add(wrapper.Scenes[0].Nodes[0]); nodeList.Add(wrapper.Scenes[0].Nodes[0].Children[0]); // Clear the vertex normal and tangent values already in the model foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Normals = null; node.Mesh.MeshPrimitives[0].Tangents = null; } // Apply non-transforming attributes first, so they're copied to the control nodes foreach (Property property in combo) { if (property.name == Propertyname.NormalTexture) { material.NormalTexture = new Runtime.Texture(); material.NormalTexture.Source = property.value; } else if (property.name == Propertyname.BaseColorTexture) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; } else if (property.name == Propertyname.MetallicRoughnessTexture) { material.MetallicRoughnessMaterial.MetallicRoughnessTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.MetallicRoughnessTexture.Source = property.value; } else { foreach (var node in nodeList) { if (property.name == Propertyname.VertexNormal) { node.Mesh.MeshPrimitives[0].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { node.Mesh.MeshPrimitives[0].Tangents = property.value; } } } } foreach (Property property in combo) { if (property.name == Propertyname.Matrix) { nodeList[1].Matrix = specialProperties[0].value; } else if (property.name == Propertyname.Scale) { nodeList[1].Scale = property.value; } } // Apply the material to each node foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Material = material; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Initialize MetallicRoughness for the empty set if (combo.Count == 0) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); } foreach (Property property in combo) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); } switch (property.name) { case Propertyname.BaseColorFactor: { material.MetallicRoughnessMaterial.BaseColorFactor = property.value; break; } case Propertyname.MetallicFactor: { material.MetallicRoughnessMaterial.MetallicFactor = property.value; break; } case Propertyname.RoughnessFactor: { material.MetallicRoughnessMaterial.RoughnessFactor = property.value; break; } case Propertyname.BaseColorTexture: { material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; break; } case Propertyname.MetallicRoughnessTexture: { material.MetallicRoughnessMaterial.MetallicRoughnessTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.MetallicRoughnessTexture.Source = property.value; break; } case Propertyname.VertexColor_Vector3_Float: { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorComponentType = Runtime.MeshPrimitive.ColorComponentTypeEnum.FLOAT; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorType = Runtime.MeshPrimitive.ColorTypeEnum.VEC3; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; break; } } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (Property property in combo) { if (property.name == Propertyname.Mode_Points || property.name == Propertyname.Mode_Lines || property.name == Propertyname.Mode_Line_Loop || property.name == Propertyname.Mode_Line_Strip || property.name == Propertyname.Mode_Triangles || property.name == Propertyname.Mode_Triangle_Strip || property.name == Propertyname.Mode_Triangle_Fan || property.name == Propertyname.Mode_Triangles) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Mode = property.value; // Points uses a different set of vertexes for their base model if (property.name == Propertyname.Mode_Points) { var modeVertexes = specialProperties.Find(e => e.name == property.name); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Positions = modeVertexes.value; } } else if (property.name.ToString().Contains("IndicesValues_") && property.name != Propertyname.IndicesValues_None) { // These modes need a different set of indices than provided by the default model Property indices = null; var mode = combo.Find(e => e.name.ToString().Contains("Mode_")); switch (mode.name) { case Propertyname.Mode_Points: { indices = specialProperties.Find(e => e.name == Propertyname.IndicesValues_Points); break; } case Propertyname.Mode_Lines: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_Lines); break; } case Propertyname.Mode_Line_Loop: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_LineLoop); break; } case Propertyname.Mode_Line_Strip: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_LineStrip); break; } case Propertyname.Mode_Triangle_Strip: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_TriangleStrip); break; } case Propertyname.Mode_Triangle_Fan: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_TriangleFan); break; } case Propertyname.Mode_Triangles: { indices = properties.Find(e => e.name == Propertyname.IndicesValues_Triangles); break; } case Propertyname.IndicesComponentType_None: { indices = null; break; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices = indices.value; } else if (property.name == Propertyname.IndicesComponentType_Byte || property.name == Propertyname.IndicesComponentType_Short || property.name == Propertyname.IndicesComponentType_Int) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].IndexComponentType = property.value; } else if (property.name == Propertyname.IndicesComponentType_None) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices = null; // If there are no indicies, some modes need custom vertexes var mode = combo.Find(e => e.name.ToString().Contains("Mode_")); var modeVertexes = specialProperties.Find(e => e.name == mode.name); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Positions = modeVertexes.value; } //else //{ // int index = -1; // if (combo.Find(e => e.name == Propertyname.Mode_Points) != null) // { // index = 0; // } // else if (combo.Find(e => e.name == Propertyname.Mode_Lines) != null) // { // index = 1; // } // if (property.name == Propertyname.VertexUV0_Float) // { // List<List<Vector2>> texCoords = new List<List<Vector2>>(); // if (combo.Find(e => e.name == Propertyname.Mode_Points) != null) // { // texCoords.Add(specialProperties.Find(e => e.name == Propertyname.VertexUV0_Float).value[index]); // } // else if (combo.Find(e => e.name == Propertyname.Mode_Lines) != null) // { // texCoords.Add(specialProperties.Find(e => e.name == Propertyname.VertexUV0_Float).value[index]); // } // wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = texCoords; // } // else if (property.name == Propertyname.VertexNormal) // { // wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = specialProperties.Find(e => e.name == Propertyname.VertexNormal).value[index]; // } // else if (property.name == Propertyname.VertexTangent) // { // wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = specialProperties.Find(e => e.name == Propertyname.VertexTangent).value[index]; // } // else if (property.name == Propertyname.NormalTexture) // { // material.NormalTexture = new Runtime.Texture(); // material.NormalTexture.Source = property.value; // material.NormalTexture.TexCoordIndex = 0; // } //} } if (material.NormalTexture == null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Switch from the flat plane to a model with multiple nodes wrapper = Common.MultiNode(); var nodeList = new List <Runtime.Node>(); nodeList.Add(wrapper.Scenes[0].Nodes[0]); nodeList.Add(wrapper.Scenes[0].Nodes[0].Children[0]); // Clear the vertex normal and tangent values already in the model foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Normals = null; node.Mesh.MeshPrimitives[0].Tangents = null; } foreach (Property req in requiredProperty) { if (req.name == Propertyname.NormalTexture) { material.NormalTexture = new Runtime.Texture(); material.NormalTexture.Source = req.value; } else if (req.name == Propertyname.BaseColorTexture) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.BaseColorTexture.Source = req.value; } else if (req.name == Propertyname.MetallicRoughnessTexture) { material.MetallicRoughnessMaterial.MetallicRoughnessTexture = new Runtime.Texture(); material.MetallicRoughnessMaterial.MetallicRoughnessTexture.Source = req.value; } else if (req.name == Propertyname.Translation_Y) { if (combo.Find(e => e.name == Propertyname.Matrix_X) == null && combo.Find(e => e.name == Propertyname.Matrix_XY) == null && combo.Find(e => e.name == Propertyname.Matrix_XYZ) == null) // The matrixs have their own translation { nodeList[1].Translation = req.value; } } } foreach (Property property in combo) { foreach (var node in nodeList) { if (property.name == Propertyname.VertexNormal) { node.Mesh.MeshPrimitives[0].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { node.Mesh.MeshPrimitives[0].Tangents = property.value; } } if (property.name == Propertyname.Matrix_X || property.name == Propertyname.Matrix_XY || property.name == Propertyname.Matrix_XYZ) { nodeList[1].Matrix = property.value; } else if (property.name == Propertyname.Scale_X || property.name == Propertyname.Scale_XY || property.name == Propertyname.Scale_XYZ) { nodeList[1].Scale = property.value; } } // Apply the material to each node foreach (var node in nodeList) { node.Mesh.MeshPrimitives[0].Material = material; } return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); foreach (Property req in requiredProperty) { if (req.name == Propertyname.MetallicFactor) { material.MetallicRoughnessMaterial.MetallicFactor = req.value; } else if (req.name == Propertyname.BaseColorFactor) { material.MetallicRoughnessMaterial.BaseColorFactor = req.value; } } foreach (Property property in combo) { switch (property.name) { case Propertyname.EmissiveFactor: { material.EmissiveFactor = property.value; break; } case Propertyname.NormalTexture: { material.NormalTexture = new Runtime.Texture(); material.NormalTexture.Source = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = specialProperties.Find(e => e.name == Propertyname.VertexNormal).value; break; } case Propertyname.Scale: { material.NormalScale = property.value; break; } case Propertyname.OcclusionTexture: { material.OcclusionTexture = new Runtime.Texture(); material.OcclusionTexture.Source = property.value; break; } case Propertyname.Strength: { material.OcclusionStrength = property.value; break; } case Propertyname.EmissiveTexture: { material.EmissiveTexture = new Runtime.Texture(); material.EmissiveTexture.Source = property.value; break; } } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Mesh_PrimitiveMode(List <string> imageList) : base(imageList) { modelGroupName = ModelGroupName.Mesh_PrimitiveMode; onlyBinaryProperties = false; noPrerequisite = false; Runtime.Image figureIndices = new Runtime.Image { Uri = imageList.Find(e => e.Contains("Indices")) }; Runtime.Image figurePointsIndices = new Runtime.Image { Uri = imageList.Find(e => e.Contains("Indices_Points")) }; //Runtime.Image normalTexture = new Runtime.Image //{ // Uri = textures.Find(e => e.Contains("Normal_Plane")) //}; //usedTextures.Add(normalTexture); usedFigures.Add(figureIndices); usedFigures.Add(figurePointsIndices); List <Vector3> noIndicesPositionsTriangles = 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), }; List <Vector3> noIndicesPositionsLines = 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), new Vector3(0.5f, 0.5f, 0.0f), new Vector3(0.5f, -0.5f, 0.0f), }; List <Vector3> noIndicesPositionsLineloopFan = 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), }; // Make a list of verticies for points with 1024 values List <Vector3> noIndicesPositionsPoints = new List <Vector3>(); List <Vector3> 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.5f, 0.0f), new Vector3(0.5f, -0.5f, 0.0f) }; for (int corner = 0; corner < 4; corner++) { for (int x = 256; x > 0; x--) { Vector3 startPoint = cornerPoints[corner]; Vector3 endPoint = cornerPoints[corner + 1]; float fractionOfLine = (float)x / 256f; noIndicesPositionsPoints.Add(PointOnLine.FindPoint(startPoint, endPoint, fractionOfLine)); } } List <Vector3> noIndicesPositionsLineStrip = 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), }; List <Vector3> noIndicesPositionsTrianglestrip = 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), }; Runtime.GLTF defaultModel = Common.SinglePlane(); // Only used to get the default indices List <int> defaultModelIndices = new List <int>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices); List <int> linesIndices = new List <int> { 0, 3, 3, 2, 2, 1, 1, 0, }; List <int> lineloopFanIndices = new List <int> { 0, 3, 2, 1, }; List <int> linestripIndices = new List <int> { 0, 3, 2, 1, 0, }; List <int> trianglestripIndices = new List <int> { 0, 3, 1, 2, }; List <int> pointsIndices = new List <int>(); for (int x = 0; x < noIndicesPositionsPoints.Count; x++) { pointsIndices.Add(x); } //List<Vector2> pointsTextureCoords = new List<Vector2>() //{ // new Vector2(1.0f, 1.0f), // new Vector2(0.75f, 1.0f), // new Vector2(0.5f, 1.0f), // new Vector2(0.25f, 1.0f), // new Vector2(0.0f, 1.0f), // new Vector2(0.0f, 0.75f), // new Vector2(0.0f, 0.5f), // new Vector2(0.0f, 0.25f), // new Vector2(0.0f, 0.0f), // new Vector2(0.25f, 0.0f), // new Vector2(0.5f, 0.0f), // new Vector2(0.75f, 0.0f), // new Vector2(1.0f, 0.0f), // new Vector2(1.0f, 0.25f), // new Vector2(1.0f, 0.5f), // new Vector2(1.0f, 0.75f), //}; //List<Vector2> linesTextureCoords = new List<Vector2>() //{ // new Vector2(1.0f, 1.0f), // new Vector2(0.0f, 1.0f), // new Vector2(0.0f, 1.0f), // new Vector2(0.0f, 0.0f), // new Vector2(0.0f, 0.0f), // new Vector2(1.0f, 0.0f), // new Vector2(1.0f, 0.0f), // new Vector2(1.0f, 1.0f), //}; //List<List<Vector2>> textureCoords = new List<List<Vector2>>() //{ // pointsTextureCoords, // linesTextureCoords //}; //List<Vector3> normalsPoints = new List<Vector3>(); //List<Vector4> tangentsPoints = new List<Vector4>(); //for (int x = 0; x < 16; x++) //{ // normalsPoints.Add(new Vector3(0.0f, 0.0f, 1.0f)); // tangentsPoints.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f)); //} //List<Vector3> normalsLines = new List<Vector3>(); //List<Vector4> tangentsLines = new List<Vector4>(); //for (int x = 0; x < 8; x++) //{ // normalsLines.Add(new Vector3(0.0f, 0.0f, 1.0f)); // tangentsLines.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f)); //} //List<List<Vector3>> normals = new List<List<Vector3>>() //{ // normalsPoints, // normalsLines //}; //List<List<Vector4>> tangents = new List<List<Vector4>>() //{ // tangentsPoints, // tangentsLines //}; properties = new List <Property> { new Property(Propertyname.Mode_Points, Runtime.MeshPrimitive.ModeEnum.POINTS, group: 1), new Property(Propertyname.Mode_Lines, Runtime.MeshPrimitive.ModeEnum.LINES, group: 1), new Property(Propertyname.Mode_Line_Loop, Runtime.MeshPrimitive.ModeEnum.LINE_LOOP, group: 1), new Property(Propertyname.Mode_Line_Strip, Runtime.MeshPrimitive.ModeEnum.LINE_STRIP, group: 1), new Property(Propertyname.Mode_Triangle_Strip, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_STRIP, group: 1), new Property(Propertyname.Mode_Triangle_Fan, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_FAN, group: 1), new Property(Propertyname.Mode_Triangles, Runtime.MeshPrimitive.ModeEnum.TRIANGLES, group: 1), new Property(Propertyname.IndicesValues_Points, "[0 - 1023]", Propertyname.Mode_Points, group: 2), new Property(Propertyname.IndicesValues_Lines, linesIndices, Propertyname.Mode_Lines, group: 2), new Property(Propertyname.IndicesValues_LineLoop, lineloopFanIndices, Propertyname.Mode_Line_Loop, group: 2), new Property(Propertyname.IndicesValues_LineStrip, linestripIndices, Propertyname.Mode_Line_Strip, group: 2), new Property(Propertyname.IndicesValues_TriangleStrip, trianglestripIndices, Propertyname.Mode_Triangle_Strip, group: 2), new Property(Propertyname.IndicesValues_TriangleFan, lineloopFanIndices, Propertyname.Mode_Triangle_Fan, group: 2), new Property(Propertyname.IndicesValues_Triangles, defaultModelIndices, Propertyname.Mode_Triangles, group: 2), new Property(Propertyname.IndicesValues_None, " ", group: 2), new Property(Propertyname.IndicesComponentType_Byte, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_BYTE, group: 4), new Property(Propertyname.IndicesComponentType_Short, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_SHORT, group: 4), new Property(Propertyname.IndicesComponentType_Int, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_INT, group: 4), new Property(Propertyname.IndicesComponentType_None, " ", group: 4), //new Property(Propertyname.VertexUV0_Float, ":white_check_mark:", group:5), //new Property(Propertyname.VertexNormal, ":white_check_mark:"), //new Property(Propertyname.VertexTangent, ":white_check_mark:"), //new Property(Propertyname.NormalTexture, normalTexture), }; specialProperties = new List <Property> { //new Property(Propertyname.VertexUV0_Float, textureCoords, group:5), //new Property(Propertyname.VertexNormal, normals), //new Property(Propertyname.VertexTangent, tangents), new Property(Propertyname.Mode_Points, noIndicesPositionsPoints, group: 1), new Property(Propertyname.Mode_Lines, noIndicesPositionsLines, group: 1), new Property(Propertyname.Mode_Line_Loop, noIndicesPositionsLineloopFan, group: 1), new Property(Propertyname.Mode_Line_Strip, noIndicesPositionsLineStrip, group: 1), new Property(Propertyname.Mode_Triangle_Strip, noIndicesPositionsTrianglestrip, group: 1), new Property(Propertyname.Mode_Triangle_Fan, noIndicesPositionsLineloopFan, group: 1), new Property(Propertyname.Mode_Triangles, noIndicesPositionsTriangles, group: 1), new Property(Propertyname.IndicesValues_Points, pointsIndices, Propertyname.Mode_Points, group: 2), }; // Each mode with and without indices, and drop singles var defaultIndices = properties.Find(e => e.name == Propertyname.IndicesComponentType_Int); var noIndicesType = properties.Find(e => e.name == Propertyname.IndicesComponentType_None); var noIndicesValue = properties.Find(e => e.name == Propertyname.IndicesValues_None); foreach (var property in properties) { if (property.propertyGroup == 1) { var IndicesValues = properties.Find(e => e.prerequisite == property.name); specialCombos.Add(ComboHelper.CustomComboCreation( property, defaultIndices, IndicesValues)); specialCombos.Add(ComboHelper.CustomComboCreation( property, noIndicesValue, noIndicesType)); } removeCombos.Add(ComboHelper.CustomComboCreation( property)); } var valueTriangles = properties.Find(e => e.name == Propertyname.IndicesValues_Triangles); var modeTriangles = properties.Find(e => e.name == Propertyname.Mode_Triangles); var modePoints = properties.Find(e => e.name == Propertyname.Mode_Points); var modeLines = properties.Find(e => e.name == Propertyname.Mode_Lines); var typeByte = properties.Find(e => e.name == Propertyname.IndicesComponentType_Byte); var typeShort = properties.Find(e => e.name == Propertyname.IndicesComponentType_Short); var vertexUV = properties.Find(e => e.name == Propertyname.VertexUV0_Float); //var normal = properties.Find(e => e.name == Propertyname.VertexNormal); //var tangent = properties.Find(e => e.name == Propertyname.VertexTangent); //var normalTex = properties.Find(e => e.name == Propertyname.NormalTexture); specialCombos.Add(new List <Property>() { valueTriangles, typeByte, modeTriangles }); specialCombos.Add(new List <Property>() { valueTriangles, typeShort, modeTriangles }); //specialCombos.Add(new List<Property>() //{ // modePoints, // noIndicesValue, // noIndicesType, // vertexUV, // normal //}); //specialCombos.Add(new List<Property>() //{ // modeLines, // noIndicesValue, // noIndicesType, // vertexUV, // normal //}); //specialCombos.Add(new List<Property>() //{ // modeLines, // noIndicesValue, // noIndicesType, // vertexUV, // normal, // tangent, // normalTex //}); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (var req in requiredProperty) { if (req.name == Propertyname.ExtensionUsed_SpecularGlossiness) { // Initialize SpecGloss for every set material.Extensions = new List <Runtime.Extensions.Extension>(); material.Extensions.Add(new Runtime.Extensions.PbrSpecularGlossiness()); if (wrapper.ExtensionsUsed == null) { wrapper.ExtensionsUsed = new List <string>(); } wrapper.ExtensionsUsed = wrapper.ExtensionsUsed.Union( new string[] { "KHR_materials_pbrSpecularGlossiness" }).ToList(); } else if (req.name == Propertyname.BaseColorTexture) { // Apply the fallback MetallicRoughness for every set material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness { BaseColorTexture = new Runtime.Texture { Source = req.value } }; } } var material2 = DeepCopy.CloneObject(material); Runtime.MeshPrimitive prim0 = null; Runtime.MeshPrimitive prim1 = null; foreach (var property in specialProperties) { if (property.name == Propertyname.Primitives_Split1) { prim0 = new Runtime.MeshPrimitive { Positions = property.value.Positions, Indices = property.value.Indices, }; } else if (property.name == Propertyname.Primitives_Split2) { prim1 = new Runtime.MeshPrimitive { Positions = property.value.Positions, Indices = property.value.Indices, }; } else if (property.propertyGroup == 0 ) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives = new List <Runtime.MeshPrimitive> { prim0, prim1 }; } if (property.name == Propertyname.Primitive0VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV0).value); } else if (property.name == Propertyname.Primitive1VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV0).value); } } foreach (Property property in combo) { switch (property.name) { case Propertyname.SpecularGlossinessOnMaterial0_Yes: // Default. No changes needed break; case Propertyname.SpecularGlossinessOnMaterial0_No: material.Extensions = null; break; case Propertyname.SpecularGlossinessOnMaterial1_Yes: // Default. No changes needed break; case Propertyname.SpecularGlossinessOnMaterial1_No: material2.Extensions = null; break; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Material = material2; return(wrapper); }
public Mesh_Indices(List <string> textures, List <string> figures) : base(textures, figures) { modelGroupName = ModelGroupName.Mesh_Indices; onlyBinaryProperties = false; noPrerequisite = false; Runtime.Image figureIndices = new Runtime.Image { Uri = figures.Find(e => e.Contains("Indices")) }; usedFigures.Add(figureIndices); List <Vector3> noIndicesPositionsTriangles = 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), }; List <Vector3> noIndicesPositionsLines = 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), new Vector3(-0.5f, -0.5f, 0.0f), new Vector3(0.5f, -0.5f, 0.0f), }; List <Vector3> noIndicesPositionsLineloopPointsFan = 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), }; List <Vector3> noIndicesPositionsLineStrip = 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), }; List <Vector3> noIndicesPositionsTrianglestrip = 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), }; Runtime.GLTF defaultModel = Common.SinglePlane(); // Only used to get the default indices List <int> defaultModelIndices = new List <int>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices); List <int> linesIndices = new List <int> { 0, 3, 3, 2, 2, 1, 1, 0, }; List <int> lineloopPointsFanIndices = new List <int> { 0, 3, 2, 1, }; List <int> linestripIndices = new List <int> { 0, 3, 2, 1, 0, }; List <int> trianglestripIndices = new List <int> { 0, 3, 1, 2, }; 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(0.0f, 0.0f, 1.0f, 0.2f) }; properties = new List <Property> { new Property(Propertyname.Mode_Points, Runtime.MeshPrimitive.ModeEnum.POINTS, group: 1), new Property(Propertyname.Mode_Lines, Runtime.MeshPrimitive.ModeEnum.LINES, group: 1), new Property(Propertyname.Mode_Line_Loop, Runtime.MeshPrimitive.ModeEnum.LINE_LOOP, group: 1), new Property(Propertyname.Mode_Line_Strip, Runtime.MeshPrimitive.ModeEnum.LINE_STRIP, group: 1), new Property(Propertyname.Mode_Triangle_Strip, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_STRIP, group: 1), new Property(Propertyname.Mode_Triangle_Fan, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_FAN, group: 1), new Property(Propertyname.Mode_Triangles, Runtime.MeshPrimitive.ModeEnum.TRIANGLES, group: 1), new Property(Propertyname.IndicesValues_Points, lineloopPointsFanIndices, Propertyname.Mode_Points, group: 2), new Property(Propertyname.IndicesValues_Lines, linesIndices, Propertyname.Mode_Lines, group: 2), new Property(Propertyname.IndicesValues_LineLoop, lineloopPointsFanIndices, Propertyname.Mode_Line_Loop, group: 2), new Property(Propertyname.IndicesValues_LineStrip, linestripIndices, Propertyname.Mode_Line_Strip, group: 2), new Property(Propertyname.IndicesValues_TriangleStrip, trianglestripIndices, Propertyname.Mode_Triangle_Strip, group: 2), new Property(Propertyname.IndicesValues_TriangleFan, lineloopPointsFanIndices, Propertyname.Mode_Triangle_Fan, group: 2), new Property(Propertyname.IndicesValues_Triangles, defaultModelIndices, Propertyname.Mode_Triangles, group: 2), new Property(Propertyname.IndicesValues_None, " ", group: 2), new Property(Propertyname.IndicesComponentType_Byte, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_BYTE, group: 4), new Property(Propertyname.IndicesComponentType_Short, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_SHORT, group: 4), new Property(Propertyname.IndicesComponentType_Int, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_INT, group: 4), new Property(Propertyname.IndicesComponentType_None, " ", group: 4), }; specialProperties = new List <Property> { new Property(Propertyname.VertexColor_Vector4_Float, vertexColors), new Property(Propertyname.Mode_Points, noIndicesPositionsLineloopPointsFan, group: 1), new Property(Propertyname.Mode_Lines, noIndicesPositionsLines, group: 1), new Property(Propertyname.Mode_Line_Loop, noIndicesPositionsLineloopPointsFan, group: 1), new Property(Propertyname.Mode_Line_Strip, noIndicesPositionsLineStrip, group: 1), new Property(Propertyname.Mode_Triangle_Strip, noIndicesPositionsTrianglestrip, group: 1), new Property(Propertyname.Mode_Triangle_Fan, noIndicesPositionsLineloopPointsFan, group: 1), new Property(Propertyname.Mode_Triangles, noIndicesPositionsTriangles, group: 1), }; // Each mode with and without indices, and drop singles var defaultIndices = properties.Find(e => e.name == Propertyname.IndicesComponentType_Int); var noIndicesType = properties.Find(e => e.name == Propertyname.IndicesComponentType_None); var noIndicesValue = properties.Find(e => e.name == Propertyname.IndicesValues_None); foreach (var property in properties) { if (property.propertyGroup == 1) { var IndicesValues = properties.Find(e => e.prerequisite == property.name); specialCombos.Add(ComboHelper.CustomComboCreation( property, defaultIndices, IndicesValues)); specialCombos.Add(ComboHelper.CustomComboCreation( property, noIndicesValue, noIndicesType)); } removeCombos.Add(ComboHelper.CustomComboCreation( property)); } specialCombos.Add(ComboHelper.CustomComboCreation( properties.Find(e => e.name == Propertyname.IndicesValues_Triangles), properties.Find(e => e.name == Propertyname.IndicesComponentType_Byte), properties.Find(e => e.name == Propertyname.Mode_Triangles))); specialCombos.Add(ComboHelper.CustomComboCreation( properties.Find(e => e.name == Propertyname.IndicesValues_Triangles), properties.Find(e => e.name == Propertyname.IndicesComponentType_Short), properties.Find(e => e.name == Propertyname.Mode_Triangles))); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { foreach (var req in requiredProperty) { if (req.name == Propertyname.ExtensionUsed_SpecularGlossiness) { // Initialize SpecGloss for every set material.Extensions = new List <Runtime.Extensions.Extension>(); material.Extensions.Add(new Runtime.Extensions.PbrSpecularGlossiness()); if (wrapper.ExtensionsUsed == null) { wrapper.ExtensionsUsed = new List <string>(); } wrapper.ExtensionsUsed = wrapper.ExtensionsUsed.Union( new string[] { "KHR_materials_pbrSpecularGlossiness" }).ToList(); } else if (req.name == Propertyname.BaseColorTexture) { // Apply the fallback MetallicRoughness for every set material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness { BaseColorTexture = new Runtime.Texture { Source = req.value } }; } } var extension = material.Extensions[0] as Runtime.Extensions.PbrSpecularGlossiness; foreach (Property property in combo) { switch (property.name) { case Propertyname.DiffuseFactor: extension.DiffuseFactor = property.value; break; case Propertyname.SpecularFactor: extension.SpecularFactor = property.value; break; case Propertyname.SpecularFactor_Override: extension.SpecularFactor = property.value; break; case Propertyname.GlossinessFactor: extension.GlossinessFactor = property.value; break; case Propertyname.DiffuseTexture: extension.DiffuseTexture = new Runtime.Texture(); extension.DiffuseTexture.Source = property.value; break; case Propertyname.SpecularGlossinessTexture: extension.SpecularGlossinessTexture = new Runtime.Texture(); extension.SpecularGlossinessTexture.Source = property.value; break; case Propertyname.OcclusionTexture: material.OcclusionTexture = new Runtime.Texture(); material.OcclusionTexture.Source = property.value; break; case Propertyname.VertexColor_Vector3_Float: wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorComponentType = Runtime.MeshPrimitive.ColorComponentTypeEnum.FLOAT; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].ColorType = Runtime.MeshPrimitive.ColorTypeEnum.VEC3; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; break; case Propertyname.ExtensionUsed_SpecularGlossiness: if (wrapper.ExtensionsUsed == null) { wrapper.ExtensionsUsed = new List <string>(); } wrapper.ExtensionsUsed = wrapper.ExtensionsUsed.Union( new string[] { "KHR_materials_pbrSpecularGlossiness" }).ToList(); break; } } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material; return(wrapper); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Determines which of the primitives will have the material and attributes applied to it var splitType = combo.Find(e => e.propertyGroup == 1); foreach (Property property in combo) { if (property.name == Propertyname.Primitives_Split1 || property.name == Propertyname.Primitives_Split2 || property.name == Propertyname.Primitives_Split3 || property.name == Propertyname.Primitives_Split4) { // Same plane, but split into two triangle primitives var primitive0 = specialProperties.Find(e => e.name == Propertyname.Primitive_0); var primitive1 = specialProperties.Find(e => e.name == Propertyname.Primitive_1); Runtime.MeshPrimitive prim0 = new Runtime.MeshPrimitive { Positions = primitive0.value.Positions, Indices = primitive0.value.Indices, }; Runtime.MeshPrimitive prim1 = new Runtime.MeshPrimitive { Positions = primitive1.value.Positions, Indices = primitive1.value.Indices, }; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives = new List <Runtime.MeshPrimitive> { prim0, prim1 }; } if (property.name == Propertyname.BaseColorTexture) { if (material.MetallicRoughnessMaterial == null) { material.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material.MetallicRoughnessMaterial.BaseColorTexture = new Runtime.Texture(); } material.MetallicRoughnessMaterial.BaseColorTexture.Source = property.value; material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 0; } if (property.name == Propertyname.NormalTexture) { if (material.NormalTexture == null) { material.NormalTexture = new Runtime.Texture(); } material.NormalTexture.Source = property.value; material.NormalTexture.TexCoordIndex = 0; } // Attributes set for only the first primitive if (splitType.name == Propertyname.Primitives_Split1) { if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Normals = null; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Tangents = null; } else if (property.name == Propertyname.VertexColor_Vector4_Float) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Colors = null; } else if (ReadmeStringHelper.GenerateNameWithSpaces(property.name.ToString()) == ReadmeStringHelper.GenerateNameWithSpaces(Propertyname.Primitive0VertexUV0.ToString())) // All UV0 { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV0).value); } else if (ReadmeStringHelper.GenerateNameWithSpaces(property.name.ToString()) == ReadmeStringHelper.GenerateNameWithSpaces(Propertyname.Primitive0VertexUV1.ToString())) // All UV1 { if (wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets == null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV1).value); } } // Attributes set for only the second primitive else if (splitType.name == Propertyname.Primitives_Split2) { if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Tangents = property.value; } else if (property.name == Propertyname.VertexColor_Vector4_Float) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Colors = property.value; } else if (ReadmeStringHelper.GenerateNameWithSpaces(property.name.ToString()) == ReadmeStringHelper.GenerateNameWithSpaces(Propertyname.Primitive1VertexUV0.ToString())) // All UV0 { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV0).value); } else if (ReadmeStringHelper.GenerateNameWithSpaces(property.name.ToString()) == ReadmeStringHelper.GenerateNameWithSpaces(Propertyname.Primitive1VertexUV1.ToString())) // All UV1 { if (wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets == null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV1).value); } } // Attributes set for both of the primitives else if (splitType.name == Propertyname.Primitives_Split3) { if (property.name == Propertyname.VertexNormal) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Normals = property.value; } else if (property.name == Propertyname.VertexTangent) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Tangents = property.value; } else if (property.name == Propertyname.VertexColor_Vector4_Float) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = property.value; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Colors = property.value; } else if (property.name == Propertyname.Primitive0VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV0).value); } else if (property.name == Propertyname.Primitive1VertexUV0) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV0).value); } else if (property.name == Propertyname.Primitive0VertexUV1) { if (wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets == null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = new List <List <Vector2> >(); } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive0VertexUV1).value); } else if (property.name == Propertyname.Primitive1VertexUV1) { if (wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets == null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = new List <List <Vector2> >(); } wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets.Add( specialProperties.Find(e => e.name == Propertyname.Primitive1VertexUV1).value); } } // Attributes set for neither of the primitives else if (splitType.name == Propertyname.Primitives_Split4) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Normals = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Tangents = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Colors = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Colors = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].TextureCoordSets = null; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].TextureCoordSets = null; } } // Material needs to be a deep copy here, or both primitives will get the same Mat. if (material.MetallicRoughnessMaterial != null) { if (splitType.name == Propertyname.Primitives_Split1 || splitType.name == Propertyname.Primitives_Split3) { var mat = DeepCopy.CloneObject(material); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = mat; } if (splitType.name == Propertyname.Primitives_Split2 || splitType.name == Propertyname.Primitives_Split3) { var mat = DeepCopy.CloneObject(material); wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Material = mat; } } // Use the second UV if it has been set if (splitType.name != Propertyname.Primitives_Split4) { var prim0UV1 = combo.Find(e => e.name == Propertyname.Primitive0VertexUV1); var prim1UV1 = combo.Find(e => e.name == Propertyname.Primitive1VertexUV1); if (prim0UV1 != null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0]. Material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 1; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0]. Material.NormalTexture.TexCoordIndex = 1; } if (prim1UV1 != null) { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1]. Material.MetallicRoughnessMaterial.BaseColorTexture.TexCoordIndex = 1; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1]. Material.NormalTexture.TexCoordIndex = 1; } } return(wrapper); }
public Node_NegativeScale(List <string> imageList) : base(imageList) { modelGroupName = ModelGroupName.Node_NegativeScale; onlyBinaryProperties = false; Runtime.Image normalTexture = new Runtime.Image { Uri = imageList.Find(e => e.Contains("Normal_Nodes")) }; Runtime.Image baseColorTexture = new Runtime.Image { Uri = imageList.Find(e => e.Contains("BaseColor_Nodes")) }; Runtime.Image metallicRoughnessTexture = new Runtime.Image { Uri = imageList.Find(e => e.Contains("MetallicRoughness_Nodes")) }; usedTextures.Add(normalTexture); usedTextures.Add(baseColorTexture); usedTextures.Add(metallicRoughnessTexture); Runtime.GLTF defaultModel = Common.MultiNode(); // Only used to get the default tangent and normal values List <Vector3> normals = new List <Vector3>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Normals); List <Vector4> tangents = new List <Vector4>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Tangents); var matrixT = Matrix4x4.CreateTranslation(new Vector3(0, 2, 0)); var matrixNegScale_X = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, 1, 1)), matrixT); var matrixNegScale_XY = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, -1, 1)), matrixT); var matrixNegScale_XYZ = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1, -1, -1)), matrixT); requiredProperty = new List <Property> { new Property(Propertyname.Translation_Y, new Vector3(0, 2, 0), group: 1), new Property(Propertyname.BaseColorTexture, baseColorTexture), new Property(Propertyname.NormalTexture, normalTexture), new Property(Propertyname.MetallicRoughnessTexture, metallicRoughnessTexture), }; properties = new List <Property> { new Property(Propertyname.Matrix_X, matrixNegScale_X, group: 1), new Property(Propertyname.Matrix_XY, matrixNegScale_XY, group: 1), new Property(Propertyname.Matrix_XYZ, matrixNegScale_XYZ, group: 1), new Property(Propertyname.Scale_X, new Vector3(-1, 1, 1), group: 2), new Property(Propertyname.Scale_XY, new Vector3(-1, -1, 1), group: 2), new Property(Propertyname.Scale_XYZ, new Vector3(-1, -1, -1), group: 2), new Property(Propertyname.VertexNormal, normals), new Property(Propertyname.VertexTangent, tangents), }; var scale_X = properties.Find(e => e.name == Propertyname.Scale_X); var scale_XY = properties.Find(e => e.name == Propertyname.Scale_XY); var scale_XYZ = properties.Find(e => e.name == Propertyname.Scale_XYZ); var normal = properties.Find(e => e.name == Propertyname.VertexNormal); var tangent = properties.Find(e => e.name == Propertyname.VertexTangent); // Makes combos with both normals, and normals with tangents for each of the following scale values var scaleSets = new List <Property>() { scale_X, scale_XY, scale_XYZ, }; foreach (var scale in scaleSets) { specialCombos.Add(new List <Property>() { scale, normal, }); specialCombos.Add(new List <Property>() { scale, normal, tangent, }); } removeCombos.Add(new List <Property>() { normal, }); removeCombos.Add(new List <Property>() { tangent, }); }
public Runtime.GLTF SetModelAttributes(Runtime.GLTF wrapper, Runtime.Material material0, List <Property> combo, ref glTFLoader.Schema.Gltf gltf) { // Same plane, but split into two triangle primitives var primitive1 = specialProperties.Find(e => e.name == Propertyname.Primitives_Split1); var primitive2 = specialProperties.Find(e => e.name == Propertyname.Primitives_Split2); Runtime.MeshPrimitive prim0 = new Runtime.MeshPrimitive { Positions = primitive1.value.Positions, Indices = primitive1.value.Indices, }; Runtime.MeshPrimitive prim2 = new Runtime.MeshPrimitive { Positions = primitive2.value.Positions, Indices = primitive2.value.Indices, }; wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives = new List <Runtime.MeshPrimitive> { prim0, prim2 }; // Make a second material var material1 = DeepCopy.CloneObject(material0); // Set the base color factor on both materials material0.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material1.MetallicRoughnessMaterial = new Runtime.PbrMetallicRoughness(); material0.MetallicRoughnessMaterial.BaseColorFactor = requiredProperty.Find(e => e.name == Propertyname.Material0WithBaseColorFactor).value; material1.MetallicRoughnessMaterial.BaseColorFactor = requiredProperty.Find(e => e.name == Propertyname.Material1WithBaseColorFactor).value; foreach (Property property in combo) { switch (property.name) { case Propertyname.Primitive0_Material0BaseColorFactor: { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material0; break; } case Propertyname.Primitive0_Material1BaseColorFactor: { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Material = material1; break; } case Propertyname.Primitive1_Material0BaseColorFactor: { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Material = material0; break; } case Propertyname.Primitive1_Material1BaseColorFactor: { wrapper.Scenes[0].Nodes[0].Mesh.MeshPrimitives[1].Material = material1; break; } } } return(wrapper); }