/** * R3.D3.Geometry.Normal.Polyhedron * @param graphics R3.GraphicsRuntime * @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; };