consolidate widget mesh position / rotation updates for setTopZ and setIndex
This commit is contained in:
parent
b5f756acf6
commit
abd1a763aa
2 changed files with 49 additions and 35 deletions
|
|
@ -74,6 +74,9 @@ CAM.init = function(kiri, api) {
|
||||||
if (!isCamMode) {
|
if (!isCamMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (isIndexed) {
|
||||||
|
settings.process.camZAnchor = "middle";
|
||||||
|
}
|
||||||
animVer = isIndexed ? 1 : 0;
|
animVer = isIndexed ? 1 : 0;
|
||||||
updateStock();
|
updateStock();
|
||||||
SPACE.platform.setVisible(!isIndexed);
|
SPACE.platform.setVisible(!isIndexed);
|
||||||
|
|
@ -166,6 +169,7 @@ CAM.init = function(kiri, api) {
|
||||||
api.ui.camStock.marker.style.display = proc.camStockOn ? 'flex' : 'none';
|
api.ui.camStock.marker.style.display = proc.camStockOn ? 'flex' : 'none';
|
||||||
updateStock(settings, 'settings.saved.internal');
|
updateStock(settings, 'settings.saved.internal');
|
||||||
setAnimationStyle(settings);
|
setAnimationStyle(settings);
|
||||||
|
func.opRender();
|
||||||
});
|
});
|
||||||
|
|
||||||
api.event.on("settings.load", (settings) => {
|
api.event.on("settings.load", (settings) => {
|
||||||
|
|
@ -432,7 +436,7 @@ 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) {
|
if (type === 'index' & indexing && !rec.disabled) {
|
||||||
index = rec.absolute ? rec.degrees : index + rec.degrees;
|
index = rec.absolute ? rec.degrees : index + rec.degrees;
|
||||||
}
|
}
|
||||||
el.rec = rec;
|
el.rec = rec;
|
||||||
|
|
|
||||||
|
|
@ -459,6 +459,14 @@ class Widget {
|
||||||
|
|
||||||
setIndexed(z) {
|
setIndexed(z) {
|
||||||
this.track.indexed = z;
|
this.track.indexed = z;
|
||||||
|
this.setTopZ(this.track.top);
|
||||||
|
}
|
||||||
|
|
||||||
|
setAxisIndex(deg) {
|
||||||
|
let rad = deg * (Math.PI / 180);
|
||||||
|
this.track.indexRad = rad;
|
||||||
|
this.mesh.rotation.x = rad;
|
||||||
|
this.setTopZ(this.track.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -468,33 +476,32 @@ class Widget {
|
||||||
*/
|
*/
|
||||||
setTopZ(z) {
|
setTopZ(z) {
|
||||||
let mesh = this.mesh,
|
let mesh = this.mesh,
|
||||||
pos = this.track.pos,
|
track = this.track,
|
||||||
ltz = this.last_top_z || {},
|
ltop = track.top || 0,
|
||||||
mbz = mesh.getBoundingBox().max.z;
|
mbz = mesh.getBoundingBox().max.z;
|
||||||
if (z) {
|
if (z) {
|
||||||
pos.z = mbz - z;
|
track.top = z;
|
||||||
mesh.position.z = -pos.z - 0.01;
|
|
||||||
this.track.top = z;
|
|
||||||
} else {
|
} else {
|
||||||
pos.z = 0;
|
track.top = mbz;
|
||||||
mesh.position.z = -this.track.zcut || 0;
|
|
||||||
this.track.top = mbz;
|
|
||||||
}
|
}
|
||||||
this.track.tzoff = mbz - z;
|
// difference between top of stock/bounds and top of widget (cam mode)
|
||||||
if (this.track.indexed) {
|
track.tzoff = mbz - z;
|
||||||
mesh.position.z -= this.track.indexed / 2;
|
if (track.indexed) {
|
||||||
}
|
let rad = track.indexRad;
|
||||||
let ntz = {
|
let mz = track.box.h / 2;
|
||||||
pz: pos.z,
|
let dx = Math.cos(rad) * mz;
|
||||||
mpz: mesh.position.z
|
let dy = Math.sin(rad) * mz;
|
||||||
|
track.delta = {
|
||||||
|
x: 0,
|
||||||
|
y: Math.sin(rad) * mz,
|
||||||
|
z: -(track.indexed / 2) + (mz - dx)
|
||||||
};
|
};
|
||||||
this.modified |= (ltz.pz !== ntz.pz || ltz.mpz !== ntz.mpz);
|
} else {
|
||||||
this.last_top_z = ntz;
|
track.delta = { x:0, y:0, z:0};
|
||||||
|
this.mesh.rotation.x = 0;
|
||||||
}
|
}
|
||||||
|
this.modified |= (ltop !== z);
|
||||||
cutZ(dist) {
|
this._updateMeshPosition();
|
||||||
this.track.zcut = dist;
|
|
||||||
this.setTopZ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
move(x, y, z, abs) {
|
move(x, y, z, abs) {
|
||||||
|
|
@ -506,25 +513,21 @@ class Widget {
|
||||||
_move(x, y, z, abs) {
|
_move(x, y, z, abs) {
|
||||||
let mesh = this.mesh,
|
let mesh = this.mesh,
|
||||||
mat = this.getMaterial(),
|
mat = this.getMaterial(),
|
||||||
pos = this.track.pos,
|
pos = this.track.pos;
|
||||||
zcut = this.track.zcut || 0;
|
|
||||||
// do not allow moves in pure slice view
|
// do not allow moves in pure slice view
|
||||||
if (!mat.visible) return;
|
if (!mat.visible) return;
|
||||||
if (abs) {
|
if (abs) {
|
||||||
mesh.position.set(x, y, z - zcut);
|
|
||||||
pos.x = (x || 0);
|
pos.x = (x || 0);
|
||||||
pos.y = (y || 0);
|
pos.y = (y || 0);
|
||||||
pos.z = (z || 0);
|
pos.z = (z || 0);
|
||||||
} else {
|
} else {
|
||||||
mesh.position.x += ( x || 0);
|
|
||||||
mesh.position.y += ( y || 0);
|
|
||||||
mesh.position.z += (-z || 0);
|
|
||||||
pos.x += (x || 0);
|
pos.x += (x || 0);
|
||||||
pos.y += (y || 0);
|
pos.y += (y || 0);
|
||||||
pos.z += (z || 0);
|
pos.z += (z || 0);
|
||||||
}
|
}
|
||||||
if (x || y || z) {
|
if (x || y || z) {
|
||||||
this.setModified();
|
this.setModified();
|
||||||
|
this._updateMeshPosition();
|
||||||
// allow for use in engine / cli
|
// allow for use in engine / cli
|
||||||
if (api && api.event) {
|
if (api && api.event) {
|
||||||
api.event.emit('widget.move', {widget: this, pos});
|
api.event.emit('widget.move', {widget: this, pos});
|
||||||
|
|
@ -532,6 +535,17 @@ class Widget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateMeshPosition() {
|
||||||
|
let mesh = this.mesh,
|
||||||
|
track = this.track,
|
||||||
|
delta = track.delta || { x:0, y:0, z:0 },
|
||||||
|
tzoff = track.tzoff,
|
||||||
|
top = track.top,
|
||||||
|
tz = tzoff !== top ? -tzoff : 0,
|
||||||
|
pos = track.pos;
|
||||||
|
mesh.position.set(pos.x + delta.x, pos.y + delta.y, pos.z + delta.z + tz);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -552,10 +566,6 @@ 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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue