fix all selection bugs!
This commit is contained in:
parent
b0ada74488
commit
d2ab9ad986
3 changed files with 129 additions and 60 deletions
|
|
@ -1190,21 +1190,68 @@ CAM.init = function(kiri, api) {
|
||||||
const widgets = kiri.api.widgets.all()
|
const widgets = kiri.api.widgets.all()
|
||||||
console.log(widgets)
|
console.log(widgets)
|
||||||
|
|
||||||
if(individual && widgets.some(w=>w.holes!= undefined) ){ // if any widget already has cached holes
|
function createHoleMesh(widget,drill){
|
||||||
// console.log("already has cached holes",widgets)
|
let {depth,selected} = drill
|
||||||
|
let color = selected ? 0xFF0000:0x39e366
|
||||||
|
let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
|
||||||
|
const material = new THREE.MeshPhongMaterial( { color } );
|
||||||
|
let mesh = new THREE.Mesh(geo, material);
|
||||||
|
mesh.position.copy(drill)
|
||||||
|
mesh.position.z -= depth/2
|
||||||
|
mesh.rotation.x = Math.PI/2
|
||||||
|
|
||||||
widgets.forEach(widget => {
|
drill.widgetID = widget.id
|
||||||
widget.holes.forEach(hole => {
|
drill.meshId = mesh.id; //add pointers to both objects
|
||||||
hole.mesh.parent = widget.mesh;
|
mesh.hole = drill;
|
||||||
widget.mesh.add(hole.mesh);
|
|
||||||
widget.adds.push(hole.mesh);
|
mesh.parent = widget.mesh;
|
||||||
});
|
|
||||||
|
widget.mesh.add(mesh);
|
||||||
|
widget.adds.push(mesh);
|
||||||
|
|
||||||
|
return mesh
|
||||||
|
}
|
||||||
|
|
||||||
|
if( individual && Object.values(poppedRec.drills) ){ // if any widget already has cached holes
|
||||||
|
console.log("already has cached holes",poppedRec.drills)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kiri.api.widgets.for(widget => {
|
||||||
|
if(widget.adds){
|
||||||
|
console.log("individual",widget)
|
||||||
|
let drills = poppedRec.drills[widget.id]
|
||||||
|
|
||||||
|
let ids = drills
|
||||||
|
.map(hole => hole.meshId)
|
||||||
|
|
||||||
|
if(widget.adds.includes(mesh)){
|
||||||
|
widget.adds.forEach(add=>{
|
||||||
|
// console.log("add",add,ids)
|
||||||
|
if(ids.includes(add.id)){
|
||||||
|
add.visible = true
|
||||||
|
widget.mesh.add(add)
|
||||||
|
console.log("visible",add)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
}else{
|
||||||
|
drills.forEach(drill => {
|
||||||
|
createHoleMesh(widget, drill)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log("done",widgets)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else{ // if no widget has cached holes
|
}else{ // if no widget has cached holes
|
||||||
console.log("no cached holes, must slice")
|
console.log("no cached holes, must slice")
|
||||||
await CAM.holes(individual?0:diam,(centers)=>{
|
await CAM.holes(individual?0:diam,(centers)=>{
|
||||||
console.log("centers",centers)
|
centers = centers ?? []
|
||||||
//flattened list of all hole centers and if they are selected
|
//flattened list of all hole centers and if they are selected
|
||||||
kiri.api.widgets.for(widget => {
|
kiri.api.widgets.for(widget => {
|
||||||
const {holes} = centers.find(center=>center.id = widget.id)
|
const {holes} = centers.find(center=>center.id = widget.id)
|
||||||
|
|
@ -1213,29 +1260,29 @@ CAM.init = function(kiri, api) {
|
||||||
unselectHoles(holes);
|
unselectHoles(holes);
|
||||||
}
|
}
|
||||||
|
|
||||||
let meshes=[];
|
|
||||||
|
|
||||||
holes.forEach(hole => {
|
holes.forEach(hole => {
|
||||||
let {depth,selected} = hole
|
createHoleMesh(widget, hole)
|
||||||
let color = selected ? 0xFF0000:0x39e366
|
// let {depth,selected} = hole
|
||||||
let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
|
// let color = selected ? 0xFF0000:0x39e366
|
||||||
const material = new THREE.MeshBasicMaterial( { color } );
|
// let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
|
||||||
let mesh = new THREE.Mesh(geo, material);
|
// const material = new THREE.MeshPhongMaterial( { color } );
|
||||||
meshes.push(mesh)
|
// let mesh = new THREE.Mesh(geo, material);
|
||||||
mesh.position.copy(hole)
|
// mesh.position.copy(hole)
|
||||||
mesh.position.z -= depth/2
|
// mesh.position.z -= depth/2
|
||||||
mesh.rotation.x = Math.PI/2
|
// mesh.rotation.x = Math.PI/2
|
||||||
|
|
||||||
hole.meshId = mesh.id; //add pointers to both objects
|
// hole.widgetID = widget.id
|
||||||
mesh.hole = hole;
|
// hole.meshId = mesh.id; //add pointers to both objects
|
||||||
|
// mesh.hole = hole;
|
||||||
|
|
||||||
mesh.parent = widget.mesh;
|
// mesh.parent = widget.mesh;
|
||||||
widget.mesh.add(mesh);
|
// widget.mesh.add(mesh);
|
||||||
widget.adds.push(mesh);
|
// widget.adds.push(mesh);
|
||||||
|
|
||||||
})
|
})
|
||||||
//add hole data to record
|
//add hole data to record
|
||||||
poppedRec.drills = poppedRec.drills || {}
|
poppedRec.drills = poppedRec.drills ?? {}
|
||||||
poppedRec.drills[widget.id] = holes
|
poppedRec.drills[widget.id] = holes
|
||||||
// console.log("hole widget:",widget)
|
// console.log("hole widget:",widget)
|
||||||
|
|
||||||
|
|
@ -1249,7 +1296,7 @@ CAM.init = function(kiri, api) {
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
console.log(" widgets sliced",kiri.api.widgets.all())
|
console.log("slice result",poppedRec.drills)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1290,19 +1337,26 @@ CAM.init = function(kiri, api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func.selectHolesHoverUp = function(int, ev) {
|
func.selectHolesHoverUp = function(int, ev) {
|
||||||
console.log("selectHolesHoverUp",int)
|
|
||||||
if (!int) return; //if not a hole mesh return
|
if (!int) return; //if not a hole mesh return
|
||||||
let { object } = int;
|
let { object } = int;
|
||||||
|
func.selectHoleToggle(object);
|
||||||
func.selectHoleToggle(object.hole);
|
|
||||||
|
|
||||||
console.log(poppedRec,poppedRec.drills)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func.selectHoleToggle = function(hole) {
|
func.selectHoleToggle = function(mesh) {
|
||||||
|
let {hole} = mesh
|
||||||
|
console.log("current rec drills",poppedRec.drills)
|
||||||
|
console.log("selectHoleToggle pre",mesh)
|
||||||
hole.selected = !hole.selected;
|
hole.selected = !hole.selected;
|
||||||
hole.updateColor();
|
// console.log("selected",hole.selected)
|
||||||
|
mesh.material.color.setHex( hole.selected ? 0xFF0000:0x39e366 );
|
||||||
|
console.log("selectHoleToggle post",mesh)
|
||||||
|
}
|
||||||
|
|
||||||
|
func.clearHolesRec = (widget)=>{
|
||||||
|
if(poppedRec.drills){
|
||||||
|
poppedRec.drills[widget.id] = undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func.selectHolesDone = () => {
|
func.selectHolesDone = () => {
|
||||||
|
|
@ -1318,11 +1372,10 @@ CAM.init = function(kiri, api) {
|
||||||
api.feature.hoverAdds = false;
|
api.feature.hoverAdds = false;
|
||||||
|
|
||||||
kiri.api.widgets.for(widget => {
|
kiri.api.widgets.for(widget => {
|
||||||
poppedRec.drills[widget.id].forEach(hole => {
|
for(let add of widget.adds){
|
||||||
hole.mesh.parent = null;
|
add.visible = false
|
||||||
widget.mesh.remove(hole.mesh);
|
widget.mesh.remove(add);
|
||||||
})
|
}
|
||||||
widget.adds = []
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1368,6 +1421,10 @@ CAM.init = function(kiri, api) {
|
||||||
if (traceOn) {
|
if (traceOn) {
|
||||||
func.traceDone();
|
func.traceDone();
|
||||||
}
|
}
|
||||||
|
if (holeSelOn) {
|
||||||
|
func.holeSelDone();
|
||||||
|
}
|
||||||
|
func.clearHolesRec(widget)
|
||||||
unselectTraces(widget);
|
unselectTraces(widget);
|
||||||
if (flipping) {
|
if (flipping) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1388,8 +1445,13 @@ CAM.init = function(kiri, api) {
|
||||||
}
|
}
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
clearTabs(widget);
|
clearTabs(widget);
|
||||||
|
if (holeSelOn) {
|
||||||
|
func.holeSelDone();
|
||||||
|
}
|
||||||
|
func.clearHolesRec(widget)
|
||||||
} else {
|
} else {
|
||||||
rotateTabs(widget, x, y, z);
|
rotateTabs(widget, x, y, z);
|
||||||
|
rotateDrills(widget, z);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
api.event.on("mouse.hover.up", rec => {
|
api.event.on("mouse.hover.up", rec => {
|
||||||
|
|
@ -1452,29 +1514,33 @@ CAM.init = function(kiri, api) {
|
||||||
SPACE.update();
|
SPACE.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotateDrills(){
|
function rotateDrills(widget, z) {
|
||||||
let tabs = API.widgets.annotate(widget.id).tab || [];
|
let drills = poppedRec.drills[widget.id]
|
||||||
tabs.forEach(rec => {
|
|
||||||
let { id, pos, rot } = rec;
|
if (!drills) {
|
||||||
if (!Array.isArray(rot)) {
|
return;
|
||||||
rot = rot.toArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let m4 = new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler( 0, 0, z ?? 0));
|
||||||
let coff = widget.track.center;
|
let coff = widget.track.center;
|
||||||
let tab = widget.tabs[id];
|
|
||||||
let m4 = new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0));
|
drills.forEach(drill => {
|
||||||
|
|
||||||
// update position vector
|
// update position vector
|
||||||
let vc = new THREE.Vector3(pos.x, pos.y, pos.z).applyMatrix4(m4);
|
let vc = new THREE.Vector3(drill.x, drill.y, drill.z).applyMatrix4(m4);
|
||||||
// update rotation quaternion
|
// update rotation quaternion
|
||||||
let [ rx, ry, rz, rw ] = rot;
|
|
||||||
rec.rot = new THREE.Quaternion().multiplyQuaternions(
|
drill.x = vc.x - coff.dx;
|
||||||
new THREE.Quaternion(rx, ry, rz, rw),
|
drill.y = vc.y - coff.dy;
|
||||||
new THREE.Quaternion().setFromRotationMatrix(m4)
|
|
||||||
).toArray();
|
mesh = widget.adds.find(m=>m.id == drill.meshId)
|
||||||
tab.box.geometry.applyMatrix4(m4);
|
|
||||||
tab.box.position.x = pos.x = vc.x - coff.dx;
|
mesh.position.x = drill.x;
|
||||||
tab.box.position.y = pos.y = vc.y - coff.dy;
|
mesh.position.y = drill.y;
|
||||||
tab.box.position.z = pos.z = vc.z;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
SPACE.update();
|
SPACE.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -471,9 +471,12 @@ CAM.holes = async function(settings, widget, diam) {
|
||||||
slices.push(slice);
|
slices.push(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(indices)
|
||||||
|
|
||||||
let opts = { each: onEach, over: false, flatoff: 0, edges: true, openok: false, lines: false };
|
let opts = { each: onEach, over: false, flatoff: 0, edges: true, openok: false, lines: false };
|
||||||
await slicer.slice(indices, opts);
|
await slicer.slice(indices, opts);
|
||||||
const tslices = slices.map(s=>s.tops).flat()
|
const tslices = slices.map(s=>s.tops).flat()
|
||||||
|
console.log("tslices",tslices)
|
||||||
for (let slice of tslices) {
|
for (let slice of tslices) {
|
||||||
slice.shadow = CAM.shadowAt(widget,slice.z, 0)
|
slice.shadow = CAM.shadowAt(widget,slice.z, 0)
|
||||||
let inner = slice.inner;
|
let inner = slice.inner;
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ function meshes() {
|
||||||
if (!api.feature.hoverAdds) {
|
if (!api.feature.hoverAdds) {
|
||||||
out.push(widget.mesh);
|
out.push(widget.mesh);
|
||||||
}
|
}
|
||||||
out.appendAll(widget.adds);
|
out.appendAll(widget.adds.filter(m=>m.visible));
|
||||||
});
|
});
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue