change how indexing is tracked and updated
This commit is contained in:
parent
d1847707ba
commit
8e6ffdb259
3 changed files with 39 additions and 30 deletions
|
|
@ -1656,6 +1656,7 @@ function updateStock(args, event) {
|
||||||
let delta = 0;
|
let delta = 0;
|
||||||
let csox = 0;
|
let csox = 0;
|
||||||
let csoy = 0;
|
let csoy = 0;
|
||||||
|
let csoz = 0;
|
||||||
let stock = settings.stock = { };
|
let stock = settings.stock = { };
|
||||||
let compute = enabled && stockSet && widgets.length;
|
let compute = enabled && stockSet && widgets.length;
|
||||||
|
|
||||||
|
|
@ -1665,7 +1666,7 @@ function updateStock(args, event) {
|
||||||
let csx = proc.camStockX;
|
let csx = proc.camStockX;
|
||||||
let csy = proc.camStockY;
|
let csy = proc.camStockY;
|
||||||
let csz = proc.camStockZ;
|
let csz = proc.camStockZ;
|
||||||
let min = { x: Infinity, y: Infinity, z: 0 };
|
let min = { x: Infinity, y: Infinity, z: Infinity };
|
||||||
let max = { x: -Infinity, y: -Infinity, z: -Infinity };
|
let max = { x: -Infinity, y: -Infinity, z: -Infinity };
|
||||||
for (let widget of widgets) {
|
for (let widget of widgets) {
|
||||||
let wbnd = widget.getBoundingBox(refresh);
|
let wbnd = widget.getBoundingBox(refresh);
|
||||||
|
|
@ -1673,12 +1674,12 @@ function updateStock(args, event) {
|
||||||
min = {
|
min = {
|
||||||
x: Math.min(min.x, wpos.x + wbnd.min.x),
|
x: Math.min(min.x, wpos.x + wbnd.min.x),
|
||||||
y: Math.min(min.y, wpos.y + wbnd.min.y),
|
y: Math.min(min.y, wpos.y + wbnd.min.y),
|
||||||
z: 0
|
z: Math.min(min.z, wpos.z + wbnd.min.z)
|
||||||
};
|
};
|
||||||
max = {
|
max = {
|
||||||
x: Math.max(max.x, wpos.x + wbnd.max.x),
|
x: Math.max(max.x, wpos.x + wbnd.max.x),
|
||||||
y: Math.max(max.y, wpos.y + wbnd.max.y),
|
y: Math.max(max.y, wpos.y + wbnd.max.y),
|
||||||
z: Math.max(max.z, wbnd.max.z)
|
z: Math.max(max.z, wpos.z + wbnd.max.z)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (offset) {
|
if (offset) {
|
||||||
|
|
@ -1687,6 +1688,7 @@ function updateStock(args, event) {
|
||||||
csz += max.z - min.z;
|
csz += max.z - min.z;
|
||||||
csox = min.x + ((max.x - min.x) / 2);
|
csox = min.x + ((max.x - min.x) / 2);
|
||||||
csoy = min.y + ((max.y - min.y) / 2);
|
csoy = min.y + ((max.y - min.y) / 2);
|
||||||
|
csoz = csz / 2; // min.z + ((max.z - min.z) / 2);
|
||||||
}
|
}
|
||||||
if (compute) {
|
if (compute) {
|
||||||
UI.func.animate.classList.remove('disabled');
|
UI.func.animate.classList.remove('disabled');
|
||||||
|
|
@ -1732,7 +1734,7 @@ function updateStock(args, event) {
|
||||||
center: {
|
center: {
|
||||||
x: csox,
|
x: csox,
|
||||||
y: csoy,
|
y: csoy,
|
||||||
z: csz / 2
|
z: csoz
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
camStock.scale.x = csx + 0.005;
|
camStock.scale.x = csx + 0.005;
|
||||||
|
|
@ -1740,7 +1742,7 @@ function updateStock(args, event) {
|
||||||
camStock.scale.z = csz + 0.005;
|
camStock.scale.z = csz + 0.005;
|
||||||
camStock.position.x = csox;
|
camStock.position.x = csox;
|
||||||
camStock.position.y = csoy;
|
camStock.position.y = csoy;
|
||||||
camStock.position.z = csz / 2;
|
camStock.position.z = csoz;
|
||||||
camStock.rotation.x = currentIndex || 0;
|
camStock.rotation.x = currentIndex || 0;
|
||||||
if (isIndexed) {
|
if (isIndexed) {
|
||||||
camStock.position.z = 0;
|
camStock.position.z = 0;
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,9 @@ class Slice {
|
||||||
let layers = this.layers = new kiri.Layers();
|
let layers = this.layers = new kiri.Layers();
|
||||||
if (tracked) {
|
if (tracked) {
|
||||||
let { track } = tracked;
|
let { track } = tracked;
|
||||||
let { indexed, indexRad, delta, tzoff } = track;
|
let { indexed, indexRad } = track;
|
||||||
if (indexed) {
|
if (indexed) {
|
||||||
layers.setRotation(indexRad);
|
layers.setRotation(indexRad);
|
||||||
// layers.setPosition(0, -delta.y, delta.z + tzoff);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return layers;
|
return layers;
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,9 @@ class Widget {
|
||||||
dx = bm.x + bd.x,
|
dx = bm.x + bd.x,
|
||||||
dy = bm.y + bd.y,
|
dy = bm.y + bd.y,
|
||||||
dz = bm.z;
|
dz = bm.z;
|
||||||
|
if (this.track.indexed) {
|
||||||
|
dz += bd.z;
|
||||||
|
}
|
||||||
this.track.center = { dx, dy, dz };
|
this.track.center = { dx, dy, dz };
|
||||||
// move mesh for each widget in group
|
// move mesh for each widget in group
|
||||||
if (!init) {
|
if (!init) {
|
||||||
|
|
@ -435,6 +438,9 @@ class Widget {
|
||||||
* todo use new prototype.moveMesh()
|
* todo use new prototype.moveMesh()
|
||||||
*/
|
*/
|
||||||
moveMesh(x, y, z) {
|
moveMesh(x, y, z) {
|
||||||
|
if (!(x || y || z)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let gap = this.mesh.geometry.attributes.position,
|
let gap = this.mesh.geometry.attributes.position,
|
||||||
pa = gap.array;
|
pa = gap.array;
|
||||||
// center point array on 0,0,0
|
// center point array on 0,0,0
|
||||||
|
|
@ -458,15 +464,20 @@ class Widget {
|
||||||
}
|
}
|
||||||
|
|
||||||
setIndexed(z) {
|
setIndexed(z) {
|
||||||
this.track.indexed = z;
|
if (z !== this.track.indexed) {
|
||||||
this.setTopZ(this.track.top);
|
this.track.indexed = z;
|
||||||
|
this.center(false);
|
||||||
|
// api.platform.update_top_z();
|
||||||
|
this._updateMeshPosition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setAxisIndex(deg) {
|
setAxisIndex(deg) {
|
||||||
let rad = deg * (Math.PI / 180);
|
let rad = deg * (Math.PI / 180);
|
||||||
this.track.indexRad = rad;
|
if (rad !== this.track.indexRad) {
|
||||||
this.mesh.rotation.x = -rad;
|
this.track.indexRad = rad;
|
||||||
this.setTopZ(this.track.top);
|
this._updateMeshPosition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -486,20 +497,6 @@ class Widget {
|
||||||
}
|
}
|
||||||
// difference between top of stock/bounds and top of widget (cam mode)
|
// difference between top of stock/bounds and top of widget (cam mode)
|
||||||
track.tzoff = mbz - z;
|
track.tzoff = mbz - z;
|
||||||
if (track.indexed) {
|
|
||||||
let rad = track.indexRad;
|
|
||||||
let mz = track.box.d / 2;
|
|
||||||
let dx = Math.sin(rad) * mz;
|
|
||||||
let dy = mz - Math.cos(rad) * mz;
|
|
||||||
track.delta = {
|
|
||||||
x: 0,
|
|
||||||
y: -dx,
|
|
||||||
z: -(track.indexed / 2) + dy
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
track.delta = { x:0, y:0, z:0 };
|
|
||||||
this.mesh.rotation.x = 0;
|
|
||||||
}
|
|
||||||
this.modified |= (ltop !== z);
|
this.modified |= (ltop !== z);
|
||||||
this._updateMeshPosition();
|
this._updateMeshPosition();
|
||||||
}
|
}
|
||||||
|
|
@ -538,19 +535,29 @@ class Widget {
|
||||||
_updateMeshPosition() {
|
_updateMeshPosition() {
|
||||||
let mesh = this.mesh,
|
let mesh = this.mesh,
|
||||||
track = this.track,
|
track = this.track,
|
||||||
delta = track.delta || { x:0, y:0, z:0 },
|
|
||||||
tzoff = track.tzoff,
|
tzoff = track.tzoff,
|
||||||
top = track.top,
|
top = track.top,
|
||||||
tz = tzoff !== top ? -tzoff : 0,
|
tz = tzoff !== top ? -tzoff : 0,
|
||||||
pos = track.pos;
|
{ x, y, z } = track.pos;
|
||||||
mesh.position.set(pos.x + delta.x, pos.y + delta.y, pos.z + delta.z + tz);
|
if (track.indexed) {
|
||||||
|
let rad = track.indexRad;
|
||||||
|
let ln = track.box.d / 2;
|
||||||
|
let dx = Math.sin(rad) * ln;
|
||||||
|
let dy = ln - Math.cos(rad) * ln;
|
||||||
|
this.mesh.rotation.x = -rad;
|
||||||
|
z = 0;
|
||||||
|
} else {
|
||||||
|
this.mesh.rotation.x = 0;
|
||||||
|
z += tz;
|
||||||
|
}
|
||||||
|
mesh.position.set(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
scale(x, y, z) {
|
scale(x, y, z) {
|
||||||
this.group.forEach(w => {
|
this.group.forEach(w => {
|
||||||
w._scale(x, y, z);
|
w._scale(x, y, z);
|
||||||
});
|
});
|
||||||
this.center();
|
this.center(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_scale(x, y, z) {
|
_scale(x, y, z) {
|
||||||
|
|
@ -599,6 +606,7 @@ class Widget {
|
||||||
this.setModified();
|
this.setModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// undo all accumulated rotations
|
||||||
unrotate() {
|
unrotate() {
|
||||||
this.roto.reverse().forEach(m => {
|
this.roto.reverse().forEach(m => {
|
||||||
this.mesh.geometry.applyMatrix4(m.clone().invert());
|
this.mesh.geometry.applyMatrix4(m.clone().invert());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue