r3-legacy/src/r3-d3-geometry-buffer-cylin...

122 lines
3.2 KiB
JavaScript
Raw Normal View History

2018-04-09 09:35:04 +02:00
/**
* R3.D3.Geometry.Buffer.Cylinder
* @param graphics R3.GraphicsRuntime
* @param apiGeometryBufferCylinder
* @constructor
*/
R3.D3.Geometry.Buffer.Cylinder = function(
graphics,
apiGeometryBufferCylinder
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiGeometryBufferCylinder)) {
apiGeometryBufferCylinder = {
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER
};
}
R3.D3.API.Geometry.Buffer.Cylinder.call(
this,
apiGeometryBufferCylinder,
apiGeometryBufferCylinder.radiusTop,
apiGeometryBufferCylinder.radiusBottom,
apiGeometryBufferCylinder.height,
apiGeometryBufferCylinder.radialSegments,
apiGeometryBufferCylinder.heightSegments,
apiGeometryBufferCylinder.openEnded,
apiGeometryBufferCylinder.thetaStart,
apiGeometryBufferCylinder.thetaLength
);
R3.D3.Geometry.Buffer.call(
this,
this.graphics,
apiGeometryBufferCylinder
);
};
R3.D3.Geometry.Buffer.Cylinder.prototype = Object.create(R3.D3.Geometry.Buffer.prototype);
R3.D3.Geometry.Buffer.Cylinder.prototype.constructor = R3.D3.Geometry.Buffer.Cylinder;
/**
* Creates a light instance
* @returns {*}
*/
R3.D3.Geometry.Buffer.Cylinder.prototype.createInstance = function() {
this.instance = new THREE.CylinderBufferGeometry(
this.radiusTop,
this.radiusBottom,
this.height,
this.radialSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
this.computeVertexNormals();
R3.D3.Geometry.Buffer.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Geometry.Buffer.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;
}
R3.D3.Geometry.Buffer.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Geometry.Buffer.Cylinder to a R3.D3.API.Geometry.Buffer.Cylinder
* @returns {R3.D3.API.Geometry.Buffer}
*/
R3.D3.Geometry.Buffer.Cylinder.prototype.toApiObject = function() {
var apiBufferGeometry = R3.D3.Geometry.Buffer.prototype.toApiObject.call(this);
var apiGeometryBufferCylinder = new R3.D3.API.Geometry.Buffer.Cylinder(
apiBufferGeometry,
this.radiusTop,
this.radiusBottom,
this.height,
this.radialSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
return apiGeometryBufferCylinder;
};