-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (77 loc) · 2.47 KB
/
main.js
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
import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
var scene, camera, renderer, controls;
var model;
init();
animate();
function init() {
showLoadingOverlay();
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.z = -10.5 * Math.SQRT1_2;
camera.position.x = 10.5 * Math.SQRT1_2;
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var loader = new GLTFLoader();
var dracoLoader = new DRACOLoader();
dracoLoader.setDecoderConfig({ type: "js" });
dracoLoader.setDecoderPath("https://www.gstatic.com/draco/v1/decoders/");
loader.setDRACOLoader(dracoLoader);
loader.load("neptunium_web.draco.gltf", function (gltf) {
model = gltf.scene;
model.position.set(0, 0.25, 0);
// model.rotateY(Math.PI);
// model.rotateX(Math.PI);
model.rotateZ(-Math.PI / 2);
model.scale.set(100, 100, 100);
scene.add(model);
hideLoadingOverlay();
});
var global_illumination = new THREE.AmbientLight(0xffffff, 1);
scene.add(global_illumination);
controls = new OrbitControls(camera, renderer.domElement);
controls.autoRotate = true;
controls.autoRotateSpeed = 2;
renderer.setClearColor(0x000000, 1);
window.addEventListener("resize", onWindowResize, false);
document.addEventListener(
"mousedown",
() => (controls.autoRotate = false),
false
);
document.addEventListener(
"mouseup",
() => (controls.autoRotate = true),
false
);
document
.getElementById("resetButton")
.addEventListener("click", () => controls.reset());
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
function showLoadingOverlay() {
document.getElementById("loadingOverlay").style.display = "flex";
}
function hideLoadingOverlay() {
document.getElementById("loadingOverlay").classList.add("fade-out");
setTimeout(() => {
document.getElementById("loadingOverlay").style.display = "none";
}, 1000);
}