track widget indexing to timeline selection

This commit is contained in:
Stewart Allen 2022-10-31 12:14:28 -04:00
commit b5f756acf6
7 changed files with 51 additions and 15 deletions

View file

@ -9,7 +9,7 @@
gapp.register("geo.paths", [], (root, exports) => { gapp.register("geo.paths", [], (root, exports) => {
const { base } = root; const { base } = root;
const { util, config, newPoint } = base; const { util, config } = base;
const { sqr, numOrDefault } = util; const { sqr, numOrDefault } = util;
const DEG2RAD = Math.PI / 180; const DEG2RAD = Math.PI / 180;

View file

@ -80,7 +80,11 @@ class Point {
} }
clone() { clone() {
return newPoint(this.x, this.y, this.z, this._key); let p = newPoint(this.x, this.y, this.z, this._key);
if (this.a) {
p.a = this.a;
}
return p;
} }
slopeTo(p) { slopeTo(p) {

View file

@ -492,7 +492,7 @@ kiri.load(() => {
const sd = Math.sqrt(mx*mx + my*my + mz*mz); const sd = Math.sqrt(mx*mx + my*my + mz*mz);
const moves = []; const moves = [];
for (let i=0, x=lp.x, y=lp.y, z=lp.z; i<st; i++) { for (let i=0, x=lp.x, y=lp.y, z=lp.z; i<st; i++) {
moves.push({x,y,z,md:sd}); moves.push({x,y,z,a:lp.a,md:sd});
x += mx; x += mx;
y += my; y += my;
z += mz; z += mz;

View file

@ -65,10 +65,15 @@ CAM.init = function(kiri, api) {
} }
function setAnimationStyle(settings) { function setAnimationStyle(settings) {
isIndexed = settings.process.camStockIndexed;
if (!isIndexed || !isCamMode) {
for (let widget of API.widgets.all()) {
widget.setAxisIndex(0);
}
}
if (!isCamMode) { if (!isCamMode) {
return; return;
} }
isIndexed = settings.process.camStockIndexed;
animVer = isIndexed ? 1 : 0; animVer = isIndexed ? 1 : 0;
updateStock(); updateStock();
SPACE.platform.setVisible(!isIndexed); SPACE.platform.setVisible(!isIndexed);
@ -400,11 +405,13 @@ CAM.init = function(kiri, api) {
listel.innerHTML = html.join(''); listel.innerHTML = html.join('');
let bounds = []; let bounds = [];
let unpop = null; let unpop = null;
let index = 0;
let indexing = true;
// drag and drop re-ordering // drag and drop re-ordering
for (let [id, rec] of Object.entries(bind)) { for (let [id, rec] of Object.entries(bind)) {
let type = rec.type; let type = rec.type;
let clock = type === '|'; let clock = type === '|';
if (!clock) if (!clock) {
$(`${id}-x`).onmousedown = (ev) => { $(`${id}-x`).onmousedown = (ev) => {
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
@ -413,6 +420,9 @@ CAM.init = function(kiri, api) {
func.tabDone(); func.tabDone();
func.opDel(rec); func.opDel(rec);
}; };
} else {
indexing = false;
}
let el = $(id); let el = $(id);
if (rec.disabled) { if (rec.disabled) {
el.classList.add("disabled"); el.classList.add("disabled");
@ -422,6 +432,9 @@ CAM.init = function(kiri, api) {
let inside = true; let inside = true;
let popped = false; let popped = false;
let poprec = popOp[rec.type]; let poprec = popOp[rec.type];
if (type === 'index' && indexing) {
index = rec.absolute ? rec.degrees : index + rec.degrees;
}
el.rec = rec; el.rec = rec;
el.unpop = () => { el.unpop = () => {
let pos = [...el.childNodes].indexOf(poprec.div); let pos = [...el.childNodes].indexOf(poprec.div);
@ -565,6 +578,10 @@ CAM.init = function(kiri, api) {
el.onmouseleave = onLeave; el.onmouseleave = onLeave;
} }
} }
// update widget rotations from timeline marker
for (let widget of API.widgets.all()) {
widget.setAxisIndex(-index);
}
}); });
func.opGCode = (label, field = 'gcode') => { func.opGCode = (label, field = 'gcode') => {

View file

@ -41,6 +41,10 @@ class CamOp {
class OpIndex extends CamOp { class OpIndex extends CamOp {
constructor(state, op) { constructor(state, op) {
super(state, op); super(state, op);
}
slice() {
let { op, state } = this;
state.setAxisIndex(op.degrees); state.setAxisIndex(op.degrees);
} }

View file

@ -147,9 +147,13 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
} }
sliceAll.appendAll(slices); sliceAll.appendAll(slices);
if (axisIndex !== undefined) { if (axisIndex !== undefined) {
console.log({post_axis_index: slices}); // update slice cam lines to add axis indexing
for (let slice of slices) { for (let slice of slices) {
slice.axisIndex = axisIndex; for (let poly of slice.camLines) {
for (let point of poly.points) {
point.a = axisIndex;
}
}
} }
} }
} }
@ -189,6 +193,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
let opSum = 0; let opSum = 0;
let opTot = opList.length ? opList.map(op => op.weight()).reduce((a,v) => a + v) : 0; let opTot = opList.length ? opList.map(op => op.weight()).reduce((a,v) => a + v) : 0;
// determing # of steps and step weighting for progress bar
for (let op of proc.ops.filter(op => !op.disabled)) { for (let op of proc.ops.filter(op => !op.disabled)) {
let opfn = OPS[op.type]; let opfn = OPS[op.type];
if (opfn) { if (opfn) {
@ -201,6 +206,8 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
// give ops access to entire sequence // give ops access to entire sequence
state.ops = opList; state.ops = opList;
// call slice() function on all ops in order
setAxisIndex(undefined);
for (let op of opList) { for (let op of opList) {
let weight = op.weight(); let weight = op.weight();
op.slice((progress, message) => { op.slice((progress, message) => {

View file

@ -552,6 +552,10 @@ class Widget {
this.setModified(); this.setModified();
} }
setAxisIndex(deg) {
this.mesh.rotation.x = deg * (Math.PI / 180);
}
rotate(x, y, z, temp) { rotate(x, y, z, temp) {
this.group.forEach(w => { this.group.forEach(w => {
w._rotate(x, y, z, temp); w._rotate(x, y, z, temp);