1
+ import * as THREE from "three" ;
2
+ import { scene } from "./scene.ts" ;
3
+
4
+ let gridSpheres : { mesh : THREE . Mesh , dist : number } [ ] = [ ] ;
5
+ let backgroundGridSpheres : { mesh : THREE . Mesh , baseY : number } [ ] = [ ] ;
6
+ let backgroundGridSpheres2D : { mesh : THREE . Mesh , baseY : number } [ ] [ ] = [ ] ;
7
+
8
+ export const initHomePage = ( ) => {
9
+ createWavyGridFloor ( ) ;
10
+ createBackgroundGrid ( ) ;
11
+ animateWaves ( ) ;
12
+ }
13
+
14
+ const createWavyGridFloor = ( ) => {
15
+ const size = 1000 ;
16
+ const divisions = 40 ;
17
+ const step = size / divisions ;
18
+ const halfSize = size / 2 ;
19
+
20
+ const sphereGeometry = new THREE . SphereGeometry ( 4 , 8 , 8 ) ;
21
+ const sphereMaterial = new THREE . MeshBasicMaterial ( { color : 0x3BFFC5 , wireframe : true } ) ;
22
+
23
+ gridSpheres = [ ] ;
24
+
25
+ for ( let i = 0 ; i <= divisions ; i ++ ) {
26
+ for ( let j = 0 ; j <= divisions ; j ++ ) {
27
+ const x = - halfSize + i * step ;
28
+ const z = - halfSize + j * step ;
29
+ const dist = Math . sqrt ( x * x + z * z ) / halfSize ; // normalized [0,1]
30
+ const sphere = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
31
+ sphere . position . set ( x , 0 , z ) ;
32
+ scene . add ( sphere ) ;
33
+ gridSpheres . push ( { mesh : sphere , dist } ) ;
34
+ }
35
+ }
36
+ }
37
+
38
+ const createBackgroundGrid = ( ) => {
39
+ const size = 10000 ;
40
+ const divisions = 50 ;
41
+ const step = size / divisions ;
42
+ const halfSize = size / 2 ;
43
+
44
+ const sphereGeometry = new THREE . SphereGeometry ( 3 , 8 , 8 ) ;
45
+ const sphereMaterial = new THREE . MeshBasicMaterial ( { color : 0xffffff , wireframe : true } ) ;
46
+
47
+ backgroundGridSpheres = [ ] ;
48
+ backgroundGridSpheres2D = [ ] ;
49
+
50
+ // Create spheres and store in 2D array
51
+ for ( let i = 0 ; i <= divisions ; i ++ ) {
52
+ backgroundGridSpheres2D [ i ] = [ ] ;
53
+ for ( let j = 0 ; j <= divisions ; j ++ ) {
54
+ const x = - halfSize + i * step ;
55
+ const z = - halfSize + j * step - 500 ;
56
+ const dist = Math . sqrt ( x * x + z * z ) / halfSize ;
57
+ const amplitude = - 2500 ;
58
+ const baseY = - 2500 - dist * amplitude ;
59
+ const sphere = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
60
+ sphere . position . set ( x , baseY , z ) ;
61
+ scene . add ( sphere ) ;
62
+ const sphereObj = { mesh : sphere , baseY } ;
63
+ backgroundGridSpheres . push ( sphereObj ) ;
64
+ backgroundGridSpheres2D [ i ] [ j ] = sphereObj ;
65
+ }
66
+ }
67
+
68
+ // Link neighbors with lines
69
+ const lineMaterial = new THREE . LineBasicMaterial ( { color : 0xffffff , opacity : 0.3 , transparent : true } ) ;
70
+ for ( let i = 0 ; i <= divisions ; i ++ ) {
71
+ for ( let j = 0 ; j <= divisions ; j ++ ) {
72
+ const current = backgroundGridSpheres2D [ i ] [ j ] . mesh . position ;
73
+ // Link to right neighbor
74
+ if ( i < divisions ) {
75
+ const right = backgroundGridSpheres2D [ i + 1 ] [ j ] . mesh . position ;
76
+ const geometry = new THREE . BufferGeometry ( ) . setFromPoints ( [ current , right ] ) ;
77
+ const line = new THREE . Line ( geometry , lineMaterial ) ;
78
+ scene . add ( line ) ;
79
+ }
80
+ // Link to bottom neighbor
81
+ if ( j < divisions ) {
82
+ const bottom = backgroundGridSpheres2D [ i ] [ j + 1 ] . mesh . position ;
83
+ const geometry = new THREE . BufferGeometry ( ) . setFromPoints ( [ current , bottom ] ) ;
84
+ const line = new THREE . Line ( geometry , lineMaterial ) ;
85
+ scene . add ( line ) ;
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ const animateWaves = ( ) => {
92
+ const time = performance . now ( ) * 0.001 ;
93
+ for ( const { mesh, dist } of gridSpheres ) {
94
+ const { x, z } = mesh . position ;
95
+ const amplitude = 20 + dist * 60 ;
96
+ mesh . position . y = Math . sin ( 0.01 * ( x + z ) + time ) * amplitude - 500 ;
97
+ }
98
+
99
+ requestAnimationFrame ( animateWaves ) ;
100
+ }
0 commit comments