@hackbuild/motion-views 0.1.0 → 0.1.2
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 +161 -85
- package/dist/avatar-drop.d.ts +4 -0
- package/dist/character-stage.d.ts +5 -1
- package/dist/clip-strip.d.ts +3 -0
- package/dist/clips.d.ts +2 -0
- package/dist/elements.d.ts +4 -0
- package/dist/gestures.d.ts +2 -0
- package/dist/gestures.js +1 -0
- package/dist/motion-views.iife.js +599 -1
- package/dist/stage.d.ts +104 -0
- package/dist/stage.js +256 -0
- package/dist/vanilla.d.ts +1 -0
- package/dist/vanilla.js +3 -1
- package/dist/words.d.ts +3 -0
- package/llms.md +581 -0
- package/package.json +7 -6
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,11 @@
|
|
|
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";
|
|
9
10
|
export * from "./elements.js";
|
|
11
|
+
export * from "./stage.js";
|
package/dist/words.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export interface RigFacts {
|
|
|
12
12
|
/** Load warnings from the avatar package, already in plain words. */
|
|
13
13
|
warnings?: readonly string[];
|
|
14
14
|
}
|
|
15
|
+
/** How a rig check line reads: fine, a limit, or a blocker. */
|
|
15
16
|
export type RigTone = "ok" | "warn" | "bad";
|
|
16
17
|
/** One line of the rig check: what works or what does not, and why. */
|
|
17
18
|
export interface RigLine {
|
|
18
19
|
tone: RigTone;
|
|
19
20
|
text: string;
|
|
20
21
|
}
|
|
22
|
+
/** The rig check: overall tone, a headline and the lines worst first. */
|
|
21
23
|
export interface RigCheck {
|
|
22
24
|
tone: RigTone;
|
|
23
25
|
/** The headline: "ready to act", "ready, with limits", "cannot act". */
|
|
@@ -28,6 +30,7 @@ export interface RigCheck {
|
|
|
28
30
|
export declare function rigCheck(f: RigFacts): RigCheck;
|
|
29
31
|
/** Bytes as "820 kb" or "12.4 mb". */
|
|
30
32
|
export declare function bytesWord(n: number): string;
|
|
33
|
+
/** The facts the size line reads: bytes, format, file and triangle counts. */
|
|
31
34
|
export interface SizeFacts {
|
|
32
35
|
/** Every file of the drop, model and textures. */
|
|
33
36
|
bytes: number;
|