- intersection slicing area

This commit is contained in:
Arno Kaimbacher 2021-06-20 16:00:09 +02:00
parent 333d55ebf6
commit 57303e5421
4 changed files with 98 additions and 14 deletions

View File

@ -99,13 +99,14 @@ export class Selection extends Layer {
this.map = map;
this.build(this.getScene());
this.emit('add');
if (this.map.layers) {
for (const [key, layer] of Object.entries(this.map.layers)) {
if (layer instanceof TinLayer) {
layer.buildBorder(this.vertices);
}
}
}
// if (this.map.layers) {
// for (const [key, layer] of Object.entries(this.map.layers)) {
// if (layer instanceof TinLayer) {
// layer.buildBorder(this.vertices);
// }
// }
// }
this.map.layers[17].buildBorder(this.vertices);
}
onRemove(map) {
@ -148,7 +149,7 @@ export class Selection extends Layer {
this.setUniforms();
}
_updateVertices() {
private _updateVertices() {
this.vertices[0].set(this.limitLow.x, this.limitLow.y, this.limitLow.z);
this.vertices[1].set(this.limitHigh.x, this.limitLow.y, this.limitLow.z);
this.vertices[2].set(this.limitLow.x, this.limitHigh.y, this.limitLow.z);
@ -159,7 +160,7 @@ export class Selection extends Layer {
this.vertices[7].set(this.limitHigh.x, this.limitHigh.y, this.limitHigh.z);
}
updateGeometries() {
private _updateGeometries() {
// for (var i = 0; i < this.meshGeometries.length; i++) {
// // this.meshGeometries[i].verticesNeedUpdate = true;
// // this.meshGeometries[i].getAttribute('position').needsUpdate = true;
@ -185,7 +186,7 @@ export class Selection extends Layer {
}
}
setUniforms() {
public setUniforms() {
let unif = uniforms.clipping;
unif.clippingLow.value.copy(this.limitLow);
unif.clippingHigh.value.copy(this.limitHigh);
@ -231,9 +232,11 @@ export class Selection extends Layer {
this.setUniforms();
this._updateVertices();
this.updateGeometries();
this._updateGeometries();
// this.setBox();
this.box.update();
this.map.layers[17].box.update();
// if (this.map.layers) {
// for (const [key, layer] of Object.entries(this.map.layers)) {
// if (layer instanceof TinLayer) {

View File

@ -2,6 +2,7 @@ import { BufferGeometry } from 'three/src/core/BufferGeometry';
import { Uint16BufferAttribute } from 'three/src/core/BufferAttribute';
import { Vector3 } from 'three/src/math/Vector3';
import { Float32BufferAttribute } from 'three/src/core/BufferAttribute';
import { eventMixin } from '../core/eventMixin';
class UpdatableBoxGeometry extends BufferGeometry {
@ -68,8 +69,11 @@ class UpdatableBoxGeometry extends BufferGeometry {
this.setFromPoints(this.vertices);
this.attributes.position.needsUpdate = true;
this.computeBoundingSphere();
this.dispatchEvent( { type: 'update', message: "example" } );
}
}
// Add the mixin with event-related methods
// Object.assign(UpdatableBoxGeometry.prototype, eventMixin);
export { UpdatableBoxGeometry };

42
src/js/core/eventMixin.js Normal file
View File

@ -0,0 +1,42 @@
let eventMixin = {
/**
* Subscribe to event, usage:
* menu.on('select', function(item) { ... }
*/
on(eventName, handler) {
if (!this._eventHandlers) this._eventHandlers = {};
if (!this._eventHandlers[eventName]) {
this._eventHandlers[eventName] = [];
}
this._eventHandlers[eventName].push(handler);
},
/**
* Cancel the subscription, usage:
* menu.off('select', handler)
*/
off(eventName, handler) {
let handlers = this._eventHandlers?.[eventName];
if (!handlers) return;
for (let i = 0; i < handlers.length; i++) {
if (handlers[i] === handler) {
handlers.splice(i--, 1);
}
}
},
/**
* Generate an event with the given name and data
* this.trigger('select', data1, data2);
*/
trigger(eventName, ...args) {
if (!this._eventHandlers?.[eventName]) {
return; // no handlers for that event name
}
// call the handlers
this._eventHandlers[eventName].forEach(handler => handler.apply(this, args));
}
};
export { eventMixin };

View File

@ -19,7 +19,11 @@ import { Box3 } from 'three/src/math/Box3';
import { uniforms } from '../clip/uniforms';
import { UpdatableBoxGeometry } from '../clip/UpdatableBoxGeometry';
import { Scene } from 'three/src/scenes/Scene';
import { CSG } from 'three-csg-ts';
import { Plane } from 'three/src/math/Plane';
import { PlaneGeometry } from '../clip/PlaneGeometry';
const POINTURL = 'https://geusegdi01.geus.dk/geom3d/data/nodes/';
const EDGEURL = 'https://geusegdi01.geus.dk/geom3d/data/triangles/';
@ -102,7 +106,11 @@ class TinLayer extends Layer {
}
buildBorder(vertices) {
let box = this.box = new UpdatableBoxGeometry(vertices)
let box = this.box = new UpdatableBoxGeometry(vertices);
box.addEventListener("update", function ( event ) {
alert( event.message );
} );
// this.boxMesh = new Mesh(box, material.capMaterial);
// let color = parseInt(this.color, 16);
@ -118,12 +126,39 @@ class TinLayer extends Layer {
// Make sure the .matrix of each mesh is current
// meshA.updateMatrix();
// meshB.updateMatrix();
// // Subtract meshB from meshA
// this.borderMesh = CSG.subtract(meshA, meshB);
// this._addObject(this.borderMesh, false);
// // this.buildPlane(0, vertices[0], vertices[1], vertices[5], vertices[4], 0); //y1 south
// let planeGeom = new PlaneGeometry(vertices[0], vertices[1], vertices[5], vertices[4]);
// planeGeom.rotateX(-Math.PI / 2);
// let plane = new Mesh(planeGeom, new MeshBasicMaterial({
// color: "lightgray",
// transparent: true,
// opacity: 0.75,
// side: DoubleSide
// }));
// this._addObject(plane, false);
// var a = new Vector3(),
// b = new Vector3(),
// c = new Vector3();
// var planePointA = new Vector3(),
// planePointB = new Vector3(),
// planePointC = new Vector3();
// // var lineAB = new Line3(),
// // lineBC = new Line3(),
// // lineCA = new Line3();
// var pointOfIntersection = new Vector3();
// let myPlane = new Plane(new Vector3(0, 1, 0), 0);
// this.frontStencil = new Scene();
// let frontMesh = new Mesh(this.geometry.clone(), material.frontStencilMaterial);
// frontMesh.userData.layerId = this.index;