All you have to do is place the .mtl file somewhere and point at it from the .obj file.
For eg, from scenes/StanfordBunny.obj of the Playground public repository, line 3:
There’s a StanfordBunny.mtl file in the same location than StanfordBunny.obj and it is being used when loading the file:
It is not obvious it creates the material from the .mtl file because the diffuse color is grey in the .mtl file (Kd 0.80000 0.800000 0.80000), but I have modified the .mtl file in my local installation to set a green diffuse texture (Kd 0.0000 0.800000 0.0000):
The path you use in the mtllib command in the .obj file should be relative to the .obj file, so intead of mtllib localhost:8000/OBJ_Color_Library.mtl do mtllib OBJ_Color_Library.mtl if OBJ_Color_Library.obj is at the root of your web server.
If you have a mtl subfolder and put the .mtl file in it, you can do mtllib mtl/OBJ_Color_Library.mtl, again assuming OBJ_Color_Library.obj is at the root.
There’s currently no way to pass the content of the mtl file to the load method. However, looking at the code, it seems you could put a base64 encoded mtl content instead of the name of the file in the mtllib command, because the parameter after mtllib is parsed as a url… For this to work (in case it works, I didn’t test it!), you will have to pass an empty string as the root url in the append / importMesh method.
Thanks so much, guys. I think I finally have my OBJ and MTL working as desired.
However, I have these basic problems with what the Playground is doing in with my OBJ and MTL file in comparison with what my desktop programs do with it. Here’s MS-Office and Windows 3D viewer’s instant responses on being loaded with this data:
The desktop viewers instantly display something. The Playground is initially blank. It’s not until you hit it with the mouse and try twirling things that something shows up.
There’s none of the clearly defined edges of the faces and the sharp shadowing of the desktop viewers.
What do I need to do here to achieve instant display with clearly defined edges?
Holy cow! That is fantastic! I love it! It sounds like ScreenSpaceCurvaturePostProcess was invented precisely for this problem! And I’d been thinking about putting colored lines on the edges for application reasons, and here you’ve given me that option right out of Bablylon! What a system! What a phenomenal user support community! You folks are fantastic! Thank you so much!