对象上的纹理不显示
Texture on object doesn't show up
我想要的
我是 Three.js 的新手,我正在尝试 将纹理 应用于加载的对象。
问题
我已经尝试了很多东西,但仍然不确定该怎么做。我没有收到任何错误,对象 加载但没有纹理 。
我的代码
var loader6 = new THREE.OBJLoader();
// load a resource
loader6.load(
// resource URL
'models/Chair.obj',
// called when resource is loaded
function ( object ) {
object.scale.x = 20;
object.scale.y = 30;
object.scale.z = 20;
object.rotation.y = -0.3;
object.position.z = -500;
object.position.x = 30;
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
console.log(texture);
child.material.map = texture;
}
});
var texture = new THREE.TextureLoader().load('models/Chair.mtl');
object6 = object;
scene.add( object6 );
},
有什么帮助吗?
您无法使用 TextureLoader
加载 .mtl
文件,您必须为此使用 MTLLoader
。 MTLLoader
应该加载纹理。然后你必须使用 'setMaterial' 函数将 material 设置为 OBJLoader
。
检查此代码 -
new THREE.MTLLoader()
.setPath( 'path to the material folder' )
.load( 'material_file.mtl', function ( materials ) {
materials.preload();
new THREE.OBJLoader()
.setMaterials( materials )
.setPath( 'path to the obj folder' )
.load( 'objModel.obj', function ( object ) {
object.position.y = - 95;
scene.add( object );
}, onProgress, onError );
} );
我想要的
我是 Three.js 的新手,我正在尝试 将纹理 应用于加载的对象。
问题
我已经尝试了很多东西,但仍然不确定该怎么做。我没有收到任何错误,对象 加载但没有纹理 。
我的代码
var loader6 = new THREE.OBJLoader();
// load a resource
loader6.load(
// resource URL
'models/Chair.obj',
// called when resource is loaded
function ( object ) {
object.scale.x = 20;
object.scale.y = 30;
object.scale.z = 20;
object.rotation.y = -0.3;
object.position.z = -500;
object.position.x = 30;
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
console.log(texture);
child.material.map = texture;
}
});
var texture = new THREE.TextureLoader().load('models/Chair.mtl');
object6 = object;
scene.add( object6 );
},
有什么帮助吗?
您无法使用 TextureLoader
加载 .mtl
文件,您必须为此使用 MTLLoader
。 MTLLoader
应该加载纹理。然后你必须使用 'setMaterial' 函数将 material 设置为 OBJLoader
。
检查此代码 -
new THREE.MTLLoader()
.setPath( 'path to the material folder' )
.load( 'material_file.mtl', function ( materials ) {
materials.preload();
new THREE.OBJLoader()
.setMaterials( materials )
.setPath( 'path to the obj folder' )
.load( 'objModel.obj', function ( object ) {
object.position.y = - 95;
scene.add( object );
}, onProgress, onError );
} );