Skip to content

Commit 79f5a01

Browse files
committed
Clean up.
1 parent 1d3b7f2 commit 79f5a01

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

examples/files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var files = {
99
"webgl_camera_logarithmicdepthbuffer",
1010
"webgl_clipping",
1111
"webgl_clipping_advanced",
12+
"webgl_clipping_intersection",
1213
"webgl_decals",
1314
"webgl_depth_texture",
1415
"webgl_effects_anaglyph",

examples/webgl_clipping_intersection.html

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121

2222
<script>
2323

24-
24+
var camera, scene, renderer;
25+
var group;
26+
27+
init();
28+
animate();
2529

2630
function init() {
2731

28-
camera = new THREE.PerspectiveCamera(
29-
40, window.innerWidth / window.innerHeight, 1, 800 );
32+
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 800 );
3033

3134
camera.position.set( -20, 10, 50 );
3235
camera.lookAt( new THREE.Vector3( 0, 0, 0) );
@@ -38,26 +41,33 @@
3841
var light = new THREE.HemisphereLight( 0xffffbb, 0x080820, 1 );
3942
scene.add( light );
4043

41-
var clipPlanes = [ new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 ),
42-
new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 0 ),
43-
new THREE.Plane( new THREE.Vector3( 0, 0, -1 ), 0 ) ]
44+
var clipPlanes = [
45+
new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 0 ),
46+
new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 0 ),
47+
new THREE.Plane( new THREE.Vector3( 0, 0, -1 ), 0 )
48+
];
4449

4550
scene.add( new THREE.AmbientLight( 0x505050 ) );
4651

47-
balls = new THREE.Object3D();
52+
group = new THREE.Object3D();
4853

49-
for ( var i = 1; i < 25; i++ ) {
50-
balls.add( new THREE.Mesh(
51-
new THREE.SphereBufferGeometry( i / 2, 48, 48),
52-
new THREE.MeshStandardMaterial( { color: new THREE.Color( Math.sin( i * 0.5 ) * 0.5 + 0.5,
53-
Math.cos( i * 1.5 ) * 0.5 + 0.5,
54-
Math.sin( i * 4.5 + 0 ) * 0.5 + 0.5 ),
55-
roughness: 0.95, metalness: 0.0, side: THREE.DoubleSide, clippingPlanes: clipPlanes, clipIntersection: true } )
56-
) );
57-
}
54+
for ( var i = 1; i < 25; i ++ ) {
55+
56+
var geometry = new THREE.SphereBufferGeometry( i / 2, 48, 48 );
57+
var material = new THREE.MeshStandardMaterial( {
58+
color: new THREE.Color( Math.sin( i * 0.5 ) * 0.5 + 0.5, Math.cos( i * 1.5 ) * 0.5 + 0.5, Math.sin( i * 4.5 + 0 ) * 0.5 + 0.5 ),
59+
roughness: 0.95,
60+
metalness: 0.0,
61+
side: THREE.DoubleSide,
62+
clippingPlanes: clipPlanes,
63+
clipIntersection: true
64+
} );
65+
group.add( new THREE.Mesh( geometry, material ) );
66+
67+
}
68+
69+
scene.add( group );
5870

59-
scene.add( balls );
60-
6171
// Renderer
6272

6373
var container = document.body;
@@ -72,7 +82,6 @@
7282
window.addEventListener( 'resize', onWindowResize, false );
7383
container.appendChild( renderer.domElement );
7484

75-
7685
// Stats
7786

7887
stats = new Stats();
@@ -84,7 +93,6 @@
8493
mode.clipIntersection = true;
8594
mode.clipPosition = 0;
8695
var gui = new dat.GUI();
87-
gui.width = 800;
8896
gui.add( mode, 'clipIntersection' ).onChange( function() {
8997
for (var i = 0; i < balls.children.length; i++) {
9098
balls.children[i].material.clipIntersection = !balls.children[i].material.clipIntersection;
@@ -119,28 +127,29 @@
119127

120128
function animate() {
121129

122-
123130
requestAnimationFrame( animate );
124131

132+
var children = group.children;
125133

126-
for ( var obj = 0; obj < balls.children.length; obj++ ) {
127-
var current = balls.children[ obj ].material;
128-
for ( var i = 0; i < current.clippingPlanes.length; i++ ) {
129-
var plane = current.clippingPlanes[ i ];
134+
for ( var i = 0; i < children.length; i ++ ) {
135+
136+
var current = children[ i ].material;
137+
138+
for ( var j = 0; j < current.clippingPlanes.length; j ++ ) {
139+
140+
var plane = current.clippingPlanes[ j ];
130141
plane.constant = ( 49 * plane.constant + mode.clipPosition ) / 50;
142+
131143
}
132-
}
133144

145+
}
134146

135147
stats.begin();
136148
renderer.render( scene, camera );
137149
stats.end();
138150

139151
}
140152

141-
init();
142-
animate();
143-
144153
</script>
145154

146155
</body>

0 commit comments

Comments
 (0)