-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive_world_builder.html
1464 lines (1286 loc) · 53.7 KB
/
interactive_world_builder.html
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html><head><base href="interactiverealtimegameworldbuilder.com">
<title>Interactive Realtime Game World Builder Pro</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
body {
margin: 0;
background: #1a1a1a;
color: #fff;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
overflow: hidden;
position: relative;
}
#canvas-container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#toolbar {
display: grid;
grid-template-columns: repeat(15, 1fr);
gap: 4px;
background: rgba(0, 0, 0, 0.85);
border-bottom: 2px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 10px rgba(0,0,0,0.5);
padding: 12px;
width: fit-content;
margin: 0 auto;
height: 80px;
position: relative;
z-index: 1000;
}
.tool-btn {
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px;
font-size: 12px;
min-width: 35px;
min-height: 35px;
text-shadow: 0 1px 2px rgba(0,0,0,0.5);
margin: 3px;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
font-weight: 500;
display: flex;
align-items: center;
justify-content: center;
border: none;
}
.tool-btn:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.tool-btn:active {
transform: scale(0.95);
box-shadow: inset 0 2px 5px rgba(0,0,0,0.2);
}
.active-tool {
background: rgba(255, 255, 255, 0.25);
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
70% { box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}
.tool-btn::after {
content: attr(data-tooltip);
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
padding: 6px 10px;
background: rgba(0, 0, 0, 0.95);
border-radius: 4px;
font-size: 12px;
white-space: nowrap;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
z-index: 9999;
color: white;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
margin-top: 8px;
pointer-events: none;
}
.tool-btn:hover::after {
opacity: 1;
visibility: visible;
transform: translateX(-50%) translateY(0);
z-index: 2000;
}
#loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(45deg, #1a1a1a, #2a1a2a);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.loader {
position: relative;
width: 100px;
height: 100px;
border: 5px solid #f3f3f3;
border-top: 5px solid #4CAF50;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loader::after {
content: 'Loading...';
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
color: white;
font-size: 14px;
letter-spacing: 2px;
}
.settings-panel {
position: fixed;
bottom: 20px;
left: 20px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
padding: 15px;
border-radius: 10px;
z-index: 100;
transition: transform 0.3s ease-out;
transform-origin: top right;
min-width: 250px;
}
.settings-panel.collapsed {
transform: scale(0);
}
.settings-content {
transition: max-height 0.3s ease-out;
max-height: 70vh;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,0.3) transparent;
padding: 0 10px;
}
.settings-content::-webkit-scrollbar {
width: 8px;
}
.settings-content::-webkit-scrollbar-track {
background: transparent;
}
.settings-content::-webkit-scrollbar-thumb {
background-color: rgba(255,255,255,0.3);
border-radius: 4px;
}
.settings-section {
border-bottom: 1px solid rgba(255,255,255,0.1);
padding: 10px 0;
margin: 5px 0;
}
.settings-section h4 {
color: #fff;
margin: 5px 0;
font-size: 14px;
}
.radio-group {
display: flex;
flex-direction: column;
gap: 5px;
margin: 10px 0;
}
.slider-container {
margin: 10px 0;
}
.slider {
-webkit-appearance: none;
height: 4px;
background: rgba(255, 255, 255, 0.2);
border-radius: 2px;
cursor: pointer;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
cursor: pointer;
transition: all 0.3s ease;
}
.slider::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
.color-picker {
margin: 5px 0;
}
#minimap {
position: fixed;
bottom: 20px;
right: 20px;
width: 200px;
height: 200px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 2px solid rgba(255, 255, 255, 0.1);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
border-radius: 10px;
z-index: 100;
transition: all 0.3s ease;
}
#minimap:hover {
transform: scale(1.05);
}
.background-stars {
display: none;
}
.star {
position: absolute;
background: white;
border-radius: 50%;
animation: twinkle 1s infinite alternate;
}
@keyframes twinkle {
0% { opacity: 0.2; }
100% { opacity: 1; }
}
.settings-header label {
font-size: 14px;
color: rgba(255, 255, 255, 0.8);
margin-bottom: 5px;
display: block;
}
#escape-hint {
display: none;
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 10px 20px;
border-radius: 20px;
font-size: 14px;
color: white;
z-index: 1000;
}
.slider-container label {
font-size: 12px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
}
.color-settings {
margin-top: 15px;
}
.checkbox-container {
margin: 8px 0;
color: rgba(255, 255, 255, 0.8);
}
.radio-container {
margin: 8px 0;
color: rgba(255, 255, 255, 0.8);
}
.radio-container label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.radio-container input[type="radio"] {
cursor: pointer;
}
</style>
<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/exporters/FBXExporter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
</head>
<body>
<div id="loading-screen">
<div class="loader"></div>
</div>
<div id="escape-hint">Press ESC to return to build mode</div>
<div id="toolbar">
<button class="tool-btn" id="add-terrain" data-tooltip="Create terrain features"><i class="fas fa-mountain"></i></button>
<button class="tool-btn" id="add-water" data-tooltip="Add water bodies"><i class="fas fa-water"></i></button>
<button class="tool-btn" id="add-vegetation" data-tooltip="Place trees and plants"><i class="fas fa-tree"></i></button>
<button class="tool-btn" id="add-rocks" data-tooltip="Add rock formations"><i class="fas fa-dice-d20"></i></button>
<button class="tool-btn" id="add-path" data-tooltip="Create pathways"><i class="fas fa-road"></i></button>
<button class="tool-btn" id="add-structure" data-tooltip="Build structures"><i class="fas fa-home"></i></button>
<button class="tool-btn" id="add-light" data-tooltip="Place light sources"><i class="fas fa-lightbulb"></i></button>
<button class="tool-btn" id="add-portal" data-tooltip="Create portals"><i class="fas fa-portal-enter"></i></button>
<button class="tool-btn" id="add-bridge" data-tooltip="Build bridges"><i class="fas fa-archway"></i></button>
<button class="tool-btn" id="add-wall" data-tooltip="Add walls"><i class="fas fa-wall"></i></button>
<button class="tool-btn" id="add-moving" data-tooltip="Add moving object"><i class="fas fa-cube"></i></button>
<button class="tool-btn" id="add-ramp" data-tooltip="Add a ramp"><i class="fas fa-angle-up"></i></button>
<button class="tool-btn" id="play-mode" data-tooltip="Test your world"><i class="fas fa-play"></i></button>
<button class="tool-btn" id="save-world" data-tooltip="Export your creation"><i class="fas fa-save"></i></button>
<button class="tool-btn" id="settings" data-tooltip="Settings"><i class="fas fa-cog"></i></button>
<button class="tool-btn" id="randomize-world" data-tooltip="Generate Random World"><i class="fas fa-dice"></i></button>
</div>
<div class="settings-panel">
<div class="settings-header">
<h3>Settings</h3>
<span>▼</span>
</div>
<div class="settings-content">
<div class="settings-section">
<h4>Game Mode</h4>
<div class="radio-group">
<label>
<input type="radio" name="camera-mode" value="first-person" checked>
First Person
</label>
<label>
<input type="radio" name="camera-mode" value="third-person">
Third Person
</label>
<label>
<input type="radio" name="camera-mode" value="overhead">
Overhead
</label>
<label>
<input type="radio" name="camera-mode" value="karting">
Karting Mode
</label>
</div>
</div>
<div class="settings-section">
<h4>Physics & Gameplay</h4>
<div class="checkbox-container">
<label>
<input type="checkbox" id="enable-collisions" checked>
Enable Collisions
</label>
</div>
<div class="slider-container">
<label>Player Speed</label>
<input type="range" class="slider" id="player-speed" min="0.1" max="1" value="0.2" step="0.1">
</div>
<div class="slider-container">
<label>Jump Height</label>
<input type="range" class="slider" id="jump-height" min="0.2" max="0.5" value="0.35" step="0.05">
</div>
<div class="slider-container">
<label>Gravity Strength</label>
<input type="range" class="slider" id="gravity-strength" min="0.01" max="0.05" value="0.02" step="0.01">
</div>
</div>
<div class="settings-section">
<h4>World Settings</h4>
<div class="slider-container">
<label>World Size</label>
<input type="range" class="slider" id="world-size" min="50" max="200" value="100" step="10">
</div>
<div class="slider-container">
<label>Day/Night Cycle Speed</label>
<input type="range" class="slider" id="day-night-speed" min="0" max="0.01" value="0.001" step="0.001">
</div>
<div class="slider-container">
<label>Particle Density</label>
<input type="range" class="slider" id="particle-density" min="0" max="100" value="50">
</div>
<div class="checkbox-container">
<label>
<input type="checkbox" id="enable-day-night">
Enable Day/Night Cycle
</label>
</div>
</div>
<div class="settings-section">
<h4>Terrain Settings</h4>
<div class="slider-container">
<label>Terrain Height</label>
<input type="range" class="slider" id="terrain-height" min="1" max="20" value="10">
</div>
<div class="slider-container">
<label>Water Level</label>
<input type="range" class="slider" id="water-level" min="0" max="20" value="5">
</div>
<div class="color-settings">
<label>Terrain Color</label>
<input type="color" id="terrain-color" value="#808080">
</div>
</div>
<div class="settings-section">
<h4>Object Colors</h4>
<div class="color-settings">
<label>Rock Color</label>
<input type="color" id="rock-color" value="#808080">
</div>
<div class="color-settings">
<label>Vegetation Color</label>
<input type="color" id="vegetation-color" value="#228B22">
</div>
<div class="color-settings">
<label>Structure Color</label>
<input type="color" id="structure-color" value="#8B4513">
</div>
</div>
<div class="settings-section">
<h4>Visual Settings</h4>
<div class="checkbox-container">
<label>
<input type="checkbox" id="shadows-enabled" checked>
Enable Shadows
</label>
</div>
<div class="checkbox-container">
<label>
<input type="checkbox" id="wireframe-mode">
Wireframe Mode
</label>
</div>
<div class="slider-container">
<label>Ambient Light</label>
<input type="range" class="slider" id="ambient-light" min="0" max="2" value="1" step="0.1">
</div>
<div class="slider-container">
<label>Fog Density</label>
<input type="range" class="slider" id="fog-density" min="0" max="0.1" value="0.015" step="0.001">
</div>
</div>
</div>
</div>
<div id="minimap"></div>
<div id="canvas-container"></div>
<script>
class Kart extends THREE.Group {
constructor() {
super();
const bodyGeom = new THREE.BoxGeometry(2, 0.75, 3);
const bodyMat = new THREE.MeshPhongMaterial({color: 0xff0000});
this.body = new THREE.Mesh(bodyGeom, bodyMat);
this.add(this.body);
const wheelGeom = new THREE.CylinderGeometry(0.4, 0.4, 0.3, 16);
const wheelMat = new THREE.MeshPhongMaterial({color: 0x333333});
this.wheels = [];
const wheelPositions = [
[-0.8, -0.3, 1],
[0.8, -0.3, 1],
[-0.8, -0.3, -1],
[0.8, -0.3, -1]
];
wheelPositions.forEach(pos => {
const wheel = new THREE.Mesh(wheelGeom, wheelMat);
wheel.position.set(...pos);
wheel.rotation.z = Math.PI / 2;
this.add(wheel);
this.wheels.push(wheel);
});
const seatGeom = new THREE.BoxGeometry(1.5, 0.4, 1);
const seatMat = new THREE.MeshPhongMaterial({color: 0x666666});
this.seat = new THREE.Mesh(seatGeom, seatMat);
this.seat.position.y = 0.4;
this.add(this.seat);
this.velocity = new THREE.Vector3();
this.speed = 0;
this.steering = 0;
this.maxSpeed = 0.5;
this.acceleration = 0.01;
this.deceleration = 0.005;
this.steeringSpeed = 0.05;
this.maxSteering = Math.PI / 4;
}
update() {
if (keysPressed['w']) {
this.speed = Math.min(this.speed + this.acceleration, this.maxSpeed);
} else if (keysPressed['s']) {
this.speed = Math.max(this.speed - this.acceleration, -this.maxSpeed / 2);
} else {
this.speed *= (1 - this.deceleration);
}
if (keysPressed['a']) {
this.steering = Math.min(this.steering + this.steeringSpeed, this.maxSteering);
} else if (keysPressed['d']) {
this.steering = Math.max(this.steering - this.steeringSpeed, -this.maxSteering);
} else {
this.steering *= 0.9;
}
this.rotation.y += this.steering * this.speed;
const movement = new THREE.Vector3(0, 0, -this.speed);
movement.applyAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
this.position.add(movement);
this.wheels.forEach(wheel => {
wheel.rotation.x += this.speed * 0.5;
});
}
}
class Character extends THREE.Group {
constructor() {
super();
const bodyGeom = new THREE.BoxGeometry(0.5, 1, 0.5);
const headGeom = new THREE.SphereGeometry(0.5, 8, 8);
const bodyMat = new THREE.MeshPhongMaterial({color: 0x00ff00});
this.body = new THREE.Mesh(bodyGeom, bodyMat);
this.head = new THREE.Mesh(headGeom, bodyMat);
this.head.position.y = 0.75;
this.add(this.body);
this.add(this.head);
this.velocity = new THREE.Vector3();
this.isGrounded = false;
this.isCrouching = false;
this.canShoot = true;
this.shootCooldown = 20;
}
shoot() {
if (!this.canShoot) return;
const bulletGeom = new THREE.SphereGeometry(0.2);
const bulletMat = new THREE.MeshPhongMaterial({color: 0xff0000});
const bullet = new THREE.Mesh(bulletGeom, bulletMat);
const direction = new THREE.Vector3();
camera.getWorldDirection(direction);
bullet.position.copy(this.position);
bullet.position.y += 1.5;
bullet.userData.velocity = direction.multiplyScalar(0.5);
bullet.userData.isProjectile = true;
scene.add(bullet);
if (!window.projectiles) window.projectiles = [];
window.projectiles.push(bullet);
this.canShoot = false;
setTimeout(() => this.canShoot = true, this.shootCooldown);
}
jump() {
if (this.isGrounded) {
this.velocity.y = 0.35;
this.isGrounded = false;
}
}
crouch() {
if (!this.isCrouching) {
this.scale.y = 0.5;
this.position.y -= 0.5;
this.isCrouching = true;
}
}
uncrouch() {
if (this.isCrouching) {
this.scale.y = 1;
this.position.y += 0.5;
this.isCrouching = false;
}
}
}
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.getElementById('canvas-container').appendChild(renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(50, 50, 50);
dirLight.castShadow = true;
scene.add(dirLight);
dirLight.shadow.mapSize.width = 2048;
dirLight.shadow.mapSize.height = 2048;
dirLight.shadow.camera.near = 0.5;
dirLight.shadow.camera.far = 500;
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
camera.position.set(0, 30, 50);
camera.lookAt(scene.position);
scene.fog = new THREE.FogExp2(0x000000, 0.015);
const floorGeometry = new THREE.PlaneGeometry(100, 100);
const floorMaterial = new THREE.MeshPhongMaterial({ color: 0x404040 });
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
window.activeTerrain = null;
let currentCameraMode = 'first-person';
let dayNightCycle = null;
function updateCameraPosition() {
if (!player || !isPlayMode) return;
switch(currentCameraMode) {
case 'first-person':
camera.position.copy(player.position);
camera.position.y += 1.6;
break;
case 'third-person':
camera.position.copy(player.position);
camera.position.y += 3;
camera.position.z += 5;
camera.lookAt(player.position);
break;
case 'overhead':
camera.position.copy(player.position);
camera.position.y = 20;
camera.lookAt(player.position);
break;
case 'karting':
if (player instanceof Kart) {
const offset = new THREE.Vector3(0, 3, 8);
camera.position.copy(player.position).add(offset);
camera.lookAt(player.position);
}
break;
}
}
function addRampAt(point) {
const rampGeometry = new THREE.BufferGeometry();
const vertices = new Float32Array([
-4, 0, 2,
4, 0, 2,
-4, 0, -2,
4, 0, -2,
0, 4, 0
]);
const indices = new Uint16Array([
0, 1, 4,
2, 3, 4,
0, 2, 4,
1, 3, 4,
0, 1, 2,
1, 2, 3
]);
rampGeometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
rampGeometry.setIndex(new THREE.BufferAttribute(indices, 1));
rampGeometry.computeVertexNormals();
const rampMaterial = new THREE.MeshPhongMaterial({
color: 0x808080,
shininess: 30,
specular: 0x404040
});
const ramp = new THREE.Mesh(rampGeometry, rampMaterial);
ramp.castShadow = true;
ramp.receiveShadow = true;
ramp.position.copy(point);
ramp.position.y += 0.1;
ramp.userData.isRamp = true;
scene.add(ramp);
const collisionBox = new THREE.Box3().setFromObject(ramp);
if (!window.collisionObjects) window.collisionObjects = [];
window.collisionObjects.push({
mesh: ramp,
box: collisionBox,
type: 'ramp'
});
}
let player = null;
let isPlayMode = false;
const keysPressed = {};
let moveSpeed = 0.2;
document.addEventListener('keydown', (e) => {
keysPressed[e.key.toLowerCase()] = true;
if(e.key === 'Escape' && isPlayMode) {
isPlayMode = false;
document.getElementById('toolbar').style.display = 'block';
document.querySelector('.settings-panel').style.display = 'block';
camera.position.set(0, 30, 50);
camera.lookAt(scene.position);
}
});
document.addEventListener('keyup', (e) => {
keysPressed[e.key.toLowerCase()] = false;
});
function updatePlayer() {
if(!player || !isPlayMode) return;
if(keysPressed['w']) {
player.position.z -= moveSpeed;
}
if(keysPressed['s']) {
player.position.z += moveSpeed;
}
if(keysPressed['a']) {
player.position.x -= moveSpeed;
}
if(keysPressed['d']) {
player.position.x += moveSpeed;
}
if(keysPressed[' ']) {
player.jump();
}
updateCameraPosition();
}
document.getElementById('play-mode').addEventListener('click', () => {
isPlayMode = !isPlayMode;
if(isPlayMode) {
if(!player) createPlayer();
document.getElementById('toolbar').style.display = 'none';
document.querySelector('.settings-panel').style.display = 'none';
document.getElementById('escape-hint').style.display = 'block';
updateCameraPosition();
setTimeout(() => {
document.getElementById('escape-hint').style.opacity = '0';
setTimeout(() => {
document.getElementById('escape-hint').style.display = 'none';
document.getElementById('escape-hint').style.opacity = '1';
}, 500);
}, 3000);
} else {
document.getElementById('toolbar').style.display = 'block';
document.querySelector('.settings-panel').style.display = 'block';
document.getElementById('escape-hint').style.display = 'none';
camera.position.set(0, 30, 50);
camera.lookAt(scene.position);
}
});
const toolButtons = document.querySelectorAll('.tool-btn');
let activeTool = null;
toolButtons.forEach(btn => {
btn.addEventListener('click', (e) => {
if(activeTool) activeTool.classList.remove('active-tool');
activeTool = e.target;
activeTool.classList.add('active-tool');
if (activeTool.id === 'add-light') {
// Function to add light
} else if (activeTool.id === 'add-portal') {
// Function to add portal
} else if (activeTool.id === 'add-bridge') {
// Function to add bridge
} else if (activeTool.id === 'add-ramp') {
addRampAt(/* point */); // Implement ramp placement
}
});
});
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
renderer.domElement.addEventListener('mousemove', (e) => {
mouse.x = (e.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
});
renderer.domElement.addEventListener('click', (e) => {
if(!activeTool) return;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(scene.children);
if(intersects.length > 0) {
const point = intersects[0].point;
switch(activeTool.id) {
case 'add-terrain':
addTerrainAt(point);
break;
case 'add-vegetation':
addVegetationAt(point);
break;
case 'add-rocks':
addRockAt(point);
break;
case 'add-structure':
addStructureAt(point);
break;
case 'add-light':
addLightAt(point);
break;
case 'add-portal':
addPortalAt(point);
break;
case 'add-bridge':
addBridgeAt(point);
break;
case 'add-wall':
addWallAt(point);
break;
case 'add-moving':
addMovingObject(point);
break;
case 'add-ramp':
addRampAt(point);
break;
}
}
});
function addTerrainAt(point) {
const height = document.getElementById('terrain-height')?.value || 10;
const hillGeometry = new THREE.ConeGeometry(5, height, 32);
const hillMaterial = new THREE.MeshPhongMaterial({
color: document.getElementById('terrain-color')?.value || 0x808080
});
const hill = new THREE.Mesh(hillGeometry, hillMaterial);
hill.position.copy(point);
scene.add(hill);
window.activeTerrain = hill;
}
function addVegetationAt(point) {
const treeGeometry = new THREE.ConeGeometry(1, 4, 8);
const treeMaterial = new THREE.MeshPhongMaterial({ color: document.getElementById('vegetation-color').value });
const tree = new THREE.Mesh(treeGeometry, treeMaterial);
tree.position.copy(point);
tree.position.y += 2;
scene.add(tree);
}
function addRockAt(point) {
const rockGeometry = new THREE.DodecahedronGeometry(Math.random() * 2 + 1);
const rockMaterial = new THREE.MeshPhongMaterial({
color: document.getElementById('rock-color')?.value || 0x808080,
roughness: 0.8,
metalness: 0.2
});
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.copy(point);
rock.position.y += 1;
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
function addStructureAt(point, type) {
const building = new THREE.Group();
switch(type) {
case 'house':
const houseGeometry = new THREE.BoxGeometry(5, 5, 5);
const houseMaterial = new THREE.MeshPhongMaterial({ color: document.getElementById('structure-color').value });
const house = new THREE.Mesh(houseGeometry, houseMaterial);
building.add(house);
break;
case 'tower':
const towerHeight = 15;
const towerGeometry = new THREE.CylinderGeometry(2, 3, towerHeight, 8);
const tower = new THREE.Mesh(towerGeometry, new THREE.MeshPhongMaterial({color: 0x808080}));
building.add(tower);
break;
case 'temple':
const baseGeom = new THREE.BoxGeometry(10, 2, 10);
const columns = [];
for(let i = 0; i < 4; i++) {
const column = new THREE.Mesh(
new THREE.CylinderGeometry(0.5, 0.5, 8, 8),
new THREE.MeshPhongMaterial({color: 0xcccccc})
);
column.position.set(
i < 2 ? -4 : 4,
4,
i % 2 === 0 ? -4 : 4
);
columns.push(column);
}
const roof = new THREE.Mesh(
new THREE.ConeGeometry(7, 4, 4),
new THREE.MeshPhongMaterial({color: 0x8b4513})
);
roof.position.y = 8;
building.add(new THREE.Mesh(baseGeom, new THREE.MeshPhongMaterial({color: 0xcccccc})));
columns.forEach(col => building.add(col));
building.add(roof);
break;
}
building.position.copy(point);
building.position.y += 2.5;
scene.add(building);
}
function addLightAt(point) {
const lightTypes = {
point: THREE.PointLight,
spot: THREE.SpotLight,
directional: THREE.DirectionalLight
};
const type = prompt('Light type (point/spot/directional):', 'point');
const color = prompt('Light color (hex):', '#ffffff');
const intensity = parseFloat(prompt('Light intensity (0-2):', '1'));
if(lightTypes[type]) {
const light = new lightTypes[type](color, intensity);
light.position.copy(point);
light.castShadow = true;
if(type === 'spot') {
light.angle = Math.PI/4;
light.penumbra = 0.1;
}
scene.add(light);
const bulbGeometry = new THREE.SphereGeometry(0.3, 8, 8);
const bulbMaterial = new THREE.MeshBasicMaterial({color: color});
const bulb = new THREE.Mesh(bulbGeometry, bulbMaterial);
bulb.position.copy(point);
scene.add(bulb);
}
}
function addPortalAt(point) {