|
2 | 2 | <html>
|
3 | 3 | <head>
|
4 | 4 | <script type="text/javascript" src="../lib/three.js"></script>
|
5 |
| - <script type="text/javascript" src="../lib/MTLLoader.js"></script> |
6 |
| - <script type="text/javascript" src="../lib/OBJMTLLoader.js"></script> |
7 | 5 |
|
8 | 6 | <script type="text/javascript">
|
9 | 7 | var scene = null;
|
10 | 8 | var camera = null;
|
11 | 9 | var renderer = null;
|
12 | 10 |
|
| 11 | + var cube = null; |
| 12 | + var alpha = 0; |
| 13 | + |
13 | 14 | function init() {
|
14 | 15 | renderer = new THREE.WebGLRenderer({
|
15 | 16 | canvas: document.getElementById('mainCanvas')
|
16 | 17 | });
|
17 | 18 | renderer.setClearColor(0x000000);
|
18 | 19 | renderer.shadowMapEnabled = true;
|
19 |
| - renderer.shadowMapSoft = true; |
20 | 20 |
|
21 | 21 | scene = new THREE.Scene();
|
22 | 22 |
|
|
25 | 25 | camera.lookAt(new THREE.Vector3(0, 0, 0));
|
26 | 26 | scene.add(camera);
|
27 | 27 |
|
28 |
| - var light = new THREE.DirectionalLight(0xffffff); |
29 |
| - light.castShadow = true; |
30 |
| - light.shadowDarkness = 0.5; |
31 |
| - light.shadowCameraNear = 0.1; |
32 |
| - light.shadowCameraFar = 20; |
33 |
| - light.shadowCameraVisible = true; |
34 |
| - light.position.set(-2.0, 5.0, 3.0); |
35 |
| - scene.add(light); |
36 |
| - |
37 |
| - var greenCube = new THREE.Mesh(new THREE.CubeGeometry(2, 2, 2), |
38 |
| - new THREE.MeshLambertMaterial({color: 0x00ff00})); |
39 |
| - greenCube.castShadow = true; |
40 |
| - scene.add(greenCube); |
41 |
| - |
42 |
| - var plane = new THREE.Mesh(new THREE.PlaneGeometry(8, 8), |
| 28 | + var plane = new THREE.Mesh(new THREE.PlaneGeometry(8, 8, 16, 16), |
43 | 29 | new THREE.MeshLambertMaterial({color: 0xcccccc}));
|
44 | 30 | plane.rotation.x = -Math.PI / 2;
|
45 | 31 | plane.position.y = -1;
|
46 | 32 | plane.receiveShadow = true;
|
47 | 33 | scene.add(plane);
|
48 | 34 |
|
| 35 | + cube = new THREE.Mesh(new THREE.CubeGeometry(1, 1, 1), |
| 36 | + new THREE.MeshLambertMaterial({color: 0x00ff00})); |
| 37 | + cube.position.x = 2; |
| 38 | + cube.castShadow = true; |
| 39 | + scene.add(cube); |
| 40 | + |
| 41 | + var light = new THREE.SpotLight(0xffff00, 1, 100, Math.PI / 6, 25); |
| 42 | + light.position.set(2, 5, 3); |
| 43 | + light.target = cube; |
| 44 | + light.castShadow = true; |
| 45 | + scene.add(light); |
| 46 | + |
| 47 | + // ambient light |
| 48 | + var ambient = new THREE.AmbientLight(0x666666); |
| 49 | + scene.add(ambient); |
| 50 | + |
| 51 | + requestAnimationFrame(draw); |
| 52 | + } |
| 53 | + |
| 54 | + function draw() { |
| 55 | + alpha += 0.01; |
| 56 | + if (alpha > Math.PI * 2) { |
| 57 | + alpha -= Math.PI * 2; |
| 58 | + } |
| 59 | + |
| 60 | + cube.position.set(2 * Math.cos(alpha), 0, 2 * Math.sin(alpha)); |
| 61 | + |
49 | 62 | renderer.render(scene, camera);
|
| 63 | + |
| 64 | + requestAnimationFrame(draw); |
50 | 65 | }
|
51 | 66 | </script>
|
52 | 67 | </head>
|
|
0 commit comments