146 lines
3.7 KiB
JavaScript
146 lines
3.7 KiB
JavaScript
|
/**
|
||
|
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||
|
* @param graphics GameLib.GraphicsRuntime
|
||
|
* @param apiMeshCylinder
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.Mesh.Cylinder = function (
|
||
|
graphics,
|
||
|
apiMeshCylinder
|
||
|
) {
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(apiMeshCylinder)) {
|
||
|
apiMeshCylinder = {
|
||
|
meshType : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||
|
};
|
||
|
}
|
||
|
|
||
|
GameLib.D3.API.Mesh.Cylinder.call(
|
||
|
this,
|
||
|
apiMeshCylinder,
|
||
|
apiMeshCylinder.radiusTop,
|
||
|
apiMeshCylinder.radiusBottom,
|
||
|
apiMeshCylinder.height,
|
||
|
apiMeshCylinder.radiusSegments,
|
||
|
apiMeshCylinder.heightSegments,
|
||
|
apiMeshCylinder.openEnded,
|
||
|
apiMeshCylinder.thetaStart,
|
||
|
apiMeshCylinder.thetaLength
|
||
|
);
|
||
|
|
||
|
GameLib.D3.Mesh.call(
|
||
|
this,
|
||
|
graphics,
|
||
|
this
|
||
|
);
|
||
|
};
|
||
|
|
||
|
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);
|
||
|
};
|
||
|
|
||
|
GameLib.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;
|
||
|
}
|
||
|
|
||
|
GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a GameLib.D3.Mesh.Cylinder to a GameLib.D3.API.Mesh.Cylinder
|
||
|
* @returns {GameLib.D3.API.Mesh.Cylinder}
|
||
|
*/
|
||
|
GameLib.D3.Mesh.Cylinder.prototype.toApiObject = function() {
|
||
|
|
||
|
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
|
||
|
|
||
|
var apiMeshCylinder = new GameLib.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
|
||
|
*/
|
||
|
GameLib.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 GameLib.D3.Material(this.graphics)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
this.updateInstance('materials');
|
||
|
|
||
|
};
|