/** * Atuendos 3D de los personajes: convierten el cuerpo-esfera en el emoji que representa * (👵 pelo con moño y gafas, 🤠 sombrero y pañuelo, 👷 casco y chaleco, 👮 gorra y uniforme, 👨 pelo…) * con piezas modeladas, de plástico suave, sin texturas planas. * * Todas las piezas se construyen sobre una esfera de radio 0.5 centrada en el origen (frente = +z). */ import * as THREE from 'three'; import { toonMaterial } from '../render/materials'; export type OutfitId = | 'none' | 'backpack' | 'straps' | 'granny' | 'cowboy' | 'builder' | 'police' | 'man' | 'robot' | 'chef' | 'grandpa' | 'farmer' | 'sage' | 'elf' | 'wizard' | 'king'; export interface OutfitInst { group: THREE.Group; /** Color de los zapatos que impone el atuendo (botas, zapatos de uniforme…). */ foot?: number; /** Color de la suela. */ sole?: number; } const R = 0.5; const geos = new Map(); const mats = new Map(); function G(key: string, make: () => THREE.BufferGeometry): THREE.BufferGeometry { let g = geos.get(key); if (!g) { g = make(); g.userData.shared = true; geos.set(key, g); } return g; } function Mt(color: number, gloss = 0.65, extra: { emissive?: number; emissiveIntensity?: number; side?: THREE.Side } = {}): THREE.Material { const key = `${color}|${gloss}|${extra.emissive ?? 0}|${extra.emissiveIntensity ?? 0}|${extra.side ?? 0}`; let m = mats.get(key); if (!m) { m = toonMaterial({ color, gloss, rim: 0.5, ...extra }); m.userData.shared = true; mats.set(key, m); } return m; } function P(g: THREE.BufferGeometry, m: THREE.Material): THREE.Mesh { const o = new THREE.Mesh(g, m); o.castShadow = true; return o; } const sphere = () => G('sphere', () => new THREE.SphereGeometry(1, 28, 20)); const box = () => G('box', () => new THREE.BoxGeometry(1, 1, 1)); /** Casquete/banda de esfera: theta 0 = polo superior. phi centrado en el frente. */ function shell(r: number, th0: number, th1: number, width = Math.PI * 2): THREE.BufferGeometry { return G(`shell|${r}|${th0}|${th1}|${width}`, () => new THREE.SphereGeometry(r, 48, 14, Math.PI / 2 - width / 2, width, th0, th1 - th0)); } /** Parche libre sobre la esfera: fn(u ∈ [-1,1], t ∈ [0,1]) → [phi desde el frente, theta]. */ function patch(key: string, r: number, fn: (u: number, t: number) => [number, number], nu = 20, nt = 10): THREE.BufferGeometry { return G(`patch|${key}|${r}`, () => { const pos: number[] = []; const idx: number[] = []; for (let j = 0; j <= nt; j++) { for (let i = 0; i <= nu; i++) { const [phi, th] = fn((i / nu) * 2 - 1, j / nt); pos.push(Math.sin(phi) * Math.sin(th) * r, Math.cos(th) * r, Math.cos(phi) * Math.sin(th) * r); } } for (let j = 0; j < nt; j++) { for (let i = 0; i < nu; i++) { const a = j * (nu + 1) + i; const b = a + 1; const c = a + nu + 1; const d = c + 1; idx.push(a, c, b, b, c, d); } } const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setIndex(idx); g.computeVertexNormals(); return g; }); } /** Punto sobre la esfera por acimut (0 = frente, + = derecha del personaje en pantalla) y elevación. */ function at(az: number, el: number, r = R): THREE.Vector3 { return new THREE.Vector3(Math.sin(az) * Math.cos(el) * r, Math.sin(el) * r, Math.cos(az) * Math.cos(el) * r); } /** Coloca un objeto sobre la superficie mirando hacia fuera. */ function onto(o: THREE.Object3D, az: number, el: number, r = R): THREE.Object3D { o.position.copy(at(az, el, r)); o.lookAt(at(az, el, r * 2)); return o; } function starShape(): THREE.Shape { const s = new THREE.Shape(); for (let i = 0; i < 10; i++) { const a = (i / 10) * Math.PI * 2 + Math.PI / 2; const r = i % 2 === 0 ? 1 : 0.46; if (i === 0) s.moveTo(Math.cos(a) * r, Math.sin(a) * r); else s.lineTo(Math.cos(a) * r, Math.sin(a) * r); } s.closePath(); return s; } function shieldShape(): THREE.Shape { const s = new THREE.Shape(); s.moveTo(-0.8, 0.7); s.quadraticCurveTo(0, 1.05, 0.8, 0.7); s.quadraticCurveTo(0.85, -0.3, 0, -1); s.quadraticCurveTo(-0.85, -0.3, -0.8, 0.7); return s; } const extr = (key: string, shape: () => THREE.Shape, depth = 0.25) => G(`ex|${key}`, () => { const g = new THREE.ExtrudeGeometry(shape(), { depth, bevelEnabled: true, bevelSize: 0.08, bevelThickness: 0.08, bevelSegments: 2, curveSegments: 8 }); g.center(); return g; }); // ───────────────────────────── Piezas comunes ───────────────────────────── /** Correas de mochila con hebillas, como en las referencias. */ function straps(g: THREE.Group, color: number, buckle = 0xbfc3d6): void { const x = 0.355; const rr = Math.sqrt(R * R - x * x) + 0.01; const ring = G('strap', () => new THREE.TorusGeometry(rr, 0.027, 10, 44)); for (const side of [-1, 1]) { const s = P(ring, Mt(color, 0.55)); s.rotation.y = Math.PI / 2; s.scale.set(1, 1, 1.7); s.rotation.z = side * 0.0; s.position.x = side * x; g.add(s); const y = -0.17; const z = Math.sqrt(rr * rr - y * y); const b = new THREE.Group(); const frame = P(box(), Mt(buckle, 0.85)); frame.scale.set(0.115, 0.09, 0.045); const inner = P(box(), Mt(color, 0.55)); inner.scale.set(0.06, 0.04, 0.055); b.add(frame, inner); b.position.set(side * (x + 0.012), y, z + 0.012); b.lookAt(b.position.clone().multiplyScalar(2)); g.add(b); } } /** Sombrero de mago: ala ancha, copa cónica con la punta caída y cinta con emblema. */ function wizardHat(g: THREE.Group, color: number, trim: number, emblem: 'drop' | 'star'): void { const hat = new THREE.Group(); const brim = P(G('wizBrim', () => new THREE.CylinderGeometry(0.7, 0.74, 0.05, 40)), Mt(color, 0.45)); const low = P(G('wizConeLow', () => new THREE.CylinderGeometry(0.2, 0.36, 0.42, 24)), Mt(color, 0.45)); low.position.y = 0.22; const tip = P(G('wizConeTip', () => new THREE.ConeGeometry(0.2, 0.46, 24)), Mt(color, 0.45)); tip.position.set(0.1, 0.6, -0.02); tip.rotation.z = -0.55; const band = P(G('wizBand', () => new THREE.TorusGeometry(0.34, 0.035, 8, 32)), Mt(trim, 0.7)); band.rotation.x = Math.PI / 2; band.position.y = 0.06; hat.add(brim, low, tip, band); if (emblem === 'drop') { const d = P(sphere(), Mt(0x7fd8ff, 0.8, { emissive: 0x2fa8f5, emissiveIntensity: 0.6 })); d.scale.set(0.075, 0.075, 0.04); d.position.set(0, 0.12, 0.33); const dt = P(G('dropTip', () => new THREE.ConeGeometry(0.06, 0.1, 12)), Mt(0x7fd8ff, 0.8, { emissive: 0x2fa8f5, emissiveIntensity: 0.6 })); dt.position.set(0, 0.2, 0.33); hat.add(d, dt); } else { for (const [x, y, s] of [[0, 0.18, 0.07], [-0.14, 0.34, 0.045], [0.12, 0.42, 0.04]] as const) { const st = P(extr('star', starShape), Mt(trim, 0.9, { emissive: 0xffa800, emissiveIntensity: 0.4 })); st.scale.setScalar(s); st.position.set(x, y, 0.3 - y * 0.25); hat.add(st); } } hat.position.set(0, 0.36, -0.02); hat.rotation.x = -0.1; g.add(hat); } /** * Barba que CUELGA: gota alargada (torneada y aplanada) que nace bajo la boca y cae por delante del * cuerpo, con mechones en relieve y punta rizada. `len` = largo, `w` = ancho, `mustache` = bigote. */ function hangingBeard(g: THREE.Group, color: number, len: number, w: number, mustache = true): void { const key = `beard|${len}|${w}`; const geo = G(key, () => { const pts: THREE.Vector2[] = []; const n = 14; for (let i = 0; i <= n; i++) { const t = i / n; // ancha arriba, panza a un cuarto y punta fina const r = w * (0.82 + Math.sin(Math.min(1, t * 2.2) * Math.PI * 0.5) * 0.18) * Math.pow(1 - t, 0.75) + 0.012; pts.push(new THREE.Vector2(r, -t * len)); } return new THREE.LatheGeometry(pts, 20); }); const mat = Mt(color, 0.42); const beard = new THREE.Group(); const body = P(geo, mat); body.scale.set(1, 1, 0.42); beard.add(body); // lóbulos laterales más cortos: silueta ondulada de barba por capas for (const side of [-1, 1]) { const lobe = P(geo, mat); lobe.scale.set(0.62, 0.72, 0.36); lobe.position.set(side * w * 0.55, 0.01, -0.02); lobe.rotation.z = side * 0.12; beard.add(lobe); } // punta rizada const curl = P(G('beardCurl', () => new THREE.TorusGeometry(0.045, 0.02, 6, 14, Math.PI * 1.5)), mat); curl.position.set(0.03, -len + 0.03, 0); curl.rotation.z = 0.6; beard.add(curl); // nace bajo la boca, por delante, y cae vertical (un pelín hacia delante) // por DELANTE de la cara/túnica (la esfera mide 0,5): así cuelga libre y no se mete en el cuerpo beard.position.set(0, -0.17, 0.5); beard.rotation.x = -0.12; beard.name = 'beard'; g.add(beard); if (mustache) { for (const side of [-1, 1]) { const m = P(sphere(), mat); m.scale.set(0.12, 0.045, 0.055); m.position.copy(at(side * 0.13, -0.1, R + 0.03)); m.rotation.z = -side * 0.45; g.add(m); } } } function hairCap(g: THREE.Group, color: number, th: number, tilt: number, r = 0.522): THREE.Mesh { const cap = P(shell(r, 0, th), Mt(color, 0.5)); cap.rotation.x = tilt; g.add(cap); return cap; } // ───────────────────────────── Atuendos ───────────────────────────── export function buildOutfit(id: OutfitId): OutfitInst | null { if (id === 'none') return null; const g = new THREE.Group(); const out: OutfitInst = { group: g }; switch (id) { case 'straps': straps(g, 0x2f7ee6); break; case 'backpack': { const red = 0xe8352b; straps(g, red, 0xd9d3e6); const bag = P(sphere(), Mt(red, 0.55)); bag.scale.set(0.3, 0.3, 0.2); bag.position.set(0, -0.04, -0.5); const pocket = P(sphere(), Mt(0xd22a22, 0.55)); pocket.scale.set(0.2, 0.15, 0.1); pocket.position.set(0, -0.12, -0.66); // saco de dormir enrollado const roll = P(G('roll', () => new THREE.CylinderGeometry(0.115, 0.115, 0.54, 24)), Mt(0xf0483a, 0.5)); roll.rotation.z = Math.PI / 2; roll.position.set(0, 0.3, -0.46); g.add(bag, pocket, roll); for (const side of [-1, 1]) { for (const [rad, tube] of [[0.075, 0.022], [0.03, 0.02]] as const) { const sp = P(G(`rollEnd${rad}`, () => new THREE.TorusGeometry(rad, tube, 8, 20)), Mt(0xd22a22, 0.5)); sp.rotation.y = Math.PI / 2; sp.position.set(side * 0.275, 0.3, -0.46); g.add(sp); } } break; } case 'granny': { const gray = 0xc9c9d4; hairCap(g, gray, 1.28, -0.5); const bun = P(sphere(), Mt(gray, 0.5)); bun.scale.setScalar(0.2); bun.position.set(-0.06, 0.52, -0.24); const bun2 = P(sphere(), Mt(0xbdbdca, 0.5)); bun2.scale.setScalar(0.13); bun2.position.set(-0.06, 0.67, -0.28); g.add(bun, bun2); // mechones que enmarcan la frente // onda frontal: mechones gruesos que barren la frente de lado a lado const wave: Array<[number, number, number, number, number]> = [ [-0.37, 0.3, 0.2, 0.2, 0.95], [-0.2, 0.42, 0.25, 0.24, 0.5], [0.04, 0.48, 0.24, 0.25, 0.08], [0.26, 0.43, 0.19, 0.22, -0.45], [0.4, 0.31, 0.12, 0.18, -0.95], [-0.1, 0.54, 0.08, 0.26, 0.2], [0.16, 0.54, 0.05, 0.24, -0.2], ]; for (const [x, y, z, sx, rz] of wave) { const lock = P(sphere(), Mt(gray, 0.5)); lock.scale.set(sx, 0.125, 0.15); lock.position.set(x, y, z); lock.rotation.z = rz; g.add(lock); } for (const side of [-1, 1]) { const puff = P(sphere(), Mt(gray, 0.5)); puff.scale.set(0.12, 0.2, 0.17); puff.position.set(side * 0.47, 0.1, 0.0); g.add(puff); } // gafas redondas const purple = 0x7a4fd6; const rim = G('glassRim', () => new THREE.TorusGeometry(0.125, 0.017, 10, 32)); for (const side of [-1, 1]) { g.add(onto(P(rim, Mt(purple, 0.8)), side * 0.25, 0.17, R + 0.03)); const temple = P(G('temple', () => new THREE.CapsuleGeometry(0.013, 0.26, 4, 8)), Mt(purple, 0.8)); temple.rotation.x = Math.PI / 2; temple.position.set(side * 0.47, 0.1, 0.12); g.add(temple); } const bridge = P(G('bridge', () => new THREE.CapsuleGeometry(0.014, 0.05, 4, 8)), Mt(purple, 0.8)); bridge.rotation.z = Math.PI / 2; bridge.position.copy(at(0, 0.19, R + 0.04)); g.add(bridge); break; } case 'cowboy': { const brown = 0xa9602f; const hat = new THREE.Group(); const brim = P(G('cowBrim', () => { const geo = new THREE.CylinderGeometry(0.66, 0.66, 0.05, 40, 1); const p = geo.attributes.position; for (let i = 0; i < p.count; i++) { const x = p.getX(i); // alas laterales curvadas hacia arriba p.setY(i, p.getY(i) + Math.pow(Math.abs(x) / 0.66, 2.2) * 0.2); } geo.computeVertexNormals(); return geo; }), Mt(brown, 0.5)); const crown = P(sphere(), Mt(brown, 0.5)); crown.scale.set(0.33, 0.3, 0.3); crown.position.y = 0.16; const band = P(G('cowBand', () => new THREE.TorusGeometry(0.315, 0.035, 8, 32)), Mt(0x4a2a16, 0.5)); band.rotation.x = Math.PI / 2; band.position.y = 0.06; const star = P(extr('star', starShape), Mt(0xffc928, 0.9, { emissive: 0xffa800, emissiveIntensity: 0.25 })); star.scale.setScalar(0.1); star.position.set(0, 0.13, 0.31); hat.add(brim, crown, band, star); hat.position.set(0, 0.31, -0.02); hat.rotation.x = -0.16; g.add(hat); // pañuelo rojo const red = 0xe8352b; const scarf = P(patch('scarf', R + 0.016, (u, t) => [u * 0.95 * (1 - t * 0.96), 1.72 + t * 0.92]), Mt(red, 0.5, { side: THREE.DoubleSide })); const collar = P(shell(R + 0.014, 1.66, 1.82), Mt(red, 0.5)); g.add(scarf, collar); out.foot = 0x9a5526; out.sole = 0x6b3818; break; } case 'builder': { const yel = 0xffb81f; const helm = new THREE.Group(); helm.add(P(shell(0.54, 0, 1.2), Mt(yel, 0.85))); const ridge = P(G('ridge', () => new THREE.TorusGeometry(0.5, 0.05, 8, 24, Math.PI)), Mt(0xffc84a, 0.85)); ridge.rotation.y = Math.PI / 2; ridge.scale.set(1, 1.02, 1); helm.add(ridge); const rimY = 0.54 * Math.cos(1.2); const rimR = 0.54 * Math.sin(1.2); const rim = P(G('helmRim', () => new THREE.TorusGeometry(rimR + 0.004, 0.028, 8, 40)), Mt(yel, 0.85)); rim.rotation.x = Math.PI / 2; rim.position.y = rimY; const visor = P(G('helmVisor', () => new THREE.CylinderGeometry(rimR + 0.085, rimR + 0.085, 0.04, 32, 1, false, -0.6, 1.2)), Mt(yel, 0.85)); visor.position.set(0, rimY - 0.005, 0.03); helm.add(rim, visor); helm.rotation.x = -0.22; helm.position.y = 0.0; g.add(helm); // chaleco reflectante g.add(P(shell(R + 0.013, 1.78, 2.5), Mt(0xff7a1a, 0.5))); g.add(P(shell(R + 0.019, 1.92, 2.04), Mt(0xffe14a, 0.7, { emissive: 0xffd000, emissiveIntensity: 0.25 }))); g.add(P(shell(R + 0.019, 2.24, 2.36), Mt(0xffe14a, 0.7, { emissive: 0xffd000, emissiveIntensity: 0.25 }))); break; } case 'police': { const blue = 0x2f43d6; const cap = new THREE.Group(); const crown = P(G('capCrown', () => new THREE.LatheGeometry([ new THREE.Vector2(0.36, 0), new THREE.Vector2(0.4, 0.06), new THREE.Vector2(0.5, 0.2), new THREE.Vector2(0.48, 0.26), new THREE.Vector2(0.3, 0.3), new THREE.Vector2(0, 0.31), ], 40)), Mt(blue, 0.6)); const band = P(G('capBand', () => new THREE.CylinderGeometry(0.375, 0.375, 0.085, 40)), Mt(0x14141c, 0.9)); band.position.y = 0.035; const visor = P(G('capVisor', () => new THREE.CylinderGeometry(0.5, 0.5, 0.035, 32, 1, false, -0.85, 1.7)), Mt(0x14141c, 0.95)); visor.position.set(0, 0.0, 0.06); visor.rotation.x = 0.16; const badge = P(extr('shield', shieldShape), Mt(0xffc928, 0.9, { emissive: 0xffa800, emissiveIntensity: 0.3 })); badge.scale.setScalar(0.075); badge.position.set(0, 0.17, 0.46); badge.rotation.x = -0.45; cap.add(crown, band, visor, badge); cap.position.set(0, 0.27, -0.01); cap.rotation.x = -0.14; g.add(cap); // uniforme g.add(P(shell(R + 0.013, 1.62, 2.75), Mt(blue, 0.55))); g.add(P(shell(R + 0.02, 2.12, 2.27), Mt(0x14141c, 0.8))); const bk = P(box(), Mt(0xc9cfe0, 0.9)); bk.scale.set(0.1, 0.085, 0.03); g.add(onto(bk, 0, -0.62, R + 0.02)); const chest = P(extr('shield', shieldShape), Mt(0xffc928, 0.9, { emissive: 0xffa800, emissiveIntensity: 0.3 })); chest.scale.setScalar(0.05); g.add(onto(chest, 0.42, -0.32, R + 0.03)); // cuello de camisa for (const side of [-1, 1]) { const col = P(patch(`collar${side}`, R + 0.022, (u, t) => [side * (0.04 + (u + 1) * 0.11 * (1 - t)), 1.6 + t * 0.26], 6, 4), Mt(0x3a52e8, 0.55, { side: THREE.DoubleSide })); g.add(col); } out.foot = 0x1b1b24; out.sole = 0x0c0c12; break; } case 'man': { const brown = 0x7a4426; hairCap(g, brown, 1.02, -0.5); // flequillo despeinado hacia un lado const tuft = G('tuft', () => new THREE.ConeGeometry(0.11, 0.3, 10)); const tufts: Array<[number, number, number, number, number]> = [ [-0.3, 0.4, 0.2, 1.9, 0.9], [-0.12, 0.47, 0.22, 1.75, 0.5], [0.06, 0.5, 0.2, 1.7, 0.2], [0.24, 0.47, 0.14, 1.55, -0.3], [0.38, 0.38, 0.04, 1.4, -0.8], [0.0, 0.6, -0.08, 0.5, 0.5], [-0.2, 0.55, -0.1, 0.6, 0.9], ]; for (const [x, y, z, rx, rz] of tufts) { const t = P(tuft, Mt(brown, 0.5)); t.position.set(x, y, z); t.rotation.set(rx, 0, rz); g.add(t); } break; } case 'chef': { const white = 0xfdfdff; const hat = new THREE.Group(); const band = P(G('toqueBand', () => new THREE.CylinderGeometry(0.3, 0.31, 0.2, 32)), Mt(white, 0.4)); band.position.y = 0.1; hat.add(band); for (const [x, z, s] of [[0, 0, 0.26], [-0.2, 0.02, 0.2], [0.2, 0.02, 0.2], [0, -0.18, 0.2], [0, 0.18, 0.2]] as const) { const puff = P(sphere(), Mt(white, 0.4)); puff.scale.setScalar(s); puff.position.set(x, 0.3 + (s - 0.2) * 0.6, z); hat.add(puff); } hat.position.set(0, 0.4, -0.03); hat.rotation.x = -0.14; g.add(hat); // delantal g.add(P(patch('apron', R + 0.014, (u, t) => [u * 0.75, 1.75 + t * 0.95]), Mt(white, 0.4, { side: THREE.DoubleSide }))); g.add(P(shell(R + 0.012, 1.7, 1.8), Mt(0xe8352b, 0.5))); break; } case 'grandpa': { const gray = 0xc9c9d4; // corona de pelo a los lados y bigote for (const side of [-1, 1]) { const tuft = P(sphere(), Mt(gray, 0.5)); tuft.scale.set(0.12, 0.2, 0.2); tuft.position.set(side * 0.46, 0.16, -0.06); g.add(tuft); const m = P(sphere(), Mt(gray, 0.5)); m.scale.set(0.11, 0.05, 0.05); m.position.copy(at(side * 0.14, -0.06, R + 0.02)); m.rotation.z = -side * 0.35; g.add(m); } const back = P(shell(0.52, 0.7, 1.5, Math.PI * 1.1), Mt(gray, 0.5)); back.rotation.y = Math.PI; g.add(back); // boina const cap = P(sphere(), Mt(0x5b6b8c, 0.45)); cap.scale.set(0.4, 0.12, 0.4); cap.position.set(0, 0.45, 0.02); cap.rotation.x = -0.15; g.add(cap); break; } case 'farmer': { const straw = 0xe6c46a; const denim = 0x3f6fa8; // sombrero de paja de ala ancha const hat = new THREE.Group(); const brim = P(G('farmBrim', () => new THREE.CylinderGeometry(0.68, 0.72, 0.05, 40)), Mt(straw, 0.45)); const crown = P(sphere(), Mt(straw, 0.45)); crown.scale.set(0.34, 0.27, 0.34); crown.position.y = 0.15; const ribbon = P(G('farmRibbon', () => new THREE.TorusGeometry(0.33, 0.035, 8, 32)), Mt(0xc2452e, 0.5)); ribbon.rotation.x = Math.PI / 2; ribbon.position.y = 0.06; hat.add(brim, crown, ribbon); hat.position.set(0, 0.34, -0.02); hat.rotation.x = -0.12; g.add(hat); // peto de granjera (sin correas de mochila) g.add(P(patch('overall', R + 0.014, (u, t) => [u * 0.66, 1.86 + t * 0.92]), Mt(denim, 0.5, { side: THREE.DoubleSide }))); g.add(P(patch('bib', R + 0.022, (u, t) => [u * 0.34, 1.55 + t * 0.4]), Mt(denim, 0.5, { side: THREE.DoubleSide }))); for (const side of [-1, 1]) { const b = P(sphere(), Mt(0xffc928, 0.9)); b.scale.setScalar(0.036); b.position.copy(at(side * 0.16, -0.18, R + 0.03)); g.add(b); } // pañuelo al cuello g.add(P(shell(R + 0.016, 1.58, 1.72), Mt(0xf2452e, 0.5))); out.foot = 0x8a5a34; out.sole = 0x5a3a20; break; } case 'sage': { const gray = 0xd8d8e2; hairCap(g, gray, 1.18, -0.45, 0.526); // barba larga que cuelga hasta las rodillas, bigote y cejas pobladas hangingBeard(g, gray, 0.6, 0.25); for (const side of [-1, 1]) { const brow = P(sphere(), Mt(gray, 0.45)); brow.scale.set(0.13, 0.038, 0.045); brow.position.copy(at(side * 0.15, 0.17, R + 0.03)); brow.rotation.z = side * 0.26; g.add(brow); } // sombrero de mago del agua: ala ancha y punta caída, cinta con una gota wizardHat(g, 0x2f6fd0, 0x7fd8ff, 'drop'); // túnica azul con ribete de olas claras g.add(P(shell(R + 0.014, 1.72, 2.86), Mt(0x2f5fb8, 0.5))); g.add(P(shell(R + 0.02, 1.71, 1.8), Mt(0x7fd8ff, 0.7, { emissive: 0x2fa8f5, emissiveIntensity: 0.25 }))); for (let i = 0; i < 6; i++) { const w = P(sphere(), Mt(0xbfeaff, 0.6)); w.scale.set(0.07, 0.04, 0.03); w.position.copy(at(-0.75 + i * 0.3, -0.62, R + 0.02)); g.add(w); } // bastón 3D con orbe const staff = P(G('sageStaff', () => new THREE.CylinderGeometry(0.028, 0.038, 1.72, 10)), Mt(0x7a4a2a, 0.35)); staff.position.set(0.64, -0.12, 0.2); staff.rotation.z = 0.08; const orb = P(sphere(), Mt(0x7fd8ff, 0.4, { emissive: 0x2fa8f5, emissiveIntensity: 0.9 })); orb.scale.setScalar(0.095); orb.position.set(0.7, 0.76, 0.2); g.add(staff, orb); out.foot = 0x4a3a2a; out.sole = 0x2e241a; break; } case 'wizard': { // Hechicero: sombrero alto morado con estrellas, capa oscura con cuello alto, bastón con orbe violeta wizardHat(g, 0x4a2a7a, 0xffc928, 'star'); // barba gris oscura, larga y afilada hangingBeard(g, 0x8a8296, 0.62, 0.21); g.add(P(shell(R + 0.014, 1.7, 2.86), Mt(0x3a1f5c, 0.5))); g.add(P(shell(R + 0.022, 1.66, 1.82), Mt(0x9f6bff, 0.7, { emissive: 0x7a3cff, emissiveIntensity: 0.3 }))); g.add(P(patch('wizCape', R + 0.03, (u, t) => [Math.PI + u * 1.55, 1.2 + t * 1.75], 18, 12), Mt(0x2a1240, 0.45, { side: THREE.DoubleSide }))); // cuello alto de la capa for (const side of [-1, 1]) { const c = P(G('wizCollar', () => new THREE.ConeGeometry(0.16, 0.34, 4)), Mt(0x5a2a8a, 0.5)); c.position.set(side * 0.34, 0.08, -0.12); c.rotation.z = side * 0.5; g.add(c); } const staff = P(G('wizStaff', () => new THREE.CylinderGeometry(0.03, 0.04, 1.8, 10)), Mt(0x2a1a14, 0.4)); staff.position.set(0.66, -0.1, 0.18); staff.rotation.z = 0.06; const orb = P(sphere(), Mt(0xc8a8ff, 0.4, { emissive: 0x8f3cff, emissiveIntensity: 1.1 })); orb.scale.setScalar(0.12); orb.position.set(0.71, 0.86, 0.18); const claw = P(G('wizClaw', () => new THREE.TorusGeometry(0.13, 0.025, 6, 16, Math.PI * 1.4)), Mt(0x2a1a14, 0.4)); claw.position.copy(orb.position); claw.rotation.z = -0.9; g.add(staff, orb, claw); out.foot = 0x2a1240; out.sole = 0x140a20; break; } case 'king': { // Rey Frío: capa real azul hielo con armiño blanco (la corona va como accesorio 'crown') g.add(P(patch('kingCape', R + 0.03, (u, t) => [Math.PI + u * 1.6, 1.25 + t * 1.7], 18, 12), Mt(0x2f6fd0, 0.5, { side: THREE.DoubleSide }))); g.add(P(shell(R + 0.03, 1.5, 1.72), Mt(0xf4f1ff, 0.3))); for (let i = 0; i < 7; i++) { const d = P(sphere(), Mt(0x2b2430, 0.5)); d.scale.set(0.022, 0.034, 0.02); d.position.copy(at(-0.9 + i * 0.3, -0.1, R + 0.045)); g.add(d); } // barba real blanca que cuelga y cetro de hielo hangingBeard(g, 0xf4f1ff, 0.48, 0.23); const sc = P(G('kingScepter', () => new THREE.CylinderGeometry(0.026, 0.032, 1.3, 10)), Mt(0xffc928, 0.85)); sc.position.set(0.62, -0.2, 0.22); const gem = P(G('kingGem', () => new THREE.OctahedronGeometry(1, 0)), Mt(0xbfeaff, 0.95, { emissive: 0x4aa8e8, emissiveIntensity: 0.6 })); gem.scale.set(0.1, 0.16, 0.1); gem.position.set(0.63, 0.55, 0.22); g.add(sc, gem); out.foot = 0x2f6fd0; out.sole = 0x1a3a70; break; } case 'elf': { const blonde = 0xf2d06a; hairCap(g, blonde, 1.14, -0.45, 0.526); for (const side of [-1, 1]) { const lock = P(sphere(), Mt(blonde, 0.45)); lock.scale.set(0.1, 0.24, 0.16); lock.position.set(side * 0.44, 0.02, -0.04); // orejas puntiagudas const ear = P(G('elfEar', () => new THREE.ConeGeometry(0.085, 0.28, 8)), Mt(0xf0c9a8, 0.35)); ear.position.set(side * 0.47, 0.14, -0.02); ear.rotation.z = side * 1.02; ear.rotation.x = -0.18; g.add(lock, ear); } // capa verde a la espalda g.add(P(patch('elfCape', R + 0.022, (u, t) => [Math.PI + u * 1.35, 1.32 + t * 1.5], 18, 12), Mt(0x2f8f46, 0.5, { side: THREE.DoubleSide }))); // túnica y cinturón g.add(P(shell(R + 0.012, 1.7, 2.72), Mt(0x3f9b45, 0.5))); g.add(P(shell(R + 0.018, 2.12, 2.3), Mt(0x8a5a34, 0.5))); const brooch = P(extr('star', starShape), Mt(0xffc928, 0.9, { emissive: 0xffa800, emissiveIntensity: 0.3 })); brooch.scale.setScalar(0.075); g.add(onto(brooch, 0, 0.04, R + 0.03)); out.foot = 0x3a5a32; out.sole = 0x2a3a22; break; } case 'robot': { for (const side of [-1, 1]) { const rod = P(G('antRod', () => new THREE.CylinderGeometry(0.014, 0.014, 0.24, 8)), Mt(0x5a6aa8, 0.8)); rod.position.set(side * 0.27, 0.55, -0.02); rod.rotation.z = -side * 0.18; const ball = P(sphere(), Mt(0x3ee6ff, 0.6, { emissive: 0x3ee6ff, emissiveIntensity: 1.4 })); ball.scale.setScalar(0.055); ball.position.set(side * 0.295, 0.68, -0.02); g.add(rod, ball); } out.foot = 0xf4f6ff; out.sole = 0x2f7ee6; break; } } return out; }