Three.js Cylinder
HTML
<script src="http://mrdoob.github.com/three.js/build/custom/ThreeCanvas.js"></script>
<script src="http://mrdoob.github.com/three.js/build/custom/ThreeExtras.js"></script>
Click on the document to rotate cylinder
CSS
body { padding: 0; margin: 0; overflow: hidden;}
JavaScript
var currentRotation = 1;
var targetRotation = 0;
var targetRotationOnMouseDown = 0;
var mouseX = 0;
var mouseXOnMouseDown = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
function onDocumentMouseDown( event ) {
event.preventDefault();
currentRotation = (currentRotation == 1) ? .5 : 1;
}
var camera, scene, renderer,
geometry, material, mesh;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
scene.add( camera );
geometry = new THREE.CubeGeometry( 200, 200, 200 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
var radius = 100, radius_half = radius / 2;
var cyGeo= new THREE.CylinderGeometry(100, 1, 200, 50, 50, false);
/*
for(var z = 0; z< cyGeo.faces.length; z++) {
cyGeo.faceVertexUvs[ 0 ][ z ][ 0 ].u = ( cyGeo.vertices[ cyGeo.faces[ z ].a ].position.x + radius_half ) / radius;
cyGeo.faceVertexUvs[ 0 ][ z ][ 0 ].v = ( cyGeo.vertices[ cyGeo.faces[ z ].a ].position.z + radius_half ) / radius;
cyGeo.faceVertexUvs[ 0 ][ z ][ 1 ].u = ( cyGeo.vertices[ cyGeo.faces[ z ].b ].position.x + radius_half ) / radius;
cyGeo.faceVertexUvs[ 0 ][ z ][ 1 ].v = ( cyGeo.vertices[ cyGeo.faces[ z ].b ].position.z + radius_half ) / radius;
cyGeo.faceVertexUvs[ 0 ][ z ][ 2 ].u = ( cyGeo.vertices[ cyGeo.faces[ z ].c ].position.x + radius_half ) / radius;
cyGeo.faceVertexUvs[ 0 ][ z ][ 2 ].v = ( cyGeo.vertices[ cyGeo.faces[ z ].c ].position.z + radius_half ) / radius;
}*/
mesh = new THREE.Mesh( cyGeo, material );
scene.add( mesh );
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
...