threeJS加载obj模型以及其纹理mtl
作者:互联网
// 模型引入obj模型引入
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';
// 模型引入obj模型的纹理引入
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader.js';
function initOBJ() {//OBJ模型加载
var mtlLoader = new MTLLoader()// mtl材加载器
//--------------------
// mtlLoader.setTexturePath('/data/tex/')// 材质加载路径
mtlLoader.load('/img/objTest.mtl', materials => {
materials.preload()
var objLoader = new OBJLoader()
objLoader.setMaterials(materials)
objLoader.load('/img/objTest.obj', (obj) => {
obj.traverse((child) => {
if (child instanceof THREE.Mesh) {
child.material.side = THREE.DoubleSide
child.scale.set(30, 30, 30)
}
})
scene.add(obj)
})
})
}
标签:threeJS,obj,模型,mtl,child,objLoader,MTLLoader,加载 来源: https://www.cnblogs.com/enhengenhengNymph/p/15386796.html