当前位置:网站首页>threejs dynamically adjust the camera position so that the camera can see the object exactly
threejs dynamically adjust the camera position so that the camera can see the object exactly
2022-08-03 01:03:00 【K song, the king】
Core Code
obj is the target object \ controls are OrbitControls
let box3 = new THREE.Box3()box3.expandByObject(obj) // Calculate the model bounding boxlet size = new THREE.Vector3()box3.getSize(size) // Calculate bounding box sizelet center = new THREE.Vector3()box3.getCenter(center) // Calculate the geometric center coordinates of a hierarchical model corresponding to the bounding boxfunction maxSize(vec3) {let maxif (vec3.x > vec3.y) {max = vec3.x} else {max = vec3.y}if (max > vec3.z) {} else {max = vec3.z}return max}let max = maxSize(size) //The largest value of the length, width and high school of the bounding box is used to characterize the size of the model// 1. Controls the rendering range, but don't forget the camera is outside the model's bounding boxthis.camera.position.copy(center.clone()span>.addScalar(max))// 2. Centered rendering: set the camera target observation point, pointing to the center of the bounding box geometrythis.camera.lookAt(center)// 3. Pay attention to the near and far size controlsthis.camera.near = max * 0.1//It is best to associate with the camera position or the bounding box, don't set itSeemingly small values like 0.1 1this.camera.far = max * 300//According to the camera position and bracket size settings, the bounding box is includedThat's it, it's better to make it too big, not too smallthis.camera.updateProjectionMatrix()//The rendering range changes, pay attention to update the projection matrixthis.controls.target.copy(center)this.controls.update()
边栏推荐
- 同样月薪6K,为什么同事跳槽月薪翻倍,而你只涨了1000?
- Unity WallFxPack使用
- 谷粒商城-day14-商城业务与压力测试
- The interviewer asked me: delete library, in addition to run do?
- msys2下载地址
- 工业元宇宙的价值和发展
- AcWing 2983. 玩具
- You and I will meet the needs of: how to export the data in a MySQL simple ~!Practical!
- 创建型模式 - 简单工厂模式StaticFactoryMethod
- IP Protocol (Internet Protocol)
猜你喜欢
随机推荐
group of people
centos7安装mysql5.7步骤(图解版)
Matplotlib drawing core principles explain (more detailed)
APT级全面免杀拿Shell
目前为止 DAO靠什么盈利?
Summary of @Transactional transaction invocation and effective scenarios
VS保存后Unity不刷新
openssl源码下载
word操作:单独调整英文字体
gdb调试简要总结
一群搞社区的人
别再用Field注入了
“百日行动”进行时:700余交通安全隐患被揪出
创建型模式 - 抽象工厂模式AbstractFactory
在软件测试行业近20年的我,再来和大家谈谈今日的软件测试
Finally understand: With threads, why do we need coroutines?
mysql 错误:The driver has not received any packets from the server.
TDengine 在中天钢铁 GPS、 AIS 调度中的落地
threejs 动态调整相机位置,使相机正好能看到对象
MDL 内存描述符链表