JSFiddle - React, Tailwind, and code Playground
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>
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 - cut a THREE.BoxGeometry VS cut a native BSP box geometry";
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();
// ambient light
var ambient = new THREE.AmbientLight(0x404040);
scene.add(ambient);
// directional light
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(-1, -1, 1);
scene.add(directionalLight);
// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 500);
camera.position.set(100, -100, 50);
camera.up.set(0, 0, 1);
camera.lookAt(new THREE.Vector3(0, 0, 0));
// controls
controls = new THREE.OrbitControls(camera);
var result, geometry, mesh, wireframe, material = new THREE.MeshPhongMaterial({
color: 0xff0000,
shading: THREE.FlatShading
});
// Add plane and box to the scene to show what we are subtracting
var mesh = new THREE.Mesh( getThreeBoxGeometry(), material );
mesh.position.setX( -30 );
scene.add( mesh);
wireframe = new THREE.WireframeHelper( mesh, 0xffffff );
scene.add( wireframe );
var planeGeometry = getThreePlaneGeometry();
var planeMaterial = new THREE.MeshBasicMaterial({
transparent: true,
color: 0xffffff,
opacity: 0.5,
side:...