@muvtacode/cli 0.1.9 → 0.1.11

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.
Files changed (93) hide show
  1. package/README.md +175 -147
  2. package/dist/agent/loop.js +4 -1
  3. package/dist/agent/loop.js.map +1 -1
  4. package/dist/agent/prompt.js +101 -0
  5. package/dist/agent/prompt.js.map +1 -1
  6. package/dist/cli.js +103 -0
  7. package/dist/cli.js.map +1 -1
  8. package/dist/commands/index.js +28 -0
  9. package/dist/commands/index.js.map +1 -1
  10. package/dist/i18n/en.js +4 -0
  11. package/dist/i18n/en.js.map +1 -1
  12. package/dist/i18n/pt.js +4 -0
  13. package/dist/i18n/pt.js.map +1 -1
  14. package/dist/remote/claudeSessions.js +82 -0
  15. package/dist/remote/claudeSessions.js.map +1 -0
  16. package/dist/remote/host.js +607 -0
  17. package/dist/remote/host.js.map +1 -0
  18. package/dist/remote/passagem.js +558 -0
  19. package/dist/remote/passagem.js.map +1 -0
  20. package/dist/remote/pastas.js +156 -0
  21. package/dist/remote/pastas.js.map +1 -0
  22. package/dist/state/templates.js +43 -10
  23. package/dist/state/templates.js.map +1 -1
  24. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.mtl +42 -0
  25. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.obj +1472 -0
  26. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.mtl +12 -0
  27. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.obj +890 -0
  28. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/LICENCA.txt +25 -0
  29. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.mtl +52 -0
  30. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.obj +1444 -0
  31. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.mtl +32 -0
  32. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.obj +1789 -0
  33. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.mtl +32 -0
  34. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.obj +1273 -0
  35. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.mtl +32 -0
  36. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.obj +485 -0
  37. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.mtl +42 -0
  38. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.obj +1589 -0
  39. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.mtl +12 -0
  40. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.obj +309 -0
  41. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.mtl +52 -0
  42. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.obj +1681 -0
  43. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.mtl +42 -0
  44. package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.obj +1275 -0
  45. package/dist/templates/game/adapt-assets-3d-01/files/src/assets/modelos.ts +270 -0
  46. package/dist/templates/game/adapt-assets-3d-01/meta.json +30 -0
  47. package/dist/templates/game/adapt-audio-01/files/src/audio/audio.ts +123 -6
  48. package/dist/templates/game/adapt-audio-01/meta.json +47 -34
  49. package/dist/templates/game/adapt-camera-rig-01/files/src/camera/rig.ts +226 -55
  50. package/dist/templates/game/adapt-camera-rig-01/meta.json +53 -38
  51. package/dist/templates/game/adapt-controle-teclado-01/files/src/controles/teclado.ts +175 -171
  52. package/dist/templates/game/adapt-controle-teclado-01/meta.json +36 -34
  53. package/dist/templates/game/adapt-controle-toque-01/files/src/controles/toque.ts +152 -36
  54. package/dist/templates/game/adapt-controle-toque-01/meta.json +43 -36
  55. package/dist/templates/game/adapt-dia-noite-01/files/src/world/dianoite.ts +274 -53
  56. package/dist/templates/game/adapt-dia-noite-01/meta.json +21 -9
  57. package/dist/templates/game/adapt-hud-01/files/src/hud/hud.ts +859 -263
  58. package/dist/templates/game/adapt-hud-01/meta.json +69 -36
  59. package/dist/templates/game/adapt-menu-01/files/src/ui/menu.ts +427 -273
  60. package/dist/templates/game/adapt-menu-01/meta.json +41 -36
  61. package/dist/templates/game/adapt-particulas-01/files/src/vfx/particulas.ts +107 -39
  62. package/dist/templates/game/adapt-particulas-01/meta.json +50 -38
  63. package/dist/templates/game/adapt-perf-mobile-01/files/src/engine/performance.ts +108 -33
  64. package/dist/templates/game/adapt-perf-mobile-01/meta.json +20 -6
  65. package/dist/templates/game/adapt-primeira-pessoa-01/files/src/camera/primeirapessoa.ts +595 -0
  66. package/dist/templates/game/adapt-primeira-pessoa-01/meta.json +63 -0
  67. package/dist/templates/game/estruturas-3d-01/files/src/world/estruturas.ts +490 -0
  68. package/dist/templates/game/estruturas-3d-01/meta.json +13 -0
  69. package/dist/templates/game/fps-3d-01/files/src/fps/arena.ts +324 -0
  70. package/dist/templates/game/fps-3d-01/files/src/fps/armas.ts +398 -0
  71. package/dist/templates/game/fps-3d-01/files/src/fps/cena.ts +801 -0
  72. package/dist/templates/game/fps-3d-01/files/src/fps/coletaveis.ts +129 -0
  73. package/dist/templates/game/fps-3d-01/files/src/fps/fisica.ts +257 -0
  74. package/dist/templates/game/fps-3d-01/files/src/fps/inimigos.ts +608 -0
  75. package/dist/templates/game/fps-3d-01/files/src/fps/jogador.ts +224 -0
  76. package/dist/templates/game/fps-3d-01/files/src/main.ts +21 -0
  77. package/dist/templates/game/fps-3d-01/meta.json +48 -0
  78. package/dist/templates/game/game-engine-base-01/files/index.html +37 -0
  79. package/dist/templates/game/game-engine-base-01/files/package.json +19 -0
  80. package/dist/templates/game/game-engine-base-01/files/src/engine/engine.ts +22 -2
  81. package/dist/templates/game/game-engine-base-01/files/src/engine/index.ts +22 -2
  82. package/dist/templates/game/game-engine-base-01/files/src/engine/input.ts +430 -58
  83. package/dist/templates/game/game-engine-base-01/files/src/engine/layout.ts +192 -0
  84. package/dist/templates/game/game-engine-base-01/files/tsconfig.json +14 -0
  85. package/dist/templates/game/game-engine-base-01/files/vite.config.ts +10 -0
  86. package/dist/templates/game/game-engine-base-01/meta.json +70 -13
  87. package/dist/templates/game/mundo-3d-01/files/src/world/mundo3d.ts +2953 -73
  88. package/dist/templates/game/mundo-3d-01/meta.json +125 -6
  89. package/dist/templates/game/npc-3d-01/files/src/ai/npc3d.ts +658 -0
  90. package/dist/templates/game/npc-3d-01/meta.json +13 -0
  91. package/dist/templates/game/personagem-3d-01/files/src/models/personagem3d.ts +428 -107
  92. package/dist/templates/game/personagem-3d-01/meta.json +60 -6
  93. package/package.json +2 -1
@@ -0,0 +1,129 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Coletáveis: munição e vida que os drones derrubam.
3
+ //
4
+ // É o que fecha o laço do combate: matar rende recurso, e o recurso cai ONDE o
5
+ // inimigo morreu — o jogador é puxado de volta para a briga em vez de acampar
6
+ // num canto. Brilham, giram e flutuam: item parado no chão escuro ninguém vê.
7
+ // ---------------------------------------------------------------------------
8
+
9
+ import * as THREE from 'three';
10
+ import { getPalette } from '../design/tokens';
11
+ import type { PontoMinimapa } from '../hud/hud';
12
+
13
+ export type TipoColetavel = 'municao' | 'vida';
14
+
15
+ export const tuning = {
16
+ /** Distância (m) para pegar. */
17
+ raioColeta: 1.4,
18
+ /** Some depois de tantos segundos (pisca nos últimos 3). */
19
+ duracao: 20,
20
+ maximo: 12
21
+ };
22
+
23
+ interface Item {
24
+ tipo: TipoColetavel;
25
+ grupo: THREE.Group;
26
+ vida: number;
27
+ ativo: boolean;
28
+ fase: number;
29
+ }
30
+
31
+ export interface Coletaveis {
32
+ raiz: THREE.Group;
33
+ soltar(tipo: TipoColetavel, pos: THREE.Vector3): void;
34
+ /** `aoPegar` devolve false quando o jogador não precisa (vida cheia): o item fica. */
35
+ atualizar(passo: number, posJogador: THREE.Vector3, aoPegar: (tipo: TipoColetavel) => boolean): void;
36
+ /** Acrescenta os itens ativos ao minimapa. */
37
+ pontos(saida: PontoMinimapa[]): void;
38
+ aplicarPaleta(): void;
39
+ limpar(): void;
40
+ dispose(): void;
41
+ }
42
+
43
+ export function criarColetaveis(): Coletaveis {
44
+ const raiz = new THREE.Group();
45
+ raiz.name = 'coletaveis';
46
+ const geoCaixa = new THREE.BoxGeometry(0.42, 0.26, 0.56);
47
+ const geoFaixa = new THREE.BoxGeometry(0.44, 0.06, 0.58);
48
+ const geoBarra = new THREE.BoxGeometry(0.16, 0.5, 0.16);
49
+ const geoBarraH = new THREE.BoxGeometry(0.5, 0.16, 0.16);
50
+ const matMunicao = new THREE.MeshStandardMaterial({ roughness: 0.5, metalness: 0.3 });
51
+ const matFaixa = new THREE.MeshBasicMaterial();
52
+ const matVida = new THREE.MeshBasicMaterial();
53
+
54
+ const aplicarPaleta = (): void => {
55
+ const p = getPalette();
56
+ matMunicao.color.set(p.secundaria).lerp(new THREE.Color(p.superficie), 0.35);
57
+ matFaixa.color.set(p.aviso);
58
+ matVida.color.set(p.sucesso);
59
+ };
60
+ aplicarPaleta();
61
+
62
+ const itens: Item[] = Array.from({ length: tuning.maximo }, (_, i) => {
63
+ const grupo = new THREE.Group();
64
+ grupo.visible = false;
65
+ raiz.add(grupo);
66
+ return { tipo: i % 2 === 0 ? 'municao' : 'vida', grupo, vida: 0, ativo: false, fase: 0 };
67
+ });
68
+
69
+ /** (Re)monta a malha do item conforme o tipo — o pool é misto. */
70
+ const vestir = (it: Item, tipo: TipoColetavel): void => {
71
+ it.tipo = tipo;
72
+ it.grupo.clear();
73
+ if (tipo === 'municao') {
74
+ it.grupo.add(new THREE.Mesh(geoCaixa, matMunicao), new THREE.Mesh(geoFaixa, matFaixa));
75
+ } else {
76
+ // Cruz: lê como "vida" em qualquer idioma.
77
+ it.grupo.add(new THREE.Mesh(geoBarra, matVida), new THREE.Mesh(geoBarraH, matVida));
78
+ }
79
+ };
80
+
81
+ return {
82
+ raiz,
83
+ soltar(tipo, pos) {
84
+ const it = itens.find((x) => !x.ativo) ?? itens.reduce((a, b) => (a.vida < b.vida ? a : b));
85
+ vestir(it, tipo);
86
+ it.ativo = true;
87
+ it.vida = tuning.duracao;
88
+ it.fase = Math.random() * Math.PI * 2;
89
+ it.grupo.position.set(pos.x, 0.6, pos.z);
90
+ it.grupo.visible = true;
91
+ },
92
+ atualizar(passo, posJogador, aoPegar) {
93
+ for (const it of itens) {
94
+ if (!it.ativo) continue;
95
+ it.vida -= passo;
96
+ it.fase += passo;
97
+ if (it.vida <= 0) { it.ativo = false; it.grupo.visible = false; continue; }
98
+ it.grupo.rotation.y += passo * 1.6;
99
+ it.grupo.position.y = 0.6 + Math.sin(it.fase * 2.4) * 0.12;
100
+ // Pisca no fim: avisa que vai sumir.
101
+ it.grupo.visible = it.vida > 3 || Math.sin(it.fase * 18) > 0;
102
+ const dx = it.grupo.position.x - posJogador.x;
103
+ const dz = it.grupo.position.z - posJogador.z;
104
+ if (dx * dx + dz * dz <= tuning.raioColeta * tuning.raioColeta && aoPegar(it.tipo)) {
105
+ it.ativo = false;
106
+ it.grupo.visible = false;
107
+ }
108
+ }
109
+ },
110
+ pontos(saida) {
111
+ const p = getPalette();
112
+ for (const it of itens) {
113
+ if (!it.ativo) continue;
114
+ saida.push({
115
+ x: it.grupo.position.x, z: it.grupo.position.z,
116
+ cor: it.tipo === 'vida' ? p.sucesso : p.aviso, forma: 'alvo', tamanho: 3
117
+ });
118
+ }
119
+ },
120
+ aplicarPaleta,
121
+ limpar() {
122
+ for (const it of itens) { it.ativo = false; it.grupo.visible = false; }
123
+ },
124
+ dispose() {
125
+ [geoCaixa, geoFaixa, geoBarra, geoBarraH].forEach((g) => g.dispose());
126
+ [matMunicao, matFaixa, matVida].forEach((m) => m.dispose());
127
+ }
128
+ };
129
+ }
@@ -0,0 +1,257 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Física mínima de FPS: tudo é CAIXA alinhada aos eixos.
3
+ //
4
+ // Por que não um motor de física (cannon, rapier): num FPS de arena o que
5
+ // importa é andar sem atravessar parede, subir degrau, pousar em plataforma e
6
+ // saber o que a bala acertou. Com o cenário feito de caixas, isso é aritmética
7
+ // barata — dezenas de caixas a 60 passos por segundo custam nada até no
8
+ // celular, e não há biblioteca de 1 MB para baixar.
9
+ //
10
+ // O mesmo `caixas[]` serve para TRÊS coisas, e é por isso que ele mora aqui:
11
+ // 1. colisão do jogador (moverCorpo) e dos drones (empurrarEsfera);
12
+ // 2. tiro (raioCenario) — a bala para na primeira parede;
13
+ // 3. linha de visada (linhaLivre) — inimigo não te vê através do pilar.
14
+ // Trocar a arena por um mapa seu é trocar a lista de caixas.
15
+ // ---------------------------------------------------------------------------
16
+
17
+ import * as THREE from 'three';
18
+
19
+ const EPS = 1e-6;
20
+ const _n = new THREE.Vector3();
21
+
22
+ /** Onde e como um raio bateu no cenário. */
23
+ export interface Batida {
24
+ distancia: number;
25
+ ponto: THREE.Vector3;
26
+ /** Normal da face atingida (para o impacto espirrar para fora dela). */
27
+ normal: THREE.Vector3;
28
+ }
29
+
30
+ export const novaBatida = (): Batida => ({
31
+ distancia: 0,
32
+ ponto: new THREE.Vector3(),
33
+ normal: new THREE.Vector3()
34
+ });
35
+
36
+ /**
37
+ * Raio contra caixa (método das lajes). Devolve a distância de ENTRADA e
38
+ * preenche `normal` com a face atingida; null se não bate até `max`. Raio que
39
+ * nasce dentro da caixa é ignorado — é o que impede a bala de "acertar" a
40
+ * parede em que o cano encostou.
41
+ */
42
+ export function raioCaixa(
43
+ o: THREE.Vector3, d: THREE.Vector3, c: THREE.Box3, max: number, normal?: THREE.Vector3
44
+ ): number | null {
45
+ let tmin = 0;
46
+ let tmax = max;
47
+ let eixo = -1;
48
+ let sinal = 0;
49
+ for (let i = 0; i < 3; i++) {
50
+ const oi = i === 0 ? o.x : i === 1 ? o.y : o.z;
51
+ const di = i === 0 ? d.x : i === 1 ? d.y : d.z;
52
+ const mn = i === 0 ? c.min.x : i === 1 ? c.min.y : c.min.z;
53
+ const mx = i === 0 ? c.max.x : i === 1 ? c.max.y : c.max.z;
54
+ if (Math.abs(di) < EPS) {
55
+ if (oi < mn || oi > mx) return null; // paralelo e fora da laje
56
+ continue;
57
+ }
58
+ const inv = 1 / di;
59
+ let t1 = (mn - oi) * inv;
60
+ let t2 = (mx - oi) * inv;
61
+ // Entrando pela face mínima, a normal aponta para o lado negativo do eixo.
62
+ let s = -1;
63
+ if (t1 > t2) { const t = t1; t1 = t2; t2 = t; s = 1; }
64
+ if (t1 > tmin) { tmin = t1; eixo = i; sinal = s; }
65
+ if (t2 < tmax) tmax = t2;
66
+ if (tmin > tmax) return null;
67
+ }
68
+ if (eixo < 0) return null;
69
+ normal?.set(eixo === 0 ? sinal : 0, eixo === 1 ? sinal : 0, eixo === 2 ? sinal : 0);
70
+ return tmin;
71
+ }
72
+
73
+ /**
74
+ * Primeiro obstáculo no caminho do raio: caixas + chão (y = 0). `d` precisa
75
+ * estar normalizado. Preenche `saida` e devolve true se bateu antes de `max`.
76
+ */
77
+ export function raioCenario(
78
+ o: THREE.Vector3, d: THREE.Vector3, max: number, caixas: readonly THREE.Box3[], saida: Batida
79
+ ): boolean {
80
+ let melhor = max;
81
+ let bateu = false;
82
+ for (const c of caixas) {
83
+ const t = raioCaixa(o, d, c, melhor, _n);
84
+ if (t !== null && t < melhor) {
85
+ melhor = t;
86
+ saida.normal.copy(_n);
87
+ bateu = true;
88
+ }
89
+ }
90
+ if (d.y < -EPS && o.y > 0) {
91
+ const t = -o.y / d.y;
92
+ if (t < melhor) {
93
+ melhor = t;
94
+ saida.normal.set(0, 1, 0);
95
+ bateu = true;
96
+ }
97
+ }
98
+ if (!bateu) return false;
99
+ saida.distancia = melhor;
100
+ saida.ponto.copy(o).addScaledVector(d, melhor);
101
+ return true;
102
+ }
103
+
104
+ const _dir = new THREE.Vector3();
105
+ /** true se nada do cenário fica entre `a` e `b` (linha de visada / tiro inimigo). */
106
+ export function linhaLivre(a: THREE.Vector3, b: THREE.Vector3, caixas: readonly THREE.Box3[]): boolean {
107
+ _dir.subVectors(b, a);
108
+ const dist = _dir.length();
109
+ if (dist < EPS) return true;
110
+ _dir.divideScalar(dist);
111
+ for (const c of caixas) {
112
+ if (raioCaixa(a, _dir, c, dist) !== null) return false;
113
+ }
114
+ return true;
115
+ }
116
+
117
+ /** Distância até a esfera ao longo do raio (d normalizado), ou null. */
118
+ export function raioEsfera(
119
+ o: THREE.Vector3, d: THREE.Vector3, centro: THREE.Vector3, raio: number, max: number
120
+ ): number | null {
121
+ const ox = o.x - centro.x, oy = o.y - centro.y, oz = o.z - centro.z;
122
+ const b = ox * d.x + oy * d.y + oz * d.z;
123
+ const c = ox * ox + oy * oy + oz * oz - raio * raio;
124
+ const disc = b * b - c;
125
+ if (disc < 0) return null;
126
+ const raiz = Math.sqrt(disc);
127
+ let t = -b - raiz;
128
+ if (t < 0) t = -b + raiz; // origem dentro da esfera
129
+ return t >= 0 && t <= max ? t : null;
130
+ }
131
+
132
+ // --------------------------------------------------------------- personagem
133
+
134
+ /** Corpo do jogador: cilindro aproximado por caixa de pé (pés em `pos`). */
135
+ export interface Corpo {
136
+ pos: THREE.Vector3;
137
+ vel: THREE.Vector3;
138
+ raio: number;
139
+ altura: number;
140
+ noChao: boolean;
141
+ }
142
+
143
+ const sobrepoe = (x: number, y: number, z: number, r: number, h: number, b: THREE.Box3): boolean =>
144
+ x + r > b.min.x && x - r < b.max.x &&
145
+ z + r > b.min.z && z - r < b.max.z &&
146
+ y + h > b.min.y && y < b.max.y;
147
+
148
+ /** Há espaço para o corpo inteiro neste ponto? (usado para levantar do agachado). */
149
+ export function espacoLivre(
150
+ x: number, y: number, z: number, r: number, h: number, caixas: readonly THREE.Box3[]
151
+ ): boolean {
152
+ for (const b of caixas) if (sobrepoe(x, y, z, r, h, b)) return false;
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * Move o corpo eixo por eixo resolvendo colisão. X e Z primeiro (com SUBIDA
158
+ * DE DEGRAU: obstáculo até `degrau` de altura é escalado em vez de bloquear —
159
+ * é o que faz escada de caixas funcionar sem rampa), depois Y (pouso no topo
160
+ * de caixa, cabeçada no teto, chão em y = 0).
161
+ *
162
+ * Eixo por eixo é o que deixa o jogador DESLIZAR na parede em vez de grudar:
163
+ * bater de quina trava só o eixo que bateu.
164
+ */
165
+ export function moverCorpo(c: Corpo, passo: number, caixas: readonly THREE.Box3[], degrau: number): void {
166
+ const p = c.pos;
167
+ const v = c.vel;
168
+ const r = c.raio;
169
+ const h = c.altura;
170
+
171
+ // ---- X
172
+ let nx = p.x + v.x * passo;
173
+ for (const b of caixas) {
174
+ if (!sobrepoe(nx, p.y, p.z, r, h, b)) continue;
175
+ const subida = b.max.y - p.y;
176
+ if (c.noChao && subida > 0 && subida <= degrau && espacoLivre(nx, b.max.y + 0.002, p.z, r, h, caixas)) {
177
+ p.y = b.max.y + 0.002;
178
+ continue;
179
+ }
180
+ nx = v.x > 0 ? b.min.x - r - 1e-4 : b.max.x + r + 1e-4;
181
+ v.x = 0;
182
+ }
183
+ p.x = nx;
184
+
185
+ // ---- Z
186
+ let nz = p.z + v.z * passo;
187
+ for (const b of caixas) {
188
+ if (!sobrepoe(p.x, p.y, nz, r, h, b)) continue;
189
+ const subida = b.max.y - p.y;
190
+ if (c.noChao && subida > 0 && subida <= degrau && espacoLivre(p.x, b.max.y + 0.002, nz, r, h, caixas)) {
191
+ p.y = b.max.y + 0.002;
192
+ continue;
193
+ }
194
+ nz = v.z > 0 ? b.min.z - r - 1e-4 : b.max.z + r + 1e-4;
195
+ v.z = 0;
196
+ }
197
+ p.z = nz;
198
+
199
+ // ---- Y
200
+ let ny = p.y + v.y * passo;
201
+ let noChao = false;
202
+ if (ny <= 0) {
203
+ ny = 0;
204
+ if (v.y < 0) v.y = 0;
205
+ noChao = true;
206
+ }
207
+ for (const b of caixas) {
208
+ if (!sobrepoe(p.x, ny, p.z, r, h, b)) continue;
209
+ if (v.y <= 0 && p.y >= b.max.y - 0.06) {
210
+ ny = b.max.y; // pousou no topo
211
+ v.y = 0;
212
+ noChao = true;
213
+ } else if (v.y > 0) {
214
+ ny = b.min.y - h - 1e-4; // cabeçada
215
+ v.y = 0;
216
+ }
217
+ }
218
+ p.y = ny;
219
+ c.noChao = noChao;
220
+ }
221
+
222
+ const _maisPerto = new THREE.Vector3();
223
+ /**
224
+ * Tira uma esfera de dentro das caixas e do chão (colisão dos drones).
225
+ * Devolve true se precisou empurrar — o drone usa isso para desviar.
226
+ */
227
+ export function empurrarEsfera(pos: THREE.Vector3, raio: number, caixas: readonly THREE.Box3[]): boolean {
228
+ let empurrou = false;
229
+ if (pos.y < raio) { pos.y = raio; empurrou = true; }
230
+ for (const b of caixas) {
231
+ b.clampPoint(pos, _maisPerto);
232
+ const dx = pos.x - _maisPerto.x, dy = pos.y - _maisPerto.y, dz = pos.z - _maisPerto.z;
233
+ const d2 = dx * dx + dy * dy + dz * dz;
234
+ if (d2 >= raio * raio) continue;
235
+ empurrou = true;
236
+ if (d2 > EPS) {
237
+ const d = Math.sqrt(d2);
238
+ const k = (raio - d) / d;
239
+ pos.x += dx * k; pos.y += dy * k; pos.z += dz * k;
240
+ } else {
241
+ // Centro DENTRO da caixa: sai pela face mais próxima.
242
+ const saidas = [
243
+ pos.x - b.min.x, b.max.x - pos.x, pos.y - b.min.y,
244
+ b.max.y - pos.y, pos.z - b.min.z, b.max.z - pos.z
245
+ ];
246
+ let i = 0;
247
+ for (let k = 1; k < 6; k++) if (saidas[k]! < saidas[i]!) i = k;
248
+ if (i === 0) pos.x = b.min.x - raio;
249
+ else if (i === 1) pos.x = b.max.x + raio;
250
+ else if (i === 2) pos.y = b.min.y - raio;
251
+ else if (i === 3) pos.y = b.max.y + raio;
252
+ else if (i === 4) pos.z = b.min.z - raio;
253
+ else pos.z = b.max.z + raio;
254
+ }
255
+ }
256
+ return empurrou;
257
+ }