protected override bool OnLoad() { if (!IsValid()) { return(false); } GLTFProperty.Load(glTFObject, baseColorTexture, metallicRoughnessTexture); // Base Color Color baseColor; if (baseColorFactor != null && baseColorFactor.Length == 3) { baseColor = new Color(baseColorFactor[0], baseColorFactor[1], baseColorFactor[2]); } if (baseColorFactor != null && baseColorFactor.Length == 4) { baseColor = new Color(baseColorFactor[0], baseColorFactor[1], baseColorFactor[2], baseColorFactor[3]); } else { baseColor = Color.white; } // Material Material = new Material(Shader.Find("GLTFUtility/Standard (Metallic)")); Material.color = baseColor; Material.SetFloat("_Metallic", metallicFactor); Material.SetFloat("_Glossiness", 1 - roughnessFactor); if (baseColorTexture != null && baseColorTexture.index >= 0) { if (glTFObject.textures.Count <= baseColorTexture.index) { Debug.LogWarning("Attempted to get basecolor texture index " + baseColorTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_MainTex", glTFObject.textures[baseColorTexture.index].Source.GetTexture()); } } if (metallicRoughnessTexture != null && metallicRoughnessTexture.index >= 0) { if (glTFObject.textures.Count <= metallicRoughnessTexture.index) { Debug.LogWarning("Attempted to get metallicRoughness texture index " + metallicRoughnessTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_MetallicGlossMap", glTFObject.textures[metallicRoughnessTexture.index].Source.GetFixedMetallicRoughness()); Material.EnableKeyword("_METALLICGLOSSMAP"); } } return(true); }
private void LoadInternal(string filepath) { this.directoryRoot = Directory.GetParent(filepath).ToString() + "/"; this.mainFile = Path.GetFileName(filepath); GLTFProperty.Load(this, buffers); GLTFProperty.Load(this, bufferViews); GLTFProperty.Load(this, accessors); GLTFProperty.Load(this, images); GLTFProperty.Load(this, textures); GLTFProperty.Load(this, materials); GLTFProperty.Load(this, scenes); GLTFProperty.Load(this, nodes); GLTFProperty.Load(this, meshes); GLTFProperty.Load(this, animations); GLTFProperty.Load(this, skins); }
public void Load(string directoryRoot, string mainFile) { if (loaded) { Debug.LogWarning("GLTFObject already loaded"); return; } this.directoryRoot = directoryRoot; this.mainFile = mainFile; GLTFProperty.Load(this, buffers); GLTFProperty.Load(this, bufferViews); GLTFProperty.Load(this, accessors); GLTFProperty.Load(this, images); GLTFProperty.Load(this, textures); GLTFProperty.Load(this, materials); GLTFProperty.Load(this, scenes); GLTFProperty.Load(this, nodes); GLTFProperty.Load(this, meshes); GLTFProperty.Load(this, animations); GLTFProperty.Load(this, skins); loaded = true; }
protected override bool OnLoad() { if (!IsValid()) { return(false); } GLTFProperty.Load(glTFObject, diffuseTexture, specularGlossinessTexture); // Base color Color baseColor; if (diffuseFactor != null && diffuseFactor.Length == 3) { baseColor = new Color(diffuseFactor[0], diffuseFactor[1], diffuseFactor[2]); } if (diffuseFactor != null && diffuseFactor.Length == 4) { baseColor = new Color(diffuseFactor[0], diffuseFactor[1], diffuseFactor[2], diffuseFactor[3]); } else { baseColor = Color.white; } // Specular color Color specularColor; if (specularFactor != null && specularFactor.Length == 3) { specularColor = new Color(specularFactor[0], specularFactor[1], specularFactor[2]); } else { specularColor = Color.white; } // Material base values Material = new Material(Shader.Find("GLTFUtility/Standard (Specular)")); Material.color = baseColor; Material.SetColor("_SpecColor", specularColor); Material.SetFloat("_Glossiness", glossinessFactor); // Diffuse texture if (diffuseTexture != null && diffuseTexture.index >= 0) { if (glTFObject.textures.Count <= diffuseTexture.index) { Debug.LogWarning("Attempted to get diffuseTexture texture index " + diffuseTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_MainTex", glTFObject.textures[diffuseTexture.index].Source.GetTexture()); } } // Specular texture if (specularGlossinessTexture != null && specularGlossinessTexture.index >= 0) { if (glTFObject.textures.Count <= specularGlossinessTexture.index) { Debug.LogWarning("Attempted to get specularGlossinessTexture texture index " + specularGlossinessTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_SpecGlossMap", glTFObject.textures[specularGlossinessTexture.index].Source.GetFixedMetallicRoughness()); Material.EnableKeyword("_SPECGLOSSMAP"); } } return(true); }
protected override bool OnLoad() { if (!IsValid()) { return(false); } GLTFProperty.Load(glTFObject, baseColorTexture, metallicRoughnessTexture); // Base Color Color baseColor; if (baseColorFactor != null && baseColorFactor.Length == 3) { baseColor = new Color(baseColorFactor[0], baseColorFactor[1], baseColorFactor[2]); } if (baseColorFactor != null && baseColorFactor.Length == 4) { baseColor = new Color(baseColorFactor[0], baseColorFactor[1], baseColorFactor[2], baseColorFactor[3]); } else { baseColor = Color.white; } // Material Shader sh = null; #if UNITY_2019_1_OR_NEWER // LWRP support if (GraphicsSettings.renderPipelineAsset) { sh = GraphicsSettings.renderPipelineAsset.defaultShader; } #endif if (sh == null) { sh = Shader.Find("GLTFUtility/Standard (Metallic)"); } Material = new Material(sh); Material.color = baseColor; Material.SetFloat("_Metallic", metallicFactor); Material.SetFloat("_Glossiness", 1 - roughnessFactor); if (baseColorTexture != null && baseColorTexture.index >= 0) { if (glTFObject.textures.Count <= baseColorTexture.index) { Debug.LogWarning("Attempted to get basecolor texture index " + baseColorTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_MainTex", glTFObject.textures[baseColorTexture.index].Source.GetTexture()); } } if (metallicRoughnessTexture != null && metallicRoughnessTexture.index >= 0) { if (glTFObject.textures.Count <= metallicRoughnessTexture.index) { Debug.LogWarning("Attempted to get metallicRoughness texture index " + metallicRoughnessTexture.index + " when only " + glTFObject.textures.Count + " exist"); } else { Material.SetTexture("_MetallicGlossMap", glTFObject.textures[metallicRoughnessTexture.index].Source.GetFixedMetallicRoughness()); Material.EnableKeyword("_METALLICGLOSSMAP"); } } // After the texture and color is extracted from the glTFObject if (Material.HasProperty("_BaseMap")) { Material.SetTexture("_BaseMap", Material.mainTexture); } if (Material.HasProperty("_BaseColor")) { Material.SetColor("_BaseColor", baseColor); } return(true); }