blenderswap blender对象为threejs

时间:2017-12-13 20:41:57

标签: javascript three.js blender

我是Blender和Blendswap的新手。我从blendswap下载了一个.blender渲染,并希望将它加载到我的threejs场景中。我将blender渲染导出为.obj,并下载了.obj文件和.mtl文件。然后我使用以下代码尝试导入它。没有错误代码,但渲染没有显示。我还希望在导入此对象后查看哪个命令是合适的,以设置它的位置。 (x,y,z)我无法使用.position.set。

  var santa;

  var manager = new THREE.LoadingManager();
    manager.onProgress = function ( item, loaded, total ) {
        console.log( item, loaded, total );
    };
  var onProgress = function ( xhr ) {
    if ( xhr.lengthComputable ) {
      var percentComplete = xhr.loaded / xhr.total * 100;
      console.log( Math.round(percentComplete, 2) + '% downloaded' );
    }
  };
  var onError = function ( xhr ) {
    console.log('Error: ' + xhr)
    };

  var loader = new THREE.OBJLoader( manager );
    loader.load( 'img/santa blendswap.obj', function ( object ) {
      santa = object;
      scene.add( santa );
    }, onProgress, onError );

1 个答案:

答案 0 :(得分:0)

如果obj文件位于指定路径中,则此代码应该有效,无论如何,您可以在加载后设置对象的位置。

var santa;
var onProgress = function ( xhr ){
    if ( xhr.lengthComputable ) {
      var percentComplete = xhr.loaded / xhr.total * 100;
      console.log( Math.round(percentComplete, 2) + '% downloaded' );
    }
};
var onError = function ( xhr ) {
    console.log('Error: ' + xhr)
};
var loader = new THREE.OBJLoader();
//use %20 to encode space between the file name. 'img/santa blendswap.obj' should also work
loader.load( 'img/santa%20blendswap.obj', function ( object ) {
    santa = object;
    santa.position.set( 0, 5, 10 );//You can set the position like this or use object.position.set( 0, 5, 10 )
    scene.add( santa );
}, onProgress, onError );