JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://www.html5canvastutorials.com/libraries/three.min.js"></script>
<div id="container"></div>
<div class="inputRow clear" data-role="tooltip">
<div> <span>Length</span>
<input class="numeric-textbox" id="inp-cylLength" type="text" value="50">
<br/>
<br/>
</div>
<div> <span>Diameter</span>
<input class="numeric-textbox" id="inp-cylDiameter" type="text" value="40">
<br/>
<br/>
</div>
<button id="btn">Click me to change the Dimensions</button>
CSS
#container {
width: 600px;
height: 400px;
border: 1px solid black;
margin: 10px auto;
padding: 0px;
}
JavaScript
var shape = null;
//Script for 3D Cylinder
// revolutions per second
var angularSpeed = 0.1;
var lastTime = 0;
var cylinder = 0;
// this function is executed on each animation frame
function animate() {
// update
var time = (new Date()).getTime();
var timeDiff = time - lastTime;
var angleChange = angularSpeed * timeDiff * 2 * Math.PI / 1000;
cylinder.rotation.x += angleChange; //Starts Rotating Object
cylinder.rotation.y += angleChange; //Starts Rotating Object Horizontally
lastTime = time;
// render
renderer.render(scene, camera);
// request new frame
requestAnimationFrame(function () {
animate();
});
}
// renderer
var container = document.getElementById("container");
var renderer = new THREE.WebGLRenderer();
renderer.setSize(container.offsetWidth, container.offsetHeight - 4);
container.appendChild(renderer.domElement);
// camera
var camera = new THREE.PerspectiveCamera(60, container.offsetWidth / container.offsetHeight, 1, 1000);
camera.position.z = 800;
// scene
var scene = new THREE.Scene();
//===============================================================
// cylinder
// API: THREE.CylinderGeometry(bottomRadius, topRadius, height, segmentsRadius, segmentsHeight)
cylinder = new THREE.Mesh(new THREE.CylinderGeometry(1, 1, 1, 100, 100, false), new THREE.MeshPhongMaterial({
// light
specular: '#cccccc',
// intermediate
color: '#666666',
// dark
emissive: '#444444',
shininess: 100
}));
// cylinder.overdraw = true;
// cylinder.rotation.x = Math.PI * 0.1;
// cylinder.rotation.z = Math.PI * 0.5;
// cylinder.rotation.y = Math.PI * 0.25;
scene.add(cylinder);
//===============================================================
// Length line
var lengthLineGeometry = new...