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
This commit is contained in:
Jacques Lucke 2021-02-04 16:36:34 +01:00
parent 95703d19e0
commit e7af04db07
Notes: blender-bot 2023-02-14 09:02:40 +01:00
Referenced by issue #85277, Is Viewport visibility node
8 changed files with 58 additions and 0 deletions

View File

@ -506,6 +506,7 @@ geometry_node_categories = [
NodeItem("FunctionNodeRandomFloat"),
NodeItem("ShaderNodeValue"),
NodeItem("FunctionNodeInputVector"),
NodeItem("GeometryNodeIsViewport"),
]),
GeometryNodeCategory("GEO_MESH", "Mesh", items=[
NodeItem("GeometryNodeBoolean"),

View File

@ -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
/** \} */

View File

@ -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()

View File

@ -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>(); \
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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);
}