当前位置:网站首页>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() 边栏推荐
猜你喜欢

MySql查询某个时间段内的数据(前一周、前三个月、前一年等)

Week 7 CNN Architectures - LeNet-5、AlexNet、VGGNet、GoogLeNet、ResNet

Web APIs BOM- 操作浏览器-Window对象

AcWing 2983. 玩具

基于STM32的FLASH读写实验含代码(HAL库)

Jmeter二次开发实现rsa加密

CS5213 chip | HDMI to VGA converter chip data sharing

The interviewer asked me: delete library, in addition to run do?

【C语言】带头双向循环链表(list)详解(定义、增、删、查、改)

【TypeScript】深入学习TypeScript模块化
随机推荐
openssl源码下载
go rand 包
group of people
Word2Vec词向量训练、使用及可视化操作
CodeTON Round 2 A - D
无代码开发平台表单样式设置步骤入门课程
js function anti-shake and function throttling and other usage scenarios
centos7安装mysql5.7
若依集成minio实现分布式文件存储
搭建直播平台,使用node生成验证码图片,并进行验证
双轴晶体中的锥形折射
【使用pyside2遇到的问题】This application failed to start because no Qt platform plugin could be initialized.
JS Date 时间戳 getTune data.parse 倒计时小程序
Task 4 Machine Learning Library Scikit-learn
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析
mysql 错误:The driver has not received any packets from the server.
go context 包
七夕到了——属于程序员的浪漫
vscode 自定义快捷键——设置eslint
CentOS7 安装MySQL 图文详细教程