相关API的使用:
1 THREE.Color (用于创建和表示颜色)
2. THREE.TextureLoader(用于加载和处理图片纹理)
在上一篇 Three.js加载外部glb,fbx,gltf,obj 模型文件 的文章基础上分别加入onSetSceneColor(设置场景颜色),onSetSceneImage(设置场景背景图),onSetSceneViewImage (设置场景全景图),三个方法。
//设置场景颜色
onSetSceneColor(color) {
this.scene.background = new THREE.Color(color)
}
//设置场景图片
onSetSceneImage(url) {
this.scene.background = new THREE.TextureLoader().load(url);
}
// 设置全景图
onSetSceneViewImage(url) {
const texture = new THREE.TextureLoader().load(url);
texture.mapping = THREE.EquirectangularReflectionMapping
this.scene.background = texture
this.scene.environment = texture
}
完整的代码可参考:## 完整的代码可参考:
https://gitee.com/ZHANG_6666/Three.js3D
https://github.com/zhangbo126/Three3d-view
界面效果图:
1.背景图
2.全景图