-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
86 lines (73 loc) · 1.71 KB
/
index.html
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
<!doctype html>
<html>
<head>
<title>3D MOOC</title>
<script src="js/three.min.js"></script>
</head>
<body style="padding: 0; margin: 0;">
<script>
var scene;
var camera;
var renderer;
function createRenderer() {
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0x000000, 1.0);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
}
function createCamera() {
camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1, 1000);
camera.position.x = 15;
camera.position.y = 16;
camera.position.z = 13;
camera.lookAt(scene.position);
}
function createSphere() {
var sphereGeometry = new THREE.SphereGeometry(6, 38, 38);
var sphereMaterial = new THREE.MeshLambertMaterial({
color: "red"
});
var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.castShadow = true;
scene.add(sphere);
}
function createPlane() {
var planeGeometry = new THREE.PlaneGeometry(40, 40);
var planeMaterial = new THREE.MeshLambertMaterial({
color: 0xcccccc
});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.receiveShadow = true;
plane.rotation.x = -0.5 * Math.PI;
plane.position.y = -5;
scene.add(plane);
}
function createLight() {
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(10,20,30);
spotLight.shadowCameraNear = 20;
spotLight.shadowCameraFar = 50;
spotLight.castShadow = true;
scene.add(spotLight);
}
function init() {
scene = new THREE.Scene();
createRenderer();
createCamera();
createSphere();
createPlane();
createLight();
document.body.appendChild(renderer.domElement);
render();
}
function render() {
renderer.render(scene, camera);
requestAnimationFrame(render);
}
init();
</script>
</body>
</html>