2015-07-26 15:32:10 +02:00
|
|
|
import THREE from 'three.js';
|
2016-08-19 14:09:51 +02:00
|
|
|
import slice from './sliceActions/index.js';
|
2015-07-26 15:32:10 +02:00
|
|
|
|
2016-08-19 14:09:51 +02:00
|
|
|
export default class {
|
2016-07-19 14:28:03 +02:00
|
|
|
setMesh(mesh) {
|
2015-07-26 15:32:10 +02:00
|
|
|
mesh.updateMatrix();
|
2015-06-11 10:28:21 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
this.setGeometry(mesh.geometry, mesh.matrix);
|
2015-04-28 14:11:41 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
return this;
|
|
|
|
}
|
2016-07-19 14:28:03 +02:00
|
|
|
setGeometry(geometry, matrix) {
|
2016-07-19 14:26:06 +02:00
|
|
|
if (geometry instanceof THREE.BufferGeometry) {
|
2015-07-26 15:32:10 +02:00
|
|
|
geometry = new THREE.Geometry().fromBufferGeometry(geometry);
|
2016-07-19 14:26:06 +02:00
|
|
|
} else if (geometry instanceof THREE.Geometry) {
|
2015-07-26 15:32:10 +02:00
|
|
|
geometry = geometry.clone();
|
2016-05-09 11:17:49 +02:00
|
|
|
} else {
|
2016-07-19 14:25:48 +02:00
|
|
|
throw 'Geometry is not an instance of BufferGeometry or Geometry';
|
2015-07-26 15:32:10 +02:00
|
|
|
}
|
2015-06-16 10:28:26 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
if (matrix instanceof THREE.Matrix4) {
|
|
|
|
geometry.applyMatrix(matrix);
|
|
|
|
}
|
2015-06-16 10:28:26 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
geometry.mergeVertices();
|
2015-07-28 12:28:05 +02:00
|
|
|
geometry.computeFaceNormals();
|
2015-07-10 15:06:51 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
this.geometry = geometry;
|
2015-06-16 10:28:26 +02:00
|
|
|
|
2015-07-26 15:32:10 +02:00
|
|
|
return this;
|
2015-06-16 10:28:26 +02:00
|
|
|
}
|
2016-08-19 14:09:51 +02:00
|
|
|
async slice(settings) {
|
|
|
|
return slice(this.geometry, settings);
|
2015-07-26 15:32:10 +02:00
|
|
|
}
|
|
|
|
}
|