mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
* feat(catalog): put the variables panel back, on payloads The panel drove its preview by loading an .html from docs/public, a type the host does not publish, so it showed an empty frame in production and was parked when the catalog was re-landed. It now mounts the same JSON payload the plain player uses and re-mounts it as values change, injecting them as window.__hfVariables into the composition head before any of its scripts run, which is where the runtime reads overrides from. Doing it in the markup rather than after load is what stops the composition initialising with the wrong values first. 172 items with variables get the panel back; the playhead carries across a change so a tweak mid-shot does not jump back to frame zero. * fix(docs): drop the unused url form and the needless escapes * fix(docs): the panel cannot reference a binding beside the export * feat(catalog): make importing an SVG the obvious move A reader arrives at this control with a shape, not with path data, and the panel asked for the coordinates first. Import is now the primary action in a drop target you can see is a drop target, and the raw path sits behind a disclosure for anyone who wants it. * feat(cli): let a fruitless catalog search report the gap An agent that searches by meaning and finds nothing worth installing knows something we do not: the name of a move the catalog is missing. There was no way to tell us, so that knowledge was lost at the end of every run. hyperframes feedback --search-miss "<query>" --wanted "<the move>" records it. It carries no rating, so it never lands in the rating metric, and it is a separate deliberate command rather than something catalog --query does on its own: plain search still sends nothing, which is what the CLI promises. --rating stops being required at the arg level, since a miss has no rating to give. The check moved into the run body, where an absent one is now handled rather than crashing on undefined. * feat(cli): carry tuned variable values into the install snippet Someone who tunes a block on its catalog page had no way to keep those values: the install command was the same one everybody gets, and the tuning stayed on the page. hyperframes add <item> --vars '<json>' now prints a mount element carrying data-variable-values, so the values land where the block is used. They ride on the host rather than being written into the installed file. That keeps the composition on disk byte-identical to the registry's, so a later reinstall can still tell an edit from an update, and it lets two mounts of the same block carry different values. * fix(catalog): serve the item's own directory so runtime paths resolve Some compositions assemble their asset URLs at run time — "compositions/components/" + texture + ".png" for the texture masks, a font the compiler pulled into _remote_media — and no scan of the markup can see a string that does not exist until a script concatenates it. Those items either rendered black or were dropped to a video that had never been uploaded. Each item that needs it now has its prepared directory published, and its payload carries a <base> pointing at it, so any relative path the composition invents resolves. caption-texture renders its masks again, and variable-font-flex has a preview at all for the first time: its MP4 and poster are both 403. Both layouts are published, because which one a composition asks for differs per item, and a directory only earns that if it is under 2 MB. The 12 MB texture sheet keeps the recorded video it already had. * fix(catalog): let the variables panel actually drive the composition Every control on the panel was inert. The values reached the composition and nothing repainted, because the payload had already been compiled: compiling inlines a mounted component and resolves its variables into the markup and CSS, so by the time a reader turns a knob there is nothing left to change. An item that declares variables now ships uncompiled, keeping the mount the runtime loads at run time, which is the only state where data-variable-values still means anything. The component travels inline as a data URI rather than a sibling file, because .html is the one type the docs host will not publish. The demo's own pinned values come off, so the reader's choices reach the mount instead of losing to the values the demo picked to show itself off. Measured on the rendered frame rather than the DOM: green rgb(98,207,144), blue rgb(6,6,199), violet rgb(177,147,230), and back to green. docs/public/catalog drops from 48 MB to 35 MB along the way, since an uncompiled payload carries far less than an inlined one. * feat(catalog): keep variable changes in the url A reader who tuned a piece lost it on reload, and had nothing to send anyone. The values now live in the query string, scoped by composition id so two links never read each other,and only the ones that differ from the defaults are written, so changing one knob gives a short URL rather than every variable spelled out. replaceState rather than pushState: dragging a slider should not leave a trail of history entries. An unreadable value is ignored rather than thrown, so a truncated or hand-edited link opens the piece at its defaults. * fix(catalog): only rewrite the url when a value actually changed * refactor(catalog): memoise the declared defaults on their content * feat(catalog): offer an install command carrying the tuned values The Install block is generated before anyone touches a knob, so it can only ever print the plain command. Someone who spent a minute tuning a piece copied it and got the defaults back. The panel now carries its own command in the Snippet tab, with --vars holding exactly the values that differ. An untouched piece still offers the same short command, so nothing gets noisier for the common case. * fix(catalog): a piece with nothing to render is a skip, not a failure caption-blend-difference is a stylesheet and a paragraph of prose — a class you add to your own captions, with no standalone scene to show. The generator treated that as a build failure, so every run ended by reporting something broken when nothing was. It now reports the shape it is and keeps its recorded video, which is the only honest preview such an item has. A genuine render failure still throws. * fix(catalog): restore variables from the url on a cold load A shared link opened at the defaults. The first render happens on the server, where there is no window to read the query string from, and React then hydrates against that markup and never revisits it — so the values only appeared once you touched a control. The URL is read again after mount, which is the first moment it exists. The value is also escaped once now rather than twice: URLSearchParams already decodes on the way out, and decoding a second time turned an SVG path full of percent-escapes into something that no longer parsed, besides doubling the length of every link. * fix(catalog): mount the preview with the values a link carried The frame was built from the declared defaults and the shared values were posted to it afterwards, which is too late for anything the composition reads once at init: a path arrived after the mark had already been drawn from the default one, so a link looked right in the panel and wrong on screen. * feat(catalog): the install command follows the values you tuned Copying the Install line gave the plain command back, because that block is generated before anyone touches a knob and had no way to know what changed. The tuned command only existed in the panel Snippet tab, which is not where anyone looks for it. The line now reads the same query string the panel writes, so the two agree without either component knowing the other exists, and a shared link carries the right command too. replaceState fires no event, so the panel announces its own writes. * fix(catalog): send a text variable to the preview once it is finished Every other control in the explorer reports a whole value on every event: a slider at any position is a position, a swatch is a colour. A text field is not. Typing v3 into a badge posted v first, so the preview remounted and rendered a composition built from half a word. The post now waits while a text field has focus and goes out when the edit is committed, with Enter or by clicking away. The field itself is unchanged and still tracks every keystroke. --------- Co-authored-by: Miguel Angel Simon Sierra <miguelangelsi07@gmail.com>
795 lines
27 KiB
Plaintext
795 lines
27 KiB
Plaintext
---
|
||
title: "Dolly Zoom (Vertigo Shot)"
|
||
description: "Camera tracks toward or away from the subject while the field of view changes the opposite way, so the subject holds its frame size while the background collapses behind it or rushes in. Focal length is solved from dolly distance every frame against d * tan(FOV/2) = const, not keyframed beside it. Requires depth: the subject sits on the z = 0 plane and the content behind it must be layered or genuinely 3D (translateZ at two or more distinct depths) -- a flat element gains nothing from this move."
|
||
---
|
||
|
||
import { InstallCommand } from "/snippets/install-command.jsx";
|
||
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
|
||
|
||
<VariablesExplorer
|
||
previewSrc="/public/catalog/blocks/camera-dolly-zoom.json"
|
||
compositionId="camera-dolly-zoom"
|
||
compositionSrc="compositions/camera-dolly-zoom.html"
|
||
variables={[{"id":"direction","type":"enum","label":"Dolly direction","default":"out","options":[{"value":"out","label":"Dolly out + zoom in (background rushes in)"},{"value":"in","label":"Dolly in + zoom out (background falls away)"}]},{"id":"strength","type":"number","label":"Move strength (end / start distance ratio)","default":2,"min":1.1,"max":4,"step":0.1},{"id":"subjectDistance","type":"number","label":"Camera-to-subject distance at the start of the move","default":1400,"min":600,"max":3000,"step":50,"unit":"px"},{"id":"easing","type":"enum","label":"Dolly easing","default":"power2.inOut","options":[{"value":"none","label":"Linear"},{"value":"sine.inOut","label":"Sine in-out"},{"value":"power1.inOut","label":"Power1 in-out"},{"value":"power2.inOut","label":"Power2 in-out"},{"value":"power3.inOut","label":"Power3 in-out"}]}]}
|
||
>
|
||
|
||
```html camera-dolly-zoom.html
|
||
<!doctype html>
|
||
<html
|
||
lang="en"
|
||
data-composition-variables='[
|
||
{
|
||
"id": "direction",
|
||
"type": "enum",
|
||
"label": "Dolly direction",
|
||
"default": "out",
|
||
"options": [
|
||
{ "value": "out", "label": "Dolly out + zoom in (background rushes in)" },
|
||
{ "value": "in", "label": "Dolly in + zoom out (background falls away)" }
|
||
]
|
||
},
|
||
{
|
||
"id": "strength",
|
||
"type": "number",
|
||
"label": "Move strength (end / start distance ratio)",
|
||
"default": 2,
|
||
"min": 1.1,
|
||
"max": 4,
|
||
"step": 0.1
|
||
},
|
||
{
|
||
"id": "subjectDistance",
|
||
"type": "number",
|
||
"label": "Camera-to-subject distance at the start of the move",
|
||
"default": 1400,
|
||
"min": 600,
|
||
"max": 3000,
|
||
"step": 50,
|
||
"unit": "px"
|
||
},
|
||
{
|
||
"id": "easing",
|
||
"type": "enum",
|
||
"label": "Dolly easing",
|
||
"default": "power2.inOut",
|
||
"options": [
|
||
{ "value": "none", "label": "Linear" },
|
||
{ "value": "sine.inOut", "label": "Sine in-out" },
|
||
{ "value": "power1.inOut", "label": "Power1 in-out" },
|
||
{ "value": "power2.inOut", "label": "Power2 in-out" },
|
||
{ "value": "power3.inOut", "label": "Power3 in-out" }
|
||
]
|
||
}
|
||
]'
|
||
>
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||
<style>
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
html,
|
||
body {
|
||
width: 1920px;
|
||
height: 1080px;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<!--
|
||
===================================================================
|
||
DOLLY ZOOM (Vertigo / Hitchcock shot)
|
||
===================================================================
|
||
|
||
The camera tracks toward or away from the subject while the field of
|
||
view changes the opposite way, so the SUBJECT HOLDS ITS FRAME SIZE
|
||
while the background collapses behind it or rushes in.
|
||
|
||
THE CONSTRAINT (this is the whole effect, and it is exact, not taste):
|
||
|
||
d * tan(FOV / 2) = constant
|
||
|
||
where d is the camera-to-subject distance. Get it wrong and the shot
|
||
reads as a clumsy zoom. So focal length is SOLVED from distance every
|
||
frame; the two are never keyframed side by side.
|
||
|
||
In CSS 3D, `perspective: P px` IS the focal length in pixels, and it
|
||
also places the camera exactly P px in front of the z = 0 plane, so
|
||
tan(FOV / 2) = (viewportWidth / 2) / P. Substituting collapses the
|
||
invariant to a single ratio:
|
||
|
||
P(t) / d(t) = SUBJECT_SCALE (constant)
|
||
|
||
Everything the rig animates falls out of that one line (see the script).
|
||
|
||
-------------------------------------------------------------------
|
||
WHAT THIS PRIMITIVE REQUIRES OF ITS CONTENT
|
||
-------------------------------------------------------------------
|
||
|
||
DEPTH. A flat element gains nothing from a dolly zoom -- with one
|
||
layer there is no background to collapse and the move is invisible.
|
||
Content dropped into #dz-rig MUST be layered or genuinely 3D:
|
||
|
||
* The SUBJECT sits on the z = 0 plane -- `translateZ(0)`. That is
|
||
the plane the solve holds; anything you want frame-locked goes
|
||
there and nowhere else.
|
||
* BACKGROUND layers get `translateZ(-N px)`, N > 0, at least two or
|
||
three distinct depths (this demo ships five arches plus a back
|
||
wall). More separation = stronger effect.
|
||
* Everything inside #dz-rig must keep `transform-style: preserve-3d`
|
||
on its ancestors and must NOT sit behind `overflow: hidden`, or
|
||
the browser flattens the scene and the depth disappears.
|
||
* Keep every layer at a depth where `d + N > 0` for the whole move,
|
||
i.e. no layer in front of the camera's closest approach.
|
||
|
||
-------------------------------------------------------------------
|
||
DETERMINISM
|
||
-------------------------------------------------------------------
|
||
|
||
State at frame N is computed from N alone. d(t) is a lerp of the
|
||
eased tween progress, P is solved from d, and both are written by a
|
||
property setter on the tweened driver object. Nothing accumulates,
|
||
nothing reads a clock, and no frame depends on the frame before it.
|
||
(The setter matters: `tl.eventCallback("onUpdate", ...)` does NOT
|
||
fire on `tl.seek()`, so anything driven that way freezes on frame 0.)
|
||
-->
|
||
<div
|
||
id="dz-root"
|
||
data-composition-id="camera-dolly-zoom"
|
||
data-start="0"
|
||
data-duration="4"
|
||
data-width="1920"
|
||
data-height="1080"
|
||
>
|
||
<style>
|
||
#dz-root {
|
||
width: 1920px;
|
||
height: 1080px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
background: #0b1020;
|
||
font-family: Inter, sans-serif;
|
||
}
|
||
|
||
/* The camera. `perspective` is the focal length and is solved from
|
||
the dolly distance every frame -- see the script. */
|
||
#dz-stage {
|
||
position: absolute;
|
||
inset: 0;
|
||
perspective-origin: 50% 50%;
|
||
}
|
||
|
||
/* The rig root. Carries the camera's z offset so the subject plane
|
||
always sits exactly `d` in front of the camera. */
|
||
#dz-rig {
|
||
position: absolute;
|
||
inset: 0;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
/* --- authored depth layers ------------------------------------ */
|
||
|
||
.dz-arch {
|
||
position: absolute;
|
||
left: -140px;
|
||
top: -80px;
|
||
width: 2200px;
|
||
height: 1240px;
|
||
border: 16px solid #465280;
|
||
border-radius: 8px;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
#dz-backwall {
|
||
position: absolute;
|
||
left: -3040px;
|
||
top: -1710px;
|
||
width: 8000px;
|
||
height: 4500px;
|
||
background: #10162c;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
/* Bright doorway on the back wall -- the layer whose on-screen size
|
||
changes while the subject's does not. */
|
||
#dz-portal {
|
||
position: absolute;
|
||
left: 3300px;
|
||
top: 1850px;
|
||
width: 1400px;
|
||
height: 1500px;
|
||
background: #cfe4ff;
|
||
}
|
||
|
||
/* --- the subject: z = 0, the plane the solve holds ------------- */
|
||
|
||
#dz-subject {
|
||
position: absolute;
|
||
left: 840px;
|
||
top: 300px;
|
||
width: 240px;
|
||
height: 620px;
|
||
transform-style: preserve-3d;
|
||
}
|
||
.dz-fig-head {
|
||
width: 120px;
|
||
height: 120px;
|
||
margin: 0 auto;
|
||
border-radius: 50%;
|
||
background: #f2b134;
|
||
}
|
||
.dz-fig-body {
|
||
width: 240px;
|
||
height: 470px;
|
||
margin-top: 30px;
|
||
border-radius: 120px 120px 10px 10px;
|
||
background: #f2b134;
|
||
}
|
||
|
||
/* --- flat overlay (outside the 3D rig) ------------------------- */
|
||
|
||
.dz-label {
|
||
position: absolute;
|
||
left: 64px;
|
||
bottom: 56px;
|
||
padding: 14px 22px;
|
||
border-radius: 8px;
|
||
background: #0b1020;
|
||
color: #e9eeff;
|
||
font-size: 26px;
|
||
letter-spacing: 0.14em;
|
||
text-transform: uppercase;
|
||
}
|
||
</style>
|
||
|
||
<div id="dz-stage" class="clip" data-start="0" data-duration="4" data-track-index="0">
|
||
<div id="dz-rig">
|
||
<div id="dz-backwall" data-layout-allow-overflow style="transform: translateZ(-3200px)">
|
||
<div id="dz-portal"></div>
|
||
</div>
|
||
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-2360px); border-color: #384166"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-1720px); border-color: #465280"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-1120px); border-color: #57669c"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-560px); border-color: #6b7cb8"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(0px); border-color: #8194d4"
|
||
></div>
|
||
|
||
<div id="dz-subject" style="transform: translateZ(0px)">
|
||
<div class="dz-fig-head"></div>
|
||
<div class="dz-fig-body"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="dz-label">Dolly zoom · d × tan(fov/2) = const</div>
|
||
</div>
|
||
|
||
<script>
|
||
window.__timelines = window.__timelines || {};
|
||
|
||
(function () {
|
||
var DEFAULTS = {
|
||
direction: "out",
|
||
strength: 2,
|
||
subjectDistance: 1400,
|
||
easing: "power2.inOut",
|
||
};
|
||
var declared =
|
||
window.__hyperframes && window.__hyperframes.getVariables
|
||
? window.__hyperframes.getVariables()
|
||
: {};
|
||
var vars = Object.assign({}, DEFAULTS, declared);
|
||
|
||
function clamp(value, lo, hi, fallback) {
|
||
var n = Number(value);
|
||
if (!isFinite(n)) return fallback;
|
||
return Math.min(hi, Math.max(lo, n));
|
||
}
|
||
function oneOf(value, allowed, fallback) {
|
||
return allowed.indexOf(String(value)) >= 0 ? String(value) : fallback;
|
||
}
|
||
|
||
var direction = oneOf(vars.direction, ["in", "out"], DEFAULTS.direction);
|
||
var strength = clamp(vars.strength, 1.1, 4, DEFAULTS.strength);
|
||
var ease = oneOf(
|
||
vars.easing,
|
||
["none", "sine.inOut", "power1.inOut", "power2.inOut", "power3.inOut"],
|
||
DEFAULTS.easing,
|
||
);
|
||
|
||
// d0 = camera-to-subject distance at the start of the move (px).
|
||
// d1 = distance at the end. "out" pulls the camera back and zooms in;
|
||
// "in" pushes the camera forward and zooms out.
|
||
var d0 = clamp(vars.subjectDistance, 600, 3000, DEFAULTS.subjectDistance);
|
||
var d1 = direction === "in" ? d0 / strength : d0 * strength;
|
||
|
||
// ---- the solve --------------------------------------------------
|
||
// Subject size is fixed iff d * tan(FOV/2) = const. With CSS 3D,
|
||
// tan(FOV/2) = (width/2) / perspective, so that invariant is exactly
|
||
// perspective / distance = SUBJECT_SCALE. Focal length is therefore
|
||
// derived from the dolly, never animated alongside it.
|
||
var SUBJECT_SCALE = 1; // subject renders 1:1 => its plane is z = 0
|
||
|
||
var stage = document.getElementById("dz-stage");
|
||
var rig = document.getElementById("dz-rig");
|
||
|
||
function applyCamera(u) {
|
||
var d = d0 + (d1 - d0) * u; // dolly -- pure function of u
|
||
var P = SUBJECT_SCALE * d; // focal length solved from d
|
||
var camZ = P - d; // put the subject plane at camera distance d
|
||
stage.style.perspective = P + "px";
|
||
rig.style.transform = "translateZ(" + camZ + "px)";
|
||
}
|
||
|
||
// GSAP suppresses timeline-level onUpdate during seek(), so the camera
|
||
// is driven by a property setter on the tweened object instead: that
|
||
// fires on every render, seeks included.
|
||
var camera = {
|
||
_u: 0,
|
||
get u() {
|
||
return this._u;
|
||
},
|
||
set u(value) {
|
||
this._u = value;
|
||
applyCamera(value);
|
||
},
|
||
};
|
||
|
||
applyCamera(0);
|
||
|
||
var tl = gsap.timeline({ paused: true });
|
||
tl.to(camera, { u: 1, duration: 4, ease: ease }, 0);
|
||
window.__timelines["camera-dolly-zoom"] = tl;
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
```
|
||
|
||
</VariablesExplorer>
|
||
|
||
## Install
|
||
|
||
<InstallCommand command="npx hyperframes add camera-dolly-zoom" item="camera-dolly-zoom" />
|
||
|
||
That writes one file: `compositions/camera-dolly-zoom.html`.
|
||
|
||
## Add it to your video
|
||
|
||
It runs for 4 seconds at 1920×1080. Paste this into your composition:
|
||
|
||
```html index.html
|
||
<div
|
||
data-composition-id="camera-dolly-zoom"
|
||
data-composition-src="compositions/camera-dolly-zoom.html"
|
||
data-start="0"
|
||
data-duration="4"
|
||
data-track-index="1"
|
||
data-width="1920"
|
||
data-height="1080"
|
||
></div>
|
||
```
|
||
|
||
Move it in time with `data-start`. Put it on a different timeline row with
|
||
`data-track-index`. See [data attributes](/concepts/data-attributes) for the rest.
|
||
|
||
## Variables
|
||
|
||
Every one of these has a default, so the piece works untouched. Set the ones you
|
||
want to change on the element:
|
||
|
||
| Variable | Default | Accepts | What it does |
|
||
| --- | --- | --- | --- |
|
||
| `direction` | `out` | `out`, `in` | |
|
||
| `strength` | `2` | 1.1 to 4, step 0.1 | |
|
||
| `subjectDistance` | `1400` | 600px to 3000px, step 50px | |
|
||
| `easing` | `power2.inOut` | `none`, `sine.inOut`, `power1.inOut`, `power2.inOut`, `power3.inOut` | |
|
||
|
||
Set them with `data-variable-values` on the element that mounts it. These are the
|
||
defaults, so this behaves exactly like the preview above until you change one:
|
||
|
||
```html wrap
|
||
<div
|
||
data-composition-id="camera-dolly-zoom"
|
||
data-composition-src="compositions/camera-dolly-zoom.html"
|
||
data-variable-values='{"direction":"out","strength":2,"subjectDistance":1400,"easing":"power2.inOut"}'
|
||
></div>
|
||
```
|
||
|
||
## Source
|
||
|
||
<Accordion title={`camera-dolly-zoom.html`}>
|
||
|
||
```html
|
||
<!doctype html>
|
||
<html
|
||
lang="en"
|
||
data-composition-variables='[
|
||
{
|
||
"id": "direction",
|
||
"type": "enum",
|
||
"label": "Dolly direction",
|
||
"default": "out",
|
||
"options": [
|
||
{ "value": "out", "label": "Dolly out + zoom in (background rushes in)" },
|
||
{ "value": "in", "label": "Dolly in + zoom out (background falls away)" }
|
||
]
|
||
},
|
||
{
|
||
"id": "strength",
|
||
"type": "number",
|
||
"label": "Move strength (end / start distance ratio)",
|
||
"default": 2,
|
||
"min": 1.1,
|
||
"max": 4,
|
||
"step": 0.1
|
||
},
|
||
{
|
||
"id": "subjectDistance",
|
||
"type": "number",
|
||
"label": "Camera-to-subject distance at the start of the move",
|
||
"default": 1400,
|
||
"min": 600,
|
||
"max": 3000,
|
||
"step": 50,
|
||
"unit": "px"
|
||
},
|
||
{
|
||
"id": "easing",
|
||
"type": "enum",
|
||
"label": "Dolly easing",
|
||
"default": "power2.inOut",
|
||
"options": [
|
||
{ "value": "none", "label": "Linear" },
|
||
{ "value": "sine.inOut", "label": "Sine in-out" },
|
||
{ "value": "power1.inOut", "label": "Power1 in-out" },
|
||
{ "value": "power2.inOut", "label": "Power2 in-out" },
|
||
{ "value": "power3.inOut", "label": "Power3 in-out" }
|
||
]
|
||
}
|
||
]'
|
||
>
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||
<style>
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
html,
|
||
body {
|
||
width: 1920px;
|
||
height: 1080px;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<!--
|
||
===================================================================
|
||
DOLLY ZOOM (Vertigo / Hitchcock shot)
|
||
===================================================================
|
||
|
||
The camera tracks toward or away from the subject while the field of
|
||
view changes the opposite way, so the SUBJECT HOLDS ITS FRAME SIZE
|
||
while the background collapses behind it or rushes in.
|
||
|
||
THE CONSTRAINT (this is the whole effect, and it is exact, not taste):
|
||
|
||
d * tan(FOV / 2) = constant
|
||
|
||
where d is the camera-to-subject distance. Get it wrong and the shot
|
||
reads as a clumsy zoom. So focal length is SOLVED from distance every
|
||
frame; the two are never keyframed side by side.
|
||
|
||
In CSS 3D, `perspective: P px` IS the focal length in pixels, and it
|
||
also places the camera exactly P px in front of the z = 0 plane, so
|
||
tan(FOV / 2) = (viewportWidth / 2) / P. Substituting collapses the
|
||
invariant to a single ratio:
|
||
|
||
P(t) / d(t) = SUBJECT_SCALE (constant)
|
||
|
||
Everything the rig animates falls out of that one line (see the script).
|
||
|
||
-------------------------------------------------------------------
|
||
WHAT THIS PRIMITIVE REQUIRES OF ITS CONTENT
|
||
-------------------------------------------------------------------
|
||
|
||
DEPTH. A flat element gains nothing from a dolly zoom -- with one
|
||
layer there is no background to collapse and the move is invisible.
|
||
Content dropped into #dz-rig MUST be layered or genuinely 3D:
|
||
|
||
* The SUBJECT sits on the z = 0 plane -- `translateZ(0)`. That is
|
||
the plane the solve holds; anything you want frame-locked goes
|
||
there and nowhere else.
|
||
* BACKGROUND layers get `translateZ(-N px)`, N > 0, at least two or
|
||
three distinct depths (this demo ships five arches plus a back
|
||
wall). More separation = stronger effect.
|
||
* Everything inside #dz-rig must keep `transform-style: preserve-3d`
|
||
on its ancestors and must NOT sit behind `overflow: hidden`, or
|
||
the browser flattens the scene and the depth disappears.
|
||
* Keep every layer at a depth where `d + N > 0` for the whole move,
|
||
i.e. no layer in front of the camera's closest approach.
|
||
|
||
-------------------------------------------------------------------
|
||
DETERMINISM
|
||
-------------------------------------------------------------------
|
||
|
||
State at frame N is computed from N alone. d(t) is a lerp of the
|
||
eased tween progress, P is solved from d, and both are written by a
|
||
property setter on the tweened driver object. Nothing accumulates,
|
||
nothing reads a clock, and no frame depends on the frame before it.
|
||
(The setter matters: `tl.eventCallback("onUpdate", ...)` does NOT
|
||
fire on `tl.seek()`, so anything driven that way freezes on frame 0.)
|
||
-->
|
||
<div
|
||
id="dz-root"
|
||
data-composition-id="camera-dolly-zoom"
|
||
data-start="0"
|
||
data-duration="4"
|
||
data-width="1920"
|
||
data-height="1080"
|
||
>
|
||
<style>
|
||
#dz-root {
|
||
width: 1920px;
|
||
height: 1080px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
background: #0b1020;
|
||
font-family: Inter, sans-serif;
|
||
}
|
||
|
||
/* The camera. `perspective` is the focal length and is solved from
|
||
the dolly distance every frame -- see the script. */
|
||
#dz-stage {
|
||
position: absolute;
|
||
inset: 0;
|
||
perspective-origin: 50% 50%;
|
||
}
|
||
|
||
/* The rig root. Carries the camera's z offset so the subject plane
|
||
always sits exactly `d` in front of the camera. */
|
||
#dz-rig {
|
||
position: absolute;
|
||
inset: 0;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
/* --- authored depth layers ------------------------------------ */
|
||
|
||
.dz-arch {
|
||
position: absolute;
|
||
left: -140px;
|
||
top: -80px;
|
||
width: 2200px;
|
||
height: 1240px;
|
||
border: 16px solid #465280;
|
||
border-radius: 8px;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
#dz-backwall {
|
||
position: absolute;
|
||
left: -3040px;
|
||
top: -1710px;
|
||
width: 8000px;
|
||
height: 4500px;
|
||
background: #10162c;
|
||
transform-style: preserve-3d;
|
||
}
|
||
|
||
/* Bright doorway on the back wall -- the layer whose on-screen size
|
||
changes while the subject's does not. */
|
||
#dz-portal {
|
||
position: absolute;
|
||
left: 3300px;
|
||
top: 1850px;
|
||
width: 1400px;
|
||
height: 1500px;
|
||
background: #cfe4ff;
|
||
}
|
||
|
||
/* --- the subject: z = 0, the plane the solve holds ------------- */
|
||
|
||
#dz-subject {
|
||
position: absolute;
|
||
left: 840px;
|
||
top: 300px;
|
||
width: 240px;
|
||
height: 620px;
|
||
transform-style: preserve-3d;
|
||
}
|
||
.dz-fig-head {
|
||
width: 120px;
|
||
height: 120px;
|
||
margin: 0 auto;
|
||
border-radius: 50%;
|
||
background: #f2b134;
|
||
}
|
||
.dz-fig-body {
|
||
width: 240px;
|
||
height: 470px;
|
||
margin-top: 30px;
|
||
border-radius: 120px 120px 10px 10px;
|
||
background: #f2b134;
|
||
}
|
||
|
||
/* --- flat overlay (outside the 3D rig) ------------------------- */
|
||
|
||
.dz-label {
|
||
position: absolute;
|
||
left: 64px;
|
||
bottom: 56px;
|
||
padding: 14px 22px;
|
||
border-radius: 8px;
|
||
background: #0b1020;
|
||
color: #e9eeff;
|
||
font-size: 26px;
|
||
letter-spacing: 0.14em;
|
||
text-transform: uppercase;
|
||
}
|
||
</style>
|
||
|
||
<div id="dz-stage" class="clip" data-start="0" data-duration="4" data-track-index="0">
|
||
<div id="dz-rig">
|
||
<div id="dz-backwall" data-layout-allow-overflow style="transform: translateZ(-3200px)">
|
||
<div id="dz-portal"></div>
|
||
</div>
|
||
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-2360px); border-color: #384166"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-1720px); border-color: #465280"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-1120px); border-color: #57669c"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(-560px); border-color: #6b7cb8"
|
||
></div>
|
||
<div
|
||
class="dz-arch"
|
||
data-layout-allow-overflow
|
||
style="transform: translateZ(0px); border-color: #8194d4"
|
||
></div>
|
||
|
||
<div id="dz-subject" style="transform: translateZ(0px)">
|
||
<div class="dz-fig-head"></div>
|
||
<div class="dz-fig-body"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="dz-label">Dolly zoom · d × tan(fov/2) = const</div>
|
||
</div>
|
||
|
||
<script>
|
||
window.__timelines = window.__timelines || {};
|
||
|
||
(function () {
|
||
var DEFAULTS = {
|
||
direction: "out",
|
||
strength: 2,
|
||
subjectDistance: 1400,
|
||
easing: "power2.inOut",
|
||
};
|
||
var declared =
|
||
window.__hyperframes && window.__hyperframes.getVariables
|
||
? window.__hyperframes.getVariables()
|
||
: {};
|
||
var vars = Object.assign({}, DEFAULTS, declared);
|
||
|
||
function clamp(value, lo, hi, fallback) {
|
||
var n = Number(value);
|
||
if (!isFinite(n)) return fallback;
|
||
return Math.min(hi, Math.max(lo, n));
|
||
}
|
||
function oneOf(value, allowed, fallback) {
|
||
return allowed.indexOf(String(value)) >= 0 ? String(value) : fallback;
|
||
}
|
||
|
||
var direction = oneOf(vars.direction, ["in", "out"], DEFAULTS.direction);
|
||
var strength = clamp(vars.strength, 1.1, 4, DEFAULTS.strength);
|
||
var ease = oneOf(
|
||
vars.easing,
|
||
["none", "sine.inOut", "power1.inOut", "power2.inOut", "power3.inOut"],
|
||
DEFAULTS.easing,
|
||
);
|
||
|
||
// d0 = camera-to-subject distance at the start of the move (px).
|
||
// d1 = distance at the end. "out" pulls the camera back and zooms in;
|
||
// "in" pushes the camera forward and zooms out.
|
||
var d0 = clamp(vars.subjectDistance, 600, 3000, DEFAULTS.subjectDistance);
|
||
var d1 = direction === "in" ? d0 / strength : d0 * strength;
|
||
|
||
// ---- the solve --------------------------------------------------
|
||
// Subject size is fixed iff d * tan(FOV/2) = const. With CSS 3D,
|
||
// tan(FOV/2) = (width/2) / perspective, so that invariant is exactly
|
||
// perspective / distance = SUBJECT_SCALE. Focal length is therefore
|
||
// derived from the dolly, never animated alongside it.
|
||
var SUBJECT_SCALE = 1; // subject renders 1:1 => its plane is z = 0
|
||
|
||
var stage = document.getElementById("dz-stage");
|
||
var rig = document.getElementById("dz-rig");
|
||
|
||
function applyCamera(u) {
|
||
var d = d0 + (d1 - d0) * u; // dolly -- pure function of u
|
||
var P = SUBJECT_SCALE * d; // focal length solved from d
|
||
var camZ = P - d; // put the subject plane at camera distance d
|
||
stage.style.perspective = P + "px";
|
||
rig.style.transform = "translateZ(" + camZ + "px)";
|
||
}
|
||
|
||
// GSAP suppresses timeline-level onUpdate during seek(), so the camera
|
||
// is driven by a property setter on the tweened object instead: that
|
||
// fires on every render, seeks included.
|
||
var camera = {
|
||
_u: 0,
|
||
get u() {
|
||
return this._u;
|
||
},
|
||
set u(value) {
|
||
this._u = value;
|
||
applyCamera(value);
|
||
},
|
||
};
|
||
|
||
applyCamera(0);
|
||
|
||
var tl = gsap.timeline({ paused: true });
|
||
tl.to(camera, { u: 1, duration: 4, ease: ease }, 0);
|
||
window.__timelines["camera-dolly-zoom"] = tl;
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
```
|
||
|
||
</Accordion>
|
||
|
||
{/* hf:generated-footer */}
|
||
|
||
Tagged `camera` `depth` `3d` `cinematic`.
|
||
|
||
## Related topics
|
||
|
||
- [Browse the complete Catalog](/catalog)
|
||
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
|
||
- [Build a richer composition](/go-further)
|