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

110 lines
2.8 KiB
JavaScript

/**
* GameLib.D3.Geometry.Normal.Torus
* @param graphics GameLib.GraphicsRuntime
* @param apiGeometryNormalTorus
* @constructor
*/
GameLib.D3.Geometry.Normal.Torus = function(
graphics,
apiGeometryNormalTorus
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiGeometryNormalTorus)) {
apiGeometryNormalTorus = {
geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS
};
}
GameLib.D3.API.Geometry.Normal.Torus.call(
this,
apiGeometryNormalTorus,
apiGeometryNormalTorus.radius,
apiGeometryNormalTorus.tube,
apiGeometryNormalTorus.radialSegments,
apiGeometryNormalTorus.tubularSegments,
apiGeometryNormalTorus.arc
);
GameLib.D3.Geometry.Normal.call(
this,
this.graphics,
apiGeometryNormalTorus
);
};
GameLib.D3.Geometry.Normal.Torus.prototype = Object.create(GameLib.D3.Geometry.Normal.prototype);
GameLib.D3.Geometry.Normal.Torus.prototype.constructor = GameLib.D3.Geometry.Normal.Torus;
/**
* Creates a light instance
* @returns {*}
*/
GameLib.D3.Geometry.Normal.Torus.prototype.createInstance = function() {
this.instance = new THREE.TorusGeometry(
this.radius,
this.tube,
this.radialSegments,
this.tubularSegments,
this.arc
);
this.computeVertexNormals();
GameLib.D3.Geometry.Normal.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Geometry.Normal.Torus.prototype.updateInstance = function(property) {
if (
property === 'radius' ||
property === 'tube' ||
property === 'radialSegments' ||
property === 'tubularSegments' ||
property === 'arc'
) {
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.Torus to a GameLib.D3.API.Geometry.Normal.Torus
* @returns {GameLib.D3.API.Geometry.Normal}
*/
GameLib.D3.Geometry.Normal.Torus.prototype.toApiObject = function() {
var apiNormalGeometry = GameLib.D3.Geometry.Normal.prototype.toApiObject.call(this);
var apiGeometryNormalTorus = new GameLib.D3.API.Geometry.Normal.Torus(
apiNormalGeometry,
this.radius,
this.tube,
this.radialSegments,
this.tubularSegments,
this.arc
);
return apiGeometryNormalTorus;
};