<commit_before><!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - clipping planes</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				margin: 0px;
				background-color: #000000;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<script src="../build/three.js"></script>
		<script src="js/controls/OrbitControls.js"></script>
		<script src="js/libs/stats.min.js"></script>
		<script src="js/libs/dat.gui.min.js"></script>

		<script>

			var camera, scene, renderer, startTime, object, stats;
			var planes, planeObjects;
			var clock;

			var params = {

				animate: true

			};

			init();
			animate();

			function createStencilGroup( geometry, material, planes ) {

				var group = new THREE.Group();
				var baseMat = new THREE.MeshBasicMaterial();
				baseMat.depthWrite = false;
				baseMat.depthTest = false;
				baseMat.colorWrite = false;
				baseMat.clippingPlanes = planes;
				baseMat.stencilWrite = true;
				baseMat.stencilFail = THREE.AlwaysStencilFunc;

				// // front faces no depth
				// var mat0 = baseMat.clone();
				// mat0.stencilFail = THREE.IncrementWrapStencilOp;
				// mat0.stencilZFail = THREE.IncrementWrapStencilOp;
				// mat0.stencilZPass = THREE.IncrementWrapStencilOp;
				// var mesh0 = new THREE.Mesh( geometry, mat0 );
				// group.add( mesh0 );

				// // back faces no depth
				// var mat1 = baseMat.clone();
				// mat1.stencilFail = THREE.DecrementWrapStencilOp;
				// mat1.stencilZFail = THREE.DecrementWrapStencilOp;
				// mat1.stencilZPass = THREE.DecrementWrapStencilOp;
				// var mesh1 = new THREE.Mesh( geometry, mat1 );
				// group.add( mesh1 );

				// back faces
				var mat0 = baseMat.clone();
				mat0.side = THREE.BackSide;
				mat0.stencilFail = THREE.IncrementWrapStencilOp;
				mat0.stencilZFail = THREE.IncrementWrapStencilOp;
				mat0.stencilZPass = THREE.IncrementWrapStencilOp;

				var mesh0 = new THREE.Mesh( geometry, mat0 );
				mesh0.renderOrder = 1;
				group.add( mesh0 );

				// front faces
				var mat1 = material.clone();
				mat1.side = THREE.FrontSide;
				mat1.clippingPlanes = planes;
				mat1.stencilWrite = true;
				mat1.stencilFail = THREE.AlwaysStencilFunc;
				mat1.stencilFail = THREE.DecrementWrapStencilOp;
				mat1.stencilZFail = THREE.DecrementWrapStencilOp;
				mat1.stencilZPass = THREE.DecrementWrapStencilOp;

				var mesh1 = new THREE.Mesh( geometry, mat1 );
				mesh1.castShadow = true;
				mesh1.receiveShadow = true;
				mesh1.renderOrder = 1;

				group.add( mesh1 );

				console.log( mat0, mat1 )

				return group;

			}

			function init() {

				clock = new THREE.Clock();

				camera = new THREE.PerspectiveCamera( 36, window.innerWidth / window.innerHeight, 1 );

				camera.position.set( 0, 1.3, 3 );

				scene = new THREE.Scene();

				scene.add( new THREE.AmbientLight( 0xffffff, 0.5 ) );

				var dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
				dirLight.position.set( 5, 10, 5 );
				dirLight.castShadow = true;
				dirLight.shadow.camera.right = 2;
				dirLight.shadow.camera.left = - 2;
				dirLight.shadow.camera.top	= 2;
				dirLight.shadow.camera.bottom = - 2;

				dirLight.shadow.mapSize.width = 1024;
				dirLight.shadow.mapSize.height = 1024;
				scene.add( dirLight );

				planes = [
					new THREE.Plane( new THREE.Vector3( 0, - 1, 0 ), 0 ),
					new THREE.Plane( new THREE.Vector3( - 1, 0, 0 ), 0 ),
					new THREE.Plane( new THREE.Vector3( 0, 0, - 1 ), 0 )
				];

				planeObjects = new Array( 3 );
				var planeGeom = new THREE.PlaneBufferGeometry( 10, 10 );
				for ( var i = 0; i < planes.length; i ++ ) {

					var plane = planes[ i ];
					var planeMat =
						new THREE.MeshStandardMaterial( {
							color: 0xE91E63,
							metalness: 0.1,
							roughness: 0.75,
							side: THREE.DoubleSide,
							clippingPlanes: planes.filter( p => p !== plane ),
							clipShadows: true,

							stencilWrite: true,
							stencilRef: 0,
							stencilFunc: THREE.NotEqualStencilFunc,

						} );
					var po = new THREE.Mesh( planeGeom, planeMat );
					po.renderOrder = 2;

					scene.add( po );
					planeObjects[ i ] = po;

				}

				// Geometry

				var material = new THREE.MeshStandardMaterial( {
					color: 0xFFC107,
					metalness: 0.1,
					roughness: 0.75,
					side: THREE.DoubleSide,
					clippingPlanes: planes,
					clipShadows: true
				} );

				var geometry = new THREE.TorusKnotBufferGeometry( 0.4, 0.15, 220, 60 );
				object = createStencilGroup( geometry, material, planes );
				scene.add( object );



				var ground = new THREE.Mesh(
					new THREE.PlaneBufferGeometry( 9, 9, 1, 1 ),
					new THREE.ShadowMaterial( { color: 0, opacity: 0.25, side: THREE.DoubleSide } )
				);

				ground.rotation.x = - Math.PI / 2; // rotates X/Y to X/Z
				ground.position.y = - 1;
				ground.receiveShadow = true;
				scene.add( ground );

				// Stats

				stats = new Stats();
				document.body.appendChild( stats.dom );

				// Renderer

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.shadowMap.enabled = true;
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				renderer.setClearColor( 0x263238 );
				window.addEventListener( 'resize', onWindowResize, false );
				document.body.appendChild( renderer.domElement );

				renderer.localClippingEnabled = true;

				// Controls

				var controls = new THREE.OrbitControls( camera, renderer.domElement );
				controls.update();

				// GUI

				var gui = new dat.GUI();
				gui.add( params, 'animate' );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

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

			}

			function animate() {

				var delta = clock.getDelta();

				requestAnimationFrame( animate );

				if ( params.animate ) {

					object.rotation.x += delta * 0.5;
					object.rotation.y += delta * 0.2;

				}

				for ( var i = 0; i < planes.length; i ++ ) {

					var plane = planes[ i ];
					var po = planeObjects[ i ];
					plane.coplanarPoint( po.position );
					po.lookAt(
						po.position.x + plane.normal.x,
						po.position.y + plane.normal.y,
						po.position.z + plane.normal.z,
					);

				}

				stats.begin();
				renderer.render( scene, camera );
				stats.end();

			}

		</script>

	</body>
</html><commit_msg>Render all clip planes<commit_after><!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - clipping planes</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				margin: 0px;
				background-color: #000000;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<script src="../build/three.js"></script>
		<script src="js/controls/OrbitControls.js"></script>
		<script src="js/libs/stats.min.js"></script>
		<script src="js/libs/dat.gui.min.js"></script>

		<script>

			var camera, scene, renderer, startTime, object, stats;
			var planes, planeObjects;
			var clock;

			var params = {

				animate: true

			};

			init();
			animate();

			function createPlaneStencilGroup( geometry, plane, renderOrder ) {

				var group = new THREE.Group();
				var baseMat = new THREE.MeshBasicMaterial();
				baseMat.depthWrite = false;
				baseMat.depthTest = false;
				baseMat.colorWrite = false;
				baseMat.clippingPlanes = [ plane ];
				baseMat.stencilWrite = true;
				baseMat.stencilFunc = THREE.AlwaysStencilFunc;

				// back faces
				var mat0 = baseMat.clone();
				mat0.side = THREE.BackSide;
				mat0.stencilFail = THREE.IncrementWrapStencilOp;
				mat0.stencilZFail = THREE.IncrementWrapStencilOp;
				mat0.stencilZPass = THREE.IncrementWrapStencilOp;

				var mesh0 = new THREE.Mesh( geometry, mat0 );
				mesh0.renderOrder = renderOrder;
				group.add( mesh0 );

				// front faces
				var mat1 = baseMat.clone();
				mat1.side = THREE.FrontSide;
				mat1.stencilFail = THREE.DecrementWrapStencilOp;
				mat1.stencilZFail = THREE.DecrementWrapStencilOp;
				mat1.stencilZPass = THREE.DecrementWrapStencilOp;

				var mesh1 = new THREE.Mesh( geometry, mat1 );
				mesh1.castShadow = true;
				mesh1.receiveShadow = true;
				mesh1.renderOrder = renderOrder;

				group.add( mesh1 );

				console.log( mat0, mat1 )

				return group;

			}

			function init() {

				clock = new THREE.Clock();

				camera = new THREE.PerspectiveCamera( 36, window.innerWidth / window.innerHeight, 1 );

				camera.position.set( 0, 1.3, 3 );

				scene = new THREE.Scene();

				scene.add( new THREE.AmbientLight( 0xffffff, 0.5 ) );

				var dirLight = new THREE.DirectionalLight( 0xffffff, 1 );
				dirLight.position.set( 5, 10, 5 );
				dirLight.castShadow = true;
				dirLight.shadow.camera.right = 2;
				dirLight.shadow.camera.left = - 2;
				dirLight.shadow.camera.top	= 2;
				dirLight.shadow.camera.bottom = - 2;

				dirLight.shadow.mapSize.width = 1024;
				dirLight.shadow.mapSize.height = 1024;
				scene.add( dirLight );

				planes = [
					new THREE.Plane( new THREE.Vector3( 0, - 1, 0 ), 0 ),
					new THREE.Plane( new THREE.Vector3( - 1, 0, 0 ), 0 ),
					new THREE.Plane( new THREE.Vector3( 0, 0, - 1 ), 0 )
				];

				var material = new THREE.MeshStandardMaterial( {
					color: 0xFFC107,
					metalness: 0.1,
					roughness: 0.75,
					side: THREE.DoubleSide,
					clippingPlanes: planes,
					clipShadows: true
				} );

				var geometry = new THREE.TorusKnotBufferGeometry( 0.4, 0.15, 220, 60 );
				object = new THREE.Group();
				object.add( new THREE.Mesh( geometry, material ) );
				scene.add( object );

				planeObjects = [];
				var planeGeom = new THREE.PlaneBufferGeometry( 10, 10 );
				for ( var i = 0; i < 3; i ++ ) {

					var plane = planes[ i ];
					var stencilGroup = createPlaneStencilGroup( geometry, plane, i + 1 )

					var planeMat =
						new THREE.MeshStandardMaterial( {
							color: 0xE91E63,
							metalness: 0.1,
							roughness: 0.75,
							clippingPlanes: planes.filter( p => p !== plane ),
							clipShadows: true,

							stencilWrite: true,
							stencilRef: 0,
							stencilFunc: THREE.NotEqualStencilFunc,
							stencilFail: THREE.ReplaceStencilOp,
							stencilZFail: THREE.ReplaceStencilOp,
							stencilZPass: THREE.ReplaceStencilOp,

						} );
					var po = new THREE.Mesh( planeGeom, planeMat );
					po.onAfterRender = function( renderer ) {
						renderer.clearStencil();
					};
					po.renderOrder = i + 1.5;

					object.add( stencilGroup );
					scene.add( po );
					planeObjects.push( po );

				}

				// Geometry




				var ground = new THREE.Mesh(
					new THREE.PlaneBufferGeometry( 9, 9, 1, 1 ),
					new THREE.ShadowMaterial( { color: 0, opacity: 0.25, side: THREE.DoubleSide } )
				);

				ground.rotation.x = - Math.PI / 2; // rotates X/Y to X/Z
				ground.position.y = - 1;
				ground.receiveShadow = true;
				scene.add( ground );

				// Stats

				stats = new Stats();
				document.body.appendChild( stats.dom );

				// Renderer

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.shadowMap.enabled = true;
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				renderer.setClearColor( 0x263238 );
				window.addEventListener( 'resize', onWindowResize, false );
				document.body.appendChild( renderer.domElement );

				renderer.localClippingEnabled = true;

				// Controls

				var controls = new THREE.OrbitControls( camera, renderer.domElement );
				controls.update();

				// GUI

				var gui = new dat.GUI();
				gui.add( params, 'animate' );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

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

			}

			function animate() {

				var delta = clock.getDelta();

				requestAnimationFrame( animate );

				if ( params.animate ) {

					object.rotation.x += delta * 0.5;
					object.rotation.y += delta * 0.2;

				}

				for ( var i = 0; i < planeObjects.length; i ++ ) {

					var plane = planes[ i ];
					var po = planeObjects[ i ];
					plane.coplanarPoint( po.position );
					po.lookAt(
						po.position.x - plane.normal.x,
						po.position.y - plane.normal.y,
						po.position.z - plane.normal.z,
					);

				}

				stats.begin();
				renderer.render( scene, camera );
				stats.end();

			}

		</script>

	</body>
</html>
{'fraction_non_alphanumeric': 0.13136771835015498, 'fraction_numerical': 0.023285385043312404, 'mean_word_length': 2.633843488304938, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '231634', 'n_tokens_mistral': 5661, 'n_tokens_neox': 4125, 'n_words': 933}