当前位置:网站首页>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()
边栏推荐
- 第十章 时序与延迟
- js function anti-shake and function throttling and other usage scenarios
- Yocto系列讲解[实战篇]85 - 制作ubi镜像和自动挂载ubifs文件系统
- MySQL删除数据后,释放磁盘空间
- The interviewer asked me: delete library, in addition to run do?
- centos7安装mysql8
- JS Date 时间戳 getTune data.parse 倒计时小程序
- H.265视频流媒体播放器EasyPlayer.js集成时出现“SourceBuffer ”报错,该如何解决?
- threejs 动态调整相机位置,使相机正好能看到对象
- 【学习笔记】博弈论
猜你喜欢
You and I will meet the needs of: how to export the data in a MySQL simple ~!Practical!
Task 4 Machine Learning Library Scikit-learn
GameStop NFT 市场分析
mysql根据多字段分组——group by带两个或多个参数
PHP实现登录失败三次需要输入验证码需求
Finally understand: With threads, why do we need coroutines?
H5网页播放器EasyPlayer.js播放器界面的加载效果无法消失是什么原因?
测试ESP32-Zigbee转发命令 : 滑轨、继电器控制
一群搞社区的人
How many ways do you know the singleton pattern?
随机推荐
双轴晶体中锥形折射的建模与应用
数字化转型巨浪拍岸,成长型企业如何“渡河”?
FRED应用:激光二极管光源耦合到光纤的仿真
You and I will meet the needs of: how to export the data in a MySQL simple ~!Practical!
“百日行动”进行时:700余交通安全隐患被揪出
软件测试到底自学还是报班?
Week 7 - Distributional Representations(分布表示)
IP Protocol (Internet Protocol)
Week 7 CNN Architectures - LeNet-5、AlexNet、VGGNet、GoogLeNet、ResNet
group of people
辅助脚本开发之旅
测试ESP32-Zigbee转发命令 : 滑轨、继电器控制
gdb调试简要总结
【DEBUG】ImportError: Unable to import required dependencies: numpy: DLL load failed: 找不到指定的模块。
Word operation: adjust the English font individually
MDL 内存描述符链表
工业元宇宙的价值和发展
谷粒商城-day14-商城业务与压力测试
【Unity】Unity开发进阶(七)双刃剑:扩展方法
How does Redis easily achieve system instant kill?