I've successfully imported a 3D model via a obj file. It displays on the screen fine. But when I try to apply the texture the model disappears. Any ideas why?
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader( manager );
loader.load( './models/Leather-Black.jpg', function ( image ) {
texture.image = image;
} );
loader.load( './models/Sofa000.obj', function ( object ) {
object.traverse( function( node ) { if ( node instanceof THREE.Mesh ) {
node.castShadow = true;
node.material.map = texture;
}
});
object.scale.set(30,20,30);
object.rotation.y = Math.PI/180 * 180;
scene.add( object );
});
loader.load()
is asynchronous. so your texture
variable is undefined
when you assign to the material.map
. What you need to is use the callback function of the TextureLoader()
so that you would know that the image has loaded and then apply it to the material.
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.