-
Notifications
You must be signed in to change notification settings - Fork 0
/
fish.js
46 lines (33 loc) · 1.13 KB
/
fish.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
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const container = document.querySelector('#scene-container');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
85, window.innerWidth / window.innerHeight , 0.1, 1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth/2, window.innerHeight/2, false);
container.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
camera.position.set(3, 0, 0);
camera.lookAt(0,-0.2,0);
controls.update();
const loader = new GLTFLoader();
loader.load('model/fish.glb', function(gltf) {
const model = gltf.scene;
model.position.set(0,-1,0);
// model.rotation.set(1,0,0);
scene.add(model);
}, undefined, function(error) {
console.error(error);
});
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
const light = new THREE.AmbientLight(0xffffff, 1);
scene.add(light);
const hlp = new THREE.AxesHelper(1);
scene.add(hlp);