当前位置:网站首页>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()
边栏推荐
猜你喜欢
一个很少见但很有用的SQL功能
Word operation: adjust the English font individually
学习基因富集工具DAVID(2)
网络运维系列:健康检查的方式
若依如何实现添加水印功能
【使用pyside2遇到的问题】This application failed to start because no Qt platform plugin could be initialized.
CentOS7 安装MySQL 图文详细教程
你离「TDengine 开发者大会」只差一条 SQL 语句!
JS 包装类 Math对象 round max() min() random
如何通过 IDEA 数据库管理工具连接 TDengine?
随机推荐
Token、Redis实现单点登录
H.265视频流媒体播放器EasyPlayer.js集成时出现“SourceBuffer ”报错,该如何解决?
典型相关分析CCA计算过程
Auto.js脚本程序打包
MySQL删除数据后,释放磁盘空间
Go语言如何操作文件
工业元宇宙的价值和发展
kubernetes pod podsecurityPolicies(PSP)
gdb调试简要总结
创建型模式 - 简单工厂模式StaticFactoryMethod
CTF命令执行题目解题思路
RuoYi-App Startup Tutorial
ZCMU--5230: 排练方阵(C语言)
牛客刷题:手动实现数组filter方法
MYSQL查看表结构
Teach you how to kill if else
软件测试到底自学还是报班?
“百日行动”进行时:700余交通安全隐患被揪出
RuoYi-App启动教程
图像识别从零写出dnf脚本关键要点