-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane_testing_lighting.html
177 lines (143 loc) · 5.3 KB
/
plane_testing_lighting.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Lights testing three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set( -13, 0, 100);
//renderer for the scene
const renderer = new THREE.WebGLRenderer();
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setSize( window.innerWidth, window.innerHeight);
document.body.appendChild( renderer.domElement);
//controls for camera
const controls = new OrbitControls(camera, renderer.domElement);
controls.minDistance = 20;
controls.maxDistance = 300;
controls.MaxPolarAngle = Math.PI/2;
controls.target.set(0, 0, 0);
controls.update();
//coordinate helper
const coordinate = new THREE.AxesHelper(5);
//scene.add(coordinate);
//random spheres used for point lights
const sphere2 = new THREE.SphereGeometry(.5, 16, 8);
const sphere3 = new THREE.SphereGeometry(.75, 20, 10);
//spotLight
let light = new THREE.SpotLight(0xffdb4d,4);
light.castShadow = true;
light.penumbra = 0.55;
light.distance = 250;
light.angle = .35;
light.position.set(30, 150, 50);
//light.target.position.set(0,0,0);
//light helper
let lightHelper = new THREE.SpotLightHelper(light);
//scene.add(light.target);
scene.add(light);
//scene.add(lightHelper);
//other Spotlight
let light2 = new THREE.SpotLight(0x80ffbf, 4);
light2.castShadow = true;
light2.penumbra = .45;
light2.distance = 250;
light2.angle = .45;
light2.position.set(-30, 150, -50);
scene.add(light2);
//Ambient Light
let ambientLight = new THREE.AmbientLight(0x404040);
ambientLight.intensity = .05;
ambientLight.isAmbientLight = true;
scene.add(ambientLight);
//point light
let pointLight = new THREE.PointLight(0xff0000, 2, 100);
pointLight.position.set(300, 0, 0);
pointLight.castShadow = true;
pointLight.add(new THREE.Mesh(sphere2, new THREE.MeshBasicMaterial(0x80ff80)));
// second point light
let pointLight2 = new THREE.PointLight(0x00e6e6, 2, 100);
pointLight2.position.set(300, 0, -100);
pointLight2.castShadow = true;
pointLight2.add(new THREE.Mesh(sphere3, new THREE.MeshBasicMaterial(0x00e6e6)));
scene.add(pointLight, pointLight2);
//rectArea Light
const width = 25;
const height = 75;
const strength = 2;
let rectLight = new THREE.RectAreaLight(0xffffff, strength, width, height)
rectLight.position.set(150, 0, 0);
scene.add(rectLight);
//plane
let planeGeo = new THREE.PlaneGeometry(2000,2000);
planeGeo.rotateX(-Math.PI / 2);
const material = new THREE.MeshStandardMaterial(0x7a7a52);
let plane = new THREE.Mesh(planeGeo, material);
plane.position.y = -50;
plane.receiveShadow = true;
//cube
let cubeGeo = new THREE.BoxGeometry(20,20,20);
const cubicMaterial = new THREE.MeshPhongMaterial();
let cube = new THREE.Mesh(cubeGeo, cubicMaterial);
cube.receiveShadow = true;
cube.castShadow = true;
cube.position.set(10,0,5);
scene.add(cube);
scene.add(plane);
//Sphere
let sphereGeo = new THREE.SphereGeometry(20,45,20);
let sphere = new THREE.Mesh(sphereGeo, cubicMaterial);
sphere.receiveShadow = true;
sphere.castShadow = true;
sphere.position.set(-35, 0 , 0);
scene.add(sphere);
//Icosahedron
let icosahedron = new THREE.IcosahedronGeometry(10, 0);
const icosahedronShape = new THREE.Mesh(icosahedron, cubicMaterial);
icosahedronShape.castShadow = true;
icosahedronShape.receiveShadow = true;
icosahedronShape.position.set(300, 0 , -50);
scene.add(icosahedronShape);
window.addEventListener( 'resize', onWindowResize );
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame(animate);
const time = performance.now() / 3000;
light.position.x = Math.cos( time ) * 25;
light.position.z = Math.sin( time ) * 25;
light2.position.x = Math.cos( time ) * -15;
light2.position.z = Math.sin( time ) * -15;
lightHelper.update();
pointLight.position.x = 300 + Math.sin( time * 0.7 ) * 30;
pointLight.position.z = Math.sin( time * 0.7 ) * 30;
pointLight2.position.x = 300 + Math.sin( time * 0.7 ) * -30;
pointLight2.position.z = Math.sin( time * 0.7 ) * -30;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>