Spaces:
Paused
Paused
World p5b: dark ribbed spire, CC0 splat terrain, sky fixes, snow
Browse files- .gitattributes +5 -5
- app.js +8 -8
- assets/tex/LICENSE.txt +1 -0
- assets/tex/aerial_grass_rock-diff.webp +3 -0
- assets/tex/aerial_grass_rock-nor_gl.webp +3 -0
- assets/tex/forrest_ground_01-diff.webp +3 -0
- assets/tex/forrest_ground_01-nor_gl.webp +3 -0
- assets/tex/snow_02-diff.webp +0 -0
- assets/tex/snow_02-nor_gl.webp +3 -0
- avatar.js +1 -1
- index.html +2 -2
- master.js +1 -1
- studios5.js +3 -3
- style.css +4 -0
- video.js +2 -2
- workspace.js +2 -2
- world.js +33 -27
.gitattributes
CHANGED
|
@@ -33,8 +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
|
| 36 |
-
assets/tex/
|
| 37 |
-
assets/tex/
|
| 38 |
-
assets/tex/
|
| 39 |
-
assets/tex/
|
| 40 |
-
assets/tex/
|
|
|
|
| 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_grass_rock-diff.webp filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/tex/aerial_grass_rock-nor_gl.webp filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/tex/forrest_ground_01-diff.webp filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/tex/forrest_ground_01-nor_gl.webp filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/tex/snow_02-nor_gl.webp filter=lfs diff=lfs merge=lfs -text
|
app.js
CHANGED
|
@@ -1,15 +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=
|
| 4 |
-
import './avatar.js?v=
|
| 5 |
-
import './master.js?v=
|
| 6 |
-
import './video.js?v=
|
| 7 |
-
import './workspace.js?v=
|
| 8 |
-
import './studios5.js?v=
|
| 9 |
-
import { icon } from './icons.js?v=
|
| 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=
|
| 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';
|
|
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
+
import './real.js?v=108';
|
| 4 |
+
import './avatar.js?v=108';
|
| 5 |
+
import './master.js?v=108';
|
| 6 |
+
import './video.js?v=108';
|
| 7 |
+
import './workspace.js?v=108';
|
| 8 |
+
import './studios5.js?v=108';
|
| 9 |
+
import { icon } from './icons.js?v=108';
|
| 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=108';
|
| 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';
|
assets/tex/LICENSE.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
Poly Haven CC0 textures (https://polyhaven.com/license): rock_face, aerial_rocks_02 (1k)
|
|
|
|
|
|
| 1 |
Poly Haven CC0 textures (https://polyhaven.com/license): rock_face, aerial_rocks_02 (1k)
|
| 2 |
+
aerial_grass_rock, snow_02, forrest_ground_01: Poly Haven CC0
|
assets/tex/aerial_grass_rock-diff.webp
ADDED
|
Git LFS Details
|
assets/tex/aerial_grass_rock-nor_gl.webp
ADDED
|
Git LFS Details
|
assets/tex/forrest_ground_01-diff.webp
ADDED
|
Git LFS Details
|
assets/tex/forrest_ground_01-nor_gl.webp
ADDED
|
Git LFS Details
|
assets/tex/snow_02-diff.webp
ADDED
|
assets/tex/snow_02-nor_gl.webp
ADDED
|
Git LFS Details
|
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=
|
| 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=108';
|
| 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=
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
@@ -49,6 +49,6 @@
|
|
| 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=
|
| 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=108">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
|
|
| 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=108"></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=
|
| 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=108';
|
| 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=
|
| 5 |
-
import { Avatars } from './avatar.js?v=
|
| 6 |
-
import { toWav, toMp3 } from './master.js?v=
|
| 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=108';
|
| 5 |
+
import { Avatars } from './avatar.js?v=108';
|
| 6 |
+
import { toWav, toMp3 } from './master.js?v=108';
|
| 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
|
@@ -264,3 +264,7 @@ body:not(.live) #beebtn{display:none}
|
|
| 264 |
#mm circle.bee{fill:#fff;stroke:#f2c94c;stroke-width:1.2}
|
| 265 |
|
| 266 |
body:not(.live) #labels{display:none}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
#mm circle.bee{fill:#fff;stroke:#f2c94c;stroke-width:1.2}
|
| 265 |
|
| 266 |
body:not(.live) #labels{display:none}
|
| 267 |
+
|
| 268 |
+
body.world .halo,.halo{display:none!important}
|
| 269 |
+
|
| 270 |
+
body::before{background:radial-gradient(ellipse at 50% 50%,transparent 55%,rgba(0,0,0,.35) 130%)!important}
|
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=
|
| 4 |
-
import { toWav } from './master.js?v=
|
| 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=108';
|
| 4 |
+
import { toWav } from './master.js?v=108';
|
| 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=
|
| 3 |
-
import { Avatars } from './avatar.js?v=
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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=108';
|
| 3 |
+
import { Avatars } from './avatar.js?v=108';
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|
world.js
CHANGED
|
@@ -24,7 +24,7 @@ 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);
|
|
@@ -33,15 +33,21 @@ function withWorld(m, frag, uniforms) { m.onBeforeCompile = (s) => { Object.assi
|
|
| 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 |
-
|
|
|
|
|
|
|
| 37 |
float slope = 1.0 - clamp(vWN.y, 0.0, 1.0);
|
| 38 |
-
vec3
|
| 39 |
-
vec3
|
| 40 |
-
vec3
|
| 41 |
-
|
| 42 |
-
float
|
| 43 |
-
vec3 c = mix(
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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);
|
|
@@ -49,11 +55,11 @@ function makeMaterials(q) {
|
|
| 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.
|
| 53 |
-
float moss = smoothstep(0.
|
| 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:
|
| 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 });
|
|
@@ -81,7 +87,7 @@ function rawH(x, z) {
|
|
| 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)) +
|
| 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; }
|
|
@@ -91,8 +97,8 @@ function terrainMesh(cx, cz, size, S, drop, q) {
|
|
| 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(.
|
| 95 |
-
c.lerp(new THREE.Color(.
|
| 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; }
|
|
@@ -101,9 +107,9 @@ function terrainMesh(cx, cz, size, S, drop, q) {
|
|
| 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(.
|
| 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 + .
|
| 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);
|
|
@@ -127,22 +133,22 @@ function cloudDeck(y, alpha, scale) { return new THREE.Mesh(new THREE.PlaneGeome
|
|
| 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*
|
| 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: .
|
| 133 |
-
const n =
|
| 134 |
-
const mist = new THREE.SpriteMaterial({ map: cloudTex, color: 0xf3e9dc, transparent: true, opacity: .
|
| 135 |
-
for (let i = 0; i <
|
| 136 |
g.userData = { hi }; return g; }
|
| 137 |
|
| 138 |
/* ---------- forest, river/lake water, village ---------- */
|
| 139 |
-
function buildForest(q) { const n = q === 'high' ?
|
| 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(.
|
| 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);
|
|
@@ -220,12 +226,12 @@ export function buildWorld(scene, renderer, studios, colOf, 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(
|
| 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));
|
|
@@ -237,7 +243,7 @@ export function buildWorld(scene, renderer, studios, colOf, q) {
|
|
| 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 = .
|
| 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(); }
|
|
|
|
| 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);
|
|
|
|
| 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 |
+
const T = (n, srgb) => tex('assets/tex/' + n + '.webp', srgb), grD = T('aerial_grass_rock-diff', true), grN = T('aerial_grass_rock-nor_gl'), fgD = T('forrest_ground_01-diff', true), snD = T('snow_02-diff', true);
|
| 37 |
+
// terrain splat: grass / forest floor / dirt / rock / snow by slope, height and the land mask (vertex colour = biome tint)
|
| 38 |
+
M.terrain = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .95, normalMap: grN, normalScale: new THREE.Vector2(1.0, 1.0) }), `
|
| 39 |
float slope = 1.0 - clamp(vWN.y, 0.0, 1.0);
|
| 40 |
+
vec3 macro = triT(tGr, vWP, vWN, 0.00013);
|
| 41 |
+
vec3 gr = triT(tGr, vWP, vWN, 0.012) * 0.55 + triT(tGr, vWP, vWN, 0.0011) * 0.65;
|
| 42 |
+
vec3 fg = triT(tFg, vWP, vWN, 0.05);
|
| 43 |
+
vec3 rk = triT(tRock, vWP, vWN, 0.01) * 0.6 + triT(tAer, vWP, vWN, 0.0012) * 0.5;
|
| 44 |
+
float forest = vColor.g - vColor.r; // >0 on wooded land
|
| 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);
|
| 47 |
+
c = mix(c, rk * vec3(0.85,0.82,0.78), smoothstep(0.28, 0.5, slope));
|
| 48 |
+
float snow = max(smoothstep(1500.0, 700.0, length(vWP.xz - uTop.xz) + 250.0 * sin(vWP.x*0.006) * cos(vWP.z*0.007)) , smoothstep(uSnow, uSnow + 220.0, vWP.y) * smoothstep(3000.0, 1800.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
|
| 52 |
M.stinger = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .93, metalness: 0, normalMap: rockN, normalScale: new THREE.Vector2(1.1, 1.1) }), `
|
| 53 |
vec3 a = triT(tRock, vWP, vWN, 0.004), b = triT(tRock, vWP, vWN, 0.00021), d = triT(tAer, vWP, vWN, 0.0000135);
|
|
|
|
| 55 |
diffuseColor.rgb = c;`, { tRock: { value: rockD }, tAer: { value: aerD } });
|
| 56 |
M.spire = withWorld(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: .9, 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) * 1.05;
|
| 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 = mix(c, vec3(0.24,0.29,0.12) * (0.7 + 0.6*b.g), moss * 0.85);
|
| 61 |
diffuseColor.rgb = c;`, { tRock: { value: rockD } });
|
| 62 |
+
M.barb = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1), normalMap: rockN, color: 0x3a3028, roughness: .9 });
|
| 63 |
M.stone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.5), normalMap: rockN, color: 0xb3a691, roughness: .92 });
|
| 64 |
M.darkStone = new THREE.MeshStandardMaterial({ map: tex('assets/tex/rock_face-diff.webp', true, 1.2), normalMap: rockN, color: 0x6f665c, roughness: .9 });
|
| 65 |
M.bronze = new THREE.MeshStandardMaterial({ color: 0x8a6a3c, metalness: .85, roughness: .48 });
|
|
|
|
| 87 |
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;
|
| 88 |
// the snow mountain (temple) + side peaks
|
| 89 |
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);
|
| 90 |
+
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);
|
| 91 |
// lake & river
|
| 92 |
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;
|
| 93 |
return h; }
|
|
|
|
| 97 |
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);
|
| 98 |
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; }
|
| 99 |
p.setY(i, y); const m = .5 + .5 * fbm(x * .0011, z * .0011, 3, 8);
|
| 100 |
+
c.setRGB(.3 + .06 * m, .33 + .06 * m, .2); // grassland & scrub (regional)
|
| 101 |
+
c.lerp(new THREE.Color(.2 + .05 * m, .32 + .07 * m, .12), lm * (.8 + .2 * m)); // green, wooded land on the east flank
|
| 102 |
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
|
| 103 |
col.set([c.r, c.g, c.b], i * 3); }
|
| 104 |
g.setAttribute('color', new THREE.BufferAttribute(col, 3)); g.computeVertexNormals(); const m = new THREE.Mesh(g, M.terrain); m.receiveShadow = true; return m; }
|
|
|
|
| 107 |
const spR = (t) => SPIRE.R0 * Math.pow(Math.max(0, 1 - t / SPIRE.L), .92);
|
| 108 |
export function spireAxis(t) { const a = SPIRE.tilt; return new THREE.Vector3(-Math.sin(a) * t, Math.cos(a) * t, 0); }
|
| 109 |
function buildSpire(q) { const grp = new THREE.Group(); const L = q === 'high' ? 420 : 220, A = q === 'high' ? 200 : 110, pos = [], col = [], idx = [];
|
| 110 |
+
const chit = new THREE.Color(.1, .085, .07), amber = new THREE.Color(.5, .34, .1), c = new THREE.Color(), SEG = 420;
|
| 111 |
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);
|
| 112 |
+
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
|
| 113 |
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));
|
| 114 |
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));
|
| 115 |
pos.push(Math.cos(a) * r, t, Math.sin(a) * r);
|
|
|
|
| 133 |
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;}
|
| 134 |
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);
|
| 135 |
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);
|
| 136 |
+
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))); }` })); }
|
| 137 |
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);
|
| 138 |
+
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 }));
|
| 139 |
+
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
|
| 140 |
+
const mist = new THREE.SpriteMaterial({ map: cloudTex, color: 0xf3e9dc, transparent: true, opacity: .28, depthWrite: false });
|
| 141 |
+
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); }
|
| 142 |
g.userData = { hi }; return g; }
|
| 143 |
|
| 144 |
/* ---------- forest, river/lake water, village ---------- */
|
| 145 |
+
function buildForest(q) { const n = q === 'high' ? 70000 : 18000; const cone = new THREE.ConeGeometry(1, 1, 7, 3); cone.translate(0, .5, 0);
|
| 146 |
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));
|
| 147 |
const im = new THREE.InstancedMesh(cone, M.pine, n), o = new THREE.Object3D(), c = new THREE.Color(); let k = 0;
|
| 148 |
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;
|
| 149 |
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;
|
| 150 |
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;
|
| 151 |
+
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(.06 + rnd() * .03, .1 + rnd() * .05, .05 + rnd() * .02); im.setColorAt(k++, c); }
|
| 152 |
im.count = k; im.castShadow = q === 'high'; im.receiveShadow = true; return im; }
|
| 153 |
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;
|
| 154 |
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);
|
|
|
|
| 226 |
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);
|
| 227 |
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);
|
| 228 |
scene.environment = pm.fromScene(es, 0, .1, 2000).texture; scene.environmentIntensity = .55; }
|
| 229 |
+
scene.fog = new THREE.FogExp2(0xb9c2cc, .00004);
|
| 230 |
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);
|
| 231 |
scene.add(new THREE.HemisphereLight(0xa8bcd8, 0x54432e, .85));
|
| 232 |
// temple summit + shrine pads
|
| 233 |
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); }
|
| 234 |
+
PADS.push({ x: top.x, z: top.z, r: 80, y: top.y - 35 }); SNOW.value = top.y - 900; TOPU.value.copy(top);
|
| 235 |
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 }));
|
| 236 |
// terrain: near (east-flank land, high detail), mid, far (to the horizon)
|
| 237 |
scene.add(terrainMesh(5000, 0, 13000, q === 'high' ? 520 : 300, false, q));
|
|
|
|
| 243 |
const shrines = studios.map((s, i) => { const r = buildShrine(s, spots[i]); scene.add(r.group); r.portal.userData.i = i; return r; });
|
| 244 |
const W = { sky, sun, spire, clouds, temple, shrines, spots, peak: top.y - 35, core: temple.userData.core, top,
|
| 245 |
update(t, dt, camera, focus) { clouds.userData.hi.material.uniforms.t.value = t;
|
| 246 |
+
const alt = Math.max(0, camera.position.y - 600); 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(); }
|
| 247 |
temple.userData.cl.intensity = 2600 + Math.sin(t * 1.3) * 250;
|
| 248 |
// shadow frustum: wide when high up (the spire's long shadow), tight around the bee near the ground
|
| 249 |
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(); }
|