stablized

master
howard 2021-03-29 18:46:55 -07:00
parent b3162d97f7
commit 254cf7c5c3
5 changed files with 30 additions and 37 deletions

View File

@ -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 { OrbitControls } from './utils/OrbitControls'
import { TrackballControls } from './utils/trackball' import { TrackballControls } from './utils/trackball'
import { Sketcher } from './sketcher/Sketcher' import { Sketcher } from './sketcher/Sketcher'
@ -163,10 +163,6 @@ async function addSketch() {
sketcher.align(...result) sketcher.align(...result)
sketcher.activate() sketcher.activate()
sketcher.addEventListener('change', this.render); sketcher.addEventListener('change', this.render);

View File

@ -10,26 +10,30 @@ import logger from 'redux-logger'
let _entId = 0 let _entId = 0
function reducer(state = {}, action) { function reducer(state = {}, action) {
let id;
switch (action.type) { switch (action.type) {
case 'toggle': case 'toggle':
return { ...state, toggle: action.payload } return { ...state, toggle: action.payload }
case 'rx-sketch': case 'rx-sketch':
id = 's' + action.obj.id
return { return {
...state, treeEntries: { ...state, treeEntries: {
byId: { ...state.treeEntries.byId, ['s' + ++_entId]: action.obj }, byId: { ...state.treeEntries.byId, [id]: action.obj },
allIds: [...state.treeEntries.allIds, 's' + _entId] allIds: [...state.treeEntries.allIds, id]
} },
env: id
} }
case 'rx-extrusion': case 'rx-extrusion':
id = 'e' + action.mesh.id
return { return {
...state, ...state,
treeEntries: { treeEntries: {
byId: { ...state.treeEntries.byId, ['e' + ++_entId]: action.obj }, byId: { ...state.treeEntries.byId, [id]: action.mesh },
allIds: [...state.treeEntries.allIds, 'e' + _entId] allIds: [...state.treeEntries.allIds, id]
}, },
mesh2sketch: { mesh2sketch: {
...state.mesh2sketch, ...state.mesh2sketch,
[action.skId]: _entId ['s' + action.sketch.id]: id
} }
} }
case 'incsk': case 'incsk':

View File

@ -17,9 +17,9 @@ class Sketcher extends THREE.Group {
constructor(camera, domElement, store) { constructor(camera, domElement, store) {
super() super()
this.name = "sketch"
this.camera = camera; this.camera = camera;
this.domElement = domElement; this.domElement = domElement;
this.matrixAutoUpdate = false;
this.store = store; this.store = store;
this.sub = new THREE.Group(); 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); this.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
// [0]:x, [1]:y, [2]:z // [0]:x, [1]:y, [2]:z
this.objIdx = new Map() this.objIdx = new Map()
this.max_pts = 1000
this.ptsBuf = new Float32Array(this.max_pts * 3).fill(NaN) this.ptsBuf = new Float32Array(this.max_pts * 3).fill(NaN)
// [0]:type, [1]:pt1, [2]:pt2, [3]:pt3, [4]:pt4 // [0]:type, [1]:pt1, [2]:pt2, [3]:pt3, [4]:pt4
this.linkedObjs = new Map() this.linkedObjs = new Map()
this.l_id = 0; this.l_id = 0;
this.max_links = 1000
this.linksBuf = new Float32Array(this.max_links * 5).fill(NaN) this.linksBuf = new Float32Array(this.max_links * 5).fill(NaN)
// [0]:type, [1]:val, [2]:pt1, [3]:pt2, [4]:lk1, [5]:lk2 // [0]:type, [1]:val, [2]:pt1, [3]:pt2, [4]:lk1, [5]:lk2
this.constraints = new Map() this.constraints = new Map()
this.c_id = 0; this.c_id = 0;
this.max_constraints = 1000
this.constraintsBuf = new Float32Array(this.max_constraints * 6).fill(NaN) this.constraintsBuf = new Float32Array(this.max_constraints * 6).fill(NaN)
this.drawOnClick1 = drawOnClick1.bind(this); this.drawOnClick1 = drawOnClick1.bind(this);
this.drawPreClick2 = drawPreClick2.bind(this); this.drawPreClick2 = drawPreClick2.bind(this);
this.drawOnClick2 = drawOnClick2.bind(this); this.drawOnClick2 = drawOnClick2.bind(this);
@ -63,10 +56,8 @@ class Sketcher extends THREE.Group {
this.matrixAutoUpdate = false; this.matrixAutoUpdate = false;
this.selected = new Set() this.selected = new Set()
this.hovered = [] this.hovered = []
this.mode = "" this.mode = ""
this.subsequent = false; this.subsequent = false;
} }
@ -152,38 +143,36 @@ class Sketcher extends THREE.Group {
deleteSelected() { deleteSelected() {
const toDelete = [...this.selected] const toDelete = [...this.selected]
.filter(e => e.type == 'Line') .filter(e => e.type == 'Line')
.sort((a, b) => b.id - a.id) .sort((a, b) => b.id - a.id)
.map(e => { .map(obj => {
const i = this.objIdx.get(e.id) return this.delete(obj)
this.delete(i)
return i
}) })
this.updatePointsBuffer(toDelete[0]) this.updatePointsBuffer(toDelete[toDelete.length - 1])
// this.updatePointsBuffer()
this.updateOtherBuffers() this.updateOtherBuffers()
this.selected.clear() this.selected.clear()
this.dispatchEvent({ type: 'change' }) this.dispatchEvent({ type: 'change' })
} }
delete(i) { delete(obj) {
const obj = this.children[i]
let link = this.linkedObjs.get(obj.l_id) let link = this.linkedObjs.get(obj.l_id)
if (!link) return; if (!link) return;
link = link[1] 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++) { for (let j = 0; j < link.length; j++) {
const obj = this.children[i + j] const obj = this.children[i + j]
obj.geometry.dispose() obj.geometry.dispose()
obj.material.dispose() obj.material.dispose()
for (let c_id of obj.constraints) { for (let c_id of obj.constraints) {
console.log(j,c_id)
this.deleteConstraints(c_id) this.deleteConstraints(c_id)
} }
} }
@ -192,6 +181,7 @@ class Sketcher extends THREE.Group {
this.linkedObjs.delete(obj.l_id) this.linkedObjs.delete(obj.l_id)
return i
} }
@ -341,6 +331,9 @@ Object.assign(Sketcher.prototype,
'coincident': 0, 'coincident': 0,
'distance': 1 'distance': 1
}, },
max_pts: 1000,
max_links: 1000,
max_constraints: 1000,
} }
) )

View File

@ -65,7 +65,7 @@ export function drawClear() {
this.domElement.removeEventListener('pointermove', this.drawPreClick2); this.domElement.removeEventListener('pointermove', this.drawPreClick2);
this.domElement.removeEventListener('pointerdown', this.drawOnClick2); this.domElement.removeEventListener('pointerdown', this.drawOnClick2);
this.delete(this.updatePoint) this.delete(this.children[this.updatePoint])
this.dispatchEvent({ type: 'change' }) this.dispatchEvent({ type: 'change' })
this.subsequent = false this.subsequent = false

View File

@ -72,14 +72,14 @@ export function extrude(sketch) {
const wireframe = new THREE.WireframeGeometry(geometry); const wireframe = new THREE.WireframeGeometry(geometry);
const pts = new THREE.Points(wireframe, pointMaterial); const pts = new THREE.Points(wireframe, pointMaterial);
pts.matrixAutoUpdate = false; // pts.matrixAutoUpdate = false;
pts.matrix.multiply(sketch.matrix) // pts.matrix.multiply(sketch.matrix)
this.scene.add(pts) mesh.add(pts)
this.render() this.render()
// this.dispatchEvent({ type: 'change' }) // sketch.visible = false
// this.visible = false this.store.dispatch({ type: 'rx-extrusion', mesh, sketch })
} }