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 - rotation direction";
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);
// material
var blueMaterial = new THREE.MeshPhongMaterial({
color: 0x0000ff,
flatShading: true
});
var redMaterial = new THREE.MeshPhongMaterial({
color: 0xff0000,
flatShading: true
});
// geometry
var geometry = new THREE.BoxGeometry(20, 20, 20);
// blue mesh
blue = new THREE.Mesh(geometry, blueMaterial);
scene.add(blue);
// red mesh
red = new THREE.Mesh(geometry, redMaterial);
scene.add(red);
red.position.z += 30;
scene.add(red);
}
function rotate() {
blue.rotation.z += 0.01;
red.rotation.z -= 0.01;
}
// render
function render() {
renderer.render(scene,...