当前位置:网站首页>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()
边栏推荐
- go 反射 reflect 包
- 虚拟内存 virualmemory
- 了解 NFT 质押:Web3 中赚取被动收益的另一种方式
- RuoYi-App启动教程
- You and I will meet the needs of: how to export the data in a MySQL simple ~!Practical!
- Learn more TypeScript 】 【 TypeScript modular
- 如何通过 IDEA 数据库管理工具连接 TDengine?
- 牛客刷题:手动实现数组filter方法
- SRv6网络演进面临的挑战
- Shunted Self-Attention via Multi-Scale Token Aggregation
猜你喜欢
MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁
kubernetes pod podsecurityPolicies(PSP)
GameStop NFT 市场分析
【使用pyside2遇到的问题】This application failed to start because no Qt platform plugin could be initialized.
学习基因富集工具DAVID(2)
软件测试到底自学还是报班?
centos7安装mysql5.7
无代码开发平台表单样式设置步骤入门课程
Yocto系列讲解[实战篇]85 - 制作ubi镜像和自动挂载ubifs文件系统
万物智联时代,悄然走入生活
随机推荐
Interviewer: can you talk about optimistic locking and pessimistic locks
如何通过 IDEA 数据库管理工具连接 TDengine?
数字化转型巨浪拍岸,成长型企业如何“渡河”?
Jmeter二次开发实现rsa加密
go rand 包
软件测试到底自学还是报班?
最新真实软件测试面试题分享,收藏了还怕进入不了大厂?
kubernetes pod podsecurityPolicies(PSP)
centos7安装mysql8
CKA、CKAD、CKS、KCNA、CFCD考试
TDengine 在中天钢铁 GPS、 AIS 调度中的落地
CodeTON Round 2 A - D
JS 包装类 Math对象 round max() min() random
Finally understand: With threads, why do we need coroutines?
How many ways do you know the singleton pattern?
Jmeter二次开发实现rsa加密
What is the core business model of the "advertising e-commerce" that has recently become popular in the circle of friends, and is the advertising revenue really reliable?
双轴晶体中的锥形折射
openssl源码下载
【使用pyside2遇到的问题】This application failed to start because no Qt platform plugin could be initialized.