Beispiel #1
0
        protected void requestTextures(object sender, IRequestInterface args)
        {
            // Textures are safe because they will be called only once per texture/material
            TextureRequest reqObj = args as TextureRequest;

            reqObj.uri = new System.Uri(ForgeLoaderConstants._endpoint + URN + "/texture/" + reqObj.texture.tex);
            //UnityEngine.Debug.Log ("URI request: " + reqObj.uri.ToString ());
            _mgr.Register(reqObj);
        }
        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);
        }