Geometry Nodes: Add Project point matrix node #120597

Merged
Hans Goudey merged 7 commits from HooglyBoogly/blender:geometry-nodes-project-point into main 2024-04-24 15:56:44 +02:00
5 changed files with 41 additions and 0 deletions

View File

@ -610,6 +610,7 @@ class NODE_MT_category_utilities_matrix(Menu):
node_add_menu.add_node_type(layout, "FunctionNodeCombineTransform")
node_add_menu.add_node_type(layout, "FunctionNodeInvertMatrix")
node_add_menu.add_node_type(layout, "FunctionNodeMatrixMultiply")
node_add_menu.add_node_type(layout, "FunctionNodeProjectPoint")
node_add_menu.add_node_type(layout, "FunctionNodeSeparateTransform")
node_add_menu.add_node_type(layout, "FunctionNodeTransformDirection")
node_add_menu.add_node_type(layout, "FunctionNodeTransformPoint")

View File

@ -1320,6 +1320,7 @@ void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, int layer_index
#define FN_NODE_SEPARATE_TRANSFORM 1236
#define FN_NODE_INVERT_MATRIX 1237
#define FN_NODE_TRANSPOSE_MATRIX 1238
#define FN_NODE_PROJECT_POINT 1239
/** \} */

View File

@ -280,6 +280,7 @@ DefNode(FunctionNode, FN_NODE_INPUT_VECTOR, def_fn_input_vector, "INPUT_VECTOR",
DefNode(FunctionNode, FN_NODE_INVERT_MATRIX, 0, "INVERT_MATRIX", InvertMatrix, "Invert Matrix", "")
DefNode(FunctionNode, FN_NODE_INVERT_ROTATION, 0, "INVERT_ROTATION", InvertRotation, "Invert Rotation", "")
DefNode(FunctionNode, FN_NODE_MATRIX_MULTIPLY, 0, "MATRIX_MULTIPLY", MatrixMultiply, "Multiply Matrices", "")
DefNode(FunctionNode, FN_NODE_PROJECT_POINT, 0, "PROJECT_POINT", ProjectPoint, "Project Point", "Project a point using a matrix, using location, rotation, scale, and perspective divide")
HooglyBoogly marked this conversation as resolved Outdated

Think this needs a description.

Think this needs a description.

I ended up adapting the code comment for project_point. Maybe eventually we'll think of something better...

I ended up adapting the code comment for `project_point`. Maybe eventually we'll think of something better...
DefNode(FunctionNode, FN_NODE_RANDOM_VALUE, def_fn_random_value, "RANDOM_VALUE", RandomValue, "Random Value", "")
DefNode(FunctionNode, FN_NODE_REPLACE_STRING, 0, "REPLACE_STRING", ReplaceString, "Replace String", "")
DefNode(FunctionNode, FN_NODE_ROTATE_EULER, def_fn_rotate_euler, "ROTATE_EULER", RotateEuler, "Rotate Euler", "")

View File

@ -35,6 +35,7 @@ set(SRC
nodes/node_fn_invert_matrix.cc
nodes/node_fn_invert_rotation.cc
nodes/node_fn_matrix_multiply.cc
nodes/node_fn_project_point.cc
nodes/node_fn_quaternion_to_rotation.cc
nodes/node_fn_random_value.cc
nodes/node_fn_replace_string.cc

View File

@ -0,0 +1,37 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_math_matrix.hh"
#include "node_function_util.hh"
namespace blender::nodes::node_fn_project_point_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.is_function_node();
b.add_input<decl::Vector>("Vector").subtype(PROP_XYZ);
b.add_input<decl::Matrix>("Transform");
b.add_output<decl::Vector>("Vector").subtype(PROP_XYZ);
}
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
{
static auto fn = mf::build::SI2_SO<float3, float4x4, float3>(
"Project Point",
[](float3 point, float4x4 matrix) { return math::project_point(matrix, point); });
HooglyBoogly marked this conversation as resolved
Review

This still needs to be removed.

This still needs to be removed.
builder.set_matching_fn(fn);
}
static void node_register()
{
static bNodeType ntype;
fn_node_type_base(&ntype, FN_NODE_PROJECT_POINT, "Project Point", NODE_CLASS_CONVERTER);
ntype.declare = node_declare;
ntype.build_multi_function = node_build_multi_function;
nodeRegisterType(&ntype);
}
NOD_REGISTER_NODE(node_register)
} // namespace blender::nodes::node_fn_project_point_cc