简体   繁体   English

THREE.js在加载时更改纹理

[英]THREE.js Changing Textures On Load

We're loading in objects created in Blender, that we would like to change the texture without having to change the .mtl file that is being referenced when we load the object. 我们正在加载在Blender中创建的对象,我们希望更改纹理而不必更改加载对象时所引用的.mtl文件。

//load in all pieces
var board = this;
var loadComplete = 0;
this.loader.load('myobj1.obj', 'myobj1.mtl', function (object){
    board.obj2 = object;
    board.loader.load('myobj2.obj', 'myobj2.mtl', function(object){
        board.obj2 = object;
        board.obj2.material = new THREE.ImageUtils.loadTexture( 'Models/textures/blackmarble1.jpg' );
        board.loader.load('myobj3.obj', 'myobj3.mtl', function(object){
            board.obj3 = object;
    });
 });
});

so in this card, we're trying to change the obj2's texture. 因此,在此卡中,我们尝试更改obj2的纹理。 However, it just loads whatever is in the mtl. 但是,它只会加载mtl中的内容。 Which we want in certain scenarios, but not in others. 在某些情况下需要的,而在其他情况下则不需要。

Also trying these methods do not do anything: 尝试这些方法也无济于事:

var blackTex = THREE.ImageUtils.loadTexture('Models/textures/blackmarble1.jpg');
obj2.material = new THREE.MeshLambertMaterial({ map: blackTex});


obj2.material.uniforms.texture = blackTex;

Figured it out. 弄清楚了。 The loader childs the meshes. 加载程序将网格作为子对象。

piece.children[0].children[0].material = new THREE.MeshLambertMaterial({ map: blackTex});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM