Skip to content

Commit f405240

Browse files
committed
Improved webgl_lights_pointlights2 example.
1 parent 4959aaf commit f405240

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

examples/webgl_lights_pointlights2.html

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -82,60 +82,38 @@
8282

8383
// CONTROLS
8484

85-
var fly = false;
85+
controls = new THREE.TrackballControls( camera );
8686

87-
if ( !fly ) {
87+
controls.rotateSpeed = 1.0;
88+
controls.zoomSpeed = 1.2;
89+
controls.panSpeed = 0.8;
8890

89-
controls = new THREE.TrackballControls( camera );
90-
controls.target.set( 0, 0, 0 );
91+
controls.noZoom = false;
92+
controls.noPan = false;
9193

92-
controls.rotateSpeed = 1.0;
93-
controls.zoomSpeed = 1.2;
94-
controls.panSpeed = 0.8;
95-
96-
controls.noZoom = false;
97-
controls.noPan = false;
98-
99-
controls.staticMoving = false;
100-
controls.dynamicDampingFactor = 0.15;
101-
102-
controls.keys = [ 65, 83, 68 ];
103-
104-
} else {
105-
106-
controls = new THREE.FirstPersonControls( camera );
107-
108-
controls.movementSpeed = 25;
109-
controls.lookSpeed = 0.05;
110-
controls.lookVertical = true;
111-
112-
controls.lon = -90;
113-
114-
}
94+
controls.staticMoving = false;
95+
controls.dynamicDampingFactor = 0.15;
11596

97+
controls.keys = [ 65, 83, 68 ];
11698

11799
// TEXTURES
100+
118101
var textureLoader = new THREE.TextureLoader();
119102

120103
var texture = textureLoader.load( "textures/disturb.jpg" );
121104
texture.repeat.set( 20, 10 );
122105
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
123106
texture.format = THREE.RGBFormat;
124107

125-
var texture2 = textureLoader.load( "textures/planets/moon_1024.jpg" );
126-
texture2.repeat.set( 2, 1 );
127-
texture2.wrapS = texture2.wrapT = THREE.RepeatWrapping;
128-
texture2.format = THREE.RGBFormat;
129-
130108
// MATERIALS
131109

132110
var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, map: texture } );
133-
var objectMaterial = new THREE.MeshStandardMaterial( { color: 0x000000, map: texture2, roughness: 0.2, metalness: 1.0 } );
111+
var objectMaterial = new THREE.MeshStandardMaterial( { color: 0xffffff, roughness: 0.5, metalness: 1.0 } );
134112

135113
// GROUND
136114

137115
var mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 800, 400, 2, 2 ), groundMaterial );
138-
mesh.position.y = -5;
116+
mesh.position.y = - 5;
139117
mesh.rotation.x = - Math.PI / 2;
140118
scene.add( mesh );
141119

@@ -164,41 +142,40 @@
164142

165143
// LIGHTS
166144

167-
scene.add( new THREE.AmbientLight( 0x111111 ) );
168-
169145
var intensity = 2.5;
170146
var distance = 100;
147+
var decay = 2.0;
148+
171149
var c1 = 0xff0040, c2 = 0x0040ff, c3 = 0x80ff80, c4 = 0xffaa00, c5 = 0x00ffaa, c6 = 0xff1100;
172-
//var c1 = 0xffffff, c2 = 0xffffff, c3 = 0xffffff, c4 = 0xffffff, c5 = 0xffffff, c6 = 0xffffff;
173150

174151
var sphere = new THREE.SphereGeometry( 0.25, 16, 8 );
175152

176-
light1 = new THREE.PointLight( c1, intensity, distance );
153+
light1 = new THREE.PointLight( c1, intensity, distance, decay );
177154
light1.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c1 } ) ) );
178155
scene.add( light1 );
179156

180-
light2 = new THREE.PointLight( c2, intensity, distance );
157+
light2 = new THREE.PointLight( c2, intensity, distance, decay );
181158
light2.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c2 } ) ) );
182159
scene.add( light2 );
183160

184-
light3 = new THREE.PointLight( c3, intensity, distance );
161+
light3 = new THREE.PointLight( c3, intensity, distance, decay );
185162
light3.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c3 } ) ) );
186163
scene.add( light3 );
187164

188-
light4 = new THREE.PointLight( c4, intensity, distance );
165+
light4 = new THREE.PointLight( c4, intensity, distance, decay );
189166
light4.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c4 } ) ) );
190167
scene.add( light4 );
191168

192-
light5 = new THREE.PointLight( c5, intensity, distance );
169+
light5 = new THREE.PointLight( c5, intensity, distance, decay );
193170
light5.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c5 } ) ) );
194171
scene.add( light5 );
195172

196-
light6 = new THREE.PointLight( c6, intensity, distance );
173+
light6 = new THREE.PointLight( c6, intensity, distance, decay );
197174
light6.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: c6 } ) ) );
198175
scene.add( light6 );
199176

200-
var dlight = new THREE.DirectionalLight( 0xffffff, 0.1 );
201-
dlight.position.set( 0.5, -1, 0 ).normalize();
177+
var dlight = new THREE.DirectionalLight( 0xffffff, 0.05 );
178+
dlight.position.set( 0.5, 1, 0 ).normalize();
202179
scene.add( dlight );
203180

204181
// RENDERER

0 commit comments

Comments
 (0)