r3-legacy/src/game-lib-d3-geometry-normal...

122 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-02-11 16:57:28 +01:00
/**
* GameLib.D3.Geometry.Normal.Cylinder
* @param graphics GameLib.GraphicsRuntime
* @param apiGeometryNormalCylinder
* @constructor
*/
GameLib.D3.Geometry.Normal.Cylinder = function(
graphics,
apiGeometryNormalCylinder
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiGeometryNormalCylinder)) {
apiGeometryNormalCylinder = {
geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER
};
}
GameLib.D3.API.Geometry.Normal.Cylinder.call(
this,
apiGeometryNormalCylinder,
apiGeometryNormalCylinder.radiusTop,
apiGeometryNormalCylinder.radiusBottom,
apiGeometryNormalCylinder.height,
apiGeometryNormalCylinder.radialSegments,
apiGeometryNormalCylinder.heightSegments,
apiGeometryNormalCylinder.openEnded,
apiGeometryNormalCylinder.thetaStart,
apiGeometryNormalCylinder.thetaLength
);
GameLib.D3.Geometry.Normal.call(
this,
this.graphics,
apiGeometryNormalCylinder
);
};
GameLib.D3.Geometry.Normal.Cylinder.prototype = Object.create(GameLib.D3.Geometry.Normal.prototype);
GameLib.D3.Geometry.Normal.Cylinder.prototype.constructor = GameLib.D3.Geometry.Normal.Cylinder;
/**
* Creates a light instance
* @returns {*}
*/
GameLib.D3.Geometry.Normal.Cylinder.prototype.createInstance = function() {
this.instance = new THREE.CylinderGeometry(
this.radiusTop,
this.radiusBottom,
this.height,
this.radialSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
this.computeVertexNormals();
GameLib.D3.Geometry.Normal.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Geometry.Normal.Cylinder.prototype.updateInstance = function(property) {
if (
property === 'radiusTop' ||
property === 'radiusBottom' ||
property === 'height' ||
property === 'radialSegments' ||
property === 'heightSegments' ||
property === 'openEnded' ||
property === 'thetaStart' ||
property === 'thetaLength'
) {
this.instance.dispose();
this.createInstance();
if (this.parentMesh && this.parentMesh.instance) {
this.parentMesh.instance.geometry = this.instance;
if (this.parentMesh.helper) {
this.parentMesh.removeHelper();
this.parentMesh.createHelper();
}
}
return;
}
GameLib.D3.Geometry.Normal.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Geometry.Normal.Cylinder to a GameLib.D3.API.Geometry.Normal.Cylinder
* @returns {GameLib.D3.API.Geometry.Normal}
*/
GameLib.D3.Geometry.Normal.Cylinder.prototype.toApiObject = function() {
var apiNormalGeometry = GameLib.D3.Geometry.Normal.prototype.toApiObject.call(this);
var apiGeometryNormalCylinder = new GameLib.D3.API.Geometry.Normal.Cylinder(
apiNormalGeometry,
this.radiusTop,
this.radiusBottom,
this.height,
this.radialSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
return apiGeometryNormalCylinder;
};