threejs (二) 相机

正交相机

js 复制代码
const camera = new THREE.OrthographicCamera(
          -aspect,
          aspect,
          aspect,
          -aspect,
          0.1, //进平面
          1000 //远平面
        ); // 透视相机

创建相机辅助线

js 复制代码
const cameraHelper = new THREE.CameraHelper(this.camera);

创建一个透视相机观察正交相机

js 复制代码
 // 创建透视相机
        const watchCamera = new THREE.PerspectiveCamera(
          75,
          this.width / this.height
        );
        // 在正交投影后,距离人眼更近
        watchCamera.position.set(2, 2, 6);
        watchCamera.lookAt(this.scene.position);
        this.scene.add(watchCamera);
        this.camera = watchCamera;
        this.watchCamera = watchCamera;

上面的

GUI调试相机参数:dat.gui

可以配置设置对象的属性:可以是numberboolean类型和方法类型,点击gui插件方法名称时,会执行改方法
npm install --save dat.gui

js 复制代码
import * as dat from 'dat.gui';
...,
const gui = new dat.GUI();
        let params = {
          wireframe: false,
          switchCamera: () => {
            if (this.camera.type === 'OrthographicCamera') {
              this.camera = this.watchCamera;
              // 鼠标控制拖动开启
              this.orbitControls.enabled = true;
            } else {
              this.camera = this.otherCamera;
              this.orbitControls.enabled = false;
            }
          },
        };
        gui.add(this.camera.position, 'x', 0.1, 10, 0.1);
        gui.add(this.camera, 'near', 0.01, 10, 0.01).onChange((val) => {
          this.camera.near = val;
          // 矩阵更新函数
          this.camera.updateProjectionMatrix();
        });
        gui.add(this.camera, 'far', 1, 100, 1).onChange((val) => {
          this.camera.far = val;
          // 矩阵更新函数
          this.camera.updateProjectionMatrix();
        });
        gui.add(this.camera, 'zoom', 0.1, 10, 0.1).onChange((val) => {
          this.camera.zoom = val;
          // 矩阵更新函数
          this.camera.updateProjectionMatrix();
        });
        gui.add(params, 'wireframe').onChange((val) => {
          this.mesh.material.wireframe = val;
        });
        gui.add(params, 'switchCamera');

透视相机

相关推荐
星图云3 小时前
Mirauge3D 赋能:全自动建模,让城市规划与建筑设计拥有高分辨率实景三维模型
3d
点云SLAM4 小时前
Pytorch中cuda相关操作详见和代码示例
人工智能·pytorch·python·深度学习·3d·cuda·多gpu训练
云飞云共享云桌面12 小时前
制造工厂高效出图新技术——共享云桌面
运维·服务器·网络·3d·自动化·制造
CG_MAGIC3 天前
虚幻 5 与 3D 软件的协作:实时渲染,所见所得
3d·ue5·游戏引擎·图形渲染·虚幻·游戏美术·渲云渲染
tirvideo3 天前
TI DLP3010光机与相机触发使用指南
3d·工业相机·光机·dlp·光机控制板·投影机
新启航光学频率梳3 天前
精密深孔偏心检具的制作及光学深孔检测探究 —— 激光频率梳 3D 轮廓检测
科技·3d·制造
博图光电3 天前
破除扫描边界Photoneo MotionCam-3D Color 解锁动态世界新维度
3d
SYNCON24 天前
通缩压力下的 “逆行者”:新启航如何用国产 3D 白光干涉仪破解半导体行业降本困局?
科技·3d·制造
罗兰Yolanda4 天前
实时3D渲染:揭秘场景化驱动的硬件配置思路
3d·实时音视频
m0_743106464 天前
【论文笔记】OccluGaussian解决大场景重建中的区域遮挡问题
论文阅读·人工智能·计算机视觉·3d·几何学