2Btainment commited on
Commit
83fd0a4
·
verified ·
1 Parent(s): ce235e1

P8 Welt-Umbau: liegender, halb begrabener Fossil-Stachel, 5 Kategorie-Terrassen, Pfad, Bergsee+Wasserfall, Minimap-Umriss, Kategorie-Schnellreise, v132

Browse files
Files changed (12) hide show
  1. app.js +15 -10
  2. avatar.js +1 -1
  3. index.html +2 -2
  4. master.js +1 -1
  5. registry.js +1 -1
  6. studios5.js +3 -3
  7. studios6.js +3 -3
  8. studios7.js +2 -2
  9. style.css +4 -0
  10. video.js +2 -2
  11. workspace.js +2 -2
  12. world.js +122 -98
app.js CHANGED
@@ -1,10 +1,10 @@
1
  import * as THREE from './vendor/three.module.min.js';
2
  import { STUDIOS, stopLoops } from './widgets.js?v=50';
3
- import { icon } from './icons.js?v=131';
4
- import { CATS as CAT5, loadAll, prefetch, getConfig } from './registry.js?v=131';
5
  import { GTAOPass } from './vendor/addons/postprocessing/GTAOPass.js';
6
  import { BokehPass } from './vendor/addons/postprocessing/BokehPass.js';
7
- import { buildWorld, makeBee, landH, MC } from './world.js?v=131';
8
  import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
9
  import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
10
  import { UnrealBloomPass } from './vendor/addons/postprocessing/UnrealBloomPass.js';
@@ -62,14 +62,14 @@ if (renderer) { try { composer = new EffectComposer(renderer); composer.addPass(
62
  /* ---------- the player bee ---------- */
63
  const bee = makeBee(); bee.scale.setScalar(1.3); scene.add(bee);
64
  const B = { pos: new THREE.Vector3(), vel: new THREE.Vector3(), yaw: Math.PI, bank: 0, travel: null, near: -1, armed: true };
65
- 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; }
66
  spawn();
67
  window.__studiusLegacyDust = null;
68
  /* ---------- HUD, labels ---------- */
69
  let cat = 'Alle', sel = 0, openId = null;
70
  const cats = $('#cats');
71
  CATS.forEach(c => { const b = document.createElement('button'); b.textContent = c.toUpperCase(); b.dataset.c = c; b.onclick = () => setCat(c); cats.append(b); });
72
- function setCat(c) { cat = c; [...cats.children].forEach(b => b.classList.toggle('on', b.dataset.c === c)); beep(520); const v = visible(); if (!v.includes(sel)) select(v[0]); }
73
  function visible() { return nodes.map((n, i) => i).filter(i => cat === 'Alle' || nodes[i].userData.s.cat === cat || nodes[i].userData.s.id === 'merge'); }
74
  const labels = STUDIOS.map((s, i) => { const d = document.createElement('div'); d.className = 'lbl'; d.innerHTML = `${icon(s.id)}<span>${s.name}</span>`; d.dataset.cat = s.cat; d.title = s.cat + ' · ' + s.like; d.tabIndex = 0; d.setAttribute('role', 'button'); d.setAttribute('aria-label', s.name + ' öffnen – ' + s.like);
75
  d.onkeydown = (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); select(i); open(i); } }; d.onfocus = () => select(i);
@@ -171,10 +171,10 @@ const intro = $('#intro'); let introT = 0;
171
  const stage = (n, ms) => setTimeout(() => !started && intro.classList.add('s' + n), ms);
172
  stage(1, 120); stage(2, 12200); stage(3, 12900); stage(4, 13600); stage(5, 14600);
173
  const peakY = W.peak;
174
- const SHOTS = [ // wide on the leaning spire at sunrise → continuous descent onto the east-flank land → ground level
175
- [0, [9000, 3200, 26000], [-2600, 5200, 0]], [4, [12000, 2600, 17000], [-1200, 3200, 0]], [7.5, [9800, 1900, 9000], [3200, 700, 300]],
176
- [10.5, [7400, 900, 5200], [4600, 300, 1500]], [13, [5900, 380, 3300], [4700, 120, 1500]], [15.5, null, null]];
177
- 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']];
178
  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>');
179
  const cine = $('#cine'), capEl = cine.querySelector('.cap'); let capI = -1;
180
  const ease = (x) => x < .5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
@@ -196,7 +196,11 @@ intro.addEventListener('pointerdown', (e) => { if (e.target.id !== 'skip') start
196
  /* ---------- loop ---------- */
197
  const clock = new THREE.Clock(); let frames = 0, fpsT = 0, statT = 0, mmT = 0;
198
  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; });
199
- const MMS = .0075, mmX = (x) => 50 + (x - 3500) * MMS, mmY = (z) => 50 + z * MMS;
 
 
 
 
200
  let mmBee = null;
201
  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'); });
202
  if (!mmBee) { mmBee = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); mmBee.setAttribute('r', 3.4); mmBee.setAttribute('class', 'bee'); mm.append(mmBee); }
@@ -273,6 +277,7 @@ function frame(now) {
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); }
 
1
  import * as THREE from './vendor/three.module.min.js';
2
  import { STUDIOS, stopLoops } from './widgets.js?v=50';
3
+ import { icon } from './icons.js?v=132';
4
+ import { CATS as CAT5, loadAll, prefetch, getConfig } from './registry.js?v=132';
5
  import { GTAOPass } from './vendor/addons/postprocessing/GTAOPass.js';
6
  import { BokehPass } from './vendor/addons/postprocessing/BokehPass.js';
7
+ import { buildWorld, makeBee, landH, MC } from './world.js?v=132';
8
  import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
9
  import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
10
  import { UnrealBloomPass } from './vendor/addons/postprocessing/UnrealBloomPass.js';
 
62
  /* ---------- the player bee ---------- */
63
  const bee = makeBee(); bee.scale.setScalar(1.3); scene.add(bee);
64
  const B = { pos: new THREE.Vector3(), vel: new THREE.Vector3(), yaw: Math.PI, bank: 0, travel: null, near: -1, armed: true };
65
+ function spawn() { const t = W.terraces[0].pos, x = t.x + 170, z = t.z; B.pos.set(x, landH(x, z) + 14, z); B.vel.set(0, 0, 0); B.yaw = Math.PI; }
66
  spawn();
67
  window.__studiusLegacyDust = null;
68
  /* ---------- HUD, labels ---------- */
69
  let cat = 'Alle', sel = 0, openId = null;
70
  const cats = $('#cats');
71
  CATS.forEach(c => { const b = document.createElement('button'); b.textContent = c.toUpperCase(); b.dataset.c = c; b.onclick = () => setCat(c); cats.append(b); });
72
+ function setCat(c) { cat = c; [...cats.children].forEach(b => b.classList.toggle('on', b.dataset.c === c)); beep(520); const v = visible(); if (!v.includes(sel)) select(v[0]); if (c !== 'Alle' && started) focusNode(v.find(i => nodes[i].userData.s.cat === c) ?? v[0]); }
73
  function visible() { return nodes.map((n, i) => i).filter(i => cat === 'Alle' || nodes[i].userData.s.cat === cat || nodes[i].userData.s.id === 'merge'); }
74
  const labels = STUDIOS.map((s, i) => { const d = document.createElement('div'); d.className = 'lbl'; d.innerHTML = `${icon(s.id)}<span>${s.name}</span>`; d.dataset.cat = s.cat; d.title = s.cat + ' · ' + s.like; d.tabIndex = 0; d.setAttribute('role', 'button'); d.setAttribute('aria-label', s.name + ' öffnen – ' + s.like);
75
  d.onkeydown = (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); select(i); open(i); } }; d.onfocus = () => select(i);
 
171
  const stage = (n, ms) => setTimeout(() => !started && intro.classList.add('s' + n), ms);
172
  stage(1, 120); stage(2, 12200); stage(3, 12900); stage(4, 13600); stage(5, 14600);
173
  const peakY = W.peak;
174
+ const SHOTS = [ // sunrise wide on the crashed stinger → along its overgrown back → the terraces → ground level
175
+ [0, [5200, 1900, 7600], [-2800, 300, 300]], [4, [4200, 1500, 5200], [-1500, 400, 400]], [7.5, [2600, 1300, 2600], [-900, 700, 400]],
176
+ [10.5, [900, 1050, 1300], [-1000, 650, 0]], [13, [300, 760, 500], [-700, 600, 0]], [15.5, null, null]];
177
+ const CAPS = [[0, 'Der Ahnen-Stachel · 10 km'], [4, 'Sein überwachsener Rücken'], [7.5, 'Gipfel · Tempel · Bergsee'], [10.5, 'Fünf Terrassen der Studios'], [13, 'Der Pfad']];
178
  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>');
179
  const cine = $('#cine'), capEl = cine.querySelector('.cap'); let capI = -1;
180
  const ease = (x) => x < .5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
 
196
  /* ---------- loop ---------- */
197
  const clock = new THREE.Clock(); let frames = 0, fpsT = 0, statT = 0, mmT = 0;
198
  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; });
199
+ const MMS = .0105, mmX = (x) => 50 + (x + 1100) * MMS, mmY = (z) => 50 + (z - 200) * MMS;
200
+ { const o = W.outline, pts = [...o.map(([x, z, r]) => [x, z - r]), ...o.slice().reverse().map(([x, z, r]) => [x, z + r])]; const sv = (t, a) => { const e = document.createElementNS('http://www.w3.org/2000/svg', t); for (const k in a) e.setAttribute(k, a[k]); return e; };
201
+ mm.querySelector('#mmd').before(sv('polygon', { points: pts.map(([x, z]) => mmX(x).toFixed(1) + ',' + mmY(z).toFixed(1)).join(' '), class: 'st' }));
202
+ W.terraces.forEach(t => mm.querySelector('#mmd').before(sv('circle', { cx: mmX(t.pos.x), cy: mmY(t.pos.z), r: 5, class: 'tr' }))); mm.querySelector('.core').setAttribute('cx', mmX(W.top.x)); mm.querySelector('.core').setAttribute('cy', mmY(W.top.z)); }
203
+ const tlbls = W.terraces.map(t => { const d = document.createElement('div'); d.className = 'tlbl'; d.textContent = t.cat; d.onclick = (e) => { e.stopPropagation(); setCat(t.cat); }; $('#labels').append(d); return d; });
204
  let mmBee = null;
205
  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'); });
206
  if (!mmBee) { mmBee = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); mmBee.setAttribute('r', 3.4); mmBee.setAttribute('class', 'bee'); mm.append(mmBee); }
 
277
  placed.push({ x: p.x, y, w });
278
  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;
279
  l.classList.toggle('dim', !v.includes(i)); });
280
+ W.terraces.forEach((t, k) => { const p = t.pos.clone().project(camera), d = t.pos.distanceTo(camP), l = tlbls[k]; l.style.display = p.z < 1 && d < 6000 ? '' : 'none'; l.classList.toggle('on', cat === t.cat); l.style.transform = `translate(${(p.x + 1) / 2 * innerWidth}px,${(1 - p.y) / 2 * innerHeight}px) translate(-50%,-50%)`; });
281
  if ((mmT += dt) > .1) { mmT = 0; drawMinimap(v); }
282
  if (openId != null && !pop.hidden) { const p = screenPos(nodes[openId]); const r = pop.getBoundingClientRect(); const wl = $('#wl');
283
  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); }
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=131';
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=132';
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=131">
12
  </head>
13
  <body>
14
  <canvas id="gl"></canvas>
@@ -50,6 +50,6 @@
50
 
51
  <a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
52
  <noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
53
- <script type="module" src="app.js?v=131"></script>
54
  </body>
55
  </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=132">
12
  </head>
13
  <body>
14
  <canvas id="gl"></canvas>
 
50
 
51
  <a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
52
  <noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
53
+ <script type="module" src="app.js?v=132"></script>
54
  </body>
55
  </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=131';
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=132';
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;
registry.js CHANGED
@@ -41,7 +41,7 @@ STUDIOS.find = function (f) { return find0.call(this, f) ?? find0.call([...ALL.v
41
  STUDIOS.push = function (...xs) { xs.forEach(x => { const s = ALL.get(x.id); if (s) { const c = s.cat; Object.assign(s, x, { cat: c, stub: false }); } else { x.cat = CAT[x.id] || x.cat; ALL.set(x.id, x); push0.call(this, x); } }); return this.length; };
42
  // lazy module loading (one chain, shared module URLs)
43
  let P = null; export let loaded = false;
44
- export function loadAll() { return P ||= (async () => { for (const m of ['./real.js?v=131', './avatar.js?v=131', './master.js?v=131', './video.js?v=131', './workspace.js?v=131', './studios5.js?v=131', './studios6.js?v=131', './studios7.js?v=131']) await import(m); loaded = true; })(); }
45
  export const prefetch = () => (window.requestIdleCallback || setTimeout)(() => loadAll(), { timeout: 2500 });
46
  if (document.readyState === 'complete') setTimeout(prefetch, 1200); else addEventListener('load', () => setTimeout(prefetch, 1200), { once: true });
47
  /* ---------- command palette (Strg/⌘+K or /) ---------- */
 
41
  STUDIOS.push = function (...xs) { xs.forEach(x => { const s = ALL.get(x.id); if (s) { const c = s.cat; Object.assign(s, x, { cat: c, stub: false }); } else { x.cat = CAT[x.id] || x.cat; ALL.set(x.id, x); push0.call(this, x); } }); return this.length; };
42
  // lazy module loading (one chain, shared module URLs)
43
  let P = null; export let loaded = false;
44
+ export function loadAll() { return P ||= (async () => { for (const m of ['./real.js?v=132', './avatar.js?v=132', './master.js?v=132', './video.js?v=132', './workspace.js?v=132', './studios5.js?v=132', './studios6.js?v=132', './studios7.js?v=132']) await import(m); loaded = true; })(); }
45
  export const prefetch = () => (window.requestIdleCallback || setTimeout)(() => loadAll(), { timeout: 2500 });
46
  if (document.readyState === 'complete') setTimeout(prefetch, 1200); else addEventListener('load', () => setTimeout(prefetch, 1200), { once: true });
47
  /* ---------- command palette (Strg/⌘+K or /) ---------- */
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=131';
5
- import { Avatars } from './avatar.js?v=131';
6
- import { toWav, toMp3 } from './master.js?v=131';
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=132';
5
+ import { Avatars } from './avatar.js?v=132';
6
+ import { toWav, toMp3 } from './master.js?v=132';
7
 
8
  const bucket = () => signedIn() && window.__ws?.bucket;
9
  const wsFile = (p) => '/api/ws/file?bucket=' + encodeURIComponent(window.__ws.bucket) + '&path=' + encodeURIComponent(p);
studios6.js CHANGED
@@ -1,9 +1,9 @@
1
  // STUDIUS P6: Branding-Kit (shared) · Docs (Markdown → DOCX/PDF) · Telefon-Assistent (Avatar + IVR + Testanruf)
2
  // + Module API: brand.get, docs.write, phone.answer, shop.draft. Nothing is posted, published or dialled externally.
3
  import { STUDIOS } from './widgets.js?v=50';
4
- import { MODULES, esc, hf, stTxt, result, badge, setS, keep, CHAT, FLUX } from './real.js?v=131';
5
- import { Avatars } from './avatar.js?v=131';
6
- import { bucket, wsFile, toBlob, slug, ts, upload, wsList, wsJson, saveJson, llm, dl, canvasBlob, loadImg, avOptions, PT, LINES, slugCode, eur, SOC, suggestPrice } from './studios5.js?v=131';
7
 
8
  /* =================== BRANDING-KIT (one source of truth for Social, Whiteboard, Docs, Telefon) =================== */
9
  const BK = 'projects/brand/brand.json';
 
1
  // STUDIUS P6: Branding-Kit (shared) · Docs (Markdown → DOCX/PDF) · Telefon-Assistent (Avatar + IVR + Testanruf)
2
  // + Module API: brand.get, docs.write, phone.answer, shop.draft. Nothing is posted, published or dialled externally.
3
  import { STUDIOS } from './widgets.js?v=50';
4
+ import { MODULES, esc, hf, stTxt, result, badge, setS, keep, CHAT, FLUX } from './real.js?v=132';
5
+ import { Avatars } from './avatar.js?v=132';
6
+ import { bucket, wsFile, toBlob, slug, ts, upload, wsList, wsJson, saveJson, llm, dl, canvasBlob, loadImg, avOptions, PT, LINES, slugCode, eur, SOC, suggestPrice } from './studios5.js?v=132';
7
 
8
  /* =================== BRANDING-KIT (one source of truth for Social, Whiteboard, Docs, Telefon) =================== */
9
  const BK = 'projects/brand/brand.json';
studios7.js CHANGED
@@ -1,7 +1,7 @@
1
  // STUDIUS P7: Dev-Baukasten (Stratum-Port), Repo-Vorschau (RepoSpace-API), Admin, 2B-Vorlagen (Musik), Veloura-Stile (Bild)
2
  import { STUDIOS } from './widgets.js?v=50';
3
- import { MODULES, esc, setS, keep, result, badge } from './real.js?v=131';
4
- import { ALL, CATS, PRESETS, DEFAULT, ME, getConfig, applyTheme, visibleFor } from './registry.js?v=131';
5
  const $ = (el, s) => el.querySelector(s);
6
  const post = async (u, f) => { const fd = new FormData(); Object.entries(f).forEach(([k, v]) => fd.append(k, v)); const r = await fetch(u, { method: 'POST', body: fd, credentials: 'include' }); const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.detail || 'HTTP ' + r.status); return j; };
7
  export const llm = (prompt, system = '', max_tokens = 1200) => post('/api/llm', { prompt, system, max_tokens });
 
1
  // STUDIUS P7: Dev-Baukasten (Stratum-Port), Repo-Vorschau (RepoSpace-API), Admin, 2B-Vorlagen (Musik), Veloura-Stile (Bild)
2
  import { STUDIOS } from './widgets.js?v=50';
3
+ import { MODULES, esc, setS, keep, result, badge } from './real.js?v=132';
4
+ import { ALL, CATS, PRESETS, DEFAULT, ME, getConfig, applyTheme, visibleFor } from './registry.js?v=132';
5
  const $ = (el, s) => el.querySelector(s);
6
  const post = async (u, f) => { const fd = new FormData(); Object.entries(f).forEach(([k, v]) => fd.append(k, v)); const r = await fetch(u, { method: 'POST', body: fd, credentials: 'include' }); const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.detail || 'HTTP ' + r.status); return j; };
7
  export const llm = (prompt, system = '', max_tokens = 1200) => post('/api/llm', { prompt, system, max_tokens });
style.css CHANGED
@@ -299,3 +299,7 @@ body::before{background:radial-gradient(ellipse at 50% 50%,transparent 55%,rgba(
299
  #cmdk ul{list-style:none;margin:8px 0;padding:0}#cmdk li{display:flex;justify-content:space-between;gap:10px;padding:8px 10px;border-radius:8px;cursor:pointer}#cmdk li span{color:var(--muted);font-size:12px}
300
  #cmdk li.on,#cmdk li:hover{background:rgba(242,201,76,.14)}#cmdk li.on b{color:var(--gold)}#cmdk small{color:var(--muted);font-size:11px}
301
  #kbtn{margin-right:6px}
 
 
 
 
 
299
  #cmdk ul{list-style:none;margin:8px 0;padding:0}#cmdk li{display:flex;justify-content:space-between;gap:10px;padding:8px 10px;border-radius:8px;cursor:pointer}#cmdk li span{color:var(--muted);font-size:12px}
300
  #cmdk li.on,#cmdk li:hover{background:rgba(242,201,76,.14)}#cmdk li.on b{color:var(--gold)}#cmdk small{color:var(--muted);font-size:11px}
301
  #kbtn{margin-right:6px}
302
+
303
+ #mm .st{fill:rgba(120,96,58,.55);stroke:rgba(242,201,76,.35);stroke-width:.5}#mm .tr{fill:none;stroke:var(--gold);stroke-width:.6;opacity:.7}
304
+ .tlbl{position:absolute;left:0;top:0;pointer-events:auto;cursor:pointer;font-size:11px;letter-spacing:.22em;text-transform:uppercase;color:#f5e9c8;padding:3px 9px;border-bottom:1px solid var(--gold);background:rgba(10,8,4,.45);border-radius:4px;text-shadow:0 1px 3px #000;z-index:1}
305
+ .tlbl.on{color:var(--gold);background:rgba(36,28,8,.8)}
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=131';
4
- import { toWav } from './master.js?v=131';
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=132';
4
+ import { toWav } from './master.js?v=132';
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=131';
3
- import { Avatars } from './avatar.js?v=131';
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=132';
3
+ import { Avatars } from './avatar.js?v=132';
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 CHANGED
@@ -1,7 +1,7 @@
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';
@@ -11,20 +11,23 @@ const fbm = (x, z, o = 5, s = 0) => { let a = 0, f = 1, w = .5; for (let i = 0;
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: 4900, z: 1600, r: 750 }; 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 = {}; const SNOW = { value: 1300, type: 'float' }, TOPU = { value: new THREE.Vector3(7200, 0, -2100), type: 'vec3' };
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);
@@ -45,7 +48,7 @@ function makeMaterials(q) {
45
  vec3 c = mix(gr, fg * vec3(0.8,0.9,0.7), clamp(forest * 4.0, 0.0, 0.6)) * (0.75 + 0.5 * macro);
46
  c *= mix(vec3(1.0), vColor.rgb * 2.4, 0.55) * vec3(0.8, 0.9, 0.75);
47
  c = mix(c, rk * vec3(0.85,0.82,0.78), smoothstep(0.28, 0.5, slope));
48
- float snow = max(smoothstep(850.0, 300.0, length(vWP.xz - uTop.xz) + 250.0 * sin(vWP.x*0.006) * cos(vWP.z*0.007) + 900.0 * (macro.g - 0.4) + 0.5 * (uTop.y - vWP.y)) , smoothstep(uSnow, uSnow + 220.0, vWP.y) * smoothstep(2200.0, 1200.0, length(vWP.xz - uTop.xz))) * (1.0 - smoothstep(0.75, 0.95, slope));
49
  c = mix(c, vec3(0.86, 0.88, 0.92) * (0.8 + 0.25 * triT(tSn, vWP, vWN, 0.02).r), snow);
50
  diffuseColor.rgb = c;`, { tAer: { value: aerD }, tRock: { value: rockD }, tGr: { value: grD }, tFg: { value: fgD }, tSn: { value: snD }, uSnow: SNOW, uTop: TOPU });
51
  // stinger: weathered stone-chitin, natural amber-ochre banding, lichen; huge-scale + close-scale detail
@@ -55,10 +58,10 @@ function makeMaterials(q) {
55
  diffuseColor.rgb = c;`, { tRock: { value: rockD }, tAer: { value: aerD } });
56
  M.spire = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1, envMapIntensity: .5, normalMap: rockN, normalScale: new THREE.Vector2(1.3, 1.3) }), `
57
  vec3 a = triT(tRock, vWP, vWN, 0.02), b = triT(tRock, vWP, vWN, 0.0016);
58
- vec3 c = vColor.rgb * (a * 0.7 + b * 0.7) * 0.6;
59
- float moss = smoothstep(0.25, 0.7, vWN.y) * smoothstep(-0.2, 0.4, sin(vWP.x*0.004)*cos(vWP.z*0.005) + sin(vWP.y*0.003));
60
- c = min(c, vec3(0.3, 0.24, 0.17));
61
- c = mix(c, vec3(0.2,0.25,0.1) * (0.7 + 0.6*b.g), moss * 0.85);
62
  diffuseColor.rgb = c;`, { tRock: { value: rockD } });
63
  M.barb = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1), normalMap: rockN, color: 0x3a3028, roughness: .9 });
64
  M.stone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.5), normalMap: rockN, color: 0xb3a691, roughness: .92 });
@@ -73,58 +76,63 @@ function makeMaterials(q) {
73
  M.cloth = new THREE.MeshStandardMaterial({ color: 0x8b6b2e, roughness: .9, side: THREE.DoubleSide });
74
  }
75
 
76
- /* ---------- terrain: world to the horizon + the east-flank land ---------- */
77
  const PADS = [];
78
  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); }
79
- 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; }
80
- 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));
 
81
  function rawH(x, z) {
82
- // regional landscape (dry high plateau, distant ranges)
83
- 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);
84
- // rocky massif burying the stinger's broken base
85
- 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));
86
- // soil & rock piled against the lower east flank: a broad ramp from the stinger down to the east, terraced
87
- 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));
88
- 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;
89
- // the snow mountain (temple) + side peaks
90
- 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);
91
- 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)) + 240 * ridged(wx * .004, wz * .004, 4) * sstep(2600, 300, d) + 60 * ridged(wx * .012, wz * .012, 3) * sstep(2600, 300, d);
92
- // lake & river
93
- 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;
94
- return h; }
95
- 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; }
 
 
 
 
96
  function terrainMesh(cx, cz, size, S, drop, q) {
97
  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();
98
- 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);
99
- 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; }
100
- p.setY(i, y - Math.pow(Math.max(0, Math.hypot(x - 4000, z) - 14000), 2) / 12.7e6); const m = .5 + .5 * fbm(x * .0011, z * .0011, 3, 8);
101
- c.setRGB(.3 + .06 * m, .33 + .06 * m, .2); // grassland & scrub (regional)
102
- c.lerp(new THREE.Color(.2 + .05 * m, .32 + .07 * m, .12), lm * (.8 + .2 * m)); // green, wooded land on the east flank
103
- const fd = fbm(x * .0016, z * .0016, 3, 12), fr = fbm(x * .00035, z * .00035, 3, 14); c.lerp(new THREE.Color(.07, .12, .05), Math.min(1, lm * sstep(-.1, .15, fd) * .9 + (1 - lm) * sstep(0, .3, fr) * .75) * sstep(1900, 1500, y)); // forests (dark canopy mass)
104
- 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
105
  col.set([c.r, c.g, c.b], i * 3); }
106
  g.setAttribute('color', new THREE.BufferAttribute(col, 3)); g.computeVertexNormals(); const m = new THREE.Mesh(g, M.terrain); m.receiveShadow = true; return m; }
107
 
108
- /* ---------- the stinger spire ---------- */
109
- const spR = (t) => SPIRE.R0 * Math.pow(Math.max(0, 1 - t / SPIRE.L), .92);
110
- export function spireAxis(t) { const a = SPIRE.tilt; return new THREE.Vector3(-Math.sin(a) * t, Math.cos(a) * t, 0); }
111
- function buildSpire(q) { const grp = new THREE.Group(); const L = q === 'high' ? 420 : 220, A = q === 'high' ? 200 : 110, pos = [], col = [], idx = [];
112
- const chit = new THREE.Color(.1, .085, .07), amber = new THREE.Color(.5, .34, .1), c = new THREE.Color(), SEG = 420;
113
- 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);
114
- const plate = 1 + .11 * Math.pow(ph, 2.2) - .05 - .03 * sstep(.97, 1, ph); // overlapping ring plates: each segment flares at its lower edge
115
- 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));
116
- 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));
117
- pos.push(Math.cos(a) * r, t, Math.sin(a) * r);
118
- 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); } }
119
  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); }
 
120
  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();
121
  const shell = new THREE.Mesh(g, M.spire); shell.castShadow = shell.receiveShadow = true; grp.add(shell);
122
- // barbs: two rows of backward-pointing teeth (like a real stinger lancet)
123
- 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;
124
- 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); }
125
- bi.castShadow = true; grp.add(bi); grp.rotation.z = SPIRE.tilt; return grp; }
126
- 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();
127
- 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); }
 
128
  im.castShadow = im.receiveShadow = true; return im; }
129
 
130
  /* ---------- sky & clouds (real clouds: morning valley fog + high altocumulus) ---------- */
@@ -137,27 +145,35 @@ function cloudDeck(y, alpha, scale) { return new THREE.Mesh(new THREE.PlaneGeome
137
  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);
138
  float dist=length(vW.xz-cameraPosition.xz); vec3 v=normalize(vW-cameraPosition); gl_FragColor=vec4(c, cov*A*smoothstep(0.02,0.25,abs(v.y))); }` })); }
139
  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);
140
- const mats = [0, 1].map(k => new THREE.SpriteMaterial({ map: cloudTex, color: new THREE.Color().setHSL(.07, .3, .86 - k * .06), transparent: true, opacity: .35, depthWrite: false }));
141
- const n = 0; 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
142
- const mist = new THREE.SpriteMaterial({ map: cloudTex, color: 0xf3e9dc, transparent: true, opacity: .28, depthWrite: false });
143
- for (let i = 0; i < 0; 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); }
144
  g.userData = { hi }; return g; }
145
 
146
- /* ---------- forest, river/lake water, village ---------- */
147
- function buildForest(q) { const n = q === 'high' ? 70000 : 18000; const cone = new THREE.ConeGeometry(1, 1, 7, 3); cone.translate(0, .5, 0);
 
 
148
  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));
149
  const im = new THREE.InstancedMesh(cone, M.pine, n), o = new THREE.Object3D(), c = new THREE.Color(); let k = 0;
150
- 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;
151
- 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;
152
- 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;
153
- const h = 22 + rnd() * 26; 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(.06 + rnd() * .03, .1 + rnd() * .05, .05 + rnd() * .02); im.setColorAt(k++, c); }
154
  im.count = k; im.castShadow = q === 'high'; im.receiveShadow = true; return im; }
155
- 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;
 
 
 
 
 
 
 
 
156
  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);
157
- const pts = RIVER.map(([x, z]) => new THREE.Vector3(x, 0, z)); const curve = new THREE.CatmullRomCurve3(pts); const N = 160, pos = [], idx = [];
158
- 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); }
159
- 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; }
160
- 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);
 
 
161
  const walls = new THREE.InstancedMesh(box, M.wall, n), roofs = new THREE.InstancedMesh(roof, M.roof, n), o = new THREE.Object3D(); let k = 0;
162
  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);
163
  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); }
@@ -209,9 +225,11 @@ function monument(kind) { const g = new THREE.Group(); const add = (geo, mat, x,
209
  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])); }
210
  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]); }
211
  return g; }
212
- export function shrineSpots(n) { // switchback along the east slope terraces, from the valley up toward the temple
213
- 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; }
214
- 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;
 
 
215
  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; };
216
  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);
217
  // gate (fly through it)
@@ -224,31 +242,37 @@ function buildShrine(s, spot) { const g = new THREE.Group(); g.position.set(spot
224
 
225
  /* ---------- build ---------- */
226
  export function buildWorld(scene, renderer, studios, colOf, q) {
227
- makeMaterials(q);
228
- 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);
229
  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);
230
  scene.environment = pm.fromScene(es, 0, .1, 2000).texture; scene.environmentIntensity = .55; }
231
- scene.fog = new THREE.FogExp2(0xa7b3c0, .00003);
232
- 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);
233
- scene.add(new THREE.HemisphereLight(0xa8bcd8, 0x54432e, .85));
234
- // temple summit + shrine pads
235
- 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); }
236
- PADS.push({ x: top.x, z: top.z, r: 80, y: top.y - 35 }); SNOW.value = top.y - 500; TOPU.value.copy(top);
237
- 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 }));
238
- // terrain: near (east-flank land, high detail), mid, far (to the horizon)
239
- scene.add(terrainMesh(5000, 0, 13000, q === 'high' ? 520 : 300, false, q));
240
- const mid = terrainMesh(0, 0, 60000, q === 'high' ? 300 : 180, true, q); mid.position.y = -2; scene.add(mid);
241
- const far = terrainMesh(0, 0, 320000, 160, true, q); far.position.y = -40; far.receiveShadow = false; scene.add(far);
 
 
242
  const spire = buildSpire(q); scene.add(spire); scene.add(buildTalus(q));
243
- const clouds = buildClouds(q); scene.add(clouds); scene.add(buildForest(q)); scene.add(buildWater()); scene.add(buildVillage(q, VILLAGE)); scene.add(buildVillage(q, VILLAGE2));
244
- const temple = buildTemple(new THREE.Vector3(top.x, top.y - 35, top.z)); scene.add(temple);
 
 
 
245
  const shrines = studios.map((s, i) => { const r = buildShrine(s, spots[i]); scene.add(r.group); r.portal.userData.i = i; return r; });
246
- const W = { sky, sun, spire, clouds, temple, shrines, spots, peak: top.y - 35, core: temple.userData.core, top,
 
 
247
  update(t, dt, camera, focus) { clouds.userData.hi.material.uniforms.t.value = t;
248
- const alt = Math.max(0, camera.position.y - 600); scene.fog.density = .00003 * Math.exp(-alt / 4000) + .000005; const nr = alt > 2500 ? Math.min(30, alt / 300) : 1; if (Math.abs(camera.near - nr) > .4) { camera.near = nr; camera.updateProjectionMatrix(); }
249
  temple.userData.cl.intensity = 2600 + Math.sin(t * 1.3) * 250;
250
- // shadow frustum: wide when high up (the spire's long shadow), tight around the bee near the ground
251
- 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(); }
252
- 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); } } };
253
  return W;
254
  }
 
1
+ // STUDIUS World P8 (realistic, compact): a colossal fossil bee stinger (~10 km) lies crashed and half-buried in the plain like a
2
+ // mountain range, base (broken end) in the east, tip dug into the ground in the west. Soil, meadow and forest overgrew its back;
3
+ // its exposed chitin flanks carry a tarn, a river and a waterfall down to a valley lake. The temple stands on the snowy summit near
4
+ // the base; the 5 category terraces step down the back along one short path. 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';
 
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, .085, .32).normalize();
15
+ const XB = 1500, LEN = 10000, R0 = 1700; // base x, length, base radius
16
+ const SU = { x: 700 }; export const MC = new THREE.Vector2(SU.x, 0); // summit (temple); MC.y set from the axis below
17
+ const CATN = ['Erschaffen', 'Veröffentlichen', 'Verkaufen', 'Team', 'Dev'];
18
+ const TX = [-60, -620, -1180, -1740, -2300]; // terrace centres (x) down the back
19
+ const zA = (x) => 420 * Math.sin(Math.min(1, Math.max(0, (XB - x) / LEN)) * Math.PI * .9); // gently curved axis
20
+ MC.y = zA(SU.x);
21
+ const sR = (u) => R0 * Math.pow(Math.max(0, 1 - u), .9), sC = (u) => -.28 * sR(u) - 200 * u * u; // radius, centre height (tip dives in)
22
+ const uOf = (x) => (XB - x) / LEN;
23
+ const TARN = { x: -900, z: zA(-900) + 300, r: 85 }; let TARN_Y = 0;
24
+ const LAKE = { x: -1500, z: 0, r: 420 }; LAKE.z = zA(-1500) + sR(uOf(-1500)) + 900; let LAKE_Y = 0;
25
+ const VILLAGE = { x: -400, z: LAKE.z + 650, r: 300 };
26
  /* ---------- textures ---------- */
27
  const TL = new THREE.TextureLoader();
28
  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; };
29
  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; }
30
+ export const M = {}; const SNOW = { value: 1300, type: 'float' }, TOPU = { value: new THREE.Vector3(), type: 'vec3' };
 
31
  // shared triplanar injection (world-space, no stretching on cliffs)
32
  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; }`;
33
  function withWorld(m, frag, uniforms) { m.onBeforeCompile = (s) => { Object.assign(s.uniforms, uniforms);
 
48
  vec3 c = mix(gr, fg * vec3(0.8,0.9,0.7), clamp(forest * 4.0, 0.0, 0.6)) * (0.75 + 0.5 * macro);
49
  c *= mix(vec3(1.0), vColor.rgb * 2.4, 0.55) * vec3(0.8, 0.9, 0.75);
50
  c = mix(c, rk * vec3(0.85,0.82,0.78), smoothstep(0.28, 0.5, slope));
51
+ float snow = smoothstep(uSnow, uSnow + 140.0, vWP.y + 120.0 * (macro.g - 0.4) + 40.0 * sin(vWP.x*0.01) * cos(vWP.z*0.012)) * smoothstep(1400.0, 700.0, length(vWP.xz - uTop.xz)) * (1.0 - smoothstep(0.7, 0.92, slope));
52
  c = mix(c, vec3(0.86, 0.88, 0.92) * (0.8 + 0.25 * triT(tSn, vWP, vWN, 0.02).r), snow);
53
  diffuseColor.rgb = c;`, { tAer: { value: aerD }, tRock: { value: rockD }, tGr: { value: grD }, tFg: { value: fgD }, tSn: { value: snD }, uSnow: SNOW, uTop: TOPU });
54
  // stinger: weathered stone-chitin, natural amber-ochre banding, lichen; huge-scale + close-scale detail
 
58
  diffuseColor.rgb = c;`, { tRock: { value: rockD }, tAer: { value: aerD } });
59
  M.spire = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1, envMapIntensity: .5, normalMap: rockN, normalScale: new THREE.Vector2(1.3, 1.3) }), `
60
  vec3 a = triT(tRock, vWP, vWN, 0.02), b = triT(tRock, vWP, vWN, 0.0016);
61
+ vec3 c = vColor.rgb * dot(a * 0.7 + b * 0.7, vec3(0.3, 0.5, 0.2)) * 1.6;
62
+ float moss = smoothstep(0.6, 0.92, vWN.y) * smoothstep(-0.2, 0.4, sin(vWP.x*0.004)*cos(vWP.z*0.005) + sin(vWP.y*0.003));
63
+ c = min(c, vec3(0.36, 0.29, 0.21));
64
+ c = mix(c, vec3(0.2,0.25,0.1) * (0.7 + 0.6*b.g), moss * 0.12);
65
  diffuseColor.rgb = c;`, { tRock: { value: rockD } });
66
  M.barb = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1), normalMap: rockN, color: 0x3a3028, roughness: .9 });
67
  M.stone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.5), normalMap: rockN, color: 0xb3a691, roughness: .92 });
 
76
  M.cloth = new THREE.MeshStandardMaterial({ color: 0x8b6b2e, roughness: .9, side: THREE.DoubleSide });
77
  }
78
 
79
+ /* ---------- terrain: plain to the horizon + the overgrown back of the stinger ---------- */
80
  const PADS = [];
81
  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); }
82
+ // exposed stinger surface height (or -1e9 off the stinger)
83
+ export function stingH(x, z) { const u = uOf(x); if (u < 0 || u > 1) return -1e9; const r = sR(u) * .96, dz = z - zA(x); if (Math.abs(dz) >= r) return -1e9; return sC(u) + Math.sqrt(r * r - dz * dz); }
84
+ const landMask = (x, z) => sstep(4200, 1800, Math.abs(z - zA(x)) + 300 * fbm(x * .0003, z * .0003, 2)) * sstep(-10500, -8000, x) * sstep(5500, 3500, x);
85
  function rawH(x, z) {
86
+ const u = uOf(x), uc = Math.min(1, Math.max(0, u)), r = sR(uc), dz = z - zA(x), q = Math.abs(dz) / Math.max(1, r);
87
+ // regional plain + distant ranges on the horizon
88
+ let g = 120 * fbm(x * .00012, z * .00012, 6, 1) + 1100 * Math.max(0, ridged(x * .00006, z * .00006, 4) - .5) * sstep(9000, 20000, Math.hypot(x + 3500, z)) + 25 * fbm(x * .0016, z * .0016, 3, 2);
89
+ // crash ejecta: soil heaped against both flanks, rubble mound at the broken base
90
+ if (u > .02 && u < 1.05) g += (60 + .12 * r) * Math.exp(-Math.pow((Math.abs(dz) - r * 1.05) / (r * .45 + 120), 2)) * (.75 + .25 * fbm(x * .001, z * .001, 3, 4)) * sstep(1.05, .9, u);
91
+ g += 140 * Math.exp(-Math.pow(Math.hypot(x - XB - 1100, dz) / 800, 2)) * (.6 + .4 * ridged(x * .002, z * .002, 3));
92
+ if (u < 0 || u > 1) return g;
93
+ // soil cover on the back: a crowned meadow surface slightly above the chitin, ending in ragged edges above the bare flanks
94
+ const n = .07 * fbm(x * .0011, z * .0011, 3, 9);
95
+ const top = sC(uc) + r * Math.sqrt(Math.max(0, 1 - q * q)), cover = sstep(.5, .3, q + n) * sstep(XB + 40, XB - 300, x) * sstep(.95, .85, u);
96
+ let h = top + (14 + .12 * r * q * q) * cover - (.08 * r + 10) * (1 - cover); // soil skin on the back; bare chitin where it thins out
97
+ h += cover * (430 * Math.exp(-(Math.pow(x - SU.x, 2) + dz * dz) / 2.2e5) * (.7 + .3 * ridged(x * .003, z * .003, 3)) + 8 * fbm(x * .004, z * .004, 3, 5)); // summit crag
98
+ h -= 14 * sstep(TARN.r * 1.4, TARN.r * .6, Math.hypot(x - TARN.x, z - TARN.z));
99
+ g = Math.max(g, h);
100
+ g -= 45 * sstep(LAKE.r * 1.3, LAKE.r * .5, Math.hypot(x - LAKE.x, z - LAKE.z));
101
+ return g; }
102
+ function groundH(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 * 1.6) h = THREE.MathUtils.lerp(h, p.y, sstep(p.r * 1.6, p.r, d)); } return h; }
103
+ export function landH(x, z) { return Math.max(groundH(x, z), stingH(x, z)); }
104
  function terrainMesh(cx, cz, size, S, drop, q) {
105
  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();
106
+ for (let i = 0; i < p.count; i++) { const x = p.getX(i), z = p.getZ(i); let y = groundH(x, z); const lm = landMask(x, z);
107
+ if (drop && x > -9300 && x < 4300 && Math.abs(z) < 6800) y = Math.min(y, 0) - 300; // hidden under the near mesh
108
+ p.setY(i, y - Math.pow(Math.max(0, Math.hypot(x + 3500, z) - 14000), 2) / 12.7e6); const m = .5 + .5 * fbm(x * .0011, z * .0011, 3, 8);
109
+ c.setRGB(.32 + .06 * m, .33 + .05 * m, .2); // dry grassland (regional)
110
+ c.lerp(new THREE.Color(.2 + .05 * m, .32 + .07 * m, .12), lm * (.8 + .2 * m)); // green land around and on the stinger
111
+ const fd = fbm(x * .0016, z * .0016, 3, 12), fr = fbm(x * .00035, z * .00035, 3, 14); c.lerp(new THREE.Color(.07, .12, .05), Math.min(1, lm * sstep(-.05, .2, fd) * .9 + (1 - lm) * sstep(0, .3, fr) * .7) * sstep(1050, 850, y)); // forests
 
112
  col.set([c.r, c.g, c.b], i * 3); }
113
  g.setAttribute('color', new THREE.BufferAttribute(col, 3)); g.computeVertexNormals(); const m = new THREE.Mesh(g, M.terrain); m.receiveShadow = true; return m; }
114
 
115
+ /* ---------- the stinger: a tapered, plated lancet lying in the ground ---------- */
116
+ function buildSpire(q) { const grp = new THREE.Group(); const L = q === 'high' ? 360 : 200, A = q === 'high' ? 160 : 96, pos = [], col = [], idx = [];
117
+ const chit = new THREE.Color(.16, .12, .085), amber = new THREE.Color(.62, .42, .14), c = new THREE.Color(), SEG = 380;
118
+ for (let i = 0; i <= L; i++) { const u = Math.pow(i / L, 1.1) * .995, x = XB - u * LEN, t = u * LEN, ph = (t / SEG) % 1, seg = Math.floor(t / SEG), r0 = sR(u), cy = sC(u), cz = zA(x);
119
+ const plate = 1 + .05 * Math.pow(1 - ph, 2.2) - .03 - .03 * sstep(.97, 1, 1 - ph); // overlapping ring plates, flaring toward the base
120
+ const band = sstep(.82, .97, 1 - ph) + sstep(0, .05, 1 - ph) * (1 - sstep(.05, .12, 1 - ph));
121
+ const brk = i === 0 ? .82 : 1; // broken, ragged base
122
+ for (let j = 0; j <= A; j++) { const a = j / A * Math.PI * 2; const r = r0 * brk * 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)) * (i === 0 ? 1 + .12 * nz(a * 3, 1) : 1);
123
+ pos.push(x + (i === 0 ? 60 * nz(a * 4, 2) : 0), cy + Math.sin(a) * r, cz + Math.cos(a) * r);
124
+ const gg = .85 + .3 * fbm(t * .003, a * 9, 3, 2); c.copy(chit).multiplyScalar(gg).lerp(amber, Math.min(1, band * (.6 + .5 * fbm(t * .002 + 4, a * 7, 3)))); col.push(c.r, c.g, c.b); } }
 
125
  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); }
126
+ // broken base face (fossil cross-section)
127
  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();
128
  const shell = new THREE.Mesh(g, M.spire); shell.castShadow = shell.receiveShadow = true; grp.add(shell);
129
+ // barbs: two rows of backward-pointing teeth along the flanks, like a real stinger lancet
130
+ const nb = q === 'high' ? 44 : 26, 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;
131
+ for (const s of [-1, 1]) for (let i = 0; i < nb; i++) { const u = .06 + i * (.62 / nb), x = XB - u * LEN, r = sR(u), a = .5, cz = zA(x) + s * Math.cos(a) * r * .97, cy = sC(u) + Math.sin(a) * r * .97, sz = r * .16 + 25;
132
+ o.position.set(x, cy, cz); o.lookAt(x + r * 1.6, cy + r * .4, cz + s * r * 1.2); o.rotateX(Math.PI / 2); o.scale.set(sz * .35, sz, sz * .35); o.updateMatrix(); bi.setMatrixAt(k++, o.matrix); }
133
+ bi.castShadow = true; grp.add(bi); return grp; }
134
+ function buildTalus(q) { const n = q === 'high' ? 700 : 300; 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();
135
+ const im = new THREE.InstancedMesh(geo, M.stone, n), o = new THREE.Object3D(); for (let i = 0; i < n; i++) { const u = rnd() * .9, x = XB - u * LEN + (i % 5 === 0 ? 900 * rnd() : 0), s1 = rnd() < .5 ? -1 : 1, z = zA(x) + s1 * sR(Math.max(0, u)) * (1 + Math.pow(rnd(), 2) * .5); const s = 8 + Math.pow(rnd(), 3) * 90; 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); }
136
  im.castShadow = im.receiveShadow = true; return im; }
137
 
138
  /* ---------- sky & clouds (real clouds: morning valley fog + high altocumulus) ---------- */
 
145
  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);
146
  float dist=length(vW.xz-cameraPosition.xz); vec3 v=normalize(vW-cameraPosition); gl_FragColor=vec4(c, cov*A*smoothstep(0.02,0.25,abs(v.y))); }` })); }
147
  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);
 
 
 
 
148
  g.userData = { hi }; return g; }
149
 
150
+ /* ---------- forest, path, tarn/river/waterfall/lake, village ---------- */
151
+ let PATHP = []; const pathD = (x, z) => { let d = 1e9; for (let i = 0; i < PATHP.length - 1; i++) d = Math.min(d, distSeg(x, z, PATHP[i].x, PATHP[i].z, PATHP[i + 1].x, PATHP[i + 1].z)); return d; };
152
+ let RIVP = []; const riverD = (x, z) => { let d = 1e9; for (let i = 0; i < RIVP.length - 1; i += 3) d = Math.min(d, distSeg(x, z, RIVP[i].x, RIVP[i].z, RIVP[Math.min(i + 3, RIVP.length - 1)].x, RIVP[Math.min(i + 3, RIVP.length - 1)].z)); return d; };
153
+ function buildForest(q) { const n = q === 'high' ? 50000 : 14000; const cone = new THREE.ConeGeometry(1, 1, 7, 3); cone.translate(0, .5, 0);
154
  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));
155
  const im = new THREE.InstancedMesh(cone, M.pine, n), o = new THREE.Object3D(), c = new THREE.Color(); let k = 0;
156
+ for (let i = 0; i < n * 5 && k < n; i++) { const x = -8000 + rnd() * 10500, z = zA(x) + (rnd() * 2 - 1) * 3600; if (landMask(x, z) < .6) continue; const dens = fbm(x * .0016, z * .0016, 3, 12); if (dens < -.02) continue;
157
+ const y = groundH(x, z); if (y < stingH(x, z) + 3 || y > 980 + 120 * dens) continue; if (Math.hypot(x - LAKE.x, z - LAKE.z) < LAKE.r * 1.15 || Math.hypot(x - TARN.x, z - TARN.z) < TARN.r * 1.4 || riverD(x, z) < 20 || pathD(x, z) < 12 || Math.hypot(x - VILLAGE.x, z - VILLAGE.z) < VILLAGE.r) continue;
158
+ const y2 = groundH(x + 4, z), y3 = groundH(x, z + 4); if (Math.hypot(y2 - y, y3 - y) > 3) continue; if (PADS.some(p => Math.hypot(p.x - x, p.z - z) < p.r * 1.25)) continue;
159
+ const h = 20 + rnd() * 24; 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(.06 + rnd() * .03, .1 + rnd() * .05, .05 + rnd() * .02); im.setColorAt(k++, c); }
160
  im.count = k; im.castShadow = q === 'high'; im.receiveShadow = true; return im; }
161
+ // draped ribbon along a polyline (path, river); keep(i) selects segments
162
+ function ribbon(pts, w, lift, mat, keep = () => true) { const pos = [], idx = []; for (let i = 0; i < pts.length; i++) { const a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)], dx = b.x - a.x, dz = b.z - a.z, l = Math.hypot(dx, dz) || 1, nx = -dz / l, nzz = dx / l;
163
+ for (const s of [-1, 1]) pos.push(pts[i].x + nx * w * s, pts[i].y + lift, pts[i].z + nzz * w * s); if (i < pts.length - 1 && keep(i)) idx.push(i * 2, i * 2 + 2, i * 2 + 1, i * 2 + 1, i * 2 + 2, i * 2 + 3); }
164
+ const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setIndex(idx); g.computeVertexNormals(); const m = new THREE.Mesh(g, mat); m.receiveShadow = true; return m; }
165
+ function sampleLine(ctrl, step) { const out = []; for (let i = 0; i < ctrl.length - 1; i++) { const [ax, az] = ctrl[i], [bx, bz] = ctrl[i + 1], n = Math.max(1, Math.ceil(Math.hypot(bx - ax, bz - az) / step)); for (let k = 0; k < n; k++) { const x = ax + (bx - ax) * k / n, z = az + (bz - az) * k / n; out.push({ x, z, y: 0 }); } } const e = ctrl[ctrl.length - 1]; out.push({ x: e[0], z: e[1], y: 0 }); return out; }
166
+ function buildWater() { const g = new THREE.Group();
167
+ TARN_Y = Math.min(...[0, 1, 2, 3, 4, 5].map(a => groundH(TARN.x + Math.cos(a) * TARN.r * 1.2, TARN.z + Math.sin(a) * TARN.r * 1.2))) - 2;
168
+ const tarn = new THREE.Mesh(new THREE.CircleGeometry(TARN.r * 1.3, 48), M.water); tarn.rotation.x = -Math.PI / 2; tarn.position.set(TARN.x, TARN_Y, TARN.z); g.add(tarn);
169
+ LAKE_Y = Math.min(...[0, 1, 2, 3, 4, 5].map(a => groundH(LAKE.x + Math.cos(a) * LAKE.r * 1.15, LAKE.z + Math.sin(a) * LAKE.r * 1.15))) - 3;
170
  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);
171
+ // river: tarn outflow → over the bare south flank (waterfall) → valley lake; height never rises downstream
172
+ let yl = 1e9; RIVP.forEach(p => { p.y = Math.min(yl, landH(p.x, p.z)); yl = p.y; });
173
+ g.add(ribbon(RIVP, 7, 1.2, M.water));
174
+ const steep = (i) => RIVP[i].y - RIVP[i + 1].y > 4; g.add(ribbon(RIVP, 8, 2, M.foam, steep));
175
+ return g; }
176
+ function buildVillage(q, VILLAGE) { const n = q === 'high' ? 110 : 60; 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);
177
  const walls = new THREE.InstancedMesh(box, M.wall, n), roofs = new THREE.InstancedMesh(roof, M.roof, n), o = new THREE.Object3D(); let k = 0;
178
  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);
179
  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); }
 
225
  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])); }
226
  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]); }
227
  return g; }
228
+ export function shrineSpots(studios) { // ring of shrines on each category terrace, all facing the terrace centre
229
+ const T = CATN.map((c, k) => ({ cat: c, x: TX[k], z: zA(TX[k]) + (k % 2 ? 90 : -90), list: [] })); studios.forEach((s, i) => (T[CATN.indexOf(s.cat)] || T[0]).list.push(i));
230
+ const out = []; T.forEach(t => { const n = t.list.length, R = Math.max(42, n * 46 / (2 * Math.PI)); t.r = R + 34; t.list.forEach((i, j) => { const a = (j + .5) / Math.max(1, n) * Math.PI * 2 + Math.PI / 2; out[i] = { x: t.x + Math.cos(a) * R, z: t.z + Math.sin(a) * R, t }; }); });
231
+ return { spots: out, T }; }
232
+ function buildShrine(s, spot) { const g = new THREE.Group(); g.position.set(spot.x, spot.y, spot.z); g.rotation.y = Math.atan2(spot.t.x - spot.x, spot.t.z - spot.z);
233
  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; };
234
  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);
235
  // gate (fly through it)
 
242
 
243
  /* ---------- build ---------- */
244
  export function buildWorld(scene, renderer, studios, colOf, q) {
245
+ makeMaterials(q); M.foam = new THREE.MeshStandardMaterial({ color: 0xdfe5e8, roughness: .55, transparent: true, opacity: .85 }); M.path = new THREE.MeshStandardMaterial({ color: 0x8c7b62, roughness: 1, polygonOffset: true, polygonOffsetFactor: -2 });
246
+ const sky = new Sky(); sky.scale.setScalar(4e5); const u = sky.material.uniforms; u.turbidity.value = 5; u.rayleigh.value = 2; u.mieCoefficient.value = .005; u.mieDirectionalG.value = .86; u.sunPosition.value.copy(SUN_DIR).multiplyScalar(1e5); scene.add(sky);
247
  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);
248
  scene.environment = pm.fromScene(es, 0, .1, 2000).texture; scene.environmentIntensity = .55; }
249
+ scene.fog = new THREE.FogExp2(0xa9b4c0, .00004);
250
+ const sun = new THREE.DirectionalLight(0xffd2a0, 4.2); sun.castShadow = true; sun.shadow.mapSize.setScalar(q === 'high' ? 4096 : 2048); sun.shadow.bias = -.0004; sun.shadow.normalBias = 2; scene.add(sun, sun.target);
251
+ scene.add(new THREE.HemisphereLight(0xa8bcd8, 0x54432e, .9));
252
+ // summit (temple) + terraces
253
+ const top = new THREE.Vector3(SU.x, -1e9, MC.y); for (let i = 0; i < 400; i++) { const x = SU.x + (rnd() - .5) * 500, z = MC.y + (rnd() - .5) * 500, h = rawH(x, z); if (h > top.y) top.set(x, h, z); }
254
+ MC.set(top.x, top.z); PADS.push({ x: top.x, z: top.z, r: 80, y: top.y - 30 }); SNOW.value = top.y - 260; TOPU.value.copy(top);
255
+ const { spots, T } = shrineSpots(studios); T.forEach(t => { t.y = rawH(t.x, t.z) + 1; PADS.push({ x: t.x, z: t.z, r: t.r, y: t.y }); }); spots.forEach(s => s.y = s.t.y);
256
+ // path: temple stairs → terraces, river: tarn → south flank → lake
257
+ PATHP = sampleLine([[top.x + 40, top.z], ...T.map(t => [t.x, t.z])], 12); PATHP.forEach(p => p.y = groundH(p.x, p.z));
258
+ RIVP = sampleLine([[TARN.x, TARN.z], [TARN.x - 120, TARN.z + 500], [LAKE.x + 150, LAKE.z - LAKE.r * .9], [LAKE.x, LAKE.z]], 10);
259
+ scene.add(terrainMesh(-2500, 0, 14000, q === 'high' ? 520 : 300, false, q));
260
+ const mid = terrainMesh(-2500, 0, 60000, q === 'high' ? 300 : 180, true, q); mid.position.y = -2; scene.add(mid);
261
+ const far = terrainMesh(-2500, 0, 320000, 160, true, q); far.position.y = -40; far.receiveShadow = false; scene.add(far);
262
  const spire = buildSpire(q); scene.add(spire); scene.add(buildTalus(q));
263
+ const clouds = buildClouds(q); scene.add(clouds); scene.add(buildWater()); scene.add(buildForest(q)); scene.add(buildVillage(q, VILLAGE));
264
+ scene.add(ribbon(PATHP, 3, .6, M.path));
265
+ // terrace rims: low dry-stone walls make each category plateau readable
266
+ T.forEach(t => { const w = new THREE.Mesh(new THREE.CylinderGeometry(t.r + 8, t.r + 10, 4, 48, 1, true), M.stone); w.position.set(t.x, t.y - 1, t.z); w.receiveShadow = true; scene.add(w); });
267
+ const temple = buildTemple(new THREE.Vector3(top.x, top.y - 30, top.z)); scene.add(temple);
268
  const shrines = studios.map((s, i) => { const r = buildShrine(s, spots[i]); scene.add(r.group); r.portal.userData.i = i; return r; });
269
+ const terraces = T.map(t => ({ cat: t.cat, pos: new THREE.Vector3(t.x, t.y + 40, t.z), list: t.list }));
270
+ const W = { sky, sun, spire, clouds, temple, shrines, spots, terraces, peak: top.y - 30, core: temple.userData.core, top,
271
+ outline: [...Array(21)].map((_, i) => { const uu = i / 20, x = XB - uu * LEN; return [x, zA(x), sR(uu) * .8]; }),
272
  update(t, dt, camera, focus) { clouds.userData.hi.material.uniforms.t.value = t;
273
+ const alt = Math.max(0, camera.position.y - 500); scene.fog.density = .00004 * Math.exp(-alt / 4000) + .000005; const nr = alt > 2500 ? Math.min(30, alt / 300) : 1; if (Math.abs(camera.near - nr) > .4) { camera.near = nr; camera.updateProjectionMatrix(); }
274
  temple.userData.cl.intensity = 2600 + Math.sin(t * 1.3) * 250;
275
+ const wide = alt > 1000, ext = wide ? 9000 : 450, sc = sun.shadow.camera; if (sc.right !== ext) { sc.left = sc.bottom = -ext; sc.right = sc.top = ext; sc.far = wide ? 50000 : 8000; sc.updateProjectionMatrix(); }
276
+ const f = wide ? new THREE.Vector3(-2500, 300, 0) : focus; if (f) { sun.position.copy(f).addScaledVector(SUN_DIR, wide ? 20000 : 3000); sun.target.position.copy(f); } } };
 
277
  return W;
278
  }