/** * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * @param graphics R3.GraphicsRuntime * @param apiMeshCylinder * @constructor */ R3.D3.Mesh.Cylinder = function ( graphics, apiMeshCylinder ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (R3.Utils.UndefinedOrNull(apiMeshCylinder)) { apiMeshCylinder = { meshType : R3.D3.API.Mesh.MESH_TYPE_CYLINDER }; } R3.D3.API.Mesh.Cylinder.call( this, apiMeshCylinder, apiMeshCylinder.radiusTop, apiMeshCylinder.radiusBottom, apiMeshCylinder.height, apiMeshCylinder.radiusSegments, apiMeshCylinder.heightSegments, apiMeshCylinder.openEnded, apiMeshCylinder.thetaStart, apiMeshCylinder.thetaLength ); R3.D3.Mesh.call( this, graphics, this ); }; R3.D3.Mesh.Cylinder.prototype = Object.create(R3.D3.Mesh.prototype); R3.D3.Mesh.Cylinder.prototype.constructor = R3.D3.Mesh.Cylinder; R3.D3.Mesh.Cylinder.prototype.createInstance = function() { var geometry = null; if (this.vertices.length === 0) { geometry = new THREE.CylinderGeometry( this.radiusTop, this.radiusBottom, this.height, this.radiusSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength ); this.updateVerticesFromGeometryInstance(geometry); } R3.D3.Mesh.prototype.createInstance.call(this); }; R3.D3.Mesh.Cylinder.prototype.updateInstance = function(property) { if ( property === 'radiusTop' || property === 'radiusBottom' || property === 'height' || property === 'radiusSegments' || property === 'heightSegments' || property === 'openEnded' || property === 'thetaStart' || property === 'thetaLength' ) { var geometry = new THREE.CylinderGeometry( this.radiusTop, this.radiusBottom, this.height, this.radiusSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength ); this.updateVerticesFromGeometryInstance(geometry); geometry = this.createInstanceGeometry(); this.instance.geometry = geometry; } R3.D3.Mesh.prototype.updateInstance.call(this, property); }; /** * Converts a R3.D3.Mesh.Cylinder to a R3.D3.API.Mesh.Cylinder * @returns {R3.D3.API.Mesh.Cylinder} */ R3.D3.Mesh.Cylinder.prototype.toApiObject = function() { var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this); var apiMeshCylinder = new R3.D3.API.Mesh.Cylinder( apiMesh, this.radiusTop, this.radiusBottom, this.height, this.radiusSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength ); return apiMeshCylinder; }; /** * This function turns the cylinder into a 'display' where each plane on the cylinder is mapped onto a flat texture */ R3.D3.Mesh.Cylinder.prototype.turnIntoDisplay = function() { this.heightSegments = 1; this.updateInstance('heightSegments'); this.openEnded = true; this.updateInstance('openEnded'); this.materials.map( function(material){ material.remove(); } ); this.materials = []; for (var i = 0; i < this.radiusSegments; i++) { this.materials.push( new R3.D3.Material(this.graphics) ) } this.updateInstance('materials'); };