Skip to content

Commit b2afd5d

Browse files
committed
update
1 parent 06425c4 commit b2afd5d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

24 Three.js解决方案之加载.gLTF模型.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,34 @@ loader.load('./xxx/model.drc',
660660

661661

662662

663+
<br>
664+
665+
## 补充说明:修改模型位置偏差
666+
667+
无论加载 .obj 文件,还是本章讲解的加载 .gltf 文件,假设模型在建模软件中位置中心并不是原点,而是非常偏远的位置。
668+
669+
那么文件加载完成后,将模型添加到场景中,模型的位置并不在场景视角的中心位置,如果位置过于偏远,甚至有可能根本看不见模型。
670+
671+
我们可以通过以下方式,计算模型的位置偏差,并修正模型的位置,使其出现在视野中心位置。
672+
673+
```
674+
const loader = new GLTFLoader()
675+
loader.load('./model/lddq.gltf', (gltf) => {
676+
const group = gltf.scene
677+
678+
const box = new Three.Box3().setFromObject(group)
679+
const center = box.getCenter(new Three.Vector3())
680+
681+
group.position.x += (group.position.x - center.x)
682+
group.position.y += (group.position.y - center.y)
683+
group.position.z += (group.position.z - center.z)
684+
685+
scene.add(group)
686+
})
687+
```
688+
689+
> Box3 的介绍请执行查阅官方文档。
690+
663691

664692

665693
<br>

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ Three.js 官方维护人员非常热心和严谨。
8383
除此之外,还有其他几个值得推荐的、国内博主写的 Three.js 系列教程:
8484

8585
* [wjceo.com:暮志未晚写的three.js教程](https://www.wjceo.com/blog/threejs/)
86+
8687
* [hewebgl.com:Three.js基础教程](http://www.hewebgl.com/article/articledir/1)
88+
8789
* [webgl3d.cn:Three.js教程](http://www.webgl3d.cn/Three.js/)
8890

91+
* 强烈推荐看一下 [图解WebGL&Three.js工作原理](https://www.cnblogs.com/wanbo/p/6754066.html)
92+
93+
> 可惜该作者近几年都没再更新 Three.js 相关文章。
94+
8995
特别说明 hewebgl.com 和 webgl3d.cn 的教程存在问题就是:
9096

9197
1. 教程内容版本有些老化,使用的并不是最新版 three.js

0 commit comments

Comments
 (0)