public static MaterialCommonConstant Deserialize(GLTFRoot root, JsonReader reader) { var commonConstant = new MaterialCommonConstant(); if (reader.Read() && reader.TokenType != JsonToken.StartObject) { throw new Exception("Asset must be an object."); } while (reader.Read() && reader.TokenType == JsonToken.PropertyName) { var curProp = reader.Value.ToString(); switch (curProp) { case "ambientFactor": commonConstant.AmbientFactor = reader.ReadAsRGBColor(); break; case "lightmapTexture": commonConstant.LightmapTexture = TextureInfo.Deserialize(root, reader); break; case "lightmapFactor": commonConstant.LightmapFactor = reader.ReadAsRGBColor(); break; default: commonConstant.DefaultPropertyDeserializer(root, reader); break; } } return commonConstant; }
public MaterialCommonConstant(MaterialCommonConstant materialCommonConstant, GLTFRoot gltfRoot) : base(materialCommonConstant) { if (materialCommonConstant == null) return; AmbientFactor = materialCommonConstant.AmbientFactor; LightmapTexture = new TextureInfo(materialCommonConstant.LightmapTexture, gltfRoot); LightmapFactor = materialCommonConstant.LightmapFactor; }
public static Material Deserialize(GLTFRoot root, JsonReader reader) { var material = new Material(); while (reader.Read() && reader.TokenType == JsonToken.PropertyName) { var curProp = reader.Value.ToString(); switch (curProp) { case "pbrMetallicRoughness": material.PbrMetallicRoughness = PbrMetallicRoughness.Deserialize(root, reader); break; case "commonConstant": material.CommonConstant = MaterialCommonConstant.Deserialize(root, reader); break; case "normalTexture": material.NormalTexture = NormalTextureInfo.Deserialize(root, reader); break; case "occlusionTexture": material.OcclusionTexture = OcclusionTextureInfo.Deserialize(root, reader); break; case "emissiveTexture": material.EmissiveTexture = TextureInfo.Deserialize(root, reader); break; case "emissiveFactor": material.EmissiveFactor = reader.ReadAsRGBColor(); break; case "alphaMode": material.AlphaMode = reader.ReadStringEnum <AlphaMode>(); break; case "alphaCutoff": material.AlphaCutoff = reader.ReadAsDouble().Value; break; case "doubleSided": material.DoubleSided = reader.ReadAsBoolean().Value; break; default: material.DefaultPropertyDeserializer(root, reader); break; } } return(material); }
public Material(Material material, GLTFRoot gltfRoot) : base(material, gltfRoot) { if (material == null) { return; } if (material.PbrMetallicRoughness != null) { PbrMetallicRoughness = new PbrMetallicRoughness(material.PbrMetallicRoughness, gltfRoot); } if (material.CommonConstant != null) { CommonConstant = new MaterialCommonConstant(material.CommonConstant, gltfRoot); } if (material.NormalTexture != null) { NormalTexture = new NormalTextureInfo(material.NormalTexture, gltfRoot); } if (material.OcclusionTexture != null) { OcclusionTexture = new OcclusionTextureInfo(material.OcclusionTexture, gltfRoot); } if (material.EmissiveTexture != null) { EmissiveTexture = new TextureInfo(material.EmissiveTexture, gltfRoot); } EmissiveFactor = material.EmissiveFactor; AlphaMode = material.AlphaMode; AlphaCutoff = material.AlphaCutoff; DoubleSided = material.DoubleSided; }