BoundingBox empty test

by wilt

HTML

<script src="https://rawgit.com/mrdoob/three.js/master/build/three.js"></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/OrbitControls.js"></script>
<script src="https://rawgit.com/Wilt/ThreeCSG/master/ThreeCSG.js"></script>
<script>
THREE.Box3.prototype.isEmpty = function () {

		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes

		return ( this.max.x <= this.min.x ) || ( this.max.y <= this.min.y ) || ( this.max.z <= this.min.z );

	};
</script>

CSS

body {
  background-color: #000;
  margin: 0px;
  overflow: hidden;
}

JavaScript

// three.js info box follows shape
var renderer, scene, camera;
var angle = 0;

init();
animate();

function init() {
  // info
  var info = document.createElement('div');
  info.style.position = 'absolute';
  info.style.top = '30px';
  info.style.width = '100%';
  info.style.textAlign = 'center';
  info.style.color = '#fff';
  info.style.fontWeight = 'bold';
  info.style.backgroundColor = 'transparent';
  info.style.zIndex = '1';
  info.style.fontFamily = 'Monospace';
  info.innerHTML = "three.js - Material shine through";
  document.body.appendChild(info);

  // renderer
  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  renderer.setPixelRatio(window.devicePixelRatio);
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  // scene
  scene = new THREE.Scene();

  // camera
  camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 150000);
  camera.position.set(-55000, -55000, -55000);
  camera.up.set(0, 0, 1);

  // controls
  controls = new THREE.OrbitControls(camera);
  controls.mouseButtons = {ORBIT: THREE.MOUSE.LEFT, PAN: THREE.MOUSE.MIDDLE};
  controls.target = new THREE.Vector3(0, 0, 0);
  controls.update();

  // material1
  material1 = new THREE.MeshBasicMaterial({
    color: 0xff0000
  });

  // material2
  material2 = new THREE.MeshBasicMaterial({
    color: 0xffffff
  });

  // geometry
  var geometry = new THREE.BoxGeometry(20000, 20000, 1);

  // mesh
  var mesh1 = new THREE.Mesh(geometry, material1);
  mesh1.position.set(0, 0, 2)
  scene.add(mesh1);

  // mesh
  var mesh2 = new THREE.Mesh(geometry, material2);
  mesh2.position.set(0, 0, 0)
  scene.add(mesh2);
  material1.blending = 3;
  material2.blending = 3;
  console.log( material1 );
}


// render
function render() {
//console.log( camera.position.x );
  renderer.render(scene, camera);
}

// animate
function animate() {
  requestAnimationFrame(animate);
  render();
}