Page MenuHome

Assets: Object bounding-box snapping with visual feedback while dragging
AbandonedPublic

Authored by Julian Eisel (Severin) on Oct 11 2021, 3:14 PM.

Details

Summary

Basic ideas is:

  • Support drop-box gizmo-group that is visible while dragging.
  • With that, show a bounding box and a grid while dragging.
  • The object always snaps with its bottom, axis-aligned bounding box edge (Z axis) to the surface.
  • The object bounding box and world matrix are written to the asset meatadata on file save.
  • This is done through a PreSaveFn callback set for object assets via a new AssetTypeInfo struct. This struct may become more important once we support non-ID assets in future.
  • For local ID assets, the data should be accessed directly, so the file doesn't have to be saved to get the bounding box updated.

Note: Object assets have to be (re-)saved with this commit or later for the bounding box to appear.

Also:

  • The "placement plane" gizmo is scaled to the bounding box size too.
  • Added proper gizmo group custom property support to C (was already supported in Python, or in C with some hacking).
  • The object preview image is disabled while dragging objects over the 3D view.
  • Change the "Add Named Object" drag into string to "Add Object". The "Named" part is kinda useless info and relates to an implementation detail.

TODO

  • Allow snapping to both positive and negative normal direction. Currently a ground plane with -Z up will place the object the wrong way around, for example.
  • Don't use this for object types with no real geometry, e.g. cameras and lamps.
  • Don't draw the bounding box with full edges, just the corners. Makes it more clear that this is just the bounding box.

Diff Detail

Repository
rB Blender
Branch
asset-browser-snap-dragging
Build Status
Buildable 17724
Build 17724: arc lint + arc unit

Event Timeline

Julian Eisel (Severin) requested review of this revision.Oct 11 2021, 3:14 PM
Julian Eisel (Severin) created this revision.
  • Adapt to changes in master
  • Properly set rotation when dropping
  • Only hide preview image while dragging over 3D View
Julian Eisel (Severin) added inline comments.
source/blender/blenkernel/BKE_main.h
247–249

Needed to use this macro in C++.

source/blender/blenkernel/intern/object.c
1151

Calculating the bounding box can be a bit expensive, I'd rather not do it on file save. But I think at this point it's usually already calculated, so think this is nothing to worry about.

This should be double-checked though.

source/blender/editors/screen/screen_edit.c
918–924

This was an attempt to make the gizmo disappear when leaving the 3D View. It doesn't seem to work reliably enough though, something to investigate/fix.

source/blender/editors/space_view3d/view3d_placement.c
477

This wasn't respecting the line width set with GPU_line_width().

1044

view3d_interactive_add_calc_plane() actually seems to handle that case just fine, so can just remove the TODO comment I think.

1891

This kind of polling isn't great, since it means the group needs to know what it will be used for. Think a better design would be letting external code register itself as "gizmo-group user" with its own poll function. E.g. the tool or dropbox code could then poll if they apply in current context, and the gizmo code checks the polls of all its potential users.

1894

Maybe we should have a separate gizmo for the snap dragging. No strong opinion.

2246

Don't think we need to support that now, so I'm fine with just leaving this TODO in. Could also add gizmo properties without actually using them.

2375

Instantiated by the placement gizmo group, see WIDGETGROUP_placement_setup().

Julian Eisel (Severin) edited the summary of this revision. (Show Details)Oct 11 2021, 4:48 PM
source/blender/editors/include/ED_asset.h
19–21

Merge conflicts :) Ignore this change.

Julian Eisel (Severin) edited the summary of this revision. (Show Details)Oct 11 2021, 5:32 PM
Julian Eisel (Severin) edited the summary of this revision. (Show Details)Oct 11 2021, 5:44 PM
Julian Eisel (Severin) edited the summary of this revision. (Show Details)Oct 15 2021, 6:33 PM

Abandoning this since @Germano Cavalcante (mano-wii) is working on an alternative version that uses the cursor system instead of the gizmo system. Some of the changes from here will be needed still though.