[Bf-blender-cvs] [c55d38f00b8] master: Geometry Nodes: viewport preview

Jacques Lucke noreply at git.blender.org
Wed Sep 28 17:56:34 CEST 2022


Commit: c55d38f00b8c0e6ae8bda9cc66614afe28fb3fc9
Author: Jacques Lucke
Date:   Wed Sep 28 17:54:59 2022 +0200
Branches: master
https://developer.blender.org/rBc55d38f00b8c0e6ae8bda9cc66614afe28fb3fc9

Geometry Nodes: viewport preview

This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.

**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
  makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
  is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
  its active or not.

**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
  When pinned, the spreadsheet still references the viewer node even
  when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
  the active viewer.

**Attribute**
* When a field is linked to the second input of the viewer node it is
  displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
  automatically. This does not work in all cases. It falls back to the
  face corner domain on meshes and the point domain on curves. When
  necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
  that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.

**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
  setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
  by disabling the "Viewer Node" option in the "View" menu.

**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
  is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
  field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
  attribute.
* The ground truth for the active viewer node is stored in the workspace
  now. Node editors, spreadsheets and viewports retrieve the active
  viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
  the viewed geometry of the corresponding object is part of the iterator
  instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
  to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
  existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
  "preferred domain" for every field input. If there is not exactly one
  preferred domain, the fallback is used.

Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
  added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
  the values might have to be normalized or some should be drawn as arrays.
  For now, we encourage users to build node groups that generate appropriate
  viewer-geometry. We might include some of that functionality in future versions.
  Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
  nvidia gpus, to be investigated.

Differential Revision: https://developer.blender.org/D15954

===================================================================

M	release/scripts/startup/bl_operators/spreadsheet.py
M	release/scripts/startup/bl_ui/space_spreadsheet.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_duplilist.h
M	source/blender/blenkernel/BKE_geometry_fields.hh
A	source/blender/blenkernel/BKE_viewer_path.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/geometry_fields.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/blenkernel/intern/object_dupli.cc
M	source/blender/blenkernel/intern/screen.c
A	source/blender/blenkernel/intern/viewer_path.cc
M	source/blender/blenkernel/intern/workspace.cc
M	source/blender/blenloader/intern/readfile.cc
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/versioning_300.cc
M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query_iter.cc
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/overlay/overlay_engine.cc
M	source/blender/draw/engines/overlay/overlay_private.hh
M	source/blender/draw/engines/overlay/overlay_shader.cc
A	source/blender/draw/engines/overlay/overlay_viewer_attribute.cc
M	source/blender/draw/engines/overlay/shaders/infos/overlay_edit_mode_info.hh
A	source/blender/draw/engines/overlay/shaders/infos/overlay_viewer_attribute_info.hh
A	source/blender/draw/engines/overlay/shaders/overlay_pointcloud_only_vert.glsl
A	source/blender/draw/engines/overlay/shaders/overlay_viewer_attribute_curve_vert.glsl
A	source/blender/draw/engines/overlay/shaders/overlay_viewer_attribute_curves_vert.glsl
A	source/blender/draw/engines/overlay/shaders/overlay_viewer_attribute_frag.glsl
A	source/blender/draw/engines/overlay/shaders/overlay_viewer_attribute_mesh_vert.glsl
A	source/blender/draw/engines/overlay/shaders/overlay_viewer_attribute_pointcloud_vert.glsl
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_extract.hh
M	source/blender/draw/intern/draw_cache_extract_mesh.cc
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_curve.cc
M	source/blender/draw/intern/draw_cache_impl_mesh.cc
M	source/blender/draw/intern/draw_cache_impl_pointcloud.cc
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/mesh_extractors/extract_mesh.hh
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc
M	source/blender/draw/tests/shaders_test.cc
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/include/ED_spreadsheet.h
A	source/blender/editors/include/ED_viewer_path.hh
M	source/blender/editors/screen/CMakeLists.txt
A	source/blender/editors/screen/workspace_listen.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_edit.cc
M	source/blender/editors/space_node/node_intern.hh
M	source/blender/editors/space_node/node_ops.cc
M	source/blender/editors/space_node/node_relationships.cc
M	source/blender/editors/space_node/node_select.cc
M	source/blender/editors/space_node/space_node.cc
M	source/blender/editors/space_spreadsheet/CMakeLists.txt
M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc
D	source/blender/editors/space_spreadsheet/spreadsheet_context.cc
D	source/blender/editors/space_spreadsheet/spreadsheet_context.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.hh
M	source/blender/editors/space_view3d/space_view3d.cc
M	source/blender/editors/space_view3d/view3d_draw.cc
M	source/blender/editors/util/CMakeLists.txt
A	source/blender/editors/util/ed_viewer_path.cc
M	source/blender/gpu/CMakeLists.txt
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesdna/DNA_view3d_defaults.h
M	source/blender/makesdna/DNA_view3d_types.h
A	source/blender/makesdna/DNA_viewer_path_types.h
M	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/NOD_geometry_nodes_log.hh
M	source/blender/nodes/geometry/nodes/node_geo_accumulate_field.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
M	source/blender/nodes/geometry/nodes/node_geo_edge_paths_to_selection.cc
M	source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_curve_handles.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_angle.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_neighbors.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_is_planar.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc
M	source/blender/nodes/geometry/nodes/node_geo_input_shortest_edge_paths.cc
M	source/blender/nodes/geometry/nodes/node_geo_interpolate_domain.cc
M	source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_face_set_boundaries.cc
M	source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
M	source/blender/nodes/geometry/nodes/node_geo_uv_pack_islands.cc
M	source/blender/nodes/geometry/nodes/node_geo_uv_unwrap.cc
M	source/blender/nodes/geometry/nodes/node_geo_viewer.cc
M	source/blender/nodes/intern/geometry_nodes_lazy_function.cc
M	source/blender/nodes/intern/geometry_nodes_log.cc
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.cc

===================================================================

diff --git a/release/scripts/startup/bl_operators/spreadsheet.py b/release/scripts/startup/bl_operators/spreadsheet.py
index 1ba7d2db2fd..aef4231d573 100644
--- a/release/scripts/startup/bl_operators/spreadsheet.py
+++ b/release/scripts/startup/bl_operators/spreadsheet.py
@@ -32,7 +32,6 @@ class SPREADSHEET_OT_toggle_pin(Operator):
     def unpin(self, context):
         space = context.space_data
         space.is_pinned = False
-        space.context_path.guess()
 
 
 classes = (
diff --git a/release/scripts/startup/bl_ui/space_spreadsheet.py b/release/scripts/startup/bl_ui/space_spreadsheet.py
index 741ad544d67..846582b0142 100644
--- a/release/scripts/startup/bl_ui/space_spreadsheet.py
+++ b/release/scripts/startup/bl_ui/space_spreadsheet.py
@@ -11,34 +11,37 @@ class SPREADSHEET_HT_header(bpy.types.Header):
         space = context.space_data
 
         layout.template_header()
+        viewer_path = space.viewer_path.path
 
-        if len(space.context_path) == 0:
-            self.draw_without_context_path(layout)
+        if len(viewer_path) == 0:
+            self.draw_without_viewer_path(layout)
             return
-        root_context = space.context_path[0]
-        if root_context.type != 'OBJECT':
-            self.draw_without_context_path(layout)
+        root_context = viewer_path[0]
+        if root_context.type != 'ID':
+            self.draw_without_viewer_path(layout)
             return
-        obj = root_context.object
+        if not isinstance(root_context.id, bpy.types.Object):
+            self.draw_without_viewer_path(layout)
+            return
+        obj = root_context.id
         if obj is None:
-            self.draw_without_context_path(layout)
+            self.draw_without_viewer_path(layout)
             return
 
         layout.prop(space, "object_eval_state", text="")
 
-        context_path = space.context_path
         if space.object_eval_state == 'ORIGINAL':
             # Only show first context.
-            context_path = context_path[:1]
-        if space.display_context_path_collapsed:
-            self.draw_collapsed_context_path(context, layout, context_path)
+            viewer_path = viewer_path[:1]
+        if space.display_viewer_path_collapsed:
+            self.draw_collapsed_viewer_path(context, layout, viewer_path)
         else:
-            self.draw_full_context_path(context, layout, context_path)
+            self.draw_full_viewer_path(context, layout, viewer_path)
 
         pin_icon = 'PINNED' if space.is_pinned else 'UNPINNED'
         layout.operator("spreadsheet.toggle_pin", text="", icon=pin_icon, emboss=False)
 
-        if space.object_eval_state == 'VIEWER_NODE' and len(context_path) < 3:
+        if space.object_eval_state == 'VIEWER_NODE' and len(viewer_path) < 3:
             layout.label(text="No active viewer node", icon='INFO')
 
         layout.separator_spacer()
@@ -49,50 +52,52 @@ class SPREADSHEET_HT_header(bpy.types.Header):
         sub.prop(space, "show_only_selected", text="")
         row.prop(space, "use_filter", toggle=True, icon='FILTER', icon_only=True)
 
-    def draw_without_context_path(self, layout):
+    def draw_without_viewer_path(self, layout):
         layout.label(text="No active context")
 
-    def draw_full_context_path(self, context, layout, context_path):
+    def draw_full_viewer_path(self, context, layout, viewer_path):
         space = context.space_data
         row = layout.row()
-        for ctx in context_path[:-1]:
+        for ctx in viewer_path[:-1]:
             subrow = row.row(align=True)
             self.draw_spreadsheet_context(subrow, ctx)
-            self.draw_spreadsheet_context_path_icon(subrow, space)
+            self.draw_spreadsheet_viewer_path_icon(subrow, space)
 
-        self.draw_spreadsheet_context(row, context_path[-1])
+        self.draw_spreadsheet_context(row, viewer_path[-1])
 
-    def draw_collapsed_context_path(self, context, layout, context_path):
+    def draw_collapsed_viewer_path(self, context, layout, viewer_path):
         space = context.space_data
         row = layout.row(align=True)
-        self.draw_spreadsheet_context(row, context_path[0])
-        if len(context_path) == 1:
+        self.draw_spreadsheet_context(row, viewer_path[0])
+        if len(viewer_path) == 1:
             return
-        self.draw_spreadsheet_context_path_icon(row, space)
-        if len(context_path) > 2:
-            self.draw_spreadsheet_context_path_icon(row, space, icon='DOT')
-            self.draw_spreadsheet_context_path_icon(row, space)
-        self.draw_spreadsheet_context(row, context_path[-1])
+        self.draw_spreadsheet_viewer_path_icon(row, space)
+        if len(viewer_path) > 2:
+            self.draw_spreadsheet_viewer_path_icon(row, space, icon='DOT')
+            self.draw_spreadsheet_viewer_path_icon(row, space)
+        self.draw_spreadsheet_context(row, viewer_path[-1])
 
     def draw_spreadsheet_context(self, layout, ctx):
-        if ctx.type == 'OBJECT':
-            if ctx.object is None:
-                layout.label(text="<no object>", icon='OBJECT_DATA')
+        if ctx.type == 'ID':
+            if ctx.id is not None and isinstance(ctx.id, bpy.types.Object):
+                layout.label(text=ctx.id.name, icon='OBJECT_DATA')
             else:
-                layout.label(text=ctx.object.name, icon='OBJECT_DATA')
+                layout.label(text="Invalid id")
         elif ctx.type == 'MODIFIER':
             layout.label(text=ctx.modifier_name, icon='MODIFIER')
         elif ctx.type == 'NODE':
             layout.label(text=ctx.node_name, icon='NODE')
 
-    def draw_spreadsheet_context_path_icon(self, layout, space, icon='RIGHTARROW_THIN'):
-        layout.prop(space, "display_context_path_collapsed", icon_only=True, emboss=False, icon=icon)
+    def draw_spreadsheet_viewer_path_icon(self, layout, space, icon='RIGHTARROW_THIN'):
+        layout.prop(space, "display_viewer_path_collapsed", icon_only=True, emboss=False, icon=icon)
 
     def selection_filter_available(self, space):
-        root_context = space.context_path[0]
-        if root_context.type != 'OBJECT':
+        root_context = space.viewer_path.path[0]
+        if root_context.type != 'ID':
+            return False
+        if not isinstance(root_context.id, bpy.types.Object):
             return False
-        obj = root_context.object
+        obj = root_context.id
         if obj is None:
             return False
         if obj.type == 'MESH':
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a687f3c937f..092fae671e0 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1216,6 +1216,7 @@ class VIEW3D_MT_view(Menu):
         layout.operator("view3d.view_all").center = False
         layout.operator("view3d.view_persportho", text="Perspective/Orthographic")
         layout.menu("VIEW3D_MT_view_local")
+        layout.prop(view, "show_viewer", text="Viewer Node")
 
         layout.separator()
 
@@ -6346,6 +6347,13 @@ class VIEW3D_PT_overlay_geometry(Panel):
         sub.prop(overlay, "wireframe_threshold", text="Wireframe")
         sub.prop(overlay, "wireframe_opacity", text="Opacity")
 
+        row = col.row(align=True)
+        row.active = view.show_viewer
+        row.prop(overlay, "show_viewer_attribute", text="")
+        subrow = row.row(align=True)
+        subrow.active = overlay.show_viewer_attribute
+        subrow.prop(overlay, "viewer_attribute_opacity", text="Viewer Node")
+
         row = col.row(align=True)
 
         # These properties should be always available in the UI for all modes
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 28c15d9224c..4dd596ad93a 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -82,6 +82,7 @@ set(SRC_DNA_INC
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view2d_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view3d_enums.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view3d_types.h
+  ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_viewer_path_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_volume_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_windowmanager_types.h
   ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_workspace_types.h
diff --git a/source/blender/blenkernel/BKE_duplilist.h b/source/blender/blenkernel/BKE_duplilist.h
index 0648cdde529..831cb5031c2 100644
--- a/source/blender/blenkernel/BKE_duplilist.h
+++ b/source/blender/blenkernel/BKE_duplilist.h
@@ -16,6 +16,8 @@ struct ListBase;
 struct Object;
 struct ParticleSystem;
 struct Scene;
+struct ViewerPath;
+struct GeomerySet;
 
 /* ---------------------------------------------------- */
 /* Dupli-Geometry */
@@ -26,6 +28,13 @@ struct Scene;
 struct ListBase *object_duplilist(struct Depsgraph *depsgraph,
                                   struct Scene *sce,
                                   struct Object *ob);
+/**
+ * \return a #ListBase of #DupliObject for the preview geometry referenced by the #ViewerPath.
+ */
+struct ListBase *object_duplilist_preview(struct Depsgraph *depsgraph,
+                                          struct Scene *scene,
+                                          struct Object *ob,
+                                          const struct ViewerPath *viewer_path);
 void free_object_duplilist(struct ListBase *lb);
 
 typedef struct DupliObject {
@@ -39,6 +48,10 @@ typedef struct DupliObject {
 
   short type; /* from Object.transflag */
   char no_draw;
+  /* If this dupli object is belongs to a preview, this is non-null. */
+  const struct GeometrySet *preview_base_geometry;
+  /* Index of the top-level instance this dupli is part of or -1 when unused. */
+  int preview_instance_index;
 
   /* Persistent identifier for a dupli object, for inter-frame matching of
    * objects with motion blur, or inter-update matching for syncing. */
diff --git a/source/blender/blenkernel/BKE_geometry_fields.hh b/source/blender/blenkernel/BKE_geometry_fields.hh
index 62aac5a4120..988e0017f04 100644
--- a/source/blender/blenkernel/BKE_geometry_fields.hh
+++ b/source/blender/blenkernel/BKE_geometry_fields.hh


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list