Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-09-28 18:54:59 +0300
committerJacques Lucke <jacques@blender.org>2022-09-28 18:54:59 +0300
commitc55d38f00b8c0e6ae8bda9cc66614afe28fb3fc9 (patch)
tree0fc280eec3e2d0655197afda823de1062f51ea05 /source/blender/blenkernel/intern/viewer_path.cc
parent2312915b9620808d29e9b20529684800638d5a2a (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/viewer_path.cc')
-rw-r--r--source/blender/blenkernel/intern/viewer_path.cc270
1 files changed, 270 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/viewer_path.cc b/source/blender/blenkernel/intern/viewer_path.cc
new file mode 100644
index 00000000000..3074a007af4
--- /dev/null
+++ b/source/blender/blenkernel/intern/viewer_path.cc
@@ -0,0 +1,270 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "BKE_lib_query.h"
+#include "BKE_lib_remap.h"
+#include "BKE_viewer_path.h"
+
+#include "BLI_index_range.hh"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_string_ref.hh"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLO_read_write.h"
+
+using blender::IndexRange;
+using blender::StringRef;
+
+void BKE_viewer_path_init(ViewerPath *viewer_path)
+{
+ BLI_listbase_clear(&viewer_path->path);
+}
+
+void BKE_viewer_path_clear(ViewerPath *viewer_path)
+{
+ LISTBASE_FOREACH_MUTABLE (ViewerPathElem *, elem, &viewer_path->path) {
+ BKE_viewer_path_elem_free(elem);
+ }
+ BLI_listbase_clear(&viewer_path->path);
+}
+
+void BKE_viewer_path_copy(ViewerPath *dst, const ViewerPath *src)
+{
+ BKE_viewer_path_init(dst);
+ LISTBASE_FOREACH (const ViewerPathElem *, src_elem, &src->path) {
+ ViewerPathElem *new_elem = BKE_viewer_path_elem_copy(src_elem);
+ BLI_addtail(&dst->path, new_elem);
+ }
+}
+
+bool BKE_viewer_path_equal(const ViewerPath *a, const ViewerPath *b)
+{
+ const ViewerPathElem *elem_a = static_cast<const ViewerPathElem *>(a->path.first);
+ const ViewerPathElem *elem_b = static_cast<const ViewerPathElem *>(b->path.first);
+
+ while (elem_a != nullptr && elem_b != nullptr) {
+ if (!BKE_viewer_path_elem_equal(elem_a, elem_b)) {
+ return false;
+ }
+ elem_a = elem_a->next;
+ elem_b = elem_b->next;
+ }
+ if (elem_a == nullptr && elem_b == nullptr) {
+ return true;
+ }
+ return false;
+}
+
+void BKE_viewer_path_blend_write(struct BlendWriter *writer, const ViewerPath *viewer_path)
+{
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
+ BLO_write_struct(writer, IDViewerPathElem, typed_elem);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ auto typed_elem = reinterpret_cast<ModifierViewerPathElem *>(elem);
+ BLO_write_struct(writer, ModifierViewerPathElem, typed_elem);
+ BLO_write_string(writer, typed_elem->modifier_name);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ auto typed_elem = reinterpret_cast<NodeViewerPathElem *>(elem);
+ BLO_write_struct(writer, NodeViewerPathElem, typed_elem);
+ BLO_write_string(writer, typed_elem->node_name);
+ break;
+ }
+ }
+ }
+}
+
+void BKE_viewer_path_blend_read_data(struct BlendDataReader *reader, ViewerPath *viewer_path)
+{
+ BLO_read_list(reader, &viewer_path->path);
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ auto typed_elem = reinterpret_cast<ModifierViewerPathElem *>(elem);
+ BLO_read_data_address(reader, &typed_elem->modifier_name);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ auto typed_elem = reinterpret_cast<NodeViewerPathElem *>(elem);
+ BLO_read_data_address(reader, &typed_elem->node_name);
+ break;
+ }
+ }
+ }
+}
+
+void BKE_viewer_path_blend_read_lib(BlendLibReader *reader, Library *lib, ViewerPath *viewer_path)
+{
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
+ BLO_read_id_address(reader, lib, &typed_elem->id);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER:
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ break;
+ }
+ }
+ }
+}
+
+void BKE_viewer_path_foreach_id(LibraryForeachIDData *data, ViewerPath *viewer_path)
+{
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
+ BKE_LIB_FOREACHID_PROCESS_ID(data, typed_elem->id, IDWALK_CB_NOP);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER:
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ break;
+ }
+ }
+ }
+}
+
+void BKE_viewer_path_id_remap(ViewerPath *viewer_path, const IDRemapper *mappings)
+{
+ LISTBASE_FOREACH (ViewerPathElem *, elem, &viewer_path->path) {
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto typed_elem = reinterpret_cast<IDViewerPathElem *>(elem);
+ BKE_id_remapper_apply(mappings, &typed_elem->id, ID_REMAP_APPLY_DEFAULT);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER:
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ break;
+ }
+ }
+ }
+}
+
+ViewerPathElem *BKE_viewer_path_elem_new(const ViewerPathElemType type)
+{
+ switch (type) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ IDViewerPathElem *elem = MEM_cnew<IDViewerPathElem>(__func__);
+ elem->base.type = type;
+ return &elem->base;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ ModifierViewerPathElem *elem = MEM_cnew<ModifierViewerPathElem>(__func__);
+ elem->base.type = type;
+ return &elem->base;
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ NodeViewerPathElem *elem = MEM_cnew<NodeViewerPathElem>(__func__);
+ elem->base.type = type;
+ return &elem->base;
+ }
+ }
+ BLI_assert_unreachable();
+ return nullptr;
+}
+
+IDViewerPathElem *BKE_viewer_path_elem_new_id()
+{
+ return reinterpret_cast<IDViewerPathElem *>(BKE_viewer_path_elem_new(VIEWER_PATH_ELEM_TYPE_ID));
+}
+
+ModifierViewerPathElem *BKE_viewer_path_elem_new_modifier()
+{
+ return reinterpret_cast<ModifierViewerPathElem *>(
+ BKE_viewer_path_elem_new(VIEWER_PATH_ELEM_TYPE_MODIFIER));
+}
+
+NodeViewerPathElem *BKE_viewer_path_elem_new_node()
+{
+ return reinterpret_cast<NodeViewerPathElem *>(
+ BKE_viewer_path_elem_new(VIEWER_PATH_ELEM_TYPE_NODE));
+}
+
+ViewerPathElem *BKE_viewer_path_elem_copy(const ViewerPathElem *src)
+{
+ ViewerPathElem *dst = BKE_viewer_path_elem_new(ViewerPathElemType(src->type));
+ switch (ViewerPathElemType(src->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto old_elem = reinterpret_cast<const IDViewerPathElem *>(src);
+ auto new_elem = reinterpret_cast<IDViewerPathElem *>(dst);
+ new_elem->id = old_elem->id;
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ auto old_elem = reinterpret_cast<const ModifierViewerPathElem *>(src);
+ auto new_elem = reinterpret_cast<ModifierViewerPathElem *>(dst);
+ if (old_elem->modifier_name != nullptr) {
+ new_elem->modifier_name = BLI_strdup(old_elem->modifier_name);
+ }
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ auto old_elem = reinterpret_cast<const NodeViewerPathElem *>(src);
+ auto new_elem = reinterpret_cast<NodeViewerPathElem *>(dst);
+ if (old_elem->node_name != nullptr) {
+ new_elem->node_name = BLI_strdup(old_elem->node_name);
+ }
+ break;
+ }
+ }
+ return dst;
+}
+
+bool BKE_viewer_path_elem_equal(const ViewerPathElem *a, const ViewerPathElem *b)
+{
+ if (a->type != b->type) {
+ return false;
+ }
+ switch (ViewerPathElemType(a->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ auto a_elem = reinterpret_cast<const IDViewerPathElem *>(a);
+ auto b_elem = reinterpret_cast<const IDViewerPathElem *>(b);
+ return a_elem->id == b_elem->id;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ auto a_elem = reinterpret_cast<const ModifierViewerPathElem *>(a);
+ auto b_elem = reinterpret_cast<const ModifierViewerPathElem *>(b);
+ return StringRef(a_elem->modifier_name) == StringRef(b_elem->modifier_name);
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ auto a_elem = reinterpret_cast<const NodeViewerPathElem *>(a);
+ auto b_elem = reinterpret_cast<const NodeViewerPathElem *>(b);
+ return StringRef(a_elem->node_name) == StringRef(b_elem->node_name);
+ }
+ }
+ return false;
+}
+
+void BKE_viewer_path_elem_free(ViewerPathElem *elem)
+{
+ switch (ViewerPathElemType(elem->type)) {
+ case VIEWER_PATH_ELEM_TYPE_ID: {
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_MODIFIER: {
+ auto typed_elem = reinterpret_cast<ModifierViewerPathElem *>(elem);
+ MEM_SAFE_FREE(typed_elem->modifier_name);
+ break;
+ }
+ case VIEWER_PATH_ELEM_TYPE_NODE: {
+ auto typed_elem = reinterpret_cast<NodeViewerPathElem *>(elem);
+ MEM_SAFE_FREE(typed_elem->node_name);
+ break;
+ }
+ }
+ MEM_freeN(elem);
+}