threejs obj模型加载

var onProgress = function(xhr) { 

 var percentComplete = xhr.loaded / xhr.total * 100;

 element.style.width = percentComplete + "%" //可以设置进度条

 };

//mtl 加载 

var mtlLoader = new THREE.MTLLoader();


mtlLoader.load(mtl, function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.load(obj, function(object) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
//遍历 子元素
}
});
}, onProgress)
});

回到顶部