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
var pivot, parent, renderer, scene, camera, controls;
var mesh1, mesh2;
var AXIS = new THREE.Vector3( 0.25, 1, 0 ).normalize();
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.fontWeight = 'bold';
info.style.backgroundColor = 'transparent';
info.style.zIndex = '1';
info.style.fontFamily = 'Monospace';
info.innerHTML = 'Drag mouse to rotate camera';
document.body.appendChild( info );
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.1, 100 );
camera.position.set( 15, 15, 15 );
// controls
controls = new THREE.OrbitControls( camera );
// axes
scene.add( new THREE.AxisHelper( 20 ) );
// geometry
var geometry = new THREE.SphereGeometry( 2, 16, 8 );
// material
var material1 = new THREE.MeshBasicMaterial( { color: 0xffff00, wireframe: true } );
var material2 = new THREE.MeshBasicMaterial( { color: 0x00aa00, wireframe: true } );
// parent
parent = new THREE.Object3D();
scene.add( parent );
// pivot
pivot = new THREE.Object3D();
parent.add( pivot );
// mesh
mesh1 = new THREE.Mesh( geometry, material1 );
mesh2 = new THREE.Mesh( geometry, material2 );
mesh2.position.x = 7;
mesh2.scale.multiplyScalar( 0.5 );
parent.add( mesh1 );
pivot.add( mesh2 );
// axes
mesh2.add( new THREE.AxisHelper( 2.5 ) );
}
function animate() {
requestAnimationFrame( animate );
mesh1.rotation.y += 0.005;
pivot.rotation.y += 0.01;
mesh2.rotateOnAxis( AXIS, 0.01 );
renderer.render( scene, camera );
}