add sketch selection and focus + normal

This commit is contained in:
Stewart Allen 2024-07-24 13:28:15 -04:00
commit a594999292
3 changed files with 20 additions and 4 deletions

View file

@ -331,13 +331,14 @@ function space_init(data) {
space.mouse.upSelect((int, event) => {
if (event && event.target.nodeName === "CANVAS") {
const model = int && int.object.model ? int.object.model : undefined;
const model = int?.object?.model;
const sketch = int?.object?.sketch;
const { altKey, ctrlKey, metaKey, shiftKey } = event;
if (mesh.split.active()) {
return mesh.split.select(model);
}
if (model) {
const group = model.group;
const { altKey, ctrlKey, metaKey, shiftKey } = event;
if (metaKey) {
// set focus on intersected face
const { x, y, z } = int.point;
@ -374,6 +375,17 @@ function space_init(data) {
break;
}
}
} else if (sketch) {
if (metaKey) {
// set focus on intersected face
const { x, y, z } = int.point;
// rotate normal using group's matrix
const normal = shiftKey ? int.face.normal : undefined;
// y,z swap due to world rotation for orbit controls
api.focus({center: { x, y:-z, z:y }, normal});
} else {
selection.toggle(sketch);
}
}
} else {
return api.objects().filter(o => o.visible);
@ -509,7 +521,7 @@ function object_destroy(id) {
// listen for changes like dark mode toggle
function set_darkmode(dark) {
let { prefs, selection, model } = mesh.api;
let { prefs, model } = mesh.api;
let { sky, platform } = moto.space;
prefs.map.space.dark = dark;
if (dark) {

View file

@ -1131,7 +1131,10 @@ const api = exports({
objects() {
// return model objects suitable for finding ray intersections
return group.list().map(o => o.models).flat().map(o => o.mesh);
return [
...group.list().map(o => o.models).flat().map(o => o.mesh),
...sketches.map(s => s.object)
];
},
isDebug: self.debug === true

View file

@ -46,6 +46,7 @@ mesh.sketch = class MeshSketch extends mesh.object {
const outlineMaterial = material.outline;
const outline = this.outline = new LineSegments(outlineGeometry, outlineMaterial);
plane.add(outline);
plane.sketch = this;
const handleGeometry = new SphereGeometry(0.05, 16, 16);
const handleMaterial = material.handle;