THREEJS -- Cameras相机

346 阅读1分钟

透视相机 THREE.PerspctiveCamera(a, b, c, d) <常用>

参数:

  • a(75)视角,视角垂直的角度
  • b (w / h) 视锥体长宽比
  • c 相机最近能看多远
  • d 相机最远能看多远
const cameras = new THREE.PerspctiveCamera(45, w/h, 1, 100)

正交相机 THREE.OrthographicCamera()

无论物体距离相机距离远近,在渲染图片中,物体的大小保持不变

// 渲染窗口的宽 / 高 = 视锥体长宽比
const aspectRatio = size.width / size.height
// 正交相机
// 参数,左右上下的视锥体,near相机最近能看见的距离,far相机最远能看的距离
const cameras = new THREE.OrthographicCamera(
    left,
    right,
    top,
    bottom,
    near,
    far,
)

控制器 OrbitControls

轨道控制相机围绕目标运行,需要单独导入,不在THREE对象中

// 轨道控制器
// 这个文件下还有许多其他控制器可以使用,当前是轨道控制器
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"

// 参数:
// camera 要控制的相机
// render.document 用于触发事件的元素,通常就是canvas
const controls = new OrbitControls(camera, render.document)
controls.update

// 在动画函数中调用
const animate = () => {
    requestAnimationFrame(animate);
    controls.update()
    renderer.render(scene, camera)
}