【问题标题】:three.js obj + mtl doesnt workthree.js obj + mtl 不起作用
【发布时间】:2018-05-14 14:19:30
【问题描述】:

我对 three.js obj + mtl 加载器有疑问。 obj 仍然没有纹理。有什么帮助吗? :(

    var loader1 = new THREE.OBJLoader();    
    var loader2 = new THREE.MTLLoader();
    loader2,load("models/house1.mtl"), function (materials){
       loader1.load("models/house1.obj ", function(obj) {
          object=obj; 
          object.materials.set( materials );
          object.scale.set(4,4,4); 
          object.position.set(-60,0,30); 
          object.rotation.set(0,0,0); 
          scene.add(object);
       })
   }

【问题讨论】:

标签: three.js textures


【解决方案1】:

我认为您错过了预加载材料资源。 MTLLoader 将在解析 mtl 文件后返回一个“MaterialCreator”实例。您可以使用此对象来预加载和准备创建材料所需的资源。更多详情,refer the code

也正如@paulsm4 所建议的,您没有使用正确的语法来加载 OBJ + MTL 模型。

var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath( "models/" ); //Give the path upto the mtl file
mtlLoader.load( "house1.mtl", function( materials ){

    materials.preload();//We can preload the material resources like this.

    var objLoader = new THREE.OBJLoader();
    objLoader.setMaterials( materials );//Set the materials for the objects using OBJLoader's setMaterials method
    objLoader.setPath( "models/" ); //Give the path upto the obj file
    objLoader.load( "house1.obj", function( object ){

        object.scale.set( 4, 4, 4 ); 
        object.position.set( -60, 0, 30 ); 
        object.rotation.set( 0, 0, 0 ); 
        scene.add( object );

    }, onProgress, onError );

} );

你也可以refer this answer

【讨论】:

  • @EvelinaDiksaitė, This answer 已经解释了如何加载 OBJ+MTL 模型。我添加了这个答案只是为了突出你错过了什么。
猜你喜欢
  • 2019-04-24
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-18
  • 1970-01-01
  • 2017-01-26
  • 2015-01-15
  • 2017-07-17
相关资源
最近更新 更多