119 lines
3.0 KiB
JavaScript
119 lines
3.0 KiB
JavaScript
/**
|
|
* GameLib.D3.Geometry.Buffer.Lathe
|
|
* @param graphics GameLib.GraphicsRuntime
|
|
* @param apiGeometryBufferLathe
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Geometry.Buffer.Lathe = function(
|
|
graphics,
|
|
apiGeometryBufferLathe
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiGeometryBufferLathe)) {
|
|
apiGeometryBufferLathe = {
|
|
geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE
|
|
};
|
|
}
|
|
|
|
GameLib.D3.API.Geometry.Buffer.Lathe.call(
|
|
this,
|
|
apiGeometryBufferLathe,
|
|
apiGeometryBufferLathe.points,
|
|
apiGeometryBufferLathe.segments,
|
|
apiGeometryBufferLathe.phiStart,
|
|
apiGeometryBufferLathe.phiLength
|
|
);
|
|
|
|
GameLib.D3.Geometry.Buffer.call(
|
|
this,
|
|
this.graphics,
|
|
apiGeometryBufferLathe
|
|
);
|
|
|
|
};
|
|
|
|
GameLib.D3.Geometry.Buffer.Lathe.prototype = Object.create(GameLib.D3.Geometry.Buffer.prototype);
|
|
GameLib.D3.Geometry.Buffer.Lathe.prototype.constructor = GameLib.D3.Geometry.Buffer.Lathe;
|
|
|
|
/**
|
|
* Creates a light instance
|
|
* @returns {*}
|
|
*/
|
|
GameLib.D3.Geometry.Buffer.Lathe.prototype.createInstance = function() {
|
|
|
|
this.instance = new THREE.LatheBufferGeometry(
|
|
this.points.map(
|
|
function(point) {
|
|
return point.instance;
|
|
}
|
|
),
|
|
this.segments,
|
|
this.phiStart,
|
|
this.phiLength
|
|
);
|
|
|
|
/**
|
|
* The instance doesn't have any groups associated with it - so I just create the default single material group
|
|
*/
|
|
this.toSingleMaterial();
|
|
|
|
this.computeVertexNormals();
|
|
|
|
GameLib.D3.Geometry.Buffer.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
GameLib.D3.Geometry.Buffer.Lathe.prototype.updateInstance = function(property) {
|
|
|
|
if (
|
|
property === 'points' ||
|
|
property === 'segments' ||
|
|
property === 'phiStart' ||
|
|
property === 'phiLength'
|
|
) {
|
|
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.Buffer.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
/**
|
|
* Converts a GameLib.D3.Geometry.Buffer.Lathe to a GameLib.D3.API.Geometry.Buffer.Lathe
|
|
* @returns {GameLib.D3.API.Geometry.Buffer}
|
|
*/
|
|
GameLib.D3.Geometry.Buffer.Lathe.prototype.toApiObject = function() {
|
|
|
|
var apiBufferGeometry = GameLib.D3.Geometry.Buffer.prototype.toApiObject.call(this);
|
|
|
|
var apiGeometryBufferLathe = new GameLib.D3.API.Geometry.Buffer.Lathe(
|
|
apiBufferGeometry,
|
|
this.points.map(
|
|
function(point) {
|
|
return point.toApiObject();
|
|
}
|
|
),
|
|
this.segments,
|
|
this.phiStart,
|
|
this.phiLength
|
|
);
|
|
|
|
return apiGeometryBufferLathe;
|
|
};
|