JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://threejs.org/build/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/OrbitControls.js"></script>
CSS
body {
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
// Two Scenes with the Second One on Top
// Three.js r.69
var mesh, renderer, scene, camera;
var controls;
init();
animate();
function init() {
// info
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.backgroundColor = 'transparent';
info.style.zIndex = '1'; // renderer domElement covers it up
info.style.fontFamily = 'Monospace';
info.innerHTML = 'Drag mouse to rotate camera - Example of two scenes, the second always on top';
document.body.appendChild( info );
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
renderer.autoClear = false;
// scene
scene = new THREE.Scene();
scene2 = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
1,
10000
);
camera.position.set( 50, 50, 150 );
// controls
controls = new THREE.OrbitControls( camera, renderer.domElement );
// geometry
var geometry = new THREE.PlaneGeometry( 50, 50, 1, 1 );
// material
var material = new THREE.MeshBasicMaterial({
color: 0xffffff,
side: THREE.DoubleSide
});
// mesh
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, 0, 10 );
scene.add( mesh );
// axes
var axes = new THREE.AxisHelper( 100 ); // this will be on top
scene2.add( axes );
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.clear();
renderer.render( scene, camera );
renderer.clearDepth();
renderer.render( scene2, camera );
}