bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
89 stars 9 forks source link

Add click-to-center feature #95

Open eteq opened 2 weeks ago

eteq commented 2 weeks ago

While this tool is really amazing for build123d and cq workflows, there is one and only one feature that sometimes forces me to go back into freecad: the "click to center" feature in some of the freecad view modes. That is, you can middle-click on a spot in the view and it re-centers the camera there, which, more importantly, means if I orbit or zoom in, it zooms into the spot I selected. This is critical for inspecting small parts embedded in a larger part.

Right now I can of course pan to wherever I need to be with right-click, but I find that imprecise and awkward to use such that in practice I sometimes have to dump my object and load it in freecad to inspect things. Can a middle-click-to-center feature be added to vscode-ocp-cad-viewer ? (or maybe this belongs better in three-cad-viewer? I confess I don't really understand the boundary of what is where)

eteq commented 2 weeks ago

(Note I'm open to "well then make a PR for that!" but I am not really sure where to find the relevant interaction code, so pointers would be helpful on that...)

bernhard-42 commented 1 week ago

Everything that is in the viewer window (cad tree, canvas with CAD object(s), mouse handling, ....) is the viewer component three-cad-viewer.

vscode-ocp-viewer does two things:

So the feature request you are asking about is in fact a three-cad-viewer topic as you suggested.

Currently it can be done by code:

set_viewer_config(target=(x,y,z))

center

bernhard-42 commented 1 week ago

And something like that can be added to the viewer component, i.e. when doing a -click, then raytracing (already used) will be used to identify the nearest point on the object that this click would point to on an axis from the camera through the click point in the view projection point to the object. And set camera's target to this point.

The code approach above uses the measure/property mode to get the coords and then sets the target of the camera.