Question: Three.js and java programming Think of the cylinder above as consisting of a single segment. We can also have multisegment cylinders. Write a function createSegmentedCylinder(n,

Three.js and java programming

Think of the cylinder above as consisting of a single segment. We can also have multisegment cylinders.

Write a function createSegmentedCylinder(n, nbrSegments, segmentLen, rad, isCappedBottom, isCappedTop) that returns the geometry of an n-sided cylinder of nbrSegments many segments. The cylinder has radius rad and sits on the xz-plane extending along the y-axis; each segment has length segmentLen. The sides of the cylinder has nnbrSegments many quadrilateral faces, hence twice that many Face3 triangles. The geometry of the image below was made with this code:

var nbrSegments = 15; var n = 12; var geom = createSegmentedCylinder(n, nbrSegments, 0.5, 2, true, true); 

Colors were assigned per-face using a MeshFaceMaterial.

function animate() { window.requestAnimationFrame(animate); render(); }

function render() { var delta = clock.getDelta(); cameraControls.update(delta); renderer.render(scene, camera); }

function addToDOM() { var container = document.getElementById('container'); var canvas = container.getElementsByTagName('canvas'); if (canvas.length>0) { container.removeChild(canvas[0]); } container.appendChild( renderer.domElement ); }

try { init(); createScene(); addToDOM(); render(); animate(); } catch(e) { var errorMsg = "Error: " + e; document.getElementById("msg").innerHTML = errorMsg; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!