需要完整源码,请加我微信:lookgxl
核心代码:
changeBody(type) {
let nowType = this.nowType
const loader = new GLTFLoader()
loader.load(`${process.env.BASE_URL}static/model/${type}.glb`, gltf => {
if (this.body_model) {
this.modelGroup.remove(this.body_model)
}
const model = gltf.scene
this.body_model = model
this.modelGroup.add(this.body_model)
model.position.y = this.position_y
model.traverse(o => {
if (o.isMesh && o.name === 'Wolf3D_Body') {
o.material.color = new THREE.Color(new THREE.Color('#996144'))
}
if (o.isMesh) {
o.castShadow = true
}
})
this.nowType = type
})
},