UnityRuntimeOBJLoaderDocs icon indicating copy to clipboard operation
UnityRuntimeOBJLoaderDocs copied to clipboard

Obj importer texture bug (Webgl)

Open AmineZouitine opened this issue 3 years ago • 2 comments

Hi, I use your addon which works very well to import an obj with its mlt in runtime, but when I use it in webgl (so in a web browser), the obj has no texture (I use the mlt well). If you have an idea, you would help me a lot.


    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Tab))
        {
            StartCoroutine(ImportObj());
        }
    }
 
    IEnumerator ImportObj()
    {
        var www = new WWW("http://192.168.43.4:3008/mapobj");
        var www2 = new WWW("http://192.168.43.4:3008/mapmtl");
 
        while (!www.isDone || !www2.isDone)
        {
            yield return new WaitForSeconds(1);
        }
        var textStream = new MemoryStream(Encoding.UTF8.GetBytes(www.text));
        var textStream2 = new MemoryStream(Encoding.UTF8.GetBytes(www2.text));
        var loadedObj = new OBJLoader().Load(textStream, textStream2);
    }

AmineZouitine avatar Jun 15 '21 14:06 AmineZouitine

@AmineZouitine did you figured this out. I can't get the colors even on the editor runtime

jayampathiadhikari avatar Jul 16 '21 18:07 jayampathiadhikari

In my project I noticed that models seemed to be displaying without textures (blank white). However, upon closer inspection I learned that they were actually loading the textures, but the brightness of the specular color was completely washing them out. Apparently the specular colors really ought to be quite dark (e.g. even super shiny objects only have a specular value of 0.1 or so), but the .MTL files often specified values much much higher. (Btw, I'm using Linear rendering... I'm not sure if the same is true in Gamma rendering).

Anyway, I fixed this in my project by replacing line 232 in MTLLoader.cs with this:

var specColor = OBJLoaderHelper.ColorFromStrArray(splitLine);

// In Linear rendering, spec colors need to be toned WAY down, otherwise they wash everything out
specColor.r /= 10f;           
specColor.g /= 10f;           
specColor.b /= 10f;   

currentMaterial.SetColor("_SpecColor", specColor);

ggardinerSC avatar Jul 28 '21 23:07 ggardinerSC