0

I have an obj file that I display with OBJloader2. I am looking for a way to apply a MeshLambertMaterial on it.

I can do that with OBJLoader, with the following code called in the onLoadedCallback function :

 material = new THREE.MeshLambertMaterial(
                                                    {
                                                        color:0x6e6e6e,
                                                        emissive:0x282727
                                                    });

// called when resource is loaded
function ( object ) {
    object.traverse( function ( child ) {
                if ( child instanceof THREE.Mesh ) {
                    child.material = material;
                }
            });

scene.add( object );

Unfortunately I can't do the same with OBJLoader2. Am I missing something? All examples I have found are importing material from .mtl files, is it the only way?

Thanks.

Thibault
  • 1
  • 3
  • 2
    I recommend to convert your `OBJ/MTL` files to `glTF` and then use `GLTFLoader`. You can use this [tool](https://github.com/AnalyticalGraphicsInc/obj2gltf) to perform the conversion. `glTF` is the recommended format of `three.js` (see https://threejs.org/docs/index.html#manual/en/introduction/Loading-3D-models). After loading the model, it should be no problem to traverse through the scene and apply your material changes. – Mugen87 Dec 11 '18 at 14:16
  • Thanks for the answer, I go trying that. – Thibault Dec 11 '18 at 14:22
  • 1
    @Mugen87 that is working really well and fast, thank you. – Thibault Dec 11 '18 at 15:07
  • 1
    Glad to hear that :) – Mugen87 Dec 11 '18 at 15:23

0 Answers0