在three.js中的导出加载程序`obj`文件中使用多个纹理

时间:2018-02-23 11:45:43

标签: javascript three.js

我尝试在导出加载程序obj文件中使用不同的纹理 我能够在场景中看到我的物体,但我无法设置它的大小和形状 我的代码中有什么错误/缺失的想法吗?

var loader = new THREE.OBJLoader();
loader.load(
  'models/Sofa/sofa.obj',
  function (object) {
      var geometry = object.children[ 0 ].geometry;
      var materials = [];
      materials.push(new THREE.MeshBasicMaterial( { map : THREE.ImageUtils.loadTexture( 'models/Sofa/Texturses/1.jpg')}));
      materials.push(new THREE.MeshBasicMaterial( { map : THREE.ImageUtils.loadTexture( 'models/Sofa/Texturses/paradis_beige.jpg')}));
      materials.push(new THREE.MeshBasicMaterial( { map : THREE.ImageUtils.loadTexture( 'models/Sofa/Texturses/2.jpg')}));
      mesh = THREE.SceneUtils.createMultiMaterialObject(geometry, materials);

      object.traverse(function (child) {
          if (child instanceof THREE.Mesh) {
              child.material = material;
          }
      });
      scene1.add(mesh);
  },
  function ( xhr ) {
    returnValue = ( xhr.loaded / xhr.total * 100 ) + '% loaded';
    console.log(returnValue);
  },
  function ( error ) {
    console.log( 'An error happened' );
  }
);

0 个答案:

没有答案