-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetropolitanSquare.html
More file actions
585 lines (516 loc) · 21.8 KB
/
Copy pathMetropolitanSquare.html
File metadata and controls
585 lines (516 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Eco-City 3D Simulation</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background-color: #0f172a;
user-select: none;
}
#canvas-container {
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.glass-panel {
background: rgba(15, 23, 42, 0.65);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.12);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}
.glow-effect {
box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}
</style>
</head>
<body class="text-white">
<div id="canvas-container"></div>
<div class="relative z-10 pointer-events-none p-4 md:p-6 h-screen flex flex-col justify-between">
<header class="flex justify-between items-start">
<div class="glass-panel pointer-events-auto rounded-2xl p-4 flex items-center space-x-3 glow-effect">
<div class="w-10 h-10 rounded-xl bg-emerald-500/20 border border-emerald-500/40 flex items-center justify-center text-emerald-400 text-xl">
<i class="fa-solid fa-city"></i>
</div>
<div>
<h1 class="text-lg font-bold bg-gradient-to-r from-emerald-400 to-teal-200 bg-clip-text text-transparent">NEO-VERDE 3D</h1>
<p class="text-xs text-slate-400">Smart Eco-Metropolis Simulation</p>
</div>
</div>
<div class="glass-panel pointer-events-auto rounded-2xl px-4 py-3 hidden sm:flex items-center space-x-4">
<div class="flex items-center space-x-2 text-xs">
<i class="fa-solid fa-leaf text-emerald-400"></i>
<span class="text-slate-300">AQI: <strong class="text-emerald-400">18 (Optimal)</strong></span>
</div>
<div class="h-4 w-px bg-slate-700"></div>
<div class="flex items-center space-x-2 text-xs">
<i class="fa-solid fa-bolt text-amber-400"></i>
<span class="text-slate-300">Solar Grid: <strong class="text-amber-400">98.4%</strong></span>
</div>
</div>
</header>
<footer class="flex flex-col md:flex-row justify-between items-end gap-4">
<div class="glass-panel pointer-events-auto rounded-2xl p-4 w-full md:w-80 space-y-3">
<div class="flex justify-between items-center border-b border-slate-700/50 pb-2">
<span class="text-xs font-semibold text-slate-400 uppercase tracking-wider">City Telemetry</span>
<span class="flex h-2 w-2 relative">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-emerald-500"></span>
</span>
</div>
<div class="grid grid-cols-2 gap-3 text-xs">
<div class="bg-slate-800/50 p-2.5 rounded-xl border border-slate-700/30">
<p class="text-slate-400">Active Cars</p>
<p id="car-count" class="text-base font-bold text-teal-300">16</p>
</div>
<div class="bg-slate-800/50 p-2.5 rounded-xl border border-slate-700/30">
<p class="text-slate-400">Pedestrians</p>
<p id="ped-count" class="text-base font-bold text-emerald-300">24</p>
</div>
<div class="bg-slate-800/50 p-2.5 rounded-xl border border-slate-700/30">
<p class="text-slate-400">Green Canopy</p>
<p class="text-base font-bold text-green-400">42% Area</p>
</div>
<div class="bg-slate-800/50 p-2.5 rounded-xl border border-slate-700/30">
<p class="text-slate-400">Clean Energy</p>
<p class="text-base font-bold text-amber-300">100%</p>
</div>
</div>
</div>
<div class="glass-panel pointer-events-auto rounded-2xl p-4 w-full md:w-auto flex flex-wrap items-center gap-4">
<button id="time-btn" class="flex items-center space-x-2 bg-emerald-600 hover:bg-emerald-500 transition-colors px-4 py-2.5 rounded-xl font-medium text-xs shadow-lg cursor-pointer">
<i id="time-icon" class="fa-solid fa-moon"></i>
<span id="time-text">Toggle Night Mode</span>
</button>
<div class="flex items-center space-x-3 bg-slate-800/60 px-3 py-2 rounded-xl border border-slate-700/50">
<i class="fa-solid fa-gauge-high text-xs text-slate-400"></i>
<label class="text-xs text-slate-300">Speed</label>
<input type="range" id="speed-slider" min="0.2" max="2.5" step="0.1" value="1" class="w-24 accent-emerald-500 cursor-pointer">
</div>
<button id="reset-cam" class="flex items-center space-x-2 bg-slate-800/80 hover:bg-slate-700 transition-colors px-3 py-2.5 rounded-xl text-xs text-slate-300 border border-slate-700 cursor-pointer">
<i class="fa-solid fa-arrows-to-eye"></i>
<span>Reset Camera</span>
</button>
</div>
</footer>
</div>
<script>
let scene, camera, renderer, controls;
let cars = [], pedestrians = [], trees = [];
let sunLight, ambientLight, hemisphereLight;
let isNight = false;
let speedMultiplier = 1;
const CITY_SIZE = 120;
const ROAD_WIDTH = 12;
function init() {
const container = document.getElementById('canvas-container');
scene = new THREE.Scene();
scene.background = new THREE.Color(0xa0c4ff);
scene.fog = new THREE.FogExp2(0xa0c4ff, 0.007);
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(70, 50, 70);
renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
container.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.maxPolarAngle = Math.PI / 2 - 0.05;
controls.minDistance = 15;
controls.maxDistance = 180;
controls.target.set(0, 0, 0);
setupLighting();
buildGroundAndRoads();
buildCentralPark();
buildBuildings();
spawnVehicles();
spawnPedestrians();
window.addEventListener('resize', onWindowResize);
setupUIEventListeners();
animate();
}
function setupLighting() {
ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);
hemisphereLight = new THREE.HemisphereLight(0xffffff, 0x3d5a80, 0.5);
scene.add(hemisphereLight);
sunLight = new THREE.DirectionalLight(0xfffaed, 1.2);
sunLight.position.set(60, 90, 40);
sunLight.castShadow = true;
sunLight.shadow.mapSize.width = 2048;
sunLight.shadow.mapSize.height = 2048;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 250;
const d = 80;
sunLight.shadow.camera.left = -d;
sunLight.shadow.camera.right = d;
sunLight.shadow.camera.top = d;
sunLight.shadow.camera.bottom = -d;
sunLight.shadow.bias = -0.0005;
scene.add(sunLight);
}
function buildGroundAndRoads() {
const groundGeo = new THREE.PlaneGeometry(CITY_SIZE, CITY_SIZE);
const groundMat = new THREE.MeshStandardMaterial({ color: 0x38b000, roughness: 0.9 });
const ground = new THREE.Mesh(groundGeo, groundMat);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const roadMat = new THREE.MeshStandardMaterial({ color: 0x22222e, roughness: 0.6 });
const stripeMat = new THREE.MeshBasicMaterial({ color: 0xffe600 });
// Horizontal Road
const roadH = new THREE.Mesh(new THREE.PlaneGeometry(CITY_SIZE, ROAD_WIDTH), roadMat);
roadH.rotation.x = -Math.PI / 2;
roadH.position.y = 0.02;
roadH.receiveShadow = true;
scene.add(roadH);
const roadV = new THREE.Mesh(new THREE.PlaneGeometry(ROAD_WIDTH, CITY_SIZE), roadMat);
roadV.rotation.x = -Math.PI / 2;
roadV.position.y = 0.02;
roadV.receiveShadow = true;
scene.add(roadV);
// Yellow Center Lines
for (let i = -CITY_SIZE / 2 + 5; i < CITY_SIZE / 2; i += 8) {
if (Math.abs(i) < ROAD_WIDTH) continue;
const stripeH = new THREE.Mesh(new THREE.PlaneGeometry(3, 0.4), stripeMat);
stripeH.rotation.x = -Math.PI / 2;
stripeH.position.set(i, 0.03, 0);
scene.add(stripeH);
const stripeV = new THREE.Mesh(new THREE.PlaneGeometry(0.4, 3), stripeMat);
stripeV.rotation.x = -Math.PI / 2;
stripeV.position.set(0, 0.03, i);
scene.add(stripeV);
}
const sidewalkMat = new THREE.MeshStandardMaterial({ color: 0x94a3b8, roughness: 0.7 });
const size = (CITY_SIZE - ROAD_WIDTH) / 2 - 2;
[-1, 1].forEach(xSign => {
[-1, 1].forEach(zSign => {
const sidewalkTile = new THREE.Mesh(
new THREE.BoxGeometry(size, 0.15, size),
sidewalkMat
);
sidewalkTile.position.set(
xSign * (size / 2 + ROAD_WIDTH / 2 + 1),
0.07,
zSign * (size / 2 + ROAD_WIDTH / 2 + 1)
);
sidewalkTile.receiveShadow = true;
scene.add(sidewalkTile);
});
});
}
function buildCentralPark() {
const parkX = 28, parkZ = -28;
const parkLawn = new THREE.Mesh(
new THREE.BoxGeometry(32, 0.2, 32),
new THREE.MeshStandardMaterial({ color: 0x2dc653, roughness: 0.8 })
);
parkLawn.position.set(parkX, 0.1, parkZ);
parkLawn.receiveShadow = true;
scene.add(parkLawn);
const pond = new THREE.Mesh(
new THREE.CylinderGeometry(6, 6, 0.15, 16),
new THREE.MeshPhysicalMaterial({
color: 0x00b4d8,
roughness: 0.1,
transmission: 0.8,
opacity: 0.9,
transparent: true
})
);
pond.position.set(parkX, 0.2, parkZ);
scene.add(pond);
const treePositions = [
[parkX + 8, parkZ + 8], [parkX - 8, parkZ + 8],
[parkX + 9, parkZ - 9], [parkX - 10, parkZ - 7],
[parkX + 4, parkZ - 10], [parkX - 5, parkZ + 11],
[-10, 8], [-10, 20], [-10, 32], [-10, -20], [-10, -35],
[10, 10], [10, 35], [10, -12], [10, -32],
[-20, 10], [-35, 10], [20, 10], [35, 10]
];
treePositions.forEach(([x, z]) => createTree(x, z));
}
function createTree(x, z) {
const treeGroup = new THREE.Group();
const trunkMat = new THREE.MeshStandardMaterial({ color: 0x5c3d2e, roughness: 0.9 });
const trunk = new THREE.Mesh(new THREE.CylinderGeometry(0.3, 0.5, 2.5, 6), trunkMat);
trunk.position.y = 1.25;
trunk.castShadow = true;
trunk.receiveShadow = true;
treeGroup.add(trunk);
const foliageColors = [0x10b981, 0x059669, 0x34d399, 0x047857];
const foliageMat = new THREE.MeshStandardMaterial({
color: foliageColors[Math.floor(Math.random() * foliageColors.length)],
roughness: 0.6
});
for (let i = 0; i < 3; i++) {
const foliage = new THREE.Mesh(
new THREE.ConeGeometry(2 - i * 0.4, 2, 7),
foliageMat
);
foliage.position.y = 2.5 + i * 1.1;
foliage.castShadow = true;
treeGroup.add(foliage);
}
treeGroup.position.set(x, 0, z);
const scale = 0.8 + Math.random() * 0.5;
treeGroup.scale.set(scale, scale, scale);
scene.add(treeGroup);
trees.push(treeGroup);
}
function buildBuildings() {
const buildingSpecs = [
{ x: -28, z: -28, w: 18, h: 35, d: 18, color: 0x3b82f6, greenRoof: true },
{ x: -28, z: -10, w: 14, h: 22, d: 12, color: 0x06b6d4, greenRoof: true },
{ x: -10, z: -28, w: 12, h: 28, d: 14, color: 0x6366f1, greenRoof: false },
{ x: -28, z: 28, w: 20, h: 42, d: 18, color: 0x0284c7, greenRoof: true },
{ x: -10, z: 28, w: 12, h: 18, d: 14, color: 0x14b8a6, greenRoof: true },
{ x: -28, z: 10, w: 14, h: 26, d: 12, color: 0x38bdf8, greenRoof: false },
{ x: 28, z: 28, w: 22, h: 38, d: 20, color: 0x0f766e, greenRoof: true },
{ x: 10, z: 28, w: 12, h: 24, d: 14, color: 0x0369a1, greenRoof: true },
{ x: 28, z: 10, w: 16, h: 30, d: 12, color: 0x4f46e5, greenRoof: false }
];
buildingSpecs.forEach(spec => createModernBuilding(spec));
}
function createModernBuilding(spec) {
const bGroup = new THREE.Group();
const glassMat = new THREE.MeshPhysicalMaterial({
color: spec.color,
metalness: 0.8,
roughness: 0.2,
clearcoat: 1.0,
clearcoatRoughness: 0.1,
transparent: true,
opacity: 0.9
});
const body = new THREE.Mesh(new THREE.BoxGeometry(spec.w, spec.h, spec.d), glassMat);
body.position.y = spec.h / 2 + 0.2;
body.castShadow = true;
body.receiveShadow = true;
bGroup.add(body);
const windowMat = new THREE.MeshStandardMaterial({
color: 0xe0f2fe,
emissive: 0x38bdf8,
emissiveIntensity: 0.2,
roughness: 0.3
});
const floorCount = Math.floor(spec.h / 3);
for (let f = 1; f < floorCount; f++) {
const band = new THREE.Mesh(
new THREE.BoxGeometry(spec.w + 0.2, 0.3, spec.d + 0.2),
windowMat
);
band.position.y = f * 3;
bGroup.add(band);
}
if (spec.greenRoof) {
const garden = new THREE.Mesh(
new THREE.BoxGeometry(spec.w - 1, 0.4, spec.d - 1),
new THREE.MeshStandardMaterial({ color: 0x10b981, roughness: 0.8 })
);
garden.position.y = spec.h + 0.4;
bGroup.add(garden);
for (let i = 0; i < 4; i++) {
const bush = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.8 + Math.random() * 0.4),
new THREE.MeshStandardMaterial({ color: 0x059669, roughness: 0.7 })
);
bush.position.set(
(Math.random() - 0.5) * (spec.w - 3),
spec.h + 1.2,
(Math.random() - 0.5) * (spec.d - 3)
);
bGroup.add(bush);
}
}
bGroup.position.set(spec.x, 0, spec.z);
scene.add(bGroup);
}
function spawnVehicles() {
const carColors = [0xef4444, 0x3b82f6, 0x10b981, 0xf59e0b, 0x8b5cf6, 0xec4899, 0xf97316];
const count = 16;
for (let i = 0; i < count; i++) {
const isHorizontal = i % 2 === 0;
const laneOffset = (Math.random() > 0.5 ? 1 : -1) * 2.8;
const car = createCarMesh(carColors[i % carColors.length]);
car.userData = {
isHorizontal,
laneOffset,
speed: 0.2 + Math.random() * 0.15,
dir: Math.random() > 0.5 ? 1 : -1,
pos: (Math.random() - 0.5) * CITY_SIZE
};
scene.add(car);
cars.push(car);
}
}
function createCarMesh(colorHex) {
const carGroup = new THREE.Group();
// Chassis
const bodyMat = new THREE.MeshStandardMaterial({ color: colorHex, roughness: 0.3, metalness: 0.7 });
const body = new THREE.Mesh(new THREE.BoxGeometry(3.2, 1.0, 1.6), bodyMat);
body.position.y = 0.7;
body.castShadow = true;
carGroup.add(body);
const cabinMat = new THREE.MeshPhysicalMaterial({ color: 0x1e293b, roughness: 0.1, transmission: 0.6 });
const cabin = new THREE.Mesh(new THREE.BoxGeometry(1.8, 0.7, 1.4), cabinMat);
cabin.position.set(-0.2, 1.45, 0);
cabin.castShadow = true;
carGroup.add(cabin);
const wheelGeo = new THREE.CylinderGeometry(0.35, 0.35, 0.3, 12);
const wheelMat = new THREE.MeshStandardMaterial({ color: 0x0f172a, roughness: 0.9 });
[[0.9, 0.35, 0.8], [0.9, 0.35, -0.8], [-0.9, 0.35, 0.8], [-0.9, 0.35, -0.8]].forEach(([wx, wy, wz]) => {
const wheel = new THREE.Mesh(wheelGeo, wheelMat);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(wx, wy, wz);
carGroup.add(wheel);
});
const headlightMat = new THREE.MeshBasicMaterial({ color: 0xffffaa });
const hlLeft = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.2, 0.3), headlightMat);
hlLeft.position.set(1.61, 0.7, 0.5);
const hlRight = hlLeft.clone();
hlRight.position.set(1.61, 0.7, -0.5);
carGroup.add(hlLeft, hlRight);
return carGroup;
}
function spawnPedestrians() {
const count = 24;
const colors = [0x38bdf8, 0xf43f5e, 0xa855f7, 0x22c55e, 0xeab308, 0xf97316];
for (let i = 0; i < count; i++) {
const ped = createPedestrianMesh(colors[i % colors.length]);
ped.userData = {
axis: i % 2 === 0 ? 'X' : 'Z',
side: Math.random() > 0.5 ? 7.5 : -7.5,
speed: 0.05 + Math.random() * 0.04,
dir: Math.random() > 0.5 ? 1 : -1,
pos: (Math.random() - 0.5) * (CITY_SIZE - 20),
animOffset: Math.random() * Math.PI * 2
};
scene.add(ped);
pedestrians.push(ped);
}
}
function createPedestrianMesh(shirtColor) {
const pedGroup = new THREE.Group();
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 8, 8),
new THREE.MeshStandardMaterial({ color: 0xffdbac, roughness: 0.6 })
);
head.position.y = 1.4;
head.castShadow = true;
pedGroup.add(head);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.2, 0.6, 8),
new THREE.MeshStandardMaterial({ color: shirtColor, roughness: 0.5 })
);
torso.position.y = 0.9;
torso.castShadow = true;
pedGroup.add(torso);
const legMat = new THREE.MeshStandardMaterial({ color: 0x1e293b });
const leftLeg = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.6, 0.12), legMat);
leftLeg.position.set(-0.1, 0.3, 0);
const rightLeg = leftLeg.clone();
rightLeg.position.set(0.1, 0.3, 0);
pedGroup.add(leftLeg, rightLeg);
pedGroup.userData.leftLeg = leftLeg;
pedGroup.userData.rightLeg = rightLeg;
return pedGroup;
}
function animate(time = 0) {
requestAnimationFrame(animate);
cars.forEach(car => {
const u = car.userData;
u.pos += u.speed * u.dir * speedMultiplier;
const limit = CITY_SIZE / 2 + 5;
if (u.pos > limit) u.pos = -limit;
if (u.pos < -limit) u.pos = limit;
if (u.isHorizontal) {
car.position.set(u.pos, 0, u.laneOffset);
car.rotation.y = u.dir === 1 ? 0 : Math.PI;
} else {
car.position.set(u.laneOffset, 0, u.pos);
car.rotation.y = u.dir === 1 ? Math.PI / 2 : -Math.PI / 2;
}
});
pedestrians.forEach(ped => {
const u = ped.userData;
u.pos += u.speed * u.dir * speedMultiplier;
const limit = CITY_SIZE / 2 - 5;
if (u.pos > limit) u.pos = -limit;
if (u.pos < -limit) u.pos = limit;
if (u.axis === 'X') {
ped.position.set(u.pos, 0, u.side);
ped.rotation.y = u.dir === 1 ? Math.PI / 2 : -Math.PI / 2;
} else {
ped.position.set(u.side, 0, u.pos);
ped.rotation.y = u.dir === 1 ? 0 : Math.PI;
}
const swing = Math.sin(time * 0.01 * speedMultiplier + u.animOffset) * 0.4;
if (ped.userData.leftLeg) ped.userData.leftLeg.rotation.x = swing;
if (ped.userData.rightLeg) ped.userData.rightLeg.rotation.x = -swing;
});
controls.update();
renderer.render(scene, camera);
}
function setupUIEventListeners() {
const timeBtn = document.getElementById('time-btn');
const timeIcon = document.getElementById('time-icon');
const timeText = document.getElementById('time-text');
timeBtn.addEventListener('click', () => {
isNight = !isNight;
if (isNight) {
scene.background.setHex(0x0a0f1d);
scene.fog.color.setHex(0x0a0f1d);
sunLight.intensity = 0.05;
ambientLight.intensity = 0.15;
hemisphereLight.intensity = 0.1;
timeIcon.className = "fa-solid fa-sun";
timeText.textContent = "Toggle Day Mode";
timeBtn.classList.replace("bg-emerald-600", "bg-indigo-600");
timeBtn.classList.replace("hover:bg-emerald-500", "hover:bg-indigo-500");
} else {
scene.background.setHex(0xa0c4ff);
scene.fog.color.setHex(0xa0c4ff);
sunLight.intensity = 1.2;
ambientLight.intensity = 0.4;
hemisphereLight.intensity = 0.5;
timeIcon.className = "fa-solid fa-moon";
timeText.textContent = "Toggle Night Mode";
timeBtn.classList.replace("bg-indigo-600", "bg-emerald-600");
timeBtn.classList.replace("hover:bg-indigo-500", "hover:bg-emerald-500");
}
});
document.getElementById('speed-slider').addEventListener('input', (e) => {
speedMultiplier = parseFloat(e.target.value);
});
document.getElementById('reset-cam').addEventListener('click', () => {
camera.position.set(70, 50, 70);
controls.target.set(0, 0, 0);
});
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>