r3-legacy/src/r3-d3-geometry-normal-ring.js

114 lines
2.8 KiB
JavaScript

/**
* R3.D3.Geometry.Normal.Ring
* @param graphics R3.Runtime.Graphics
* @param apiGeometryNormalRing
* @constructor
*/
R3.D3.Geometry.Normal.Ring = function(
graphics,
apiGeometryNormalRing
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiGeometryNormalRing)) {
apiGeometryNormalRing = {
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING
};
}
R3.D3.API.Geometry.Normal.Ring.call(
this,
apiGeometryNormalRing,
apiGeometryNormalRing.innerRadius,
apiGeometryNormalRing.outerRadius,
apiGeometryNormalRing.thetaSegments,
apiGeometryNormalRing.phiSegments,
apiGeometryNormalRing.thetaStart,
apiGeometryNormalRing.thetaLength
);
R3.D3.Geometry.Normal.call(
this,
this.graphics,
apiGeometryNormalRing
);
};
R3.D3.Geometry.Normal.Ring.prototype = Object.create(R3.D3.Geometry.Normal.prototype);
R3.D3.Geometry.Normal.Ring.prototype.constructor = R3.D3.Geometry.Normal.Ring;
/**
* Creates a light instance
* @returns {*}
*/
R3.D3.Geometry.Normal.Ring.prototype.createInstance = function() {
this.instance = new THREE.RingGeometry(
this.innerRadius,
this.outerRadius,
this.thetaSegments,
this.phiSegments,
this.thetaStart,
this.thetaLength
);
this.computeVertexNormals();
R3.D3.Geometry.Normal.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Geometry.Normal.Ring.prototype.updateInstance = function(property) {
if (
property === 'innerRadius' ||
property === 'outerRadius' ||
property === 'thetaSegments' ||
property === 'phiSegments' ||
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.Normal.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Geometry.Normal.Ring to a R3.D3.API.Geometry.Normal.Ring
* @returns {R3.D3.API.Geometry.Normal}
*/
R3.D3.Geometry.Normal.Ring.prototype.toApiObject = function() {
var apiNormalGeometry = R3.D3.Geometry.Normal.prototype.toApiObject.call(this);
var apiGeometryNormalRing = new R3.D3.API.Geometry.Normal.Ring(
apiNormalGeometry,
this.innerRadius,
this.outerRadius,
this.thetaSegments,
this.phiSegments,
this.thetaStart,
this.thetaLength
);
return apiGeometryNormalRing;
};