start drag snapping with models
This commit is contained in:
parent
caeba6a48d
commit
a6be28907c
7 changed files with 70 additions and 41 deletions
|
|
@ -213,9 +213,7 @@ const selection = {
|
|||
},
|
||||
|
||||
drag(opt = {}) {
|
||||
for (let s of selection.sketches()) {
|
||||
s.drag(opt);
|
||||
}
|
||||
selected.forEach(s => s.drag(opt));
|
||||
return selection;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -284,18 +284,18 @@ api.settings = function() {
|
|||
}),
|
||||
]);
|
||||
|
||||
// const set5 = h.div([
|
||||
// h.label({ class: "header", _: 'snap'}),
|
||||
// h.label('value'),
|
||||
// h.input({ type: "text", size: 5, value: parseFloat(space.snap || 1),
|
||||
// onchange: ev => call.set_snap_value(ev.target.value)
|
||||
// }),
|
||||
// h.label('enabled'),
|
||||
// h.input({ type: "checkbox",
|
||||
// onchange: ev => prefs.save( space.snapon = !space.snapon ),
|
||||
// [ space.snapon === true ? 'checked' : 'unchecked' ] : 1
|
||||
// }),
|
||||
// ]);
|
||||
const set5 = h.div([
|
||||
h.label({ class: "header", _: 'snap'}),
|
||||
h.label('value'),
|
||||
h.input({ type: "text", size: 5, value: parseFloat(space.snap || 1),
|
||||
onchange: ev => call.set_snap_value(ev.target.value)
|
||||
}),
|
||||
h.label('enabled'),
|
||||
h.input({ type: "checkbox",
|
||||
onchange: ev => prefs.save( space.snapon = !space.snapon ),
|
||||
[ space.snapon === true ? 'checked' : 'unchecked' ] : 1
|
||||
}),
|
||||
]);
|
||||
|
||||
modal.show('settings', h.div({ class: "settings" }, [ set1, set2, set3, set4, set5 ] ));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,8 +156,9 @@ mesh.group = class MeshGroup extends mesh.object {
|
|||
}
|
||||
|
||||
// ok, this is confusing, but necessary for now :/
|
||||
// todo: obsolete?
|
||||
setSelected() {
|
||||
super.select();
|
||||
// super.select();
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const { MeshPhongMaterial, MeshBasicMaterial, LineBasicMaterial } = THREE;
|
|||
const { BufferGeometry, BufferAttribute, DoubleSide, Mesh } = THREE;
|
||||
const { mesh, moto } = root;
|
||||
const { space } = moto;
|
||||
const { api } = mesh;
|
||||
|
||||
const mapp = mesh;
|
||||
const worker = moto.client.fn;
|
||||
|
|
@ -129,6 +130,43 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
return this.mesh.matrixWorld;
|
||||
}
|
||||
|
||||
drag(opt = {}) {
|
||||
let { start, delta, offset, end } = opt;
|
||||
let { snap, snapon } = api.prefs.map.space;
|
||||
if (start) {
|
||||
let mid = this.bounds.mid;
|
||||
this._save = {
|
||||
pos: Object.assign({},mid),
|
||||
start: Object.assign({},mid),
|
||||
}
|
||||
} else if (end) {
|
||||
delete this._save;
|
||||
} else if (offset) {
|
||||
let { pos, start } = this._save;
|
||||
let target = {
|
||||
x: start.x + offset.x,
|
||||
y: start.y + offset.y,
|
||||
z: start.z + offset.z
|
||||
};
|
||||
if (snapon && snap) {
|
||||
target.x = Math.round(target.x / snap) * snap;
|
||||
target.y = Math.round(target.y / snap) * snap;
|
||||
target.z = Math.round(target.z / snap) * snap;
|
||||
}
|
||||
delta = {
|
||||
x: target.x - pos.x,
|
||||
y: target.y - pos.y,
|
||||
z: target.z - pos.z
|
||||
};
|
||||
pos.x += delta.x;
|
||||
pos.y += delta.y;
|
||||
pos.z += delta.z;
|
||||
}
|
||||
if (delta) {
|
||||
this.move(delta.x, delta.y, delta.z);
|
||||
}
|
||||
}
|
||||
|
||||
// override and translate mesh
|
||||
move(x = 0, y = 0, z = 0) {
|
||||
let attr = this.attributes;
|
||||
|
|
|
|||
|
|
@ -352,10 +352,14 @@ mesh.sketch = class MeshSketch extends mesh.object {
|
|||
|
||||
drag(opt = {}) {
|
||||
let { items } = this;
|
||||
if (opt.start) {
|
||||
let { start, delta, end } = opt;
|
||||
if (start) {
|
||||
let selected = items.filter(i => i.selected);
|
||||
this.dragging = opt.start.sketch_item ? selected : opt.start;
|
||||
} else if (opt.end) {
|
||||
this.dragging = start.sketch_item ? selected : start;
|
||||
// } else if (offset) {
|
||||
} else if (delta) {
|
||||
this.move(delta.x, delta.y, delta.z);
|
||||
} else if (end) {
|
||||
this.dragging = undefined;
|
||||
} else {
|
||||
console.log({ invalid_sketch_drag: opt });
|
||||
|
|
|
|||
Loading…
Reference in a new issue