@hackbuild/motion-views 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/character-stage.d.ts +9 -0
- package/dist/character-stage.js +38 -4
- package/dist/clip-pack.d.ts +21 -0
- package/dist/clip-pack.js +53 -0
- package/dist/gestures.d.ts +11 -1
- package/dist/gestures.js +86 -0
- package/dist/motion-views.iife.js +836 -65
- package/dist/stage.d.ts +104 -0
- package/dist/stage.js +256 -0
- package/dist/vanilla.d.ts +2 -0
- package/dist/vanilla.js +4 -1
- package/llms.md +124 -0
- package/package.json +1 -1
package/dist/stage.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Group, PerspectiveCamera, Scene, Vector3, WebGLRenderer, type Object3D } from "three";
|
|
2
|
+
/** Drag to turn the camera round `target`, wheel or pinch to move in and out. */
|
|
3
|
+
export interface StageOrbit {
|
|
4
|
+
/** The point the camera looks at and turns round. */
|
|
5
|
+
readonly target: Vector3;
|
|
6
|
+
/** Off, the pointer and update leave the camera alone (a page that drives it itself). */
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
/** Points the camera at the target while enabled; the stage calls it each frame. */
|
|
9
|
+
update(): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
/** A drag orbit on `el` for `camera`: horizontal drag turns, vertical drag tilts, the wheel moves in and out. */
|
|
13
|
+
export declare function stageOrbit(camera: PerspectiveCamera, el: HTMLElement): StageOrbit;
|
|
14
|
+
/** Frees the geometry and materials of every mesh under `root`. */
|
|
15
|
+
export declare function freeMeshes(root: Object3D): void;
|
|
16
|
+
/** A running stage: its scene, camera, renderer and orbit, and how to stop it. */
|
|
17
|
+
export interface ThreeStage {
|
|
18
|
+
scene: Scene;
|
|
19
|
+
camera: PerspectiveCamera;
|
|
20
|
+
renderer: WebGLRenderer;
|
|
21
|
+
/** The drag orbit; set `orbit.enabled = false` to drive the camera from the page. */
|
|
22
|
+
orbit: StageOrbit;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
}
|
|
25
|
+
/** Options of `threeStage`. */
|
|
26
|
+
export interface ThreeStageOptions {
|
|
27
|
+
/** A paper coloured ground plane, 40 m square. Default on. */
|
|
28
|
+
ground?: boolean;
|
|
29
|
+
/** Pass a renderer the page already made; the stage still sizes and frees it. */
|
|
30
|
+
renderer?: WebGLRenderer;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A stage lit in paper light that fills `host`: it sizes with the host,
|
|
34
|
+
* calls `tick(dt, t)` each frame (dt capped at 50 ms), draws, and on
|
|
35
|
+
* dispose stops the loop and frees the renderer, the orbit and every mesh.
|
|
36
|
+
*/
|
|
37
|
+
export declare function threeStage(host: HTMLElement, tick: (dt: number, t: number) => void, opts?: ThreeStageOptions): ThreeStage;
|
|
38
|
+
/** A running turntable: its stage, what it shows, and how to stop it. */
|
|
39
|
+
export interface MeshTurntable {
|
|
40
|
+
stage: ThreeStage;
|
|
41
|
+
/** Shows `o` in place of what was shown; the old one's meshes are freed. */
|
|
42
|
+
show(o: Object3D): void;
|
|
43
|
+
dispose(): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A turntable that fills `host`: hemisphere light, drag to turn, one
|
|
47
|
+
* object at a time, sized for a relief or a depth surface tens of units
|
|
48
|
+
* across (the camera starts 80 units out, looking down at 30 degrees).
|
|
49
|
+
*/
|
|
50
|
+
export declare function meshTurntable(host: HTMLElement, opts?: {
|
|
51
|
+
renderer?: WebGLRenderer;
|
|
52
|
+
}): MeshTurntable;
|
|
53
|
+
/** The bone names of `boxDog`, in the shape `@hackbuild/gait` reads (hips, spine, tail, four legs). */
|
|
54
|
+
export declare const BOX_DOG_BONES: {
|
|
55
|
+
readonly hips: "hips";
|
|
56
|
+
readonly spine: readonly ["spine2", "chest"];
|
|
57
|
+
readonly tail: readonly ["tail1", "tail3", "tail_03"];
|
|
58
|
+
readonly legs: {
|
|
59
|
+
readonly LF: {
|
|
60
|
+
readonly up: "frontUpr.L";
|
|
61
|
+
readonly mid: "frontLeg.L_03";
|
|
62
|
+
readonly end: "frontHorselink.L";
|
|
63
|
+
readonly toes: readonly ["frontToe.L"];
|
|
64
|
+
};
|
|
65
|
+
readonly RF: {
|
|
66
|
+
readonly up: "frontUpr.R";
|
|
67
|
+
readonly mid: "frontLeg.R_03";
|
|
68
|
+
readonly end: "frontHorselink.R";
|
|
69
|
+
readonly toes: readonly ["frontToe.R"];
|
|
70
|
+
};
|
|
71
|
+
readonly LH: {
|
|
72
|
+
readonly up: "rearUpr.L";
|
|
73
|
+
readonly mid: "rearLwr.L";
|
|
74
|
+
readonly end: "rearHorselink.L";
|
|
75
|
+
readonly toes: readonly ["rearFoot.L", "rearToe.L"];
|
|
76
|
+
};
|
|
77
|
+
readonly RH: {
|
|
78
|
+
readonly up: "rearUpr.R";
|
|
79
|
+
readonly mid: "rearLwr.R";
|
|
80
|
+
readonly end: "rearHorselink.R";
|
|
81
|
+
readonly toes: readonly ["rearFoot.R", "rearToe.R"];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A dog of bones and boxes facing +z, about 0.78 m nose to tail with the
|
|
87
|
+
* hips 0.38 m up; bone names are `BOX_DOG_BONES`. Each bone carries a box
|
|
88
|
+
* to its child, so the legs show what a gait does to them.
|
|
89
|
+
*/
|
|
90
|
+
export declare function boxDog(color?: string): Group;
|
|
91
|
+
/** Options of `walkBvh`. */
|
|
92
|
+
export interface WalkBvhOptions {
|
|
93
|
+
/** Loop length in seconds. Default 2.4. */
|
|
94
|
+
seconds?: number;
|
|
95
|
+
fps?: number;
|
|
96
|
+
/** Stride scale: 0.6 strolls, 1.5 marches. Default 1. */
|
|
97
|
+
swing?: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A two step walk loop as bvh text for a humanoid that is not ours: other
|
|
101
|
+
* bone names (Hips, LeftUpLeg, RightForeArm and so on), centimetres, arms
|
|
102
|
+
* down, ZXY channels. A retarget has real work to do on it.
|
|
103
|
+
*/
|
|
104
|
+
export declare function walkBvh(o?: WalkBvhOptions): string;
|
package/dist/stage.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// Small three.js stages for pages and examples: a lit stage that fills a
|
|
2
|
+
// host element and ticks, a turntable that shows one object at a time, a
|
|
3
|
+
// drag orbit both share, a dog of bones and boxes, and a walk written as
|
|
4
|
+
// bvh text for another rig. Everything is built in code; no model, clip or
|
|
5
|
+
// weight file. Each stage frees its renderer, geometry and materials on
|
|
6
|
+
// dispose.
|
|
7
|
+
import { AmbientLight, Bone, BoxGeometry, Color, DirectionalLight, Group, HemisphereLight, Mesh, MeshStandardMaterial, PerspectiveCamera, PlaneGeometry, Scene, Spherical, Vector3, WebGLRenderer, } from "three";
|
|
8
|
+
/** A drag orbit on `el` for `camera`: horizontal drag turns, vertical drag tilts, the wheel moves in and out. */
|
|
9
|
+
export function stageOrbit(camera, el) {
|
|
10
|
+
const target = new Vector3();
|
|
11
|
+
const s = new Spherical();
|
|
12
|
+
let drag = null;
|
|
13
|
+
const turn = (dTheta, dPhi, scale = 1) => {
|
|
14
|
+
s.setFromVector3(camera.position.clone().sub(target));
|
|
15
|
+
s.theta += dTheta;
|
|
16
|
+
s.phi = Math.min(Math.PI * 0.49, Math.max(0.08, s.phi + dPhi));
|
|
17
|
+
s.radius = Math.min(200, Math.max(0.3, s.radius * scale));
|
|
18
|
+
camera.position.setFromSpherical(s).add(target);
|
|
19
|
+
};
|
|
20
|
+
const down = (e) => {
|
|
21
|
+
if (!orbit.enabled)
|
|
22
|
+
return;
|
|
23
|
+
drag = { x: e.clientX, y: e.clientY, id: e.pointerId };
|
|
24
|
+
el.setPointerCapture?.(e.pointerId);
|
|
25
|
+
};
|
|
26
|
+
const move = (e) => {
|
|
27
|
+
if (!drag || e.pointerId !== drag.id || !orbit.enabled)
|
|
28
|
+
return;
|
|
29
|
+
turn(-(e.clientX - drag.x) * 0.008, -(e.clientY - drag.y) * 0.008);
|
|
30
|
+
drag.x = e.clientX;
|
|
31
|
+
drag.y = e.clientY;
|
|
32
|
+
};
|
|
33
|
+
const up = () => (drag = null);
|
|
34
|
+
const wheel = (e) => {
|
|
35
|
+
if (!orbit.enabled)
|
|
36
|
+
return;
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
turn(0, 0, Math.exp(e.deltaY * 0.001));
|
|
39
|
+
};
|
|
40
|
+
el.addEventListener("pointerdown", down);
|
|
41
|
+
el.addEventListener("pointermove", move);
|
|
42
|
+
el.addEventListener("pointerup", up);
|
|
43
|
+
el.addEventListener("pointercancel", up);
|
|
44
|
+
el.addEventListener("wheel", wheel, { passive: false });
|
|
45
|
+
const orbit = {
|
|
46
|
+
target,
|
|
47
|
+
enabled: true,
|
|
48
|
+
update: () => { if (orbit.enabled)
|
|
49
|
+
camera.lookAt(target); },
|
|
50
|
+
dispose() {
|
|
51
|
+
el.removeEventListener("pointerdown", down);
|
|
52
|
+
el.removeEventListener("pointermove", move);
|
|
53
|
+
el.removeEventListener("pointerup", up);
|
|
54
|
+
el.removeEventListener("pointercancel", up);
|
|
55
|
+
el.removeEventListener("wheel", wheel);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
return orbit;
|
|
59
|
+
}
|
|
60
|
+
/** Frees the geometry and materials of every mesh under `root`. */
|
|
61
|
+
export function freeMeshes(root) {
|
|
62
|
+
root.traverse((o) => {
|
|
63
|
+
if (o instanceof Mesh) {
|
|
64
|
+
o.geometry.dispose();
|
|
65
|
+
for (const m of [o.material].flat())
|
|
66
|
+
m.dispose();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A stage lit in paper light that fills `host`: it sizes with the host,
|
|
72
|
+
* calls `tick(dt, t)` each frame (dt capped at 50 ms), draws, and on
|
|
73
|
+
* dispose stops the loop and frees the renderer, the orbit and every mesh.
|
|
74
|
+
*/
|
|
75
|
+
export function threeStage(host, tick, opts = {}) {
|
|
76
|
+
const renderer = opts.renderer ?? new WebGLRenderer({ antialias: true });
|
|
77
|
+
renderer.setPixelRatio(Math.min(2, globalThis.devicePixelRatio || 1));
|
|
78
|
+
renderer.domElement.style.cssText = "display:block;width:100%;height:100%;touch-action:none";
|
|
79
|
+
host.append(renderer.domElement);
|
|
80
|
+
const scene = new Scene();
|
|
81
|
+
scene.background = new Color("#efe9db");
|
|
82
|
+
const camera = new PerspectiveCamera(40, 1, 0.05, 200);
|
|
83
|
+
camera.position.set(2.4, 1.6, 3.2);
|
|
84
|
+
const orbit = stageOrbit(camera, renderer.domElement);
|
|
85
|
+
orbit.target.set(0, 0.5, 0);
|
|
86
|
+
scene.add(new AmbientLight("#ffffff", 1.1));
|
|
87
|
+
const sun = new DirectionalLight("#ffffff", 1.6);
|
|
88
|
+
sun.position.set(3, 6, 4);
|
|
89
|
+
scene.add(sun);
|
|
90
|
+
if (opts.ground !== false) {
|
|
91
|
+
const g = new PlaneGeometry(40, 40);
|
|
92
|
+
g.rotateX(-Math.PI / 2);
|
|
93
|
+
scene.add(new Mesh(g, new MeshStandardMaterial({ color: "#d9d0bd", roughness: 1 })));
|
|
94
|
+
}
|
|
95
|
+
const fit = () => {
|
|
96
|
+
const w = Math.max(1, host.clientWidth);
|
|
97
|
+
const h = Math.max(1, host.clientHeight);
|
|
98
|
+
renderer.setSize(w, h, false);
|
|
99
|
+
camera.aspect = w / h;
|
|
100
|
+
camera.updateProjectionMatrix();
|
|
101
|
+
};
|
|
102
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(fit) : null;
|
|
103
|
+
ro?.observe(host);
|
|
104
|
+
fit();
|
|
105
|
+
let raf = 0;
|
|
106
|
+
let last = performance.now();
|
|
107
|
+
let t = 0;
|
|
108
|
+
const frame = (now) => {
|
|
109
|
+
const dt = Math.min(0.05, Math.max(0, (now - last) / 1000));
|
|
110
|
+
last = now;
|
|
111
|
+
t += dt;
|
|
112
|
+
tick(dt, t);
|
|
113
|
+
orbit.update();
|
|
114
|
+
renderer.render(scene, camera);
|
|
115
|
+
raf = requestAnimationFrame(frame);
|
|
116
|
+
};
|
|
117
|
+
raf = requestAnimationFrame(frame);
|
|
118
|
+
return {
|
|
119
|
+
scene, camera, renderer, orbit,
|
|
120
|
+
dispose() {
|
|
121
|
+
cancelAnimationFrame(raf);
|
|
122
|
+
ro?.disconnect();
|
|
123
|
+
orbit.dispose();
|
|
124
|
+
freeMeshes(scene);
|
|
125
|
+
renderer.dispose();
|
|
126
|
+
renderer.domElement.remove();
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A turntable that fills `host`: hemisphere light, drag to turn, one
|
|
132
|
+
* object at a time, sized for a relief or a depth surface tens of units
|
|
133
|
+
* across (the camera starts 80 units out, looking down at 30 degrees).
|
|
134
|
+
*/
|
|
135
|
+
export function meshTurntable(host, opts = {}) {
|
|
136
|
+
const renderer = opts.renderer ?? new WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
|
|
137
|
+
const stage = threeStage(host, () => { }, { ground: false, renderer });
|
|
138
|
+
stage.camera.position.set(0, -40, 70);
|
|
139
|
+
stage.camera.near = 0.1;
|
|
140
|
+
stage.camera.far = 1000;
|
|
141
|
+
stage.camera.updateProjectionMatrix();
|
|
142
|
+
stage.orbit.target.set(0, 0, 0);
|
|
143
|
+
stage.scene.add(new HemisphereLight(0xffffff, 0x8a8170, 1.2));
|
|
144
|
+
let shown = null;
|
|
145
|
+
return {
|
|
146
|
+
stage,
|
|
147
|
+
show(o) {
|
|
148
|
+
if (shown) {
|
|
149
|
+
stage.scene.remove(shown);
|
|
150
|
+
freeMeshes(shown);
|
|
151
|
+
}
|
|
152
|
+
shown = o;
|
|
153
|
+
stage.scene.add(o);
|
|
154
|
+
},
|
|
155
|
+
dispose: () => stage.dispose(),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/** The bone names of `boxDog`, in the shape `@hackbuild/gait` reads (hips, spine, tail, four legs). */
|
|
159
|
+
export const BOX_DOG_BONES = {
|
|
160
|
+
hips: "hips",
|
|
161
|
+
spine: ["spine2", "chest"],
|
|
162
|
+
tail: ["tail1", "tail3", "tail_03"],
|
|
163
|
+
legs: {
|
|
164
|
+
LF: { up: "frontUpr.L", mid: "frontLeg.L_03", end: "frontHorselink.L", toes: ["frontToe.L"] },
|
|
165
|
+
RF: { up: "frontUpr.R", mid: "frontLeg.R_03", end: "frontHorselink.R", toes: ["frontToe.R"] },
|
|
166
|
+
LH: { up: "rearUpr.L", mid: "rearLwr.L", end: "rearHorselink.L", toes: ["rearFoot.L", "rearToe.L"] },
|
|
167
|
+
RH: { up: "rearUpr.R", mid: "rearLwr.R", end: "rearHorselink.R", toes: ["rearFoot.R", "rearToe.R"] },
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* A dog of bones and boxes facing +z, about 0.78 m nose to tail with the
|
|
172
|
+
* hips 0.38 m up; bone names are `BOX_DOG_BONES`. Each bone carries a box
|
|
173
|
+
* to its child, so the legs show what a gait does to them.
|
|
174
|
+
*/
|
|
175
|
+
export function boxDog(color = "#c9a36b") {
|
|
176
|
+
const root = new Group();
|
|
177
|
+
const bone = (name, parent, p) => {
|
|
178
|
+
const b = new Bone();
|
|
179
|
+
b.name = name;
|
|
180
|
+
b.position.set(...p);
|
|
181
|
+
parent.add(b);
|
|
182
|
+
return b;
|
|
183
|
+
};
|
|
184
|
+
const hips = bone("hips", root, [0, 0.38, 0]);
|
|
185
|
+
const spine = bone("spine2", hips, [0, 0, 0.1]);
|
|
186
|
+
const chest = bone("chest", spine, [0, 0, 0.12]);
|
|
187
|
+
const head = bone("head", bone("neck1", chest, [0, 0.08, 0.05]), [0, 0.08, 0.06]);
|
|
188
|
+
for (const [s, x] of [["L", 0.09], ["R", -0.09]]) {
|
|
189
|
+
const fe = bone(`frontHorselink.${s}`, bone(`frontLeg.${s}_03`, bone(`frontUpr.${s}`, chest, [x, 0, 0]), [0, -0.18, -0.08]), [0, -0.16, 0.08]);
|
|
190
|
+
bone(`frontToe.${s}`, fe, [0, -0.02, 0.03]);
|
|
191
|
+
const re = bone(`rearHorselink.${s}`, bone(`rearLwr.${s}`, bone(`rearUpr.${s}`, hips, [x, 0, -0.2]), [0, -0.17, 0.07]), [0, -0.15, -0.08]);
|
|
192
|
+
bone(`rearToe.${s}`, bone(`rearFoot.${s}`, re, [0, -0.02, 0.01]), [0, -0.02, 0.03]);
|
|
193
|
+
}
|
|
194
|
+
bone("tail_03", bone("tail3", bone("tail1", hips, [0, 0.02, -0.25]), [0, 0, -0.08]), [0, 0, -0.08]);
|
|
195
|
+
const mat = new MeshStandardMaterial({ color, roughness: 0.7 });
|
|
196
|
+
const Z = new Vector3(0, 0, 1);
|
|
197
|
+
const parts = [];
|
|
198
|
+
root.traverse((o) => {
|
|
199
|
+
if (!(o instanceof Bone))
|
|
200
|
+
return;
|
|
201
|
+
for (const c of o.children) {
|
|
202
|
+
if (!(c instanceof Bone) || c.position.length() < 1e-4)
|
|
203
|
+
continue;
|
|
204
|
+
const thick = c.name === "spine2" || c.name === "chest" ? 0.17 : /Upr/.test(c.name) ? 0.07 : /tail/.test(c.name) ? 0.03 : 0.045;
|
|
205
|
+
const m = new Mesh(new BoxGeometry(thick, thick, c.position.length()), mat);
|
|
206
|
+
m.position.copy(c.position).multiplyScalar(0.5);
|
|
207
|
+
m.quaternion.setFromUnitVectors(Z, c.position.clone().normalize());
|
|
208
|
+
parts.push([o, m]);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
for (const [o, m] of parts)
|
|
212
|
+
o.add(m);
|
|
213
|
+
const skull = new Mesh(new BoxGeometry(0.11, 0.1, 0.18), mat);
|
|
214
|
+
skull.position.set(0, 0.02, 0.05);
|
|
215
|
+
head.add(skull);
|
|
216
|
+
return root;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A two step walk loop as bvh text for a humanoid that is not ours: other
|
|
220
|
+
* bone names (Hips, LeftUpLeg, RightForeArm and so on), centimetres, arms
|
|
221
|
+
* down, ZXY channels. A retarget has real work to do on it.
|
|
222
|
+
*/
|
|
223
|
+
export function walkBvh(o = {}) {
|
|
224
|
+
const { seconds = 2.4, fps = 30, swing = 1 } = o;
|
|
225
|
+
const J = [
|
|
226
|
+
["Hips", -1, [0, 0, 0]], ["Spine", 0, [0, 12, 0]], ["Spine1", 1, [0, 16, 0]], ["Neck", 2, [0, 26, 0]], ["Head", 3, [0, 11, 0]],
|
|
227
|
+
["LeftArm", 2, [18, 22, 0]], ["LeftForeArm", 5, [29, 0, 0]], ["LeftHand", 6, [26, 0, 0]],
|
|
228
|
+
["RightArm", 2, [-18, 22, 0]], ["RightForeArm", 8, [-29, 0, 0]], ["RightHand", 9, [-26, 0, 0]],
|
|
229
|
+
["LeftUpLeg", 0, [10, -6, 0]], ["LeftLeg", 11, [0, -47, 0]], ["LeftFoot", 12, [0, -45, 0]], ["LeftToeBase", 13, [0, -8, 14]],
|
|
230
|
+
["RightUpLeg", 0, [-10, -6, 0]], ["RightLeg", 15, [0, -47, 0]], ["RightFoot", 16, [0, -45, 0]], ["RightToeBase", 17, [0, -8, 14]],
|
|
231
|
+
];
|
|
232
|
+
const kids = (i) => J.map((j, k) => [j, k]).filter(([j]) => j[1] === i).map(([, k]) => k);
|
|
233
|
+
const order = [];
|
|
234
|
+
const write = (i, pad) => {
|
|
235
|
+
order.push(i);
|
|
236
|
+
const [name, parent, off] = J[i];
|
|
237
|
+
const ch = parent < 0 ? "CHANNELS 6 Xposition Yposition Zposition Zrotation Xrotation Yrotation" : "CHANNELS 3 Zrotation Xrotation Yrotation";
|
|
238
|
+
const c = kids(i);
|
|
239
|
+
const body = c.length ? c.map((k) => write(k, pad + " ")).join("") : `${pad} End Site\n${pad} {\n${pad} OFFSET 0 6 0\n${pad} }\n`;
|
|
240
|
+
return `${pad}${parent < 0 ? "ROOT" : "JOINT"} ${name}\n${pad}{\n${pad} OFFSET ${off.join(" ")}\n${pad} ${ch}\n${body}${pad}}\n`;
|
|
241
|
+
};
|
|
242
|
+
const tree = write(0, "");
|
|
243
|
+
const n = Math.round(seconds * fps);
|
|
244
|
+
const lines = [];
|
|
245
|
+
for (let f = 0; f < n; f++) {
|
|
246
|
+
const ph = (f / fps) * 2 * Math.PI * (1 / seconds) * 2;
|
|
247
|
+
const s = Math.sin(ph) * swing;
|
|
248
|
+
const rot = {
|
|
249
|
+
LeftUpLeg: [0, -28 * s, 0], RightUpLeg: [0, 28 * s, 0],
|
|
250
|
+
LeftLeg: [0, 45 * Math.max(0, Math.sin(ph + 1.4)) * swing, 0], RightLeg: [0, 45 * Math.max(0, Math.sin(ph + 1.4 + Math.PI)) * swing, 0],
|
|
251
|
+
LeftArm: [-70, 22 * s, 0], RightArm: [70, -22 * s, 0], LeftForeArm: [0, 0, -15], RightForeArm: [0, 0, 15],
|
|
252
|
+
};
|
|
253
|
+
lines.push(order.map((i) => (i === 0 ? [0, 106 + 2.5 * Math.cos(2 * ph), 0, 2 * s, 0, 3 * s] : rot[J[i][0]] ?? [0, 0, 0]).map((v) => v.toFixed(3)).join(" ")).join(" "));
|
|
254
|
+
}
|
|
255
|
+
return `HIERARCHY\n${tree}MOTION\nFrames: ${n}\nFrame Time: ${(1 / fps).toFixed(6)}\n${lines.join("\n")}\n`;
|
|
256
|
+
}
|
package/dist/vanilla.d.ts
CHANGED
package/dist/vanilla.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// @hackbuild/motion-views/vanilla: CharacterStage, AvatarDrop and ClipStrip
|
|
2
2
|
// as framework free views over hackbuild-ui classes, and as custom
|
|
3
|
-
// elements once defineMotionViews() runs
|
|
3
|
+
// elements once defineMotionViews() runs, and the small stages (threeStage,
|
|
4
|
+
// meshTurntable, boxDog, walkBvh). Importing defines nothing.
|
|
4
5
|
export * from "./index.js";
|
|
5
6
|
export * from "./character-stage.js";
|
|
6
7
|
export * from "./avatar-drop.js";
|
|
7
8
|
export * from "./clip-strip.js";
|
|
8
9
|
export * from "./gestures.js";
|
|
10
|
+
export * from "./clip-pack.js";
|
|
9
11
|
export * from "./elements.js";
|
|
12
|
+
export * from "./stage.js";
|
package/llms.md
CHANGED
|
@@ -319,6 +319,18 @@ interface AvatarReport {
|
|
|
319
319
|
|
|
320
320
|
What AvatarDrop learned about a dropped avatar: name, format, size, rig check, licence and still.
|
|
321
321
|
|
|
322
|
+
```ts
|
|
323
|
+
const BOX_DOG_BONES: { readonly hips: "hips"; readonly legs: { readonly LF: { readonly end: "frontHorselink.L"; readonly mid: "frontLeg.L_03"; readonly toes: readonly ["frontToe.L"]; readonly up: "frontUpr.L" }; readonly LH: { readonly end: "rearHorselink.L"; readonly mid: "rearLwr.L"; readonly toes: readonly ["rearFoot.L", "rearToe.L"]; readonly up: "rearUpr.L" }; readonly RF: { readonly end: "frontHorselink.R"; readonly mid: "frontLeg.R_03"; readonly toes: readonly ["frontToe.R"]; readonly up: "frontUpr.R" }; readonly RH: { readonly end: "rearHorselink.R"; readonly mid: "rearLwr.R"; readonly toes: readonly ["rearFoot.R", "rearToe.R"]; readonly up: "rearUpr.R" } }; readonly spine: readonly ["spine2", "chest"]; readonly tail: readonly ["tail1", "tail3", "tail_03"] }
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The bone names of `boxDog`, in the shape `@hackbuild/gait` reads (hips, spine, tail, four legs).
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
function boxDog(color?: string): Group
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
A dog of bones and boxes facing +z, about 0.78 m nose to tail with the hips 0.38 m up; bone names are `BOX_DOG_BONES`.
|
|
333
|
+
|
|
322
334
|
```ts
|
|
323
335
|
function characterStage(host: HTMLElement, opts?: CharacterStageOptions): CharacterStageHandle
|
|
324
336
|
```
|
|
@@ -371,6 +383,7 @@ interface CharacterStageOptions extends StageOptions {
|
|
|
371
383
|
background?: number | null;
|
|
372
384
|
body?: Omit<BodyOptions, "rng">;
|
|
373
385
|
canvas?: HTMLCanvasElement;
|
|
386
|
+
clips?: string | ClipPack;
|
|
374
387
|
drop?: boolean;
|
|
375
388
|
environment?: string | EnvironmentRequest;
|
|
376
389
|
follow?: FollowOptions;
|
|
@@ -380,6 +393,7 @@ interface CharacterStageOptions extends StageOptions {
|
|
|
380
393
|
maxPixelRatio?: number;
|
|
381
394
|
name?: string;
|
|
382
395
|
normalize?: NormalizeOptions;
|
|
396
|
+
plate?: boolean;
|
|
383
397
|
repair?: false | RepairOptions;
|
|
384
398
|
restoreButton?: boolean;
|
|
385
399
|
rng?: Rng;
|
|
@@ -392,6 +406,16 @@ interface CharacterStageOptions extends StageOptions {
|
|
|
392
406
|
|
|
393
407
|
Options of `characterStage`: stage options plus name, model URL, verbs, framing, drop and the hello speech.
|
|
394
408
|
|
|
409
|
+
```ts
|
|
410
|
+
interface ClipPack {
|
|
411
|
+
clips: Record<string, { dur: number; loop: boolean; n: number; p?: string; q: string }>;
|
|
412
|
+
fps: number;
|
|
413
|
+
roles: readonly string[];
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
The pack file: role names, frame rate and the clips.
|
|
418
|
+
|
|
395
419
|
```ts
|
|
396
420
|
function clipStrip(host: HTMLElement, opts?: ClipStripOptions): ClipStripHandle
|
|
397
421
|
```
|
|
@@ -459,6 +483,12 @@ type Framing = "bust" | "full"
|
|
|
459
483
|
|
|
460
484
|
The stage shot: bust, or the full body.
|
|
461
485
|
|
|
486
|
+
```ts
|
|
487
|
+
function freeMeshes(root: Object3D): void
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Frees the geometry and materials of every mesh under `root`.
|
|
491
|
+
|
|
462
492
|
```ts
|
|
463
493
|
type Gesture = "wave" | "nod" | "shake" | "bow"
|
|
464
494
|
```
|
|
@@ -477,6 +507,22 @@ const GESTURES: readonly Gesture[]
|
|
|
477
507
|
|
|
478
508
|
Every gesture `gestureClip` can make.
|
|
479
509
|
|
|
510
|
+
```ts
|
|
511
|
+
function meshTurntable(host: HTMLElement, opts?: { renderer?: WebGLRenderer }): MeshTurntable
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
A turntable that fills `host`: hemisphere light, drag to turn, one object at a time, sized for a relief or a depth surface tens of units across (the camera starts 80 units out, looking down at 30 degrees).
|
|
515
|
+
|
|
516
|
+
```ts
|
|
517
|
+
interface MeshTurntable {
|
|
518
|
+
stage: ThreeStage;
|
|
519
|
+
dispose(): void;
|
|
520
|
+
show(o: Object3D): void;
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
A running turntable: its stage, what it shows, and how to stop it.
|
|
525
|
+
|
|
480
526
|
```ts
|
|
481
527
|
interface MotionViewsOptions {
|
|
482
528
|
drop?: AvatarDropOptions;
|
|
@@ -486,6 +532,41 @@ interface MotionViewsOptions {
|
|
|
486
532
|
|
|
487
533
|
Options `defineMotionViews` shares with every element it defines.
|
|
488
534
|
|
|
535
|
+
```ts
|
|
536
|
+
function packClips(pack: ClipPack, names: readonly string[], base: ArrayLike<number>): Record<string, Clip>
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
The pack's clips as presence clips over `names` (the body's bone order).
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
function packCoverage(pack: ClipPack, names: readonly string[]): number
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
How many of the pack's roles land on one of `names`.
|
|
546
|
+
|
|
547
|
+
```ts
|
|
548
|
+
function rigGestureClip(id: Gesture, bones: readonly Object3D<Object3DEventMap>[], names: readonly string[], fps?: number): Clip | null
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
A gesture as a presence clip built on the rig itself: each bone is aimed or turned in world space, in the body's own frame (forward, left and up from its shoulders), then read back as local rotations.
|
|
552
|
+
|
|
553
|
+
```ts
|
|
554
|
+
function stageOrbit(camera: PerspectiveCamera, el: HTMLElement): StageOrbit
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
A drag orbit on `el` for `camera`: horizontal drag turns, vertical drag tilts, the wheel moves in and out.
|
|
558
|
+
|
|
559
|
+
```ts
|
|
560
|
+
interface StageOrbit {
|
|
561
|
+
enabled: boolean;
|
|
562
|
+
readonly target: Vector3;
|
|
563
|
+
dispose(): void;
|
|
564
|
+
update(): void;
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
Drag to turn the camera round `target`, wheel or pinch to move in and out.
|
|
569
|
+
|
|
489
570
|
```ts
|
|
490
571
|
interface StripItem extends ClipItem {
|
|
491
572
|
animation?: () => AnimationClip | Promise<AnimationClip>;
|
|
@@ -502,6 +583,33 @@ interface StripItem extends ClipItem {
|
|
|
502
583
|
|
|
503
584
|
A clip in the strip; `animation` lets the strip draw its still.
|
|
504
585
|
|
|
586
|
+
```ts
|
|
587
|
+
function threeStage(host: HTMLElement, tick: (dt: number, t: number) => void, opts?: ThreeStageOptions): ThreeStage
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
A stage lit in paper light that fills `host`: it sizes with the host, calls `tick(dt, t)` each frame (dt capped at 50 ms), draws, and on dispose stops the loop and frees the renderer, the orbit and every mesh.
|
|
591
|
+
|
|
592
|
+
```ts
|
|
593
|
+
interface ThreeStage {
|
|
594
|
+
camera: PerspectiveCamera;
|
|
595
|
+
orbit: StageOrbit;
|
|
596
|
+
renderer: WebGLRenderer;
|
|
597
|
+
scene: Scene;
|
|
598
|
+
dispose(): void;
|
|
599
|
+
}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
A running stage: its scene, camera, renderer and orbit, and how to stop it.
|
|
603
|
+
|
|
604
|
+
```ts
|
|
605
|
+
interface ThreeStageOptions {
|
|
606
|
+
ground?: boolean;
|
|
607
|
+
renderer?: WebGLRenderer;
|
|
608
|
+
}
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
Options of `threeStage`.
|
|
612
|
+
|
|
505
613
|
```ts
|
|
506
614
|
interface Verb {
|
|
507
615
|
go?: boolean;
|
|
@@ -512,6 +620,22 @@ interface Verb {
|
|
|
512
620
|
|
|
513
621
|
One verb on the stage.
|
|
514
622
|
|
|
623
|
+
```ts
|
|
624
|
+
function walkBvh(o?: WalkBvhOptions): string
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
A two step walk loop as bvh text for a humanoid that is not ours: other bone names (Hips, LeftUpLeg, RightForeArm and so on), centimetres, arms down, ZXY channels.
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
interface WalkBvhOptions {
|
|
631
|
+
fps?: number;
|
|
632
|
+
seconds?: number;
|
|
633
|
+
swing?: number;
|
|
634
|
+
}
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
Options of `walkBvh`.
|
|
638
|
+
|
|
515
639
|
### @hackbuild/motion-views/vue
|
|
516
640
|
|
|
517
641
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/motion-views",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "The motion views: CharacterStage, AvatarDrop and ClipStrip, binding the motion packages to hackbuild-ui, each as a Vue component and a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|