1
1

Compare commits

...

18 Commits

Author SHA1 Message Date
dddcf1e9bb Merge branch 'master' into temp-compact-node-prototype 2021-06-14 12:44:13 +02:00
3b162b7c18 remove unused file 2021-03-25 16:09:27 +01:00
0300d2a0cc fix after merge 2021-03-25 16:04:49 +01:00
11c7b041e8 Merge branch 'master' into temp-compact-node-prototype 2021-03-25 16:02:13 +01:00
6baf71adfa more nodes 2021-03-25 14:10:28 +01:00
3acfbdc2b1 use prototype in math node 2021-03-25 13:47:38 +01:00
9a0a31fd75 cleanup 2021-03-25 13:41:21 +01:00
846d36c9bf cleanup 2021-03-25 13:38:11 +01:00
e8748fa9c6 fix 2021-03-25 13:38:02 +01:00
863570d099 simplify supporting heterogenous hashing 2021-03-25 13:23:30 +01:00
2bc0a886f1 cleanup 2021-03-25 13:15:48 +01:00
dae5c03553 cleanup 2021-03-25 13:09:00 +01:00
b6541ca4d8 cleanup 2021-03-25 13:01:59 +01:00
cb634d5204 move to sidebar 2021-03-25 12:27:01 +01:00
3049d479dc Merge branch 'master' into temp-compact-node-prototype 2021-03-25 12:06:20 +01:00
74ff3537bc better enum 2021-03-25 10:21:36 +01:00
9501ca7fcc more 2021-03-25 10:13:22 +01:00
3dfc3df1a4 initial expose code 2021-03-25 10:03:59 +01:00
10 changed files with 430 additions and 66 deletions

View File

@@ -305,6 +305,26 @@ class NODE_OT_tree_path_parent(Operator):
return {'FINISHED'}
class NODE_OT_expose_input_socket(Operator):
'''Expose socket'''
bl_idname = "node.expose_input_socket"
bl_label = "Expose Input Socket"
tree_name: StringProperty()
node_name: StringProperty()
# Might reference multiple sockets intentionally.
socket_name: StringProperty()
expose: BoolProperty(default=True)
def execute(self, context):
tree = bpy.data.node_groups[self.tree_name]
node = tree.nodes[self.node_name]
for socket in node.inputs:
if socket.name == self.socket_name:
socket.hide = not self.expose
return {'FINISHED'}
class NODE_OT_active_preview_toggle(Operator):
'''Toggle active preview state of node'''
@@ -364,6 +384,7 @@ class NODE_OT_active_preview_toggle(Operator):
return spreadsheets
classes = (
NodeSetting,
@@ -372,5 +393,6 @@ classes = (
NODE_OT_add_search,
NODE_OT_collapse_hide_unused_toggle,
NODE_OT_tree_path_parent,
NODE_OT_expose_input_socket,
NODE_OT_active_preview_toggle,
)

View File

@@ -549,21 +549,6 @@ class NODE_PT_active_node_properties(Panel):
elif hasattr(node, "draw_buttons"):
node.draw_buttons(context, layout)
# XXX this could be filtered further to exclude socket types
# which don't have meaningful input values (e.g. cycles shader)
value_inputs = [socket for socket in node.inputs if self.show_socket_input(socket)]
if value_inputs:
layout.separator()
layout.label(text="Inputs:")
for socket in value_inputs:
row = layout.row()
socket.draw(
context,
row,
node,
iface_(socket.label if socket.label else socket.name, socket.bl_rna.translation_context),
)
def show_socket_input(self, socket):
return hasattr(socket, 'draw') and socket.enabled and not socket.is_linked

View File

@@ -0,0 +1,196 @@
/*
* 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.
*/
#pragma once
/** \file
* \ingroup bli
*/
#include "BLI_hash.hh"
namespace blender {
template<typename T> class HeapValue {
private:
T *value_ = nullptr;
public:
HeapValue(T value)
{
value_ = new T(std::move(value));
}
HeapValue(const HeapValue &other)
{
if (other.value_ != nullptr) {
value_ = new T(*other.value_);
}
}
HeapValue(HeapValue &&other)
{
value_ = other.value_;
other.value_ = nullptr;
}
~HeapValue()
{
delete value_;
}
HeapValue &operator=(const HeapValue &other)
{
if (this == &other) {
return *this;
}
if (value_ != nullptr) {
if (other.value_ != nullptr) {
*value_ = *other.value_;
}
else {
delete value_;
value_ = nullptr;
}
}
else {
if (other.value_ != nullptr) {
value_ = new T(*other.value_);
}
else {
/* Do nothing. */
}
}
return *this;
}
HeapValue &operator=(HeapValue &&other)
{
if (this == &other) {
return *this;
}
delete value_;
value_ = other.value_;
other.value_ = nullptr;
return *this;
}
HeapValue &operator=(T value)
{
if (value_ == nullptr) {
value_ = new T(std::move(value));
}
else {
*value_ = std::move(value);
}
}
operator bool() const
{
return value_ != nullptr;
}
T &operator*()
{
BLI_assert(value_ != nullptr);
return *value_;
}
const T &operator*() const
{
BLI_assert(value_ != nullptr);
return *value_;
}
T *operator->()
{
BLI_assert(value_ != nullptr);
return value_;
}
const T *operator->() const
{
BLI_assert(value_ != nullptr);
return value_;
}
T *get()
{
return value_;
}
const T *get() const
{
return value_;
}
uint64_t hash() const
{
if (value_ != nullptr) {
return DefaultHash<T>{}(*value_);
}
return 0;
}
static uint64_t hash_as(const T &value)
{
return DefaultHash<T>{}(value);
}
friend bool operator==(const HeapValue &a, const HeapValue &b)
{
if (a.value_ == nullptr && b.value_ == nullptr) {
return true;
}
if (a.value_ == nullptr) {
return false;
}
if (b.value_ == nullptr) {
return false;
}
return *a.value_ == *b.value_;
}
friend bool operator==(const HeapValue &a, const T &b)
{
if (a.value_ == nullptr) {
return false;
}
return *a.value_ == b;
}
friend bool operator==(const T &a, const HeapValue &b)
{
return b == a;
}
friend bool operator!=(const HeapValue &a, const HeapValue &b)
{
return !(a == b);
}
friend bool operator!=(const HeapValue &a, const T &b)
{
return !(a == b);
}
friend bool operator!=(const T &a, const HeapValue &b)
{
return !(a == b);
}
};
} // namespace blender

View File

@@ -208,6 +208,7 @@ set(SRC
BLI_hash_tables.hh
BLI_heap.h
BLI_heap_simple.h
BLI_heap_value.hh
BLI_index_mask.hh
BLI_index_range.hh
BLI_inplace_priority_queue.hh

View File

@@ -38,6 +38,7 @@ set(INC
../makesdna
../makesrna
../render
../windowmanager
../../../intern/glew-mx
../../../intern/guardedalloc
../../../intern/sky/include

View File

@@ -298,4 +298,10 @@ class GeoNodeExecParams {
const bNodeSocket *find_available_socket(const StringRef name) const;
};
void draw_input_socket(bContext *C,
uiLayout *layout,
PointerRNA *node_ptr,
StringRef socket_name,
StringRef additional_enum_prop = "");
} // namespace blender::nodes

View File

@@ -14,6 +14,19 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "node_geometry_util.hh"
#include "BLI_heap_value.hh"
#include "BLI_rand.hh"
#include "DNA_mesh_types.h"
#include "DNA_pointcloud_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "WM_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -35,18 +48,16 @@ static bNodeSocketTemplate geo_node_attribute_fill_out[] = {
{-1, ""},
};
static void geo_node_attribute_fill_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
}
static void geo_node_attribute_fill_init(bNodeTree *UNUSED(tree), bNode *node)
{
node->custom1 = CD_PROP_FLOAT;
node->custom2 = ATTR_DOMAIN_AUTO;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->type != SOCK_GEOMETRY) {
socket->flag |= SOCK_HIDDEN;
}
}
}
static void geo_node_attribute_fill_update(bNodeTree *UNUSED(ntree), bNode *node)
@@ -68,6 +79,120 @@ static void geo_node_attribute_fill_update(bNodeTree *UNUSED(ntree), bNode *node
namespace blender::nodes {
struct SocketMenuInfo {
bNodeTree *ntree;
bNode *node;
bNodeSocket *socket;
std::string enum_name;
uint64_t hash() const
{
return get_default_hash_3(ntree, node, socket);
}
friend bool operator==(const SocketMenuInfo &a, const SocketMenuInfo &b)
{
return a.ntree == b.ntree && a.node == b.node && a.socket == b.socket;
}
};
static Set<HeapValue<SocketMenuInfo>> &get_socket_menu_info_set()
{
static Set<HeapValue<SocketMenuInfo>> set;
return set;
}
static void draw_socket_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
{
SocketMenuInfo *socket_info = (SocketMenuInfo *)arg;
PointerRNA node_ptr;
RNA_pointer_create(&socket_info->ntree->id, &RNA_Node, socket_info->node, &node_ptr);
PointerRNA socket_ptr;
RNA_pointer_create(&socket_info->ntree->id, &RNA_NodeSocket, socket_info->socket, &socket_ptr);
if (socket_info->socket->flag & SOCK_HIDDEN) {
PointerRNA expose_props;
uiItemFullO(layout,
"node.expose_input_socket",
"Expose",
ICON_TRACKING_BACKWARDS_SINGLE,
nullptr,
WM_OP_EXEC_DEFAULT,
0,
&expose_props);
RNA_string_set(&expose_props, "tree_name", socket_info->ntree->id.name + 2);
RNA_string_set(&expose_props, "node_name", socket_info->node->name);
RNA_string_set(&expose_props, "socket_name", socket_info->socket->name);
RNA_boolean_set(&expose_props, "expose", true);
}
else {
uiLayout *col = uiLayoutColumn(layout, false);
uiLayoutSetEnabled(col, (socket_info->socket->flag & SOCK_IN_USE) == 0);
PointerRNA expose_props;
uiItemFullO(col,
"node.expose_input_socket",
"Unexpose",
ICON_TRACKING_CLEAR_BACKWARDS,
nullptr,
WM_OP_EXEC_DEFAULT,
0,
&expose_props);
RNA_string_set(&expose_props, "tree_name", socket_info->ntree->id.name + 2);
RNA_string_set(&expose_props, "node_name", socket_info->node->name);
RNA_string_set(&expose_props, "socket_name", socket_info->socket->name);
RNA_boolean_set(&expose_props, "expose", false);
}
if (!socket_info->enum_name.empty()) {
uiItemsEnumR(layout, &node_ptr, socket_info->enum_name.c_str());
}
}
void draw_input_socket(bContext *C,
uiLayout *layout,
PointerRNA *node_ptr,
StringRef socket_name,
StringRef additional_enum_prop)
{
bNodeTree *ntree = (bNodeTree *)node_ptr->owner_id;
bNode *node = (bNode *)node_ptr->data;
bNodeSocket *socket_to_draw = nullptr;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if ((socket->flag & SOCK_UNAVAIL) == 0 && socket->name == socket_name) {
socket_to_draw = socket;
break;
}
}
if (socket_to_draw == nullptr) {
return;
}
PointerRNA socket_ptr;
RNA_pointer_create(&ntree->id, &RNA_NodeSocket, socket_to_draw, &socket_ptr);
SocketMenuInfo info;
info.ntree = ntree;
info.node = node;
info.socket = socket_to_draw;
info.enum_name = additional_enum_prop;
Set<HeapValue<SocketMenuInfo>> &set = get_socket_menu_info_set();
const SocketMenuInfo *stored_info = set.lookup_key_or_add_as(info).get();
uiLayout *row = uiLayoutRow(layout, false);
uiLayout *sub_row = uiLayoutRow(row, false);
uiLayoutSetActive(sub_row, (socket_to_draw->flag & SOCK_HIDDEN) != 0);
socket_to_draw->typeinfo->draw(C, sub_row, &socket_ptr, node_ptr, socket_to_draw->name);
uiItemMenuF(row, "", ICON_DOWNARROW_HLT, draw_socket_menu, (void *)stored_info);
}
static void geo_node_attribute_fill_layout(uiLayout *layout, bContext *C, PointerRNA *node_ptr)
{
uiItemR(layout, node_ptr, "domain", 0, IFACE_("Domain"), ICON_NONE);
draw_input_socket(C, layout, node_ptr, "Attribute");
draw_input_socket(C, layout, node_ptr, "Value", "data_type");
}
static AttributeDomain get_result_domain(const GeometryComponent &component, const StringRef name)
{
/* Use the domain of the result attribute if it already exists. */
@@ -161,6 +286,6 @@ void register_node_type_geo_attribute_fill()
node_type_init(&ntype, geo_node_attribute_fill_init);
node_type_update(&ntype, geo_node_attribute_fill_update);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_fill_exec;
ntype.draw_buttons = geo_node_attribute_fill_layout;
ntype.draw_buttons_ex = blender::nodes::geo_node_attribute_fill_layout;
nodeRegisterType(&ntype);
}

View File

@@ -100,25 +100,6 @@ static bool operation_use_input_b(const NodeMathOperation operation)
return false;
}
static void geo_node_attribute_math_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
NodeAttributeMath *node_storage = (NodeAttributeMath *)node->storage;
NodeMathOperation operation = (NodeMathOperation)node_storage->operation;
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "input_type_a", 0, IFACE_("A"), ICON_NONE);
if (operation_use_input_b(operation)) {
uiItemR(layout, ptr, "input_type_b", 0, IFACE_("B"), ICON_NONE);
}
if (operation_use_input_c(operation)) {
uiItemR(layout, ptr, "input_type_c", 0, IFACE_("C"), ICON_NONE);
}
}
static void geo_node_attribute_math_init(bNodeTree *UNUSED(tree), bNode *node)
{
NodeAttributeMath *data = (NodeAttributeMath *)MEM_callocN(sizeof(NodeAttributeMath), __func__);
@@ -128,10 +109,33 @@ static void geo_node_attribute_math_init(bNodeTree *UNUSED(tree), bNode *node)
data->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
data->input_type_c = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
node->storage = data;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->type != SOCK_GEOMETRY) {
socket->flag |= SOCK_HIDDEN;
}
}
}
namespace blender::nodes {
static void geo_node_attribute_math_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
NodeAttributeMath *node_storage = (NodeAttributeMath *)node->storage;
NodeMathOperation operation = (NodeMathOperation)node_storage->operation;
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
draw_input_socket(C, layout, ptr, "A", "input_type_a");
if (operation_use_input_b(operation)) {
draw_input_socket(C, layout, ptr, "B", "input_type_b");
}
if (operation_use_input_c(operation)) {
draw_input_socket(C, layout, ptr, "C", "input_type_c");
}
}
static void geo_node_attribute_math_update(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeAttributeMath &node_storage = *(NodeAttributeMath *)node->storage;
@@ -295,7 +299,7 @@ void register_node_type_geo_attribute_math()
geo_node_type_base(&ntype, GEO_NODE_ATTRIBUTE_MATH, "Attribute Math", NODE_CLASS_ATTRIBUTE, 0);
node_type_socket_templates(&ntype, geo_node_attribute_math_in, geo_node_attribute_math_out);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_math_exec;
ntype.draw_buttons = geo_node_attribute_math_layout;
ntype.draw_buttons_ex = blender::nodes::geo_node_attribute_math_layout;
node_type_update(&ntype, blender::nodes::geo_node_attribute_math_update);
node_type_init(&ntype, geo_node_attribute_math_init);
node_type_storage(

View File

@@ -66,27 +66,6 @@ static bool operation_use_input_c(const NodeVectorMathOperation operation)
NODE_VECTOR_MATH_MULTIPLY_ADD);
}
static void geo_node_attribute_vector_math_layout(uiLayout *layout,
bContext *UNUSED(C),
PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
const NodeAttributeVectorMath &node_storage = *(NodeAttributeVectorMath *)node->storage;
const NodeVectorMathOperation operation = (const NodeVectorMathOperation)node_storage.operation;
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "input_type_a", 0, IFACE_("A"), ICON_NONE);
if (operation_use_input_b(operation)) {
uiItemR(layout, ptr, "input_type_b", 0, IFACE_("B"), ICON_NONE);
}
if (operation_use_input_c(operation)) {
uiItemR(layout, ptr, "input_type_c", 0, IFACE_("C"), ICON_NONE);
}
}
static CustomDataType operation_get_read_type_b(const NodeVectorMathOperation operation)
{
if (operation == NODE_VECTOR_MATH_SCALE) {
@@ -112,6 +91,12 @@ static void geo_node_attribute_vector_math_init(bNodeTree *UNUSED(tree), bNode *
data->input_type_a = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
data->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE;
node->storage = data;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->type != SOCK_GEOMETRY) {
socket->flag |= SOCK_HIDDEN;
}
}
}
static CustomDataType operation_get_result_type(const NodeVectorMathOperation operation)
@@ -154,6 +139,27 @@ static CustomDataType operation_get_result_type(const NodeVectorMathOperation op
namespace blender::nodes {
static void geo_node_attribute_vector_math_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
const NodeAttributeVectorMath &node_storage = *(NodeAttributeVectorMath *)node->storage;
const NodeVectorMathOperation operation = (const NodeVectorMathOperation)node_storage.operation;
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
draw_input_socket(C, layout, ptr, "A", "input_type_a");
if (operation_use_input_b(operation)) {
draw_input_socket(C, layout, ptr, "B", "input_type_b");
}
if (operation_use_input_c(operation)) {
draw_input_socket(C, layout, ptr, "C", "input_type_c");
}
uiItemS(layout);
draw_input_socket(C, layout, ptr, "Result");
}
static void geo_node_attribute_vector_math_update(bNodeTree *UNUSED(ntree), bNode *node)
{
const NodeAttributeVectorMath *node_storage = (NodeAttributeVectorMath *)node->storage;
@@ -548,7 +554,7 @@ void register_node_type_geo_attribute_vector_math()
node_type_socket_templates(
&ntype, geo_node_attribute_vector_math_in, geo_node_attribute_vector_math_out);
ntype.geometry_node_execute = blender::nodes::geo_node_attribute_vector_math_exec;
ntype.draw_buttons = geo_node_attribute_vector_math_layout;
ntype.draw_buttons_ex = blender::nodes::geo_node_attribute_vector_math_layout;
node_type_update(&ntype, blender::nodes::geo_node_attribute_vector_math_update);
node_type_init(&ntype, geo_node_attribute_vector_math_init);
node_type_storage(

View File

@@ -47,6 +47,22 @@ static bNodeSocketTemplate geo_node_transform_out[] = {
namespace blender::nodes {
static void geo_node_transform_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
draw_input_socket(C, layout, ptr, "Translation");
draw_input_socket(C, layout, ptr, "Rotation");
draw_input_socket(C, layout, ptr, "Scale");
}
static void geo_node_transform_init(bNodeTree *UNUSED(tree), bNode *node)
{
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->type != SOCK_GEOMETRY) {
socket->flag |= SOCK_HIDDEN;
}
}
}
static bool use_translate(const float3 rotation, const float3 scale)
{
if (compare_ff(rotation.length_squared(), 0.0f, 1e-9f) != 1) {
@@ -207,6 +223,8 @@ void register_node_type_geo_transform()
geo_node_type_base(&ntype, GEO_NODE_TRANSFORM, "Transform", NODE_CLASS_GEOMETRY, 0);
node_type_socket_templates(&ntype, geo_node_transform_in, geo_node_transform_out);
node_type_init(&ntype, blender::nodes::geo_node_transform_init);
ntype.geometry_node_execute = blender::nodes::geo_node_transform_exec;
ntype.draw_buttons_ex = blender::nodes::geo_node_transform_layout;
nodeRegisterType(&ntype);
}