-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (49 loc) · 1.87 KB
/
script.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
console.log("Initializing script");
// Ensure THREE.js and OrbitControls are available
if (typeof THREE === 'undefined' || typeof THREE.OrbitControls === 'undefined') {
console.error("THREE.js or OrbitControls not loaded");
return;
}
// Initialize scene, camera, and renderer
const scene = new THREE.Scene();
const container = document.getElementById('modelContainer');
// Ensure the container has some size
if (!container.clientWidth || !container.clientHeight) {
container.style.width = '800px';
container.style.height = '600px';
}
const camera = new THREE.PerspectiveCamera(75, container.clientWidth / container.clientHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(container.clientWidth, container.clientHeight);
renderer.setClearColor(0xaaaaaa);
container.appendChild(renderer.domElement);
console.log("Added renderer to container");
const controls = new THREE.OrbitControls(camera, container);
const ambientLight = new THREE.AmbientLight(0x404040, 0.5);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0xffffff, 1);
pointLight.position.set(50, 50, 50);
scene.add(pointLight);
console.log("Added lights to scene");
camera.position.z = 50;
const loader = new THREE.GLTFLoader();
loader.load('/static/mike.glb',
(gltf) => {
console.log("Successfully loaded GLB model", gltf);
scene.add(gltf.scene);
animate();
},
(xhr) => {
console.log("Model " + (xhr.loaded / xhr.total * 100) + "% loaded");
},
(error) => {
console.error("An error occurred while loading the GLB model:", error);
}
);
console.log("Set up GLTFLoader");
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
console.log("Set up animation loop");