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

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?

万物智联时代,悄然走入生活

如何通过 IDEA 数据库管理工具连接 TDengine?

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

CTF命令执行题目解题思路

双轴晶体中的锥形折射

Jmeter二次开发实现rsa加密

刚安装完win10专业工作站版,系统变量中Path默认值有哪些?重新建一个“PATH”变量名,会覆盖掉原先的“Path”。

group of people

The interviewer asked me: delete library, in addition to run do?
随机推荐
Token、Redis实现单点登录
ROS2初级知识(9):bag记录过程数据和重放
Teach you how to kill if else
【TypeScript】深入学习TypeScript模块化
gdb调试简要总结
B站回应“HR 称核心用户都是 Loser”:该面试官去年底已被劝退,会吸取教训加强管理
# 医院管理系统完整项目代码以及数据库建表语句分享
学习基因富集工具DAVID(2)
无代码开发平台数据ID入门教程
饥荒联机版Mod开发——制作简单的物品(三)
WebShell 木马免杀过WAF
IP Protocol (Internet Protocol)
Week 7 CNN Architectures - LeNet-5、AlexNet、VGGNet、GoogLeNet、ResNet
GameStop NFT 市场分析
ssm整合(三)Controller 和 视图层编写
SRv6网络演进面临的挑战
centos7安装mysql5.7
openssl源码下载
牛客刷题:手动实现数组filter方法
成功解决TypeError: can‘t multiply sequence by non-int of type ‘float‘