Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
1129 lines (913 loc) · 39.9 KB
/
Copy pathmain.js
File metadata and controls
1129 lines (913 loc) · 39.9 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
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
import * as THREE from 'three';
import Stats from 'three/addons/libs/stats.module.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { Water } from 'three/addons/objects/Water.js';
import { Sky } from 'three/addons/objects/Sky.js';
import { GLTFLoader } from "https://cdn.rawgit.com/mrdoob/three.js/master/examples/jsm/loaders/GLTFLoader.js"
import { FontLoader } from "https://cdn.rawgit.com/mrdoob/three.js/master/examples/jsm/loaders/FontLoader.js"
import { TextGeometry } from "https://cdn.rawgit.com/mrdoob/three.js/master/examples/jsm/geometries/TextGeometry.js"
let container, stats;
let camera, scene, renderer;
let controls, water, sun, box1, box2,music=false,donald;
// Define a global clock
const clock = new THREE.Clock();
// Move parameters to a global scope
const parameters = {
elevation: 2,
azimuth: 180
};
init();
async function init() {
const loadingScreen = document.getElementById('loading-screen');
try {
container = document.getElementById('container');
if (!container) {
throw new Error("Container element with id 'container' not found.");
}
initRenderer();
initScene();
initCamera();
initSun();
initWater();
initSky();
initControls();
initStats();
initGUI();
// Wait for async initializations (e.g., loading models)
const tasks = [
initIsland(),
initWelcomeModel(),
initConcert(),
initAudience(),
initLightHouse(),
initWhale(),
initBird(),
initVideo(),
initLasers(),
initBox(),
initPhoenix(),
initClassicShip(),
initEaster_island_head(),
initHouse(),
initSkeleton(),
initYacht(),
initClouds() // Assuming `initClouds` uses a Promise or can be adapted
];
await Promise.allSettled(tasks);
// Remove loading screen after initialization
loadingScreen.style.display = 'none';
window.addEventListener('resize', onWindowResize);
} catch (error) {
console.error("Error during initialization:", error);
loadingScreen.innerHTML = "An error occurred. Please reload the page.";
}
}
function initRenderer() {
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animate);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 0.5;
container.appendChild(renderer.domElement);
}
function initScene() {
scene = new THREE.Scene();
}
function initCamera() {
// Increase the FOV for a wider view
camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 1, 10000); // FOV increased, far plane set to 50000
camera.position.set(40, 200, 100); // Adjust camera position to make the environment appear larger
}
function initSun() {
sun = new THREE.Vector3();
}
function initWater() {
const waterGeometry = new THREE.PlaneGeometry(10000, 10000);
// Create the top water surface
water = new Water(waterGeometry, {
textureWidth: 512,
textureHeight: 512,
waterNormals: new THREE.TextureLoader().load(
'https://threejs.org/examples/textures/waternormals.jpg',
(texture) => {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
}
),
sunDirection: new THREE.Vector3(0, 1, 0),
sunColor: 0xffffff,
waterColor: 0x001e0f,
distortionScale: 3.7,
fog: scene.fog !== undefined
});
water.rotation.x = -Math.PI / 2;
water.position.y = 0; // Top surface position
water.material.transparent = true; // Enable transparency
water.material.side = THREE.DoubleSide; // Render both sides of the water
scene.add(water);
}
function initSky() {
const sky = new Sky();
sky.scale.setScalar(10000); // Increase the scale for a more expansive sky
scene.add(sky);
const skyUniforms = sky.material.uniforms;
skyUniforms['turbidity'].value = 10;
skyUniforms['rayleigh'].value = 2;
skyUniforms['mieCoefficient'].value = 0.005;
skyUniforms['mieDirectionalG'].value = 0.5;
const pmremGenerator = new THREE.PMREMGenerator(renderer);
const sceneEnv = new THREE.Scene();
let renderTarget;
function updateSun() {
const phi = THREE.MathUtils.degToRad(90 - parameters.elevation);
const theta = THREE.MathUtils.degToRad(parameters.azimuth);
sun.setFromSphericalCoords(1, phi, theta);
sky.material.uniforms['sunPosition'].value.copy(sun);
water.material.uniforms['sunDirection'].value.copy(sun).normalize();
if (renderTarget !== undefined) renderTarget.dispose();
sceneEnv.add(sky);
renderTarget = pmremGenerator.fromScene(sceneEnv);
scene.add(sky);
scene.environment = renderTarget.texture;
}
updateSun();
}
function initControls() {
controls = new OrbitControls(camera, renderer.domElement);
controls.maxPolarAngle = Math.PI * 0.495;
controls.target.set(0, 50, 0); // Adjusted the target to (0, 50, 0) for a better view
controls.minDistance = 40.0;
controls.maxDistance = 10000.0; // Increased max zoom distance to allow a wider view of the environment
controls.update();
}
function initStats() {
stats = new Stats();
container.appendChild(stats.dom);
}
function initGUI() {
const gui = new GUI();
const folderSky = gui.addFolder('Sky');
folderSky.add(parameters, 'elevation', 0, 90, 0.1).onChange(() => {
const phi = THREE.MathUtils.degToRad(90 - parameters.elevation);
const theta = THREE.MathUtils.degToRad(parameters.azimuth);
sun.setFromSphericalCoords(1, phi, theta);
water.material.uniforms['sunDirection'].value.copy(sun).normalize();
});
folderSky.add(parameters, 'azimuth', -180, 180, 0.1).onChange(() => {
const phi = THREE.MathUtils.degToRad(90 - parameters.elevation);
const theta = THREE.MathUtils.degToRad(parameters.azimuth);
sun.setFromSphericalCoords(1, phi, theta);
water.material.uniforms['sunDirection'].value.copy(sun).normalize();
});
folderSky.open();
const waterUniforms = water.material.uniforms;
const folderWater = gui.addFolder('Water');
folderWater.add(waterUniforms.distortionScale, 'value', 0, 8, 0.1).name('distortionScale');
folderWater.add(waterUniforms.size, 'value', 0.1, 10, 0.1).name('size');
folderWater.open();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
render();
stats.update();
}
function render() {
const time = performance.now() * 0.001;
// Remove the box oscillation, keep it fixed at y = 60 (above the water)
if (box1) {
box1.rotation.x = time * 0.5;
box1.rotation.z = time * 0.51;
}
if (box2) {
box2.rotation.x = time * 0.5;
box2.rotation.z = time * 0.51;
}
water.material.uniforms['time'].value += 1.0 / 60.0;
renderer.render(scene, camera);
}
function initBox() {
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('pablooo.jpg');
const geometry = new THREE.BoxGeometry(100, 100, 100);
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.5,
metalness: 4
});
// Create the first box
box1 = new THREE.Mesh(geometry, material);
box1.position.set(-200, 200, 0); // Set position to one corner of the island
scene.add(box1);
// // Create the second box
box2 = new THREE.Mesh(geometry, material);
box2.position.set(-200, 200,0); // Set position to the opposite corner of the island
scene.add(box2);
}
function initConcert() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/concert.glb',
(gltf) => {
try {
const Concert = gltf.scene;
Concert.position.set(1000, -20, 0);
Concert.rotation.y = 1;
Concert.scale.set(0.5, 0.5, 0.5);
scene.add(Concert);
resolve(); // Resolve the promise when the concert model is added to the scene
} catch (error) {
reject(`Error processing concert model: ${error}`);
}
},
undefined,
(error) => {
reject(`Error loading concert model: ${error}`);
}
);
});
}
function initLasers() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/laser_light.glb',
(gltf) => {
const lasers = gltf.scene;
lasers.position.set(1000, 100, 40);
lasers.rotation.y = 1;
lasers.scale.set(10, 10, 10);
scene.add(lasers);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0) {
const mixer = new THREE.AnimationMixer(lasers); // Animation mixer for lasers
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations (modify if you want specific animations)
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animateLasers() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
requestAnimationFrame(animateLasers);
}
animateLasers(); // Start animation loop
} else {
console.warn("No animations found in the lasers model.");
}
resolve(); // Resolve the promise once the lasers are added
},
undefined,
(error) => {
console.error('An error occurred while loading the lasers:', error);
reject(error); // Reject the promise if there's an error
}
);
});
}
function initAudience() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/people/audience.glb',
(gltf) => {
const audience = gltf.scene;
audience.position.set(1000, 100, 30);
audience.rotation.y = 1;
audience.scale.set(10, 10, 10);
scene.add(audience);
resolve(); // Resolve the promise when the audience is added
},
undefined,
(error) => {
console.error('An error occurred while loading the audience:', error);
reject(error); // Reject the promise in case of error
}
);
});
}
function initVideo() {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
const soundEffect = new Audio('public/sounds/click.mp3'); // Button click sound
const songs = ['public/sounds/Karma_pablo.mp4', 'public/sounds/Melody_pablo.mp4', 'public/sounds/Mabda2_pablo.mp4']; // Add more songs here
let currentSongIndex = 0;
video.src = songs[currentSongIndex];
video.loop = true;
video.muted = false;
const texture = new THREE.VideoTexture(video);
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.format = THREE.RGBFormat;
const geometry = new THREE.PlaneGeometry(16 * 45, 9 * 45);
const material = new THREE.MeshBasicMaterial({ map: texture });
const plane = new THREE.Mesh(geometry, material);
plane.position.set(690, 210, -210);
plane.rotation.y = 1; // Rotate the plane to make it vertical and face the camera
scene.add(plane);
// Create the 3D button as a mesh (using a box geometry for the button)
const buttonGeometry = new THREE.BoxGeometry(40, 20, 10); // Increased size of the button
const buttonMaterial = new THREE.MeshBasicMaterial({ color: 0x32cd32 }); // Dodger blue color for the button 0x32cd32
const buttonMesh = new THREE.Mesh(buttonGeometry, buttonMaterial);
buttonMesh.position.set(1200, 210, -200); // Position the button in front of the video screen
scene.add(buttonMesh);
// Create the next song button
const nextButtonGeometry = new THREE.BoxGeometry(40, 20, 10);
const nextButtonMaterial = new THREE.MeshBasicMaterial({ color: 0x1e90ff }); // Lime green color for the next button
const nextButtonMesh = new THREE.Mesh(nextButtonGeometry, nextButtonMaterial);
nextButtonMesh.position.set(1200, 180, -200); // Position the next button below the play button
scene.add(nextButtonMesh);
// Add text to the buttons
const loader = new FontLoader();
loader.load('https://threejs.org/examples/fonts/helvetiker_regular.typeface.json', function (font) {
const textGeometry = new TextGeometry('Play Music', {
font: font,
size: 4, // Adjust size to fit on the button
depth: 1,
});
const textMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const textMesh = new THREE.Mesh(textGeometry, textMaterial);
textMesh.position.set(-16, -2, 5.1); // Position the text on the button
buttonMesh.add(textMesh); // Add text as a child of the button
const nextTextGeometry = new TextGeometry('Next Song', {
font: font,
size: 4,
depth: 1,
});
const nextTextMesh = new THREE.Mesh(nextTextGeometry, textMaterial);
nextTextMesh.position.set(-16, -2, 5.1); // Position the text on the next button
nextButtonMesh.add(nextTextMesh); // Add text as a child of the next button
// Animate the buttons and text rotation
function animateButton() {
buttonMesh.rotation.y += 0.03;
nextButtonMesh.rotation.y += 0.03;
requestAnimationFrame(animateButton);
}
animateButton();
}, undefined, (error) => {
console.error('Error loading font for buttons:', error);
reject(error); // Reject the promise if font loading fails
});
// Add raycasting to detect mouse click on the 3D buttons
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
window.addEventListener('click', onMouseClick, false);
window.addEventListener('mousemove', onMouseMove, false); // To detect mouse hover
// Button scaling on hover
function onMouseMove(event) {
// Calculate mouse position in normalized device coordinates (-1 to +1)
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// Update the raycaster with the mouse coordinates
raycaster.setFromCamera(mouse, camera); // 'camera' is the perspective camera in your scene
// Check for intersections between the ray and the buttons
const intersects = raycaster.intersectObjects([buttonMesh, nextButtonMesh]);
if (intersects.length > 0) {
intersects[0].object.scale.set(1.1, 1.1, 1); // Scale up when hovered
} else {
buttonMesh.scale.set(1, 1, 1); // Return to original size
nextButtonMesh.scale.set(1, 1, 1); // Return to original size
}
}
function onMouseClick(event) {
// Calculate mouse position in normalized device coordinates (-1 to +1)
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// Update the raycaster with the mouse coordinates
raycaster.setFromCamera(mouse, camera);
// Check for intersections between the ray and the buttons
const intersects = raycaster.intersectObjects([buttonMesh, nextButtonMesh]);
if (intersects.length > 0) {
if (intersects[0].object === buttonMesh) {
// Play video and button click sound
video.play().catch((error) => {
console.error('Error attempting to play video:', error);
reject(error); // Reject the promise if video fails to play
});
soundEffect.play().catch((error) => {
console.error('Error playing sound effect:', error);
reject(error); // Reject the promise if sound effect fails
});
music = true;
initDonald();
initstarwarsTropper();
// Make the button disappear
buttonMesh.visible = false;
} else if (intersects[0].object === nextButtonMesh) {
// Switch to the next song
currentSongIndex = (currentSongIndex + 1) % songs.length;
video.src = songs[currentSongIndex];
video.play().catch((error) => {
console.error('Error attempting to play video:', error);
reject(error); // Reject the promise if video fails to play
});
soundEffect.play().catch((error) => {
console.error('Error playing sound effect:', error);
reject(error); // Reject the promise if sound effect fails
});
}
}
}
// Adjust sound volume based on camera distance
function adjustVolume() {
const distance = camera.position.distanceTo(plane.position);
const maxDistance = 3500; // Maximum distance for full volume
const minDistance = 200; // Minimum distance for zero volume
// Calculate volume based on distance
let volume = 1 - (distance - minDistance) / (maxDistance - minDistance);
volume = Math.max(0, Math.min(1, volume)); // Clamp volume between 0 and 1
video.volume = volume;
requestAnimationFrame(adjustVolume);
}
adjustVolume(); // Start adjusting volume
resolve(); // Resolve the promise when the video setup is complete
});
}
function initEaster_island_head() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/easter_island_head.glb',
(gltf) => {
try {
const island = gltf.scene;
island.position.set(1000, -20, 0); // Position inside the concert
island.rotation.y = 1;
island.scale.set(1, 1, 1);
scene.add(island);
resolve(); // Resolve the promise when the island is added to the scene
} catch (error) {
reject(`Error processing Easter Island head model: ${error}`);
}
},
undefined,
(error) => {
reject(`Error loading Easter Island head model: ${error}`);
}
);
});
}
function initClouds() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
const cloudPositions = Array.from({ length: 30 }, () => ({
x: Math.random() * 8000 - 4000,
y: 1000,
z: Math.random() * 8000 - 4000
}));
loader.load('public/clouds/scene.gltf', function (gltf) {
try {
cloudPositions.forEach(position => {
const cloud = gltf.scene.clone();
cloud.position.set(position.x, position.y, position.z);
cloud.scale.set(0.5, 0.5, 0.5);
scene.add(cloud);
// Animate clouds
function animateClouds() {
cloud.position.x += 0.5;
if (cloud.position.x > 5000) {
cloud.position.x = -5000;
}
requestAnimationFrame(animateClouds);
}
animateClouds();
});
resolve(); // Resolve the promise when the clouds are added to the scene
} catch (error) {
reject(`Error processing clouds model: ${error}`);
}
}, undefined, function (error) {
reject(`Error loading clouds model: ${error}`);
});
});
}
// houses models >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function initLightHouse() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/lighthouse_on_a_sea_rock.glb',
(gltf) => {
try {
const lightHouse = gltf.scene;
lightHouse.position.set(3000, 2, 2000); // Adjust position if needed
lightHouse.scale.set(5, 5, 5); // Adjust scale if needed
scene.add(lightHouse);
resolve(); // Resolve the promise when the lighthouse is added to the scene
} catch (error) {
reject(`Error processing lighthouse model: ${error}`);
}
},
undefined,
(error) => {
reject(`Error loading lighthouse model: ${error}`);
}
);
});
}
function initHouse() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/house.glb',
function (gltf) {
try {
const house = gltf.scene;
house.position.set(-1000, 20, -3000); // Initial position
house.scale.set(150, 150, 150); // Adjust scale as needed
house.rotation.y = 1;
scene.add(house);
resolve(); // Resolve the promise when the house is added to the scene
} catch (error) {
reject(`Error processing house model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading house model: ${error}`);
}
);
});
}
function initSkeleton() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/people/spooky_skeleton_dance_1.glb',
function (gltf) {
try {
const skeleton = gltf.scene;
skeleton.position.set(-500, 20, -2500); // Initial position
skeleton.scale.set(50, 50, 50); // Adjust scale as needed
skeleton.rotation.y = 1;
scene.add(skeleton);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0) {
const mixer = new THREE.AnimationMixer(skeleton); // Animation mixer for skeleton
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations (modify if you want specific animations)
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animateSkeleton() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
requestAnimationFrame(animateSkeleton);
}
animateSkeleton(); // Start animation loop
} else {
console.warn("No animations found in the skeleton model.");
}
resolve(); // Resolve the promise when the skeleton is added to the scene
} catch (error) {
reject(`Error processing skeleton model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading skeleton model: ${error}`);
}
);
});
}
function initYacht() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/ships/yatch_ii.glb',
function (gltf) {
try {
const yacht = gltf.scene;
yacht.position.set(-500, -50, -1500); // Initial position
yacht.scale.set(30, 30, 30); // Adjust scale as needed
yacht.rotation.y = -1;
scene.add(yacht);
resolve(); // Resolve the promise when the yacht is added to the scene
} catch (error) {
reject(`Error processing yacht model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading yacht model: ${error}`);
}
);
});
}
function initDonald() {
const loader = new GLTFLoader();
loader.load(
'public/people/donald.glb',
function (gltf) {
donald = gltf.scene;
donald.position.set(800, 10, 200); // Initial position
donald.scale.set(50, 50, 50); // Adjust scale as needed
donald.rotation.y = 1;
scene.add(donald);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0 && music) {
const mixer = new THREE.AnimationMixer(donald); // Animation mixer for donald
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations (modify if you want specific animations)
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animateDonald() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
requestAnimationFrame(animateDonald);
}
animateDonald(); // Start animation loop
} else {
console.log("No animations found in the donald model.");
}
},
undefined,
function (error) {
console.error('An error happened while loading the donald:', error);
}
);
}
function initstarwarsTropper() {
const loader = new GLTFLoader();
loader.load(
'public/people/dancing_stormtrooper.glb',
function (gltf) {
const Tropper = gltf.scene;
Tropper.position.set(1100, 10, -250); // Initial position
Tropper.scale.set(50, 50, 50); // Adjust scale as needed
Tropper.rotation.y = 1;
scene.add(Tropper);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0 && music) {
const mixer = new THREE.AnimationMixer(Tropper); // Animation mixer for Tropper
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations (modify if you want specific animations)
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animateDonald() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
requestAnimationFrame(animateDonald);
}
animateDonald(); // Start animation loop
} else {
console.log("No animations found in the Tropper model.");
}
},
undefined,
function (error) {
console.error('An error happened while loading the Tropper:', error);
}
);
}
// ships models >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//public\ships\classic_ship.glb
function initClassicShip() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/ships/classic_ship.glb',
function (gltf) {
try {
const ship = gltf.scene;
ship.position.set(2100, -10, 1000); // Position beside the lighthouse
ship.scale.set(20, 20, 20); // Adjust scale as needed
ship.rotation.y = -1;
scene.add(ship);
resolve(); // Resolve the promise when the ship is added to the scene
} catch (error) {
reject(`Error processing classic ship model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading classic ship model: ${error}`);
}
);
});
}
// Animals models >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function initWhale() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/animals/whale_of_the_veil_-_stylized_animated_model/scene.gltf',
function (gltf) {
try {
const whale = gltf.scene;
whale.position.set(-3000, -10, 0); // Initial position
whale.scale.set(90, 90, 90); // Adjust scale as needed
whale.rotation.y = 0;
scene.add(whale);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0) {
const mixer = new THREE.AnimationMixer(whale); // Animation mixer for whale
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animateWhale() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
whale.position.z += 0.8;
whale.rotation.z += 0.004;
if (whale.position.z > 5000) {
whale.position.z = -5000;
}
requestAnimationFrame(animateWhale);
}
animateWhale(); // Start animation loop
} else {
console.warn("No animations found in the whale model.");
}
resolve(); // Resolve the promise when the whale is added to the scene
} catch (error) {
reject(`Error processing whale model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading whale model: ${error}`);
}
);
});
}
function initPhoenix() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/animals/phoenix_bird.glb',
function (gltf) {
try {
const phoenix = gltf.scene;
phoenix.position.set(2000, 400, -3000); // Initial position
phoenix.scale.set(0.5, 0.5, 0.5); // Adjust scale as needed
phoenix.rotation.y = -1;
scene.add(phoenix);
// Check if animations exist
if (gltf.animations && gltf.animations.length > 0) {
const mixer = new THREE.AnimationMixer(phoenix); // Animation mixer for bird
const clock = new THREE.Clock(); // Clock for animation timing
// Play all animations (modify if you want specific animations)
gltf.animations.forEach((clip) => {
const action = mixer.clipAction(clip);
action.play();
});
// Animation loop
function animatePhoenix() {
const delta = clock.getDelta(); // Time since last frame
mixer.update(delta); // Update animations
phoenix.position.z += 1;
if (phoenix.position.z > 4000) {
phoenix.position.z = -4000;
}
requestAnimationFrame(animatePhoenix);
}
animatePhoenix(); // Start animation loop
} else {
console.warn("No animations found in the bird model.");
}
resolve(); // Resolve the promise when the phoenix is added to the scene
} catch (error) {
reject(`Error processing phoenix model: ${error}`);
}
},
undefined,
function (error) {
reject(`Error loading phoenix model: ${error}`);
}
);
});
}
function initBird() {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(
'public/animals/birds.glb',
function (gltf) {
try {