fix handle drag + snap
This commit is contained in:
parent
257d841b0a
commit
51ecc9ce11
1 changed files with 23 additions and 12 deletions
|
|
@ -26,6 +26,12 @@ const mapp = mesh;
|
||||||
const worker = moto.client.fn;
|
const worker = moto.client.fn;
|
||||||
const POLYS = base.polygons;
|
const POLYS = base.polygons;
|
||||||
const drag = {};
|
const drag = {};
|
||||||
|
const hpos = [
|
||||||
|
[-1, 1, 1],
|
||||||
|
[ 1, 1, 1],
|
||||||
|
[-1,-1, 1],
|
||||||
|
[ 1,-1, 1],
|
||||||
|
];
|
||||||
|
|
||||||
const material = {
|
const material = {
|
||||||
normal: new MeshBasicMaterial({ color: 0x888888, side: DoubleSide, transparent: true, opacity: 0.25 }),
|
normal: new MeshBasicMaterial({ color: 0x888888, side: DoubleSide, transparent: true, opacity: 0.25 }),
|
||||||
|
|
@ -317,12 +323,7 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
||||||
center.z += z;
|
center.z += z;
|
||||||
this.render();
|
this.render();
|
||||||
} else if (handle >= 0) {
|
} else if (handle >= 0) {
|
||||||
const sf = [
|
const sf = hpos[handle];
|
||||||
[-1, 1, 1],
|
|
||||||
[ 1, 1, 1],
|
|
||||||
[-1,-1, 1],
|
|
||||||
[ 1,-1, 1],
|
|
||||||
][handle];
|
|
||||||
center.x += x / 2;
|
center.x += x / 2;
|
||||||
center.y += y / 2;
|
center.y += y / 2;
|
||||||
center.z += z / 2;
|
center.z += z / 2;
|
||||||
|
|
@ -352,6 +353,17 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_pos(handle) {
|
||||||
|
if (handle < 0) return;
|
||||||
|
let { scale, center } = this;
|
||||||
|
let v = hpos[handle];
|
||||||
|
return {
|
||||||
|
x: v[0] * scale.x/2 + center.x,
|
||||||
|
y: v[1] * scale.y/2 + center.y,
|
||||||
|
z: v[2] * scale.z/2 + center.z,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
drag(opt = {}) {
|
drag(opt = {}) {
|
||||||
let { items, center, handles } = this;
|
let { items, center, handles } = this;
|
||||||
let { start, delta, offset, end } = opt;
|
let { start, delta, offset, end } = opt;
|
||||||
|
|
@ -359,18 +371,17 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
||||||
let selected = items.filter(i => i.selected);
|
let selected = items.filter(i => i.selected);
|
||||||
let target = start.sketch_item ? selected : start;
|
let target = start.sketch_item ? selected : start;
|
||||||
let item = Array.isArray(target) ? target[0] : undefined;
|
let item = Array.isArray(target) ? target[0] : undefined;
|
||||||
let handle = this.handles.indexOf(target);
|
drag.handle = handles.indexOf(target);
|
||||||
drag.handle = handle >= 0 ? handles[handle] : undefined;
|
|
||||||
drag.item = item;
|
drag.item = item;
|
||||||
drag.target = target;
|
drag.target = target;
|
||||||
drag.start = Object.assign({}, drag.handle ?
|
drag.start = Object.assign({}, drag.handle >= 0 ?
|
||||||
util.extract(util.bounds(drag.handle).mid, { map: true }) :
|
this.handle_pos(drag.handle) :
|
||||||
item?.center ?? center);
|
item?.center ?? center);
|
||||||
} else if (offset) {
|
} else if (offset) {
|
||||||
let { start, item, handle } = drag;
|
let { start, item, handle } = drag;
|
||||||
let { snap, snapon } = api.prefs.map.space;
|
let { snap, snapon } = api.prefs.map.space;
|
||||||
let pos = handle ?
|
let pos = handle >= 0 ?
|
||||||
util.extract(util.bounds(handle).mid, { map: true }) :
|
this.handle_pos(handle) :
|
||||||
item?.center ?? center;
|
item?.center ?? center;
|
||||||
let end = {
|
let end = {
|
||||||
x: start.x + offset.x,
|
x: start.x + offset.x,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue