glodrei
Version:
useful add-ons for react-three-fiber
57 lines (46 loc) • 2.09 kB
text/mdx
---
title: PerspectiveCamera
sourcecode: src/core/PerspectiveCamera.tsx
---
[](https://drei.vercel.app/?path=/story/camera-perspectivecamera--perspective-camera-scene-st)
```tsx
type Props = Omit<JSX.IntrinsicElements['perspectiveCamera'], 'children'> & {
/** Registers the camera as the system default, fiber will start rendering with it */
makeDefault?: boolean
/** Making it manual will stop responsiveness and you have to calculate aspect ratio yourself. */
manual?: boolean
/** The contents will either follow the camera, or be hidden when filming if you pass a function */
children?: React.ReactNode | ((texture: THREE.Texture) => React.ReactNode)
/** Number of frames to render, 0 */
frames?: number
/** Resolution of the FBO, 256 */
resolution?: number
/** Optional environment map for functional use */
envMap?: THREE.Texture
}
```
A responsive [THREE.PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) that can set itself as the default.
```jsx
<PerspectiveCamera makeDefault {...props} />
<mesh />
```
You can also give it children, which will now occupy the same position as the camera and follow along as it moves.
```jsx
<PerspectiveCamera makeDefault {...props}>
<mesh />
</PerspectiveCamera>
```
You can also drive it manually, it won't be responsive and you have to calculate aspect ratio yourself.
```jsx
<PerspectiveCamera manual aspect={...} onUpdate={(c) => c.updateProjectionMatrix()}>
```
You can use the PerspectiveCamera to film contents into a RenderTarget, similar to CubeCamera. As a child you must provide a render-function which receives the texture as its first argument. The result of that function will _not follow the camera_, instead it will be set invisible while the FBO renders so as to avoid issues where the meshes that receive the texture are interrering.
```jsx
<PerspectiveCamera position={[0, 0, 10]}>
{(texture) => (
<mesh geometry={plane}>
<meshBasicMaterial map={texture} />
</mesh>
)}
</PerspectiveCamera>
```