File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -660,6 +660,34 @@ loader.load('./xxx/model.drc',
660
660
661
661
662
662
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
+
663
691
664
692
665
693
<br >
Original file line number Diff line number Diff line change @@ -83,9 +83,15 @@ Three.js 官方维护人员非常热心和严谨。
83
83
除此之外,还有其他几个值得推荐的、国内博主写的 Three.js 系列教程:
84
84
85
85
* [ wjceo.com:暮志未晚写的three.js教程] ( https://www.wjceo.com/blog/threejs/ )
86
+
86
87
* [ hewebgl.com:Three.js基础教程] ( http://www.hewebgl.com/article/articledir/1 )
88
+
87
89
* [ webgl3d.cn:Three.js教程] ( http://www.webgl3d.cn/Three.js/ )
88
90
91
+ * 强烈推荐看一下 [ 图解WebGL&Three.js工作原理] ( https://www.cnblogs.com/wanbo/p/6754066.html )
92
+
93
+ > 可惜该作者近几年都没再更新 Three.js 相关文章。
94
+
89
95
特别说明 hewebgl.com 和 webgl3d.cn 的教程存在问题就是:
90
96
91
97
1 . 教程内容版本有些老化,使用的并不是最新版 three.js
You can’t perform that action at this time.
0 commit comments