UNPKG

@edsilv/ami.js

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/214063/46479857-4cd66e80-c7f0-11e8-9585-5748409c9490.png" width="60%"> </p>

115 lines (93 loc) 2.63 kB
/** * @module helpers/border */ const helpersBorder = (three = window.THREE) => { if (three === undefined || three.Object3D === undefined) { return null; } const Constructor = three.Object3D; return class extends Constructor { constructor(helpersSlice) { // super(); this._helpersSlice = helpersSlice; this._visible = true; this._color = 0xff0000; this._material = null; this._geometry = null; this._mesh = null; this._create(); } set helpersSlice(helpersSlice) { this._helpersSlice = helpersSlice; this._update(); } get helpersSlice() { return this._helpersSlice; } set visible(visible) { this._visible = visible; if (this._mesh) { this._mesh.visible = this._visible; } } get visible() { return this._visible; } set color(color) { this._color = color; if (this._material) { this._material.color.set(this._color); } } get color() { return this._color; } _create() { if (!this._material) { this._material = new three.LineBasicMaterial({ color: this._color, linewidth: 1, }); } if (!this._helpersSlice.geometry.vertices) { return; } this._geometry = new three.BufferGeometry(); // set vertices positions const nbOfVertices = this._helpersSlice.geometry.vertices.length; const positions = new Float32Array((nbOfVertices + 1) * 3); positions.set(this._helpersSlice.geometry.attributes.position.array, 0); positions.set(this._helpersSlice.geometry.vertices[0].toArray(), nbOfVertices * 3); this._geometry.addAttribute( 'position', new three.Float32BufferAttribute( positions, 3 ) ); this._mesh = new three.Line(this._geometry, this._material); if (this._helpersSlice.aabbSpace === 'IJK') { this._mesh.applyMatrix(this._helpersSlice.stack.ijk2LPS); } this._mesh.visible = this._visible; // and add it! this.add(this._mesh); } _update() { // update slice if (this._mesh) { this.remove(this._mesh); this._mesh.geometry.dispose(); this._mesh = null; } this._create(); } dispose() { this._mesh.material.dispose(); this._mesh.material = null; this._geometry.dispose(); this._geometry = null; this._material.dispose(); this._material = null; } }; }; // export factory export { helpersBorder }; // default export to export default helpersBorder();