@7ots/cli 0.1.10 → 0.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@7ots/cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "7ots.com — your AI companion with a face of its own: a desktop pet that watches over your coding agent (Claude Code and shell hooks), a personal assistant (reminders, alerts, notes, opens sites, sees your screen if allowed) and a reproducible identity (face, personality, voice) for any agent — in apuchat meet calls, Orquesta projects or your own server.",
5
5
  "homepage": "https://7ots.com",
6
6
  "repository": {
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Música para los bailes y las entradas del ot, sintetizada en el momento con Web Audio.
3
+ *
4
+ * Nada de audio con derechos: cada estilo es un patrón propio de 16 pasos (bombo, caja, hats, bajo,
5
+ * acordes y una melodía) que suena al pulso de los bailes (DANCE_BPM), así un gesto de baile y su
6
+ * música, arrancados juntos, caen en los mismos tiempos.
7
+ * hype electrónica de cuatro en el piso funk bajo sincopado y guitarra rítmica
8
+ * chip 8 bits (cuadradas y triangular) trap 808 largo, hats con redobles
9
+ * entrance público que ruge, dos golpes con pirotecnia y un riff de rock (entradas tipo lucha libre)
10
+ *
11
+ * playBeat(style, { ms, volume }) → { stop(), done: Promise, analyser } (solo en el navegador).
12
+ */
13
+
14
+ import { DANCE_BPM } from './motion.js';
15
+
16
+ export const BEAT_STYLES = ['hype', 'funk', 'chip', 'trap', 'entrance'];
17
+
18
+ const hz = (m) => 440 * 2 ** ((m - 69) / 12);
19
+ let shared = null;
20
+ const noiseOf = (ctx) => {
21
+ if (ctx.__noise) return ctx.__noise;
22
+ const b = ctx.createBuffer(1, ctx.sampleRate, ctx.sampleRate);
23
+ const d = b.getChannelData(0);
24
+ let s = 7;
25
+ for (let i = 0; i < d.length; i++) d[i] = ((s = (s * 16807) % 2147483647) / 2147483647) * 2 - 1;
26
+ return (ctx.__noise = b);
27
+ };
28
+
29
+ // ── instrumentos: cada golpe crea sus nodos y se desconecta solo al terminar ──
30
+ function env(ctx, out, t, peak, a, d) {
31
+ const g = ctx.createGain();
32
+ g.gain.setValueAtTime(0.0001, t);
33
+ g.gain.exponentialRampToValueAtTime(Math.max(0.0002, peak), t + a);
34
+ g.gain.exponentialRampToValueAtTime(0.0001, t + a + d);
35
+ g.connect(out);
36
+ return g;
37
+ }
38
+ function osc(ctx, type, f, t, dur, dest) {
39
+ const o = ctx.createOscillator();
40
+ o.type = type;
41
+ o.frequency.setValueAtTime(f, t);
42
+ o.connect(dest);
43
+ o.start(t);
44
+ o.stop(t + dur + 0.05);
45
+ return o;
46
+ }
47
+ function noise(ctx, t, dur, dest) {
48
+ const n = ctx.createBufferSource();
49
+ n.buffer = noiseOf(ctx);
50
+ n.loop = true;
51
+ n.connect(dest);
52
+ n.start(t, Math.random() * 0.5);
53
+ n.stop(t + dur + 0.05);
54
+ return n;
55
+ }
56
+ function filt(ctx, type, f, q, dest) {
57
+ const b = ctx.createBiquadFilter();
58
+ b.type = type;
59
+ b.frequency.value = f;
60
+ b.Q.value = q;
61
+ b.connect(dest);
62
+ return b;
63
+ }
64
+ const I = {
65
+ kick(ctx, out, t, v = 1, low = 45) {
66
+ const g = env(ctx, out, t, 0.9 * v, 0.003, 0.32);
67
+ const o = osc(ctx, 'sine', 150, t, 0.4, g);
68
+ o.frequency.exponentialRampToValueAtTime(low, t + 0.12);
69
+ },
70
+ snare(ctx, out, t, v = 1) {
71
+ noise(ctx, t, 0.2, filt(ctx, 'bandpass', 1900, 0.8, env(ctx, out, t, 0.5 * v, 0.002, 0.18)));
72
+ osc(ctx, 'triangle', 190, t, 0.1, env(ctx, out, t, 0.25 * v, 0.002, 0.08));
73
+ },
74
+ clap(ctx, out, t, v = 1) {
75
+ for (let i = 0; i < 3; i++) noise(ctx, t + i * 0.011, 0.12, filt(ctx, 'bandpass', 1300, 1.2, env(ctx, out, t + i * 0.011, 0.35 * v, 0.001, i === 2 ? 0.16 : 0.02)));
76
+ },
77
+ hat(ctx, out, t, v = 1, open = false) {
78
+ noise(ctx, t, open ? 0.25 : 0.05, filt(ctx, 'highpass', 7500, 0.7, env(ctx, out, t, 0.16 * v, 0.001, open ? 0.2 : 0.035)));
79
+ },
80
+ bass(ctx, out, t, m, dur, v = 1, type = 'sawtooth') {
81
+ const lp = filt(ctx, 'lowpass', 420, 6, env(ctx, out, t, 0.32 * v, 0.005, dur));
82
+ lp.frequency.setValueAtTime(1400, t);
83
+ lp.frequency.exponentialRampToValueAtTime(260, t + dur);
84
+ osc(ctx, type, hz(m), t, dur, lp);
85
+ },
86
+ sub(ctx, out, t, m, dur, v = 1, from = null) {
87
+ const g = env(ctx, out, t, 0.55 * v, 0.004, dur);
88
+ const o = osc(ctx, 'sine', hz(from ?? m), t, dur, g);
89
+ if (from != null) o.frequency.exponentialRampToValueAtTime(hz(m), t + 0.09);
90
+ },
91
+ lead(ctx, out, t, m, dur, v = 1, type = 'square') {
92
+ const g = env(ctx, out, t, 0.11 * v, 0.004, dur);
93
+ osc(ctx, type, hz(m), t, dur, type === 'square' ? filt(ctx, 'lowpass', 3200, 0.5, g) : g);
94
+ },
95
+ chord(ctx, out, t, ms, dur, v = 1, type = 'sawtooth') {
96
+ const lp = filt(ctx, 'lowpass', 1500, 0.8, env(ctx, out, t, 0.07 * v, 0.02, dur));
97
+ for (const m of ms) for (const det of [-7, 7]) osc(ctx, type, hz(m), t, dur, lp).detune.value = det;
98
+ },
99
+ power(ctx, out, t, m, dur, v = 1) {
100
+ // acorde de quinta distorsionado (guitarra de rock)
101
+ const ws = ctx.createWaveShaper();
102
+ const c = new Float32Array(1024);
103
+ for (let i = 0; i < c.length; i++) {
104
+ const x = (i / c.length) * 2 - 1;
105
+ c[i] = Math.tanh(x * 6);
106
+ }
107
+ ws.curve = c;
108
+ ws.connect(filt(ctx, 'lowpass', 2600, 0.7, env(ctx, out, t, 0.12 * v, 0.004, dur)));
109
+ for (const k of [0, 7, 12]) osc(ctx, 'sawtooth', hz(m + k), t, dur, ws);
110
+ },
111
+ crowd(ctx, out, t, dur, v = 1) {
112
+ const g = ctx.createGain();
113
+ g.gain.setValueAtTime(0.0001, t);
114
+ g.gain.exponentialRampToValueAtTime(0.22 * v, t + dur * 0.4);
115
+ g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
116
+ g.connect(out);
117
+ const bp = filt(ctx, 'bandpass', 700, 0.6, g);
118
+ bp.frequency.setValueAtTime(500, t);
119
+ bp.frequency.linearRampToValueAtTime(1100, t + dur * 0.5);
120
+ noise(ctx, t, dur, bp);
121
+ // gritos sueltos del público
122
+ for (let i = 0; i < 8; i++) {
123
+ const s = t + Math.random() * dur * 0.8;
124
+ const o = osc(ctx, 'sawtooth', 300 + Math.random() * 500, s, 0.35, filt(ctx, 'bandpass', 900, 3, env(ctx, out, s, 0.025 * v, 0.05, 0.3)));
125
+ o.frequency.linearRampToValueAtTime(o.frequency.value * 1.3, s + 0.3);
126
+ }
127
+ },
128
+ boom(ctx, out, t, v = 1) {
129
+ I.kick(ctx, out, t, 1.2 * v, 30);
130
+ noise(ctx, t, 1.4, filt(ctx, 'lowpass', 900, 0.5, env(ctx, out, t, 0.5 * v, 0.005, 1.3)));
131
+ noise(ctx, t + 0.05, 0.6, filt(ctx, 'highpass', 4000, 0.5, env(ctx, out, t + 0.05, 0.12 * v, 0.01, 0.5))); // chispas
132
+ },
133
+ };
134
+
135
+ // ── estilos: patrones de 16 pasos por compás, 4 compases (acordes en midi) ──
136
+ const on = (p, i) => p[i % p.length] === 'x';
137
+ const STYLES = {
138
+ hype: {
139
+ chords: [[57, 60, 64], [53, 57, 60], [48, 52, 55], [55, 59, 62]],
140
+ step(ctx, out, t, i, bar, sd) {
141
+ const ch = this.chords[bar % 4];
142
+ if (i % 4 === 0) I.kick(ctx, out, t);
143
+ if (i === 4 || i === 12) I.clap(ctx, out, t);
144
+ if (i % 4 === 2) (I.hat(ctx, out, t, 1, true), I.bass(ctx, out, t, ch[0] - 24, sd * 1.6));
145
+ else I.hat(ctx, out, t, 0.35);
146
+ if (i === 0) I.chord(ctx, out, t, ch, sd * 14, 0.8);
147
+ if (bar % 2 === 1 && i % 2 === 0) I.lead(ctx, out, t, ch[(i / 2) % 3] + 12 + (i >= 8 ? 12 : 0), sd * 0.9, 0.8);
148
+ },
149
+ },
150
+ funk: {
151
+ roots: [52, 52, 57, 55],
152
+ line: [0, null, 12, null, 0, null, 10, 7, 0, null, 12, null, 3, 5, 7, 10],
153
+ step(ctx, out, t, i, bar, sd) {
154
+ const r = this.roots[bar % 4];
155
+ if (on('x.....x.x.....x.', i)) I.kick(ctx, out, t);
156
+ if (i === 4 || i === 12) I.snare(ctx, out, t);
157
+ if (i === 15 && bar % 2) I.snare(ctx, out, t, 0.4);
158
+ I.hat(ctx, out, t, i % 2 ? 0.25 : 0.55, i === 14);
159
+ const n = this.line[i];
160
+ if (n != null) I.bass(ctx, out, t, r - 24 + n, sd * 0.9, 1.1, 'square');
161
+ if (on('..x...x..x..x.x.', i)) I.chord(ctx, out, t, [r + 7, r + 10, r + 14], sd * 0.5, 1.4, 'square');
162
+ },
163
+ },
164
+ chip: {
165
+ chords: [[60, 64, 67], [55, 59, 62], [57, 60, 64], [53, 57, 60]],
166
+ step(ctx, out, t, i, bar, sd) {
167
+ const ch = this.chords[bar % 4];
168
+ if (i % 8 === 0 || i === 10) I.kick(ctx, out, t, 0.8);
169
+ if (i === 4 || i === 12) noise(ctx, t, 0.1, filt(ctx, 'highpass', 1500, 0.5, env(ctx, out, t, 0.25, 0.001, 0.09)));
170
+ I.lead(ctx, out, t, ch[i % 3] + 12 + (Math.floor(i / 4) % 2) * 12, sd * 0.8, 0.9);
171
+ if (i % 4 === 0) I.lead(ctx, out, t, ch[0] - 12, sd * 3, 2.2, 'triangle');
172
+ if (bar % 4 === 3 && i >= 12) I.lead(ctx, out, t, ch[2] + 24 + (i - 12) * 2, sd * 0.8, 0.7);
173
+ },
174
+ },
175
+ trap: {
176
+ roots: [45, 45, 41, 43],
177
+ step(ctx, out, t, i, bar, sd) {
178
+ const r = this.roots[bar % 4];
179
+ if (on('x.......x.x.....', i)) (I.kick(ctx, out, t), I.sub(ctx, out, t, r - 12, sd * (i === 0 ? 7 : 3), 1, i === 10 ? r : null));
180
+ if (i === 8) I.clap(ctx, out, t, 1.1);
181
+ // hats con redoble en el último tiempo
182
+ if (i >= 12 && bar % 2) for (let k = 0; k < 3; k++) I.hat(ctx, out, t + (k * sd) / 3, 0.4 + k * 0.1);
183
+ else if (i % 2 === 0) I.hat(ctx, out, t, 0.5);
184
+ if (i === 0 && bar % 2 === 0) I.chord(ctx, out, t, [r + 12, r + 15, r + 19], sd * 30, 0.7, 'triangle');
185
+ },
186
+ },
187
+ entrance: {
188
+ intro: 2.2, // s de público y golpes antes del riff
189
+ start(ctx, out, t) {
190
+ I.crowd(ctx, out, t, 4.5);
191
+ I.boom(ctx, out, t + 1.0);
192
+ I.boom(ctx, out, t + 1.6, 0.8);
193
+ I.power(ctx, out, t + 1.6, 40, 0.5, 1.2);
194
+ },
195
+ step(ctx, out, t, i, bar, sd) {
196
+ const r = [40, 40, 43, 38][bar % 4];
197
+ if (on('x.....x.x.......', i)) I.kick(ctx, out, t, 1.1);
198
+ if (i === 4 || i === 12) I.snare(ctx, out, t, 1.2);
199
+ if (i % 2 === 0) I.hat(ctx, out, t, 0.4, i === 14);
200
+ if (on('x.x.xx..x.x.x..x', i)) I.power(ctx, out, t, r + (i === 15 ? 3 : 0), sd * 1.3);
201
+ if (i === 0 && bar % 2 === 0) I.crowd(ctx, out, t, 2.5, 0.35);
202
+ },
203
+ },
204
+ };
205
+
206
+ /**
207
+ * Toca un estilo durante `ms`. Devuelve { stop(), done, analyser } o null sin Web Audio.
208
+ * `volume` 0..1. El primer paso cae en el instante en que se llama (con el gesto de baile).
209
+ */
210
+ export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx = null } = {}) {
211
+ const AC = globalThis.AudioContext || globalThis.webkitAudioContext;
212
+ if (!AC) return null;
213
+ ctx ||= shared ||= new AC();
214
+ if (ctx.state === 'suspended') ctx.resume().catch(() => {});
215
+ const S = STYLES[style] || STYLES.hype;
216
+ const master = ctx.createGain();
217
+ const vol = Math.max(0, Math.min(1, volume)) * 0.7;
218
+ master.gain.value = vol;
219
+ const comp = ctx.createDynamicsCompressor();
220
+ const analyser = ctx.createAnalyser();
221
+ analyser.fftSize = 256;
222
+ master.connect(comp).connect(analyser).connect(ctx.destination);
223
+ const sd = 60 / bpm / 4; // un paso = semicorchea
224
+ const t0 = ctx.currentTime + 0.05;
225
+ const end = t0 + ms / 1000;
226
+ if (S.start) S.start(ctx, master, t0);
227
+ let next = t0 + (S.intro || 0);
228
+ let i = 0;
229
+ let stopped = false;
230
+ let resolve;
231
+ const done = new Promise((r) => (resolve = r));
232
+ const pump = () => {
233
+ if (stopped) return;
234
+ while (next < Math.min(end - 0.05, ctx.currentTime + 0.15)) {
235
+ S.step(ctx, master, next, i % 16, Math.floor(i / 16), sd);
236
+ next += sd;
237
+ i++;
238
+ }
239
+ if (ctx.currentTime >= end) stop(0);
240
+ };
241
+ const timer = setInterval(pump, 25);
242
+ pump();
243
+ function stop(fade = 0.4) {
244
+ if (stopped) return;
245
+ stopped = true;
246
+ clearInterval(timer);
247
+ const now = ctx.currentTime;
248
+ master.gain.cancelScheduledValues(now);
249
+ master.gain.setValueAtTime(master.gain.value, now);
250
+ master.gain.linearRampToValueAtTime(0.0001, now + Math.max(0.05, fade));
251
+ setTimeout(() => (master.disconnect(), resolve()), (Math.max(0.05, fade) + 1.5) * 1000);
252
+ }
253
+ // el final se desvanece en el último compás
254
+ master.gain.setValueAtTime(vol, Math.max(t0, end - 0.8));
255
+ master.gain.linearRampToValueAtTime(0.0001, end);
256
+ return { stop, done, analyser, ctx };
257
+ }
@@ -58,6 +58,20 @@ const env = (t, a = 0.15, b = 0.15) => Math.min(EASE.inOut(clamp(t / a)), EASE.i
58
58
 
59
59
  // ───────────────────────────── gestos ─────────────────────────────
60
60
 
61
+ /** Pulso de los bailes: 120 bpm (2 tiempos por segundo). */
62
+ export const DANCE_BPM = 120;
63
+ const BEAT = DANCE_BPM / 60;
64
+ /** Onda más «cuadrada» (llega y se queda en los extremos), para golpes de baile. */
65
+ const snap = (v) => Math.sign(v) * Math.abs(v) ** 0.55;
66
+ /** Tiempo de compás: [índice del tiempo, avance 0..1 con llegada rápida] para moverse a golpes. */
67
+ const beatStep = (age, hz = BEAT) => {
68
+ const b = (age / 1000) * hz;
69
+ const i = Math.floor(b);
70
+ return [i, EASE.out(clamp((b - i) / 0.22))];
71
+ };
72
+
73
+
74
+
61
75
  /** Pose neutra: cuerpo sin transformar y cara sin retoques. */
62
76
  export const POSE0 = Object.freeze({ x: 0, y: 0, r: 0, sx: 1, sy: 1, lx: 0, ly: 0, blink: 0, eye: 1, lift: 0, open: 0, curve: 0, msx: 1 });
63
77
 
@@ -81,6 +95,8 @@ function keys(list) {
81
95
  * wings?: 'slow'|'fast', fx?: [[t, efecto|metamorfosis, opts?]], hold?: se puede alargar con {ms} }.
82
96
  * Se diseñan mirando a la derecha; con { dir: -1 } se reflejan x, r, lx y la mano activa.
83
97
  */
98
+ const DAB = keys([[0, {}], [0.15, { sy: 0.9, sx: 1.06, y: 0.01, r: 4 }], [0.25, { r: -14, x: -0.03, sy: 1.02, ly: 0.7, lx: -0.5, blink: 0.4, curve: 0.5 }, 'out'], [0.85, { r: -14, x: -0.03, sy: 1.01, ly: 0.7, lx: -0.5, blink: 0.4, curve: 0.5 }], [1, {}]]);
99
+
84
100
  export const GESTURES = {
85
101
  jump: {
86
102
  ms: 800,
@@ -182,6 +198,7 @@ export const GESTURES = {
182
198
  dance: {
183
199
  ms: 2600,
184
200
  hold: true,
201
+ dance: 'funk',
185
202
  hands: 'dance',
186
203
  fx: [[0.05, 'notes']],
187
204
  pose: (t, age) => {
@@ -191,6 +208,132 @@ export const GESTURES = {
191
208
  return { r: beat * 9 * e, x: beat * 0.04 * e, y: -0.06 * hop * e, sy: 1 + (0.06 * hop - 0.03) * e, sx: 1 - (0.04 * hop - 0.02) * e, curve: 0.6 * e, lx: beat * 0.3 * e };
192
209
  },
193
210
  },
211
+ // ── bailes (al pulso de DANCE_BPM: la música de beat.js arranca con el gesto y cae en los mismos tiempos) ──
212
+ floss: {
213
+ ms: 6000,
214
+ hold: true,
215
+ dance: 'hype',
216
+ hands: 'floss',
217
+ fx: [[0.04, 'notes']],
218
+ pose: (t, age) => {
219
+ const e = env(t, 0.06, 0.08);
220
+ const sw = snap(S(age, BEAT / 2));
221
+ const hop = Math.abs(S(age, BEAT));
222
+ return { x: -sw * 0.05 * e, r: sw * 6 * e, y: -0.02 * hop * e, sy: 1 + 0.03 * hop * e, sx: 1 - 0.02 * hop * e, curve: 0.7 * e, lx: sw * 0.4 * e, open: 0.15 * e };
223
+ },
224
+ },
225
+ robot: {
226
+ ms: 6000,
227
+ hold: true,
228
+ dance: 'chip',
229
+ hands: 'robot',
230
+ fx: [[0.04, 'notes']],
231
+ pose: (t, age) => {
232
+ const e = env(t, 0.05, 0.08);
233
+ const [i, k] = beatStep(age);
234
+ const at = (n) => [[0, 0], [-6, -0.025], [0, 0], [6, 0.025]][((n % 4) + 4) % 4];
235
+ const a = at(i - 1);
236
+ const b = at(i);
237
+ const r = lerp(a[0], b[0], k);
238
+ return { r: r * e, x: lerp(a[1], b[1], k) * e, sy: 1 + 0.02 * (1 - k) * e, lx: (r / 6) * 0.6 * e, eye: 1 + 0.06 * e, msx: 1 + 0.2 * e, curve: 0.1 * e };
239
+ },
240
+ },
241
+ shuffle: {
242
+ ms: 6000,
243
+ hold: true,
244
+ dance: 'hype',
245
+ hands: 'pump',
246
+ fx: [[0.04, 'notes']],
247
+ pose: (t, age) => {
248
+ const e = env(t, 0.06, 0.08);
249
+ const hop = Math.abs(S(age, BEAT));
250
+ const land = 1 - hop;
251
+ const side = S(age, BEAT / 2);
252
+ return { y: -0.06 * hop * e, x: side * 0.035 * e, r: -side * 4 * e, sy: 1 + (0.05 * hop - 0.05 * land * land) * e, sx: 1 - (0.03 * hop - 0.04 * land * land) * e, curve: 0.8 * e, open: 0.25 * hop * e };
253
+ },
254
+ },
255
+ dab: {
256
+ ms: 4000,
257
+ hold: true,
258
+ dance: 'trap',
259
+ hands: 'dab',
260
+ fx: [[0.08, 'sparkles']],
261
+ // un golpe cada dos segundos (4 tiempos): se prepara, clava el dab y lo sostiene
262
+ pose: (t, age) => {
263
+ const e = env(t, 0.05, 0.1);
264
+ const p = DAB((age % 2000) / 2000);
265
+ const out = {};
266
+ for (const f in p) out[f] = POSE0[f] + (p[f] - POSE0[f]) * e;
267
+ return out;
268
+ },
269
+ },
270
+ groove: {
271
+ ms: 6000,
272
+ hold: true,
273
+ dance: 'funk',
274
+ hands: 'groove',
275
+ fx: [[0.04, 'notes']],
276
+ pose: (t, age) => {
277
+ const e = env(t, 0.06, 0.08);
278
+ const bob = Math.abs(S(age, BEAT));
279
+ const step = S(age, BEAT / 4);
280
+ return { x: step * 0.05 * e, y: -0.025 * bob * e, sy: 1 + (0.04 * bob - 0.02) * e, sx: 1 - (0.03 * bob - 0.015) * e, r: S(age, BEAT / 2) * 5 * e, curve: 0.8 * e, lx: step * 0.3 * e, open: 0.2 * e };
281
+ },
282
+ },
283
+ armwave: {
284
+ ms: 6000,
285
+ hold: true,
286
+ dance: 'chip',
287
+ hands: 'armwave',
288
+ fx: [[0.04, 'notes']],
289
+ pose: (t, age) => {
290
+ const e = env(t, 0.06, 0.08);
291
+ const w = S(age, BEAT / 2, Math.PI / 2);
292
+ return { y: -0.03 * Math.max(0, S(age, BEAT / 2)) * e, r: w * 5 * e, x: w * 0.02 * e, sy: 1 + 0.03 * S(age, BEAT / 2) * e, curve: 0.6 * e, lx: w * 0.5 * e, blink: 0.3 * e };
293
+ },
294
+ },
295
+ disco: {
296
+ ms: 6000,
297
+ hold: true,
298
+ dance: 'funk',
299
+ hands: 'disco',
300
+ fx: [[0.04, 'notes'], [0.04, 'sparkles']],
301
+ pose: (t, age) => {
302
+ const e = env(t, 0.06, 0.08);
303
+ const [i, k] = beatStep(age);
304
+ const at = (n) => (n % 2 ? -1 : 1);
305
+ const p = lerp(at(i - 1), at(i), k);
306
+ return { x: p * 0.03 * e, r: p * 7 * e, y: -0.02 * (1 - k) * e, ly: -p * 0.4 * e, lx: 0.5 * e, curve: 0.8 * e, lift: 2 * e };
307
+ },
308
+ },
309
+ moonwalk: {
310
+ ms: 6000,
311
+ hold: true,
312
+ dance: 'funk',
313
+ hands: 'swing',
314
+ fx: [[0.04, 'notes']],
315
+ pose: (t, age) => {
316
+ const e = env(t, 0.06, 0.08);
317
+ // se desliza hacia atrás (inclinado hacia delante) y vuelve de un paso al compás
318
+ const f = ((age / 1000) * (BEAT / 2)) % 1;
319
+ const back = f < 0.8 ? f / 0.8 : 1 - EASE.inOut((f - 0.8) / 0.2);
320
+ return { x: (0.04 - back * 0.09) * e, r: 6 * e, y: -0.012 * Math.abs(S(age, BEAT)) * e, sy: 1 - 0.02 * e, curve: 0.5 * e, lx: 0.4 * e, blink: 0.35 * e };
321
+ },
322
+ },
323
+ routine: {
324
+ ms: 8000,
325
+ hold: true,
326
+ dance: 'hype',
327
+ hands: 'routine',
328
+ fx: [[0.04, 'notes']],
329
+ pose: (t, age) => {
330
+ const e = env(t, 0.05, 0.08);
331
+ const b = Math.floor((age / 1000) * BEAT) % 8;
332
+ const wig = b >= 6 ? S(age, BEAT * 2) : 0;
333
+ const bob = Math.abs(S(age, BEAT));
334
+ return { r: wig * 7 * e, x: wig * 0.02 * e, y: -0.015 * bob * e, sy: 1 + 0.02 * bob * e, curve: 0.7 * e, open: (b >= 6 ? 0.3 : 0.1) * e };
335
+ },
336
+ },
194
337
  yawn: {
195
338
  ms: 2000,
196
339
  pose: keys([[0, {}], [0.25, { sy: 1.1, sx: 0.95, y: -0.01, open: 0.5, blink: 0.6, lift: 4, msx: 0.8 }], [0.55, { sy: 1.12, sx: 0.94, y: -0.015, open: 1, blink: 0.85, lift: 5, msx: 0.75 }], [0.75, { sy: 0.95, sx: 1.03, open: 0.1, blink: 0.7 }], [1, {}]]),
@@ -267,8 +410,14 @@ export const GESTURES = {
267
410
  export const GESTURE_ALIAS = {
268
411
  handup: 'wave', hi: 'wave', hello: 'wave', index: 'point', ok: 'nod', yes: 'nod', no: 'shake',
269
412
  thumbup: 'thumbsup', thumbdown: 'thumbsdown', side: 'wiggle', namaste: 'bow', hop: 'jump', cheer: 'celebrate',
413
+ default: 'groove', runningman: 'shuffle', robotdance: 'robot', macarena: 'routine', wavearms: 'armwave', slide: 'moonwalk', boogie: 'disco',
270
414
  };
271
415
 
416
+ /** Los gestos que son bailes (llevan `dance`: el estilo de música que les va). */
417
+ export const DANCES = Object.keys(GESTURES).filter((k) => GESTURES[k].dance);
418
+ /** Baile → estilo de música (beat.js). */
419
+ export const DANCE_STYLE = Object.fromEntries(DANCES.map((k) => [k, GESTURES[k].dance]));
420
+
272
421
  // ───────────────────────────── manos ─────────────────────────────
273
422
 
274
423
  /**
@@ -290,6 +439,47 @@ export const HAND_POSES = {
290
439
  namaste: (s, a, dir, c) => ({ x: c.cx + s * c.W * 0.06, y: c.mouthY + c.H * 0.2, ang: 0, type: 'open' }),
291
440
  dance: (s, a) => ({ u: 1.15, v: -0.25 + s * S(a, 1) * 0.6, ang: 30 + s * S(a, 1) * 25, type: 'open' }),
292
441
  hips: () => ({ u: 0.98, v: 0.28, ang: 200, type: 'fist' }),
442
+ // bailes
443
+ floss: (s, a) => {
444
+ const sw = snap(S(a, BEAT / 2));
445
+ return { u: 0.75 + s * sw * 0.85, v: 0.42, ang: 180 - sw * 35, type: 'fist', s: 1 + 0.12 * S(a, BEAT / 2, Math.PI / 2) * s };
446
+ },
447
+ robot: (s, a) => {
448
+ const [i, k] = beatStep(a);
449
+ const up = (n) => ((n + (s > 0 ? 0 : 1)) % 2 ? 1 : 0);
450
+ const u0 = up(i - 1);
451
+ const u1 = up(i);
452
+ const q = lerp(u0, u1, k);
453
+ return { u: 1.22, v: lerp(0.25, -0.4, q), ang: lerp(90, 0, q), type: 'open' };
454
+ },
455
+ pump: (s, a) => ({ u: 1.12, v: 0.08 + s * S(a, BEAT / 2) * 0.32, ang: 25 + s * S(a, BEAT / 2) * 30, type: 'fist' }),
456
+ dab: (s, a, dir, c) => (s === dir ? { u: 1.55, v: -0.78, ang: 52, type: 'open' } : { x: c.cx + dir * c.W * 0.1, y: c.eyeY - c.H * 0.02, ang: -75, type: 'open' }),
457
+ groove: (s, a) => {
458
+ const w = S(a, BEAT / 2) * s;
459
+ return { u: 1.1 - 0.3 * Math.max(0, w), v: -0.1 - w * 0.5, ang: 35 + w * 35, type: 'fist' };
460
+ },
461
+ armwave: (s, a) => ({ u: 1.42, v: -0.32 - 0.3 * S(a, BEAT / 2, s * 1.3), ang: 90 - 45 * S(a, BEAT / 2, s * 1.3 + 0.7), type: 'open' }),
462
+ disco: (s, a, dir) => {
463
+ if (s !== dir) return { u: 0.98, v: 0.28, ang: 200, type: 'fist' };
464
+ const [i, k] = beatStep(a);
465
+ const P = [{ u: 1.45, v: -1.0, ang: 35 }, { u: -0.35, v: 0.6, ang: 215 }];
466
+ const p0 = P[((i - 1) % 2 + 2) % 2];
467
+ const p1 = P[i % 2];
468
+ return { u: lerp(p0.u, p1.u, k), v: lerp(p0.v, p1.v, k), ang: lerp(p0.ang, p1.ang, k), type: 'point' };
469
+ },
470
+ swing: (s, a) => ({ u: 1.1, v: 0.42 + s * S(a, BEAT / 2) * 0.12, ang: 165 + s * S(a, BEAT / 2) * 15, type: 'open' }),
471
+ routine: (s, a) => {
472
+ // 8 tiempos: brazo afuera, palma arriba, al hombro contrario, a la nuca (uno y otro, alternados)
473
+ const P = [REST, { u: 1.5, v: -0.12, ang: 90 }, { u: 1.48, v: -0.2, ang: 80 }, { u: -0.3, v: -0.35, ang: -60 }, { u: 0.45, v: -1.05, ang: -30 }];
474
+ const stage = (n) => {
475
+ const b = ((n % 8) + 8) % 8;
476
+ return s > 0 ? Math.floor((b + 2) / 2) : Math.floor((b + 1) / 2);
477
+ };
478
+ const [i, k] = beatStep(a);
479
+ const p0 = P[stage(i - 1)];
480
+ const p1 = P[stage(i)];
481
+ return { u: lerp(p0.u, p1.u, k), v: lerp(p0.v, p1.v, k), ang: lerp(p0.ang, p1.ang, k), type: 'open' };
482
+ },
293
483
  cover: (s, a, dir, c) => ({ x: c.cx + s * c.sp, y: c.eyeY, ang: -8, type: 'open', s: 1.3 }),
294
484
  };
295
485
 
@@ -16,7 +16,7 @@
16
16
  import * as THREE from 'three';
17
17
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
18
18
  import { layout } from '../character/Character.js';
19
- import { EASE, clamp, approach } from '../character/motion.js';
19
+ import { EASE, clamp, approach, HAND_POSES } from '../character/motion.js';
20
20
  import { U } from './body.js';
21
21
  import { shadowTexture } from './materials.js';
22
22
 
@@ -44,6 +44,15 @@ const CLIP_FOR = {
44
44
  dizzy: /dizz|death|die/i,
45
45
  yawn: /yawn|sit/i,
46
46
  fly: /fly/i,
47
+ floss: /floss/i,
48
+ robot: /robot/i,
49
+ shuffle: /shuffle|running_?man/i,
50
+ dab: /\bdab/i,
51
+ groove: /groove|hip_?hop|default_?dance/i,
52
+ armwave: /arm_?wave|wave_?arms/i,
53
+ disco: /disco|boogie/i,
54
+ moonwalk: /moonwalk|slide/i,
55
+ routine: /routine|macarena/i,
47
56
  };
48
57
  const IDLE = /idle|breath|stand/i;
49
58
 
@@ -140,6 +149,82 @@ async function headOf(gltf) {
140
149
  return head;
141
150
  }
142
151
 
152
+ /** Brazos humanoides { s: lado en pantalla (+1 derecha), up, low, end, q0 } (VRM o nombres tipo Mixamo). */
153
+ async function armsOf(gltf) {
154
+ const { parser } = gltf;
155
+ const ext = parser.json.extensions || {};
156
+ const v1 = ext.VRMC_vrm?.humanoid?.humanBones;
157
+ const v0 = ext.VRM?.humanoid?.humanBones;
158
+ const byVrm = (b) => {
159
+ const idx = v1 ? v1[b]?.node : v0?.find((x) => x.bone === b)?.node;
160
+ return idx == null ? null : parser.getDependency('node', idx).catch(() => null);
161
+ };
162
+ const bones = [];
163
+ gltf.scene.traverse((o) => { if (o.isBone) bones.push(o); });
164
+ // sin esqueleto: nodos rígidos (modelos hechos por partes) con los mismos nombres
165
+ if (!bones.length) gltf.scene.traverse((o) => { if (!o.isMesh) bones.push(o); });
166
+ const byName = (side, part) => {
167
+ const L = side === 'left' ? 'l(eft)?' : 'r(ight)?';
168
+ const re = {
169
+ up: new RegExp(`^(mixamorig\\d*:?)?(${L}[_.]?(upper_?)?arm|(upper_?)?arm[_.]?${L})$`, 'i'),
170
+ low: new RegExp(`^(mixamorig\\d*:?)?(${L}[_.]?(fore_?arm|lower_?arm)|(fore_?arm|lower_?arm)[_.]?${L})$`, 'i'),
171
+ end: new RegExp(`^(mixamorig\\d*:?)?(${L}[_.]?hand|hand[_.]?${L})$`, 'i'),
172
+ }[part];
173
+ return bones.find((b) => re.test(b.name.replace(/\s+/g, ''))) || null;
174
+ };
175
+ const out = [];
176
+ for (const side of ['left', 'right']) {
177
+ const C = side[0].toUpperCase() + side.slice(1);
178
+ let [up, low, end] = await Promise.all(['UpperArm', 'LowerArm', 'Hand'].map((p) => (v1 || v0 ? byVrm(side + p) : null)));
179
+ up ||= byName(side, 'up');
180
+ low ||= byName(side, 'low');
181
+ end ||= byName(side, 'end');
182
+ if (!up || !low || !end || low.parent !== up) continue;
183
+ out.push({ side: C, up, low, end, q0: [up.quaternion.clone(), low.quaternion.clone()] });
184
+ }
185
+ return out.length === 2 ? out : [];
186
+ }
187
+
188
+ const _v = [new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3()];
189
+ const _q = [new THREE.Quaternion(), new THREE.Quaternion(), new THREE.Quaternion()];
190
+ // HAND_POSES en unidades del ot (centro = 0, medio ancho/alto = 1, y hacia abajo)
191
+ const HCTX = { cx: 0, W: 2, H: 2, mid: 0, mouthY: -0.4, eyeY: -0.7, mw: 0.2, sp: 0.3, pts: null };
192
+
193
+ /** Gira `bone` (en el espacio del mundo) para que su eje hacia `child` apunte a `dir`, con peso w. */
194
+ function aim(bone, child, dir, w) {
195
+ const a = bone.getWorldPosition(_v[0]);
196
+ const cur = child.getWorldPosition(_v[1]).sub(a).normalize();
197
+ const q = _q[0].setFromUnitVectors(cur, dir);
198
+ if (w < 1) q.slerp(_q[2].identity(), 1 - w);
199
+ const pw = bone.parent.getWorldQuaternion(_q[1]);
200
+ bone.quaternion.premultiply(pw.clone().invert().multiply(q).multiply(pw));
201
+ bone.updateMatrixWorld(true);
202
+ }
203
+
204
+ /** Brazos del modelo siguiendo la postura de manos del gesto (sólo si el modelo no trae la animación). */
205
+ function tickArms(md, rig, gest, t, rm) {
206
+ const def = gest.def;
207
+ const age = rm ? 0 : t - gest.start;
208
+ const w = EASE.inOut(clamp(Math.min(age / 250, (gest.ms - age) / 300)));
209
+ if (!(w > 0)) return;
210
+ const pose = HAND_POSES[def.hands] || HAND_POSES.rest;
211
+ const rq = rig.getWorldQuaternion(_q[2]).clone();
212
+ rig.updateMatrixWorld(true);
213
+ for (const arm of md.arms) {
214
+ // lado en pantalla: x del hombro en el espacio del ot
215
+ const sx = rig.worldToLocal(arm.up.getWorldPosition(new THREE.Vector3())).x;
216
+ const s = sx >= 0 ? 1 : -1;
217
+ const p = pose(s, age, gest.dir || 1, HCTX);
218
+ const hx = p.x ?? s * p.u;
219
+ const hy = -(p.y ?? p.v);
220
+ const up = new THREE.Vector3(hx - s * 0.55, hy - 0.3, 0.35).normalize().applyQuaternion(rq);
221
+ aim(arm.up, arm.low, up, w);
222
+ const ang = (p.ang || 0) * DEG;
223
+ const low = new THREE.Vector3(s * Math.sin(ang), Math.cos(ang), 0.3).normalize().applyQuaternion(rq);
224
+ aim(arm.low, arm.end, low, w);
225
+ }
226
+ }
227
+
143
228
  /**
144
229
  * Construye el ot como modelo (llamado desde Character3D.build con la ficha ya resuelta).
145
230
  * `this` es la instancia de Character3D.
@@ -211,6 +296,8 @@ export function buildModel(s) {
211
296
  md.head = await headOf(gltf);
212
297
  if (this.modelTok !== tok) return;
213
298
  if (md.head) md.q0 = md.head.quaternion.clone();
299
+ md.arms = await armsOf(gltf);
300
+ if (this.modelTok !== tok) return;
214
301
  if (gltf.animations.length) {
215
302
  md.mixer = new THREE.AnimationMixer(scene);
216
303
  md.clips = gltf.animations;
@@ -336,7 +423,9 @@ export function tickModel(t, dt) {
336
423
 
337
424
  // animaciones y cabeza
338
425
  if (md.head && md.q0) md.head.quaternion.copy(md.q0);
426
+ for (const a of md.arms || []) { a.up.quaternion.copy(a.q0[0]); a.low.quaternion.copy(a.q0[1]); }
339
427
  md.mixer?.update(rm ? 0 : dt / 1000);
428
+ if (gest && !gest.clip && gest.def.hands && md.arms?.length) tickArms(md, rig, gest, t, rm);
340
429
  if (md.head && md.head.parent) {
341
430
  const pw = md.head.parent.getWorldQuaternion(new THREE.Quaternion());
342
431
  const rw = rig.getWorldQuaternion(new THREE.Quaternion());
package/src/index.js CHANGED
@@ -81,6 +81,8 @@ export {
81
81
  CHARACTER_MOODS, CHARACTER_GESTURES, CHARACTER_MORPHS, CHARACTER_EFFECTS, CHARACTER_GESTURE_ALIAS, VISEMES, textToVisemes, SHAPES, EYES, BROWS, MOUTHS, CHEEKS, PATTERNS, FINISHES, ACCESSORIES, ACCESSORY_GROUPS, PRESETS, partLabel,
82
82
  resolveCharacter, normalizeMods, normalizeMod, sanitizeSvg, modName, MOD_ANCHORS, MAX_MODS,
83
83
  } from './character/Character.js';
84
+ export { DANCES, DANCE_STYLE, DANCE_BPM } from './character/motion.js';
85
+ export { playBeat, BEAT_STYLES } from './character/beat.js';
84
86
  import { createAvatarEditor, AvatarEditor } from './character/AvatarEditor.js';
85
87
  import { renderCharacter as _renderCharacter, createCharacter as _createCharacter } from './character/Character.js';
86
88
  export { createAvatarEditor, AvatarEditor };