-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight-shade.html
80 lines (73 loc) · 2.41 KB
/
light-shade.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title></title>
<script src="./js/three.min.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, .1, 1000);
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setClearColor(0x333333);
renderer.setSize(window.innerWidth,window.innerHeight);
// 启动阴影效果
renderer.shadowMapEnabled = true;
var planeGeometry = new THREE.PlaneGeometry(60,20);
// 创建对光源有反应的材质
var planeMaterial = new THREE.MeshLambertMaterial({color:0xffffff});
// plane
var plane = new THREE.Mesh(planeGeometry,planeMaterial);
plane.receiveShadow = true;
plane.rotation.x = -.5*Math.PI;
plane.position.x = 10;
plane.position.y = 0;
plane.position.z = 0;
scene.add(plane);
// 立方体
var cubeGeometry = new THREE.BoxGeometry(4,4,4);
var cubeMaterial = new THREE.MeshLambertMaterial({color:0xff0000});
var cube = new THREE.Mesh(cubeGeometry,cubeMaterial);
cube.castShadow = true;
cube.position.x = -.4;
cube.position.y = 3;
cube.position.z = 0;
scene.add(cube);
// 球面体
var sphereGeometry = new THREE.SphereGeometry(4,20,20);
var sphereMaterial = new THREE.MeshLambertMaterial({color:0x7777ff});
var sphere = new THREE.Mesh(sphereGeometry,sphereMaterial);
sphere.position.x = 20;
sphere.position.y = 4;
sphere.position.z = 2;
sphere.castShadow = true;
scene.add(sphere);
camera.position.x = -30;
camera.position.y = 40;
camera.position.z = 30;
camera.lookAt(scene.position);
// 创建光源
// 聚光灯
// var light = new THREE.SpotLight(0xffffff);
// 环境光
// var light = new THREE.AmbientLight(0xcccccc);
// 点光源
var light = new THREE.PointLight(0xffffff);
// 平行光
// var light = new THREE.DirectionalLight(0xffffff);
light.position.set(-40,60,10);
light.castShadow = true;
scene.add(light);
document.body.appendChild(renderer.domElement);
renderer.render(scene,camera);
</script>
</body>
</html>