Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ <h2>Tech demos</h2>
<li><a href="demos/find-code/index.html">Find the Code</a></li>
<li><a href="demos/fog-of-history/index.html">Fog of History</a></li>
<li><a href="demos/lights-out/index.html">Lights Out</a></li>
<li><a href="demos/light-shafts/index.html">Light Shafts</a></li>
<li><a href="demos/still-water/index.html">Still Water</a></li>
<li><a href="demos/moon/index.html">The Moon</a></li>
<li><a href="demos/globe-gores/index.html">America, folded</a></li>
</ul>
Expand Down
48 changes: 28 additions & 20 deletions examples/public/demos/find-code/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ const TARGET = [0, 130, -40];
const CODE = "1847";
// How far scrolling moves the camera towards its target
const DOLLY = 350;
const ZOOMED_EYE = vec3.scaleAndAdd(
[],
EYE,
vec3.normalize([], vec3.sub([], TARGET, EYE)),
DOLLY,
);

const container = new Container();
container.camera.transform = Transform.targetTo(EYE, TARGET);
Expand Down Expand Up @@ -74,24 +68,34 @@ const MON_FRONT = MON_BACK + 8;
const BEZEL_Y = DESK_TOP + 30;
const SCREEN_Y = BEZEL_Y + BEZEL + SCREEN_H / 2;

// The views this page can reach, so a face turned away from all of them skips the DOM
// The views this page can reach
const POSES = {
home: [EYE, TARGET],
zoomed: [ZOOMED_EYE, TARGET],
drawer: [
[110, 470, 330],
[130, 30, -230],
],
// Far enough back that the full dolly still stops short of the screen
screen: [
[MON_X, SCREEN_Y + 15, MON_FRONT + 287],
[MON_X, SCREEN_Y + 15, MON_FRONT + 440],
[MON_X, SCREEN_Y, MON_FRONT - 33],
],
door: [
[-80, 300, 620],
[190, 110, 0],
],
};
const POSE_EYES = Object.values(POSES).map(([eye]) => eye);
// Scrolling moves each eye DOLLY closer. A face turned away from every eye, near and far,
// skips the DOM
const POSE_EYES = Object.values(POSES).flatMap(([eye, target]) => [
eye,
vec3.scaleAndAdd(
[],
eye,
vec3.normalize([], vec3.sub([], target, eye)),
DOLLY,
),
]);
// A box that never moves can drop the faces no pose sees
const solid = (lo, hi, color) => {
for (const pts of Object.values(boxFaces(lo, hi)))
Expand Down Expand Up @@ -133,7 +137,7 @@ solid(
[W, DOOR_H + CASE, DOOR_Z1 + CASE],
RIM,
);
// The reveal runs through the wall's thickness, faces only: a box would show through in Firefox
// The reveal runs through the wall's thickness
const REVEAL = "#d9cfba";
quad(root, "+z", [W, 0, DOOR_Z0], [W + T, DOOR_H, DOOR_Z0], REVEAL);
quad(root, "-z", [W, 0, DOOR_Z1], [W + T, DOOR_H, DOOR_Z1], REVEAL);
Expand Down Expand Up @@ -374,12 +378,13 @@ const addDrawer = (id, label, content, furnish) => {
const drawer = new Group();
drawer.domElement.classList.add("slide", `s-${id}`);
at.addChild(drawer);
// In two, split where the note stands: Firefox paints a floor crossing its plane over it
for (const [z0, z1] of [
[CAB_FRONT - NOTE_Z, CAB_FRONT],
[back, CAB_FRONT - NOTE_Z],
])
quad(drawer, "+y", [DRAWER_X0, y0, z0], [DRAWER_X1, y0, z1], "#5d3f28");
quad(
drawer,
"+y",
[DRAWER_X0, y0, back],
[DRAWER_X1, y0, CAB_FRONT],
"#5d3f28",
);
const SIDE = "#7c5635";
quad(
drawer,
Expand Down Expand Up @@ -454,10 +459,13 @@ sticky.setAttribute("aria-label", "A sticky note asks where the code went");
place(root, sticky, Transform.translate([-10, 310, -D + 1]), 0.9);

const camera = (sel, [eye, target]) =>
`${sel} .c3r-container>.c3r-view{${cameraView(eye, target)};animation:none}`;
`${sel} .c3r-container>.c3r-view{${cameraView(eye, target)}}`;
const scene = await container.toHTML();
// Values from the scene, the rest is in style.css
const css = `:root{--dolly:${DOLLY * container.unitScale}px;--note-z:${NOTE_Z}px}
// Values from the scene, the rest is in style.css. The dolly is outside transform, so it moves
// along the view axis of every pose and the pose transitions leave it alone. Its length is
// written out because Firefox steps a var() keyframe, in pixels as the scene inside is unit-scaled
const css = `@keyframes dolly{to{translate:0 0 ${DOLLY * container.unitScale}px}}
:root{--note-z:${NOTE_Z}px}
${camera("html:has(details[open])", POSES.drawer)}
${camera("html:has(#code:focus)", POSES.screen)}
${camera("html:has(#code:valid)", POSES.door)}
Expand Down
6 changes: 0 additions & 6 deletions examples/public/demos/find-code/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ body {
.c3r-view {
transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Outside transform, so it dollies along the view axis. The close-up poses turn it off. Lengths out here are in pixels, the scene inside is unit-scaled */
@keyframes dolly {
to {
translate: 0 0 var(--dolly);
}
}
/* Without the guard an unsupporting browser fills to the last keyframe and stays zoomed */
@supports (animation-timeline: scroll()) {
.c3r-view {
Expand Down
9 changes: 6 additions & 3 deletions examples/public/demos/fog-of-history/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "../../../demos.mjs";

const HERE = import.meta.dirname;
const { Container, Group, Transform } = await happyC3R();
const { Container, Group, Timeline, Transform, Tween } = await happyC3R();
const items = load(path.join(HERE, "hextris.json"));
const tiles = load(path.join(HERE, "hexmeta.json"));
const LIGHT = { ambient: 0.62, intensity: 0.62, direction: [-0.5, -1, -0.45] };
Expand Down Expand Up @@ -120,6 +120,10 @@ const unhidden = (tris) => {

const container = new Container();
container.camera.transform = Transform.targetTo(EYE, FOCUS);
container.camera.tween = new Tween({
keyframes: [Transform.translate([0, 0, -DOLLY])],
timeline: new Timeline({ scroll: true }),
});

const pan = new Group();
pan.domElement.classList.add("pan");
Expand Down Expand Up @@ -172,7 +176,6 @@ const pans = tiles.map((tile) => {
return `html:has(#t${tile.tag}:target) .pan{transform:translate3d(${(-x).toFixed(1)}px,0,${(-z).toFixed(1)}px)}`;
});
const scene = await container.toHTML();
const css = `:root{--dolly:${DOLLY * container.unitScale}px}
@media (orientation:portrait){.c3r-container.c3r-container>.c3r-view{${cameraView(PORTRAIT_EYE, FOCUS)}}}
const css = `@media (orientation:portrait){.c3r-container.c3r-container>.c3r-view{${cameraView(PORTRAIT_EYE, FOCUS)}}}
${pans.join("\n")}`;
writePage(HERE, { css, targets, scene });
13 changes: 0 additions & 13 deletions examples/public/demos/fog-of-history/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ body {
margin: 0;
height: 300vh;
}
/* Outside transform, so it dollies along the view axis. Lengths out here are in pixels, the scene inside is unit-scaled */
@keyframes dolly {
to {
translate: 0 0 var(--dolly);
}
}
/* Without the guard an unsupporting browser fills to the last keyframe and stays zoomed */
@supports (animation-timeline: scroll()) {
.c3r-view {
animation: dolly linear both;
animation-timeline: scroll(root);
}
}
.c3r-container.c3r-container {
position: fixed;
inset: 0;
Expand Down
13 changes: 11 additions & 2 deletions examples/public/demos/globe-gores/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { join } from "node:path";
import { happyC3R, load, writePage } from "../../../demos.mjs";

const HERE = import.meta.dirname;
const { Container, Group, Material, Transform, Tween, ElementObject } =
await happyC3R();
const {
Container,
Group,
Material,
Timeline,
Transform,
Tween,
ElementObject,
} = await happyC3R();
const { rotateX, rotateY, rotateZ, translate } = Transform;
const { gores, tex, scale, full, crop } = load(join(HERE, "gores.json"));
const [TW, TH] = tex;
Expand Down Expand Up @@ -93,6 +100,7 @@ const HOLD = 7;
const FOLD = 43;
const TURN = 42;
const REST = 8;
const page = new Timeline({ scroll: true });
const phase = (rest, moved, before, during, after) =>
new Tween({
from: rest,
Expand All @@ -102,6 +110,7 @@ const phase = (rest, moved, before, during, after) =>
{ steps: moved, duration: after },
],
easing: "ease-in-out",
timeline: page,
});
const fold = (flat, folded) => phase(flat, folded, HOLD, FOLD, TURN + REST);

Expand Down
4 changes: 0 additions & 4 deletions examples/public/demos/globe-gores/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ html .c3r-container {
html .label {
backface-visibility: hidden;
}
.c3r-group[style*="animation"],
.c3r-view {
animation-timeline: scroll(root) !important;
}
.label {
display: block;
background: none;
Expand Down
4 changes: 4 additions & 0 deletions examples/public/demos/light-shafts/index.eta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% layout("@layout", { title: "Light Shafts" }) %>
<%~ it.scene %>
<div class="lens"></div>
<header><h1>Light Shafts</h1><p>Scroll to walk down the nave. The sunbeams, haze and dust are gradients on flat planes.</p></header>
Loading
Loading