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

110 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-04-09 09:35:04 +02:00
/**
* R3.D3.Geometry.Normal.Tube
* @param graphics R3.GraphicsRuntime
* @param apiGeometryNormalTube
* @constructor
*/
R3.D3.Geometry.Normal.Tube = function(
graphics,
apiGeometryNormalTube
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiGeometryNormalTube)) {
apiGeometryNormalTube = {
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE
};
}
R3.D3.API.Geometry.Normal.Tube.call(
this,
apiGeometryNormalTube,
apiGeometryNormalTube.path,
apiGeometryNormalTube.tubularSegments,
apiGeometryNormalTube.radius,
apiGeometryNormalTube.radialSegments,
apiGeometryNormalTube.closed
);
R3.D3.Geometry.Normal.call(
this,
this.graphics,
apiGeometryNormalTube
);
};
R3.D3.Geometry.Normal.Tube.prototype = Object.create(R3.D3.Geometry.Normal.prototype);
R3.D3.Geometry.Normal.Tube.prototype.constructor = R3.D3.Geometry.Normal.Tube;
/**
* Creates a light instance
* @returns {*}
*/
R3.D3.Geometry.Normal.Tube.prototype.createInstance = function() {
this.instance = new THREE.TubeGeometry(
this.path.instance,
this.tubularSegments,
this.radius,
this.radialSegments,
this.closed
);
this.computeVertexNormals();
R3.D3.Geometry.Normal.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Geometry.Normal.Tube.prototype.updateInstance = function(property) {
if (
property === 'path' ||
property === 'tubularSegments' ||
property === 'radius' ||
property === 'radialSegments' ||
property === 'closed'
) {
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.Tube to a R3.D3.API.Geometry.Normal.Tube
* @returns {R3.D3.API.Geometry.Normal}
*/
R3.D3.Geometry.Normal.Tube.prototype.toApiObject = function() {
var apiNormalGeometry = R3.D3.Geometry.Normal.prototype.toApiObject.call(this);
var apiGeometryNormalTube = new R3.D3.API.Geometry.Normal.Tube(
apiNormalGeometry,
R3.Utils.IdOrNull(this.path),
this.tubularSegments,
this.radius,
this.radialSegments,
this.closed
);
return apiGeometryNormalTube;
};