Skip to content

PolyCamera

PolyCSS provides two camera components: <PolyCamera> (alias <PolyOrthographicCamera>) for parallel projection, and <PolyPerspectiveCamera> for scenes with depth foreshortening. The camera element is always the outer node — <poly-scene> / PolyScene is nested inside it. This is required by the CSS rendering model: CSS perspective only applies to descendants, so the scene’s transform: matrix3d(...) must be a child of the camera.

<PolyCamera> is orthographic by default. Use <PolyPerspectiveCamera> when depth foreshortening is needed (e.g. first-person or game-like scenes).

For pointer drag, wheel zoom, and autorotate, drop a <PolyOrbitControls> child inside the scene: see PolyOrbitControls.

Use caseComponent
Isometric / voxel / diagrammatic scenes<PolyCamera> (alias <PolyOrthographicCamera>) — default
3D scenes with depth foreshortening<PolyPerspectiveCamera>

PolyCSS defaults to orthographic rather than perspective — PolyCSS’s strengths (integer-pixel atlas, no per-frame JS, DOM stacking) are most visible in ortho scenes. This deliberately diverges from three.js’s default.

PolyCamera is an alias for PolyOrthographicCamera. Import either: they are identical. Uses perspective: none (parallel projection). No perspective prop.

PropTypeDefaultDescription
zoomnumber1Scales the scene. 1 is the natural size; values above 1 zoom in, below 1 zoom out.
rotXnumber65Rotation around the X axis in degrees.
rotYnumber45Rotation around the Y axis in degrees (0–360).
distancenumber0Dolly pull-back in pixels. When > 0, adds translateZ(-distance)px to the scene transform. Driven by dolly mode in PolyOrbitControls.
targetVec3[0,0,0]Point in scene space the camera orbits around.

Adds CSS perspective for depth foreshortening. Use for game-like or first-person scenes.

All props from PolyCamera above, plus:

PropTypeDefaultDescription
perspectivenumber32000CSS perspective depth in pixels. Higher values feel flatter (more isometric); lower values exaggerate depth.

Set an initial angle. PolyCamera (orthographic) is the default.

<script type="module" src="https://esm.sh/@layoutit/polycss/elements"></script>
<poly-camera zoom="0.8" rot-x="70" rot-y="30">
<poly-scene>
<poly-cone color="#ffd166"></poly-cone>
</poly-scene>
</poly-camera>

<poly-camera> / PolyCamera is orthographic. PolyOrthographicCamera is the explicit alias — use either.

<poly-camera rot-x="65" rot-y="45">
<poly-scene>
<poly-icosahedron size="100" color="#ff6644"></poly-icosahedron>
</poly-scene>
</poly-camera>
Section titled “Interactive Camera with Auto-rotation (recommended)”

Drop a <PolyOrbitControls> child for drag, wheel, and dt-clamped autorotate. Works the same across vanilla, React, and Vue.

<!-- Vanilla -->
<poly-camera rot-x="65" rot-y="45">
<poly-scene>
<poly-orbit-controls drag wheel animate-speed="0.5"></poly-orbit-controls>
<poly-torus color="#4ecdc4"></poly-torus>
</poly-scene>
</poly-camera>
// React
<PolyCamera rotX={65} rotY={45}>
<PolyScene>
<PolyOrbitControls drag wheel animate={{ axis: "y", speed: 0.5 }} />
<PolyTorus color="#4ecdc4" />
</PolyScene>
</PolyCamera>

Full options reference: PolyOrbitControls.

distance adds a translateZ(-distance)px to the scene transform. Unlike zoom, which scales the entire scene, distance moves the viewpoint back along the view axis: equivalent to increasing the spherical radius in three.js OrbitControls. Enable dolly on PolyOrbitControls to let the wheel drive distance instead of zoom.

usePolyCamera is used internally by <PolyCamera>. Use <PolyCamera> as the wrapper whenever a React or Vue scene needs camera state, pointer controls, wheel controls, or autorotate.