Geometry Nodes: Add Viewport Transform node #118680
@ -295,6 +295,8 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
|
|||||||
node_add_menu.add_node_type(layout, "GeometryNodeObjectInfo")
|
node_add_menu.add_node_type(layout, "GeometryNodeObjectInfo")
|
||||||
node_add_menu.add_node_type(layout, "GeometryNodeInputSceneTime")
|
node_add_menu.add_node_type(layout, "GeometryNodeInputSceneTime")
|
||||||
node_add_menu.add_node_type(layout, "GeometryNodeSelfObject")
|
node_add_menu.add_node_type(layout, "GeometryNodeSelfObject")
|
||||||
|
if context.space_data.geometry_nodes_type == 'TOOL':
|
||||||
|
node_add_menu.add_node_type(layout, "GeometryNodeViewportTransform")
|
||||||
node_add_menu.draw_assets_for_catalog(layout, "Input/Scene")
|
node_add_menu.draw_assets_for_catalog(layout, "Input/Scene")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1278,6 +1278,7 @@ void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, int layer_index
|
|||||||
#define GEO_NODE_GRID_TO_MESH 2129
|
#define GEO_NODE_GRID_TO_MESH 2129
|
||||||
#define GEO_NODE_DISTRIBUTE_POINTS_IN_GRID 2130
|
#define GEO_NODE_DISTRIBUTE_POINTS_IN_GRID 2130
|
||||||
#define GEO_NODE_SDF_GRID_BOOLEAN 2131
|
#define GEO_NODE_SDF_GRID_BOOLEAN 2131
|
||||||
|
#define GEO_NODE_TOOL_VIEWPORT_TRANSFORM 2132
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
|
@ -394,6 +394,7 @@ static int run_node_group_exec(bContext *C, wmOperator *op)
|
|||||||
Main *bmain = CTX_data_main(C);
|
Main *bmain = CTX_data_main(C);
|
||||||
Scene *scene = CTX_data_scene(C);
|
Scene *scene = CTX_data_scene(C);
|
||||||
Object *active_object = CTX_data_active_object(C);
|
Object *active_object = CTX_data_active_object(C);
|
||||||
|
const RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||||
if (!active_object) {
|
if (!active_object) {
|
||||||
return OPERATOR_CANCELLED;
|
return OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
@ -470,6 +471,7 @@ static int run_node_group_exec(bContext *C, wmOperator *op)
|
|||||||
operator_eval_data.depsgraphs = &depsgraphs;
|
operator_eval_data.depsgraphs = &depsgraphs;
|
||||||
operator_eval_data.self_object_orig = object;
|
operator_eval_data.self_object_orig = object;
|
||||||
operator_eval_data.scene_orig = scene;
|
operator_eval_data.scene_orig = scene;
|
||||||
|
operator_eval_data.rv3d = rv3d;
|
||||||
|
|
||||||
nodes::GeoNodesCallData call_data{};
|
nodes::GeoNodesCallData call_data{};
|
||||||
call_data.operator_data = &operator_eval_data;
|
call_data.operator_data = &operator_eval_data;
|
||||||
|
@ -190,6 +190,7 @@ struct GeoNodesOperatorData {
|
|||||||
const Object *self_object_orig = nullptr;
|
const Object *self_object_orig = nullptr;
|
||||||
const GeoNodesOperatorDepsgraphs *depsgraphs = nullptr;
|
const GeoNodesOperatorDepsgraphs *depsgraphs = nullptr;
|
||||||
Scene *scene_orig = nullptr;
|
Scene *scene_orig = nullptr;
|
||||||
|
const RegionView3D *rv3d = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GeoNodesCallData {
|
struct GeoNodesCallData {
|
||||||
|
@ -469,6 +469,7 @@ DefNode(GeometryNode, GEO_NODE_TOOL_FACE_SET, 0, "TOOL_FACE_SET", ToolFaceSet, "
|
|||||||
DefNode(GeometryNode, GEO_NODE_TOOL_SELECTION, 0, "TOOL_SELECTION", ToolSelection, "Selection", "User selection of the edited geometry, for tool execution")
|
DefNode(GeometryNode, GEO_NODE_TOOL_SELECTION, 0, "TOOL_SELECTION", ToolSelection, "Selection", "User selection of the edited geometry, for tool execution")
|
||||||
DefNode(GeometryNode, GEO_NODE_TOOL_SET_FACE_SET, 0, "TOOL_SET_FACE_SET", ToolSetFaceSet, "Set Face Set", "Set sculpt face set values for faces")
|
DefNode(GeometryNode, GEO_NODE_TOOL_SET_FACE_SET, 0, "TOOL_SET_FACE_SET", ToolSetFaceSet, "Set Face Set", "Set sculpt face set values for faces")
|
||||||
DefNode(GeometryNode, GEO_NODE_TOOL_SET_SELECTION, 0, "TOOL_SELECTION_SET", ToolSetSelection, "Set Selection", "Set selection of the edited geometry, for tool execution")
|
DefNode(GeometryNode, GEO_NODE_TOOL_SET_SELECTION, 0, "TOOL_SELECTION_SET", ToolSetSelection, "Set Selection", "Set selection of the edited geometry, for tool execution")
|
||||||
|
DefNode(GeometryNode, GEO_NODE_TOOL_VIEWPORT_TRANSFORM, 0, "VIEWPORT_TRANFORM", ViewportTransform, "Viewport Transform", "Retrieve the view direction and location of the 3D viewport")
|
||||||
DefNode(GeometryNode, GEO_NODE_TRANSFORM_GEOMETRY, 0, "TRANSFORM_GEOMETRY", Transform, "Transform Geometry", "Translate, rotate or scale the geometry")
|
DefNode(GeometryNode, GEO_NODE_TRANSFORM_GEOMETRY, 0, "TRANSFORM_GEOMETRY", Transform, "Transform Geometry", "Translate, rotate or scale the geometry")
|
||||||
DefNode(GeometryNode, GEO_NODE_TRANSLATE_INSTANCES, 0, "TRANSLATE_INSTANCES",TranslateInstances, "Translate Instances", "Move top-level geometry instances in local or global space")
|
DefNode(GeometryNode, GEO_NODE_TRANSLATE_INSTANCES, 0, "TRANSLATE_INSTANCES",TranslateInstances, "Translate Instances", "Move top-level geometry instances in local or global space")
|
||||||
DefNode(GeometryNode, GEO_NODE_TRIANGULATE, 0, "TRIANGULATE", Triangulate, "Triangulate", "Convert all faces in a mesh to triangular faces")
|
DefNode(GeometryNode, GEO_NODE_TRIANGULATE, 0, "TRIANGULATE", Triangulate, "Triangulate", "Convert all faces in a mesh to triangular faces")
|
||||||
|
@ -205,6 +205,7 @@ set(SRC
|
|||||||
nodes/node_geo_uv_pack_islands.cc
|
nodes/node_geo_uv_pack_islands.cc
|
||||||
nodes/node_geo_uv_unwrap.cc
|
nodes/node_geo_uv_unwrap.cc
|
||||||
nodes/node_geo_viewer.cc
|
nodes/node_geo_viewer.cc
|
||||||
|
nodes/node_geo_viewport_transform.cc
|
||||||
nodes/node_geo_volume_cube.cc
|
nodes/node_geo_volume_cube.cc
|
||||||
nodes/node_geo_volume_to_mesh.cc
|
nodes/node_geo_volume_to_mesh.cc
|
||||||
|
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/* SPDX-FileCopyrightText: 2024 Blender Authors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
|
|
||||||
|
#include "DNA_view3d_types.h"
|
||||||
|
|
||||||
|
#include "BLI_math_matrix.hh"
|
||||||
|
|
||||||
|
#include "node_geometry_util.hh"
|
||||||
|
|
||||||
|
namespace blender::nodes::node_geo_viewport_transform_cc {
|
||||||
|
|
||||||
|
static void node_declare(NodeDeclarationBuilder &b)
|
||||||
|
{
|
||||||
|
b.add_output<decl::Matrix>("Projection")
|
||||||
|
.description("The 3D viewport's perspective or orthographic projection matrix");
|
||||||
HooglyBoogly marked this conversation as resolved
Outdated
|
|||||||
|
b.add_output<decl::Matrix>("View").description(
|
||||||
|
"The view direction and location of the 3D viewport");
|
||||||
|
b.add_output<decl::Bool>("Is Orthographic")
|
||||||
|
.description("Whether the viewport is using orthographic projection");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void node_geo_exec(GeoNodeExecParams params)
|
||||||
|
{
|
||||||
|
if (!check_tool_context_and_error(params)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
HooglyBoogly marked this conversation as resolved
Outdated
Jacques Lucke
commented
Node group operators should work even when there is no 3D view. Node group operators should work even when there is no 3D view.
|
|||||||
|
const Object &self_object = *params.self_object();
|
||||||
|
const RegionView3D *rv3d = params.user_data()->call_data->operator_data->rv3d;
|
||||||
|
if (!rv3d) {
|
||||||
|
params.set_default_remaining_outputs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params.set_output("Projection", float4x4(rv3d->winmat) * self_object.object_to_world());
|
||||||
|
params.set_output("View", float4x4(rv3d->viewmat) * self_object.object_to_world());
|
||||||
|
params.set_output("Is Orthographic", !bool(rv3d->is_persp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void node_register()
|
||||||
|
{
|
||||||
|
static bNodeType ntype;
|
||||||
|
geo_node_type_base(
|
||||||
|
&ntype, GEO_NODE_TOOL_VIEWPORT_TRANSFORM, "Viewport Transform", NODE_CLASS_INPUT);
|
||||||
|
ntype.declare = node_declare;
|
||||||
|
ntype.geometry_node_execute = node_geo_exec;
|
||||||
|
ntype.gather_link_search_ops = search_link_ops_for_tool_node;
|
||||||
|
nodeRegisterType(&ntype);
|
||||||
|
}
|
||||||
|
NOD_REGISTER_NODE(node_register)
|
||||||
|
|
||||||
|
} // namespace blender::nodes::node_geo_viewport_transform_cc
|
Loading…
Reference in New Issue
Block a user
perspective or orthographic?
Okay I guess it deals with orthographic projection too. I'll change it to
perspective or orthographic