JSFiddle - React, Tailwind, and code Playground
by realhunts
HTML
<script src="http://threejs.org/build/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/OrbitControls.js"></script>
JavaScript
// a basic three.js scene
var container, renderer, scene, camera, controls;
init();
animate();
function init() {
// renderer
renderer = new THREE.WebGLRenderer({
antialias: false
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xccccff);
container = document.createElement('div');
document.body.appendChild(container);
container.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 200, 800);
camera.lookAt(scene.position);
// (camera) controls
// mouse controls: left button to rotate,
// mouse wheel to zoom, right button to pan
controls = new THREE.OrbitControls(camera, renderer.domElement);
// light
var light = new THREE.PointLight(0xffffff);
light.position.set(100, 250, 250);
scene.add(light);
// mesh
var sphereGeometry = new THREE.BoxGeometry(10, 10, 100);
sphereGeometry.rotateX(90)
var sphereMaterial = new THREE.MeshLambertMaterial({
color: 0xff0000
});
var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.position.y = 100;
scene.add(sphere);
var box = new THREE.BoxHelper( sphere, 0xffff00 );
scene.add( box );
var bbox = new THREE.Box3().setFromObject(sphere);
bbox.min.sub(sphere.position);
bbox.max.sub(sphere.position);
var rbox = new THREE.Mesh(new THREE.BoxGeometry(bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y, bbox.max.z - bbox.min.z))
scene.add(rbox)
var planeGeometry = new THREE.PlaneGeometry(500, 500, 10, 10);
var planeMaterial = new THREE.MeshLambertMaterial({
color: 0x888888,
side: THREE.DoubleSide
});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.rotation.x = -Math.PI / 2;
scene.add(plane);
// events
...