当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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.

//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. However, it just loads whatever is in the 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});
分享给朋友:
您可能感兴趣的文章:
随机阅读: