[Bf-blender-cvs] [e7af04db079] master: Geometry Nodes: new Is Viewport node

Jacques Lucke noreply at git.blender.org
Thu Feb 4 16:37:57 CET 2021


Commit: e7af04db0793b6c50194e22cb54ffc08629b8d2e
Author: Jacques Lucke
Date:   Thu Feb 4 16:36:34 2021 +0100
Branches: master
https://developer.blender.org/rBe7af04db0793b6c50194e22cb54ffc08629b8d2e

Geometry Nodes: new Is Viewport node

This node outputs true when geometry nodes is currently evaluated
for the viewport and false for final renders.

Ref T85277.

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

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/functions/FN_cpp_type.hh
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_is_viewport.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index f04a3f6eaf6..f15eed64913 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -506,6 +506,7 @@ geometry_node_categories = [
         NodeItem("FunctionNodeRandomFloat"),
         NodeItem("ShaderNodeValue"),
         NodeItem("FunctionNodeInputVector"),
+        NodeItem("GeometryNodeIsViewport"),
     ]),
     GeometryNodeCategory("GEO_MESH", "Mesh", items=[
         NodeItem("GeometryNodeBoolean"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 17f116912fa..dcfd6ca7bdd 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1365,6 +1365,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE 1021
 #define GEO_NODE_POINTS_TO_VOLUME 1022
 #define GEO_NODE_COLLECTION_INFO 1023
+#define GEO_NODE_IS_VIEWPORT 1024
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 2dbfa85b8e1..3c9c255cacd 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4774,6 +4774,7 @@ static void registerGeometryNodes()
   register_node_type_geo_sample_texture();
   register_node_type_geo_points_to_volume();
   register_node_type_geo_collection_info();
+  register_node_type_geo_is_viewport();
 }
 
 static void registerFunctionNodes()
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 5a7dfadf537..a854e63288d 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -929,4 +929,9 @@ inline std::unique_ptr<const CPPType> create_cpp_type(StringRef name, const T &d
     static std::unique_ptr<const CPPType> cpp_type = blender::fn::create_cpp_type<TYPE_NAME>( \
         STRINGIFY(IDENTIFIER), default_value); \
     return *cpp_type; \
+  } \
+  /* Support using `CPPType::get<const T>()`. Otherwise the caller would have to remove const. */ \
+  template<> const blender::fn::CPPType &blender::fn::CPPType::get<const TYPE_NAME>() \
+  { \
+    return blender::fn::CPPType::get<TYPE_NAME>(); \
   }
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 9982962cabd..aedca4b34fb 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -153,6 +153,7 @@ set(SRC
   geometry/nodes/node_geo_collection_info.cc
   geometry/nodes/node_geo_common.cc
   geometry/nodes/node_geo_edge_split.cc
+  geometry/nodes/node_geo_is_viewport.cc
   geometry/nodes/node_geo_join_geometry.cc
   geometry/nodes/node_geo_object_info.cc
   geometry/nodes/node_geo_point_distribute.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 178831d5d96..9b391ab7981 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -50,6 +50,7 @@ void register_node_type_geo_align_rotation_to_vector(void);
 void register_node_type_geo_sample_texture(void);
 void register_node_type_geo_points_to_volume(void);
 void register_node_type_geo_collection_info(void);
+void register_node_type_geo_is_viewport(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index cbc5f715db0..f9730af0c08 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -292,6 +292,7 @@ DefNode(GeometryNode, GEO_NODE_POINT_TRANSLATE, def_geo_point_translate, "POINT_
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_SAMPLE_TEXTURE, def_geo_attribute_sample_texture, "ATTRIBUTE_SAMPLE_TEXTURE", AttributeSampleTexture, "Attribute Sample Texture", "")
 DefNode(GeometryNode, GEO_NODE_POINTS_TO_VOLUME, def_geo_points_to_volume, "POINTS_TO_VOLUME", PointsToVolume, "Points to Volume", "")
 DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLECTION_INFO", CollectionInfo, "Collection Info", "")
+DefNode(GeometryNode, GEO_NODE_IS_VIEWPORT, 0, "IS_VIEWPORT", IsViewport, "Is Viewport", "")
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_is_viewport.cc b/source/blender/nodes/geometry/nodes/node_geo_is_viewport.cc
new file mode 100644
index 00000000000..667beaa1722
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_is_viewport.cc
@@ -0,0 +1,47 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_geometry_util.hh"
+
+#include "DEG_depsgraph_query.h"
+
+static bNodeSocketTemplate geo_node_is_viewport_out[] = {
+    {SOCK_BOOLEAN, N_("Is Viewport")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void geo_node_is_viewport_exec(GeoNodeExecParams params)
+{
+  const Depsgraph *depsgraph = params.depsgraph();
+  const eEvaluationMode mode = DEG_get_mode(depsgraph);
+  const bool is_viewport = mode == DAG_EVAL_VIEWPORT;
+
+  params.set_output("Is Viewport", is_viewport);
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_is_viewport()
+{
+  static bNodeType ntype;
+
+  geo_node_type_base(&ntype, GEO_NODE_IS_VIEWPORT, "Is Viewport", NODE_CLASS_INPUT, 0);
+  node_type_socket_templates(&ntype, nullptr, geo_node_is_viewport_out);
+  ntype.geometry_node_execute = blender::nodes::geo_node_is_viewport_exec;
+  nodeRegisterType(&ntype);
+}



More information about the Bf-blender-cvs mailing list