PerspectiveCamera.updateAspect¶
Summary¶
PerspectiveCamera.updateAspect updates aspect ratio directly from viewport width and height. This is the preferred resize path when canvas dimensions change. The method marks projection dirty and returns the same camera for chaining.
Syntax¶
PerspectiveCamera.updateAspect(width: number, height: number): PerspectiveCamera
const result = camera.updateAspect(width, height);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
width |
number |
Yes | Viewport width in pixels or CSS units used to compute aspect. |
height |
number |
Yes | Viewport height in pixels or CSS units used to compute aspect. |
Returns¶
PerspectiveCamera - The same camera instance after applying width / height.
Type Details¶
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const camera = wgpu.createCamera.perspective();
camera.updateAspect(canvas.clientWidth, canvas.clientHeight);
window.addEventListener("resize", () => {
camera.updateAspect(canvas.clientWidth, canvas.clientHeight);
});