-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (52 loc) · 1.51 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
import * as THREE from "three";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
document.body.appendChild(renderer.domElement);
const light = new THREE.DirectionalLight(0xffffff);
light.position.set(5,10,0);
scene.add(light);
const light2 = new THREE.AmbientLight(0xffffff, 0.3);
light2.position.set(-5,10,0);
scene.add(light2);const light3 = new THREE.DirectionalLight(0xFFFEA6, 3);
camera.position.y = 0;
camera.position.x = 0;
camera.position.z = 10;
var model;
const loader = new GLTFLoader();
loader.load(
"assets/scene.gltf",
function (gltf) {
scene.add(gltf.scene);
gltf.animations;
gltf.scene;
gltf.scenes;
gltf.cameras;
gltf.asset;
model = gltf.scene;
},
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
function (error) {
console.log("An error happened", error);
}
);
const controls = new OrbitControls(camera, renderer.domElement);
function animate() {
requestAnimationFrame(animate);
if (model) {
model.rotation.y += 0.01;
}
renderer.render(scene, camera);
}
animate();