Function Nodes: Input Vector

Ref: T82651

Normally people use "Combine XYZ" to input a vector, but it is more
interesting to have an explicit vector input.

So this is basically "Combine XYZ" without any input sockets, the values
are stored in the node itself.

Differential Revision: https://developer.blender.org/D9885
This commit is contained in:
Dalai Felinto 2020-12-17 18:37:04 +01:00
parent b342e089c3
commit f43561eae6
10 changed files with 87 additions and 0 deletions

View File

@ -502,6 +502,7 @@ geometry_node_categories = [
NodeItem("GeometryNodeObjectInfo"),
NodeItem("FunctionNodeRandomFloat"),
NodeItem("ShaderNodeValue"),
NodeItem("FunctionNodeInputVector"),
]),
GeometryNodeCategory("GEO_MESH", "Mesh", items=[
NodeItem("GeometryNodeTriangulate"),

View File

@ -1369,6 +1369,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define FN_NODE_COMBINE_STRINGS 1204
#define FN_NODE_OBJECT_TRANSFORMS 1205
#define FN_NODE_RANDOM_FLOAT 1206
#define FN_NODE_INPUT_VECTOR 1207
/** \} */

View File

@ -4755,6 +4755,7 @@ static void registerFunctionNodes(void)
register_node_type_fn_combine_strings();
register_node_type_fn_object_transforms();
register_node_type_fn_random_float();
register_node_type_fn_input_vector();
}
void BKE_node_system_init(void)

View File

@ -3289,6 +3289,12 @@ static void node_function_buts_switch(uiLayout *layout, bContext *UNUSED(C), Poi
uiItemR(layout, ptr, "data_type", DEFAULT_FLAGS, "", ICON_NONE);
}
static void node_function_buts_input_vector(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *col = uiLayoutColumn(layout, true);
uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
}
static void node_function_set_butfunc(bNodeType *ntype)
{
switch (ntype->type) {
@ -3301,6 +3307,9 @@ static void node_function_set_butfunc(bNodeType *ntype)
case FN_NODE_SWITCH:
ntype->draw_buttons = node_function_buts_switch;
break;
case FN_NODE_INPUT_VECTOR:
ntype->draw_buttons = node_function_buts_input_vector;
break;
}
}

View File

@ -1110,6 +1110,10 @@ typedef struct NodeAttributeColorRamp {
ColorBand color_ramp;
} NodeAttributeColorRamp;
typedef struct NodeInputVector {
float vector[3];
} NodeInputVector;
/* script node mode */
#define NODE_SCRIPT_INTERNAL 0
#define NODE_SCRIPT_EXTERNAL 1

View File

@ -4480,6 +4480,19 @@ static void def_texture(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_fn_input_vector(StructRNA *srna)
{
PropertyRNA *prop;
RNA_def_struct_sdna_from(srna, "NodeInputVector", "storage");
prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_XYZ);
RNA_def_property_array(prop, 3);
RNA_def_property_float_sdna(prop, NULL, "vector");
RNA_def_property_ui_text(prop, "Vector", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
/* -- Shader Nodes ---------------------------------------------------------- */
static void def_sh_output(StructRNA *srna)

View File

@ -133,6 +133,7 @@ set(SRC
function/nodes/node_fn_combine_strings.cc
function/nodes/node_fn_float_compare.cc
function/nodes/node_fn_group_instance_id.cc
function/nodes/node_fn_input_vector.cc
function/nodes/node_fn_object_transforms.cc
function/nodes/node_fn_random_float.cc
function/nodes/node_fn_switch.cc

View File

@ -27,6 +27,7 @@ void register_node_type_fn_group_instance_id(void);
void register_node_type_fn_combine_strings(void);
void register_node_type_fn_object_transforms(void);
void register_node_type_fn_random_float(void);
void register_node_type_fn_input_vector(void);
#ifdef __cplusplus
}

View File

@ -265,6 +265,7 @@ DefNode(FunctionNode, FN_NODE_GROUP_INSTANCE_ID, 0, "GROUP_INSTANCE_
DefNode(FunctionNode, FN_NODE_COMBINE_STRINGS, 0, "COMBINE_STRINGS", CombineStrings, "Combine Strings", "")
DefNode(FunctionNode, FN_NODE_OBJECT_TRANSFORMS, 0, "OBJECT_TRANSFORMS", ObjectTransforms, "Object Transforms", "")
DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0, "RANDOM_FLOAT", RandomFloat, "Random Float", "")
DefNode(FunctionNode, FN_NODE_INPUT_VECTOR, def_fn_input_vector, "INPUT_VECTOR", InputVector, "Vector", "")
DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "")
DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")

View File

@ -0,0 +1,55 @@
/*
* 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_function_util.hh"
#include "BLI_hash.h"
static bNodeSocketTemplate fn_node_input_vector_out[] = {
{SOCK_VECTOR, N_("Vector")},
{-1, ""},
};
static void fn_node_vector_input_expand_in_mf_network(
blender::nodes::NodeMFNetworkBuilder &builder)
{
bNode &bnode = builder.bnode();
NodeInputVector *node_storage = static_cast<NodeInputVector *>(bnode.storage);
blender::float3 vector(node_storage->vector);
builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<blender::float3>>(vector);
}
static void fn_node_input_vector_init(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeInputVector *data = (NodeInputVector *)MEM_callocN(sizeof(NodeInputVector),
"input vector node");
node->storage = data;
}
void register_node_type_fn_input_vector()
{
static bNodeType ntype;
fn_node_type_base(&ntype, FN_NODE_INPUT_VECTOR, "Vector", 0, 0);
node_type_socket_templates(&ntype, nullptr, fn_node_input_vector_out);
node_type_init(&ntype, fn_node_input_vector_init);
node_type_storage(
&ntype, "NodeInputVector", node_free_standard_storage, node_copy_standard_storage);
ntype.expand_in_mf_network = fn_node_vector_input_expand_in_mf_network;
nodeRegisterType(&ntype);
}