r3-legacy/bak/r3-d3-mesh-box.js

97 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2017-09-05 05:22:52 +02:00
/**
2018-04-09 10:05:13 +02:00
* R3.D3.Mesh.Box
* @param graphics R3.GraphicsRuntime
* @param apiMeshBox
2017-09-05 05:22:52 +02:00
* @constructor
*/
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Box = function (
2017-09-05 05:22:52 +02:00
graphics,
apiMeshBox
2017-09-05 05:22:52 +02:00
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
2018-04-09 10:05:13 +02:00
if (R3.Utils.UndefinedOrNull(apiMeshBox)) {
apiMeshBox = {
2018-04-09 10:05:13 +02:00
meshType: R3.D3.API.Mesh.MESH_TYPE_BOX
2017-12-04 13:23:15 +01:00
};
}
2018-04-09 10:05:13 +02:00
R3.D3.API.Mesh.Box.call(
this,
apiMeshBox,
apiMeshBox.width,
apiMeshBox.height,
apiMeshBox.depth
);
2017-09-05 05:22:52 +02:00
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.call(
2017-09-05 05:22:52 +02:00
this,
this.graphics,
this
2017-09-05 05:22:52 +02:00
);
};
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Box.prototype = Object.create(R3.D3.Mesh.prototype);
R3.D3.Mesh.Box.prototype.constructor = R3.D3.Mesh.Box;
2017-09-05 05:22:52 +02:00
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Box.prototype.createInstance = function() {
2017-09-05 05:22:52 +02:00
var geometry = null;
if (this.vertices.length === 0) {
2017-09-05 05:22:52 +02:00
geometry = new THREE.BoxGeometry(
this.width,
this.height,
this.depth
);
this.updateVerticesFromGeometryInstance(geometry);
}
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.prototype.createInstance.call(this);
2017-09-05 05:22:52 +02:00
};
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Box.prototype.updateInstance = function(property) {
2017-09-05 05:22:52 +02:00
if (
property === 'width' ||
property === 'height' ||
property === 'depth'
2017-09-05 05:22:52 +02:00
) {
var geometry = new THREE.BoxGeometry(
this.width,
this.height,
this.depth
);
this.updateVerticesFromGeometryInstance(geometry);
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
return;
2017-09-05 05:22:52 +02:00
}
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.prototype.updateInstance.call(this, property);
2017-09-05 05:22:52 +02:00
};
/**
2018-04-09 10:05:13 +02:00
* Converts a R3.D3.Mesh.Box to a R3.D3.API.Mesh.Box
* @returns {R3.D3.API.Mesh.Box}
2017-09-05 05:22:52 +02:00
*/
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Box.prototype.toApiObject = function() {
2017-09-05 05:22:52 +02:00
2018-04-09 10:05:13 +02:00
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
2017-09-05 05:22:52 +02:00
2018-04-09 10:05:13 +02:00
var apiMeshBox = new R3.D3.API.Mesh.Box(
2017-09-05 05:22:52 +02:00
apiMesh,
this.width,
this.height,
this.depth
2017-09-05 05:22:52 +02:00
);
return apiMeshBox;
};