97 lines
2.0 KiB
JavaScript
97 lines
2.0 KiB
JavaScript
|
/**
|
||
|
* R3.D3.Mesh.Box
|
||
|
* @param graphics R3.GraphicsRuntime
|
||
|
* @param apiMeshBox
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.Mesh.Box = function (
|
||
|
graphics,
|
||
|
apiMeshBox
|
||
|
) {
|
||
|
this.graphics = graphics;
|
||
|
this.graphics.isNotThreeThrow();
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiMeshBox)) {
|
||
|
apiMeshBox = {
|
||
|
meshType: R3.D3.API.Mesh.MESH_TYPE_BOX
|
||
|
};
|
||
|
}
|
||
|
|
||
|
R3.D3.API.Mesh.Box.call(
|
||
|
this,
|
||
|
apiMeshBox,
|
||
|
apiMeshBox.width,
|
||
|
apiMeshBox.height,
|
||
|
apiMeshBox.depth
|
||
|
);
|
||
|
|
||
|
R3.D3.Mesh.call(
|
||
|
this,
|
||
|
this.graphics,
|
||
|
this
|
||
|
);
|
||
|
};
|
||
|
|
||
|
R3.D3.Mesh.Box.prototype = Object.create(R3.D3.Mesh.prototype);
|
||
|
R3.D3.Mesh.Box.prototype.constructor = R3.D3.Mesh.Box;
|
||
|
|
||
|
R3.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);
|
||
|
}
|
||
|
|
||
|
R3.D3.Mesh.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
R3.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;
|
||
|
}
|
||
|
|
||
|
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a R3.D3.Mesh.Box to a R3.D3.API.Mesh.Box
|
||
|
* @returns {R3.D3.API.Mesh.Box}
|
||
|
*/
|
||
|
R3.D3.Mesh.Box.prototype.toApiObject = function() {
|
||
|
|
||
|
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||
|
|
||
|
var apiMeshBox = new R3.D3.API.Mesh.Box(
|
||
|
apiMesh,
|
||
|
this.width,
|
||
|
this.height,
|
||
|
this.depth
|
||
|
);
|
||
|
|
||
|
return apiMeshBox;
|
||
|
};
|