2
votes

If I use the following code to load the .obj and .mtl downloaded from https://poly.google.com/view/9NXf-SDxJny it works fine, I see the star rendered in my scene.

return new Promise((resolve, reject) => 
    {
        let mtlLoader = new THREE.MTLLoader();
        mtlLoader.crossOrigin = true;
        mtlLoader.setPath(ASSETS_PATH);
        mtlLoader.load(filename + '.mtl', (materials) => 
        {           
            materials.preload();
            let objLoader = new THREE.OBJLoader();
                objLoader.setPath(ASSETS_PATH);

                objLoader.setMaterials(materials);
                objLoader.load(filename + '.obj', (obj) => 
                {   
                    this.obj = obj; 
                    resolve(true);
                });
        });
    });

But when I use the same code to load the obj and mtl from https://poly.google.com/view/4-OZNPuTqFq it doesn't show. I don't get any errors. If I remove the line objLoader.setMaterials(materials); then i see the cake but with no material. So it appears to be a material issue.

I have a codepen with the full code here https://codepen.io/steveg3003/pen/6f0d8c4a17ed12bea49b3391a6d80ce3?editors=0010

Thanks

2
Is THREE.OBJLoader2.setMaterials throwing an exception or error you can see in your browser console log? Can you see if the materials array is null before you pass it in? - Timothy John Laird
Ok so if I switch to OBJLoader2 I can see the shape but the material is all grey. And I get the following error > THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values. - steveg
Can you go to the browser and stick a breakpoint where computeBoundingSphere gets called (think 4 places) in BufferGeometry.js? It generates the same error text you saw and I think it's called at some point when objloader2.load gets called. See if it yields any clues. - Timothy John Laird
Any update on this? I see the same problem with aframe and it uses three.js - Omid
@Omid yes, I had to manually change the 'd' value inside the .mtl file from 0 to 1. It appears to set the transparency and for some reason by default the material was set to fully transparent when downloaded from poly.google.com - steveg

2 Answers

1
votes

So the solution for me was to manually change the 'd' value inside the material file (.mtl) from 0.00000 to 1.00000

1
votes

Something similar happened to me, except the model was all black. I had to open up the .mtl file and change the "Kd 0.00 0.00 0.00" to "Kd 1.00 1.00 1.00"