我正在编写以下脚本。更改 .glb 模型的图像。它只产生白色。没有发生适当的纹理变化。请帮我。
const nextButtonComponent = () => ({
init: function() {
const model = document.getElementById('model')
const nextButton = document.getElementById('nextbutton')
const loader = new THREE.TextureLoader();
var material = new THREE.MeshStandardMaterial({
side: THREE.DoubleSide,
flatShading: true,
});
const mesh = model.getObject3D('mesh');
nextButton.style.display = 'block';
const nextAnimation = () => {
loader.load( './assets/img/1.jpg' ,
function(texture){
material.map = texture;
material.needsUpdate = true;
if(mesh){
mesh.traverse((node) => {
if (node.isMesh) {
node.material = material;
node.material.map = texture;
node.material.needsUpdate = true;
}
});
}
});
}
nextButton.onclick = nextAnimation // Switch to the next animation when the button is pressed.
}
})
export {nextButtonComponent}