pre-work quicksave
This commit is contained in:
parent
43cd45cb90
commit
b0ada74488
3 changed files with 61 additions and 32 deletions
|
|
@ -1187,8 +1187,8 @@ CAM.init = function(kiri, api) {
|
||||||
alert = api.show.alert("[esc] cancels trace editing");
|
alert = api.show.alert("[esc] cancels trace editing");
|
||||||
kiri.api.widgets.opacity(0.8);
|
kiri.api.widgets.opacity(0.8);
|
||||||
|
|
||||||
// console.log(kiri.api.widgets.all())
|
|
||||||
const widgets = kiri.api.widgets.all()
|
const widgets = kiri.api.widgets.all()
|
||||||
|
console.log(widgets)
|
||||||
|
|
||||||
if(individual && widgets.some(w=>w.holes!= undefined) ){ // if any widget already has cached holes
|
if(individual && widgets.some(w=>w.holes!= undefined) ){ // if any widget already has cached holes
|
||||||
// console.log("already has cached holes",widgets)
|
// console.log("already has cached holes",widgets)
|
||||||
|
|
@ -1208,52 +1208,48 @@ CAM.init = function(kiri, api) {
|
||||||
//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)
|
||||||
widget.holes = holes;
|
|
||||||
|
|
||||||
holes.toRecord = () => {
|
|
||||||
return holes.map(hole => {
|
|
||||||
let {x,y,z,depth,selected} = hole
|
|
||||||
return {x,y,z,depth,selected}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!holes.length) {
|
if (!holes.length) {
|
||||||
unselectHoles(holes);
|
unselectHoles(holes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let meshes=[];
|
||||||
|
|
||||||
holes.forEach(hole => {
|
holes.forEach(hole => {
|
||||||
if(!hole.mesh){
|
|
||||||
let {depth,selected} = hole
|
let {depth,selected} = hole
|
||||||
let color = selected ? 0xFF0000:0x39e366
|
let color = selected ? 0xFF0000:0x39e366
|
||||||
let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
|
let geo = new THREE.CylinderGeometry(diam/2,diam/2,depth,20);
|
||||||
const material = new THREE.MeshBasicMaterial( { color } );
|
const material = new THREE.MeshBasicMaterial( { color } );
|
||||||
let mesh = new THREE.Mesh(geo, material);
|
let mesh = new THREE.Mesh(geo, material);
|
||||||
|
meshes.push(mesh)
|
||||||
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.mesh = mesh; //add pointers to both objects
|
hole.meshId = mesh.id; //add pointers to both objects
|
||||||
mesh.hole = hole;
|
mesh.hole = hole;
|
||||||
hole.updateColor = ()=>{
|
|
||||||
hole.mesh.material.color.set(hole.selected?0xFF0000:0x39e366)
|
mesh.parent = widget.mesh;
|
||||||
}
|
widget.mesh.add(mesh);
|
||||||
}else{
|
widget.adds.push(mesh);
|
||||||
hole.updateColor()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
//add hole data to record
|
//add hole data to record
|
||||||
poppedRec.drills[widget.id] = holes.toRecord();
|
poppedRec.drills = poppedRec.drills || {}
|
||||||
|
poppedRec.drills[widget.id] = holes
|
||||||
// console.log("hole widget:",widget)
|
// console.log("hole widget:",widget)
|
||||||
|
|
||||||
|
console.log(poppedRec)
|
||||||
|
|
||||||
widget.holes.forEach(hole => {
|
if(!widget.drills){widget.drills = []}
|
||||||
hole.mesh.parent = widget.mesh;
|
|
||||||
widget.mesh.add(hole.mesh);
|
let drills = poppedRec.drills[widget.id]
|
||||||
widget.adds.push(hole.mesh);
|
|
||||||
});
|
widget.drills.push(drills)
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
// console.log(" widgets sliced",kiri.api.widgets.all())
|
console.log(" widgets sliced",kiri.api.widgets.all())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1297,11 +1293,10 @@ CAM.init = function(kiri, api) {
|
||||||
console.log("selectHolesHoverUp",int)
|
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.hole);
|
func.selectHoleToggle(object.hole);
|
||||||
|
|
||||||
let widget = object.parent.widget; //only update the parent widget
|
|
||||||
console.log(poppedRec,poppedRec.drills)
|
console.log(poppedRec,poppedRec.drills)
|
||||||
poppedRec.drills[widget.id] = widget.holes.toRecord();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1321,12 +1316,12 @@ CAM.init = function(kiri, api) {
|
||||||
api.hide.alert(alert);
|
api.hide.alert(alert);
|
||||||
api.feature.hover = false;
|
api.feature.hover = false;
|
||||||
api.feature.hoverAdds = false;
|
api.feature.hoverAdds = false;
|
||||||
|
|
||||||
kiri.api.widgets.for(widget => {
|
kiri.api.widgets.for(widget => {
|
||||||
if (widget.holes) {
|
poppedRec.drills[widget.id].forEach(hole => {
|
||||||
widget.holes.forEach(hole => {
|
hole.mesh.parent = null;
|
||||||
widget.mesh.remove(hole.mesh);
|
widget.mesh.remove(hole.mesh);
|
||||||
})
|
})
|
||||||
}
|
|
||||||
widget.adds = []
|
widget.adds = []
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -1457,6 +1452,33 @@ CAM.init = function(kiri, api) {
|
||||||
SPACE.update();
|
SPACE.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rotateDrills(){
|
||||||
|
let tabs = API.widgets.annotate(widget.id).tab || [];
|
||||||
|
tabs.forEach(rec => {
|
||||||
|
let { id, pos, rot } = rec;
|
||||||
|
if (!Array.isArray(rot)) {
|
||||||
|
rot = rot.toArray();
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
// update position vector
|
||||||
|
let vc = new THREE.Vector3(pos.x, pos.y, pos.z).applyMatrix4(m4);
|
||||||
|
// update rotation quaternion
|
||||||
|
let [ rx, ry, rz, rw ] = rot;
|
||||||
|
rec.rot = new THREE.Quaternion().multiplyQuaternions(
|
||||||
|
new THREE.Quaternion(rx, ry, rz, rw),
|
||||||
|
new THREE.Quaternion().setFromRotationMatrix(m4)
|
||||||
|
).toArray();
|
||||||
|
tab.box.geometry.applyMatrix4(m4);
|
||||||
|
tab.box.position.x = pos.x = vc.x - coff.dx;
|
||||||
|
tab.box.position.y = pos.y = vc.y - coff.dy;
|
||||||
|
tab.box.position.z = pos.z = vc.z;
|
||||||
|
});
|
||||||
|
SPACE.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function hasIndexing() {
|
function hasIndexing() {
|
||||||
return isIndexed;
|
return isIndexed;
|
||||||
}
|
}
|
||||||
|
|
@ -2094,6 +2116,7 @@ function unselectTraces(widget, skip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unselectHoles(widget) {
|
function unselectHoles(widget) {
|
||||||
|
if (!widget.holes) return
|
||||||
widget.holes.forEach(hole => {
|
widget.holes.forEach(hole => {
|
||||||
hole.selected = false
|
hole.selected = false
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -477,10 +477,16 @@ CAM.holes = async function(settings, widget, diam) {
|
||||||
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;
|
||||||
|
|
||||||
|
slice.shadow = CAM.shadowAt(widget,slice.z, 0)
|
||||||
|
// console.log("looking at slice",slice)
|
||||||
|
|
||||||
for (let poly of inner) {
|
for (let poly of inner) {
|
||||||
let center = poly.calcCircleCenter();
|
let center = poly.calcCircleCenter();
|
||||||
|
|
||||||
center.selected = (!individual && poly.circularity() >= 0.985 && Math.abs(poly.area() - area) <= areaDelta );
|
center.selected = (!individual && poly.circularity() >= 0.985 && Math.abs(poly.area() - area) <= areaDelta );
|
||||||
// center.points = poly.points;
|
// center.points = poly.points;
|
||||||
|
|
||||||
if (center.isInPolygon(slice.shadow)) {
|
if (center.isInPolygon(slice.shadow)) {
|
||||||
//TODO: test if this is working
|
//TODO: test if this is working
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -697,7 +697,7 @@ class Widget {
|
||||||
getBoundingBox(refresh) {
|
getBoundingBox(refresh) {
|
||||||
if (!this.bounds || refresh || this.modified) {
|
if (!this.bounds || refresh || this.modified) {
|
||||||
this.bounds = new THREE.Box3().setFromArray(this.getGeoVertices());
|
this.bounds = new THREE.Box3().setFromArray(this.getGeoVertices());
|
||||||
this.modified = false;
|
// this.modified = false;
|
||||||
}
|
}
|
||||||
return this.bounds;
|
return this.bounds;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue