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

146 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-09-05 05:22:52 +02:00
/**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
2018-04-09 10:05:13 +02:00
* @param graphics R3.GraphicsRuntime
2018-01-23 11:01:59 +01:00
* @param apiMeshCylinder
2017-09-05 05:22:52 +02:00
* @constructor
*/
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Cylinder = function (
2017-09-05 05:22:52 +02:00
graphics,
2018-01-23 11:01:59 +01:00
apiMeshCylinder
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(apiMeshCylinder)) {
2018-01-23 11:01:59 +01:00
apiMeshCylinder = {
2018-04-09 10:05:13 +02:00
meshType : R3.D3.API.Mesh.MESH_TYPE_CYLINDER
2017-12-04 13:23:15 +01:00
};
}
2018-04-09 10:05:13 +02:00
R3.D3.API.Mesh.Cylinder.call(
2018-01-23 11:01:59 +01:00
this,
apiMeshCylinder,
apiMeshCylinder.radiusTop,
apiMeshCylinder.radiusBottom,
apiMeshCylinder.height,
apiMeshCylinder.radiusSegments,
apiMeshCylinder.heightSegments,
apiMeshCylinder.openEnded,
apiMeshCylinder.thetaStart,
apiMeshCylinder.thetaLength
);
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,
2018-01-23 11:01:59 +01:00
graphics,
this
2017-09-05 05:22:52 +02:00
);
};
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Cylinder.prototype = Object.create(R3.D3.Mesh.prototype);
R3.D3.Mesh.Cylinder.prototype.constructor = R3.D3.Mesh.Cylinder;
2017-09-05 05:22:52 +02:00
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Cylinder.prototype.createInstance = function() {
2017-09-05 05:22:52 +02:00
var geometry = null;
if (this.vertices.length === 0) {
geometry = new THREE.CylinderGeometry(
this.radiusTop,
this.radiusBottom,
this.height,
this.radiusSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
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.Cylinder.prototype.updateInstance = function(property) {
2017-09-05 05:22:52 +02:00
if (
2018-01-23 11:01:59 +01:00
property === 'radiusTop' ||
property === 'radiusBottom' ||
property === 'height' ||
property === 'radiusSegments' ||
property === 'heightSegments' ||
property === 'openEnded' ||
property === 'thetaStart' ||
property === 'thetaLength'
2017-09-05 05:22:52 +02:00
) {
var geometry = new THREE.CylinderGeometry(
this.radiusTop,
this.radiusBottom,
this.height,
this.radiusSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
this.updateVerticesFromGeometryInstance(geometry);
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
}
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.Cylinder to a R3.D3.API.Mesh.Cylinder
* @returns {R3.D3.API.Mesh.Cylinder}
2017-09-05 05:22:52 +02:00
*/
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Cylinder.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 apiMeshCylinder = new R3.D3.API.Mesh.Cylinder(
apiMesh,
this.radiusTop,
this.radiusBottom,
this.height,
this.radiusSegments,
this.heightSegments,
this.openEnded,
this.thetaStart,
this.thetaLength
);
2017-09-05 05:22:52 +02:00
return apiMeshCylinder;
2017-09-05 05:22:52 +02:00
};
/**
2018-01-23 11:01:59 +01:00
* This function turns the cylinder into a 'display' where each plane on the cylinder is mapped onto a flat texture
2017-09-05 05:22:52 +02:00
*/
2018-04-09 10:05:13 +02:00
R3.D3.Mesh.Cylinder.prototype.turnIntoDisplay = function() {
2017-09-05 05:22:52 +02:00
2018-01-23 11:01:59 +01:00
this.heightSegments = 1;
this.updateInstance('heightSegments');
2017-09-05 05:22:52 +02:00
2018-01-23 11:01:59 +01:00
this.openEnded = true;
this.updateInstance('openEnded');
this.materials.map(
function(material){
material.remove();
}
2017-09-05 05:22:52 +02:00
);
2018-01-23 11:01:59 +01:00
this.materials = [];
for (var i = 0; i < this.radiusSegments; i++) {
this.materials.push(
2018-04-09 10:05:13 +02:00
new R3.D3.Material(this.graphics)
2018-01-23 11:01:59 +01:00
)
}
this.updateInstance('materials');
};