-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_4.php
72 lines (59 loc) · 2.05 KB
/
demo_4.php
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>WebGL Demo with three.js</title>
<link rel="stylesheet" href="./styles/style.css" type="text/css">
</head>
<body>
<h1>WebGL Demo with three.js</h1>
<canvas id="glcanvas" width="640" height="480"></canvas>
<p>This statue is imported from Blender to webGL using Three.js library. Use your mouse to move it !</p>
<?php include("_navigation.php"); ?>
</body>
<script type="module">
import * as THREE from './scripts/three.js/three.module.js';
import { OrbitControls } from './scripts/three.js/OrbitControls.js';
import { GLTFLoader } from './scripts/three.js/GLTFLoader.js';
function startGL() {
const canvas = document.querySelector('#glcanvas');
const renderer = new THREE.WebGLRenderer({canvas});
// CAMERA
const fov = 56;
const aspect = 4/3; // the canvas default
const near = 0.1;
const far = 50;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set ( 0, 0, 2 );
camera.lookAt( 0, 0, 0 );
// CONTROLS
const controls = new OrbitControls( camera, renderer.domElement );
// SCENE
const scene = new THREE.Scene();
// LIGHT
const color = 0xFFFFFF;
const intensity = 5;
const light1 = new THREE.DirectionalLight(color, intensity);
const light2 = new THREE.DirectionalLight(color, intensity - 4);
light1.position.set(-1, 2, 4);
light2.position.set(0, 1, -2);
scene.add(light1);
scene.add(light2);
// LODING BLENDER STATUE
const loader = new GLTFLoader();
loader.load( 'meshes/statue.glb', function ( gltf ) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
// RENDERING
function render(time) {
time *= 0.001; // convert time to seconds
renderer.render(scene, camera);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
}
startGL();
</script>
</html>