r3-legacy/src/r3-d3-geometry-normal-polyh...

117 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-04-09 09:35:04 +02:00
/**
* R3.D3.Geometry.Normal.Polyhedron
2019-07-25 22:22:32 +02:00
* @param graphics R3.Runtime.Graphics
2018-04-09 09:35:04 +02:00
* @param apiGeometryNormalPolyhedron
* @constructor
*/
R3.D3.Geometry.Normal.Polyhedron = function(
graphics,
apiGeometryNormalPolyhedron
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiGeometryNormalPolyhedron)) {
apiGeometryNormalPolyhedron = {
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON
};
}
R3.D3.API.Geometry.Normal.Polyhedron.call(
this,
apiGeometryNormalPolyhedron,
apiGeometryNormalPolyhedron.vertices,
apiGeometryNormalPolyhedron.indices,
apiGeometryNormalPolyhedron.radius,
apiGeometryNormalPolyhedron.detail
);
R3.D3.Geometry.Normal.call(
this,
this.graphics,
apiGeometryNormalPolyhedron
);
};
R3.D3.Geometry.Normal.Polyhedron.prototype = Object.create(R3.D3.Geometry.Normal.prototype);
R3.D3.Geometry.Normal.Polyhedron.prototype.constructor = R3.D3.Geometry.Normal.Polyhedron;
/**
* Creates a light instance
* @returns {*}
*/
R3.D3.Geometry.Normal.Polyhedron.prototype.createInstance = function() {
this.instance = new THREE.PolyhedronGeometry(
this.vertices.map(
function(vertex) {
return vertex.position.instance;
}
),
this.indices.map(
function(index) {
return index.instance;
}
),
this.radius,
this.detail
);
this.computeVertexNormals();
R3.D3.Geometry.Normal.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Geometry.Normal.Polyhedron.prototype.updateInstance = function(property) {
if (
property === 'vertices' ||
property === 'indices' ||
property === 'radius' ||
property === 'detail'
) {
this.instance.dispose();
this.createInstance();
if (this.parentMesh && this.parentMesh.instance) {
this.parentMesh.instance.geometry = this.instance;
}
return;
}
R3.D3.Geometry.Normal.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Geometry.Normal.Polyhedron to a R3.D3.API.Geometry.Normal.Polyhedron
* @returns {R3.D3.API.Geometry.Normal}
*/
R3.D3.Geometry.Normal.Polyhedron.prototype.toApiObject = function() {
var apiNormalGeometry = R3.D3.Geometry.Normal.prototype.toApiObject.call(this);
var apiGeometryNormalPolyhedron = new R3.D3.API.Geometry.Normal.Polyhedron(
apiNormalGeometry,
this.vertices.map(
function(vertex){
return vertex.toApiObject();
}
),
this.indices.map(
function(index){
return index.toApiObject();
}
),
this.radius,
this.detail
);
return apiGeometryNormalPolyhedron;
};