Page MenuHome

Snap system: Adds support to Clip Planes and uses a clip plane to simulate occlusion
ClosedPublic

Authored by Germano Cavalcante (mano-wii) on Feb 26 2017, 3:28 PM.

Details

Summary

This patch adds support for clip_planes (ie ignore what is behind a face)...

The idea is to first execute a raycast to get the polygon to which the mouse cursor points.
Then a snap test is done on the vertices or edges of the polygon.
Then with the normal and location obtained in raycast a new clip_plane is created and the snap over the whole scene is processed ignoring the elements behind the clip_plane.

Here 2 gif of how the previous patch would work on blender2.79:

Diff Detail

Repository
rB Blender

Event Timeline

Germano Cavalcante (mano-wii) retitled this revision from to Snap system: Adds support to Clip Planes and uses a clip plane to simulate occlusion.
Germano Cavalcante (mano-wii) updated this object.
  • Update to adapt changes in the master (reobtain directory of unallocated arrays);

Great to see this problem tackled :)

  • I think it's definitely a good idea to ignore faces for object in bounding box mode. Those are most of the time complex meshes which are instanced a lot like trees. They would occlude the geometry the user really see and give unexpected result for the user (particularly when the bounding box is not visible in the current view, because the zoom level is too high). But for wireframe, I don't see a clear reason to do it. Maybe it could be an option in the snapping part of the 3DView header.
  • I'm not a specialist in this area, so excuse me if the question is stupid, but why not use the selection method (Automatic/OpenGL Occlusion Queries/OpenGL select) for snapping to face? It works good to select and the goal is the same, get the first face under the mouse cursor.
  • Maybe for a later version, it would be great to make it offer the same options/behavior like for selection: have a key to display a list of objects under the mouse cursor that could be snapped to (shift+alt+select mouse in the default keymap, it's the enumerate option). It would also solve the problem of deciding whether the draw method of objects should influence the snapping point and let the user decide on a per case basis.

The idea behind ​​ignoring faces in wireframe is that, as in BounBox, we don't see the faces. But it may not be ideal to change the current behavior of Blender, since users are already accustomed to it.

  • I'm not a specialist in this area, so excuse me if the question is stupid, but why not use the selection method (Automatic/OpenGL Occlusion Queries/OpenGL select) for snapping to face? It works good to select and the goal is the same, get the first face under the mouse cursor.

In fact we could use OpenGL to snap. For example, to test occlusion, we can use the unproject function and compare the Z-depth with Z_depth = dot_m4_v3_row_z(pmat, co)/mul_project_m4_v3_zfac(pmat, co);
But as we see in some bug reports, different GPUs sometimes have a problem with OpenGL.
The entire snap system could be done with the help of OpenGL, but in that case the functions would need to redraw the entire View3d and test each element individually (as is already done with the selection system). This is not as efficient as using CPU and BVHs.

  • Maybe for a later version, it would be great to make it offer the same options/behavior like for selection: have a key to display a list of objects under the mouse cursor that could be snapped to (shift+alt+select mouse in the default keymap, it's the enumerate option). It would also solve the problem of deciding whether the draw method of objects should influence the snapping point and let the user decide on a per case basis.

This is an interesting idea that would really help users ;)
A more urgent idea would be to expose the snap functions for Python. Thus, addons focused on architecture could add these features and enhance Blender

A more urgent idea would be to expose the snap functions for Python. Thus, addons focused on architecture could add these features and enhance Blender

Fully agree :) If it can be done for 2.79, it would be awesome.

Germano Cavalcante (mano-wii) updated this object.
  • Move function that cheks if a point is in front of all planes to math_geom;
  • Disable occlusion test in snap_to_face (corresponds to the current behavior of the blender).

isect_point_planes_positive_side_v3 to isect_point_planes_v3_negate

  • Ensure to release allocated arrays before return
  • Use BM_elem_index_get macro to get the index;

Simplifications:

  • range depth planes are now clip planes like the others... rv3d clip_planes;
  • snap_segment_v3, no longer need the ray parameters;

Other changes

  • Optimizations in dist_squared_to_projected_aabb;
  • updated to match blender2.8
Germano Cavalcante (mano-wii) edited the summary of this revision. (Show Details)
  • Cleanup: Remove unused variables.
  • Return the index of non-polygons/face elements. (Currently only mesh objects).
Campbell Barton (campbellbarton) requested changes to this revision.May 16 2018, 2:53 PM
Campbell Barton (campbellbarton) added inline comments.
source/blender/editors/transform/transform_snap_object.c
729–731

This seems like a high level check to add in low level raycast callback.

891

remove.

956

Looks like this should be a lookup BLI_ghash_lookup - since ensure is never assigning to the target.

This revision now requires changes to proceed.May 16 2018, 2:53 PM
  • Added max clipping plane;
  • cleanup (remmoved unecessary comment lines);
  • removed high level check from raycast callback;
  • use BLI_ghash_lookup instead BLI_ghash_ensure_p.
Germano Cavalcante (mano-wii) marked 3 inline comments as done.May 16 2018, 3:19 PM
Campbell Barton (campbellbarton) added inline comments.
source/blender/editors/transform/transform_snap_object.c
995

this can be changed to BLI_assert(sod->type == SNAP_EDIT_MESH);

This revision is now accepted and ready to land.May 16 2018, 3:26 PM
This revision was automatically updated to reflect the committed changes.