[Bf-blender-cvs] [c6ff722a1fc] master: Spreadsheet: support showing data of specific node

Jacques Lucke noreply at git.blender.org
Thu Apr 8 17:36:25 CEST 2021


Commit: c6ff722a1fcc632eacebcfc94417df466742ce5f
Author: Jacques Lucke
Date:   Thu Apr 8 17:35:06 2021 +0200
Branches: master
https://developer.blender.org/rBc6ff722a1fcc632eacebcfc94417df466742ce5f

Spreadsheet: support showing data of specific node

Previously, the spreadsheet editor could only show data of the original
and of the final evaluated object. Now it is possible to show the data
at some intermediate stages too.

For that the mode has to be set to "Node" in the spreadsheet editor.
Furthermore, the preview of a specific node has to be activated by
clicking the new icon in the header of geometry nodes.

The exact ui of this feature might be refined in upcoming commits.
It is already very useful for debugging node groups in it's current
state though.

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

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/geometry_component_instances.cc
M	source/blender/blenkernel/intern/geometry_component_mesh.cc
M	source/blender/blenkernel/intern/geometry_component_pointcloud.cc
M	source/blender/blenkernel/intern/geometry_component_volume.cc
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/node_ops.c
M	source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/modifiers/intern/MOD_nodes.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index ab126ecb152..2ce8ce5749f 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -141,6 +141,12 @@ class GeometryComponent {
   /* The returned component should be of the same type as the type this is called on. */
   virtual GeometryComponent *copy() const = 0;
 
+  /* Direct data is everything except for instances of objects/collections.
+   * If this returns true, the geometry set can be cached and is still valid after e.g. modifier
+   * evaluation ends. Instances can only be valid as long as the data they instance is valid. */
+  virtual bool owns_direct_data() const = 0;
+  virtual void ensure_owns_direct_data() = 0;
+
   void user_add() const;
   void user_remove() const;
   bool is_mutable() const;
@@ -315,6 +321,8 @@ struct GeometrySet {
 
   void clear();
 
+  void ensure_owns_direct_data();
+
   /* Utility methods for creation. */
   static GeometrySet create_with_mesh(
       Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
@@ -374,6 +382,9 @@ class MeshComponent : public GeometryComponent {
 
   bool is_empty() const final;
 
+  bool owns_direct_data() const override;
+  void ensure_owns_direct_data() override;
+
   static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_MESH;
 
  private:
@@ -404,6 +415,9 @@ class PointCloudComponent : public GeometryComponent {
 
   bool is_empty() const final;
 
+  bool owns_direct_data() const override;
+  void ensure_owns_direct_data() override;
+
   static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_POINT_CLOUD;
 
  private:
@@ -444,6 +458,9 @@ class InstancesComponent : public GeometryComponent {
 
   bool is_empty() const final;
 
+  bool owns_direct_data() const override;
+  void ensure_owns_direct_data() override;
+
   static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_INSTANCES;
 };
 
@@ -466,5 +483,8 @@ class VolumeComponent : public GeometryComponent {
   const Volume *get_for_read() const;
   Volume *get_for_write();
 
+  bool owns_direct_data() const override;
+  void ensure_owns_direct_data() override;
+
   static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_VOLUME;
 };
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 0c2c6313dde..6d5638375d6 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -34,6 +34,7 @@ struct Base;
 struct BoundBox;
 struct Curve;
 struct Depsgraph;
+struct GeometrySet;
 struct GpencilModifierData;
 struct HookGpencilModifierData;
 struct HookModifierData;
@@ -69,6 +70,8 @@ void BKE_object_free_curve_cache(struct Object *ob);
 void BKE_object_free_derived_caches(struct Object *ob);
 void BKE_object_free_caches(struct Object *object);
 
+void BKE_object_set_preview_geometry_set(struct Object *ob, struct GeometrySet *geometry_set);
+
 void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd);
 void BKE_object_modifier_gpencil_hook_reset(struct Object *ob,
                                             struct HookGpencilModifierData *hmd);
diff --git a/source/blender/blenkernel/intern/geometry_component_instances.cc b/source/blender/blenkernel/intern/geometry_component_instances.cc
index 68c551645d2..11526eda762 100644
--- a/source/blender/blenkernel/intern/geometry_component_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_component_instances.cc
@@ -108,6 +108,18 @@ bool InstancesComponent::is_empty() const
   return transforms_.size() == 0;
 }
 
+bool InstancesComponent::owns_direct_data() const
+{
+  /* The object and collection instances are not direct data. Instance transforms are direct data
+   * and are always owned. Therefore, instance components always own all their direct data. */
+  return true;
+}
+
+void InstancesComponent::ensure_owns_direct_data()
+{
+  BLI_assert(this->is_mutable());
+}
+
 static blender::Array<int> generate_unique_instance_ids(Span<int> original_ids)
 {
   using namespace blender;
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index f0f46717744..df451b5db1d 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -157,6 +157,20 @@ bool MeshComponent::is_empty() const
   return mesh_ == nullptr;
 }
 
+bool MeshComponent::owns_direct_data() const
+{
+  return ownership_ == GeometryOwnershipType::Owned;
+}
+
+void MeshComponent::ensure_owns_direct_data()
+{
+  BLI_assert(this->is_mutable());
+  if (ownership_ != GeometryOwnershipType::Owned) {
+    mesh_ = BKE_mesh_copy_for_eval(mesh_, false);
+    ownership_ = GeometryOwnershipType::Owned;
+  }
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/geometry_component_pointcloud.cc b/source/blender/blenkernel/intern/geometry_component_pointcloud.cc
index 32c4ee8a6a6..135de14b4f7 100644
--- a/source/blender/blenkernel/intern/geometry_component_pointcloud.cc
+++ b/source/blender/blenkernel/intern/geometry_component_pointcloud.cc
@@ -107,6 +107,20 @@ bool PointCloudComponent::is_empty() const
   return pointcloud_ == nullptr;
 }
 
+bool PointCloudComponent::owns_direct_data() const
+{
+  return ownership_ == GeometryOwnershipType::Owned;
+}
+
+void PointCloudComponent::ensure_owns_direct_data()
+{
+  BLI_assert(this->is_mutable());
+  if (ownership_ != GeometryOwnershipType::Owned) {
+    pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_, false);
+    ownership_ = GeometryOwnershipType::Owned;
+  }
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/geometry_component_volume.cc b/source/blender/blenkernel/intern/geometry_component_volume.cc
index fd2327e0bf5..94ed07a63de 100644
--- a/source/blender/blenkernel/intern/geometry_component_volume.cc
+++ b/source/blender/blenkernel/intern/geometry_component_volume.cc
@@ -97,4 +97,18 @@ Volume *VolumeComponent::get_for_write()
   return volume_;
 }
 
+bool VolumeComponent::owns_direct_data() const
+{
+  return ownership_ == GeometryOwnershipType::Owned;
+}
+
+void VolumeComponent::ensure_owns_direct_data()
+{
+  BLI_assert(this->is_mutable());
+  if (ownership_ != GeometryOwnershipType::Owned) {
+    volume_ = BKE_volume_copy_for_eval(volume_, false);
+    ownership_ = GeometryOwnershipType::Owned;
+  }
+}
+
 /** \} */
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 3b027c05f39..fd86f4e550c 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -207,6 +207,19 @@ void GeometrySet::clear()
   components_.clear();
 }
 
+/* Make sure that the geometry can be cached. This does not ensure ownership of object/collection
+ * instances. */
+void GeometrySet::ensure_owns_direct_data()
+{
+  for (GeometryComponentType type : components_.keys()) {
+    const GeometryComponent *component = this->get_component_for_read(type);
+    if (!component->owns_direct_data()) {
+      GeometryComponent &component_for_write = this->get_component_for_write(type);
+      component_for_write.ensure_owns_direct_data();
+    }
+  }
+}
+
 /* Returns a read-only mesh or null. */
 const Mesh *GeometrySet::get_mesh_for_read() const
 {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 1c56312b38b..002071fac30 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1756,6 +1756,10 @@ void BKE_object_free_derived_caches(Object *ob)
     BKE_geometry_set_free(ob->runtime.geometry_set_eval);
     ob->runtime.geometry_set_eval = NULL;
   }
+  if (ob->runtime.geometry_set_preview != NULL) {
+    BKE_geometry_set_free(ob->runtime.geometry_set_preview);
+    ob->runtime.geometry_set_preview = NULL;
+  }
 }
 
 void BKE_object_free_caches(Object *object)
@@ -1806,6 +1810,18 @@ void BKE_object_free_caches(Object *object)
   }
 }
 
+/* Can be called from multiple threads. */
+void BKE_object_set_preview_geometry_set(Object *ob, struct GeometrySet *geometry_set)
+{
+  static ThreadMutex mutex = BLI_MUTEX_INITIALIZER;
+  BLI_mutex_lock(&mutex);
+  if (ob->runtime.geometry_set_preview != NULL) {
+    BKE_geometry_set_free(ob->runtime.geometry_set_preview);
+  }
+  ob->runtime.geometry_set_preview = geometry_set;
+  BLI_mutex_unlock(&mutex);
+}
+
 /**
  * Actual check for internal data, not context or flags.
  */
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 07a5dbe1d7b..88234c861a0 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1404,6 +1404,28 @@ static void node_draw_basis(const bContext *C,
                  "");
     UI_block_emboss_set(node->block, UI_EMBOSS);
   }
+  if (ntree->type == NTREE_GEOMETRY) {
+    /* Active preview toggle. */
+    iconofs -= iconbutw;
+    UI_block_emboss_set(node->block, UI_EMBOSS_NONE);
+    int icon = (node->flag & NODE_ACTIVE_PREVIEW) ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON;
+    uiBut *but = uiDefIconBut(node->block,
+                              UI_BTYPE_BUT_TOGGLE,
+                              0,
+                              icon,
+                              iconofs,
+                              rct->ymax - NODE_DY,
+                              iconbutw,
+                              UI_UNIT_Y,
+                              nullptr,
+                              0,
+                              0,
+                              0,
+                              0,
+                              "Show this node's geometry output in the spreadsheet in Node mode");
+    UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_active_preview_toggle");
+    UI_block_emboss

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list