简体   繁体   中英

assign material to loaded .obj without .mtl in three.js

how to add material like THREE.MeshPhongMaterial() to one of objects in loaded.obj file (.obj has multiple objects)

        var material_10 = new THREE.MeshBasicMaterial( { color: 0x444444 } );
        var loader = new THREE.OBMLoader();
        loader.load("https://aroncad.com/wp-content/themes/AronCad/3d/satllite/100.obm", function( obj ){
            obj.traverse( function( child ) {

                ...........

            } );
            scene.add( obj );
        });

One way to solve your issue is the usage of Object3D.traverse () like you already do in your code. This approach is also used in the official OBJ example in order to apply a texture to all materials. The code adapted to your use case looks like so:

object.traverse( function ( child ) {

    if ( child.isMesh ) child.material = material_10;

} );

three.js R109

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM