18three.js加载obj模型和材质
图片.png
obj和mtl加载器更新变化很大。
下面的代码是92版本的代码,参考官方的案例。
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
}
};
var onError = function(xhr) {};
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath('models/');
mtlLoader.load('Rhino_3.mtl', function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/');
objLoader.load('Rhino_3.OBJ', function(object) {
object.position.y = 3.5;
object.scale.set(8, 8, 8);
scene.add(object);
console.log(object);
}, onProgress, onError);
});
var mtlLoader1 = new THREE.MTLLoader();
mtlLoader1.setPath('models/');
mtlLoader1.load('Rhino_1.mtl', function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/');
objLoader.load('Rhino_1.OBJ', function(object) {
object.position.y = 3.5;
object.position.z = 5.5;
object.scale.set(8, 8, 8);
scene.add(object);
console.log(object);
}, onProgress, onError);
});
网友评论