diff --git a/src/main/mesh.js b/src/main/mesh.js index 21af8a4e..bf8f733e 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -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) { diff --git a/src/mesh/api.js b/src/mesh/api.js index 5dbb3d9d..372be79c 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -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 diff --git a/src/mesh/sketch.js b/src/mesh/sketch.js index a83c8e25..361f004e 100644 --- a/src/mesh/sketch.js +++ b/src/mesh/sketch.js @@ -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;