@7ots/cli 0.1.17 → 0.1.36
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/.env.example +14 -0
- package/README.md +11 -0
- package/brand/logos/base.svg +1 -0
- package/brand/logos/clawpump.png +0 -0
- package/brand/logos/conductors.svg +1 -0
- package/brand/logos/notlogin.svg +12 -0
- package/brand/logos/pumpfun.png +0 -0
- package/brand/logos/solana.png +0 -0
- package/brand/logos/spawnerbot.svg +1 -0
- package/brand/logos/virtuals.png +0 -0
- package/cli/7ots.mjs +61 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +92 -14
- package/cli/lib/brain.mjs +84 -11
- package/cli/lib/card-shot.mjs +1 -1
- package/cli/lib/config.mjs +14 -3
- package/cli/lib/desktop-sync.mjs +177 -0
- package/cli/lib/i18n.mjs +9 -0
- package/cli/lib/inferences.mjs +19 -2
- package/cli/lib/integrations.mjs +98 -13
- package/cli/lib/mcp.mjs +1 -1
- package/cli/lib/open.mjs +3 -1
- package/cli/lib/pet-server.mjs +352 -41
- package/cli/lib/prompts.mjs +1 -1
- package/cli/lib/screen.mjs +1 -1
- package/cli/lib/senses/gestures.mjs +121 -0
- package/cli/lib/senses/index.mjs +490 -0
- package/cli/lib/senses/rules.mjs +159 -0
- package/cli/lib/senses/sources/activity.mjs +95 -0
- package/cli/lib/senses/sources/calendar.mjs +75 -0
- package/cli/lib/senses/sources/index.mjs +17 -0
- package/cli/lib/senses/sources/mail.mjs +48 -0
- package/cli/lib/senses/sources/system.mjs +39 -0
- package/cli/lib/senses/util.mjs +41 -0
- package/cli/lib/senses/vendor.mjs +78 -0
- package/cli/lib/stt-local.py +16 -8
- package/cli/lib/stt.mjs +53 -6
- package/cli/lib/tooluse.mjs +56 -0
- package/cli/lib/tts-local.mjs +2 -2
- package/cli/lib/vm.mjs +2 -2
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +190 -8
- package/cli/pet/pet.html +153 -34
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +815 -74
- package/dist/7ots.esm.js +373 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +373 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +18 -4
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +84 -14
- package/server/settings.mjs +3 -0
- package/server/site.mjs +401 -0
- package/server/tts.mjs +29 -5
- package/src/avatar/AvatarStage.js +2 -2
- package/src/avatar/three.js +3 -2
- package/src/character/AvatarEditor.js +2 -1
- package/src/character/Character.js +38 -5
- package/src/character/TradingCard.js +2 -0
- package/src/character/beat.js +64 -2
- package/src/character/mods/orc.js +8 -1
- package/src/character/mods.js +104 -10
- package/src/character/motion.js +252 -1
- package/src/character/parts.js +40 -38
- package/src/character/styles.js +40 -38
- package/src/character3d/Character3D.js +26 -5
- package/src/character3d/body.js +14 -12
- package/src/character3d/export.js +693 -0
- package/src/character3d/fx.js +13 -0
- package/src/character3d/index.js +2 -0
- package/src/character3d/materials.js +106 -10
- package/src/character3d/room-themes.js +1184 -0
- package/src/character3d/room.js +487 -0
- package/src/character3d/stage.js +14 -2
- package/src/creator/StepCreator.js +316 -0
- package/src/i18n/index.js +3 -3
- package/src/i18n/messages/character.js +352 -4
- package/src/i18n/messages/creator.js +138 -0
- package/src/i18n/messages/identity.js +89 -1
- package/src/i18n/messages/platform.js +270 -4
- package/src/i18n/messages/server.js +443 -1
- package/src/i18n/messages/widget.js +233 -0
- package/src/identity/random.js +14 -2
- package/src/identity/schema.js +2 -1
- package/src/index.js +9 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -319
- package/server/platform/connect.mjs +0 -387
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -275
- package/server/platform/device.mjs +0 -222
- package/server/platform/integrations.mjs +0 -169
- package/server/platform/look.mjs +0 -20
- package/server/platform/mods.mjs +0 -222
- package/server/platform/orquesta.mjs +0 -577
- package/server/platform/profile.mjs +0 -161
- package/server/platform/routes.mjs +0 -542
- package/server/platform/runtime.mjs +0 -242
- package/server/platform/sites.mjs +0 -146
- package/server/platform/store.mjs +0 -456
- package/server/platform/vm.mjs +0 -1057
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* La habitación del ot: una pieza 3D (ventana con haz de luz, sofá, alfombra, cama, escritorio con la
|
|
3
|
+
* plaza, planta) donde el ot vive solo — elige un lugar, camina, hace su cosa — o lo manejas tú
|
|
4
|
+
* (WASD/flechas, clic en el suelo, cruceta en táctil, E para usar el lugar más cercano).
|
|
5
|
+
*
|
|
6
|
+
* const room = createRoom3D(el, look.character, { name: 'Din', locale: 'es', onEdit: () => … });
|
|
7
|
+
* room.message('Hola!'); // corre al escritorio a «leerlo»
|
|
8
|
+
* room.react('plaza'); // revisa la plaza
|
|
9
|
+
* room.setTheme('gothic'); // otro tipo de casa (ROOM_THEMES), mismos lugares
|
|
10
|
+
* room.setSpec(spec); room.setName('Din'); room.say('…'); room.setMode('ctl'); room.destroy();
|
|
11
|
+
*
|
|
12
|
+
* Usa su propio renderer y canvas DENTRO de `el` (no el stage compartido, que es un canvas fijo encima
|
|
13
|
+
* de la página): así el HUD queda sobre el 3D aunque el contenedor viva en otro contexto de apilamiento.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as THREE from 'three';
|
|
17
|
+
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
|
18
|
+
import { Character3D } from './Character3D.js';
|
|
19
|
+
import { buildRoom, ROOM_THEMES, DEFAULT_ROOM_THEME } from './room-themes.js';
|
|
20
|
+
import '../i18n/messages/creator.js';
|
|
21
|
+
import { translator } from '../i18n/index.js';
|
|
22
|
+
|
|
23
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
24
|
+
|
|
25
|
+
const OT_H = 1.3;
|
|
26
|
+
|
|
27
|
+
// lugares de la pieza: dónde se para, hacia dónde mira y, si se sube, a qué altura
|
|
28
|
+
const POIS = {
|
|
29
|
+
window: { at: [-1.2, -3.0], face: Math.PI },
|
|
30
|
+
sofa: { at: [-3.2, 0.5], seat: [-4.15, 0.66, 0.5], face: Math.PI / 2 },
|
|
31
|
+
rug: { at: [0.6, 0.9], face: 0.35 },
|
|
32
|
+
bed: { at: [1.9, -2.2], seat: [3.55, 0.68, -2.3], face: 0.3 },
|
|
33
|
+
desk: { at: [0.95, -2.75], face: Math.PI },
|
|
34
|
+
plant: { at: [-3.5, -2.6], face: -2.3 },
|
|
35
|
+
front: { at: [0.9, 2.0], face: 0.25 },
|
|
36
|
+
};
|
|
37
|
+
// obstáculos (cajas en el suelo) para cuando lo controlas tú
|
|
38
|
+
const BLOCKS = [[-5, -0.95, -3.7, 1.95], [-4.75, -1.85, -3.85, -1.05], [2.45, -4, 4.65, -0.95], [0, -4, 2.05, -3.0], [-4.8, -3.85, -3.9, -2.95]];
|
|
39
|
+
const BOUNDS = [-4.6, 4.6, -3.6, 3.6];
|
|
40
|
+
const RAD = 0.32;
|
|
41
|
+
|
|
42
|
+
const CSS = `
|
|
43
|
+
.otr{position:relative;overflow:hidden;border-radius:inherit;min-height:260px;background:#2a1f55;outline:none;--otr-glass:rgb(10 7 32 / .62);--otr-line:rgb(255 255 255 / .14);--otr-accent:#ffd23f;--otr-accent-ink:#1a1240;color:#f4f1ff}
|
|
44
|
+
.otr canvas{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:crosshair}
|
|
45
|
+
.otr button{font:inherit;color:inherit;cursor:pointer}
|
|
46
|
+
.otr-hud{position:absolute;z-index:2;left:12px;right:12px;top:12px;display:flex;justify-content:space-between;align-items:flex-start;gap:8px;flex-wrap:wrap;pointer-events:none}
|
|
47
|
+
.otr-hud>*{pointer-events:auto;display:flex;gap:8px;align-items:center;flex-wrap:wrap}
|
|
48
|
+
.otr-btn{border:1px solid var(--otr-line);background:var(--otr-glass);backdrop-filter:blur(6px);border-radius:999px;padding:6px 12px;font-weight:600;font-size:13px}
|
|
49
|
+
.otr-btn:hover{background:rgb(40 30 90 / .75)}
|
|
50
|
+
.otr-who{padding:6px 12px;border-radius:999px;background:var(--otr-glass);backdrop-filter:blur(6px);color:rgb(244 241 255 / .7);font-size:13px}
|
|
51
|
+
.otr-who b{color:#fff}
|
|
52
|
+
.otr-seg{display:flex;padding:3px;border-radius:999px;background:var(--otr-glass);backdrop-filter:blur(6px);border:1px solid var(--otr-line)}
|
|
53
|
+
.otr-seg button{border:0;background:none;padding:5px 12px;border-radius:999px;color:rgb(244 241 255 / .7);font-weight:600;font-size:13px}
|
|
54
|
+
.otr-seg button[aria-pressed=true]{background:var(--otr-accent);color:var(--otr-accent-ink)}
|
|
55
|
+
.otr-bubble{position:absolute;z-index:3;transform:translate(-50%,-100%);max-width:min(240px,70%);padding:7px 12px;border-radius:16px;background:#fff;color:#1a1240;font-weight:600;font-size:13px;line-height:1.3;box-shadow:0 8px 24px rgb(0 0 0 / .3);pointer-events:none}
|
|
56
|
+
.otr-bubble::after{content:"";position:absolute;left:50%;bottom:-6px;width:12px;height:12px;background:#fff;transform:translateX(-50%) rotate(45deg)}
|
|
57
|
+
.otr-keys{position:absolute;z-index:2;left:50%;bottom:12px;transform:translateX(-50%);margin:0;padding:6px 12px;border-radius:999px;background:var(--otr-glass);color:rgb(244 241 255 / .75);font-size:12px;white-space:nowrap}
|
|
58
|
+
.otr-prompt{position:absolute;z-index:2;left:50%;bottom:52px;transform:translateX(-50%);margin:0;padding:6px 14px;border-radius:999px;background:var(--otr-accent);color:var(--otr-accent-ink);font-weight:700;font-size:13px;white-space:nowrap}
|
|
59
|
+
.otr-pad{pointer-events:auto;position:absolute;z-index:2;right:12px;bottom:12px;display:grid;grid-template:repeat(3,44px)/repeat(3,44px);gap:5px}
|
|
60
|
+
.otr-pad button{border-radius:12px;border:1px solid var(--otr-line);background:var(--otr-glass);font-size:16px;touch-action:none;user-select:none;-webkit-user-select:none}
|
|
61
|
+
.otr-pad button:active{background:rgb(139 123 255 / .45)}
|
|
62
|
+
.otr-pad [data-d=up]{grid-area:1/2}.otr-pad [data-d=left]{grid-area:2/1}.otr-pad [data-d=use]{grid-area:2/2;background:rgb(255 210 63 / .25)}.otr-pad [data-d=right]{grid-area:2/3}.otr-pad [data-d=down]{grid-area:3/2}
|
|
63
|
+
.otr [hidden]{display:none!important}
|
|
64
|
+
.otr.compact .otr-who,.otr.compact .otr-keys{display:none!important}
|
|
65
|
+
.otr.compact .otr-prompt{bottom:12px;left:12px;transform:none}
|
|
66
|
+
`;
|
|
67
|
+
let cssDone = false;
|
|
68
|
+
const injectCss = () => {
|
|
69
|
+
if (cssDone) return;
|
|
70
|
+
cssDone = true;
|
|
71
|
+
const s = document.createElement('style');
|
|
72
|
+
s.dataset.ots = 'room3d';
|
|
73
|
+
s.textContent = CSS;
|
|
74
|
+
document.head.appendChild(s);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const disposeTree = (o) => o.traverse((m) => {
|
|
78
|
+
m.geometry?.dispose?.();
|
|
79
|
+
for (const mat of [].concat(m.material || [])) {
|
|
80
|
+
for (const v of Object.values(mat)) if (v?.isTexture) v.dispose();
|
|
81
|
+
mat.dispose?.();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {HTMLElement} el contenedor (se le da position:relative; el alto lo pone la página)
|
|
87
|
+
* @param {object} spec look.character
|
|
88
|
+
* @param {{ name?: string, locale?: string, controls?: boolean, compact?: boolean, demo?: boolean, onEdit?: ()=>void, maxDpr?: number, theme?: string }} [opts]
|
|
89
|
+
* controls=false: solo se mueve solo (sin HUD de modo). demo: botón «Mensaje» que simula uno.
|
|
90
|
+
*/
|
|
91
|
+
export { ROOM_THEMES, DEFAULT_ROOM_THEME };
|
|
92
|
+
|
|
93
|
+
export function createRoom3D(el, spec, opts = {}) {
|
|
94
|
+
injectCss();
|
|
95
|
+
const t = translator(opts.locale);
|
|
96
|
+
let name = opts.name || 'ot';
|
|
97
|
+
const controls = opts.controls !== false;
|
|
98
|
+
const coarse = matchMedia('(hover: none)').matches;
|
|
99
|
+
|
|
100
|
+
el.classList.add('otr');
|
|
101
|
+
el.classList.toggle('compact', !!opts.compact);
|
|
102
|
+
if (!el.hasAttribute('tabindex')) el.tabIndex = 0;
|
|
103
|
+
const box = document.createElement('div');
|
|
104
|
+
box.style.cssText = 'position:absolute;inset:0;pointer-events:none';
|
|
105
|
+
box.innerHTML = `
|
|
106
|
+
<div class="otr-bubble" data-bubble hidden></div>
|
|
107
|
+
<div class="otr-hud">
|
|
108
|
+
<div>${opts.onEdit ? `<button type="button" class="otr-btn" data-edit>✎ ${esc(t('room.edit'))}</button>` : ''}<span class="otr-who"><b data-name></b> <span data-doing>${esc(t('room.inRoom'))}</span></span></div>
|
|
109
|
+
<div>${opts.demo ? `<button type="button" class="otr-btn" data-msg title="${esc(t('room.messageHint'))}">📩 ${esc(t('room.message'))}</button>` : ''}${controls ? `<div class="otr-seg" role="group"><button type="button" data-mode="auto" aria-pressed="true">🧠 ${esc(t('room.auto'))}</button><button type="button" data-mode="ctl" aria-pressed="false">🎮 ${esc(t('room.control'))}</button></div>` : ''}</div>
|
|
110
|
+
</div>
|
|
111
|
+
<p class="otr-keys" data-keys hidden>${esc(t('room.keys'))}</p>
|
|
112
|
+
<p class="otr-prompt" data-prompt hidden></p>
|
|
113
|
+
<div class="otr-pad" data-pad hidden>${['up', 'left', 'use', 'right', 'down'].map((d) => `<button type="button" data-d="${d}" aria-label="${esc(t(`room.pad.${d}`))}">${{ up: '▲', left: '◀', use: 'E', right: '▶', down: '▼' }[d]}</button>`).join('')}</div>`;
|
|
114
|
+
const $ = (s) => box.querySelector(s);
|
|
115
|
+
$('[data-name]').textContent = name;
|
|
116
|
+
|
|
117
|
+
// renderer propio
|
|
118
|
+
const canvas = document.createElement('canvas');
|
|
119
|
+
canvas.setAttribute('aria-label', t('room.inRoom'));
|
|
120
|
+
el.append(canvas, box);
|
|
121
|
+
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance' });
|
|
122
|
+
renderer.setPixelRatio(Math.min(opts.maxDpr || 1.5, devicePixelRatio || 1));
|
|
123
|
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
124
|
+
renderer.toneMapping = THREE.NeutralToneMapping;
|
|
125
|
+
renderer.toneMappingExposure = 1.05;
|
|
126
|
+
const pm = new THREE.PMREMGenerator(renderer);
|
|
127
|
+
const envTarget = pm.fromScene(new RoomEnvironment(), 0.04);
|
|
128
|
+
pm.dispose();
|
|
129
|
+
|
|
130
|
+
const scene = new THREE.Scene();
|
|
131
|
+
scene.background = new THREE.Color('#2a1f55');
|
|
132
|
+
scene.environment = envTarget.texture;
|
|
133
|
+
scene.environmentIntensity = 0.45;
|
|
134
|
+
const hemi = new THREE.HemisphereLight(0xe8ecff, 0x40304e, 0.56);
|
|
135
|
+
const key = new THREE.DirectionalLight(0xfff1e0, 2.4 * 0.55);
|
|
136
|
+
key.position.set(2.2, 3.4, 3.2);
|
|
137
|
+
const rim = new THREE.DirectionalLight(0xcfe0ff, 2.2 * 0.55);
|
|
138
|
+
rim.position.set(-2.6, 2.2, -3.0);
|
|
139
|
+
const fill = new THREE.DirectionalLight(0xffe6f4, 0.5 * 0.55);
|
|
140
|
+
fill.position.set(-3, 0.5, 2);
|
|
141
|
+
const amb = new THREE.AmbientLight('#ffe9d6', 0.25);
|
|
142
|
+
scene.add(hemi, key, rim, fill, amb);
|
|
143
|
+
let env = null;
|
|
144
|
+
// el tipo de casa: rehace la pieza (mismos lugares y obstáculos) y descarta la anterior
|
|
145
|
+
const applyTheme = (id) => {
|
|
146
|
+
if (env) { scene.remove(env.group); disposeTree(env.group); }
|
|
147
|
+
env = buildRoom(scene, id);
|
|
148
|
+
const L = env.look;
|
|
149
|
+
scene.background.set(L.bg);
|
|
150
|
+
el.style.background = L.bg;
|
|
151
|
+
scene.environmentIntensity = L.env;
|
|
152
|
+
renderer.toneMappingExposure = L.exposure;
|
|
153
|
+
hemi.color.set(L.hemi[0]); hemi.groundColor.set(L.hemi[1]); hemi.intensity = L.hemi[2];
|
|
154
|
+
amb.color.set(L.amb[0]); amb.intensity = L.amb[1];
|
|
155
|
+
key.intensity = 2.4 * 0.55 * L.key; rim.intensity = 2.2 * 0.55 * L.key; fill.intensity = 0.5 * 0.55 * L.key;
|
|
156
|
+
};
|
|
157
|
+
applyTheme(opts.theme || DEFAULT_ROOM_THEME);
|
|
158
|
+
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 80);
|
|
159
|
+
|
|
160
|
+
let ch = null;
|
|
161
|
+
const pos = new THREE.Vector3(0.9, 0, 2.0);
|
|
162
|
+
let heading = 0.2, wantHeading = 0.2, baseY = 0, bob = 0, walking = 0, speedK = 1;
|
|
163
|
+
let nav = null, hop = null, seated = null;
|
|
164
|
+
let mode = 'auto';
|
|
165
|
+
const keys = new Set();
|
|
166
|
+
const camT = new THREE.Vector3(-0.4, 0.6, -0.6);
|
|
167
|
+
|
|
168
|
+
const bubble = $('[data-bubble]');
|
|
169
|
+
let bubbleUntil = 0;
|
|
170
|
+
const say = (text, ms = 2600) => { bubble.textContent = text; bubble.hidden = false; bubbleUntil = performance.now() + ms; };
|
|
171
|
+
const doing = (s) => { $('[data-doing]').textContent = s; };
|
|
172
|
+
|
|
173
|
+
const build = (s) => {
|
|
174
|
+
if (ch) { scene.remove(ch.root); ch.dispose(); }
|
|
175
|
+
ch = new Character3D(s, { quality: 'high', material: opts.material || 'plush' });
|
|
176
|
+
ch.root.scale.setScalar(OT_H / ch.H);
|
|
177
|
+
scene.add(ch.root);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// movimiento
|
|
181
|
+
const angTo = (a, b, k) => { let d = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI; if (d < -Math.PI) d += Math.PI * 2; return a + d * k; };
|
|
182
|
+
const blocked = (x, z) => x < BOUNDS[0] || x > BOUNDS[1] || z < BOUNDS[2] || z > BOUNDS[3] || BLOCKS.some(([x0, z0, x1, z1]) => x > x0 - RAD && x < x1 + RAD && z > z0 - RAD && z < z1 + RAD);
|
|
183
|
+
const walkTo = (x, z, sp = 1) => new Promise((res) => { nav = { x, z, sp, res }; });
|
|
184
|
+
const hopTo = (to, ms = 520) => new Promise((res) => { hop = { from: new THREE.Vector3(pos.x, baseY, pos.z), to: new THREE.Vector3(...to), t0: performance.now(), ms, res }; });
|
|
185
|
+
const leaveSeat = async () => {
|
|
186
|
+
if (!seated) return;
|
|
187
|
+
const p = seated;
|
|
188
|
+
seated = null;
|
|
189
|
+
if (ch.moodName === 'sleep') ch.mood('neutral'); // taken out of bed mid-nap: it wakes up (eyes open) before moving
|
|
190
|
+
await hopTo([p.at[0], 0, p.at[1]]);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// piloto automático: elige un lugar, camina, hace su cosa, repite
|
|
194
|
+
let job = 0;
|
|
195
|
+
const timers = new Set();
|
|
196
|
+
const wait = (ms) => new Promise((r) => { const id = setTimeout(() => { timers.delete(id); r(); }, ms); timers.add(id); });
|
|
197
|
+
const run = (fn) => { const id = ++job; nav = null; fn(() => id !== job).catch(() => {}); };
|
|
198
|
+
const guard = (dead) => async (p) => { const v = await p; if (dead()) throw 0; return v; };
|
|
199
|
+
async function act(id, dead, { hurry = false, line = null } = {}) {
|
|
200
|
+
const g = guard(dead);
|
|
201
|
+
const p = POIS[id];
|
|
202
|
+
await g(leaveSeat());
|
|
203
|
+
ch.mood('neutral');
|
|
204
|
+
doing(t(hurry ? 'room.run' : 'room.walk'));
|
|
205
|
+
await g(walkTo(p.at[0], p.at[1], hurry ? 2.2 : 1));
|
|
206
|
+
wantHeading = p.face;
|
|
207
|
+
doing(t(`room.doing.${id}`));
|
|
208
|
+
await g(wait(350));
|
|
209
|
+
if (p.seat) { seated = p; await g(hopTo(p.seat)); wantHeading = p.face; }
|
|
210
|
+
if (id === 'window') { ch.gesture('think'); say(t('room.say.window')); await g(wait(3200)); ch.effect('sparkles'); await g(wait(2400)); }
|
|
211
|
+
else if (id === 'sofa') { ch.mood('happy'); await g(wait(2200)); ch.gesture('yawn'); say(t('room.say.sofa')); await g(wait(4200)); }
|
|
212
|
+
else if (id === 'rug') { for (const m of ['dance', 'groove', 'disco'].sort(() => Math.random() - 0.5).slice(0, 2)) { ch.gesture(m); ch.effect('notes'); await g(wait(2600)); } }
|
|
213
|
+
else if (id === 'bed') { ch.mood('sleep'); say('zzz…', 1800); for (let i = 0; i < 4; i++) { ch.effect('zzz'); await g(wait(2200)); } ch.mood('neutral'); ch.gesture('yawn'); await g(wait(1600)); }
|
|
214
|
+
else if (id === 'desk') { ch.gesture('think'); ch.effect('thought'); say(line || t('room.say.desk')); await g(wait(3400)); ch.gesture('nod'); await g(wait(1600)); }
|
|
215
|
+
else if (id === 'plant') { ch.gesture('point'); say(t('room.say.plant')); await g(wait(2800)); ch.effect('hearts'); await g(wait(1400)); }
|
|
216
|
+
else if (id === 'front') { ch.gesture('wave'); say(t('room.say.hello', { name })); await g(wait(2600)); }
|
|
217
|
+
}
|
|
218
|
+
let last = 'front';
|
|
219
|
+
const autopilot = (skipHello) => run(async (dead) => {
|
|
220
|
+
const g = guard(dead);
|
|
221
|
+
if (!skipHello) await g(act('front', dead));
|
|
222
|
+
for (;;) {
|
|
223
|
+
const o = Object.keys(POIS).filter((k) => k !== last);
|
|
224
|
+
last = o[Math.floor(Math.random() * o.length)];
|
|
225
|
+
await g(act(last, dead));
|
|
226
|
+
ch.mood('neutral');
|
|
227
|
+
await g(wait(600 + Math.random() * 1200));
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
const resume = () => { if (mode === 'auto') autopilot(true); else doing(t('room.you')); };
|
|
231
|
+
/** Le llega un mensaje: se sobresalta, corre al escritorio, lo «lee» y lo responde. */
|
|
232
|
+
const message = (text) => run(async (dead) => {
|
|
233
|
+
const g = guard(dead);
|
|
234
|
+
ch.effect('exclaim');
|
|
235
|
+
ch.gesture('surprise');
|
|
236
|
+
say(t('room.say.gotMsg'), 2200);
|
|
237
|
+
await g(wait(900));
|
|
238
|
+
await g(act('desk', dead, { hurry: true, line: text ? `«${String(text).slice(0, 90)}»` : null }));
|
|
239
|
+
ch.mood('happy');
|
|
240
|
+
ch.gesture('thumbsup');
|
|
241
|
+
say(t('room.say.replied'));
|
|
242
|
+
await g(wait(2400));
|
|
243
|
+
resume();
|
|
244
|
+
});
|
|
245
|
+
/** Reacciones a lo que pasa fuera: 'plaza' (actividad en la plaza), 'poke', o cualquier efecto 3D. */
|
|
246
|
+
const react = (kind, text) => {
|
|
247
|
+
if (kind === 'message') return message(text);
|
|
248
|
+
if (kind === 'plaza') return run(async (dead) => { await guard(dead)(act('desk', dead, { line: text || null })); resume(); });
|
|
249
|
+
if (kind === 'poke') { ch.gesture('wave'); ch.effect('hearts'); return say(text || t('room.say.hello', { name })); }
|
|
250
|
+
ch.effect(kind);
|
|
251
|
+
if (text) say(text);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// modo control
|
|
255
|
+
const near = () => {
|
|
256
|
+
let best = null, bd = 1.3;
|
|
257
|
+
for (const [k, p] of Object.entries(POIS)) { const d = Math.hypot(pos.x - p.at[0], pos.z - p.at[1]); if (d < bd) { bd = d; best = k; } }
|
|
258
|
+
return best;
|
|
259
|
+
};
|
|
260
|
+
const use = () => {
|
|
261
|
+
if (mode !== 'ctl') return;
|
|
262
|
+
if (seated) return run(async (dead) => { await guard(dead)(leaveSeat()); ch.mood('neutral'); });
|
|
263
|
+
const k = near();
|
|
264
|
+
if (k) run((dead) => act(k, dead));
|
|
265
|
+
else ch.gesture('jump');
|
|
266
|
+
};
|
|
267
|
+
const setMode = (m) => {
|
|
268
|
+
if (!controls && m === 'ctl') return;
|
|
269
|
+
mode = m;
|
|
270
|
+
box.querySelectorAll('[data-mode]').forEach((b) => b.setAttribute('aria-pressed', b.dataset.mode === m));
|
|
271
|
+
$('[data-keys]').hidden = m !== 'ctl' || coarse;
|
|
272
|
+
$('[data-pad]').hidden = m !== 'ctl' || !(coarse || el.clientWidth < 640);
|
|
273
|
+
if (m === 'auto') { $('[data-prompt]').hidden = true; autopilot(true); }
|
|
274
|
+
else { job++; nav = null; doing(t('room.you')); say(t('room.say.takeMe'), 1600); el.focus({ preventScroll: true }); }
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// teclado: solo con la pieza enfocada o el puntero encima, y nunca mientras se escribe
|
|
278
|
+
const KEYMAP = { KeyW: 'up', ArrowUp: 'up', KeyS: 'down', ArrowDown: 'down', KeyA: 'left', ArrowLeft: 'left', KeyD: 'right', ArrowRight: 'right' };
|
|
279
|
+
let hover = false;
|
|
280
|
+
const onKey = (e) => {
|
|
281
|
+
if (!controls) return;
|
|
282
|
+
if (e.target.closest?.('input,textarea,select,[contenteditable]')) return;
|
|
283
|
+
const d = KEYMAP[e.code];
|
|
284
|
+
if (e.type === 'keyup') { if (d) keys.delete(d); return; }
|
|
285
|
+
if (!(hover || el.contains(document.activeElement))) return;
|
|
286
|
+
if (mode === 'auto' && (d || e.code === 'Space')) setMode('ctl');
|
|
287
|
+
if (d) { e.preventDefault(); keys.add(d); }
|
|
288
|
+
if (e.code === 'Space') { e.preventDefault(); ch.gesture('jump'); }
|
|
289
|
+
if (e.code === 'KeyE') use();
|
|
290
|
+
};
|
|
291
|
+
const clearKeys = () => keys.clear();
|
|
292
|
+
addEventListener('keydown', onKey);
|
|
293
|
+
addEventListener('keyup', onKey);
|
|
294
|
+
addEventListener('blur', clearKeys);
|
|
295
|
+
el.addEventListener('pointerenter', () => { hover = true; });
|
|
296
|
+
el.addEventListener('pointerleave', () => { hover = false; });
|
|
297
|
+
const pad = $('[data-pad]');
|
|
298
|
+
pad.addEventListener('pointerdown', (e) => { const d = e.target.closest('[data-d]')?.dataset.d; if (!d) return; e.preventDefault(); if (d === 'use') use(); else keys.add(d); });
|
|
299
|
+
const padUp = (e) => { const d = e.target.closest?.('[data-d]')?.dataset.d; if (d) keys.delete(d); };
|
|
300
|
+
pad.addEventListener('pointerup', padUp);
|
|
301
|
+
pad.addEventListener('pointercancel', padUp);
|
|
302
|
+
pad.addEventListener('pointerleave', clearKeys);
|
|
303
|
+
|
|
304
|
+
// clic en el suelo: ir ahí (o, si cae en un mueble, al lugar de ese mueble)
|
|
305
|
+
const ray = new THREE.Raycaster();
|
|
306
|
+
const ndc = new THREE.Vector2();
|
|
307
|
+
canvas.addEventListener('pointerdown', (e) => {
|
|
308
|
+
const r = canvas.getBoundingClientRect();
|
|
309
|
+
ndc.set(((e.clientX - r.left) / r.width) * 2 - 1, -((e.clientY - r.top) / r.height) * 2 + 1);
|
|
310
|
+
ray.setFromCamera(ndc, camera);
|
|
311
|
+
if (!controls) {
|
|
312
|
+
// sin controles: tocarlo lo saluda
|
|
313
|
+
if (ray.intersectObject(ch.root, true).length) react('poke');
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const hit = ray.intersectObject(env.floor)[0];
|
|
317
|
+
if (!hit) return;
|
|
318
|
+
if (mode === 'auto') setMode('ctl');
|
|
319
|
+
const { x, z } = hit.point;
|
|
320
|
+
if (Math.hypot(x - pos.x, z - pos.z) < 0.25) { ch.gesture('jump'); return; }
|
|
321
|
+
const k = Object.keys(POIS).find((kk) => { const p = POIS[kk]; return Math.hypot(x - (p.seat?.[0] ?? p.at[0]), z - (p.seat?.[2] ?? p.at[1])) < 0.9; });
|
|
322
|
+
if (k && (POIS[k].seat || blocked(x, z))) return run((dead) => act(k, dead));
|
|
323
|
+
if (blocked(x, z)) return;
|
|
324
|
+
run(async (dead) => { await guard(dead)(leaveSeat()); doing(t('room.walk')); await guard(dead)(walkTo(x, z, 1.3)); doing(t('room.you')); });
|
|
325
|
+
});
|
|
326
|
+
box.addEventListener('click', (e) => {
|
|
327
|
+
const b = e.target.closest('button');
|
|
328
|
+
if (!b) return;
|
|
329
|
+
if (b.dataset.mode) setMode(b.dataset.mode);
|
|
330
|
+
else if (b.dataset.msg != null) message();
|
|
331
|
+
else if (b.dataset.edit != null) opts.onEdit?.();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// tamaño
|
|
335
|
+
let W0 = 0, H0 = 0;
|
|
336
|
+
const resize = () => {
|
|
337
|
+
const w = Math.max(1, el.clientWidth), h = Math.max(1, el.clientHeight);
|
|
338
|
+
if (w === W0 && h === H0) return;
|
|
339
|
+
W0 = w; H0 = h;
|
|
340
|
+
renderer.setSize(w, h, false);
|
|
341
|
+
const a = w / h;
|
|
342
|
+
camera.aspect = a;
|
|
343
|
+
camera.fov = a < 1 ? 50 : 36;
|
|
344
|
+
camera.updateProjectionMatrix();
|
|
345
|
+
if (mode === 'ctl') $('[data-pad]').hidden = !(coarse || w < 640);
|
|
346
|
+
};
|
|
347
|
+
const ro = new ResizeObserver(resize);
|
|
348
|
+
ro.observe(el);
|
|
349
|
+
|
|
350
|
+
const fwd = new THREE.Vector3(), right = new THREE.Vector3(), tmp = new THREE.Vector3();
|
|
351
|
+
const head = new THREE.Vector3();
|
|
352
|
+
function frame(tm, dt) {
|
|
353
|
+
const s = dt / 1000;
|
|
354
|
+
const a = camera.aspect;
|
|
355
|
+
env.tick(tm, dt);
|
|
356
|
+
let moving = false;
|
|
357
|
+
// controlado con teclas / cruceta (relativo a la cámara)
|
|
358
|
+
if (mode === 'ctl' && keys.size && !hop) {
|
|
359
|
+
if (seated) { run(async (dead) => { await guard(dead)(leaveSeat()); }); }
|
|
360
|
+
else {
|
|
361
|
+
camera.getWorldDirection(fwd); fwd.y = 0; fwd.normalize();
|
|
362
|
+
right.crossVectors(fwd, camera.up).normalize();
|
|
363
|
+
tmp.set(0, 0, 0);
|
|
364
|
+
if (keys.has('up')) tmp.add(fwd);
|
|
365
|
+
if (keys.has('down')) tmp.sub(fwd);
|
|
366
|
+
if (keys.has('right')) tmp.add(right);
|
|
367
|
+
if (keys.has('left')) tmp.sub(right);
|
|
368
|
+
if (tmp.lengthSq() > 0) {
|
|
369
|
+
if (job && nav) { job++; nav = null; ch.mood('neutral'); doing(t('room.you')); }
|
|
370
|
+
tmp.normalize().multiplyScalar(2.1 * s);
|
|
371
|
+
if (!blocked(pos.x + tmp.x, pos.z)) pos.x += tmp.x;
|
|
372
|
+
if (!blocked(pos.x, pos.z + tmp.z)) pos.z += tmp.z;
|
|
373
|
+
wantHeading = Math.atan2(tmp.x, tmp.z);
|
|
374
|
+
moving = true;
|
|
375
|
+
speedK = 1.4;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (hop) {
|
|
380
|
+
const k = Math.min(1, (performance.now() - hop.t0) / hop.ms);
|
|
381
|
+
const e = k < 0.5 ? 2 * k * k : 1 - (-2 * k + 2) ** 2 / 2;
|
|
382
|
+
pos.x = THREE.MathUtils.lerp(hop.from.x, hop.to.x, e);
|
|
383
|
+
pos.z = THREE.MathUtils.lerp(hop.from.z, hop.to.z, e);
|
|
384
|
+
baseY = THREE.MathUtils.lerp(hop.from.y, hop.to.y, e) + Math.sin(Math.PI * k) * 0.55;
|
|
385
|
+
if (k > 0.05 && k < 0.6) wantHeading = Math.atan2(hop.to.x - hop.from.x, hop.to.z - hop.from.z) || wantHeading;
|
|
386
|
+
if (k >= 1) { const r = hop.res; baseY = hop.to.y; hop = null; r(); }
|
|
387
|
+
} else if (nav && !moving) {
|
|
388
|
+
const dx = nav.x - pos.x, dz = nav.z - pos.z, d = Math.hypot(dx, dz);
|
|
389
|
+
const step = Math.min(d, 1.5 * nav.sp * s);
|
|
390
|
+
if (d < 0.04) { const r = nav.res; nav = null; r(); }
|
|
391
|
+
else {
|
|
392
|
+
pos.x += (dx / d) * step; pos.z += (dz / d) * step;
|
|
393
|
+
wantHeading = Math.atan2(dx, dz);
|
|
394
|
+
moving = true;
|
|
395
|
+
speedK = nav.sp;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
walking += ((moving ? 1 : 0) - walking) * Math.min(1, s * 10);
|
|
399
|
+
bob += s * 11 * speedK;
|
|
400
|
+
heading = angTo(heading, wantHeading, Math.min(1, s * 9));
|
|
401
|
+
const lift = Math.abs(Math.sin(bob)) * 0.08 * walking;
|
|
402
|
+
ch.root.position.set(pos.x, baseY + lift, pos.z);
|
|
403
|
+
ch.root.rotation.set(0, heading, Math.sin(bob) * 0.07 * walking);
|
|
404
|
+
if (ch.shadow) { ch.shadow.position.y = 0.002 - lift / ch.root.scale.y; ch.shadow.material.opacity = 1 - Math.min(0.7, lift * 4); }
|
|
405
|
+
ch.tick(tm, dt);
|
|
406
|
+
ch.lod(Math.min(320, H0 * 0.35));
|
|
407
|
+
// cámara: encuadra la pieza y sigue un poco al ot (más en vertical)
|
|
408
|
+
const follow = a < 1 ? 0.75 : 0.3;
|
|
409
|
+
const goal = tmp.set(THREE.MathUtils.lerp(-0.3, pos.x, follow), 0.5, THREE.MathUtils.lerp(-0.6, pos.z, follow));
|
|
410
|
+
camT.lerp(goal, Math.min(1, s * 2.5));
|
|
411
|
+
const dist = a < 1 ? 10.5 : opts.compact ? 11.4 : 12.6;
|
|
412
|
+
camera.position.set(camT.x + dist * 0.42, camT.y + dist * 0.62, camT.z + dist * 0.66);
|
|
413
|
+
camera.lookAt(camT);
|
|
414
|
+
renderer.render(scene, camera);
|
|
415
|
+
// burbuja sobre la cabeza
|
|
416
|
+
if (!bubble.hidden) {
|
|
417
|
+
if (performance.now() > bubbleUntil) bubble.hidden = true;
|
|
418
|
+
head.set(0, ch.H * 1.12, 0).applyMatrix4(ch.root.matrixWorld).project(camera);
|
|
419
|
+
bubble.style.left = `${((head.x + 1) / 2) * W0}px`;
|
|
420
|
+
bubble.style.top = `${((1 - head.y) / 2) * H0}px`;
|
|
421
|
+
}
|
|
422
|
+
// a qué puedes jugar aquí (modo control)
|
|
423
|
+
if (mode === 'ctl') {
|
|
424
|
+
const k = !nav && !hop && near();
|
|
425
|
+
const txt = seated ? t('room.getOff') : k ? t('room.use', { label: t(`room.places.${k}`) }) : '';
|
|
426
|
+
const pr = $('[data-prompt]');
|
|
427
|
+
if (pr.textContent !== txt) pr.textContent = txt;
|
|
428
|
+
pr.hidden = !txt;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// bucle: se duerme fuera de pantalla o con la pestaña oculta
|
|
433
|
+
let raf = 0, lastT = 0, onScreen = true, dead = false;
|
|
434
|
+
const loop = (tm) => {
|
|
435
|
+
raf = 0;
|
|
436
|
+
if (dead || !onScreen || document.hidden) return;
|
|
437
|
+
const dt = Math.min(100, lastT ? tm - lastT : 16);
|
|
438
|
+
lastT = tm;
|
|
439
|
+
resize();
|
|
440
|
+
frame(tm, dt);
|
|
441
|
+
raf = requestAnimationFrame(loop);
|
|
442
|
+
};
|
|
443
|
+
const wake = () => { if (!raf && !dead && onScreen && !document.hidden) { lastT = 0; raf = requestAnimationFrame(loop); } };
|
|
444
|
+
const io = new IntersectionObserver(([e]) => { onScreen = e.isIntersecting; wake(); }, { rootMargin: '64px' });
|
|
445
|
+
io.observe(el);
|
|
446
|
+
document.addEventListener('visibilitychange', wake);
|
|
447
|
+
|
|
448
|
+
build(spec);
|
|
449
|
+
resize();
|
|
450
|
+
autopilot(false);
|
|
451
|
+
wake();
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
el,
|
|
455
|
+
say,
|
|
456
|
+
message,
|
|
457
|
+
react,
|
|
458
|
+
setMode,
|
|
459
|
+
get mode() { return mode; },
|
|
460
|
+
setName(n) { name = n || 'ot'; $('[data-name]').textContent = name; },
|
|
461
|
+
setSpec(s) { const m = ch.moodName; build(s); ch.mood(m || 'neutral'); ch.gesture('celebrate'); },
|
|
462
|
+
/** Cambia el tipo de casa (ROOM_THEMES[].id); uno desconocido cae en 'cozy'. */
|
|
463
|
+
setTheme(id) { if (dead) return; applyTheme(id); wake(); },
|
|
464
|
+
get theme() { return env.id; },
|
|
465
|
+
destroy() {
|
|
466
|
+
dead = true;
|
|
467
|
+
job++;
|
|
468
|
+
cancelAnimationFrame(raf);
|
|
469
|
+
for (const id of timers) clearTimeout(id);
|
|
470
|
+
io.disconnect();
|
|
471
|
+
ro.disconnect();
|
|
472
|
+
removeEventListener('keydown', onKey);
|
|
473
|
+
removeEventListener('keyup', onKey);
|
|
474
|
+
removeEventListener('blur', clearKeys);
|
|
475
|
+
document.removeEventListener('visibilitychange', wake);
|
|
476
|
+
ch.dispose();
|
|
477
|
+
scene.remove(ch.root);
|
|
478
|
+
disposeTree(scene);
|
|
479
|
+
envTarget.dispose();
|
|
480
|
+
renderer.dispose();
|
|
481
|
+
renderer.forceContextLoss?.();
|
|
482
|
+
canvas.remove();
|
|
483
|
+
box.remove();
|
|
484
|
+
el.classList.remove('otr', 'compact');
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
}
|
package/src/character3d/stage.js
CHANGED
|
@@ -50,7 +50,8 @@ class Stage {
|
|
|
50
50
|
(opts.parent || document.body).appendChild(canvas);
|
|
51
51
|
this.canvas = canvas;
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// preserve: deja leer el canvas fuera de su cuadro (la plaza saca selfies y clips de él)
|
|
54
|
+
const r = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance', preserveDrawingBuffer: !!opts.preserve });
|
|
54
55
|
r.setPixelRatio(this.dpr);
|
|
55
56
|
r.outputColorSpace = THREE.SRGBColorSpace;
|
|
56
57
|
r.toneMapping = THREE.NeutralToneMapping;
|
|
@@ -117,6 +118,14 @@ class Stage {
|
|
|
117
118
|
this.visible.delete(view);
|
|
118
119
|
this.io.unobserve(view.el);
|
|
119
120
|
delete view.el.__ots3dView;
|
|
121
|
+
if (!this.visible.size) this.clear();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Borra el canvas: sin vistas el bucle se duerme, y el último cuadro quedaría pegado encima de la página. */
|
|
125
|
+
clear() {
|
|
126
|
+
this.sleep();
|
|
127
|
+
this.renderer.setScissorTest(false);
|
|
128
|
+
this.renderer.clear();
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
wake() {
|
|
@@ -144,7 +153,10 @@ class Stage {
|
|
|
144
153
|
|
|
145
154
|
frame(t) {
|
|
146
155
|
this.raf = 0;
|
|
147
|
-
if (document.hidden
|
|
156
|
+
if (document.hidden) return;
|
|
157
|
+
// una vista cuyo elemento salió del DOM sin destroy() (la vista cambió por innerHTML) no se dibuja más
|
|
158
|
+
for (const v of this.visible) if (!v.el.isConnected) this.visible.delete(v);
|
|
159
|
+
if (!this.visible.size) return this.clear();
|
|
148
160
|
const dt = Math.min(64, Math.max(0, t - this.last));
|
|
149
161
|
this.last = t;
|
|
150
162
|
const t0 = performance.now();
|