diff --git a/src/Renderer.js b/src/Renderer.js index 0aed444..8491ad8 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -1,7 +1,7 @@ -import * as THREE from 'three/src/Three'; +import * as THREE from '../node_modules/three/src/Three'; // import { OrbitControls } from './utils/OrbitControls' import { TrackballControls } from './utils/trackball' import { Sketcher } from './sketcher/Sketcher' @@ -163,10 +163,6 @@ async function addSketch() { sketcher.align(...result) - - - - sketcher.activate() sketcher.addEventListener('change', this.render); diff --git a/src/index.js b/src/index.js index de2b0cf..caa06bc 100644 --- a/src/index.js +++ b/src/index.js @@ -10,26 +10,30 @@ import logger from 'redux-logger' let _entId = 0 function reducer(state = {}, action) { + let id; switch (action.type) { case 'toggle': return { ...state, toggle: action.payload } case 'rx-sketch': + id = 's' + action.obj.id return { ...state, treeEntries: { - byId: { ...state.treeEntries.byId, ['s' + ++_entId]: action.obj }, - allIds: [...state.treeEntries.allIds, 's' + _entId] - } + byId: { ...state.treeEntries.byId, [id]: action.obj }, + allIds: [...state.treeEntries.allIds, id] + }, + env: id } case 'rx-extrusion': + id = 'e' + action.mesh.id return { ...state, treeEntries: { - byId: { ...state.treeEntries.byId, ['e' + ++_entId]: action.obj }, - allIds: [...state.treeEntries.allIds, 'e' + _entId] + byId: { ...state.treeEntries.byId, [id]: action.mesh }, + allIds: [...state.treeEntries.allIds, id] }, mesh2sketch: { ...state.mesh2sketch, - [action.skId]: _entId + ['s' + action.sketch.id]: id } } case 'incsk': diff --git a/src/sketcher/Sketcher.js b/src/sketcher/Sketcher.js index 5c29631..219ae10 100644 --- a/src/sketcher/Sketcher.js +++ b/src/sketcher/Sketcher.js @@ -17,9 +17,9 @@ class Sketcher extends THREE.Group { constructor(camera, domElement, store) { super() + this.name = "sketch" this.camera = camera; this.domElement = domElement; - this.matrixAutoUpdate = false; this.store = store; this.sub = new THREE.Group(); @@ -29,28 +29,21 @@ class Sketcher extends THREE.Group { this.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0); - // [0]:x, [1]:y, [2]:z this.objIdx = new Map() - this.max_pts = 1000 this.ptsBuf = new Float32Array(this.max_pts * 3).fill(NaN) // [0]:type, [1]:pt1, [2]:pt2, [3]:pt3, [4]:pt4 this.linkedObjs = new Map() this.l_id = 0; - this.max_links = 1000 this.linksBuf = new Float32Array(this.max_links * 5).fill(NaN) - // [0]:type, [1]:val, [2]:pt1, [3]:pt2, [4]:lk1, [5]:lk2 this.constraints = new Map() this.c_id = 0; - this.max_constraints = 1000 this.constraintsBuf = new Float32Array(this.max_constraints * 6).fill(NaN) - - this.drawOnClick1 = drawOnClick1.bind(this); this.drawPreClick2 = drawPreClick2.bind(this); this.drawOnClick2 = drawOnClick2.bind(this); @@ -63,10 +56,8 @@ class Sketcher extends THREE.Group { this.matrixAutoUpdate = false; - this.selected = new Set() this.hovered = [] - this.mode = "" this.subsequent = false; } @@ -152,38 +143,36 @@ class Sketcher extends THREE.Group { deleteSelected() { + + const toDelete = [...this.selected] .filter(e => e.type == 'Line') .sort((a, b) => b.id - a.id) - .map(e => { - const i = this.objIdx.get(e.id) - this.delete(i) - return i + .map(obj => { + return this.delete(obj) }) - this.updatePointsBuffer(toDelete[0]) - // this.updatePointsBuffer() + this.updatePointsBuffer(toDelete[toDelete.length - 1]) this.updateOtherBuffers() this.selected.clear() this.dispatchEvent({ type: 'change' }) } - delete(i) { - const obj = this.children[i] + delete(obj) { let link = this.linkedObjs.get(obj.l_id) if (!link) return; link = link[1] - console.log('delete',link.length) + let i = this.objIdx.get(link[0]) || this.updatePoint // hacky, see drawEvent.js for updatePoint def + for (let j = 0; j < link.length; j++) { const obj = this.children[i + j] obj.geometry.dispose() obj.material.dispose() for (let c_id of obj.constraints) { - console.log(j,c_id) this.deleteConstraints(c_id) } } @@ -192,6 +181,7 @@ class Sketcher extends THREE.Group { this.linkedObjs.delete(obj.l_id) + return i } @@ -341,6 +331,9 @@ Object.assign(Sketcher.prototype, 'coincident': 0, 'distance': 1 }, + max_pts: 1000, + max_links: 1000, + max_constraints: 1000, } ) diff --git a/src/sketcher/drawEvents.js b/src/sketcher/drawEvents.js index 4fea6b4..77f6f41 100644 --- a/src/sketcher/drawEvents.js +++ b/src/sketcher/drawEvents.js @@ -65,7 +65,7 @@ export function drawClear() { this.domElement.removeEventListener('pointermove', this.drawPreClick2); this.domElement.removeEventListener('pointerdown', this.drawOnClick2); - this.delete(this.updatePoint) + this.delete(this.children[this.updatePoint]) this.dispatchEvent({ type: 'change' }) this.subsequent = false diff --git a/src/sketcher/extrude.js b/src/sketcher/extrude.js index 18583b4..e7f17a6 100644 --- a/src/sketcher/extrude.js +++ b/src/sketcher/extrude.js @@ -72,14 +72,14 @@ export function extrude(sketch) { const wireframe = new THREE.WireframeGeometry(geometry); const pts = new THREE.Points(wireframe, pointMaterial); - pts.matrixAutoUpdate = false; - pts.matrix.multiply(sketch.matrix) - this.scene.add(pts) + // pts.matrixAutoUpdate = false; + // pts.matrix.multiply(sketch.matrix) + mesh.add(pts) this.render() - // this.dispatchEvent({ type: 'change' }) - // this.visible = false + // sketch.visible = false + this.store.dispatch({ type: 'rx-extrusion', mesh, sketch }) }