feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -0,0 +1,82 @@
|
||||
export type ModelVariant = "classic" | "chunky" | "rounded" | "metal" | "full";
|
||||
export type MaterialPreset = "red" | "matte" | "glossy" | "metal" | "chrome" | "plastic" | "glass";
|
||||
export type RotationAxis = "x" | "y" | "z" | "free";
|
||||
export type ClawMode = "synchronized" | "alternating" | "offset";
|
||||
|
||||
export interface LabConfig {
|
||||
variant: ModelVariant;
|
||||
material: MaterialPreset;
|
||||
depth: number;
|
||||
bevel: number;
|
||||
wireframe: boolean;
|
||||
paused: boolean;
|
||||
autoRotate: boolean;
|
||||
rotationSpeed: number;
|
||||
rotationAxis: RotationAxis;
|
||||
idleFloat: boolean;
|
||||
idleBody: boolean;
|
||||
idleSpeed: number;
|
||||
idleStrength: number;
|
||||
claws: boolean;
|
||||
leftClaw: boolean;
|
||||
rightClaw: boolean;
|
||||
clawMode: ClawMode;
|
||||
clawSpeed: number;
|
||||
clawStrength: number;
|
||||
clawFrequency: number;
|
||||
antennae: boolean;
|
||||
leftAntenna: boolean;
|
||||
rightAntenna: boolean;
|
||||
antennaSpeed: number;
|
||||
antennaStrength: number;
|
||||
secondaryMotion: boolean;
|
||||
eyes: boolean;
|
||||
bodyPulse: boolean;
|
||||
axes: boolean;
|
||||
bounds: boolean;
|
||||
pivots: boolean;
|
||||
ground: boolean;
|
||||
keyLight: number;
|
||||
fillLight: number;
|
||||
rimLight: number;
|
||||
fov: number;
|
||||
}
|
||||
|
||||
export const initialConfig: LabConfig = {
|
||||
variant: "classic",
|
||||
material: "red",
|
||||
depth: 0.48,
|
||||
bevel: 0.08,
|
||||
wireframe: false,
|
||||
paused: false,
|
||||
autoRotate: true,
|
||||
rotationSpeed: 0.32,
|
||||
rotationAxis: "y",
|
||||
idleFloat: true,
|
||||
idleBody: false,
|
||||
idleSpeed: 0.8,
|
||||
idleStrength: 0.08,
|
||||
claws: true,
|
||||
leftClaw: true,
|
||||
rightClaw: true,
|
||||
clawMode: "offset",
|
||||
clawSpeed: 1,
|
||||
clawStrength: 0.18,
|
||||
clawFrequency: 0.7,
|
||||
antennae: true,
|
||||
leftAntenna: true,
|
||||
rightAntenna: true,
|
||||
antennaSpeed: 0.75,
|
||||
antennaStrength: 0.1,
|
||||
secondaryMotion: true,
|
||||
eyes: false,
|
||||
bodyPulse: false,
|
||||
axes: false,
|
||||
bounds: false,
|
||||
pivots: false,
|
||||
ground: true,
|
||||
keyLight: 7,
|
||||
fillLight: 3,
|
||||
rimLight: 5,
|
||||
fov: 34,
|
||||
};
|
||||
@@ -0,0 +1,359 @@
|
||||
// Deterministic Homarr lobster rig, adapted from the feat/3d-logo-lab branch.
|
||||
// Every pose is derived from the state passed to render(), never from a clock.
|
||||
import * as THREE from "three";
|
||||
import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
|
||||
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
||||
import { initialConfig } from "./lab-types";
|
||||
import { animateWordmarkRig, buildWordmarkRig, defaultWordmarkMotion, type WordmarkRig } from "./wordmark-rig";
|
||||
|
||||
type Side = -1 | 1;
|
||||
type JointKind = "claw" | "antenna";
|
||||
|
||||
interface JointChain {
|
||||
mesh: THREE.SkinnedMesh;
|
||||
shoulder: THREE.Bone;
|
||||
middle: THREE.Bone;
|
||||
tip: THREE.Bone;
|
||||
side: Side;
|
||||
}
|
||||
|
||||
const lobsterParts = [
|
||||
"left-antenna",
|
||||
"right-antenna",
|
||||
"body",
|
||||
"left-eye",
|
||||
"right-eye",
|
||||
"right-claw",
|
||||
"left-claw",
|
||||
] as const;
|
||||
|
||||
function smoothstep(a: number, b: number, v: number) {
|
||||
const t = THREE.MathUtils.clamp((v - a) / (b - a), 0, 1);
|
||||
return t * t * (3 - 2 * t);
|
||||
}
|
||||
|
||||
function makeJointedPart(
|
||||
geometry: THREE.ExtrudeGeometry,
|
||||
material: THREE.Material,
|
||||
center: THREE.Vector3,
|
||||
kind: JointKind,
|
||||
side: Side,
|
||||
): JointChain {
|
||||
const mesh = new THREE.SkinnedMesh(geometry, material);
|
||||
mesh.frustumCulled = false;
|
||||
const joints: [number, number][] =
|
||||
kind === "claw"
|
||||
? [
|
||||
[134, 335],
|
||||
[95, 270],
|
||||
[65, 180],
|
||||
]
|
||||
: [
|
||||
[227, 226],
|
||||
[185, 165],
|
||||
[169, 105],
|
||||
];
|
||||
const at = ([x, y]: [number, number]) => new THREE.Vector3((side === -1 ? x : 512 - x) - center.x, y - center.y, 0);
|
||||
const [a, b, c] = joints.map(at) as [THREE.Vector3, THREE.Vector3, THREE.Vector3];
|
||||
const shoulder = new THREE.Bone();
|
||||
shoulder.position.copy(a);
|
||||
const middle = new THREE.Bone();
|
||||
middle.position.copy(b).sub(a);
|
||||
const tip = new THREE.Bone();
|
||||
tip.position.copy(c).sub(b);
|
||||
shoulder.add(middle);
|
||||
middle.add(tip);
|
||||
mesh.add(shoulder);
|
||||
|
||||
const positions = geometry.getAttribute("position");
|
||||
const skinIndices: number[] = [];
|
||||
const skinWeights: number[] = [];
|
||||
const baseY = kind === "claw" ? 370 : 230;
|
||||
const topY = kind === "claw" ? 113 : 83;
|
||||
for (let i = 0; i < positions.count; i++) {
|
||||
const p = THREE.MathUtils.clamp((baseY - (center.y + positions.getY(i))) / (baseY - topY), 0, 1);
|
||||
const mw = smoothstep(0.08, 0.48, p);
|
||||
const tw = smoothstep(0.42, 0.9, p);
|
||||
skinIndices.push(0, 1, 2, 0);
|
||||
skinWeights.push(1 - mw, mw * (1 - tw), mw * tw, 0);
|
||||
}
|
||||
geometry.setAttribute("skinIndex", new THREE.Uint16BufferAttribute(skinIndices, 4));
|
||||
geometry.setAttribute("skinWeight", new THREE.Float32BufferAttribute(skinWeights, 4));
|
||||
mesh.bind(new THREE.Skeleton([shoulder, middle, tip]));
|
||||
return { mesh, shoulder, middle, tip, side };
|
||||
}
|
||||
|
||||
export interface LogoState {
|
||||
visible: boolean;
|
||||
x: number; // world units
|
||||
y: number;
|
||||
z: number;
|
||||
scale: number;
|
||||
rx: number; // radians
|
||||
ry: number;
|
||||
rz: number;
|
||||
clawL: number; // 0 open → 1 closed
|
||||
clawR: number;
|
||||
antenna: number; // phase in radians
|
||||
antennaAmp: number;
|
||||
antennaLift: number; // radians, positive perks both antennae upright
|
||||
waveL: number; // radians around the claw's shoulder, positive raises it outward
|
||||
waveR: number;
|
||||
blinkL: number; // 0 open → 1 shut
|
||||
blinkR: number;
|
||||
explode: number; // 0 → parts fly apart
|
||||
camZ: number;
|
||||
sparks: number; // 0..1 burst progress, <0 disabled
|
||||
dust: number; // opacity of dust field
|
||||
t: number;
|
||||
/** Extruded wordmark plaque, posed independently of the lobster (world units, radians). */
|
||||
wm: { on: boolean; x: number; y: number; scale: number; rx: number; ry: number };
|
||||
}
|
||||
|
||||
export const defaultLogoState = (): LogoState => ({
|
||||
visible: false,
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
scale: 1,
|
||||
rx: 0,
|
||||
ry: 0,
|
||||
rz: 0,
|
||||
clawL: 0,
|
||||
clawR: 0,
|
||||
antenna: 0,
|
||||
antennaAmp: 0.1,
|
||||
antennaLift: 0,
|
||||
waveL: 0,
|
||||
waveR: 0,
|
||||
blinkL: 0,
|
||||
blinkR: 0,
|
||||
explode: 0,
|
||||
camZ: 12,
|
||||
sparks: -1,
|
||||
dust: 0,
|
||||
t: 0,
|
||||
wm: { on: false, x: 0, y: 0, scale: 1, rx: 0, ry: 0 },
|
||||
});
|
||||
|
||||
export class LogoGL {
|
||||
renderer: THREE.WebGLRenderer;
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(30, 16 / 9, 0.05, 200);
|
||||
root = new THREE.Group();
|
||||
model = new THREE.Group();
|
||||
claws: JointChain[] = [];
|
||||
antennae: JointChain[] = [];
|
||||
parts: THREE.Mesh[] = [];
|
||||
eyes: { mesh: THREE.Mesh; side: Side }[] = [];
|
||||
sparks: THREE.Points;
|
||||
sparkSeeds: Float32Array;
|
||||
dust: THREE.Points;
|
||||
wordmark: WordmarkRig;
|
||||
wmRoot = new THREE.Group();
|
||||
|
||||
constructor(canvas: HTMLCanvasElement, svg: string, wordmarkSvg: string) {
|
||||
this.renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, preserveDrawingBuffer: true });
|
||||
this.renderer.setPixelRatio(1);
|
||||
this.renderer.setSize(1920, 1080, false);
|
||||
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
|
||||
this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
this.renderer.toneMappingExposure = 0.92;
|
||||
this.renderer.setClearColor(0x000000, 0);
|
||||
|
||||
const pmrem = new THREE.PMREMGenerator(this.renderer);
|
||||
this.scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
|
||||
this.scene.environmentIntensity = 0.35;
|
||||
|
||||
const key = new THREE.DirectionalLight(0xfff0ea, 2.4);
|
||||
key.position.set(-5, 7, 6);
|
||||
const fill = new THREE.DirectionalLight(0x6f8cff, 0.9);
|
||||
fill.position.set(7, -1, 4);
|
||||
const rim = new THREE.DirectionalLight(0xffc2ba, 3.4);
|
||||
rim.position.set(3, 4, -7);
|
||||
const rim2 = new THREE.DirectionalLight(0xff4a5a, 4);
|
||||
rim2.position.set(-6, -2, -5);
|
||||
this.scene.add(key, fill, rim, rim2, new THREE.HemisphereLight(0xffd8d4, 0x0b0b12, 0.25));
|
||||
this.scene.add(this.root);
|
||||
this.root.add(this.model);
|
||||
this.build(svg);
|
||||
this.wordmark = buildWordmarkRig(wordmarkSvg, initialConfig);
|
||||
this.wmRoot.add(this.wordmark.model);
|
||||
this.scene.add(this.wmRoot);
|
||||
|
||||
// Spark burst: 600 points on deterministic trajectories.
|
||||
const n = 600;
|
||||
this.sparkSeeds = new Float32Array(n * 4);
|
||||
for (let i = 0; i < n; i++) {
|
||||
const r = (k: number) => {
|
||||
const x = Math.sin((i * 4 + k) * 91.345 + 17.1) * 43758.5453;
|
||||
return x - Math.floor(x);
|
||||
};
|
||||
this.sparkSeeds.set([r(0), r(1), r(2), r(3)], i * 4);
|
||||
}
|
||||
const sg = new THREE.BufferGeometry();
|
||||
sg.setAttribute("position", new THREE.BufferAttribute(new Float32Array(n * 3), 3));
|
||||
this.sparks = new THREE.Points(
|
||||
sg,
|
||||
new THREE.PointsMaterial({
|
||||
color: 0xff7a70,
|
||||
size: 0.1,
|
||||
transparent: true,
|
||||
opacity: 1,
|
||||
blending: THREE.AdditiveBlending,
|
||||
depthWrite: false,
|
||||
}),
|
||||
);
|
||||
this.scene.add(this.sparks);
|
||||
|
||||
const dn = 1400;
|
||||
const dg = new THREE.BufferGeometry();
|
||||
const dp = new Float32Array(dn * 3);
|
||||
for (let i = 0; i < dn; i++) {
|
||||
const r = (k: number) => {
|
||||
const x = Math.sin((i * 3 + k) * 12.9898 + 78.233) * 43758.5453;
|
||||
return x - Math.floor(x);
|
||||
};
|
||||
dp.set([(r(0) - 0.5) * 40, (r(1) - 0.5) * 24, -r(2) * 40 + 4], i * 3);
|
||||
}
|
||||
dg.setAttribute("position", new THREE.BufferAttribute(dp, 3));
|
||||
this.dust = new THREE.Points(
|
||||
dg,
|
||||
new THREE.PointsMaterial({ color: 0xffb0a8, size: 0.035, transparent: true, opacity: 0, depthWrite: false }),
|
||||
);
|
||||
this.scene.add(this.dust);
|
||||
}
|
||||
|
||||
build(svg: string) {
|
||||
const parsed = new SVGLoader().parse(svg);
|
||||
const material = new THREE.MeshPhysicalMaterial({
|
||||
color: 0xf23b3f,
|
||||
metalness: 0.1,
|
||||
roughness: 0.34,
|
||||
clearcoat: 0.4,
|
||||
clearcoatRoughness: 0.22,
|
||||
sheen: 0.15,
|
||||
sheenColor: new THREE.Color(0xff9a90),
|
||||
side: THREE.DoubleSide,
|
||||
});
|
||||
let idx = 0;
|
||||
parsed.paths.forEach((path) => {
|
||||
SVGLoader.createShapes(path).forEach((shape) => {
|
||||
const geometry = new THREE.ExtrudeGeometry(shape, {
|
||||
depth: 0.5 * 54,
|
||||
bevelEnabled: true,
|
||||
bevelThickness: 0.1 * 20,
|
||||
bevelSize: 0.1 * 15,
|
||||
bevelSegments: 5,
|
||||
curveSegments: 14,
|
||||
});
|
||||
geometry.computeVertexNormals();
|
||||
geometry.computeBoundingBox();
|
||||
const c = geometry.boundingBox!.getCenter(new THREE.Vector3());
|
||||
geometry.translate(-c.x, -c.y, -c.z);
|
||||
const part = lobsterParts[idx];
|
||||
const side: Side = part?.startsWith("left") ? -1 : 1;
|
||||
let mesh: THREE.Mesh;
|
||||
if (part?.endsWith("claw") || part?.endsWith("antenna")) {
|
||||
const kind = part.endsWith("claw") ? "claw" : "antenna";
|
||||
const chain = makeJointedPart(geometry, material, c, kind, side);
|
||||
mesh = chain.mesh;
|
||||
(kind === "claw" ? this.claws : this.antennae).push(chain);
|
||||
} else {
|
||||
mesh = new THREE.Mesh(geometry, material);
|
||||
if (part?.endsWith("eye")) this.eyes.push({ mesh, side });
|
||||
}
|
||||
mesh.position.copy(c);
|
||||
mesh.name = part ?? `part-${idx}`;
|
||||
idx++;
|
||||
this.parts.push(mesh);
|
||||
this.model.add(mesh);
|
||||
});
|
||||
});
|
||||
const box = new THREE.Box3().setFromObject(this.model);
|
||||
const center = box.getCenter(new THREE.Vector3());
|
||||
this.model.children.forEach((child) => {
|
||||
child.position.sub(center);
|
||||
child.userData.home = child.position.clone();
|
||||
});
|
||||
const size = new THREE.Box3().setFromObject(this.model).getSize(new THREE.Vector3());
|
||||
const s = 5.15 / Math.max(size.x, size.y);
|
||||
this.model.scale.set(s, -s, s);
|
||||
}
|
||||
|
||||
render(st: LogoState) {
|
||||
this.camera.position.set(0, 0, st.camZ);
|
||||
this.camera.lookAt(0, 0, 0);
|
||||
this.camera.updateProjectionMatrix();
|
||||
this.model.visible = st.visible;
|
||||
this.root.position.set(st.x, st.y, st.z);
|
||||
this.root.rotation.set(st.rx, st.ry, st.rz);
|
||||
this.root.scale.setScalar(st.scale);
|
||||
|
||||
for (const chain of this.claws) {
|
||||
const closure = (chain.side === -1 ? st.clawL : st.clawR) * 0.2;
|
||||
chain.middle.rotation.z = -chain.side * closure * 2.1;
|
||||
chain.tip.rotation.z = -chain.side * closure;
|
||||
chain.shoulder.rotation.z = chain.side * (chain.side === -1 ? st.waveL : st.waveR);
|
||||
}
|
||||
for (const chain of this.antennae) {
|
||||
const ph = st.antenna + (chain.side === 1 ? 0.55 : 0);
|
||||
chain.middle.rotation.z = Math.sin(ph) * st.antennaAmp * 0.7;
|
||||
chain.tip.rotation.z = Math.sin(ph - 0.85) * st.antennaAmp * 1.25;
|
||||
chain.middle.rotation.x = Math.sin(ph * 0.72) * st.antennaAmp * 0.2;
|
||||
chain.tip.rotation.x = Math.sin(ph * 0.72 - 0.65) * st.antennaAmp * 0.45;
|
||||
chain.shoulder.rotation.z = -chain.side * st.antennaLift;
|
||||
}
|
||||
this.model.children.forEach((child, i) => {
|
||||
const home = child.userData.home as THREE.Vector3;
|
||||
if (st.explode > 0) {
|
||||
const dir = home
|
||||
.clone()
|
||||
.setZ(i % 2 ? 60 : -60)
|
||||
.normalize();
|
||||
child.position.copy(home).add(dir.multiplyScalar(st.explode * (120 + (i % 3) * 40)));
|
||||
child.rotation.set(
|
||||
st.explode * (i % 2 ? 0.8 : -0.6),
|
||||
st.explode * ((i % 3) - 1) * 0.9,
|
||||
st.explode * 0.4 * (i - 3),
|
||||
);
|
||||
} else {
|
||||
child.position.copy(home);
|
||||
child.rotation.set(0, 0, 0);
|
||||
}
|
||||
});
|
||||
for (const { mesh, side } of this.eyes) mesh.scale.y = Math.max(0.08, 1 - (side === -1 ? st.blinkL : st.blinkR));
|
||||
|
||||
this.wmRoot.visible = st.wm.on;
|
||||
if (st.wm.on) {
|
||||
animateWordmarkRig(this.wordmark, st.t, 1 / 60, defaultWordmarkMotion, null);
|
||||
this.wmRoot.position.set(st.wm.x, st.wm.y, 0);
|
||||
this.wmRoot.rotation.set(st.wm.rx, st.wm.ry, 0);
|
||||
this.wmRoot.scale.setScalar(Math.max(1e-3, st.wm.scale));
|
||||
}
|
||||
|
||||
// Sparks: radial burst in the logo's plane with gravity and fade.
|
||||
const sp = this.sparks.geometry.getAttribute("position") as THREE.BufferAttribute;
|
||||
const mat = this.sparks.material as THREE.PointsMaterial;
|
||||
if (st.sparks >= 0 && st.sparks <= 1) {
|
||||
this.sparks.visible = true;
|
||||
const p = st.sparks;
|
||||
for (let i = 0; i < sp.count; i++) {
|
||||
const a = this.sparkSeeds[i * 4]! * Math.PI * 2;
|
||||
const sp0 = 2 + this.sparkSeeds[i * 4 + 1]! * 9;
|
||||
const zz = (this.sparkSeeds[i * 4 + 2]! - 0.5) * 6;
|
||||
const d = 1 - Math.exp(-p * 3.2);
|
||||
sp.setXYZ(i, st.x + Math.cos(a) * sp0 * d, st.y + Math.sin(a) * sp0 * d * 0.7 - p * p * 2.5, zz * d);
|
||||
}
|
||||
sp.needsUpdate = true;
|
||||
mat.opacity = Math.max(0, 1 - p) ** 1.5;
|
||||
} else this.sparks.visible = false;
|
||||
|
||||
const dm = this.dust.material as THREE.PointsMaterial;
|
||||
dm.opacity = st.dust;
|
||||
this.dust.visible = st.dust > 0.001;
|
||||
this.dust.position.set(Math.sin(st.t * 0.07) * 1.5, Math.cos(st.t * 0.05), (st.t * 0.6) % 8);
|
||||
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
import * as THREE from "three";
|
||||
import { SVGLoader } from "three/examples/jsm/loaders/SVGLoader.js";
|
||||
import type { LabConfig } from "./lab-types";
|
||||
|
||||
export interface WordmarkRig {
|
||||
model: THREE.Group;
|
||||
baseScale: number;
|
||||
frame: THREE.Group;
|
||||
spine: THREE.Group;
|
||||
cursor: THREE.Group;
|
||||
clickRays: THREE.Group;
|
||||
panels: THREE.Group[];
|
||||
letters: THREE.Group[];
|
||||
kana: THREE.Group[];
|
||||
arrowHead: THREE.Group;
|
||||
arrowSegments: THREE.Group[];
|
||||
arrowTip: THREE.Group;
|
||||
breathingOrder: THREE.Group[];
|
||||
hoverParts: THREE.Group[];
|
||||
hoverMeshes: THREE.Mesh[];
|
||||
beamParts: THREE.Group[];
|
||||
beamAnchors: number[];
|
||||
beamPath: THREE.CatmullRomCurve3;
|
||||
beamDots: THREE.Mesh[];
|
||||
}
|
||||
|
||||
export interface WordmarkMotion {
|
||||
cursor: boolean;
|
||||
arrow: boolean;
|
||||
panels: boolean;
|
||||
letters: boolean;
|
||||
kana: boolean;
|
||||
beam: boolean;
|
||||
breathe: boolean;
|
||||
}
|
||||
|
||||
export const defaultWordmarkMotion: WordmarkMotion = {
|
||||
cursor: true,
|
||||
arrow: true,
|
||||
panels: true,
|
||||
letters: true,
|
||||
kana: true,
|
||||
beam: true,
|
||||
breathe: true,
|
||||
};
|
||||
|
||||
function home(part: THREE.Group) {
|
||||
return part.userData.home as THREE.Vector3;
|
||||
}
|
||||
|
||||
const beamColor = new THREE.Color(0xffe9c4);
|
||||
const hoverColor = new THREE.Color(0xffc1c1);
|
||||
|
||||
function tintPart(part: THREE.Group, color: THREE.Color, amount: number) {
|
||||
for (const child of part.children) {
|
||||
if (!(child instanceof THREE.Mesh)) continue;
|
||||
const face = Array.isArray(child.material) ? child.material[0] : child.material;
|
||||
if (!(face instanceof THREE.MeshBasicMaterial)) continue;
|
||||
face.color.copy(child.userData.baseFaceColor as THREE.Color).lerp(color, amount);
|
||||
}
|
||||
}
|
||||
|
||||
export function buildWordmarkRig(svg: string, config: LabConfig): WordmarkRig {
|
||||
const paths = new SVGLoader().parse(svg).paths;
|
||||
const model = new THREE.Group();
|
||||
model.name = "IllustratedWordmarkRig";
|
||||
const reverseArtwork = new THREE.Group();
|
||||
reverseArtwork.name = "StaticReverseArtwork";
|
||||
const parts = new Map<string, THREE.Group>();
|
||||
const plateDepth = config.depth * 60;
|
||||
|
||||
paths.forEach((path, pathIndex) => {
|
||||
const node = path.userData?.node as Element | undefined;
|
||||
const parent = node?.parentNode as Element | null | undefined;
|
||||
const partName = parent?.getAttribute("data-rig-part");
|
||||
if (!partName) throw new Error(`Wordmark contour ${pathIndex} has no rig part`);
|
||||
|
||||
let part = parts.get(partName);
|
||||
if (!part) {
|
||||
part = new THREE.Group();
|
||||
part.name = partName;
|
||||
parts.set(partName, part);
|
||||
}
|
||||
|
||||
let depth = 2.2;
|
||||
let back = 4 + pathIndex * 0.025;
|
||||
if (pathIndex === 0) {
|
||||
depth = plateDepth;
|
||||
back = -plateDepth;
|
||||
} else if (pathIndex === 1) {
|
||||
depth = 2.4;
|
||||
back = 0.25;
|
||||
} else if (partName === "arrow-spine") {
|
||||
depth = 2;
|
||||
back = 2.8 + pathIndex * 0.025;
|
||||
} else if (partName === "cursor" || partName === "click-rays") {
|
||||
depth = 3;
|
||||
back = 7 + pathIndex * 0.025;
|
||||
}
|
||||
|
||||
const face = new THREE.MeshBasicMaterial({
|
||||
color: path.color,
|
||||
side: THREE.DoubleSide,
|
||||
wireframe: config.wireframe,
|
||||
toneMapped: false,
|
||||
});
|
||||
const edgeColor = pathIndex === 0 ? new THREE.Color(0xf93232) : path.color.clone().multiplyScalar(0.58);
|
||||
const edge = new THREE.MeshStandardMaterial({
|
||||
color: edgeColor,
|
||||
metalness: 0.1,
|
||||
roughness: 0.58,
|
||||
side: THREE.DoubleSide,
|
||||
wireframe: config.wireframe,
|
||||
});
|
||||
|
||||
for (const shape of SVGLoader.createShapes(path)) {
|
||||
const geometry = new THREE.ExtrudeGeometry(shape, {
|
||||
depth,
|
||||
bevelEnabled: pathIndex === 0,
|
||||
bevelThickness: config.bevel * 8,
|
||||
bevelSize: config.bevel * 6,
|
||||
bevelSegments: 2,
|
||||
curveSegments: 10,
|
||||
});
|
||||
geometry.computeBoundingBox();
|
||||
const center = geometry.boundingBox?.getCenter(new THREE.Vector3()) ?? new THREE.Vector3();
|
||||
geometry.translate(-center.x, -center.y, -center.z);
|
||||
const mesh = new THREE.Mesh(geometry, [face, edge]);
|
||||
mesh.name = `${partName}-${pathIndex}`;
|
||||
mesh.position.set(center.x, center.y, center.z + back);
|
||||
mesh.renderOrder = pathIndex;
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
mesh.userData.baseFaceColor = path.color.clone();
|
||||
part.add(mesh);
|
||||
|
||||
if (pathIndex > 0) {
|
||||
// The reverse is painted too, so the lockup remains readable from
|
||||
// behind instead of becoming an unmarked white silhouette.
|
||||
const reverseGeometry = new THREE.ShapeGeometry(shape, 10);
|
||||
reverseGeometry.translate(-center.x, -center.y, 0);
|
||||
const reverse = new THREE.Mesh(reverseGeometry, face.clone());
|
||||
reverse.name = `${partName}-${pathIndex}-reverse`;
|
||||
reverse.position.set(center.x, center.y, -plateDepth - 0.5 - pathIndex * 0.025);
|
||||
reverse.renderOrder = pathIndex;
|
||||
// The rear print belongs to the plaque, not the articulated foreground.
|
||||
// Moving it with a letter would bury it inside the backing from behind.
|
||||
reverseArtwork.add(reverse);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const part of parts.values()) {
|
||||
const bounds = new THREE.Box3().setFromObject(part);
|
||||
const origin = bounds.getCenter(new THREE.Vector3());
|
||||
if (part.name === "cursor" || part.name === "click-rays") origin.set(1229, 287, origin.z);
|
||||
for (const child of part.children) child.position.sub(origin);
|
||||
part.position.copy(origin);
|
||||
model.add(part);
|
||||
}
|
||||
model.add(reverseArtwork);
|
||||
|
||||
const bounds = new THREE.Box3().setFromObject(model);
|
||||
const center = bounds.getCenter(new THREE.Vector3());
|
||||
const size = bounds.getSize(new THREE.Vector3());
|
||||
for (const part of parts.values()) {
|
||||
part.position.sub(center);
|
||||
part.userData.home = part.position.clone();
|
||||
}
|
||||
reverseArtwork.position.sub(center);
|
||||
const scale = 8.5 / Math.max(size.x, size.y);
|
||||
model.scale.set(scale, -scale, scale);
|
||||
|
||||
const getPart = (name: string) => {
|
||||
const part = parts.get(name);
|
||||
if (!part) throw new Error(`Missing wordmark rig part: ${name}`);
|
||||
return part;
|
||||
};
|
||||
|
||||
const frame = getPart("frame");
|
||||
const spine = getPart("arrow-spine");
|
||||
const cursor = getPart("cursor");
|
||||
const clickRays = getPart("click-rays");
|
||||
const panels = ["panel-left", "panel-center", "panel-right"].map(getPart);
|
||||
const letters = ["letter-h", "letter-o", "letter-m", "letter-a", "letter-r-one", "letter-r-two"].map(getPart);
|
||||
const kana = ["kana-ho", "kana-ma", "kana-dash", "kana-ru"].map(getPart);
|
||||
const arrowHead = getPart("arrow-head");
|
||||
const arrowSegments = [
|
||||
"arrow-segment-one",
|
||||
"arrow-segment-two",
|
||||
"arrow-segment-three",
|
||||
"arrow-segment-four",
|
||||
"arrow-segment-five",
|
||||
].map(getPart);
|
||||
const arrowTip = getPart("arrow-tip");
|
||||
const chain = [arrowTip, ...arrowSegments.toReversed(), arrowHead];
|
||||
const beamPoints = chain.map((part) => new THREE.Vector3(home(part).x, home(part).y, home(part).z + 17));
|
||||
const beamPath = new THREE.CatmullRomCurve3(beamPoints);
|
||||
let previous = beamPoints[0];
|
||||
if (!previous) throw new Error("Wordmark chain has no parts");
|
||||
let beamLength = 0;
|
||||
const beamDistances = [0];
|
||||
for (const point of beamPoints.slice(1)) {
|
||||
beamLength += point.distanceTo(previous);
|
||||
beamDistances.push(beamLength);
|
||||
previous = point;
|
||||
}
|
||||
if (beamLength === 0) throw new Error("Wordmark chain has no length");
|
||||
const beamAnchors = beamDistances.map((distance) => distance / beamLength);
|
||||
const beamDots = [
|
||||
{ radius: 10, opacity: 0.95 },
|
||||
{ radius: 22, opacity: 0.22 },
|
||||
{ radius: 7, opacity: 0.48 },
|
||||
{ radius: 5, opacity: 0.28 },
|
||||
].map(({ radius, opacity }) => {
|
||||
const dot = new THREE.Mesh(
|
||||
new THREE.SphereGeometry(radius, 12, 8),
|
||||
new THREE.MeshBasicMaterial({
|
||||
color: 0xffe7b5,
|
||||
transparent: true,
|
||||
opacity,
|
||||
depthWrite: false,
|
||||
toneMapped: false,
|
||||
}),
|
||||
);
|
||||
dot.visible = false;
|
||||
model.add(dot);
|
||||
return dot;
|
||||
});
|
||||
const breathingOrder = [frame, ...panels, cursor, clickRays, ...letters, ...kana, spine, ...chain];
|
||||
const hoverParts = [...panels, ...letters, ...kana, cursor, clickRays, ...chain];
|
||||
const hoverMeshes = hoverParts.flatMap((part) =>
|
||||
part.children.filter((child): child is THREE.Mesh => child instanceof THREE.Mesh),
|
||||
);
|
||||
|
||||
return {
|
||||
model,
|
||||
baseScale: scale,
|
||||
frame,
|
||||
spine,
|
||||
cursor,
|
||||
clickRays,
|
||||
panels,
|
||||
letters,
|
||||
kana,
|
||||
arrowHead,
|
||||
arrowSegments,
|
||||
arrowTip,
|
||||
breathingOrder,
|
||||
hoverParts,
|
||||
hoverMeshes,
|
||||
beamParts: chain,
|
||||
beamAnchors,
|
||||
beamPath,
|
||||
beamDots,
|
||||
};
|
||||
}
|
||||
|
||||
export function animateWordmarkRig(
|
||||
rig: WordmarkRig,
|
||||
time: number,
|
||||
delta: number,
|
||||
motion: WordmarkMotion,
|
||||
hoveredPart: string | null,
|
||||
) {
|
||||
const breathPeriod = rig.breathingOrder.length * 0.23 + 1.3;
|
||||
const breath = (index: number) => {
|
||||
if (!motion.breathe) return 0;
|
||||
const phase = (((time - index * 0.23) % breathPeriod) + breathPeriod) % breathPeriod;
|
||||
const distance = (phase - 0.24) / 0.3;
|
||||
return Math.exp(-(distance * distance));
|
||||
};
|
||||
rig.breathingOrder.forEach((part, index) => {
|
||||
part.position.copy(home(part));
|
||||
part.rotation.set(0, 0, 0);
|
||||
part.scale.setScalar(1);
|
||||
if (part === rig.frame) return;
|
||||
const pulse = breath(index);
|
||||
part.position.z += pulse * 9;
|
||||
part.scale.setScalar(1 + pulse * 0.05);
|
||||
});
|
||||
const plaqueScale = rig.baseScale * (1 + breath(0) * 0.006);
|
||||
rig.model.scale.set(plaqueScale, -plaqueScale, plaqueScale);
|
||||
|
||||
const blend = 1 - Math.exp(-delta * 14);
|
||||
const hover = (part: THREE.Group, target: number) => {
|
||||
const current = (part.userData.hoverLevel as number | undefined) ?? 0;
|
||||
const next = current + (target - current) * blend;
|
||||
part.userData.hoverLevel = next;
|
||||
return next;
|
||||
};
|
||||
|
||||
const activePanel = rig.panels.findIndex((part) => part.name === hoveredPart);
|
||||
rig.panels.forEach((part, index) => {
|
||||
let target = 0;
|
||||
if (motion.panels && activePanel >= 0) target = index === activePanel ? 1 : 0.12;
|
||||
const level = hover(part, target);
|
||||
part.position.y -= level * (12 + Math.sin(time * 7 + index) * 2);
|
||||
part.position.z += level * 46;
|
||||
part.rotation.y = level * (Math.sin(time * 7 + index) * 0.08);
|
||||
part.scale.multiplyScalar(1 + level * 0.13);
|
||||
tintPart(part, hoverColor, level * 0.42);
|
||||
});
|
||||
|
||||
const activeLetter = rig.letters.findIndex((part) => part.name === hoveredPart);
|
||||
rig.letters.forEach((part, index) => {
|
||||
let target = 0;
|
||||
if (motion.letters && activeLetter >= 0) {
|
||||
if (index === activeLetter) target = 1;
|
||||
else if (Math.abs(index - activeLetter) === 1) target = 0.18;
|
||||
}
|
||||
const level = hover(part, target);
|
||||
part.position.y -= level * 12;
|
||||
part.position.z += level * 55;
|
||||
part.rotation.y = Math.sin(time * 6 + index) * level * 0.05;
|
||||
part.scale.multiplyScalar(1 + level * 0.14);
|
||||
tintPart(part, hoverColor, level * 0.38);
|
||||
});
|
||||
|
||||
const activeKana = rig.kana.findIndex((part) => part.name === hoveredPart);
|
||||
rig.kana.forEach((part, index) => {
|
||||
let target = 0;
|
||||
if (motion.kana && activeKana >= 0) {
|
||||
if (index === activeKana) target = 1;
|
||||
else if (Math.abs(index - activeKana) === 1) target = 0.18;
|
||||
}
|
||||
const level = hover(part, target);
|
||||
part.position.y -= level * 10;
|
||||
part.position.z += level * 50;
|
||||
part.rotation.z = Math.sin(time * 7 + index) * level * 0.035;
|
||||
part.scale.multiplyScalar(1 + level * 0.16);
|
||||
tintPart(part, hoverColor, level * 0.42);
|
||||
});
|
||||
|
||||
const cursorHover = hover(rig.cursor, motion.cursor && hoveredPart === rig.cursor.name ? 1 : 0);
|
||||
const raysHover = hover(rig.clickRays, motion.cursor && hoveredPart === rig.clickRays.name ? 1 : 0);
|
||||
const click = motion.cursor ? ((1 + Math.cos(time * 3)) / 2) ** 10 : 0;
|
||||
rig.cursor.position.y += click * 13 - cursorHover * 8;
|
||||
rig.cursor.position.z += click * 18 + cursorHover * 30;
|
||||
rig.cursor.scale.multiplyScalar(1 - click * 0.12 + cursorHover * 0.14);
|
||||
rig.clickRays.position.z += click * 18 + raysHover * 26;
|
||||
rig.clickRays.scale.multiplyScalar(1 + click * 0.28 + raysHover * 0.24);
|
||||
|
||||
rig.arrowSegments.forEach((part, index) => {
|
||||
if (motion.arrow) {
|
||||
const wave = Math.sin(time * 1.35 - index * 0.48);
|
||||
part.position.y += wave * 8;
|
||||
part.position.z += Math.max(0, wave) * 12;
|
||||
part.rotation.z = wave * 0.02;
|
||||
}
|
||||
});
|
||||
if (motion.arrow) {
|
||||
rig.arrowHead.rotation.z = Math.sin(time * 1.35 + 0.4) * 0.018;
|
||||
rig.arrowTip.rotation.z = Math.sin(time * 1.35 - 2.9) * 0.018;
|
||||
}
|
||||
|
||||
const beamProgress = (time % 5.2) / 4.2;
|
||||
const beamActive = motion.beam && beamProgress <= 1;
|
||||
rig.beamDots.forEach((dot, index) => {
|
||||
const trail = index < 2 ? 0 : (index - 1) * 0.035;
|
||||
dot.visible = beamActive && beamProgress >= trail;
|
||||
if (dot.visible) rig.beamPath.getPointAt(beamProgress - trail, dot.position);
|
||||
});
|
||||
rig.beamParts.forEach((part, index) => {
|
||||
const center = rig.beamAnchors[index];
|
||||
if (center === undefined) return;
|
||||
const distance = (beamProgress - center) / 0.1;
|
||||
const light = beamActive ? Math.exp(-(distance * distance)) : 0;
|
||||
const level = hover(part, motion.arrow && hoveredPart === part.name ? 1 : 0);
|
||||
part.position.z += light * 9 + level * 24;
|
||||
part.scale.multiplyScalar(1 + light * 0.055 + level * 0.06);
|
||||
tintPart(part, beamColor, Math.min(1, light * 0.7 + level * 0.36));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user