Turan0k commited on
Commit
d6c8fba
·
verified ·
1 Parent(s): 8fc5d5b

3D hero and About scenes

Browse files
Files changed (2) hide show
  1. index.html +21 -5
  2. scenes3d.js +311 -0
index.html CHANGED
@@ -84,9 +84,16 @@ body::before{content:"";position:fixed;inset:0 0 auto;height:env(safe-area-inset
84
  .hero .cta{display:flex;flex-wrap:wrap;gap:12px}
85
  .stage{grid-column:5/-1;position:relative;margin-top:calc(var(--u)*5);height:clamp(280px,30vw,420px);border-radius:20px;background:var(--navy);overflow:hidden}
86
  .stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
 
 
 
 
 
 
 
87
  .stage .tl{position:absolute;bottom:16px;color:var(--on-navy-2)}
88
  .stage .tl.l{left:20px}.stage .tl.r{right:20px;color:var(--blue-3)}
89
- @media(max-width:900px){.hero .side,.stage{grid-column:1/-1}.stage{height:260px;margin-top:calc(var(--u)*4)}}
90
 
91
  /* stats row */
92
  .facts{border-top:1px solid var(--line);border-bottom:1px solid var(--line)}
@@ -186,7 +193,7 @@ section.s{padding-block:calc(var(--u)*14)}
186
  .about .facts2 div+div{border-left:1px solid var(--navy-line);padding-left:var(--gap)}
187
  .about .facts2 .mono{color:var(--on-navy-2)}
188
  .about .facts2 span:last-child{font-size:17px;font-weight:600}
189
- @media(max-width:760px){.about .q{grid-column:1/-1}.about .facts2{grid-template-columns:minmax(0,1fr)}.about .facts2 div+div{border-left:0;padding-left:0;border-top:1px solid var(--navy-line);margin-top:24px}}
190
 
191
  /* footer */
192
  footer{padding-block:calc(var(--u)*12) calc(var(--u)*4 + env(safe-area-inset-bottom,0px))}
@@ -230,7 +237,7 @@ footer nav a:hover{color:var(--blue)}
230
  <a class="btn line" href="#models">Models</a>
231
  </div>
232
  </div>
233
- <div class="stage" id="stage" role="img" aria-label="A large field of pixels flows into one blue pixel, the centre of the MAIN Lab logo">
234
  <canvas id="hero-cv"></canvas>
235
  <span class="tl l mono">Big AI</span><span class="tl r mono">Small AI</span>
236
  </div>
@@ -302,6 +309,7 @@ footer nav a:hover{color:var(--blue)}
302
  <section class="s about" id="about">
303
  <div class="wrap g12">
304
  <p class="q split">Frontier agents build. <em>Small models run offline.</em></p>
 
305
  <div class="facts2">
306
  <div class="up"><span class="mono">Agents</span><span>Claude Code · Codex</span></div>
307
  <div class="up"><span class="mono">First language</span><span>Azerbaijani</span></div>
@@ -330,6 +338,7 @@ footer nav a:hover{color:var(--blue)}
330
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
331
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js"></script>
332
  <script src="https://cdn.jsdelivr.net/npm/lenis@1.1.13/dist/lenis.min.js"></script>
 
333
  <script>
334
  (function(){
335
  const NAVY='#0B1437',BLUE='#2F6BFF';
@@ -465,7 +474,10 @@ if(G){
465
  if(!reduce)addEventListener('scroll',()=>{const m=document.documentElement.scrollHeight-innerHeight;prog.style.transform=`scaleX(${m>0?scrollY/m:0})`;},{passive:true});
466
  }
467
 
468
- /* ---------- hero canvas: a big pixel field flows into one blue pixel ---------- */
 
 
 
469
  const cv=document.getElementById('hero-cv'),ctx=cv.getContext('2d');
470
  let W=0,Hh=0,cells=[],M=[],T={x:0,y:0},sz=8,running=true,last=0,t0=performance.now(),pulse=0,acc=0;
471
  let seed=7;const rnd=()=>((seed=(seed*16807)%2147483647)/2147483647);
@@ -498,7 +510,7 @@ function draw(now){
498
  ctx.shadowColor='rgba(47,107,255,.9)';ctx.shadowBlur=24*e;ctx.fillStyle=BLUE;rr(x,y,m.s,m.s,m.s*.14);ctx.shadowBlur=0;}
499
  else{ctx.fillStyle=`rgba(255,255,255,${(.95*e).toFixed(3)})`;rr(x,y,m.s,m.s,m.s*.14);}});
500
  pulse=Math.max(0,pulse-dt*2.2);
501
- if(running&&!reduce)requestAnimationFrame(draw);
502
  }
503
  layout();requestAnimationFrame(draw);
504
  let rt;addEventListener('resize',()=>{clearTimeout(rt);rt=setTimeout(()=>{layout();if(reduce)requestAnimationFrame(draw);},120);});
@@ -507,7 +519,11 @@ if(!reduce&&'IntersectionObserver' in window){
507
  new IntersectionObserver(([e])=>{const was=running;running=e.isIntersecting&&!document.hidden;if(running&&!was)wake();}).observe(cv);
508
  document.addEventListener('visibilitychange',()=>{const was=running;running=!document.hidden;if(running&&!was)wake();});
509
  }
 
 
 
510
  })();
511
  </script>
 
512
  </body>
513
  </html>
 
84
  .hero .cta{display:flex;flex-wrap:wrap;gap:12px}
85
  .stage{grid-column:5/-1;position:relative;margin-top:calc(var(--u)*5);height:clamp(280px,30vw,420px);border-radius:20px;background:var(--navy);overflow:hidden}
86
  .stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
87
+ .stage canvas.gl{opacity:0;transition:opacity 1s ease}
88
+ .stage canvas.gl.on{opacity:1}
89
+ .stage .tl{z-index:2}
90
+ .m3d{grid-column:8/-1;position:relative;height:clamp(320px,34vw,480px);align-self:center}
91
+ .m3d canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
92
+ .m3d{-webkit-mask-image:radial-gradient(closest-side,#000 62%,transparent 100%);mask-image:radial-gradient(closest-side,#000 62%,transparent 100%)}
93
+ .about.has3d .q{grid-column:1/span 7;align-self:center}
94
  .stage .tl{position:absolute;bottom:16px;color:var(--on-navy-2)}
95
  .stage .tl.l{left:20px}.stage .tl.r{right:20px;color:var(--blue-3)}
96
+ @media(max-width:900px){.hero .side,.stage{grid-column:1/-1}.stage{height:320px;margin-top:calc(var(--u)*4)}}
97
 
98
  /* stats row */
99
  .facts{border-top:1px solid var(--line);border-bottom:1px solid var(--line)}
 
193
  .about .facts2 div+div{border-left:1px solid var(--navy-line);padding-left:var(--gap)}
194
  .about .facts2 .mono{color:var(--on-navy-2)}
195
  .about .facts2 span:last-child{font-size:17px;font-weight:600}
196
+ @media(max-width:760px){.about .q,.about.has3d .q{grid-column:1/-1}.m3d{grid-column:1/-1;height:300px;margin-top:16px}.about .facts2{grid-template-columns:minmax(0,1fr)}.about .facts2 div+div{border-left:0;padding-left:0;border-top:1px solid var(--navy-line);margin-top:24px}}
197
 
198
  /* footer */
199
  footer{padding-block:calc(var(--u)*12) calc(var(--u)*4 + env(safe-area-inset-bottom,0px))}
 
237
  <a class="btn line" href="#models">Models</a>
238
  </div>
239
  </div>
240
+ <div class="stage" id="stage" role="img" aria-label="3D animation: a large block of cubes streams into one glowing blue cube, the centre of the MAIN Lab logo">
241
  <canvas id="hero-cv"></canvas>
242
  <span class="tl l mono">Big AI</span><span class="tl r mono">Small AI</span>
243
  </div>
 
309
  <section class="s about" id="about">
310
  <div class="wrap g12">
311
  <p class="q split">Frontier agents build. <em>Small models run offline.</em></p>
312
+ <div class="m3d" id="m3d" hidden aria-hidden="true"></div>
313
  <div class="facts2">
314
  <div class="up"><span class="mono">Agents</span><span>Claude Code · Codex</span></div>
315
  <div class="up"><span class="mono">First language</span><span>Azerbaijani</span></div>
 
338
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
339
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js"></script>
340
  <script src="https://cdn.jsdelivr.net/npm/lenis@1.1.13/dist/lenis.min.js"></script>
341
+ <script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.169.0/build/three.module.min.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.169.0/examples/jsm/"}}</script>
342
  <script>
343
  (function(){
344
  const NAVY='#0B1437',BLUE='#2F6BFF';
 
474
  if(!reduce)addEventListener('scroll',()=>{const m=document.documentElement.scrollHeight-innerHeight;prog.style.transform=`scaleX(${m>0?scrollY/m:0})`;},{passive:true});
475
  }
476
 
477
+ /* ---------- 2D fallback: a pixel field flows into one blue pixel (used only if 3D can't run) ---------- */
478
+ let started2D=false,kill2D=false;
479
+ window.__stop2D=()=>{kill2D=true;const c=document.getElementById('hero-cv');if(c)c.style.visibility='hidden';};
480
+ window.__start2D=()=>{if(started2D||kill2D)return;started2D=true;
481
  const cv=document.getElementById('hero-cv'),ctx=cv.getContext('2d');
482
  let W=0,Hh=0,cells=[],M=[],T={x:0,y:0},sz=8,running=true,last=0,t0=performance.now(),pulse=0,acc=0;
483
  let seed=7;const rnd=()=>((seed=(seed*16807)%2147483647)/2147483647);
 
510
  ctx.shadowColor='rgba(47,107,255,.9)';ctx.shadowBlur=24*e;ctx.fillStyle=BLUE;rr(x,y,m.s,m.s,m.s*.14);ctx.shadowBlur=0;}
511
  else{ctx.fillStyle=`rgba(255,255,255,${(.95*e).toFixed(3)})`;rr(x,y,m.s,m.s,m.s*.14);}});
512
  pulse=Math.max(0,pulse-dt*2.2);
513
+ if(running&&!reduce&&!kill2D)requestAnimationFrame(draw);
514
  }
515
  layout();requestAnimationFrame(draw);
516
  let rt;addEventListener('resize',()=>{clearTimeout(rt);rt=setTimeout(()=>{layout();if(reduce)requestAnimationFrame(draw);},120);});
 
519
  new IntersectionObserver(([e])=>{const was=running;running=e.isIntersecting&&!document.hidden;if(running&&!was)wake();}).observe(cv);
520
  document.addEventListener('visibilitychange',()=>{const was=running;running=!document.hidden;if(running&&!was)wake();});
521
  }
522
+ };
523
+ /* give the 3D scene a few seconds to load, then fall back */
524
+ setTimeout(()=>{if(!kill2D)window.__start2D();},5000);
525
  })();
526
  </script>
527
+ <script type="module" src="scenes3d.js" onerror="window.__start2D&&window.__start2D()"></script>
528
  </body>
529
  </html>
scenes3d.js ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // MAIN Lab 3D scenes (Three.js r169, ES modules via the import map in index.html).
2
+ // Hero: a big block of cubes ("big AI") streams into the Pixel M's blue core ("small AI").
3
+ // About: the Pixel M assembles from scattered cubes as the section scrolls into view.
4
+ // If WebGL is missing or anything fails, index.html falls back to the 2D canvas.
5
+ import * as THREE from 'three';
6
+ import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
7
+ import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
8
+ import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
9
+ import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
10
+ import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
11
+ import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
12
+
13
+ const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
14
+ const small = matchMedia('(max-width: 760px)').matches;
15
+ const NAVY = 0x0B1437, BLUE = 0x2F6BFF;
16
+ // Neutral tone mapping subtracts a small offset from dark colours; this input comes out as exactly #0B1437.
17
+ const BG = new THREE.Color().setRGB(.0233, .0269, .0579);
18
+ const P = [[0,0],[4,0],[0,1],[1,1],[3,1],[4,1],[0,2],[2,2],[4,2],[0,3],[4,3],[0,4],[4,4]];
19
+ const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
20
+ const easeOut = t => 1 - Math.pow(1 - t, 3);
21
+ const easeInOut = t => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
22
+ const smooth = t => t * t * (3 - 2 * t);
23
+ // Never scale a lit mesh to exactly 0: its normals become NaN and the bloom pass smears NaN over the whole frame.
24
+ const MIN = 1e-3; const sc = s => Math.max(MIN, s);
25
+
26
+ function webglOK() {
27
+ try { const c = document.createElement('canvas'); return !!(c.getContext('webgl2') || c.getContext('webgl')); }
28
+ catch (e) { return false; }
29
+ }
30
+
31
+ /* pointer, shared by both scenes (mouse only, so touch scrolling is never captured) */
32
+ const pointer = { x: 0, y: 0 };
33
+ addEventListener('pointermove', e => {
34
+ if (e.pointerType !== 'mouse') return;
35
+ pointer.x = e.clientX / innerWidth * 2 - 1;
36
+ pointer.y = e.clientY / innerHeight * 2 - 1;
37
+ }, { passive: true });
38
+
39
+ const geo = new RoundedBoxGeometry(1, 1, 1, 3, .16);
40
+ const views = [];
41
+
42
+ function makeView(el, bloom) {
43
+ const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
44
+ renderer.setPixelRatio(Math.min(devicePixelRatio || 1, small ? 1.5 : 2));
45
+ renderer.toneMapping = THREE.NeutralToneMapping;
46
+ renderer.toneMappingExposure = 1;
47
+ const canvas = renderer.domElement;
48
+ canvas.className = 'gl';
49
+ el.appendChild(canvas);
50
+
51
+ const scene = new THREE.Scene();
52
+ scene.background = BG;
53
+ scene.fog = new THREE.Fog(BG, 10, 26);
54
+ const pmrem = new THREE.PMREMGenerator(renderer);
55
+ scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
56
+ scene.environmentIntensity = .3;
57
+
58
+ const camera = new THREE.PerspectiveCamera(30, 1, .1, 80);
59
+ const composer = new EffectComposer(renderer);
60
+ composer.addPass(new RenderPass(scene, camera));
61
+ composer.addPass(new UnrealBloomPass(new THREE.Vector2(256, 256), bloom.strength, bloom.radius, bloom.threshold));
62
+ composer.addPass(new OutputPass());
63
+
64
+ scene.add(new THREE.HemisphereLight(0xC9D7FF, NAVY, .45));
65
+ const key = new THREE.DirectionalLight(0xffffff, 1.35); key.position.set(4, 6, 8); scene.add(key);
66
+ const rim = new THREE.DirectionalLight(0x6E9BFF, 1.2); rim.position.set(-6, -2, -5); scene.add(rim);
67
+
68
+ const v = { el, renderer, scene, camera, composer, w: 1, h: 1, visible: true, baseZ: 10, onResize: null, tick: null };
69
+ const resize = () => {
70
+ const r = el.getBoundingClientRect();
71
+ v.w = Math.max(1, r.width); v.h = Math.max(1, r.height);
72
+ renderer.setSize(v.w, v.h, false); composer.setSize(v.w, v.h);
73
+ camera.aspect = v.w / v.h; camera.updateProjectionMatrix();
74
+ if (v.onResize) v.onResize(v);
75
+ if (reduce) renderOnce(v);
76
+ };
77
+ v.resize = resize;
78
+ v.fit = (W, H) => {
79
+ const half = THREE.MathUtils.degToRad(camera.fov) / 2;
80
+ v.baseZ = Math.max(H / 2 / Math.tan(half), W / 2 / (Math.tan(half) * camera.aspect)) * 1.08;
81
+ scene.fog.near = v.baseZ - 1; scene.fog.far = v.baseZ + 16;
82
+ };
83
+ new ResizeObserver(resize).observe(el);
84
+ new IntersectionObserver(([e]) => { v.visible = e.isIntersecting; }, { rootMargin: '100px' }).observe(el);
85
+ views.push(v);
86
+ return v;
87
+ }
88
+
89
+ function renderOnce(v) { if (v.tick) { v.tick(99, 0); v.composer.render(0); } }
90
+
91
+ /* soft round sprite for the dust */
92
+ function dotTexture() {
93
+ const c = document.createElement('canvas'); c.width = c.height = 64;
94
+ const g = c.getContext('2d'), gr = g.createRadialGradient(32, 32, 0, 32, 32, 32);
95
+ gr.addColorStop(0, 'rgba(255,255,255,1)'); gr.addColorStop(.4, 'rgba(255,255,255,.35)'); gr.addColorStop(1, 'rgba(255,255,255,0)');
96
+ g.fillStyle = gr; g.fillRect(0, 0, 64, 64);
97
+ const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t;
98
+ }
99
+
100
+ function dust(scene, n, spread) {
101
+ const pos = new Float32Array(n * 3);
102
+ for (let i = 0; i < n; i++) { pos[i * 3] = (Math.random() - .5) * spread; pos[i * 3 + 1] = (Math.random() - .5) * spread * .6; pos[i * 3 + 2] = -2 - Math.random() * 8; }
103
+ const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.BufferAttribute(pos, 3));
104
+ const pts = new THREE.Points(g, new THREE.PointsMaterial({ size: .09, map: dotTexture(), color: 0x6E9BFF, transparent: true, opacity: .55, depthWrite: false }));
105
+ scene.add(pts); return pts;
106
+ }
107
+
108
+ /* ---------------- hero: distillation ---------------- */
109
+ function heroScene() {
110
+ const stage = document.getElementById('stage');
111
+ const v = makeView(stage, { strength: .7, radius: .45, threshold: .96 });
112
+ const { scene, camera } = v;
113
+ const root = new THREE.Group(); scene.add(root);
114
+ const motes = dust(scene, small ? 120 : 260, 22);
115
+
116
+ /* big AI: a 7x7x7 block with gaps */
117
+ let seed = 7; const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
118
+ const lat = new THREE.Group(); root.add(lat);
119
+ const N = 7, SP = .44, CS = .3, cells = [];
120
+ for (let x = 0; x < N; x++) for (let y = 0; y < N; y++) for (let z = 0; z < N; z++) {
121
+ if (rnd() < .22) continue;
122
+ const p = new THREE.Vector3((x - 3) * SP, (y - 3) * SP, (z - 3) * SP);
123
+ cells.push({ p, d: p.length() / (3 * SP * Math.sqrt(3)), ph: rnd() * 6.28, h: 0, hT: 0, back: 0 });
124
+ }
125
+ const latMesh = new THREE.InstancedMesh(geo, new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: .34, metalness: .12 }), cells.length);
126
+ const col = new THREE.Color(), cA = new THREE.Color(0xDCE3F2), cB = new THREE.Color(0x4A5B88);
127
+ cells.forEach((c, i) => latMesh.setColorAt(i, col.copy(cA).lerp(cB, clamp(rnd() * .7 + c.d * .3))));
128
+ lat.add(latMesh);
129
+
130
+ /* small AI: the Pixel M with a glowing core */
131
+ const mG = new THREE.Group(); root.add(mG);
132
+ const MS = .5, MC = .42;
133
+ const outer = P.filter(([x, y]) => !(x === 2 && y === 2));
134
+ const mMesh = new THREE.InstancedMesh(geo, new THREE.MeshStandardMaterial({ color: 0xE9EEF8, roughness: .28, metalness: .12 }), outer.length);
135
+ const mBase = outer.map(([x, y], i) => ({ p: new THREE.Vector3((x - 2) * MS, (2 - y) * MS, 0), delay: .9 + i * .055 }));
136
+ mG.add(mMesh);
137
+ const coreMat = new THREE.MeshStandardMaterial({ color: BLUE, emissive: BLUE, emissiveIntensity: 2, roughness: .3, metalness: .1 });
138
+ const core = new THREE.Mesh(geo, coreMat); mG.add(core);
139
+ const coreLight = new THREE.PointLight(BLUE, 2, 4, 2); mG.add(coreLight);
140
+
141
+ /* the stream */
142
+ const PN = 44;
143
+ const pMesh = new THREE.InstancedMesh(geo, new THREE.MeshBasicMaterial({ color: 0xffffff }), PN);
144
+ pMesh.frustumCulled = false; scene.add(pMesh);
145
+ const parts = Array.from({ length: PN }, () => ({ on: false, t: 0, dur: 1, a: new THREE.Vector3(), c: new THREE.Vector3(), cell: -1, s0: CS }));
146
+ const white = new THREE.Color(.86, .89, .96), hot = new THREE.Color(.5, 1.15, 4.6);
147
+ for (let i = 0; i < PN; i++) pMesh.setColorAt(i, white);
148
+
149
+ v.onResize = () => {
150
+ const aspect = v.w / v.h;
151
+ if (aspect < .9) {
152
+ lat.position.set(0, 1.3, 0); lat.scale.setScalar(.8);
153
+ mG.position.set(0, -1.75, 0); mG.scale.setScalar(.85); v.fit(4.6, 7.4);
154
+ } else if (aspect < 1.6) {
155
+ lat.position.set(-1.5, 0, 0); lat.scale.setScalar(.82);
156
+ mG.position.set(1.75, 0, 0); mG.scale.setScalar(.8); v.fit(7, 3.9);
157
+ } else {
158
+ lat.position.set(-2.25, 0, 0); lat.scale.setScalar(1);
159
+ mG.position.set(2.4, 0, 0); mG.scale.setScalar(1); v.fit(10.4, 4.6);
160
+ }
161
+ v.mY = mG.position.y;
162
+ };
163
+
164
+ const d = new THREE.Object3D(), tmp = new THREE.Vector3(), target = new THREE.Vector3();
165
+ let yaw = 0, pitch = 0, pulse = 0, acc = 0;
166
+
167
+ function launch() {
168
+ const free = [];
169
+ for (let i = 0; i < cells.length; i++) if (cells[i].hT === 0 && cells[i].h < .05) free.push(i);
170
+ const slot = parts.find(p => !p.on);
171
+ if (!free.length || !slot) return;
172
+ const ci = free[(Math.random() * free.length) | 0], c = cells[ci];
173
+ c.hT = 1; c.back = 0;
174
+ slot.on = true; slot.t = 0; slot.dur = 1.5 + Math.random() * 1.1; slot.cell = ci; slot.s0 = CS * lat.scale.x;
175
+ slot.a.copy(c.p).applyMatrix4(latMesh.matrixWorld);
176
+ core.getWorldPosition(target);
177
+ slot.c.lerpVectors(slot.a, target, .5).add(tmp.set(0, (Math.random() - .5) * 2.4, .8 + Math.random() * 1.6));
178
+ }
179
+
180
+ v.tick = (t, dt) => {
181
+ const r = stage.getBoundingClientRect();
182
+ const sp = reduce ? 0 : clamp(-r.top / (r.height + 80));
183
+ yaw += (pointer.x * .32 - yaw) * Math.min(1, dt * 2.5);
184
+ pitch += (pointer.y * .16 - pitch) * Math.min(1, dt * 2.5);
185
+ root.rotation.set(pitch + sp * .18, yaw + sp * .7, 0);
186
+ camera.position.set(0, .25, v.baseZ * (1 - sp * .14)); camera.lookAt(0, 0, 0);
187
+
188
+ lat.rotation.set(.42 + Math.sin(t * .3) * .06, t * .17, 0);
189
+ mG.rotation.y = -.3 + Math.sin(t * .5) * .1;
190
+ mG.position.y = v.mY + Math.sin(t * .9) * .05;
191
+ motes.rotation.y = t * .01;
192
+ root.updateMatrixWorld(true);
193
+
194
+ /* block: grow in from the centre, cubes leave and come back */
195
+ for (let i = 0; i < cells.length; i++) {
196
+ const c = cells[i];
197
+ if (c.back > 0) { c.back -= dt; if (c.back <= 0) c.hT = 0; }
198
+ c.h += (c.hT - c.h) * Math.min(1, dt * 12);
199
+ const intro = easeOut(clamp((t - .1 - c.d * .9) / .7));
200
+ d.position.copy(c.p); d.rotation.set(0, 0, 0);
201
+ d.scale.setScalar(sc(CS * intro * (1 - c.h) * (1 + .035 * Math.sin(t * 1.6 + c.ph))));
202
+ d.updateMatrix(); latMesh.setMatrixAt(i, d.matrix);
203
+ }
204
+ latMesh.instanceMatrix.needsUpdate = true;
205
+
206
+ /* M: cubes drop into place */
207
+ mBase.forEach((b, i) => {
208
+ const k = easeOut(clamp((t - b.delay) / .8));
209
+ d.position.set(b.p.x, b.p.y + (1 - k) * 2.6, b.p.z); d.rotation.set((1 - k) * 1.2, 0, 0);
210
+ d.scale.setScalar(sc(MC * k)); d.updateMatrix(); mMesh.setMatrixAt(i, d.matrix);
211
+ });
212
+ mMesh.instanceMatrix.needsUpdate = true;
213
+ const kc = easeOut(clamp((t - 1.6) / .8));
214
+ core.scale.setScalar(sc(MC * kc * (1 + pulse * .22)));
215
+ coreMat.emissiveIntensity = 7 + pulse * 8;
216
+ coreLight.intensity = (2 + pulse * 9) * kc;
217
+
218
+ /* stream */
219
+ if (!reduce && t > 2.3) { acc += dt * 5.5; while (acc >= 1) { acc--; launch(); } }
220
+ core.getWorldPosition(target);
221
+ for (let i = 0; i < PN; i++) {
222
+ const p = parts[i];
223
+ if (!p.on) { d.position.set(0, -50, 0); d.scale.setScalar(MIN); d.updateMatrix(); pMesh.setMatrixAt(i, d.matrix); continue; }
224
+ p.t += dt / p.dur; const k = clamp(p.t), e = smooth(k), u = 1 - e;
225
+ d.position.set(u * u * p.a.x + 2 * u * e * p.c.x + e * e * target.x, u * u * p.a.y + 2 * u * e * p.c.y + e * e * target.y, u * u * p.a.z + 2 * u * e * p.c.z + e * e * target.z);
226
+ d.rotation.set(e * 3, e * 2, 0);
227
+ d.scale.setScalar(p.s0 * (1 - e * .72));
228
+ d.updateMatrix(); pMesh.setMatrixAt(i, d.matrix);
229
+ pMesh.setColorAt(i, col.copy(white).lerp(hot, easeInOut(e)));
230
+ if (k >= 1) { p.on = false; pulse = 1; cells[p.cell].back = .6 + Math.random() * 1.6; }
231
+ }
232
+ pMesh.instanceMatrix.needsUpdate = true; pMesh.instanceColor.needsUpdate = true;
233
+ pulse = Math.max(0, pulse - dt * 2.4);
234
+ };
235
+ return v;
236
+ }
237
+
238
+ /* ---------------- about: the M assembles on scroll ---------------- */
239
+ function aboutScene() {
240
+ const section = document.getElementById('about'), box = document.getElementById('m3d');
241
+ section.classList.add('has3d'); box.hidden = false;
242
+ const v = makeView(box, { strength: .7, radius: .4, threshold: .96 });
243
+ const { scene, camera } = v;
244
+ const g = new THREE.Group(); scene.add(g);
245
+ dust(scene, small ? 60 : 120, 14);
246
+ const S = 1, C = .82;
247
+ let seed = 3; const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
248
+ const make = (x, y) => {
249
+ const dir = new THREE.Vector3(rnd() - .5, rnd() - .5, rnd() * .6 - .1).normalize();
250
+ return {
251
+ end: new THREE.Vector3((x - 2) * S, (2 - y) * S, 0),
252
+ start: dir.multiplyScalar(4 + rnd() * 3),
253
+ q0: new THREE.Quaternion().setFromEuler(new THREE.Euler(rnd() * 6, rnd() * 6, rnd() * 6)),
254
+ lag: rnd() * .25
255
+ };
256
+ };
257
+ const outer = P.filter(([x, y]) => !(x === 2 && y === 2)).map(([x, y]) => make(x, y));
258
+ const coreB = make(2, 2); coreB.lag = .32;
259
+ const mesh = new THREE.InstancedMesh(geo, new THREE.MeshStandardMaterial({ color: 0xE9EEF8, roughness: .28, metalness: .12 }), outer.length);
260
+ g.add(mesh);
261
+ const coreMat = new THREE.MeshStandardMaterial({ color: BLUE, emissive: BLUE, emissiveIntensity: .5, roughness: .3, metalness: .1 });
262
+ const core = new THREE.Mesh(geo, coreMat); g.add(core);
263
+ const light = new THREE.PointLight(BLUE, 0, 5, 2); g.add(light);
264
+ v.onResize = () => v.fit(7.4, 7.4);
265
+
266
+ const d = new THREE.Object3D(), I = new THREE.Quaternion();
267
+ let yaw = 0, pitch = 0;
268
+ const place = (b, q, obj) => {
269
+ const k = easeInOut(clamp((q - b.lag) / (1 - .32)));
270
+ obj.position.lerpVectors(b.start, b.end, k);
271
+ obj.quaternion.slerpQuaternions(b.q0, I, k);
272
+ obj.scale.setScalar(C * (.55 + .45 * k));
273
+ return k;
274
+ };
275
+ v.tick = (t, dt) => {
276
+ const r = section.getBoundingClientRect();
277
+ const q = reduce ? 1 : clamp((innerHeight * .95 - r.top) / (innerHeight * .8));
278
+ yaw += (pointer.x * .4 - yaw) * Math.min(1, dt * 2.5);
279
+ pitch += (pointer.y * .2 - pitch) * Math.min(1, dt * 2.5);
280
+ g.rotation.set(.1 + pitch, -.35 + Math.sin(t * .4) * .16 + yaw, 0);
281
+ g.position.y = Math.sin(t * .8) * .06;
282
+ camera.position.set(0, .2, v.baseZ); camera.lookAt(0, 0, 0);
283
+ outer.forEach((b, i) => { place(b, q, d); d.updateMatrix(); mesh.setMatrixAt(i, d.matrix); });
284
+ mesh.instanceMatrix.needsUpdate = true;
285
+ const k = place(coreB, q, core);
286
+ coreMat.emissiveIntensity = .6 + 6.8 * k * (1 + .12 * Math.sin(t * 2.2));
287
+ light.intensity = 4 * k;
288
+ };
289
+ return v;
290
+ }
291
+
292
+ /* ---------------- boot ---------------- */
293
+ function start() {
294
+ if (!webglOK()) throw new Error('no webgl');
295
+ const hero = heroScene();
296
+ aboutScene();
297
+ views.forEach(v => v.resize());
298
+ if (window.__stop2D) window.__stop2D();
299
+ if (window.ScrollTrigger) window.ScrollTrigger.refresh();
300
+ let last = performance.now(); const t0 = last;
301
+ const loop = now => {
302
+ const dt = Math.min(.05, (now - last) / 1000); last = now; const t = (now - t0) / 1000;
303
+ if (!document.hidden) for (const v of views) if (v.visible) { v.tick(t, dt); v.composer.render(dt); }
304
+ requestAnimationFrame(loop);
305
+ };
306
+ if (reduce) views.forEach(renderOnce); else requestAnimationFrame(loop);
307
+ requestAnimationFrame(() => hero.renderer.domElement.classList.add('on'));
308
+ }
309
+
310
+ try { start(); }
311
+ catch (e) { if (window.__start2D) window.__start2D(); }