97 lines
2.1 KiB
JavaScript
97 lines
2.1 KiB
JavaScript
/**
|
|
* GameLib.D3.Mesh.Box
|
|
* @param graphics GameLib.GraphicsRuntime
|
|
* @param apiMeshBox
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Mesh.Box = function (
|
|
graphics,
|
|
apiMeshBox
|
|
) {
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiMeshBox)) {
|
|
apiMeshBox = {
|
|
meshType: GameLib.D3.API.Mesh.MESH_TYPE_BOX
|
|
};
|
|
}
|
|
|
|
GameLib.D3.API.Mesh.Box.call(
|
|
this,
|
|
apiMeshBox,
|
|
apiMeshBox.width,
|
|
apiMeshBox.height,
|
|
apiMeshBox.depth
|
|
);
|
|
|
|
GameLib.D3.Mesh.call(
|
|
this,
|
|
this.graphics,
|
|
this
|
|
);
|
|
};
|
|
|
|
GameLib.D3.Mesh.Box.prototype = Object.create(GameLib.D3.Mesh.prototype);
|
|
GameLib.D3.Mesh.Box.prototype.constructor = GameLib.D3.Mesh.Box;
|
|
|
|
GameLib.D3.Mesh.Box.prototype.createInstance = function() {
|
|
|
|
var geometry = null;
|
|
|
|
if (this.vertices.length === 0) {
|
|
|
|
geometry = new THREE.BoxGeometry(
|
|
this.width,
|
|
this.height,
|
|
this.depth
|
|
);
|
|
|
|
this.updateVerticesFromGeometryInstance(geometry);
|
|
}
|
|
|
|
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
|
};
|
|
|
|
GameLib.D3.Mesh.Box.prototype.updateInstance = function(property) {
|
|
|
|
if (
|
|
property === 'width' ||
|
|
property === 'height' ||
|
|
property === 'depth'
|
|
) {
|
|
var geometry = new THREE.BoxGeometry(
|
|
this.width,
|
|
this.height,
|
|
this.depth
|
|
);
|
|
|
|
this.updateVerticesFromGeometryInstance(geometry);
|
|
|
|
geometry = this.createInstanceGeometry();
|
|
|
|
this.instance.geometry = geometry;
|
|
|
|
return;
|
|
}
|
|
|
|
GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
/**
|
|
* Converts a GameLib.D3.Mesh.Box to a GameLib.D3.API.Mesh.Box
|
|
* @returns {GameLib.D3.API.Mesh.Box}
|
|
*/
|
|
GameLib.D3.Mesh.Box.prototype.toApiObject = function() {
|
|
|
|
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
|
|
|
|
var apiMeshBox = new GameLib.D3.API.Mesh.Box(
|
|
apiMesh,
|
|
this.width,
|
|
this.height,
|
|
this.depth
|
|
);
|
|
|
|
return apiMeshBox;
|
|
}; |