Skip to content

Commit 983a702

Browse files
committed
Examples: Simplified webgl2_sandbox.
1 parent 2a29bd2 commit 983a702

File tree

1 file changed

+24
-46
lines changed

1 file changed

+24
-46
lines changed

examples/webgl2_sandbox.html

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
77
<style>
88
body {
9-
background:#000;
10-
padding:0;
11-
margin:0;
9+
background: #000;
10+
padding: 0;
11+
margin: 0;
1212
font-weight: bold;
13-
overflow:hidden;
13+
}
14+
15+
canvas {
16+
display: block;
1417
}
1518

1619
#info {
1720
position: absolute;
1821
top: 0px; width: 100%;
1922
color: #ffffff;
2023
padding: 5px;
21-
font-family:Monospace;
22-
font-size:13px;
23-
text-align:center;
24-
z-index:1000;
24+
font-family: Monospace;
25+
font-size: 13px;
26+
text-align: center;
2527
}
2628

2729
a {
@@ -46,40 +48,38 @@
4648
import { Scene } from '../src/scenes/Scene.js';
4749
import { WebGLRenderer } from '../src/renderers/WebGLRenderer.js';
4850

51+
import { OrbitControls } from './jsm/controls/OrbitControls.js';
52+
4953
//
5054

5155
var camera, scene, renderer;
52-
53-
var mouseX = 0, mouseY = 0;
54-
55-
var windowHalfX = window.innerWidth / 2;
56-
var windowHalfY = window.innerHeight / 2;
56+
var controls;
5757

5858
init();
59-
animate();
59+
render();
6060

6161
function init() {
6262

63-
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 20000 );
64-
camera.position.z = 3200;
63+
camera = new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 );
64+
camera.position.z = 3;
6565

6666
scene = new Scene();
6767
scene.background = new Color( 0, 0, 0.5 );
68-
scene.fog = new Fog( 0x000000, 1, 20000 );
68+
scene.fog = new Fog( 0x000000, 0.1, 3 );
6969

7070
var light = new PointLight( 0xffffff );
7171
scene.add( light );
7272

73-
var geometry = new SphereBufferGeometry( 50, 32, 16 );
73+
var geometry = new SphereBufferGeometry( 0.05, 32, 16 );
7474
var material = new MeshNormalMaterial();
7575

7676
for ( var i = 0; i < 5000; i ++ ) {
7777

7878
var mesh = new Mesh( geometry, material );
7979

80-
mesh.position.x = Math.random() * 10000 - 5000;
81-
mesh.position.y = Math.random() * 10000 - 5000;
82-
mesh.position.z = Math.random() * 10000 - 5000;
80+
mesh.position.x = Math.random() * 10 - 5;
81+
mesh.position.y = Math.random() * 10 - 5;
82+
mesh.position.z = Math.random() * 10 - 5;
8383

8484
mesh.rotation.y = Math.random() * 2 * Math.PI;
8585

@@ -97,50 +97,28 @@
9797
renderer.setSize( window.innerWidth, window.innerHeight );
9898
document.body.appendChild( renderer.domElement );
9999

100-
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
100+
window.addEventListener( 'resize', onWindowResize, false );
101101

102102
//
103103

104-
window.addEventListener( 'resize', onWindowResize, false );
104+
controls = new OrbitControls( camera, renderer.domElement );
105+
controls.addEventListener( 'change', render );
105106

106107
}
107108

108109
function onWindowResize() {
109110

110-
windowHalfX = window.innerWidth / 2;
111-
windowHalfY = window.innerHeight / 2;
112-
113111
camera.aspect = window.innerWidth / window.innerHeight;
114112
camera.updateProjectionMatrix();
115113

116114
renderer.setSize( window.innerWidth, window.innerHeight );
117115

118116
}
119117

120-
function onDocumentMouseMove( event ) {
121-
122-
mouseX = ( event.clientX - windowHalfX ) * 10;
123-
mouseY = ( event.clientY - windowHalfY ) * 10;
124-
125-
}
126-
127118
//
128119

129-
function animate() {
130-
131-
requestAnimationFrame( animate );
132-
133-
render();
134-
135-
}
136-
137120
function render() {
138121

139-
camera.position.x += ( mouseX - camera.position.x ) * .05;
140-
camera.position.y += ( - mouseY - camera.position.y ) * .05;
141-
142-
camera.lookAt( scene.position );
143-
144122
renderer.render( scene, camera );
145123

146124
}

0 commit comments

Comments
 (0)