当前位置:网站首页>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() 边栏推荐
猜你喜欢
随机推荐
图像识别从零写出dnf脚本关键要点
在软件测试行业近20年的我,再来和大家谈谈今日的软件测试
kubernetes pod podsecurityPolicies(PSP)
Week 7 - Distributional Representations(分布表示)
万物智联时代,悄然走入生活
创建型模式 - 抽象工厂模式AbstractFactory
CKA、CKAD、CKS、KCNA、CFCD考试
matplotlib绘图的核心原理讲解(超详细)
go exec 包
Word operation: adjust the English font individually
SRv6网络演进面临的挑战
centos7安装mysql8
“百日行动”进行时:700余交通安全隐患被揪出
Web APIs BOM- 操作浏览器-Window对象
Auto.js实现朋友圈自动点赞
TDengine 在中天钢铁 GPS、 AIS 调度中的落地
学习基因富集工具DAVID(3)
Summary of @Transactional transaction invocation and effective scenarios
软件测试笔试题1(附答案)
RuoYi-App Startup Tutorial


![[TypeScript] Deep Learning of TypeScript Classes (Part 1)](/img/47/34954f1e01b844816d74f3ac556f9b.png)






