Search code examples
3dthree.jswebglsketchup

SketchUp export obj with textures - how


Windows 7 (64bit), SketchUp Make 13.0.4812.

Goal: convert SketchUp .skp model to .obj and load to WebGL using three.js.

Problem: sketchup exports model to .obj with external textures, and these textures are not loaded by three.js.

Question: is it possible to save SketchUp model as one .obj file with textures?


Solution

  • No, .obj is a simple text format. You can't store textures in .obj. Here is an example on how to load the texture from a separate .jpg file.

    I copied the important bits:

    // texture
    var manager = new THREE.LoadingManager();
    manager.onProgress = function ( item, loaded, total ) {
      console.log( item, loaded, total );
    };
    var texture = new THREE.Texture();
    var loader = new THREE.ImageLoader( manager );
    loader.load( 'textures/ash_uvgrid01.jpg', function ( image ) {
      texture.image = image;
      texture.needsUpdate = true;
    } );
    
    // model
    var loader = new THREE.OBJLoader( manager );
    loader.load( 'obj/male02/male02.obj', function ( object ) {
      object.traverse( function ( child ) {
        if ( child instanceof THREE.Mesh ) {
          child.material.map = texture;
        }
        scene.add( object );
      });
    });