/** * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * @param graphics GameLib.D3.Graphics * @param apiMesh GameLib.D3.API.Mesh * @param radiusTop * @param radiusBottom * @param height * @param radiusSegments * @param heightSegments * @param openEnded * @param thetaStart * @param thetaLength * @constructor */ GameLib.D3.Mesh.Cylinder = function ( graphics, apiMesh, radiusTop, radiusBottom, height, radiusSegments, heightSegments, openEnded, thetaStart, thetaLength ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { apiMesh = {}; } if (apiMesh instanceof GameLib.D3.Mesh.Box) { return apiMesh; } apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_CYLINDER; if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } this.radiusTop = radiusTop; if (GameLib.Utils.UndefinedOrNull(radiusBottom)) { radiusBottom = 1; } this.radiusBottom = radiusBottom; if (GameLib.Utils.UndefinedOrNull(height)) { height = 5; } this.height = height; if (GameLib.Utils.UndefinedOrNull(radiusSegments)) { radiusSegments = 10; } this.radiusSegments = radiusSegments; if (GameLib.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 10; } this.heightSegments = heightSegments; if (GameLib.Utils.UndefinedOrNull(openEnded)) { openEnded = false; } this.openEnded = openEnded; if (GameLib.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; if (GameLib.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; GameLib.D3.Mesh.call( this, this.graphics, apiMesh ); }; GameLib.D3.Mesh.Cylinder.prototype = Object.create(GameLib.D3.Mesh.prototype); GameLib.D3.Mesh.Cylinder.prototype.constructor = GameLib.D3.Mesh.Cylinder; GameLib.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); } GameLib.D3.Mesh.prototype.createInstance.call(this); this.instance.userData.radiusTop = this.radiusTop; this.instance.userData.radiusBottom = this.radiusBottom; this.instance.userData.height = this.height; this.instance.userData.radiusSegments = this.radiusSegments; this.instance.userData.heightSegments = this.heightSegments; this.instance.userData.openEnded = this.openEnded; this.instance.userData.thetaStart = this.thetaStart; this.instance.userData.thetaLength = this.thetaLength; }; GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function() { if ( this.instance.userData.radiusTop !== this.radiusTop || this.instance.userData.radiusBottom !== this.radiusBottom || this.instance.userData.height !== this.height || this.instance.userData.radiusSegments !== this.radiusSegments || this.instance.userData.heightSegments !== this.heightSegments || this.instance.userData.openEnded !== this.openEnded || this.instance.userData.thetaStart !== this.thetaStart || this.instance.userData.thetaLength !== this.thetaLength ) { this.instance.userData.radiusTop = this.radiusTop; this.instance.userData.radiusBottom = this.radiusBottom; this.instance.userData.height = this.height; this.instance.userData.radiusSegments = this.radiusSegments; this.instance.userData.heightSegments = this.heightSegments; this.instance.userData.openEnded = this.openEnded; this.instance.userData.thetaStart = this.thetaStart; this.instance.userData.thetaLength = this.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; } GameLib.D3.Mesh.prototype.updateInstance.call(this); }; /** * Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh * @returns {GameLib.D3.API.Mesh} */ GameLib.D3.Mesh.Cylinder.prototype.toApiObject = function() { var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); apiMesh.radiusTop = this.radiusTop; apiMesh.radiusBottom = this.radiusBottom; apiMesh.height = this.height; apiMesh.radiusSegments = this.radiusSegments; apiMesh.heightSegments = this.heightSegments; apiMesh.openEnded = this.openEnded; apiMesh.thetaStart = this.thetaStart; apiMesh.thetaLength = this.thetaLength; return apiMesh; }; /** * Converts a standard object mesh to a GameLib.D3.Mesh * @param graphics GameLib.D3.Graphics * @param objectMesh {Object} * @constructor */ GameLib.D3.Mesh.Cylinder.FromObject = function(graphics, objectMesh) { var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); return new GameLib.D3.Mesh.Cylinder( graphics, apiMesh, objectMesh.radiusTop, objectMesh.radiusBottom, objectMesh.height, objectMesh.radiusSegments, objectMesh.heightSegments, objectMesh.openEnded, objectMesh.thetaStart, objectMesh.thetaLength ); };