2Btainment commited on
Commit
f2b420f
·
verified ·
1 Parent(s): 8da270f

World: leaning 12 km fossil stinger spire, east-flank land, horizon terrain, sunrise intro

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/tex/aerial_rocks_02-diff.webp filter=lfs diff=lfs merge=lfs -text
37
+ assets/tex/aerial_rocks_02-nor_gl.webp filter=lfs diff=lfs merge=lfs -text
38
+ assets/tex/aerial_rocks_02-rough.webp filter=lfs diff=lfs merge=lfs -text
39
+ assets/tex/rock_face-diff.webp filter=lfs diff=lfs merge=lfs -text
40
+ assets/tex/rock_face-nor_gl.webp filter=lfs diff=lfs merge=lfs -text
app.js CHANGED
@@ -1,13 +1,15 @@
1
  import * as THREE from './vendor/three.module.min.js';
2
  import { STUDIOS, stopLoops } from './widgets.js?v=50';
3
- import './real.js?v=96';
4
- import './avatar.js?v=96';
5
- import './master.js?v=96';
6
- import './video.js?v=96';
7
- import './workspace.js?v=96';
8
- import './studios5.js?v=96';
9
- import { icon } from './icons.js?v=96';
10
- import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
 
 
11
  import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
12
  import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
13
  import { UnrealBloomPass } from './vendor/addons/postprocessing/UnrealBloomPass.js';
@@ -32,90 +34,41 @@ function toggleSound() { soundOn = !soundOn; $('#snd').innerHTML = icon(soundOn
32
  $('#snd').onclick = toggleSound; $('#snd').innerHTML = icon('mute');
33
 
34
  /* ---------- three setup ---------- */
35
- let renderer = null, gl3d = true, composer = null, bloom = null;
36
  try {
37
  const tc = document.createElement('canvas'); if (!(tc.getContext('webgl2') || tc.getContext('webgl'))) throw new Error('no webgl');
38
- renderer = new THREE.WebGLRenderer({ canvas: $('#gl'), antialias: !isMobile, powerPreference: 'high-performance' });
39
  } catch (e) { gl3d = false; console.warn('WebGL unavailable, 2D fallback'); }
40
- if (renderer) { renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1.05; }
41
- if (renderer) { try { const g = renderer.getContext(), ext = g.getExtension('WEBGL_debug_renderer_info'); const nm = ext ? g.getParameter(ext.UNMASKED_RENDERER_WEBGL) : '';
42
- if (/swiftshader|llvmpipe|software|basic render/i.test(nm)) quality = 'low'; } catch (e) {} }
43
- const scene = new THREE.Scene(); scene.fog = new THREE.FogExp2(0x020c17, 0.028);
44
- const camera = new THREE.PerspectiveCamera(55, innerWidth / innerHeight, .1, 200);
45
- const cam = { base: isMobile ? 26 : 21, r: isMobile ? 26 : 21, th: 0.4, ph: 1.15, tr: 21, tth: .4, tph: 1.15 };
 
 
 
 
 
46
  function applyQuality() {
47
  if (!renderer) return;
48
  renderer.setPixelRatio(Math.min(AR.pr, quality === 'high' ? Math.min(devicePixelRatio, 2) : Math.min(devicePixelRatio, 1.25)));
49
  renderer.setSize(innerWidth, innerHeight, false);
50
  if (composer) { composer.setPixelRatio(renderer.getPixelRatio()); composer.setSize(innerWidth, innerHeight); }
51
- if (swarm) swarm.count = quality === 'high' ? SW_MAX : SW_MAX / 3 | 0;
52
- if (dust) dust.geometry.setDrawRange(0, quality === 'high' ? DUST : DUST / 3 | 0);
53
  $('#q').textContent = 'Q:' + (qMode === 'AUTO' ? 'AUTO·' + quality[0].toUpperCase() : quality.toUpperCase());
54
  }
55
  if (renderer) { try { composer = new EffectComposer(renderer); composer.addPass(new RenderPass(scene, camera));
56
- bloom = new UnrealBloomPass(new THREE.Vector2(innerWidth, innerHeight), .6, .5, .42); composer.addPass(bloom); composer.addPass(new OutputPass()); } catch (e) { composer = null; } }
57
- if (renderer) { const pm = new THREE.PMREMGenerator(renderer); scene.environment = pm.fromScene(new RoomEnvironment(), .04).texture; scene.environmentIntensity = .5; }
58
- scene.add(new THREE.AmbientLight(0x334455, 1.2));
59
- const coreLight = new THREE.PointLight(GOLD, 60, 40, 1.6); scene.add(coreLight);
60
- const key = new THREE.DirectionalLight(0xfff1c8, 2.2); key.position.set(8, 12, 10); scene.add(key);
61
- const rim = new THREE.DirectionalLight(ORANGE, 1.2); rim.position.set(-10, 8, -6); scene.add(rim);
62
-
63
- /* core */
64
- const core = new THREE.Group(); scene.add(core);
65
- const coreMat = new THREE.MeshPhysicalMaterial({ color: 0xe0b04a, emissive: 0xc9962a, emissiveIntensity: .2, metalness: 1, roughness: .28, clearcoat: 1, clearcoatRoughness: .1, flatShading: true });
66
- const coreMesh = new THREE.Mesh(new THREE.IcosahedronGeometry(2.2, 1), coreMat); core.add(coreMesh);
67
- const shell = new THREE.Mesh(new THREE.IcosahedronGeometry(3.1, 1), new THREE.MeshBasicMaterial({ color: ORANGE, wireframe: true, transparent: true, opacity: .35 })); core.add(shell);
68
- const shell2 = new THREE.Mesh(new THREE.IcosahedronGeometry(3.8, 2), new THREE.MeshBasicMaterial({ color: GOLD, wireframe: true, transparent: true, opacity: .07 })); core.add(shell2);
69
- const glowTex = (() => { const c = document.createElement('canvas'); c.width = c.height = 128; const x = c.getContext('2d'); const g = x.createRadialGradient(64, 64, 0, 64, 64, 64); g.addColorStop(0, 'rgba(255,230,150,1)'); g.addColorStop(.3, 'rgba(242,201,76,.5)'); g.addColorStop(1, 'rgba(0,0,0,0)'); x.fillStyle = g; x.fillRect(0, 0, 128, 128); return new THREE.CanvasTexture(c); })();
70
- const glow = new THREE.Sprite(new THREE.SpriteMaterial({ map: glowTex, blending: THREE.AdditiveBlending, depthWrite: false, transparent: true })); glow.scale.set(14, 14, 1); core.add(glow);
71
- // orbit rings
72
- for (let i = 0; i < 3; i++) { const ring = new THREE.Mesh(new THREE.TorusGeometry(5 + i * 1.1, .025, 6, 120), new THREE.MeshBasicMaterial({ color: [GOLD, GOLD, CYAN][i], transparent: true, opacity: i === 2 ? .22 : .45 })); ring.rotation.x = Math.PI / 2 + i * .35; ring.rotation.y = i * .6; ring.userData.spin = .2 + i * .15; core.add(ring); }
73
- // hex floor grid
74
- {
75
- const pts = []; const R = .9, W = R * Math.sqrt(3);
76
- for (let q = -14; q <= 14; q++) for (let r = -14; r <= 14; r++) {
77
- const cx = W * (q + r / 2), cz = 1.5 * R * r; if (cx * cx + cz * cz > 420) continue;
78
- for (let k = 0; k < 6; k++) { const a = Math.PI / 6 + k * Math.PI / 3, b = a + Math.PI / 3; pts.push(cx + R * Math.cos(a), 0, cz + R * Math.sin(a), cx + R * Math.cos(b), 0, cz + R * Math.sin(b)); }
79
- }
80
- const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pts, 3));
81
- const floor = new THREE.LineSegments(g, new THREE.LineBasicMaterial({ color: 0xd4a63a, transparent: true, opacity: .13 })); floor.position.y = -6; scene.add(floor);
82
- }
83
- // hex swarm (instanced)
84
- const SW_MAX = isMobile ? 260 : 620;
85
- const hexGeo = new THREE.CylinderGeometry(.11, .11, .04, 6);
86
- const swarm = new THREE.InstancedMesh(hexGeo, new THREE.MeshPhysicalMaterial({ color: GOLD, emissive: 0x4a3008, metalness: 1, roughness: .25, clearcoat: .5 }), SW_MAX);
87
- const swData = [...Array(SW_MAX)].map(() => ({ r: 4.5 + Math.random() * 9, a: Math.random() * 6.28, y: (Math.random() - .5) * 7, s: (.1 + Math.random() * .4) * (Math.random() < .5 ? -1 : 1), w: Math.random() * 6 }));
88
- const tmp = new THREE.Object3D(), tmpC = new THREE.Color();
89
- swData.forEach((d, i) => swarm.setColorAt(i, tmpC.set([GOLD, GOLD, 0xd4a63a, GOLD, ORANGE, CYAN][i % 6])));
90
- scene.add(swarm);
91
- // dust / burst particles
92
- const DUST = isMobile ? 1500 : 4000;
93
- const dpos = new Float32Array(DUST * 3), dvel = new Float32Array(DUST * 3);
94
- for (let i = 0; i < DUST; i++) { const v = new THREE.Vector3().randomDirection().multiplyScalar(10 + Math.random() * 40); dpos.set([v.x, v.y, v.z], i * 3); }
95
- const dGeo = new THREE.BufferGeometry(); dGeo.setAttribute('position', new THREE.BufferAttribute(dpos, 3));
96
- const dust = new THREE.Points(dGeo, new THREE.PointsMaterial({ color: 0xf6dcac, size: .07, transparent: true, opacity: .55, blending: THREE.AdditiveBlending, depthWrite: false })); scene.add(dust);
97
- function burst() { for (let i = 0; i < DUST; i++) { const v = new THREE.Vector3().randomDirection().multiplyScalar(.3 + Math.random() * 1.2); dpos.set([0, 0, 0], i * 3); dvel.set([v.x, v.y, v.z], i * 3); } bursting = 1; }
98
- let bursting = 0;
99
-
100
- /* studio nodes */
101
- const CATS = ['Alle', 'Text', 'Bild', 'Video', 'Audio', 'Automation', 'Code', 'Community', 'Design'];
102
- const nodes = []; const nodeGeo = new THREE.CylinderGeometry(.75, .75, .35, 6);
103
- const streamPts = [];
104
- STUDIOS.forEach((s, i) => {
105
- const a = i / STUDIOS.length * Math.PI * 2, R = 10 + (i % 2) * 1.6;
106
- const col = s.id === 'merge' ? RED : [GOLD, GOLD, ORANGE, GOLD, CYAN][CATS.indexOf(s.cat) % 5];
107
- const m = new THREE.Mesh(nodeGeo, new THREE.MeshPhysicalMaterial({ color: 0x2a2010, emissive: col, emissiveIntensity: .45, metalness: .85, roughness: .22, clearcoat: 1, clearcoatRoughness: .08 }));
108
- const edge = new THREE.LineSegments(new THREE.EdgesGeometry(nodeGeo), new THREE.LineBasicMaterial({ color: GOLD, transparent: true, opacity: .9 })); m.add(edge);
109
- m.rotation.x = Math.PI / 2; m.userData = { s, a, R, y: Math.sin(i * 1.7) * 2.2, i, col, lift: { x: 0, v: 0 }, sc: { x: 1, v: 0 } };
110
- scene.add(m); nodes.push(m);
111
- // data stream line node→core
112
- const lg = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]);
113
- const line = new THREE.Line(lg, new THREE.LineBasicMaterial({ color: col, transparent: true, opacity: .25 })); scene.add(line); m.userData.line = line;
114
- for (let k = 0; k < 3; k++) streamPts.push({ n: m, t: Math.random() });
115
- });
116
- const spGeo = new THREE.BufferGeometry(); const spPos = new Float32Array(streamPts.length * 3); spGeo.setAttribute('position', new THREE.BufferAttribute(spPos, 3));
117
- scene.add(new THREE.Points(spGeo, new THREE.PointsMaterial({ color: 0xfff1b0, size: .28, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, map: glowTex })));
118
 
 
 
 
 
 
 
119
  /* ---------- HUD, labels ---------- */
120
  let cat = 'Alle', sel = 0, openId = null;
121
  const cats = $('#cats');
@@ -127,10 +80,10 @@ const labels = STUDIOS.map((s, i) => { const d = document.createElement('div');
127
  d.onmouseenter = () => select(i); d.onclick = (e) => { e.stopPropagation(); select(i); open(i); }; $('#labels').append(d); return d; });
128
  function select(i) { if (i == null) return; if (sel !== i) beep(660, .03); sel = i; labels.forEach((l, k) => l.classList.toggle('sel', k === i)); }
129
  const pop = $('#pop'); if (window.ResizeObserver) new ResizeObserver(() => placePop()).observe(pop);
130
- function open(i) {
131
  stopLoops(); openId = i; const s = STUDIOS[i]; beep(990, .08, 'triangle');
132
  pop.innerHTML = `<div class="ph"><span class="pi">${icon(s.id)}</span><span class="pt"><b>${s.name}</b><small>${s.cat === '+' ? 'Modul' : s.cat} · ${s.like}</small></span><button aria-label="schließen">${icon('close')}</button></div><div class="pb"></div><div class="pf"><span>STUDIO ${String(i + 1).padStart(2, '0')}/${STUDIOS.length}</span><span>● SIMULATION</span></div>`;
133
- pop.classList.remove('in'); void pop.offsetWidth; pop.classList.add('in'); focusNode(i);
134
  pop.hidden = false; pop.setAttribute('role', 'dialog'); pop.setAttribute('aria-label', s.name + ' Studio'); pop.querySelector('.ph button').onclick = close; retFocus = document.activeElement; s.build(pop.querySelector('.pb')); window.dispatchEvent(new CustomEvent('studius-opened', { detail: { id: s.id, el: pop.querySelector('.pb') } })); const bd = pop.querySelector('.pf span:last-child'); if (s.real) { bd.textContent = '● REAL · ' + s.real; bd.classList.add('real'); }
135
  setTimeout(() => { if (openId === i && !pop.contains(document.activeElement)) pop.querySelector('.ph button').focus({ preventScroll: true }); }, 30); placePop(); $('#wire').classList.add('on'); setTimeout(placePop, 60);
136
  }
@@ -143,97 +96,147 @@ function placePop() {
143
  pop.style.left = x + 'px'; pop.style.top = y + 'px';
144
  }
145
 
146
- // smooth camera focus: swing the orbit so the node faces the camera
147
- function focusNode(i) { if (!started) return; const n = nodes[i]; const a = Math.atan2(n.position.z, n.position.x);
148
- let d = a - cam.tth; d = Math.atan2(Math.sin(d), Math.cos(d)); cam.tth += d; spin = 0; cam.tr = Math.max(14, cam.base - 4); cam.tph = 1.12; }
149
  function screenPos(o) { const v = o.getWorldPosition(new THREE.Vector3()).project(camera); return { x: (v.x + 1) / 2 * innerWidth, y: (1 - v.y) / 2 * innerHeight, z: v.z }; }
150
- window.addEventListener('studius-merge', () => { burst(); beep(200, .3, 'sawtooth'); });
151
 
152
- /* ---------- input ---------- */
153
  const keys = {};
154
- let started = false, lookK = 0;
 
155
  addEventListener('keydown', e => {
156
  if (!started) { start(); return; }
157
  if (e.key === 'Escape') { close(); return; }
158
  if (e.target.matches('input,textarea,select,[contenteditable]')) return;
159
- if (pop.contains(e.target)) return; // don't hijack keys inside the studio
160
  if (e.target.classList?.contains('lbl') && (e.key === 'Enter' || e.key === ' ')) return;
161
- const v = visible(), k = v.indexOf(sel);
162
- if (['ArrowRight', 'd', 'D', 'ArrowDown', 's', 'S'].includes(e.key)) select(v[(k + 1) % v.length]);
163
- else if (['ArrowLeft', 'a', 'A', 'ArrowUp', 'w', 'W'].includes(e.key)) select(v[(k - 1 + v.length) % v.length]);
164
- else if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(sel); }
 
165
  else if (e.key === 'Backspace') close();
166
  else if (e.key === 'q' || e.key === 'Q') cycleQ();
167
  else if (e.key === 'm' || e.key === 'M') toggleSound();
168
  else if (e.key === 'c' || e.key === 'C') { setCat(CATS[(CATS.indexOf(cat) + 1) % CATS.length]); }
 
169
  });
 
 
170
  const mouse = new THREE.Vector2(9, 9), ray = new THREE.Raycaster(); let drag = null;
171
  const cv = $('#gl');
172
- const ptrs = new Map(); let pinch0 = 0, lastMv = 0, idleT = 0; const ZMIN = 12, ZMAX = 34;
 
173
  addEventListener('pointermove', e => { mouse.set(e.clientX / innerWidth * 2 - 1, -(e.clientY / innerHeight) * 2 + 1); });
174
  cv.addEventListener('pointerdown', e => { if (!started) return; cv.setPointerCapture(e.pointerId); ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY }); idleT = 0;
175
- if (ptrs.size === 1) drag = { x: e.clientX, y: e.clientY, moved: 0, t: performance.now(), v: 0, vp: 0, pick: pickAt(e.clientX, e.clientY, e.pointerType) };
176
  if (ptrs.size === 2) { const [a, b] = [...ptrs.values()]; pinch0 = Math.hypot(a.x - b.x, a.y - b.y); drag = null; } });
177
  cv.addEventListener('pointermove', e => { const p = ptrs.get(e.pointerId); if (!p) return; p.x = e.clientX; p.y = e.clientY; idleT = 0;
178
- if (ptrs.size === 2) { const [a, b] = [...ptrs.values()]; const d = Math.hypot(a.x - b.x, a.y - b.y); if (pinch0) cam.tr = Math.max(ZMIN, Math.min(ZMAX, cam.tr * pinch0 / d)); pinch0 = d; return; }
179
- if (!drag) return; const now = performance.now(), dts = Math.max(.008, (now - (lastMv || now)) / 1000); lastMv = now;
180
- const dx = e.clientX - drag.x, dy = e.clientY - drag.y; drag.moved += Math.abs(dx) + Math.abs(dy); drag.x = e.clientX; drag.y = e.clientY;
181
- if (drag.moved > (e.pointerType === 'mouse' ? 6 : 14)) { const w = -dx * .005; cam.tth += w; cam.th += w; drag.v = drag.v * .6 + (w / dts) * .4; cam.tph = Math.max(.45, Math.min(1.5, cam.tph - dy * .004)); cv.style.cursor = 'grabbing'; } });
182
  function pickAt(x, y, type) { mouse.set(x / innerWidth * 2 - 1, -(y / innerHeight) * 2 + 1); ray.setFromCamera(mouse, camera); const h = ray.intersectObjects(nodes, false)[0]; let hi = h ? h.object.userData.i : -1;
183
- if (hi < 0) { let bd = type === 'mouse' ? 18 : 40; nodes.forEach((n, k) => { const p = screenPos(n); const d = Math.hypot(p.x - x, p.y - y); if (p.z < 1 && d < bd) { bd = d; hi = k; } }); } return hi; }
184
- function endPtr(e) { if (!ptrs.has(e.pointerId)) return; ptrs.delete(e.pointerId); if (ptrs.size < 2) pinch0 = 0; lastMv = 0;
185
- if (drag && ptrs.size === 0) { if (drag.moved <= (e.pointerType === 'mouse' ? 6 : 14)) { let hi = drag.pick; if (hi < 0) hi = pickAt(e.clientX, e.clientY, e.pointerType);
186
- if (hi >= 0) { select(hi); open(hi); navigator.vibrate?.(8); } }
187
- else spin = Math.max(-3, Math.min(3, drag.v)); drag = null; cv.style.cursor = ''; } }
188
  cv.addEventListener('pointerup', endPtr); cv.addEventListener('pointercancel', e => { ptrs.delete(e.pointerId); if (!ptrs.size) { drag = null; pinch0 = 0; cv.style.cursor = ''; } });
189
- cv.addEventListener('wheel', e => { if (!started) return; e.preventDefault(); idleT = 0; cam.tr = Math.max(ZMIN, Math.min(ZMAX, cam.tr * Math.exp(e.deltaY * .0012))); }, { passive: false });
190
- let spin = 0;
 
 
 
 
 
 
 
191
  function cycleQ() { qMode = qMode === 'AUTO' ? 'HIGH' : qMode === 'HIGH' ? 'LOW' : 'AUTO'; if (qMode !== 'AUTO') quality = qMode.toLowerCase(); applyQuality(); }
192
  $('#q').onclick = cycleQ;
193
  let rsT = 0; const onResize = () => { camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix(); applyQuality(); if (innerWidth < 700) { pop.style.left = ''; pop.style.top = ''; } placePop(); };
194
  addEventListener('resize', () => { cancelAnimationFrame(rsT); rsT = requestAnimationFrame(onResize); }); addEventListener('orientationchange', () => setTimeout(onResize, 250)); screen.orientation?.addEventListener?.('change', () => setTimeout(onResize, 250));
195
- // gamepad
196
- let gpCool = 0;
197
- function pollPad() { const p = navigator.getGamepads ? [...navigator.getGamepads()].find(Boolean) : null; if (!p) return; if (Math.abs(p.axes[2] || 0) > .15) cam.tth += p.axes[2] * .04; if (Math.abs(p.axes[3] || 0) > .15) cam.tph = Math.max(.45, Math.min(1.5, cam.tph + p.axes[3] * .02)); if (gpCool-- > 0) return;
198
- const x = p.axes[0] || 0, v = visible(), k = v.indexOf(sel);
 
 
 
199
  if (!started && p.buttons.some(b => b.pressed)) { start(); gpCool = 20; return; }
200
- if (x > .5 || p.buttons[15]?.pressed) { select(v[(k + 1) % v.length]); gpCool = 12; }
201
- else if (x < -.5 || p.buttons[14]?.pressed) { select(v[(k - 1 + v.length) % v.length]); gpCool = 12; }
202
- else if (p.buttons[0]?.pressed) { open(sel); gpCool = 20; } else if (p.buttons[1]?.pressed) { close(); gpCool = 20; }
203
- }
204
 
205
- /* ---------- intro ---------- */
206
  const intro = $('#intro'); let introT = 0;
207
  const stage = (n, ms) => setTimeout(() => !started && intro.classList.add('s' + n), ms);
208
- stage(1, 120); stage(2, 1100); stage(3, 2300); stage(4, 3300); stage(5, 4600);
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  intro.addEventListener('pointermove', e => { const x = e.clientX / innerWidth - .5, y = e.clientY / innerHeight - .5; $('#reveal').style.transform = `translate(${x * -18}px,${y * -14}px) rotateY(${x * 6}deg)`; });
210
  function start() {
211
- if (started) return; started = true; beep(110, .5, 'sine', .06); burst();
212
- intro.classList.add('out'); setTimeout(() => intro.remove(), 1100);
213
- ['#hud', '#hint', '#core-stats', '#frame', '#mm'].forEach(s => $(s).hidden = false); document.body.classList.add('live'); cam.tr = cam.base; setCat('Alle'); select(0);
 
214
  }
215
  $('#skip').onclick = (e) => { e.stopPropagation(); start(); };
216
  intro.addEventListener('pointerdown', (e) => { if (e.target.id !== 'skip') start(); });
217
- cam.r = 60; cam.tr = 40;
218
 
219
  /* ---------- loop ---------- */
220
- const clock = new THREE.Clock(); let frames = 0, fpsT = 0, lowStreak = 0, statT = 0, mmT = 0;
221
  const mm = $('#mm'); const mmDots = STUDIOS.map((s, i) => { const c = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); c.setAttribute('r', 2.6); mm.querySelector('#mmd').append(c); return c; });
222
- function drawMinimap(v) { const vw = mm.querySelector('#mmv'); nodes.forEach((n, i) => { const c = mmDots[i]; c.setAttribute('cx', 50 + n.position.x * 3.4); c.setAttribute('cy', 50 + n.position.z * 3.4);
223
- c.setAttribute('class', i === sel ? 'sel' : v.includes(i) ? 'on' : 'off'); });
224
- const a = Math.atan2(camera.position.z, camera.position.x) * 180 / Math.PI; vw.setAttribute('transform', `rotate(${a} 50 50)`); }
 
 
 
225
  const stats = $('#core-stats');
226
- const spring = (s, target, dt, w) => { const n = Math.max(1, Math.ceil(dt / .008)), h = dt / n; for (let k = 0; k < n; k++) { const a = w * w * (target - s.x) - 2 * w * s.v; s.v += a * h; s.x += s.v * h; } return s.x; };
227
- const sp = { th: { x: 0, v: 0 }, ph: { x: 1.15, v: 0 }, r: { x: 60, v: 0 }, lk: { x: 0, v: 0 }, mx: { x: 0, v: 0 }, my: { x: 0, v: 0 } };
228
  const AR = { pr: 1, ema: 16.7, t: 0, slow: 0 }; let lastT = performance.now();
229
  function setPR(p) { if (!renderer) return; AR.pr = p; renderer.setPixelRatio(p); renderer.setSize(innerWidth, innerHeight, false); if (composer) { composer.setPixelRatio(p); composer.setSize(innerWidth, innerHeight); } }
230
  let paused = document.hidden, ctxLost = false;
231
- document.addEventListener('visibilitychange', () => { paused = document.hidden; lastT = performance.now(); if (paused) { spin = 0; ac?.suspend?.(); } else if (soundOn) ac?.resume?.(); });
232
  if (renderer) { const c = renderer.domElement;
233
  c.addEventListener('webglcontextlost', e => { e.preventDefault(); ctxLost = true; if (!$('#ctxmsg')) document.body.insertAdjacentHTML('beforeend', '<div id="ctxmsg" role="status" style="position:fixed;left:50%;top:70px;transform:translateX(-50%);z-index:40;padding:6px 12px;border:1px solid #faa968;background:#000c;color:#faa968;font-size:12px;border-radius:6px">GPU-Kontext verloren – stelle wieder her…</div>'); });
234
  c.addEventListener('webglcontextrestored', () => { ctxLost = false; $('#ctxmsg')?.remove(); applyQuality(); setPR(AR.pr); lastT = performance.now(); }); }
235
  window.__studiusLoseCtx = () => renderer?.forceContextLoss?.();
236
  window.__studiusRestoreCtx = () => renderer?.forceContextRestore?.();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  function frame(now) {
238
  requestAnimationFrame(frame);
239
  if (paused || ctxLost) { lastT = now ?? performance.now(); window.__paused = (window.__paused || 0) + (paused ? 1 : 0); return; }
@@ -243,70 +246,43 @@ function frame(now) {
243
  if (AR.t > .6) { AR.t = 0; const mxp = quality === 'high' ? Math.min(devicePixelRatio, 2) : Math.min(devicePixelRatio, 1.25); let p = AR.pr;
244
  if (AR.ema > 19) p = Math.max(.6, p - (AR.ema > 30 ? .15 : .08)); else if (AR.ema < 14.5) p = Math.min(mxp, p + .05); if (Math.abs(p - AR.pr) > .01) setPR(+p.toFixed(2));
245
  AR.slow = AR.pr <= .6 && AR.ema > 34 ? AR.slow + 1 : 0; if (AR.slow > 4 && quality === 'high') { quality = 'low'; applyQuality(); AR.slow = 0; } } }
246
- window.__pr = AR.pr; if (!started) { introT += dt; if (introT > 7.8 && intro.classList.contains('s5')) start(); }
247
- pollPad();
248
- // camera (intro: slow fly; mouse parallax)
249
- idleT += dt; const idle = started && idleT > 9 && openId == null;
250
- const drift = openId != null ? 0 : started ? dt * (idle ? .09 : .03) : dt * .12; cam.tth += drift + spin * dt; spin *= Math.exp(-dt * 1.6);
251
- if (drag) sp.th.x = cam.tth; // direct manipulation while dragging, springs take over on release
252
- cam.th = spring(sp.th, cam.tth, dt, 3.4); cam.ph = spring(sp.ph, cam.tph + (idle ? Math.sin(t * .25) * .05 : 0), dt, 4); cam.r = spring(sp.r, cam.tr, dt, started ? 3.2 : 1.1);
253
- const mx = mouse.x < 5 ? spring(sp.mx, mouse.x, dt, 4) : 0, my = mouse.y < 5 ? spring(sp.my, mouse.y, dt, 4) : 0;
254
- camera.position.set(cam.r * Math.sin(cam.ph) * Math.cos(cam.th) + mx * 1.5, cam.r * Math.cos(cam.ph) + my * 1.5, cam.r * Math.sin(cam.ph) * Math.sin(cam.th)); const mob = innerWidth < 700, want = openId == null ? 0 : 1; lookK = spring(sp.lk, want, dt, 4);
255
- const ox = mob ? 0 : .19 * cam.r * camera.aspect * lookK, oy = mob ? -.27 * cam.r * lookK : 0;
256
- camera.lookAt(Math.sin(cam.th) * ox, oy, -Math.cos(cam.th) * ox);
257
- // core pulse
258
- const pulse = 1 + Math.sin(t * 2.4) * .06 + (bursting * .5);
259
- coreMesh.scale.setScalar(pulse); coreMesh.rotation.y += dt * .4; coreMesh.rotation.x += dt * .15; coreMat.emissiveIntensity = .18 + Math.max(0, Math.sin(t * 2.4)) * .22;
260
- shell.rotation.y -= dt * .25; shell2.rotation.x += dt * .1; glow.scale.setScalar(9 + Math.sin(t * 2.4) * 1 + bursting * 10);
261
- core.children.forEach(c => { if (c.userData.spin) c.rotation.z += dt * c.userData.spin; });
262
- coreLight.intensity = 35 + Math.sin(t * 2.4) * 10;
263
- // swarm
264
- const sc = swarm.count;
265
- for (let i = 0; i < sc; i++) { const d = swData[i]; d.a += d.s * dt * (1 + bursting * 4);
266
- const r = d.r + Math.sin(t + d.w) * .6 + bursting * 6;
267
- tmp.position.set(Math.cos(d.a) * r, d.y + Math.sin(t * .7 + d.w) * .8, Math.sin(d.a) * r);
268
- tmp.rotation.set(t + d.w, d.a, 0); tmp.scale.setScalar(.7 + .3 * Math.sin(t * 3 + d.w)); tmp.updateMatrix(); swarm.setMatrixAt(i, tmp.matrix); }
269
- swarm.instanceMatrix.needsUpdate = true;
270
- // dust burst
271
- if (bursting > 0) { for (let i = 0; i < DUST * 3; i++) { dpos[i] += dvel[i]; dvel[i] *= .985; } dGeo.attributes.position.needsUpdate = true; bursting = Math.max(0, bursting - dt * .5); }
272
- dust.rotation.y += dt * .02;
273
- // nodes
274
- const v = visible();
275
- nodes.forEach((n, i) => { const u = n.userData; u.ph = (u.ph || 0) + (openId != null ? 0 : dt * .04); const a = u.a + u.ph; const on = v.includes(i); spring(u.lift, i === sel ? .45 : 0, dt, 8); const s = spring(u.sc, (i === sel ? 1.35 : 1) * (on ? 1 : .6), dt, 9);
276
- n.position.set(Math.cos(a) * u.R, u.y + Math.sin(t + i) * .3 + u.lift.x + (idle ? Math.sin(t * 1.3 + i) * .15 : 0), Math.sin(a) * u.R);
277
- n.rotation.z += dt * (i === sel ? 1.5 : .3); n.scale.setScalar(s);
278
- n.material.emissiveIntensity = i === sel ? .9 + Math.sin(t * 4) * .2 : on ? .32 : .08;
279
- const p = u.line.geometry.attributes.position; p.setXYZ(1, n.position.x, n.position.y, n.position.z); p.needsUpdate = true; u.line.material.opacity = on ? (i === sel ? .8 : .25) : .05; });
280
- streamPts.forEach((s, k) => { s.t = (s.t + dt * .35) % 1; const p = s.n.position; spPos[k * 3] = p.x * (1 - s.t); spPos[k * 3 + 1] = p.y * (1 - s.t); spPos[k * 3 + 2] = p.z * (1 - s.t); });
281
- spGeo.attributes.position.needsUpdate = true;
282
- // hover raycast
283
  if (started && !drag && mouse.x < 5 && openId == null) { ray.setFromCamera(mouse, camera); const h = ray.intersectObjects(nodes, false)[0]; cv.style.cursor = h ? 'pointer' : 'grab'; if (h && h.object.userData.i !== sel) select(h.object.userData.i); }
284
- if (renderer) { if (composer && quality === 'high') composer.render(); else renderer.render(scene, camera); }
285
- // labels + wire
286
  if (started) {
287
- const placed = []; const camP = camera.position;
288
- const blk = ['#hud', '#core-stats', '#mm', '#pop', '#hint', '#bmc'].map(q => $(q)).filter(e => e && !e.hidden && e.offsetParent !== null).map(e => e.getBoundingClientRect());
289
- nodes.map((n, i) => ({ n, i, d: n.position.distanceTo(camP) })).sort((a, b) => a.d - b.d).forEach(({ n, i, d }, rank) => {
290
- const p = screenPos(n); const l = labels[i]; if (p.z >= 1) { l.style.display = 'none'; return; } l.style.display = '';
291
- const far = rank > 9 && i !== sel && i !== openId; l.classList.toggle('far', far);
292
- const w = far ? 30 : l.offsetWidth || 110, h = 26; let y = p.y + 34;
293
  for (let k = 0; k < 6; k++) { const hit = placed.find(r => Math.abs(r.x - p.x) < (r.w + w) / 2 + 4 && Math.abs(r.y - y) < h); if (!hit) break; y = hit.y + (y >= hit.y ? h : -h); }
294
  placed.push({ x: p.x, y, w });
295
  const lx0 = p.x - w / 2, lx1 = p.x + w / 2; l.classList.toggle('hid', blk.some(r => lx0 < r.right && lx1 > r.left && y - 13 < r.bottom && y + 13 > r.top)); l.style.transform = `translate(${p.x}px,${y}px) translate(-50%,-50%)`; l.style.zIndex = 100 - rank;
296
  l.classList.toggle('dim', !v.includes(i)); });
297
  if ((mmT += dt) > .1) { mmT = 0; drawMinimap(v); }
298
  if (openId != null && !pop.hidden) { const p = screenPos(nodes[openId]); const r = pop.getBoundingClientRect(); const wl = $('#wl');
299
- const tx = p.x < r.left ? r.left : r.right; wl.setAttribute('x1', p.x); wl.setAttribute('y1', p.y); wl.setAttribute('x2', tx); wl.setAttribute('y2', r.top + 14);
300
- }
301
- if ((statT += dt) > .5) { statT = 0; const ld = (55 + Math.sin(t * .7) * 20) | 0; stats.innerHTML = `<h4>META-ENGINE CORE</h4><dl><dt>Agenten</dt><dd>${120 + (Math.sin(t) * 8 | 0)}</dd><dt>Tokens/s</dt><dd>${(4200 + Math.random() * 900) | 0}</dd><dt>Studios</dt><dd>${STUDIOS.length}</dd><dt>Last</dt><dd>${ld}%</dd></dl><div class="bar"><i style="width:${ld}%"></i></div><p>● SIMULATION</p>`; }
302
  }
303
  }
304
  setPR(1); applyQuality();
305
- window.__studius = { STUDIOS, select: (i) => select(i), core: () => screenPos(core), get sel() { return sel; }, get openId() { return openId; }, get zoom() { return cam.r; }, get th() { return cam.th; }, nodeScreen: (i) => screenPos(nodes[i]), open: (i) => { select(i); open(i); }, close: () => close(), get paused() { return paused; }, get ctxLost() { return ctxLost; } };
 
306
  if (gl3d) requestAnimationFrame(frame); else { setTimeout(() => start(), 7800);
307
  document.body.insertAdjacentHTML('beforeend', '<div style="position:fixed;left:14px;top:60px;z-index:16;color:#faa968;font-size:11px">⚠ WebGL nicht verfügbar – 2D-Modus</div>');
308
- // minimal 2D loop to keep labels in a ring
309
- const tick = () => { requestAnimationFrame(tick); if (document.hidden) return; const t = performance.now() / 1000; nodes.forEach((n, i) => { const u = n.userData; const a = u.a + t * .04; n.position.set(Math.cos(a) * u.R, u.y, Math.sin(a) * u.R); });
310
- camera.position.set(0, 18, 18); camera.lookAt(0, 0, 0); camera.updateMatrixWorld(); if (started) nodes.forEach((n, i) => { n.updateMatrixWorld(); const p = screenPos(n); labels[i].style.transform = `translate(${p.x}px,${p.y}px) translate(-50%,-50%)`; }); };
311
- tick();
312
  }
 
1
  import * as THREE from './vendor/three.module.min.js';
2
  import { STUDIOS, stopLoops } from './widgets.js?v=50';
3
+ import './real.js?v=102';
4
+ import './avatar.js?v=102';
5
+ import './master.js?v=102';
6
+ import './video.js?v=102';
7
+ import './workspace.js?v=102';
8
+ import './studios5.js?v=102';
9
+ import { icon } from './icons.js?v=102';
10
+ import { GTAOPass } from './vendor/addons/postprocessing/GTAOPass.js';
11
+ import { BokehPass } from './vendor/addons/postprocessing/BokehPass.js';
12
+ import { buildWorld, makeBee, landH, MC } from './world.js?v=102';
13
  import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
14
  import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
15
  import { UnrealBloomPass } from './vendor/addons/postprocessing/UnrealBloomPass.js';
 
34
  $('#snd').onclick = toggleSound; $('#snd').innerHTML = icon('mute');
35
 
36
  /* ---------- three setup ---------- */
37
+ let renderer = null, gl3d = true, composer = null, bloom = null, gtao = null, bokeh = null;
38
  try {
39
  const tc = document.createElement('canvas'); if (!(tc.getContext('webgl2') || tc.getContext('webgl'))) throw new Error('no webgl');
40
+ renderer = new THREE.WebGLRenderer({ canvas: $('#gl'), antialias: !isMobile, powerPreference: 'high-performance', logarithmicDepthBuffer: false });
41
  } catch (e) { gl3d = false; console.warn('WebGL unavailable, 2D fallback'); }
42
+ let soft = false;
43
+ if (renderer) { renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = .82; renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;
44
+ try { const g = renderer.getContext(), ext = g.getExtension('WEBGL_debug_renderer_info'); const nm = ext ? g.getParameter(ext.UNMASKED_RENDERER_WEBGL) : ''; if (/swiftshader|llvmpipe|software|basic render/i.test(nm)) { quality = 'low'; soft = true; } } catch (e) {} }
45
+ const urlQ = new URLSearchParams(location.search).get('q'); if (urlQ === 'high' || urlQ === 'low') { quality = urlQ; qMode = urlQ.toUpperCase(); }
46
+ const scene = new THREE.Scene();
47
+ const camera = new THREE.PerspectiveCamera(55, innerWidth / innerHeight, 1, 4e6);
48
+ const CATS = ['Alle', 'Text', 'Bild', 'Video', 'Audio', 'Automation', 'Code', 'Community', 'Design'];
49
+ const colOf = (s) => s.id === 'merge' ? RED : [GOLD, 0xffd77a, ORANGE, GOLD, CYAN][CATS.indexOf(s.cat) % 5];
50
+ const W = buildWorld(scene, renderer, STUDIOS, colOf, quality);
51
+ const nodes = W.shrines.map(s => s.portal); nodes.forEach((n, i) => n.userData = { ...n.userData, s: STUDIOS[i], i });
52
+ const core = W.core;
53
  function applyQuality() {
54
  if (!renderer) return;
55
  renderer.setPixelRatio(Math.min(AR.pr, quality === 'high' ? Math.min(devicePixelRatio, 2) : Math.min(devicePixelRatio, 1.25)));
56
  renderer.setSize(innerWidth, innerHeight, false);
57
  if (composer) { composer.setPixelRatio(renderer.getPixelRatio()); composer.setSize(innerWidth, innerHeight); }
58
+ renderer.shadowMap.enabled = quality === 'high' || !soft; if (gtao) gtao.enabled = quality === 'high'; if (bokeh) bokeh.enabled = quality === 'high';
 
59
  $('#q').textContent = 'Q:' + (qMode === 'AUTO' ? 'AUTO·' + quality[0].toUpperCase() : quality.toUpperCase());
60
  }
61
  if (renderer) { try { composer = new EffectComposer(renderer); composer.addPass(new RenderPass(scene, camera));
62
+ try { gtao = new GTAOPass(scene, camera, innerWidth, innerHeight); gtao.updateGtaoMaterial({ radius: 4, distanceExponent: 1.4, thickness: 2, scale: 1.2 }); gtao.blendIntensity = .8; composer.addPass(gtao); } catch (e) { gtao = null; }
63
+ try { bokeh = new BokehPass(scene, camera, { focus: 12, aperture: .00012, maxblur: .006 }); composer.addPass(bokeh); } catch (e) { bokeh = null; }
64
+ bloom = new UnrealBloomPass(new THREE.Vector2(innerWidth, innerHeight), .18, .5, .92); composer.addPass(bloom); composer.addPass(new OutputPass()); } catch (e) { composer = null; } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ /* ---------- the player bee ---------- */
67
+ const bee = makeBee(); bee.scale.setScalar(1.3); scene.add(bee);
68
+ const B = { pos: new THREE.Vector3(), vel: new THREE.Vector3(), yaw: Math.PI, bank: 0, travel: null, near: -1, armed: true };
69
+ function spawn() { const x = 5150, z = 1950; B.pos.set(x, landH(x, z) + 14, z); B.vel.set(0, 0, 0); B.yaw = Math.PI; }
70
+ spawn();
71
+ window.__studiusLegacyDust = null;
72
  /* ---------- HUD, labels ---------- */
73
  let cat = 'Alle', sel = 0, openId = null;
74
  const cats = $('#cats');
 
80
  d.onmouseenter = () => select(i); d.onclick = (e) => { e.stopPropagation(); select(i); open(i); }; $('#labels').append(d); return d; });
81
  function select(i) { if (i == null) return; if (sel !== i) beep(660, .03); sel = i; labels.forEach((l, k) => l.classList.toggle('sel', k === i)); }
82
  const pop = $('#pop'); if (window.ResizeObserver) new ResizeObserver(() => placePop()).observe(pop);
83
+ function open(i, here) {
84
  stopLoops(); openId = i; const s = STUDIOS[i]; beep(990, .08, 'triangle');
85
  pop.innerHTML = `<div class="ph"><span class="pi">${icon(s.id)}</span><span class="pt"><b>${s.name}</b><small>${s.cat === '+' ? 'Modul' : s.cat} · ${s.like}</small></span><button aria-label="schließen">${icon('close')}</button></div><div class="pb"></div><div class="pf"><span>STUDIO ${String(i + 1).padStart(2, '0')}/${STUDIOS.length}</span><span>● SIMULATION</span></div>`;
86
+ pop.classList.remove('in'); void pop.offsetWidth; pop.classList.add('in'); if (!here) focusNode(i);
87
  pop.hidden = false; pop.setAttribute('role', 'dialog'); pop.setAttribute('aria-label', s.name + ' Studio'); pop.querySelector('.ph button').onclick = close; retFocus = document.activeElement; s.build(pop.querySelector('.pb')); window.dispatchEvent(new CustomEvent('studius-opened', { detail: { id: s.id, el: pop.querySelector('.pb') } })); const bd = pop.querySelector('.pf span:last-child'); if (s.real) { bd.textContent = '● REAL · ' + s.real; bd.classList.add('real'); }
88
  setTimeout(() => { if (openId === i && !pop.contains(document.activeElement)) pop.querySelector('.ph button').focus({ preventScroll: true }); }, 30); placePop(); $('#wire').classList.add('on'); setTimeout(placePop, 60);
89
  }
 
96
  pop.style.left = x + 'px'; pop.style.top = y + 'px';
97
  }
98
 
99
+ // fly the bee to a shrine (labels/keyboard/menu open → the bee travels there)
100
+ function shrineFront(i) { const g = W.shrines[i].group; g.updateMatrixWorld(); const v = new THREE.Vector3(0, 8, 34).applyMatrix4(g.matrixWorld); return v; }
101
+ function focusNode(i) { if (!started) return; const from = B.pos.clone(), to = shrineFront(i); B.travel = { from, to, t: 0, d: Math.max(1.5, Math.min(6, from.distanceTo(to) / 400)), i }; B.armed = false; }
102
  function screenPos(o) { const v = o.getWorldPosition(new THREE.Vector3()).project(camera); return { x: (v.x + 1) / 2 * innerWidth, y: (1 - v.y) / 2 * innerHeight, z: v.z }; }
103
+ window.addEventListener('studius-merge', () => { beep(200, .3, 'sawtooth'); });
104
 
105
+ /* ---------- input: fly the bee ---------- */
106
  const keys = {};
107
+ let started = false, lookK = 0, shotCam = null;
108
+ const FLYKEYS = { w: 'f', arrowup: 'f', s: 'b', arrowdown: 'b', a: 'l', arrowleft: 'l', d: 'r', arrowright: 'r', ' ': 'u', e: 'u', x: 'dn', control: 'dn', shift: 'boost' };
109
  addEventListener('keydown', e => {
110
  if (!started) { start(); return; }
111
  if (e.key === 'Escape') { close(); return; }
112
  if (e.target.matches('input,textarea,select,[contenteditable]')) return;
113
+ if (pop.contains(e.target)) return;
114
  if (e.target.classList?.contains('lbl') && (e.key === 'Enter' || e.key === ' ')) return;
115
+ const k = FLYKEYS[e.key.toLowerCase()]; if (k) { keys[k] = 1; B.travel = null; if (e.key.startsWith('Arrow') || e.key === ' ') e.preventDefault(); return; }
116
+ const v = visible(), ix = v.indexOf(sel);
117
+ if (e.key === 'n' || e.key === 'N' || e.key === 'PageDown') { select(v[(ix + 1) % v.length]); focusNode(sel); }
118
+ else if (e.key === 'p' || e.key === 'P' || e.key === 'PageUp') { select(v[(ix - 1 + v.length) % v.length]); focusNode(sel); }
119
+ else if (e.key === 'Enter') { e.preventDefault(); open(B.near >= 0 ? B.near : sel); }
120
  else if (e.key === 'Backspace') close();
121
  else if (e.key === 'q' || e.key === 'Q') cycleQ();
122
  else if (e.key === 'm' || e.key === 'M') toggleSound();
123
  else if (e.key === 'c' || e.key === 'C') { setCat(CATS[(CATS.indexOf(cat) + 1) % CATS.length]); }
124
+ else if (e.key === 'h' || e.key === 'H') { spawn(); }
125
  });
126
+ addEventListener('keyup', e => { const k = FLYKEYS[e.key.toLowerCase()]; if (k) keys[k] = 0; });
127
+ addEventListener('blur', () => Object.keys(keys).forEach(k => keys[k] = 0));
128
  const mouse = new THREE.Vector2(9, 9), ray = new THREE.Raycaster(); let drag = null;
129
  const cv = $('#gl');
130
+ const ptrs = new Map(); let pinch0 = 0, idleT = 0; const ZMIN = 4, ZMAX = 400;
131
+ const cam = { yaw: Math.PI, pitch: .16, dist: 11, tdist: 11, free: 0 };
132
  addEventListener('pointermove', e => { mouse.set(e.clientX / innerWidth * 2 - 1, -(e.clientY / innerHeight) * 2 + 1); });
133
  cv.addEventListener('pointerdown', e => { if (!started) return; cv.setPointerCapture(e.pointerId); ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY }); idleT = 0;
134
+ if (ptrs.size === 1) drag = { x: e.clientX, y: e.clientY, moved: 0, pick: pickAt(e.clientX, e.clientY, e.pointerType) };
135
  if (ptrs.size === 2) { const [a, b] = [...ptrs.values()]; pinch0 = Math.hypot(a.x - b.x, a.y - b.y); drag = null; } });
136
  cv.addEventListener('pointermove', e => { const p = ptrs.get(e.pointerId); if (!p) return; p.x = e.clientX; p.y = e.clientY; idleT = 0;
137
+ if (ptrs.size === 2) { const [a, b] = [...ptrs.values()]; const d = Math.hypot(a.x - b.x, a.y - b.y); if (pinch0) cam.tdist = Math.max(ZMIN, Math.min(ZMAX, cam.tdist * pinch0 / d)); pinch0 = d; return; }
138
+ if (!drag) return; const dx = e.clientX - drag.x, dy = e.clientY - drag.y; drag.moved += Math.abs(dx) + Math.abs(dy); drag.x = e.clientX; drag.y = e.clientY;
139
+ if (drag.moved > (e.pointerType === 'mouse' ? 6 : 14)) { cam.yaw -= dx * .006; cam.pitch = Math.max(-.6, Math.min(1.25, cam.pitch + dy * .004)); cam.free = 2.5; cv.style.cursor = 'grabbing'; } });
 
140
  function pickAt(x, y, type) { mouse.set(x / innerWidth * 2 - 1, -(y / innerHeight) * 2 + 1); ray.setFromCamera(mouse, camera); const h = ray.intersectObjects(nodes, false)[0]; let hi = h ? h.object.userData.i : -1;
141
+ if (hi < 0) { let bd = type === 'mouse' ? 18 : 40; nodes.forEach((n, k) => { const p = screenPos(n); const d = Math.hypot(p.x - x, p.y - y); if (p.z < 1 && d < bd && n.getWorldPosition(new THREE.Vector3()).distanceTo(camera.position) < 700) { bd = d; hi = k; } }); } return hi; }
142
+ function endPtr(e) { if (!ptrs.has(e.pointerId)) return; ptrs.delete(e.pointerId); if (ptrs.size < 2) pinch0 = 0;
143
+ if (drag && ptrs.size === 0) { if (drag.moved <= (e.pointerType === 'mouse' ? 6 : 14)) { let hi = drag.pick; if (hi < 0) hi = pickAt(e.clientX, e.clientY, e.pointerType); if (hi >= 0) { select(hi); open(hi); navigator.vibrate?.(8); } }
144
+ drag = null; cv.style.cursor = ''; } }
 
145
  cv.addEventListener('pointerup', endPtr); cv.addEventListener('pointercancel', e => { ptrs.delete(e.pointerId); if (!ptrs.size) { drag = null; pinch0 = 0; cv.style.cursor = ''; } });
146
+ cv.addEventListener('wheel', e => { if (!started) return; e.preventDefault(); idleT = 0; cam.tdist = Math.max(ZMIN, Math.min(ZMAX, cam.tdist * Math.exp(e.deltaY * .0012))); }, { passive: false });
147
+ // touch joystick + up/down
148
+ const joy = { x: 0, y: 0, u: 0 };
149
+ if (matchMedia('(pointer:coarse)').matches || isMobile) { document.body.insertAdjacentHTML('beforeend', '<div id="joy" aria-label="Flug-Joystick"><i></i></div><div id="joyud"><button type="button" data-u="1" aria-label="steigen">▲</button><button type="button" data-u="-1" aria-label="sinken">▼</button></div>');
150
+ const J = $('#joy'), K = J.querySelector('i'); let jid = null, c0 = null;
151
+ J.addEventListener('pointerdown', e => { jid = e.pointerId; J.setPointerCapture(jid); const r = J.getBoundingClientRect(); c0 = { x: r.left + r.width / 2, y: r.top + r.height / 2, R: r.width / 2 }; B.travel = null; });
152
+ J.addEventListener('pointermove', e => { if (e.pointerId !== jid) return; let dx = (e.clientX - c0.x) / c0.R, dy = (e.clientY - c0.y) / c0.R; const l = Math.hypot(dx, dy); if (l > 1) { dx /= l; dy /= l; } joy.x = dx; joy.y = dy; K.style.transform = `translate(${dx * 34}px,${dy * 34}px)`; });
153
+ const end = () => { jid = null; joy.x = joy.y = 0; K.style.transform = ''; }; J.addEventListener('pointerup', end); J.addEventListener('pointercancel', end);
154
+ $('#joyud').querySelectorAll('button').forEach(b => { b.onpointerdown = () => { joy.u = +b.dataset.u; B.travel = null; }; b.onpointerup = b.onpointerleave = () => joy.u = 0; }); }
155
  function cycleQ() { qMode = qMode === 'AUTO' ? 'HIGH' : qMode === 'HIGH' ? 'LOW' : 'AUTO'; if (qMode !== 'AUTO') quality = qMode.toLowerCase(); applyQuality(); }
156
  $('#q').onclick = cycleQ;
157
  let rsT = 0; const onResize = () => { camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix(); applyQuality(); if (innerWidth < 700) { pop.style.left = ''; pop.style.top = ''; } placePop(); };
158
  addEventListener('resize', () => { cancelAnimationFrame(rsT); rsT = requestAnimationFrame(onResize); }); addEventListener('orientationchange', () => setTimeout(onResize, 250)); screen.orientation?.addEventListener?.('change', () => setTimeout(onResize, 250));
159
+ // gamepad: left stick fly, right stick camera, A up / open near, B close, LT/RT down/up, LB/RB studio prev/next
160
+ let gpCool = 0; const pad = { x: 0, y: 0, u: 0 };
161
+ function pollPad() { const p = navigator.getGamepads ? [...navigator.getGamepads()].find(Boolean) : null; pad.x = pad.y = pad.u = 0; if (!p) return;
162
+ const dz = (v) => Math.abs(v) > .15 ? v : 0; pad.x = dz(p.axes[0] || 0); pad.y = dz(p.axes[1] || 0); if (pad.x || pad.y) B.travel = null;
163
+ if (dz(p.axes[2] || 0)) { cam.yaw -= p.axes[2] * .04; cam.free = 2; } if (dz(p.axes[3] || 0)) cam.pitch = Math.max(-.6, Math.min(1.25, cam.pitch + p.axes[3] * .02));
164
+ pad.u = (p.buttons[7]?.value || 0) - (p.buttons[6]?.value || 0) + (p.buttons[0]?.pressed && B.near < 0 ? 1 : 0);
165
+ if (gpCool-- > 0) return; const v = visible(), k = v.indexOf(sel);
166
  if (!started && p.buttons.some(b => b.pressed)) { start(); gpCool = 20; return; }
167
+ if (p.buttons[5]?.pressed) { select(v[(k + 1) % v.length]); focusNode(sel); gpCool = 16; }
168
+ else if (p.buttons[4]?.pressed) { select(v[(k - 1 + v.length) % v.length]); focusNode(sel); gpCool = 16; }
169
+ else if (p.buttons[0]?.pressed && B.near >= 0 && openId == null) { open(B.near); gpCool = 20; } else if (p.buttons[1]?.pressed) { close(); gpCool = 20; } }
 
170
 
171
+ /* ---------- intro: cinematic flythrough (void → stinger shard → east land → mountain → temple → core) ---------- */
172
  const intro = $('#intro'); let introT = 0;
173
  const stage = (n, ms) => setTimeout(() => !started && intro.classList.add('s' + n), ms);
174
+ stage(1, 120); stage(2, 12200); stage(3, 12900); stage(4, 13600); stage(5, 14600);
175
+ const peakY = W.peak;
176
+ const SHOTS = [ // wide on the leaning spire at sunrise → continuous descent onto the east-flank land → ground level
177
+ [0, [9000, 3200, 26000], [-2600, 5200, 0]], [4, [12000, 2600, 17000], [-1200, 3200, 0]], [7.5, [9800, 1900, 9000], [3200, 700, 300]],
178
+ [10.5, [7400, 900, 5200], [4600, 300, 1500]], [13, [5900, 380, 3300], [4700, 120, 1500]], [15.5, null, null]];
179
+ const CAPS = [[0, 'Der Ahnen-Stachel · 12 km'], [4, 'Die Ostflanke'], [7.5, 'Wald · See · Dörfer'], [10.5, 'Die Terrassen der Schreine'], [13, 'Talgrund']];
180
+ document.body.insertAdjacentHTML('beforeend', '<div id="cine" aria-hidden="true"><i class="lb t"></i><i class="lb b"></i><p class="cap"></p></div>');
181
+ const cine = $('#cine'), capEl = cine.querySelector('.cap'); let capI = -1;
182
+ const ease = (x) => x < .5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
183
+ const pA = new THREE.Vector3(), pB = new THREE.Vector3(), lA = new THREE.Vector3(), lB = new THREE.Vector3(), introLook = new THREE.Vector3();
184
+ function introCam(t) { let i = 0; while (i < SHOTS.length - 2 && t > SHOTS[i + 1][0]) i++; const [t0, p0, l0] = SHOTS[i], [t1, p1, l1] = SHOTS[i + 1];
185
+ if (!p1) { camera.position.set(...p0); introLook.set(...l0); camera.lookAt(introLook); return; }
186
+ const k = ease(Math.min(1, (t - t0) / (t1 - t0))); pA.set(...p0); pB.set(...p1); lA.set(...l0); lB.set(...l1); camera.position.lerpVectors(pA, pB, k); introLook.lerpVectors(lA, lB, k); camera.lookAt(introLook);
187
+ const ci = CAPS.findLastIndex(c => t >= c[0]); if (ci !== capI) { capI = ci; capEl.classList.remove('on'); setTimeout(() => { capEl.textContent = CAPS[ci][1]; capEl.classList.add('on'); }, 250); } }
188
  intro.addEventListener('pointermove', e => { const x = e.clientX / innerWidth - .5, y = e.clientY / innerHeight - .5; $('#reveal').style.transform = `translate(${x * -18}px,${y * -14}px) rotateY(${x * 6}deg)`; });
189
  function start() {
190
+ if (started) return; started = true; beep(110, .5, 'sine', .06);
191
+ intro.classList.add('out'); cine.classList.add('out'); setTimeout(() => { intro.remove(); cine.remove(); }, 1100);
192
+ ['#hud', '#hint', '#core-stats', '#frame', '#mm'].forEach(s => $(s).hidden = false); document.body.classList.add('live'); setCat('Alle'); select(0);
193
+ camT.copy(camera.position); cam.yaw = B.yaw; cam.pitch = .18;
194
  }
195
  $('#skip').onclick = (e) => { e.stopPropagation(); start(); };
196
  intro.addEventListener('pointerdown', (e) => { if (e.target.id !== 'skip') start(); });
 
197
 
198
  /* ---------- loop ---------- */
199
+ const clock = new THREE.Clock(); let frames = 0, fpsT = 0, statT = 0, mmT = 0;
200
  const mm = $('#mm'); const mmDots = STUDIOS.map((s, i) => { const c = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); c.setAttribute('r', 2.6); mm.querySelector('#mmd').append(c); return c; });
201
+ const MMS = .0075, mmX = (x) => 50 + (x - 3500) * MMS, mmY = (z) => 50 + z * MMS;
202
+ let mmBee = null;
203
+ function drawMinimap(v) { const vw = mm.querySelector('#mmv'); nodes.forEach((n, i) => { const c = mmDots[i], g = W.shrines[i].group; c.setAttribute('cx', mmX(g.position.x)); c.setAttribute('cy', mmY(g.position.z)); c.setAttribute('class', i === sel ? 'sel' : v.includes(i) ? 'on' : 'off'); });
204
+ if (!mmBee) { mmBee = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); mmBee.setAttribute('r', 3.4); mmBee.setAttribute('class', 'bee'); mm.append(mmBee); }
205
+ mmBee.setAttribute('cx', Math.max(4, Math.min(96, mmX(B.pos.x)))); mmBee.setAttribute('cy', Math.max(4, Math.min(96, mmY(B.pos.z))));
206
+ vw.setAttribute('transform', `translate(${mmX(B.pos.x) - 50} ${mmY(B.pos.z) - 50}) rotate(${-cam.yaw * 180 / Math.PI + 180} 50 50)`); }
207
  const stats = $('#core-stats');
 
 
208
  const AR = { pr: 1, ema: 16.7, t: 0, slow: 0 }; let lastT = performance.now();
209
  function setPR(p) { if (!renderer) return; AR.pr = p; renderer.setPixelRatio(p); renderer.setSize(innerWidth, innerHeight, false); if (composer) { composer.setPixelRatio(p); composer.setSize(innerWidth, innerHeight); } }
210
  let paused = document.hidden, ctxLost = false;
211
+ document.addEventListener('visibilitychange', () => { paused = document.hidden; lastT = performance.now(); if (paused) { ac?.suspend?.(); } else if (soundOn) ac?.resume?.(); });
212
  if (renderer) { const c = renderer.domElement;
213
  c.addEventListener('webglcontextlost', e => { e.preventDefault(); ctxLost = true; if (!$('#ctxmsg')) document.body.insertAdjacentHTML('beforeend', '<div id="ctxmsg" role="status" style="position:fixed;left:50%;top:70px;transform:translateX(-50%);z-index:40;padding:6px 12px;border:1px solid #faa968;background:#000c;color:#faa968;font-size:12px;border-radius:6px">GPU-Kontext verloren – stelle wieder her…</div>'); });
214
  c.addEventListener('webglcontextrestored', () => { ctxLost = false; $('#ctxmsg')?.remove(); applyQuality(); setPR(AR.pr); lastT = performance.now(); }); }
215
  window.__studiusLoseCtx = () => renderer?.forceContextLoss?.();
216
  window.__studiusRestoreCtx = () => renderer?.forceContextRestore?.();
217
+ const camT = new THREE.Vector3(), look = new THREE.Vector3(), fwd = new THREE.Vector3(), rgt = new THREE.Vector3(), acc = new THREE.Vector3(), tmpV = new THREE.Vector3();
218
+ const angLerp = (a, b, k) => { let d = b - a; d = Math.atan2(Math.sin(d), Math.cos(d)); return a + d * k; };
219
+ function updateBee(dt, t) {
220
+ const inF = (keys.f ? 1 : 0) - (keys.b ? 1 : 0) - joy.y - pad.y, inR = (keys.r ? 1 : 0) - (keys.l ? 1 : 0) + joy.x + pad.x, inU = (keys.u ? 1 : 0) - (keys.dn ? 1 : 0) + joy.u + pad.u;
221
+ const moving = Math.abs(inF) + Math.abs(inR) + Math.abs(inU) > .05;
222
+ if (B.travel) { const T = B.travel; T.t += dt / T.d; const k = ease(Math.min(1, T.t)); const arc = Math.sin(k * Math.PI) * Math.min(400, T.from.distanceTo(T.to) * .25);
223
+ const p = tmpV.lerpVectors(T.from, T.to, k); p.y += arc; B.vel.subVectors(p, B.pos).divideScalar(Math.max(dt, 1e-3)); B.pos.copy(p); const sh = W.shrines[T.i].group.position; if (B.vel.lengthSq() > 4) B.yaw = angLerp(B.yaw, Math.atan2(-B.vel.z, B.vel.x), Math.min(1, dt * 5)); if (k > .85) B.yaw = angLerp(B.yaw, Math.atan2(-(sh.z - B.pos.z), sh.x - B.pos.x), Math.min(1, dt * 4)); if (T.t >= 1) B.travel = null; }
224
+ else { fwd.set(Math.cos(cam.yaw + Math.PI), 0, -Math.sin(cam.yaw + Math.PI)); rgt.set(-fwd.z, 0, fwd.x).multiplyScalar(-1); rgt.set(fwd.z * -1, 0, fwd.x); rgt.set(-fwd.z, 0, fwd.x);
225
+ const sp = keys.boost ? 320 : 45; acc.set(0, 0, 0).addScaledVector(fwd, inF).addScaledVector(rgt, inR); if (acc.lengthSq() > 1) acc.normalize(); acc.multiplyScalar(sp); acc.y = inU * sp * .7;
226
+ B.vel.lerp(acc, Math.min(1, dt * (moving ? 2.6 : 1.6))); B.pos.addScaledVector(B.vel, dt);
227
+ const hv = Math.hypot(B.vel.x, B.vel.z); if (hv > 1.5) B.yaw = angLerp(B.yaw, Math.atan2(-B.vel.z, B.vel.x), Math.min(1, dt * 6)); }
228
+ const g = landH(B.pos.x, B.pos.z); if (B.pos.y < g + 2.2) { B.pos.y = g + 2.2; B.vel.y = Math.max(0, B.vel.y); }
229
+ const R = Math.hypot(B.pos.x - MC.x, B.pos.z - MC.y); if (R > 60000) B.pos.addScaledVector(tmpV.set(MC.x - B.pos.x, 0, MC.y - B.pos.z).normalize(), (R - 60000)); B.pos.y = Math.min(30000, B.pos.y);
230
+ const hover = Math.sin(t * 3.1) * .25; bee.position.set(B.pos.x, B.pos.y + hover, B.pos.z);
231
+ const lat = THREE.MathUtils.clamp(inR * -.5 + (B.travel ? 0 : 0), -.6, .6); B.bank = THREE.MathUtils.lerp(B.bank, lat, Math.min(1, dt * 4));
232
+ bee.rotation.set(B.bank, B.yaw, THREE.MathUtils.clamp(B.vel.y * .012, -.4, .4) - Math.min(.25, Math.hypot(B.vel.x, B.vel.z) * .004), 'YXZ');
233
+ const fl = Math.sin(t * 60) * .9; bee.userData.wings.forEach(w => { w.piv.rotation.x = w.s * fl; });
234
+ // proximity: fly INTO a shrine portal → open its studio
235
+ let near = -1, nd = 1e9; nodes.forEach((n, i) => { const d = n.getWorldPosition(tmpV).distanceTo(B.pos); if (d < nd) { nd = d; near = i; } }); B.near = nd < 90 ? near : -1; window.__near = { i: B.near, d: +nd.toFixed(1) };
236
+ if (nd > 40) B.armed = true;
237
+ if (B.armed && nd < 7.5 && openId == null && !B.travel && started) { B.armed = false; select(near); open(near, true); }
238
+ if (B.near >= 0 && B.near !== sel && openId == null) select(B.near);
239
+ return moving; }
240
  function frame(now) {
241
  requestAnimationFrame(frame);
242
  if (paused || ctxLost) { lastT = now ?? performance.now(); window.__paused = (window.__paused || 0) + (paused ? 1 : 0); return; }
 
246
  if (AR.t > .6) { AR.t = 0; const mxp = quality === 'high' ? Math.min(devicePixelRatio, 2) : Math.min(devicePixelRatio, 1.25); let p = AR.pr;
247
  if (AR.ema > 19) p = Math.max(.6, p - (AR.ema > 30 ? .15 : .08)); else if (AR.ema < 14.5) p = Math.min(mxp, p + .05); if (Math.abs(p - AR.pr) > .01) setPR(+p.toFixed(2));
248
  AR.slow = AR.pr <= .6 && AR.ema > 34 ? AR.slow + 1 : 0; if (AR.slow > 4 && quality === 'high') { quality = 'low'; applyQuality(); AR.slow = 0; } } }
249
+ window.__pr = AR.pr; pollPad();
250
+ if (shotCam) { camera.position.set(...shotCam[0]); introLook.set(...shotCam[1]); camera.lookAt(introLook); }
251
+ else if (!started) { introT += dt; introCam(introT); if (introT > 16) start(); }
252
+ else { idleT += dt; const moving = updateBee(dt, t);
253
+ // third-person follow camera: behind the bee, user can orbit (drag/right stick), springs back while flying
254
+ cam.free = Math.max(0, cam.free - dt); if (moving && cam.free <= 0 && !drag) cam.yaw = angLerp(cam.yaw, B.yaw + Math.PI, Math.min(1, dt * 1.6)); if (B.travel && !drag) cam.yaw = angLerp(cam.yaw, B.yaw + Math.PI, Math.min(1, dt * 2.2));
255
+ cam.dist = THREE.MathUtils.lerp(cam.dist, cam.tdist + (B.travel ? 30 : 0) + Math.min(30, B.vel.length() * .06), Math.min(1, dt * 3));
256
+ const cp = Math.cos(cam.pitch); tmpV.set(Math.cos(cam.yaw) * cp, Math.sin(cam.pitch), -Math.sin(cam.yaw) * cp).multiplyScalar(cam.dist).add(B.pos); tmpV.y += 2.5;
257
+ const gh = landH(tmpV.x, tmpV.z) + 2.5; if (tmpV.y < gh) tmpV.y = gh;
258
+ camT.lerp(tmpV, Math.min(1, dt * 6)); camera.position.copy(camT);
259
+ const mob = innerWidth < 700, want = openId == null ? 0 : 1; lookK += (want - lookK) * Math.min(1, dt * 4);
260
+ look.copy(B.pos); look.y += 1.5; if (!mob && lookK > .01) { rgt.set(Math.sin(cam.yaw), 0, Math.cos(cam.yaw)); look.addScaledVector(rgt, .32 * cam.dist * camera.aspect * lookK); } camera.lookAt(look); }
261
+ W.update(t, dt, camera, started && !shotCam ? B.pos : introLook);
262
+ if (bokeh && quality === 'high') { const f = started ? camera.position.distanceTo(B.pos) : camera.position.distanceTo(introLook) * .9; bokeh.uniforms.focus.value = f; bokeh.uniforms.aperture.value = started ? .00002 : 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  if (started && !drag && mouse.x < 5 && openId == null) { ray.setFromCamera(mouse, camera); const h = ray.intersectObjects(nodes, false)[0]; cv.style.cursor = h ? 'pointer' : 'grab'; if (h && h.object.userData.i !== sel) select(h.object.userData.i); }
264
+ if (renderer) { if (composer && (quality === 'high' || !soft)) composer.render(); else renderer.render(scene, camera); }
 
265
  if (started) {
266
+ const placed = []; const camP = camera.position; const v = visible();
267
+ const blk = ['#hud', '#core-stats', '#mm', '#pop', '#hint', '#bmc', '#joy', '#joyud'].map(q => $(q)).filter(e => e && !e.hidden && e.offsetParent !== null).map(e => e.getBoundingClientRect());
268
+ nodes.map((n, i) => ({ n, i, d: n.getWorldPosition(tmpV).distanceTo(camP) })).sort((a, b) => a.d - b.d).forEach(({ n, i, d }, rank) => {
269
+ const p = screenPos(n); const l = labels[i]; if (p.z >= 1 || (d > 3500 && i !== sel)) { l.style.display = 'none'; return; } l.style.display = '';
270
+ const far = (rank > 7 || d > 1500) && i !== sel && i !== openId; l.classList.toggle('far', far);
271
+ const w = far ? 30 : l.offsetWidth || 110, h = 26; let y = p.y - 30;
272
  for (let k = 0; k < 6; k++) { const hit = placed.find(r => Math.abs(r.x - p.x) < (r.w + w) / 2 + 4 && Math.abs(r.y - y) < h); if (!hit) break; y = hit.y + (y >= hit.y ? h : -h); }
273
  placed.push({ x: p.x, y, w });
274
  const lx0 = p.x - w / 2, lx1 = p.x + w / 2; l.classList.toggle('hid', blk.some(r => lx0 < r.right && lx1 > r.left && y - 13 < r.bottom && y + 13 > r.top)); l.style.transform = `translate(${p.x}px,${y}px) translate(-50%,-50%)`; l.style.zIndex = 100 - rank;
275
  l.classList.toggle('dim', !v.includes(i)); });
276
  if ((mmT += dt) > .1) { mmT = 0; drawMinimap(v); }
277
  if (openId != null && !pop.hidden) { const p = screenPos(nodes[openId]); const r = pop.getBoundingClientRect(); const wl = $('#wl');
278
+ const tx = p.x < r.left ? r.left : r.right; wl.setAttribute('x1', p.x); wl.setAttribute('y1', p.y); wl.setAttribute('x2', tx); wl.setAttribute('y2', r.top + 14); }
279
+ if ((statT += dt) > .5) { statT = 0; const ld = (55 + Math.sin(t * .7) * 20) | 0; stats.innerHTML = `<h4>META-ENGINE CORE</h4><dl><dt>Agenten</dt><dd>${120 + (Math.sin(t) * 8 | 0)}</dd><dt>Tokens/s</dt><dd>${(4200 + Math.random() * 900) | 0}</dd><dt>Studios</dt><dd>${STUDIOS.length}</dd><dt>Höhe</dt><dd>${Math.round(B.pos.y)} m</dd></dl><div class="bar"><i style="width:${ld}%"></i></div><p>● SIMULATION</p>`; }
 
280
  }
281
  }
282
  setPR(1); applyQuality();
283
+ window.__studius = { STUDIOS, select: (i) => select(i), core: () => screenPos(core), get sel() { return sel; }, get openId() { return openId; }, get zoom() { return cam.dist; }, get th() { return cam.yaw; }, nodeScreen: (i) => screenPos(nodes[i]), open: (i) => { select(i); open(i); }, close: () => close(), get paused() { return paused; }, get ctxLost() { return ctxLost; } };
284
+ window.__world = { bee: B, cam, camera, W, keys, flyTo: (i) => { select(i); focusNode(i); }, shot: (pos, at) => { shotCam = pos ? [pos, at] : null; }, get quality() { return quality; }, setQ: (q) => { qMode = q.toUpperCase(); quality = q; applyQuality(); } };
285
  if (gl3d) requestAnimationFrame(frame); else { setTimeout(() => start(), 7800);
286
  document.body.insertAdjacentHTML('beforeend', '<div style="position:fixed;left:14px;top:60px;z-index:16;color:#faa968;font-size:11px">⚠ WebGL nicht verfügbar – 2D-Modus</div>');
287
+ STUDIOS.forEach((s, i) => { labels[i].style.transform = `translate(${80 + (i % 5) * 180}px,${140 + (i / 5 | 0) * 60}px)`; });
 
 
 
288
  }
assets/tex/LICENSE.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Poly Haven CC0 textures (https://polyhaven.com/license): rock_face, aerial_rocks_02 (1k)
assets/tex/aerial_rocks_02-diff.webp ADDED

Git LFS Details

  • SHA256: 7a5d5eefd4b7cb2d792c96046ada7d75220d851cf6192f1dfc384877a0e62c3d
  • Pointer size: 131 Bytes
  • Size of remote file: 304 kB
assets/tex/aerial_rocks_02-nor_gl.webp ADDED

Git LFS Details

  • SHA256: 8d31b500d7d7b8076928dbeec17eb7c76959f966df91925e1309c30864d9e4a3
  • Pointer size: 131 Bytes
  • Size of remote file: 341 kB
assets/tex/aerial_rocks_02-rough.webp ADDED

Git LFS Details

  • SHA256: 3ffb3708bf3ee01c5738a16d1e70937fc07bd0b71549156787528da2a67d868e
  • Pointer size: 131 Bytes
  • Size of remote file: 149 kB
assets/tex/rock_face-diff.webp ADDED

Git LFS Details

  • SHA256: 9686be928ee4b423cd10d5258d6eafc16504d6d4d5b2d6dbc0b02a971b08f7dc
  • Pointer size: 131 Bytes
  • Size of remote file: 106 kB
assets/tex/rock_face-nor_gl.webp ADDED

Git LFS Details

  • SHA256: 0ff19ebf79e3fa8496379f3314f28006ba8af23e59eabeaf4fa04b215be9e9a2
  • Pointer size: 131 Bytes
  • Size of remote file: 299 kB
assets/tex/rock_face-rough.webp ADDED
avatar.js CHANGED
@@ -1,7 +1,7 @@
1
  // Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
2
  // avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
3
  import { STUDIOS, onStop } from './widgets.js?v=50';
4
- import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=96';
5
 
6
  export const MODA = 'multimodalart/MoDA-fast-talking-head', W2L = 'pragnakalp/Wav2lip-ZeroGPU';
7
  const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
 
1
  // Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
2
  // avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
3
  import { STUDIOS, onStop } from './widgets.js?v=50';
4
+ import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=102';
5
 
6
  export const MODA = 'multimodalart/MoDA-fast-talking-head', W2L = 'pragnakalp/Wav2lip-ZeroGPU';
7
  const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
index.html CHANGED
@@ -8,7 +8,7 @@
8
  <title>STUDIUS · DAS Studio — Einswarm</title>
9
  <link rel="icon" href="assets/einswarm-mascot.webp">
10
  <link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
11
- <link rel="stylesheet" href="style.css?v=96">
12
  </head>
13
  <body>
14
  <canvas id="gl"></canvas>
@@ -45,10 +45,10 @@
45
  <div id="labels"></div>
46
  <svg id="wire"><line id="wl" x1="0" y1="0" x2="0" y2="0"/></svg>
47
  <div id="pop" hidden></div>
48
- <footer id="hint" hidden><kbd>←→</kbd><kbd>WASD</kbd> wählen <kbd>ENTER</kbd> öffnen <kbd>ESC</kbd> zurück <kbd>C</kbd> Kategorie <kbd>TAB</kbd> Fokus <kbd>Q</kbd> Qualität · Ziehen = Orbit</footer>
49
 
50
  <a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
51
  <noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
52
- <script type="module" src="app.js?v=96"></script>
53
  </body>
54
  </html>
 
8
  <title>STUDIUS · DAS Studio — Einswarm</title>
9
  <link rel="icon" href="assets/einswarm-mascot.webp">
10
  <link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
11
+ <link rel="stylesheet" href="style.css?v=102">
12
  </head>
13
  <body>
14
  <canvas id="gl"></canvas>
 
45
  <div id="labels"></div>
46
  <svg id="wire"><line id="wl" x1="0" y1="0" x2="0" y2="0"/></svg>
47
  <div id="pop" hidden></div>
48
+ <footer id="hint" hidden><kbd>WASD</kbd> fliegen <kbd>SPACE</kbd>/<kbd>X</kbd> hoch/runter <kbd>SHIFT</kbd> schnell · in ein Portal fliegen = Studio <kbd>N</kbd>/<kbd>P</kbd> nächstes Studio <kbd>ENTER</kbd> öffnen <kbd>ESC</kbd> zurück <kbd>H</kbd> Start · Ziehen = Kamera</footer>
49
 
50
  <a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
51
  <noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
52
+ <script type="module" src="app.js?v=102"></script>
53
  </body>
54
  </html>
master.js CHANGED
@@ -1,7 +1,7 @@
1
  // Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
2
  // (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
3
  import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
4
- import { result, MODULES, esc, setS, keep } from './real.js?v=96';
5
 
6
  /* ---------- BS.1770 loudness ---------- */
7
  function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
 
1
  // Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
2
  // (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
3
  import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
4
+ import { result, MODULES, esc, setS, keep } from './real.js?v=102';
5
 
6
  /* ---------- BS.1770 loudness ---------- */
7
  function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
studios5.js CHANGED
@@ -1,9 +1,9 @@
1
  // STUDIUS P5: Radio Studio · Social/Marketing Studio · Shop Studio (JDT link-shop) + video reframe helper.
2
  // Every result goes on the asset bus (save to workspace / send to studio). Nothing is ever posted or published externally.
3
  import { STUDIOS } from './widgets.js?v=50';
4
- import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, signedIn, TF, CHAT, FLUX } from './real.js?v=96';
5
- import { Avatars } from './avatar.js?v=96';
6
- import { toWav, toMp3 } from './master.js?v=96';
7
 
8
  const bucket = () => signedIn() && window.__ws?.bucket;
9
  const wsFile = (p) => '/api/ws/file?bucket=' + encodeURIComponent(window.__ws.bucket) + '&path=' + encodeURIComponent(p);
 
1
  // STUDIUS P5: Radio Studio · Social/Marketing Studio · Shop Studio (JDT link-shop) + video reframe helper.
2
  // Every result goes on the asset bus (save to workspace / send to studio). Nothing is ever posted or published externally.
3
  import { STUDIOS } from './widgets.js?v=50';
4
+ import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, signedIn, TF, CHAT, FLUX } from './real.js?v=102';
5
+ import { Avatars } from './avatar.js?v=102';
6
+ import { toWav, toMp3 } from './master.js?v=102';
7
 
8
  const bucket = () => signedIn() && window.__ws?.bucket;
9
  const wsFile = (p) => '/api/ws/file?bucket=' + encodeURIComponent(window.__ws.bucket) + '&path=' + encodeURIComponent(p);
style.css CHANGED
@@ -248,3 +248,19 @@ body:not(.live) #beebtn{display:none}
248
  .cols label{margin-right:8px;font-size:12px}.sw{display:inline-block;width:12px;height:12px;border-radius:50%;border:1px solid var(--line2);margin:0 3px -2px}
249
  .price{margin:4px 0}.price b{color:var(--gold);font-size:18px}
250
  #pop .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:8px}.pcard{border:1px solid var(--line);border-radius:8px;padding:6px;display:flex;flex-direction:column;gap:3px;font-size:11px}.pcard img{width:100%;border-radius:6px}.pcard a{color:var(--gold)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  .cols label{margin-right:8px;font-size:12px}.sw{display:inline-block;width:12px;height:12px;border-radius:50%;border:1px solid var(--line2);margin:0 3px -2px}
249
  .price{margin:4px 0}.price b{color:var(--gold);font-size:18px}
250
  #pop .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:8px}.pcard{border:1px solid var(--line);border-radius:8px;padding:6px;display:flex;flex-direction:column;gap:3px;font-size:11px}.pcard img{width:100%;border-radius:6px}.pcard a{color:var(--gold)}
251
+
252
+ /* P5 world: cinematic intro over the live 3D flythrough */
253
+ #intro{background:radial-gradient(ellipse at center,rgba(0,0,0,0) 40%,rgba(0,0,0,.55) 100%)!important}
254
+ #intro .sweep,#intro .halo{opacity:.35}
255
+ #cine{position:fixed;inset:0;z-index:39;pointer-events:none}#cine .lb{position:absolute;left:0;right:0;height:9vh;background:#000;transition:transform 1s var(--ease)}#cine .t{top:0}#cine .b{bottom:0}
256
+ #cine.out .t{transform:translateY(-100%)}#cine.out .b{transform:translateY(100%)}
257
+ #cine .cap{position:absolute;left:6vw;bottom:13vh;margin:0;font-size:clamp(18px,2.6vw,34px);letter-spacing:.32em;text-transform:uppercase;color:#f6e3b0;text-shadow:0 0 18px rgba(242,201,76,.6),0 2px 8px #000;opacity:0;transform:translateY(8px);transition:opacity .8s,transform .8s}
258
+ #cine .cap.on{opacity:1;transform:none}
259
+ #intro:not(.s2) #reveal{opacity:0}#intro #reveal{transition:opacity 1.2s,transform .3s ease-out}
260
+ #hexbg{display:none}
261
+ #joy{position:fixed;left:22px;bottom:90px;width:110px;height:110px;border-radius:50%;border:1px solid var(--line2);background:rgba(10,8,4,.35);z-index:20;touch-action:none;backdrop-filter:blur(4px)}
262
+ #joy i{position:absolute;left:50%;top:50%;width:46px;height:46px;margin:-23px;border-radius:50%;background:radial-gradient(circle at 35% 35%,#ffe7a0,#c8941e);box-shadow:0 0 16px rgba(242,201,76,.5)}
263
+ #joyud{position:fixed;right:22px;bottom:110px;z-index:20;display:flex;flex-direction:column;gap:10px}#joyud button{width:54px;height:54px;border-radius:50%;border:1px solid var(--line2);background:rgba(10,8,4,.45);color:var(--gold);font-size:20px;touch-action:none}
264
+ #mm circle.bee{fill:#fff;stroke:#f2c94c;stroke-width:1.2}
265
+
266
+ body:not(.live) #labels{display:none}
video.js CHANGED
@@ -1,7 +1,7 @@
1
  // STUDIUS P3.4: Video Gen (LTX-Video, text→video + image→video), Video Edit (trim, soundtrack, title, fades → MP4/WebM export)
2
  // and Stems (Demucs split → synced mixer with gain/mute/solo → WAV mixdown). All results go on the asset bus (save / send).
3
- import { run, result, MODULES, esc, hf, stTxt, url, badge, timer, setS, S, keep } from './real.js?v=96';
4
- import { toWav } from './master.js?v=96';
5
  import { onStop } from './widgets.js?v=50';
6
 
7
  export const LTX = 'Lightricks/ltx-video-distilled';
 
1
  // STUDIUS P3.4: Video Gen (LTX-Video, text→video + image→video), Video Edit (trim, soundtrack, title, fades → MP4/WebM export)
2
  // and Stems (Demucs split → synced mixer with gain/mute/solo → WAV mixdown). All results go on the asset bus (save / send).
3
+ import { run, result, MODULES, esc, hf, stTxt, url, badge, timer, setS, S, keep } from './real.js?v=102';
4
+ import { toWav } from './master.js?v=102';
5
  import { onStop } from './widgets.js?v=50';
6
 
7
  export const LTX = 'Lightricks/ltx-video-distilled';
workspace.js CHANGED
@@ -1,6 +1,6 @@
1
  // STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
2
- import { MODULES, refreshQuota } from './real.js?v=96';
3
- import { Avatars } from './avatar.js?v=96';
4
  const $ = (s, r = document) => r.querySelector(s);
5
  const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
6
  const ST = () => window.__studius.STUDIOS;
 
1
  // STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
2
+ import { MODULES, refreshQuota } from './real.js?v=102';
3
+ import { Avatars } from './avatar.js?v=102';
4
  const $ = (s, r = document) => r.querySelector(s);
5
  const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
6
  const ST = () => window.__studius.STUDIOS;
world.js ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // STUDIUS World (realistic): a single colossal fossil bee stinger (~12 km) juts out of the earth, leaning ~30° from vertical
2
+ // toward the west. Its broken base is buried in a rocky massif; soil and rock have piled up against its broad lower EAST flank,
3
+ // and on that flank-slope lies the land: forest, lake, villages, a snow-capped mountain with the temple on its summit, and
4
+ // shrine terraces climbing toward the stinger. Real ground runs to the horizon. Sun rises in the east (+X). Units: metres.
5
+ import * as THREE from './vendor/three.module.min.js';
6
+ import { ImprovedNoise } from './vendor/addons/math/ImprovedNoise.js';
7
+ import { Sky } from './vendor/addons/objects/Sky.js';
8
+
9
+ const N3 = new ImprovedNoise(); const nz = (x, y, z = 0) => N3.noise(x, y, z);
10
+ const fbm = (x, z, o = 5, s = 0) => { let a = 0, f = 1, w = .5; for (let i = 0; i < o; i++) { a += w * nz(x * f, z * f, s + i * 7.1); f *= 2.03; w *= .5; } return a; };
11
+ const ridged = (x, z, o = 5) => { let a = 0, f = 1, w = .55; for (let i = 0; i < o; i++) { const n = 1 - Math.abs(nz(x * f, z * f, 3.3 + i)); a += w * n * n; f *= 2.07; w *= .48; } return a; };
12
+ const sstep = (a, b, x) => { const t = Math.min(1, Math.max(0, (x - a) / (b - a))); return t * t * (3 - 2 * t); };
13
+ let seed = 11; const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
14
+ export const SUN_DIR = new THREE.Vector3(1, .075, .3).normalize();
15
+ export const SPIRE = { L: 12500, R0: 1900, tilt: THREE.MathUtils.degToRad(30), bury: 1600 };
16
+ export const MC = new THREE.Vector2(7200, -2100); // snow mountain (temple)
17
+ const LAKE = { x: 4700, z: 1500, r: 520 }; let LAKE_Y = 0;
18
+ const RIVER = [[6200, -600], [5800, 0], [5300, 700], [5000, 1150]];
19
+ const VILLAGE = { x: 5600, z: 2350, r: 380 }; const VILLAGE2 = { x: 3600, z: -1500, r: 260 };
20
+ const PATCH = { x0: 600, x1: 10500, z0: -5500, z1: 5500 };
21
+ const curv = () => 0;
22
+ /* ---------- textures ---------- */
23
+ const TL = new THREE.TextureLoader();
24
+ const tex = (p, srgb, rep = 1) => { const t = TL.load(p); t.wrapS = t.wrapT = THREE.RepeatWrapping; t.repeat.set(rep, rep); t.anisotropy = 8; if (srgb) t.colorSpace = THREE.SRGBColorSpace; return t; };
25
+ function canvasTex(w, h, draw, srgb = true) { const c = document.createElement('canvas'); c.width = w; c.height = h; draw(c.getContext('2d'), w, h); const t = new THREE.CanvasTexture(c); t.wrapS = t.wrapT = THREE.RepeatWrapping; t.anisotropy = 8; if (srgb) t.colorSpace = THREE.SRGBColorSpace; return t; }
26
+ const cloudTex = canvasTex(256, 256, (x) => { for (let i = 0; i < 90; i++) { const px = 128 + (Math.random() - .5) * 160, py = 150 + (Math.random() - .5) * 60 - Math.random() * 40, r = 18 + Math.random() * 55; const g = x.createRadialGradient(px, py - r * .2, 0, px, py, r); g.addColorStop(0, 'rgba(255,255,255,.28)'); g.addColorStop(.6, 'rgba(235,235,240,.12)'); g.addColorStop(1, 'rgba(255,255,255,0)'); x.fillStyle = g; x.fillRect(0, 0, 256, 256); } });
27
+ export const M = {};
28
+ // shared triplanar injection (world-space, no stretching on cliffs)
29
+ const TRI = `vec3 triT(sampler2D t, vec3 p, vec3 n, float sc){ vec3 b = pow(abs(n), vec3(4.0)); b /= (b.x+b.y+b.z); return texture2D(t,p.zy*sc).rgb*b.x + texture2D(t,p.xz*sc).rgb*b.y + texture2D(t,p.xy*sc).rgb*b.z; }`;
30
+ function withWorld(m, frag, uniforms) { m.onBeforeCompile = (s) => { Object.assign(s.uniforms, uniforms);
31
+ s.vertexShader = s.vertexShader.replace('#include <common>', '#include <common>\nvarying vec3 vWP; varying vec3 vWN;').replace('#include <worldpos_vertex>', '#include <worldpos_vertex>\nvWP = (modelMatrix * vec4(transformed,1.0)).xyz; vWN = normalize(mat3(modelMatrix) * objectNormal);');
32
+ s.fragmentShader = s.fragmentShader.replace('#include <common>', '#include <common>\nvarying vec3 vWP; varying vec3 vWN;\n' + Object.keys(uniforms).map(k => `uniform ${uniforms[k].type || 'sampler2D'} ${k};`).join('\n') + '\n' + TRI).replace('#include <map_fragment>', frag); }; return m; }
33
+ function makeMaterials(q) {
34
+ const rockD = tex('assets/tex/rock_face-diff.webp', true), rockN = tex('assets/tex/rock_face-nor_gl.webp'), aerD = tex('assets/tex/aerial_rocks_02-diff.webp', true), aerN = tex('assets/tex/aerial_rocks_02-nor_gl.webp');
35
+ // terrain: grass/forest floor on flats, rock on slopes, snow on high flats; colour from vertex attr + triplanar detail
36
+ M.terrain = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .95, normalMap: aerN, normalScale: new THREE.Vector2(.9, .9) }), `
37
+ float slope = 1.0 - clamp(vWN.y, 0.0, 1.0);
38
+ vec3 det = triT(tAer, vWP, vWN, 0.02) * 0.6 + triT(tAer, vWP, vWN, 0.0019) * 0.6;
39
+ vec3 rk = triT(tRock, vWP, vWN, 0.012) * vec3(0.78,0.74,0.7);
40
+ vec3 base = vColor.rgb * mix(vec3(1.0), det * 1.5, 0.55);
41
+ float rockK = smoothstep(0.32, 0.62, slope);
42
+ float snow = smoothstep(2600.0, 1500.0, length(vWP.xz - vec2(7200.0, -2100.0))) * smoothstep(1250.0, 1500.0, vWP.y + 120.0 * sin(vWP.x*0.01) * cos(vWP.z*0.013)) * (1.0 - smoothstep(0.45, 0.75, slope));
43
+ vec3 c = mix(base, rk, rockK); c = mix(c, vec3(0.93,0.95,1.0) * (0.85 + 0.15 * det.r), snow);
44
+ diffuseColor.rgb = c;`, { tAer: { value: aerD }, tRock: { value: rockD } });
45
+ // stinger: weathered stone-chitin, natural amber-ochre banding, lichen; huge-scale + close-scale detail
46
+ M.stinger = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .93, metalness: 0, normalMap: rockN, normalScale: new THREE.Vector2(1.1, 1.1) }), `
47
+ vec3 a = triT(tRock, vWP, vWN, 0.004), b = triT(tRock, vWP, vWN, 0.00021), d = triT(tAer, vWP, vWN, 0.0000135);
48
+ vec3 c = vColor.rgb * (a * 0.55 + b * 0.75 + d * 0.5) * 1.15;
49
+ diffuseColor.rgb = c;`, { tRock: { value: rockD }, tAer: { value: aerD } });
50
+ M.spire = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .9, normalMap: rockN, normalScale: new THREE.Vector2(1.3, 1.3) }), `
51
+ vec3 a = triT(tRock, vWP, vWN, 0.02), b = triT(tRock, vWP, vWN, 0.0016);
52
+ vec3 c = vColor.rgb * (a * 0.6 + b * 0.7) * 1.25;
53
+ float moss = smoothstep(0.35, 0.75, vWN.y) * smoothstep(-0.2, 0.4, sin(vWP.x*0.004)*cos(vWP.z*0.005) + sin(vWP.y*0.003));
54
+ c = mix(c, vec3(0.24,0.29,0.12) * (0.7 + 0.6*b.g), moss * 0.85);
55
+ diffuseColor.rgb = c;`, { tRock: { value: rockD } });
56
+ M.barb = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1), normalMap: rockN, color: 0x6a5c4c, roughness: .9 });
57
+ M.stone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.5), normalMap: rockN, color: 0xb3a691, roughness: .92 });
58
+ M.darkStone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.2), normalMap: rockN, color: 0x6f665c, roughness: .9 });
59
+ M.bronze = new THREE.MeshStandardMaterial({ color: 0x8a6a3c, metalness: .85, roughness: .48 });
60
+ M.patina = new THREE.MeshStandardMaterial({ color: 0x4f6d5a, metalness: .55, roughness: .7 });
61
+ M.wood = new THREE.MeshStandardMaterial({ color: 0x5a4330, roughness: .85 });
62
+ M.roof = new THREE.MeshStandardMaterial({ color: 0x3b3430, roughness: .8 });
63
+ M.wall = new THREE.MeshStandardMaterial({ color: 0xcfc2a8, roughness: .9 });
64
+ M.pine = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .9 }); M.trunk = new THREE.MeshStandardMaterial({ color: 0x3d2c1f, roughness: 1 });
65
+ M.water = new THREE.MeshPhysicalMaterial({ color: 0x1d3442, roughness: .06, metalness: 0, transmission: 0, clearcoat: 1, clearcoatRoughness: .05, envMapIntensity: 1.3 });
66
+ M.cloth = new THREE.MeshStandardMaterial({ color: 0x8b6b2e, roughness: .9, side: THREE.DoubleSide });
67
+ }
68
+
69
+ /* ---------- terrain: world to the horizon + the east-flank land ---------- */
70
+ const PADS = [];
71
+ function distSeg(px, pz, ax, az, bx, bz) { const vx = bx - ax, vz = bz - az, t = Math.max(0, Math.min(1, ((px - ax) * vx + (pz - az) * vz) / (vx * vx + vz * vz))); return Math.hypot(px - ax - vx * t, pz - az - vz * t); }
72
+ function riverD(x, z) { let d = 1e9; for (let i = 0; i < RIVER.length - 1; i++) d = Math.min(d, distSeg(x, z, ...RIVER[i], ...RIVER[i + 1])); return d; }
73
+ const landMask = (x, z) => sstep(-900, 400, x - PATCH.x0) * sstep(PATCH.x1, PATCH.x1 - 2500, x) * sstep(PATCH.z1, PATCH.z1 - 2500, Math.abs(z) + 400 * fbm(x * .0003, z * .0003, 2));
74
+ function rawH(x, z) {
75
+ // regional landscape (dry high plateau, distant ranges)
76
+ let h = 260 * fbm(x * .00012, z * .00012, 6, 1) + 900 * Math.max(0, ridged(x * .00007, z * .00007, 4) - .45) + 30 * fbm(x * .0016, z * .0016, 3, 2);
77
+ // rocky massif burying the stinger's broken base
78
+ const rb = Math.hypot(x * .85, z); h += 950 * Math.exp(-Math.pow(rb / 3000, 1.6)) * (.6 + .4 * ridged(x * .0011, z * .0011)) + 180 * ridged(x * .004, z * .004, 3) * Math.exp(-Math.pow(rb / 3200, 2));
79
+ // soil & rock piled against the lower east flank: a broad ramp from the stinger down to the east, terraced
80
+ const ex = x - 1200, ramp = Math.max(0, 1 - ex / 4200) * sstep(3400, 1200, Math.abs(z)) * sstep(-400, 300, ex); let mound = 1150 * Math.pow(ramp, 1.25) * (.88 + .12 * fbm(x * .0012, z * .0012, 3, 6));
81
+ const stp = 55, qn = Math.floor(mound / stp) * stp, fr = (mound - qn) / stp; mound = THREE.MathUtils.lerp(mound, qn + stp * sstep(.55, 1, fr), .7 * sstep(80, 260, mound)); h += mound;
82
+ // the snow mountain (temple) + side peaks
83
+ const wx = x + 300 * fbm(x * .0005, z * .0005, 3, 1), wz = z + 300 * fbm(x * .0005 + 5, z * .0005, 3, 2), d = Math.hypot(wx - MC.x, wz - MC.y), d2 = Math.hypot(wx - MC.x - 1300, wz - MC.y + 400), d3 = Math.hypot(wx - MC.x + 200, wz - MC.y - 1300);
84
+ h += 2050 * Math.exp(-Math.pow(d / 1050, 1.45)) * (.45 + .55 * ridged(wx * .0011, wz * .0011)) + 1100 * Math.exp(-Math.pow(d2 / 700, 1.6)) * (.5 + .5 * ridged(wx * .0015 + 3, wz * .0015)) + 700 * Math.exp(-Math.pow(d3 / 650, 1.6)) * (.5 + .5 * ridged(wx * .0016, wz * .0016 + 7)) + 70 * ridged(wx * .008, wz * .008, 3) * sstep(2200, 400, d);
85
+ // lake & river
86
+ const lm = landMask(x, z); h -= 70 * sstep(LAKE.r * 1.3, LAKE.r * .55, Math.hypot(x - LAKE.x, z - LAKE.z)); h -= 14 * sstep(45, 8, riverD(x, z)) * lm;
87
+ return h; }
88
+ export function landH(x, z) { let h = rawH(x, z); for (const p of PADS) { const d = Math.hypot(x - p.x, z - p.z); if (d < p.r * 2) h = THREE.MathUtils.lerp(h, p.y, sstep(p.r * 2, p.r, d)); } return h; }
89
+ function terrainMesh(cx, cz, size, S, drop, q) {
90
+ const g = new THREE.PlaneGeometry(size, size, S, S); g.rotateX(-Math.PI / 2); g.translate(cx, 0, cz); const p = g.attributes.position, col = new Float32Array(p.count * 3), c = new THREE.Color();
91
+ for (let i = 0; i < p.count; i++) { const x = p.getX(i), z = p.getZ(i); let y = landH(x, z); const lm = landMask(x, z);
92
+ if (drop) { const inNear = x > PATCH.x0 - 2400 && x < PATCH.x1 + 600 && Math.abs(z) < PATCH.z1 + 600 && Math.hypot(x, z) > 0; if (inNear) y -= 25; }
93
+ p.setY(i, y); const m = .5 + .5 * fbm(x * .0011, z * .0011, 3, 8);
94
+ c.setRGB(.36 + .06 * m, .34 + .05 * m, .25); // dry grassland (regional)
95
+ c.lerp(new THREE.Color(.27 + .08 * m, .33 + .07 * m, .17), lm * (.75 + .25 * m)); // green, wooded land on the east flank
96
+ const rb = Math.hypot(x * .85, z); c.lerp(new THREE.Color(.42, .39, .35), sstep(2600, 1200, rb) * .9); // rocky massif around the base
97
+ col.set([c.r, c.g, c.b], i * 3); }
98
+ g.setAttribute('color', new THREE.BufferAttribute(col, 3)); g.computeVertexNormals(); const m = new THREE.Mesh(g, M.terrain); m.receiveShadow = true; return m; }
99
+
100
+ /* ---------- the stinger spire ---------- */
101
+ const spR = (t) => SPIRE.R0 * Math.pow(Math.max(0, 1 - t / SPIRE.L), .92);
102
+ export function spireAxis(t) { const a = SPIRE.tilt; return new THREE.Vector3(-Math.sin(a) * t, Math.cos(a) * t, 0); }
103
+ function buildSpire(q) { const grp = new THREE.Group(); const L = q === 'high' ? 420 : 220, A = q === 'high' ? 200 : 110, pos = [], col = [], idx = [];
104
+ const chit = new THREE.Color(.16, .14, .12), amber = new THREE.Color(.55, .39, .14), c = new THREE.Color(), SEG = 420;
105
+ for (let i = 0; i <= L; i++) { const t = -SPIRE.bury + (SPIRE.L + SPIRE.bury) * Math.pow(i / L, 1.05); const ph = ((t + 5000) / SEG) % 1, seg = Math.floor((t + 5000) / SEG);
106
+ const plate = 1 + .055 * Math.pow(ph, 1.6) - .03; // overlapping ring plates: each segment flares at its lower edge
107
+ const band = Math.pow(Math.max(0, Math.sin(ph * Math.PI)), .5) * sstep(.82, .97, ph) + sstep(.0, .05, ph) * (1 - sstep(.05, .12, ph));
108
+ for (let j = 0; j <= A; j++) { const a = j / A * Math.PI * 2; const r = spR(t) * plate * (1 + .012 * fbm(t * .0015, a * 6, 4, seg % 7) + .006 * nz(t * .01, a * 30)) * (1 - .015 * Math.pow(Math.abs(Math.sin(a * 9)), 8));
109
+ pos.push(Math.cos(a) * r, t, Math.sin(a) * r);
110
+ const g = .85 + .3 * fbm(t * .003, a * 9, 3, 2); c.copy(chit).multiplyScalar(g).lerp(amber, Math.min(1, band * (.6 + .5 * fbm(t * .002 + 4, a * 7, 3)))); col.push(c.r, c.g, c.b); } }
111
+ for (let i = 0; i < L; i++) for (let j = 0; j < A; j++) { const a = i * (A + 1) + j, b = a + A + 1; idx.push(a, a + 1, b, b, a + 1, b + 1); }
112
+ const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3)); g.setIndex(idx); g.computeVertexNormals();
113
+ const shell = new THREE.Mesh(g, M.spire); shell.castShadow = shell.receiveShadow = true; grp.add(shell);
114
+ // barbs: two rows of backward-pointing teeth (like a real stinger lancet)
115
+ const nb = q === 'high' ? 70 : 40, cone = new THREE.ConeGeometry(1, 1, 7); cone.translate(0, .5, 0); const bi = new THREE.InstancedMesh(cone, M.barb, nb * 2), o = new THREE.Object3D(); let k = 0;
116
+ for (const side of [Math.PI * .5, Math.PI * 1.5]) for (let i = 0; i < nb; i++) { const t = 900 + i * (SPIRE.L * .8 / nb), r = spR(t), s = r * .2 + 20; o.position.set(Math.cos(side) * r * .97, t, Math.sin(side) * r * .97); o.lookAt(Math.cos(side) * r * 3, t - r * 2.2, Math.sin(side) * r * 3); o.rotateX(Math.PI / 2); o.scale.set(s * .35, s, s * .35); o.updateMatrix(); bi.setMatrixAt(k++, o.matrix); }
117
+ bi.castShadow = true; grp.add(bi); grp.rotation.z = SPIRE.tilt; return grp; }
118
+ function buildTalus(q) { const n = q === 'high' ? 900 : 350; const geo = new THREE.IcosahedronGeometry(1, 1); const p = geo.attributes.position; for (let i = 0; i < p.count; i++) { const v = new THREE.Vector3().fromBufferAttribute(p, i); v.multiplyScalar(1 + .3 * nz(v.x * 2.1, v.y * 2.1, v.z * 2.1)); v.y *= .7; p.setXYZ(i, v.x, v.y, v.z); } geo.computeVertexNormals();
119
+ const im = new THREE.InstancedMesh(geo, M.stone, n), o = new THREE.Object3D(); for (let i = 0; i < n; i++) { const a = rnd() * 6.28, r = SPIRE.R0 * (.95 + Math.pow(rnd(), 2) * 1.2), x = Math.cos(a) * r, z = Math.sin(a) * r; const s = 15 + Math.pow(rnd(), 3) * 140; o.position.set(x, landH(x, z) - s * .25, z); o.rotation.set(rnd() * 6, rnd() * 6, rnd() * 6); o.scale.set(s, s * (.6 + rnd() * .6), s * (.8 + rnd() * .4)); o.updateMatrix(); im.setMatrixAt(i, o.matrix); }
120
+ im.castShadow = im.receiveShadow = true; return im; }
121
+
122
+ /* ---------- sky & clouds (real clouds: morning valley fog + high altocumulus) ---------- */
123
+ function cloudDeck(y, alpha, scale) { return new THREE.Mesh(new THREE.PlaneGeometry(6e5, 6e5, 1, 1), new THREE.ShaderMaterial({ transparent: true, depthWrite: false, fog: false, side: THREE.DoubleSide, uniforms: { t: { value: 0 }, A: { value: alpha }, S: { value: scale } },
124
+ vertexShader: 'varying vec3 vW; void main(){ vec4 w=modelMatrix*vec4(position,1.0); vW=w.xyz; gl_Position=projectionMatrix*viewMatrix*w; }',
125
+ fragmentShader: `uniform float t; uniform float A; uniform float S; varying vec3 vW;
126
+ float hash(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);} float n2(vec2 p){vec2 i=floor(p),f=fract(p);f=f*f*(3.0-2.0*f);return mix(mix(hash(i),hash(i+vec2(1,0)),f.x),mix(hash(i+vec2(0,1)),hash(i+vec2(1,1)),f.x),f.y);}
127
+ float fb(vec2 p){float a=0.0,w=0.5;for(int i=0;i<6;i++){a+=w*n2(p);p=p*2.02+vec2(1.7,9.2);w*=0.5;}return a;}
128
+ void main(){ vec2 p=vW.xz*S+vec2(t*0.0006,t*0.0002); float d=fb(p+0.5*fb(p*2.1)); float cov=smoothstep(0.5,0.78,d);
129
+ float toward=pow(max(0.0,normalize(vW.xz-cameraPosition.xz).x),2.0); vec3 c=mix(vec3(0.62,0.6,0.64),vec3(1.0,0.78,0.55),0.4+0.6*toward*d);
130
+ float dist=length(vW.xz-cameraPosition.xz); gl_FragColor=vec4(c, cov*A*(1.0-smoothstep(60000.0,250000.0,dist))); }` })); }
131
+ function buildClouds(q) { const g = new THREE.Group(); const hi = cloudDeck(0, .55, .00006); hi.rotation.x = -Math.PI / 2; hi.position.y = 14500; g.add(hi);
132
+ const mats = [0, 1].map(k => new THREE.SpriteMaterial({ map: cloudTex, color: new THREE.Color().setHSL(.07, .3, .86 - k * .06), transparent: true, opacity: .75, depthWrite: false }));
133
+ const n = q === 'high' ? 260 : 110; for (let i = 0; i < n; i++) { const a = rnd() * 6.28, r = 6000 + Math.pow(rnd(), .7) * 70000, x = Math.cos(a) * r, z = Math.sin(a) * r; const s = 900 + rnd() * 3500; const sp = new THREE.Sprite(mats[i % 2]); sp.scale.set(s * 2.4, s * .5, 1); sp.position.set(x, landH(x, z) + 60 + rnd() * 220, z); g.add(sp); } // morning valley fog banks
134
+ const mist = new THREE.SpriteMaterial({ map: cloudTex, color: 0xf3e9dc, transparent: true, opacity: .5, depthWrite: false });
135
+ for (let i = 0; i < (q === 'high' ? 60 : 25); i++) { const x = PATCH.x0 + 1500 + rnd() * 7000, z = -4000 + rnd() * 8000; const s = 220 + rnd() * 500; const sp = new THREE.Sprite(mist); sp.scale.set(s * 2.4, s * .5, 1); sp.position.set(x, landH(x, z) + 30 + rnd() * 90, z); g.add(sp); }
136
+ g.userData = { hi }; return g; }
137
+
138
+ /* ---------- forest, river/lake water, village ---------- */
139
+ function buildForest(q) { const n = q === 'high' ? 40000 : 14000; const cone = new THREE.ConeGeometry(1, 1, 7, 3); cone.translate(0, .5, 0);
140
+ const cc = new Float32Array(cone.attributes.position.count * 3); for (let i = 0; i < cc.length / 3; i++) { const y = cone.attributes.position.getY(i); cc.set([.75 + y * .4, .85 + y * .3, .7], i * 3); } cone.setAttribute('color', new THREE.BufferAttribute(cc, 3));
141
+ const im = new THREE.InstancedMesh(cone, M.pine, n), o = new THREE.Object3D(), c = new THREE.Color(); let k = 0;
142
+ for (let i = 0; i < n * 4 && k < n; i++) { const x = PATCH.x0 + 400 + rnd() * (PATCH.x1 - PATCH.x0 - 1200), z = (rnd() * 2 - 1) * (PATCH.z1 - 900); if (landMask(x, z) < .6) continue; const dens = fbm(x * .0016, z * .0016, 3, 12); if (dens < -.05) continue;
143
+ const y = landH(x, z); if (y > 1750 + 150 * dens) continue; if (Math.hypot(x - LAKE.x, z - LAKE.z) < LAKE.r * 1.15 || riverD(x, z) < 22 || Math.hypot(x - VILLAGE.x, z - VILLAGE.z) < VILLAGE.r || Math.hypot(x - VILLAGE2.x, z - VILLAGE2.z) < VILLAGE2.r) continue;
144
+ const y2 = landH(x + 4, z), y3 = landH(x, z + 4); if (Math.hypot(y2 - y, y3 - y) > 3.2) continue; if (PADS.some(p => Math.hypot(p.x - x, p.z - z) < p.r * 1.3)) continue;
145
+ const h = 14 + rnd() * 22; o.position.set(x, y - .5, z); o.scale.set(h * .22, h, h * .22); o.rotation.y = rnd() * 6; o.updateMatrix(); im.setMatrixAt(k, o.matrix); c.setRGB(.13 + rnd() * .05, .2 + rnd() * .07, .1 + rnd() * .03); im.setColorAt(k++, c); }
146
+ im.count = k; im.castShadow = q === 'high'; im.receiveShadow = true; return im; }
147
+ function buildWater() { const g = new THREE.Group(); LAKE_Y = Math.min(...[0, 1, 2, 3, 4, 5].map(a => landH(LAKE.x + Math.cos(a) * LAKE.r * 1.15, LAKE.z + Math.sin(a) * LAKE.r * 1.15))) - 3;
148
+ const lake = new THREE.Mesh(new THREE.CircleGeometry(LAKE.r * 1.35, 64), M.water); lake.rotation.x = -Math.PI / 2; lake.position.set(LAKE.x, LAKE_Y, LAKE.z); lake.receiveShadow = true; g.add(lake);
149
+ const pts = RIVER.map(([x, z]) => new THREE.Vector3(x, 0, z)); const curve = new THREE.CatmullRomCurve3(pts); const N = 160, pos = [], idx = [];
150
+ for (let i = 0; i <= N; i++) { const t = i / N, p = curve.getPoint(t), tg = curve.getTangent(t), nx = -tg.z, nzz = tg.x, w = 9 + 7 * t; for (const s of [-1, 1]) { const x = p.x + nx * w * s, z = p.z + nzz * w * s; pos.push(x, landH(p.x, p.z) + 1.4, z); } if (i < N) idx.push(i * 2, i * 2 + 1, i * 2 + 2, i * 2 + 1, i * 2 + 3, i * 2 + 2); }
151
+ const rg = new THREE.BufferGeometry(); rg.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); rg.setIndex(idx); rg.computeVertexNormals(); g.add(new THREE.Mesh(rg, M.water)); return g; }
152
+ function buildVillage(q, VILLAGE) { const n = q === 'high' ? 140 : 70; const box = new THREE.BoxGeometry(1, 1, 1); box.translate(0, .5, 0); const roof = new THREE.CylinderGeometry(.0, .75, .5, 4, 1); roof.rotateY(Math.PI / 4); roof.scale(1, 1, .72); roof.translate(0, 1.25, 0);
153
+ const walls = new THREE.InstancedMesh(box, M.wall, n), roofs = new THREE.InstancedMesh(roof, M.roof, n), o = new THREE.Object3D(); let k = 0;
154
+ for (let i = 0; i < n * 3 && k < n; i++) { const a = rnd() * 6.28, r = Math.sqrt(rnd()) * VILLAGE.r, x = VILLAGE.x + Math.cos(a) * r, z = VILLAGE.z + Math.sin(a) * r * .7; const y = landH(x, z);
155
+ const w = 7 + rnd() * 6, d = 9 + rnd() * 8, h = 5 + rnd() * 4; o.position.set(x, y - .4, z); o.rotation.y = Math.round(a * 2) / 2 + (rnd() - .5) * .2; o.scale.set(w, h, d); o.updateMatrix(); walls.setMatrixAt(k, o.matrix); o.scale.set(w * 1.45, h * 1.4, d * 1.45); o.position.y = y - .4 - h * .4; o.updateMatrix(); roofs.setMatrixAt(k++, o.matrix); }
156
+ walls.count = roofs.count = k; [walls, roofs].forEach(m => { m.castShadow = true; m.receiveShadow = true; }); const g = new THREE.Group(); g.add(walls, roofs);
157
+ const tower = new THREE.Mesh(new THREE.CylinderGeometry(4, 5, 26, 8), M.stone); tower.position.set(VILLAGE.x, landH(VILLAGE.x, VILLAGE.z) + 12, VILLAGE.z); tower.castShadow = true; g.add(tower); return g; }
158
+
159
+ /* ---------- bee (player) — realistic honey bee ---------- */
160
+ const stripe = canvasTex(512, 128, (x, w, h) => { x.fillStyle = '#1a140e'; x.fillRect(0, 0, w, h); for (let i = 0; i < 4; i++) { const g = x.createLinearGradient(30 + i * 118, 0, 90 + i * 118, 0); g.addColorStop(0, '#9a6a1c'); g.addColorStop(.5, '#d6a443'); g.addColorStop(1, '#9a6a1c'); x.fillStyle = g; x.fillRect(30 + i * 118, 0, 62, h); }
161
+ for (let i = 0; i < 4000; i++) { x.fillStyle = `rgba(${200 + Math.random() * 55},${170 + Math.random() * 50},${110 + Math.random() * 40},${Math.random() * .25})`; x.fillRect(Math.random() * w, Math.random() * h, 1, 3); } });
162
+ export function makeBee() { const g = new THREE.Group();
163
+ const body = new THREE.MeshPhysicalMaterial({ map: stripe, roughness: .62, sheen: 1, sheenColor: new THREE.Color(0xe8c27a), sheenRoughness: .5 });
164
+ const fur = new THREE.MeshPhysicalMaterial({ color: 0x8c6a3a, roughness: .8, sheen: 1, sheenColor: new THREE.Color(0xf0d49a), sheenRoughness: .4 });
165
+ const dark = new THREE.MeshStandardMaterial({ color: 0x1a140f, roughness: .55 }), eye = new THREE.MeshPhysicalMaterial({ color: 0x0c0906, roughness: .15, clearcoat: 1 });
166
+ const abd = new THREE.Mesh(new THREE.SphereGeometry(.5, 40, 24), body); abd.scale.set(1.45, .92, .92); abd.rotation.z = Math.PI / 2; abd.position.set(-.62, -.06, 0);
167
+ const th = new THREE.Mesh(new THREE.SphereGeometry(.37, 32, 20), fur); th.position.set(.1, .02, 0);
168
+ const hd = new THREE.Mesh(new THREE.SphereGeometry(.27, 32, 20), dark); hd.scale.set(.85, 1, 1.05); hd.position.set(.52, 0, 0);
169
+ [-1, 1].forEach(s => { const e = new THREE.Mesh(new THREE.SphereGeometry(.13, 24, 16), eye); e.scale.set(.75, 1.25, .65); e.position.set(.57, .06, .16 * s); g.add(e);
170
+ const an = new THREE.Mesh(new THREE.CylinderGeometry(.011, .011, .42, 6), dark); an.position.set(.74, .27, .08 * s); an.rotation.set(.3 * s, 0, -.75); g.add(an);
171
+ for (let k = 0; k < 3; k++) { const l = new THREE.Mesh(new THREE.CylinderGeometry(.018, .01, .55, 6), dark); l.position.set(.2 - k * .2, -.3, .2 * s); l.rotation.set(.7 * s, 0, .2 - k * .2); g.add(l); } });
172
+ const wmat = new THREE.MeshPhysicalMaterial({ color: 0xf4efe4, transparent: true, opacity: .22, roughness: .1, iridescence: .6, side: THREE.DoubleSide, depthWrite: false });
173
+ const wg = new THREE.CircleGeometry(.5, 24); wg.scale(1.5, .52, 1); wg.translate(-.55, 0, 0); const wings = [];
174
+ [-1, 1].forEach(s => { const piv = new THREE.Group(); piv.position.set(.05, .32, .12 * s); const w = new THREE.Mesh(wg, wmat); w.rotation.x = -Math.PI / 2 * s; w.rotation.y = .15 * s; piv.add(w); g.add(piv); wings.push({ piv, s }); });
175
+ g.add(abd, th, hd); g.traverse(o => { if (o.isMesh && o.material !== wmat) o.castShadow = true; }); g.userData.wings = wings; return g; }
176
+
177
+ /* ---------- temple on the summit (stone + bronze), core = warm light inside ---------- */
178
+ function buildTemple(top) { const g = new THREE.Group(); g.position.copy(top); const add = (geo, mat, x, y, z, ry = 0) => { const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.rotation.y = ry; m.castShadow = m.receiveShadow = true; g.add(m); return m; };
179
+ [[70, 8], [58, 8], [48, 8]].reduce((y, [r, h]) => { add(new THREE.CylinderGeometry(r * .97, r, h, 6), M.stone, 0, y + h / 2, 0, Math.PI / 6); return y + h; }, 0);
180
+ const y0 = 24; add(new THREE.CylinderGeometry(30, 32, 34, 6), M.stone, 0, y0 + 17, 0, Math.PI / 6);
181
+ for (let i = 0; i < 18; i++) { const a = i / 18 * 6.28; add(new THREE.CylinderGeometry(1.6, 1.9, 30, 12), M.stone, Math.cos(a) * 40, y0 + 15, Math.sin(a) * 40); }
182
+ add(new THREE.CylinderGeometry(44, 44, 3, 6), M.darkStone, 0, y0 + 31.5, 0, Math.PI / 6);
183
+ add(new THREE.CylinderGeometry(4, 36, 30, 6), M.patina, 0, y0 + 48, 0, Math.PI / 6); add(new THREE.CylinderGeometry(9, 12, 22, 6), M.stone, 0, y0 + 66, 0, Math.PI / 6); add(new THREE.ConeGeometry(10, 26, 6), M.patina, 0, y0 + 90, 0, Math.PI / 6);
184
+ // east door (dark opening) with warm interior light = the CORE
185
+ add(new THREE.BoxGeometry(2, 22, 16), new THREE.MeshStandardMaterial({ color: 0x120c06, emissive: 0x6a3a10, emissiveIntensity: .35, roughness: 1 }), 31.2, y0 + 11, 0);
186
+ add(new THREE.BoxGeometry(3, 3, 22), M.bronze, 32, y0 + 23.5, 0);
187
+ for (let i = 0; i < 14; i++) add(new THREE.BoxGeometry(5, 1.6, 26), M.stone, 74 + i * 5, 20 - i * 3, 0); // stairs down the east face
188
+ const core = new THREE.Group(); core.position.set(10, y0 + 12, 0); const cl = new THREE.PointLight(0xffa94d, 3000, 120, 2); core.add(cl); g.add(core);
189
+ g.userData = { core, cl }; return g; }
190
+
191
+ /* ---------- shrines on the terraces (stone + bronze), one per studio ---------- */
192
+ const THEME = { radio: 'mast', music: 'bells', master: 'bells', audio: 'bells', stems: 'bells', avatar: 'mirror', shop: 'stall', social: 'banners', community: 'banners', videogen: 'wall', videoedit: 'wall', agent: 'hive', auto: 'hive', image: 'easel', canvas: 'easel', design: 'easel' };
193
+ function monument(kind) { const g = new THREE.Group(); const add = (geo, mat, x, y, z, r = [0, 0, 0], s = [1, 1, 1]) => { const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.rotation.set(...r); m.scale.set(...s); m.castShadow = m.receiveShadow = true; g.add(m); return m; };
194
+ if (kind === 'mast') { add(new THREE.CylinderGeometry(.4, .9, 34, 8), M.bronze, 0, 17, 0); for (let i = 0; i < 4; i++) add(new THREE.CylinderGeometry(.08, .08, 36, 4), M.bronze, Math.cos(i * 1.57) * 6, 16, Math.sin(i * 1.57) * 6, [Math.sin(i * 1.57) * .17, 0, -Math.cos(i * 1.57) * .17]); add(new THREE.BoxGeometry(4, 1, 1), M.bronze, 0, 30, 0); }
195
+ else if (kind === 'bells') { add(new THREE.BoxGeometry(14, 1.6, 3), M.wood, 0, 10, 0); [-1, 1].forEach(x => add(new THREE.BoxGeometry(1.4, 11, 1.4), M.stone, x * 6.5, 5, 0)); [-4, 0, 4].forEach((x, i) => add(new THREE.CylinderGeometry(.6, 1.6 + i * .3, 2.4 + i * .4, 16, 1, true), M.bronze, x, 8, 0)); }
196
+ else if (kind === 'mirror') { add(new THREE.CylinderGeometry(4, 4, .5, 48), new THREE.MeshStandardMaterial({ color: 0xb8a88a, metalness: 1, roughness: .12 }), 0, 9, 0, [Math.PI / 2, 0, 0], [1, 1, 1.3]); add(new THREE.TorusGeometry(4.1, .35, 8, 48), M.bronze, 0, 9, 0, [0, 0, 0], [1, 1.3, 1]); add(new THREE.BoxGeometry(2, 4, 2), M.stone, 0, 2, 0); }
197
+ else if (kind === 'stall') { add(new THREE.BoxGeometry(10, 3, 4), M.wood, 0, 1.5, 0); [-4.6, 4.6].forEach(x => add(new THREE.BoxGeometry(.4, 7, .4), M.wood, x, 3.5, 2)); add(new THREE.PlaneGeometry(10.5, 5, 1, 1), M.cloth, 0, 7, 0.8, [-1.1, 0, 0]); for (let i = 0; i < 6; i++) add(new THREE.BoxGeometry(1, .8, 1), i % 2 ? M.cloth : M.wood, -3.5 + i * 1.4, 3.4, 0); }
198
+ else if (kind === 'banners') { [-4, 0, 4].forEach(x => { add(new THREE.CylinderGeometry(.2, .2, 14, 8), M.wood, x, 7, 0); add(new THREE.PlaneGeometry(2.4, 7, 1, 1), M.cloth, x + 1.3, 9.5, 0); }); }
199
+ else if (kind === 'wall') { add(new THREE.BoxGeometry(16, 9, 1.6), M.stone, 0, 4.5, 0); add(new THREE.PlaneGeometry(14, 7), new THREE.MeshStandardMaterial({ color: 0xe6dccb, roughness: .9 }), 0, 4.8, .82); }
200
+ else if (kind === 'hive') { add(new THREE.SphereGeometry(4, 24, 16), new THREE.MeshStandardMaterial({ color: 0x9a7a4a, roughness: .95 }), 0, 5, 0, [0, 0, 0], [1, 1.25, 1]); add(new THREE.CylinderGeometry(2, 3.5, 2, 12), M.stone, 0, 1, 0); }
201
+ else if (kind === 'easel') { add(new THREE.BoxGeometry(6, 8, .5), M.wood, 0, 6, 0, [-.15, 0, 0]); [-2.5, 2.5].forEach(x => add(new THREE.BoxGeometry(.3, 11, .3), M.wood, x, 5, -.6, [-.15, 0, 0])); }
202
+ else { add(new THREE.BoxGeometry(3, 16, 3), M.stone, 0, 8, 0); add(new THREE.ConeGeometry(2.2, 3, 4), M.bronze, 0, 17.5, 0, [0, Math.PI / 4, 0]); }
203
+ return g; }
204
+ export function shrineSpots(n) { // switchback along the east slope terraces, from the valley up toward the temple
205
+ const out = []; for (let i = 0; i < n; i++) { const k = i / Math.max(1, n - 1), d = 1500 - k * 1150, a = Math.PI * (-.42 + .84 * ((i % 4) / 3)) * (1 - k * .2) + (i % 2 ? .08 : -.08); out.push({ x: MC.x + Math.cos(a) * d, z: MC.y + Math.sin(a) * d * .9, a }); } return out; }
206
+ function buildShrine(s, spot) { const g = new THREE.Group(); g.position.set(spot.x, spot.y, spot.z); g.rotation.y = -Math.atan2(spot.z - MC.y, spot.x - MC.x) + Math.PI / 2;
207
+ const add = (geo, mat, x, y, z) => { const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.castShadow = m.receiveShadow = true; g.add(m); return m; };
208
+ add(new THREE.CylinderGeometry(15, 16.5, 2.4, 6), M.stone, 0, .4, 0); add(new THREE.BoxGeometry(7, .8, 6), M.stone, 0, -.2, 17);
209
+ // gate (fly through it)
210
+ [-1, 1].forEach(x => add(new THREE.BoxGeometry(1.6, 13, 1.6), M.stone, x * 6, 7.4, 9)); add(new THREE.BoxGeometry(16, 1.6, 2.2), M.stone, 0, 14.4, 9); add(new THREE.BoxGeometry(13, .8, 1.6), M.bronze, 0, 12.6, 9);
211
+ const portal = new THREE.Mesh(new THREE.PlaneGeometry(10.4, 11.5), new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })); portal.position.set(0, 7.2, 9); g.add(portal);
212
+ const mon = monument(THEME[s.id] || 'obelisk'); mon.position.z = -4; g.add(mon);
213
+ // two small bronze braziers (real fire light, subtle)
214
+ const fl = new THREE.PointLight(0xff9a4a, 0, 28, 2); fl.position.set(0, 3, 12); g.add(fl);
215
+ g.userData = { portal, fl }; return { group: g, portal }; }
216
+
217
+ /* ---------- build ---------- */
218
+ export function buildWorld(scene, renderer, studios, colOf, q) {
219
+ makeMaterials(q);
220
+ const sky = new Sky(); sky.scale.setScalar(4e5); const u = sky.material.uniforms; u.turbidity.value = 6; u.rayleigh.value = 2.2; u.mieCoefficient.value = .005; u.mieDirectionalG.value = .86; u.sunPosition.value.copy(SUN_DIR).multiplyScalar(1e5); scene.add(sky);
221
+ if (renderer) { const pm = new THREE.PMREMGenerator(renderer); const es = new THREE.Scene(); const s2 = new Sky(); s2.scale.setScalar(1000); s2.material.uniforms.sunPosition.value.copy(SUN_DIR).multiplyScalar(500); ['turbidity', 'rayleigh', 'mieCoefficient', 'mieDirectionalG'].forEach(k => s2.material.uniforms[k].value = u[k].value); es.add(s2);
222
+ scene.environment = pm.fromScene(es, 0, .1, 2000).texture; scene.environmentIntensity = .55; }
223
+ scene.fog = new THREE.FogExp2(0xd2b89a, .00006);
224
+ const sun = new THREE.DirectionalLight(0xffcf98, 4.4); sun.castShadow = true; sun.shadow.mapSize.setScalar(q === 'high' ? 4096 : 2048); sun.shadow.bias = -.0004; sun.shadow.normalBias = 2; scene.add(sun, sun.target);
225
+ scene.add(new THREE.HemisphereLight(0xa8bcd8, 0x54432e, .85));
226
+ // temple summit + shrine pads
227
+ const top = new THREE.Vector3(MC.x, -1e9, MC.y); for (let i = 0; i < 600; i++) { const x = MC.x + (rnd() - .5) * 900, z = MC.y + (rnd() - .5) * 900, h = rawH(x, z); if (h > top.y) top.set(x, h, z); }
228
+ PADS.push({ x: top.x, z: top.z, r: 80, y: top.y - 35 });
229
+ const spots = shrineSpots(studios.length).map(s => ({ ...s, y: rawH(s.x, s.z) + 1 })); spots.forEach(s => PADS.push({ x: s.x, z: s.z, r: 22, y: s.y }));
230
+ // terrain: near (east-flank land, high detail), mid, far (to the horizon)
231
+ scene.add(terrainMesh(5000, 0, 13000, q === 'high' ? 520 : 300, false, q));
232
+ const mid = terrainMesh(0, 0, 60000, q === 'high' ? 300 : 180, true, q); mid.position.y = -2; scene.add(mid);
233
+ const far = terrainMesh(0, 0, 320000, 160, true, q); far.position.y = -40; far.receiveShadow = false; scene.add(far);
234
+ const spire = buildSpire(q); scene.add(spire); scene.add(buildTalus(q));
235
+ const clouds = buildClouds(q); scene.add(clouds); scene.add(buildForest(q)); scene.add(buildWater()); scene.add(buildVillage(q, VILLAGE)); scene.add(buildVillage(q, VILLAGE2));
236
+ const temple = buildTemple(new THREE.Vector3(top.x, top.y - 35, top.z)); scene.add(temple);
237
+ const shrines = studios.map((s, i) => { const r = buildShrine(s, spots[i]); scene.add(r.group); r.portal.userData.i = i; return r; });
238
+ const W = { sky, sun, spire, clouds, temple, shrines, spots, peak: top.y - 35, core: temple.userData.core, top,
239
+ update(t, dt, camera, focus) { clouds.userData.hi.material.uniforms.t.value = t;
240
+ const alt = Math.max(0, camera.position.y - 600); scene.fog.density = .000065 * Math.exp(-alt / 4000) + .000006; const nr = alt > 2500 ? Math.min(30, alt / 300) : 1; if (Math.abs(camera.near - nr) > .4) { camera.near = nr; camera.updateProjectionMatrix(); }
241
+ temple.userData.cl.intensity = 2600 + Math.sin(t * 1.3) * 250;
242
+ // shadow frustum: wide when high up (the spire's long shadow), tight around the bee near the ground
243
+ const wide = alt > 1200, ext = wide ? 16000 : 450, sc = sun.shadow.camera; if (sc.right !== ext) { sc.left = sc.bottom = -ext; sc.right = sc.top = ext; sc.far = wide ? 60000 : 8000; sc.updateProjectionMatrix(); }
244
+ const f = wide ? new THREE.Vector3(-2500, 2000, 0) : focus; if (f) { sun.position.copy(f).addScaledVector(SUN_DIR, wide ? 25000 : 3000); sun.target.position.copy(f); } } };
245
+ return W;
246
+ }