Capítulo 17 de 859

Chapter 17: CubeCamera

Core Idea

A special type of camera that is positioned in 3D space to render its surroundings into a cube render target. The render target can then be used as an environment map for rendering realtime reflections in your scene.

Key Concepts

  • activeMipmapLevel : number: The current active mipmap level
  • coordinateSystem : WebGLCoordinateSystem | WebGPUCoordinateSystem: The current active coordinate system.
  • renderTarget : WebGLCubeRenderTarget: A reference to the cube render target.

Code Examples

// Create cube render target
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 256, { generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } );
// Create cube camera
const cubeCamera = new THREE.CubeCamera( 1, 100000, cubeRenderTarget );
scene.add( cubeCamera );
// Create car
const chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: cubeRenderTarget.texture } );
const car = new THREE.Mesh( carGeometry, chromeMaterial );
scene.add( car );
// Update the render target cube
car.visible = false;
cubeCamera.position.copy( car.position );
cubeCamera.update( renderer, scene );
// Render the scene
car.visible = true;
renderer.render( scene, camera );
  • What it demonstrates: Typical usage of CubeCamera.

Reference Tables

Constructor

Signature
new CubeCamera( near : number, far : number, renderTarget : WebGLCubeRenderTarget )

Properties

PropertyDescription
.activeMipmapLevel : numberThe current active mipmap level
`.coordinateSystem : WebGLCoordinateSystemWebGPUCoordinateSystem`
.renderTarget : WebGLCubeRenderTargetA reference to the cube render target.

Methods

MethodDescription
`.update( renderer : RendererWebGLRenderer, scene : Scene )`
.updateCoordinateSystem()Must be called when the coordinate system of the cube camera is changed.

Key Takeaways

  1. CubeCamera extends: EventDispatcher → Object3D
  2. Most relevant properties: activeMipmapLevel, coordinateSystem, renderTarget.
  3. Key methods: update, updateCoordinateSystem.

Connects To