JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://raw.github.com/mrdoob/three.js/master/build/three.js"></script>
<script src="https://raw.github.com/mrdoob/three.js/master/examples/js/controls/OrbitControls.js"></script>
CSS
body {
font-family: Monospace;
color: #fff;
background-color: #000;
margin: 0px;
overflow: hidden;
}
/*
parameters = {
*
* size: <float>, // size of the text
* height: <float>, // thickness to extrude text
* curveSegments: <int>, // number of points on the curves
* steps: <int>, // number of points for z-side extrusions
*
* font: <string>, // font name
* weight: <string>, // font weight (normal, bold)
* style: <string>, // font style (normal, italics)
*
* bevelEnabled: <bool>, // turn on bevel
* bevelThickness: <float>, // how deep into text bevel goes
* bevelSize: <float>, // how far from text outline is bevel
* bevelSegments: <int>, // number of bevel layers
*
* extrudePath: <THREE.CurvePath> // path to extrude shape along
* bendPath: <THREE.CurvePath> // path to bend the geometry around
*
* material: <THREE.Material> // material for front and back faces
* extrudeMaterial: <THREE.Material> // material for extrusion and beveled faces
*
*/
JavaScript
// Picking with Callback
// three.js r.52
var container,
info,
camera,
scene,
light,
geometry,
mesh,
projector,
renderer,
controls;
objects = [];
// dom
container = document.createElement( 'div' );
document.body.appendChild( container );
// info
info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = "drag to rotate camera; click to select";
container.appendChild( info );
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
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, 300, 500 );
scene.add( camera );
// controls
controls = new THREE.OrbitControls( camera );
// light
scene.add( new THREE.AmbientLight( 0x222222 ) );
// light
light = new THREE.PointLight( 0xaaaaaa );
light.position = camera.position;
scene.add( light );
// geometry
geometry = new THREE.CubeGeometry( 100, 100, 100 );
// material
material = new THREE.MeshLambertMaterial( { color: 0xff0000, ambient: 0xff0000, overdraw: true } );
// mesh
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( -50,0,0 );
mesh.name = "Red Object";
mesh.callback = function() { info.innerHTML = this.name; }
scene.add( mesh );
objects.push( mesh );
// geometry
////////////
// CUSTOM //
////////////
var starPoints2 = new...