public override GameObject BuildScene(string name, bool saveToDisk = false) { #if UNITY_EDITOR if (saveToDisk) { //FileStream file =File.Create (ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + this.texture.tex) ; //file.Write (image, 0, image.Length) ; //file.Close () ; File.WriteAllBytes(ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + this.texture.tex, image); AssetDatabase.Refresh(); } #endif StandardMaterial lmvMat = new StandardMaterial(lmvtkDef, null); Texture2D tex = new Texture2D(1, 1); tex.LoadImage(image); tex.Apply(); #if UNITY_EDITOR if (saveToDisk) { tex = AssetDatabase.LoadAssetAtPath <Texture2D> (ForgeConstants._resourcesPath + this.loader.PROJECTID + "/" + this.texture.tex); } #endif image = null; switch (texture.texType) { case Texture.TextureType.Diffuse: material.SetTexture("_MainTex", tex); material.mainTextureScale = new Vector2(texture.u, texture.v); break; case Texture.TextureType.Specular: material.SetTexture("_SpecGlossMap", tex); //material.SetFloat ("_Glossiness", texture.u) ; //if ( lmvMat.isMetal ) // material.SetFloat ("_MetallicGlossMap", texture.u) ; //else material.SetFloat("_GlossMapScale", texture.u); //material.EnableKeyword ("_SPECULARHIGHLIGHTS_OFF") ; //material.SetFloat ("_SpecularHighlights", 0f) ; break; case Texture.TextureType.Bump: material.SetTexture("_BumpMap", tex); material.SetFloat("_BumpScale", texture.u); break; } material.SetMaterialKeywords(texture.texType, lmvMat.isMetal); base.BuildScene(name, saveToDisk); return(gameObject); }
protected Material CreateMaterial(StandardMaterial lmvMat) { // https://docs.unity3d.com/Manual/StandardShaderMetallicVsSpecular.html // Standard: The shader exposes a “metallic” value that states whether the material is metallic or not. // Standard (Specular setup): Choose this shader for the classic approach. Material mat = new Material( lmvMat.isMetal == true ? Shader.Find("Standard") : Shader.Find("Standard (Specular setup)") ); try { if (lmvMat.specular_tex != null) { mat.EnableKeyword("_SPECULARHIGHLIGHTS_OFF"); mat.SetFloat("_SpecularHighlights", 0f); } //mat.DisableKeyword ("_SPECULARHIGHLIGHTS_OFF") ; //mat.SetFloat ("_SpecularHighlights", 1f) ; mat.EnableKeyword("_GLOSSYREFLECTIONS_OFF"); mat.SetFloat("_GlossyReflections", 0f); var ambiant = lmvMat.ambient; if (ambiant != Color.clear) { mat.SetColor("_Color", ambiant); } var diffuse = lmvMat.diffuse; if (diffuse != Color.clear) { mat.SetColor("_Color", diffuse); } var emissive = lmvMat.emissive; if (emissive != Color.clear) { mat.SetColor("_EmissionColor", emissive); } var specular = lmvMat.specular; if (specular != Color.clear && ( lmvMat.isMetal == true && // In Unity3d, the texture would not show lmvMat.diffuse_tex != null && specular != Color.white ) ) { mat.SetColor("_SpecColor", specular); } var transparent = lmvMat.transparent; if (transparent) { mat.SetFloat("_Mode", (float)BlendMode.Transparent); mat.EnableKeyword("_ALPHABLEND_ON"); Color color = mat.GetColor("_Color"); color.a = lmvMat.transparency; mat.SetColor("_Color", color); } // Create a new request to get the Textures if (lmvMat.diffuse_tex != null) { //TextureRequest req =new TextureRequest (loader, null, mat, Texture.TextureType.Diffuse, lmvMat.material) ; TextureRequest req = new TextureRequest(loader, null, bearer, mat, lmvMat.diffuse_tex, lmvMat.material); if (fireRequestCallback != null) { fireRequestCallback(this, req); } } if (lmvMat.specular_tex != null) { TextureRequest req = new TextureRequest(loader, null, bearer, mat, lmvMat.specular_tex, lmvMat.material); if (fireRequestCallback != null) { fireRequestCallback(this, req); } } if (lmvMat.bump_tex != null) { TextureRequest req = new TextureRequest(loader, null, bearer, mat, lmvMat.bump_tex, lmvMat.material); if (fireRequestCallback != null) { fireRequestCallback(this, req); } } } catch (System.Exception e) { Debug.Log("exception " + e.Message); mat = ForgeLoaderEngine.GetDefaultMaterial(); } return(mat); }
protected Material CreateMaterial(JSONNode json, JSONNode protein) { StandardMaterial lmvMat = new StandardMaterial(json, protein); return(CreateMaterial(lmvMat)); }
protected Material CreateMaterial(string jsonSt, string proteinSt) { StandardMaterial lmvMat = new StandardMaterial(jsonSt, proteinSt); return(CreateMaterial(lmvMat)); }