Transforms
Move, scale and turn a layer, pivot it about its centre, and give it depth with a camera or a 3D scene.
Every layer takes x, y, scale and rotation. Compute them from the frame to animate them.
import { Rect, interpolate, useCurrentFrame } from '@kinetographdev/core';
export const Spin = () => {
const frame = useCurrentFrame();
const turn = interpolate(frame, [0, 60], [0, 90], { extrapolateRight: 'clamp' });
return <Rect x={640} y={360} width={300} height={200} fill="#f6c177" origin="center" rotation={turn} scale={1 + frame / 120} />;
};Position, scale and turn
| Prop | Meaning |
|---|---|
x, y | Where the layer lands in its parent, in pixels. |
scale | Scale about the pivot. |
rotation | Degrees, clockwise. |
origin | The pivot for scale and turn: 'center', or fractions of the layer's size. |
A child moves inside its parent, so move a Layer to move everything in it. origin needs a layer with a box (a shape, an image, text, or a group with a layout).
In <div> elements, transform works as in CSS, and @keyframes follow the frame's time.
Depth: a camera and 3D turns
rotateX and rotateY (degrees) turn a layer in 3D, and z moves it toward the viewer in pixels. A Camera gives the scene a perspective. Without one the view is flat: turns foreshorten, and z moves nothing.
import { Camera, Image, Layer, interpolate, staticFile, useCurrentFrame } from '@kinetographdev/core';
export const Flip = () => {
const frame = useCurrentFrame();
const spin = interpolate(frame, [0, 60], [0, 180]);
return (
<Layer>
<Camera perspective={1400} />
<Image src={staticFile('images/card.png')} width={400} height={560} x={440} y={80} origin="center" rotateY={spin} />
</Layer>
);
};- Turn a layer past 90 degrees and you see its back, mirrored, as in CSS.
- Put
preserve3don aLayerto let its children sit at differentzand turn together. It cannot haveeffects,clip,mask,matteormotionBlur; wrap it in an ordinaryLayerand put them there.
3D scenes
For real 3D, a Scene3D holds a camera, lights and objects, and draws as one layer. It takes the common props of a layer.
import { AmbientLight, Camera3D, DirectionalLight, Mesh, Scene3D, useCurrentFrame } from '@kinetographdev/core';
export const Torus = () => {
const frame = useCurrentFrame();
return (
<Scene3D width={960} height={540}>
<Camera3D fov={40} position={[0, 2, 8]} target={[0, 0.5, 0]} />
<AmbientLight intensity={0.3} />
<DirectionalLight direction={[-1, -1, -1]} intensity={1.6} />
<Mesh geometry={{ kind: 'torus' }} material={{ color: '#c77dff', roughness: 0.3 }} rotation={[60, frame * 3, 0]} />
</Scene3D>
);
};Meshtakes abox,sphere,plane,cylinderortorus.Modelloads a glTF or GLB file.Text3DandExtrudemake letters and SVG paths solid.Camera3Dis a perspective camera, or an orthographic one withtype="orthographic"and aheight. APointLightfalls off with distance squared; itsrangeis a limit, and 0 means none.- Shadows come from a
DirectionalLightwithcastShadow;environmenttakes an equirectangular image to light the scene. There is no Three.js API behind it. The full props are in AUTHORING.md, section 6.6.
Suggested prompt
/kinetograph-markupFlip the card over with a 3D turn and a camera, then show me a strip of 12 frames.
What works
- Drawn natively: 2D transforms, 3D turns with a camera,
preserve3dwith depth sorting, andScene3D. - Approximated: the crossing line of
preserve3dplanes is not anti-aliased, and abackdrop-filteron a turned element mirrors the backdrop at its bounding box. A layer is cut at the canvas edge before it is turned, unless a margin gives it room. - Not supported:
@remotion/three, whichScene3Dreplaces. A glTF extension or a second set of texture coordinates in aModelis not read, anddoctorreports it by name. - See What works.