diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index 3991b162..bf838143 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -1656,6 +1656,7 @@ function updateStock(args, event) { let delta = 0; let csox = 0; let csoy = 0; + let csoz = 0; let stock = settings.stock = { }; let compute = enabled && stockSet && widgets.length; @@ -1665,7 +1666,7 @@ function updateStock(args, event) { let csx = proc.camStockX; let csy = proc.camStockY; 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 }; for (let widget of widgets) { let wbnd = widget.getBoundingBox(refresh); @@ -1673,12 +1674,12 @@ function updateStock(args, event) { min = { x: Math.min(min.x, wpos.x + wbnd.min.x), y: Math.min(min.y, wpos.y + wbnd.min.y), - z: 0 + z: Math.min(min.z, wpos.z + wbnd.min.z) }; max = { x: Math.max(max.x, wpos.x + wbnd.max.x), 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) { @@ -1687,6 +1688,7 @@ function updateStock(args, event) { csz += max.z - min.z; csox = min.x + ((max.x - min.x) / 2); csoy = min.y + ((max.y - min.y) / 2); + csoz = csz / 2; // min.z + ((max.z - min.z) / 2); } if (compute) { UI.func.animate.classList.remove('disabled'); @@ -1732,7 +1734,7 @@ function updateStock(args, event) { center: { x: csox, y: csoy, - z: csz / 2 + z: csoz } }; camStock.scale.x = csx + 0.005; @@ -1740,7 +1742,7 @@ function updateStock(args, event) { camStock.scale.z = csz + 0.005; camStock.position.x = csox; camStock.position.y = csoy; - camStock.position.z = csz / 2; + camStock.position.z = csoz; camStock.rotation.x = currentIndex || 0; if (isIndexed) { camStock.position.z = 0; diff --git a/src/kiri/slice.js b/src/kiri/slice.js index df2a6bce..d6a229e2 100644 --- a/src/kiri/slice.js +++ b/src/kiri/slice.js @@ -47,10 +47,9 @@ class Slice { let layers = this.layers = new kiri.Layers(); if (tracked) { let { track } = tracked; - let { indexed, indexRad, delta, tzoff } = track; + let { indexed, indexRad } = track; if (indexed) { layers.setRotation(indexRad); - // layers.setPosition(0, -delta.y, delta.z + tzoff); } } return layers; diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 39d80115..fb762856 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -420,6 +420,9 @@ class Widget { dx = bm.x + bd.x, dy = bm.y + bd.y, dz = bm.z; + if (this.track.indexed) { + dz += bd.z; + } this.track.center = { dx, dy, dz }; // move mesh for each widget in group if (!init) { @@ -435,6 +438,9 @@ class Widget { * todo use new prototype.moveMesh() */ moveMesh(x, y, z) { + if (!(x || y || z)) { + return; + } let gap = this.mesh.geometry.attributes.position, pa = gap.array; // center point array on 0,0,0 @@ -458,15 +464,20 @@ class Widget { } setIndexed(z) { - this.track.indexed = z; - this.setTopZ(this.track.top); + if (z !== this.track.indexed) { + this.track.indexed = z; + this.center(false); + // api.platform.update_top_z(); + this._updateMeshPosition(); + } } setAxisIndex(deg) { let rad = deg * (Math.PI / 180); - this.track.indexRad = rad; - this.mesh.rotation.x = -rad; - this.setTopZ(this.track.top); + if (rad !== this.track.indexRad) { + this.track.indexRad = rad; + this._updateMeshPosition(); + } } /** @@ -486,20 +497,6 @@ class Widget { } // difference between top of stock/bounds and top of widget (cam mode) 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._updateMeshPosition(); } @@ -538,19 +535,29 @@ 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); + { x, y, z } = track.pos; + 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) { this.group.forEach(w => { w._scale(x, y, z); }); - this.center(); + this.center(false); } _scale(x, y, z) { @@ -599,6 +606,7 @@ class Widget { this.setModified(); } + // undo all accumulated rotations unrotate() { this.roto.reverse().forEach(m => { this.mesh.geometry.applyMatrix4(m.clone().invert());