Compare commits

...

24 Commits

Author SHA1 Message Date
dddcf1e9bb Merge branch 'master' into temp-compact-node-prototype 2021-06-14 12:44:13 +02:00
c9dc55301c Fix T88494: add missing depsgraph relation update tags
Adding e.g. a Collection Info node creates a new depsgraph relation.
Therefore the relations should be updated.
2021-06-14 11:35:36 +02:00
a19c9e9351 Fix T88947: invalid normals when converting point cloud to mesh 2021-06-14 11:07:42 +02:00
Campbell Barton
2db09f67a4 Nodes: remove redundant increment node tree current socket index
`ntree->cur_index` was being incremented twice in make_socket_interface.

Reviewed By: JacquesLucke

Ref D11590
2021-06-14 18:46:39 +10:00
03544ed54f Fix T88807: crash when there are multiple links between the same sockets
This commit does two things:

* Disallows creating more than one link from one socket to a multi socket input.
* Properly count links if there happen to be more than one link between the same sockets.

The new link counting should also be more efficient asymptotically.

Differential Revision: https://developer.blender.org/D11570
2021-06-14 10:04:52 +02:00
54a03d4247 Cleanup: Reduce indentation from redundant check 2021-06-13 18:56:52 -05:00
84adc23941 Cleanup: Order return argument last 2021-06-13 18:22:31 -05: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
18 changed files with 668 additions and 287 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

@@ -93,8 +93,8 @@ void BKE_displist_make_curveTypes_forRender(struct Depsgraph *depsgraph,
const struct Scene *scene,
struct Object *ob,
struct ListBase *dispbase,
struct Mesh **r_final,
const bool for_orco);
const bool for_orco,
struct Mesh **r_final);
void BKE_displist_make_mball(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
void BKE_displist_make_mball_forRender(struct Depsgraph *depsgraph,
struct Scene *scene,

View File

@@ -1420,237 +1420,237 @@ static void do_makeDispListCurveTypes(Depsgraph *depsgraph,
if (ob->type == OB_SURF) {
displist_make_surf(depsgraph, scene, ob, dispbase, r_final, for_render, for_orco);
return;
}
else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
ListBase nubase = {nullptr, nullptr};
bool force_mesh_conversion = false;
BKE_curve_bevelList_free(&ob->runtime.curve_cache->bev);
ListBase nubase = {nullptr, nullptr};
bool force_mesh_conversion = false;
/* We only re-evaluate path if evaluation is not happening for orco.
* If the calculation happens for orco, we should never free data which
* was needed before and only not needed for orco calculation. */
if (!for_orco) {
if (ob->runtime.curve_cache->anim_path_accum_length) {
MEM_freeN((void *)ob->runtime.curve_cache->anim_path_accum_length);
BKE_curve_bevelList_free(&ob->runtime.curve_cache->bev);
/* We only re-evaluate path if evaluation is not happening for orco.
* If the calculation happens for orco, we should never free data which
* was needed before and only not needed for orco calculation. */
if (!for_orco) {
if (ob->runtime.curve_cache->anim_path_accum_length) {
MEM_freeN((void *)ob->runtime.curve_cache->anim_path_accum_length);
}
ob->runtime.curve_cache->anim_path_accum_length = nullptr;
}
if (ob->type == OB_FONT) {
BKE_vfont_to_curve_nubase(ob, FO_EDIT, &nubase);
}
else {
BKE_nurbList_duplicate(&nubase, BKE_curve_nurbs_get(const_cast<Curve *>(cu)));
}
if (!for_orco) {
force_mesh_conversion = BKE_curve_calc_modifiers_pre(
depsgraph, scene, ob, &nubase, &nubase, for_render);
}
BKE_curve_bevelList_make(ob, &nubase, for_render);
/* If curve has no bevel will return nothing */
ListBase dlbev = BKE_curve_bevel_make(cu);
/* no bevel or extrude, and no width correction? */
if (BLI_listbase_is_empty(&dlbev) && cu->width == 1.0f) {
curve_to_displist(cu, &nubase, for_render, dispbase);
}
else {
const float widfac = cu->width - 1.0f;
BevList *bl = (BevList *)ob->runtime.curve_cache->bev.first;
Nurb *nu = (Nurb *)nubase.first;
for (; bl && nu; bl = bl->next, nu = nu->next) {
float *data;
if (bl->nr == 0) { /* blank bevel lists can happen */
continue;
}
ob->runtime.curve_cache->anim_path_accum_length = nullptr;
}
if (ob->type == OB_FONT) {
BKE_vfont_to_curve_nubase(ob, FO_EDIT, &nubase);
}
else {
BKE_nurbList_duplicate(&nubase, BKE_curve_nurbs_get(const_cast<Curve *>(cu)));
}
/* exception handling; curve without bevel or extrude, with width correction */
if (BLI_listbase_is_empty(&dlbev)) {
DispList *dl = (DispList *)MEM_callocN(sizeof(DispList), "makeDispListbev");
dl->verts = (float *)MEM_mallocN(sizeof(float[3]) * bl->nr, "dlverts");
BLI_addtail(dispbase, dl);
if (!for_orco) {
force_mesh_conversion = BKE_curve_calc_modifiers_pre(
depsgraph, scene, ob, &nubase, &nubase, for_render);
}
BKE_curve_bevelList_make(ob, &nubase, for_render);
/* If curve has no bevel will return nothing */
ListBase dlbev = BKE_curve_bevel_make(cu);
/* no bevel or extrude, and no width correction? */
if (BLI_listbase_is_empty(&dlbev) && cu->width == 1.0f) {
curve_to_displist(cu, &nubase, for_render, dispbase);
}
else {
const float widfac = cu->width - 1.0f;
BevList *bl = (BevList *)ob->runtime.curve_cache->bev.first;
Nurb *nu = (Nurb *)nubase.first;
for (; bl && nu; bl = bl->next, nu = nu->next) {
float *data;
if (bl->nr == 0) { /* blank bevel lists can happen */
continue;
if (bl->poly != -1) {
dl->type = DL_POLY;
}
else {
dl->type = DL_SEGM;
dl->flag = (DL_FRONT_CURVE | DL_BACK_CURVE);
}
/* exception handling; curve without bevel or extrude, with width correction */
if (BLI_listbase_is_empty(&dlbev)) {
DispList *dl = (DispList *)MEM_callocN(sizeof(DispList), "makeDispListbev");
dl->verts = (float *)MEM_mallocN(sizeof(float[3]) * bl->nr, "dlverts");
dl->parts = 1;
dl->nr = bl->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
dl->rt = nu->flag;
int a = dl->nr;
BevPoint *bevp = bl->bevpoints;
data = dl->verts;
while (a--) {
data[0] = bevp->vec[0] + widfac * bevp->sina;
data[1] = bevp->vec[1] + widfac * bevp->cosa;
data[2] = bevp->vec[2];
bevp++;
data += 3;
}
}
else {
ListBase bottom_capbase = {nullptr, nullptr};
ListBase top_capbase = {nullptr, nullptr};
float bottom_no[3] = {0.0f};
float top_no[3] = {0.0f};
float first_blend = 0.0f, last_blend = 0.0f;
int start, steps = 0;
if (nu->flagu & CU_NURB_CYCLIC) {
calc_bevfac_mapping_default(bl, &start, &first_blend, &steps, &last_blend);
}
else {
if (fabsf(cu->bevfac2 - cu->bevfac1) < FLT_EPSILON) {
continue;
}
calc_bevfac_mapping(cu, bl, nu, &start, &first_blend, &steps, &last_blend);
}
LISTBASE_FOREACH (DispList *, dlb, &dlbev) {
/* for each part of the bevel use a separate displblock */
DispList *dl = (DispList *)MEM_callocN(sizeof(DispList), "makeDispListbev1");
dl->verts = data = (float *)MEM_mallocN(sizeof(float[3]) * dlb->nr * steps, "dlverts");
BLI_addtail(dispbase, dl);
if (bl->poly != -1) {
dl->type = DL_POLY;
dl->type = DL_SURF;
dl->flag = dlb->flag & (DL_FRONT_CURVE | DL_BACK_CURVE);
if (dlb->type == DL_POLY) {
dl->flag |= DL_CYCL_U;
}
else {
dl->type = DL_SEGM;
dl->flag = (DL_FRONT_CURVE | DL_BACK_CURVE);
if ((bl->poly >= 0) && (steps > 2)) {
dl->flag |= DL_CYCL_V;
}
dl->parts = 1;
dl->nr = bl->nr;
dl->parts = steps;
dl->nr = dlb->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
dl->rt = nu->flag;
int a = dl->nr;
BevPoint *bevp = bl->bevpoints;
data = dl->verts;
while (a--) {
data[0] = bevp->vec[0] + widfac * bevp->sina;
data[1] = bevp->vec[1] + widfac * bevp->cosa;
data[2] = bevp->vec[2];
bevp++;
data += 3;
}
}
else {
ListBase bottom_capbase = {nullptr, nullptr};
ListBase top_capbase = {nullptr, nullptr};
float bottom_no[3] = {0.0f};
float top_no[3] = {0.0f};
float first_blend = 0.0f, last_blend = 0.0f;
int start, steps = 0;
/* for each point of poly make a bevel piece */
BevPoint *bevp_first = bl->bevpoints;
BevPoint *bevp_last = &bl->bevpoints[bl->nr - 1];
BevPoint *bevp = &bl->bevpoints[start];
for (int i = start, a = 0; a < steps; i++, bevp++, a++) {
float radius_factor = 1.0;
float *cur_data = data;
if (nu->flagu & CU_NURB_CYCLIC) {
calc_bevfac_mapping_default(bl, &start, &first_blend, &steps, &last_blend);
}
else {
if (fabsf(cu->bevfac2 - cu->bevfac1) < FLT_EPSILON) {
continue;
if (cu->taperobj == nullptr) {
radius_factor = bevp->radius;
}
else {
float taper_factor;
if (cu->flag & CU_MAP_TAPER) {
float len = (steps - 3) + first_blend + last_blend;
calc_bevfac_mapping(cu, bl, nu, &start, &first_blend, &steps, &last_blend);
}
LISTBASE_FOREACH (DispList *, dlb, &dlbev) {
/* for each part of the bevel use a separate displblock */
DispList *dl = (DispList *)MEM_callocN(sizeof(DispList), "makeDispListbev1");
dl->verts = data = (float *)MEM_mallocN(sizeof(float[3]) * dlb->nr * steps, "dlverts");
BLI_addtail(dispbase, dl);
dl->type = DL_SURF;
dl->flag = dlb->flag & (DL_FRONT_CURVE | DL_BACK_CURVE);
if (dlb->type == DL_POLY) {
dl->flag |= DL_CYCL_U;
}
if ((bl->poly >= 0) && (steps > 2)) {
dl->flag |= DL_CYCL_V;
}
dl->parts = steps;
dl->nr = dlb->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
dl->rt = nu->flag;
/* for each point of poly make a bevel piece */
BevPoint *bevp_first = bl->bevpoints;
BevPoint *bevp_last = &bl->bevpoints[bl->nr - 1];
BevPoint *bevp = &bl->bevpoints[start];
for (int i = start, a = 0; a < steps; i++, bevp++, a++) {
float radius_factor = 1.0;
float *cur_data = data;
if (cu->taperobj == nullptr) {
radius_factor = bevp->radius;
}
else {
float taper_factor;
if (cu->flag & CU_MAP_TAPER) {
float len = (steps - 3) + first_blend + last_blend;
if (a == 0) {
taper_factor = 0.0f;
}
else if (a == steps - 1) {
taper_factor = 1.0f;
}
else {
taper_factor = ((float)a - (1.0f - first_blend)) / len;
}
if (a == 0) {
taper_factor = 0.0f;
}
else if (a == steps - 1) {
taper_factor = 1.0f;
}
else {
float len = bl->nr - 1;
taper_factor = (float)i / len;
if (a == 0) {
taper_factor += (1.0f - first_blend) / len;
}
else if (a == steps - 1) {
taper_factor -= (1.0f - last_blend) / len;
}
taper_factor = ((float)a - (1.0f - first_blend)) / len;
}
radius_factor = displist_calc_taper(depsgraph, scene, cu->taperobj, taper_factor);
if (cu->taper_radius_mode == CU_TAPER_RADIUS_MULTIPLY) {
radius_factor *= bevp->radius;
}
else if (cu->taper_radius_mode == CU_TAPER_RADIUS_ADD) {
radius_factor += bevp->radius;
}
}
/* rotate bevel piece and write in data */
if ((a == 0) && (bevp != bevp_last)) {
rotateBevelPiece(
cu, bevp, bevp + 1, dlb, 1.0f - first_blend, widfac, radius_factor, &data);
}
else if ((a == steps - 1) && (bevp != bevp_first)) {
rotateBevelPiece(
cu, bevp, bevp - 1, dlb, 1.0f - last_blend, widfac, radius_factor, &data);
}
else {
rotateBevelPiece(cu, bevp, nullptr, dlb, 0.0f, widfac, radius_factor, &data);
float len = bl->nr - 1;
taper_factor = (float)i / len;
if (a == 0) {
taper_factor += (1.0f - first_blend) / len;
}
else if (a == steps - 1) {
taper_factor -= (1.0f - last_blend) / len;
}
}
if ((cu->flag & CU_FILL_CAPS) && !(nu->flagu & CU_NURB_CYCLIC)) {
if (a == 1) {
fillBevelCap(nu, dlb, cur_data - 3 * dlb->nr, &bottom_capbase);
copy_v3_v3(bottom_no, bevp->dir);
}
if (a == steps - 1) {
fillBevelCap(nu, dlb, cur_data, &top_capbase);
negate_v3_v3(top_no, bevp->dir);
}
radius_factor = displist_calc_taper(depsgraph, scene, cu->taperobj, taper_factor);
if (cu->taper_radius_mode == CU_TAPER_RADIUS_MULTIPLY) {
radius_factor *= bevp->radius;
}
else if (cu->taper_radius_mode == CU_TAPER_RADIUS_ADD) {
radius_factor += bevp->radius;
}
}
/* gl array drawing: using indices */
displist_surf_indices(dl);
/* rotate bevel piece and write in data */
if ((a == 0) && (bevp != bevp_last)) {
rotateBevelPiece(
cu, bevp, bevp + 1, dlb, 1.0f - first_blend, widfac, radius_factor, &data);
}
else if ((a == steps - 1) && (bevp != bevp_first)) {
rotateBevelPiece(
cu, bevp, bevp - 1, dlb, 1.0f - last_blend, widfac, radius_factor, &data);
}
else {
rotateBevelPiece(cu, bevp, nullptr, dlb, 0.0f, widfac, radius_factor, &data);
}
if ((cu->flag & CU_FILL_CAPS) && !(nu->flagu & CU_NURB_CYCLIC)) {
if (a == 1) {
fillBevelCap(nu, dlb, cur_data - 3 * dlb->nr, &bottom_capbase);
copy_v3_v3(bottom_no, bevp->dir);
}
if (a == steps - 1) {
fillBevelCap(nu, dlb, cur_data, &top_capbase);
negate_v3_v3(top_no, bevp->dir);
}
}
}
if (bottom_capbase.first) {
BKE_displist_fill(&bottom_capbase, dispbase, bottom_no, false);
BKE_displist_fill(&top_capbase, dispbase, top_no, false);
BKE_displist_free(&bottom_capbase);
BKE_displist_free(&top_capbase);
}
/* gl array drawing: using indices */
displist_surf_indices(dl);
}
if (bottom_capbase.first) {
BKE_displist_fill(&bottom_capbase, dispbase, bottom_no, false);
BKE_displist_fill(&top_capbase, dispbase, top_no, false);
BKE_displist_free(&bottom_capbase);
BKE_displist_free(&top_capbase);
}
}
BKE_displist_free(&dlbev);
}
if (!(cu->flag & CU_DEFORM_FILL)) {
curve_to_filledpoly(cu, dispbase);
}
if (!for_orco) {
if ((cu->flag & CU_PATH) ||
DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH) {
BKE_anim_path_calc_data(ob);
}
BKE_nurbList_duplicate(&ob->runtime.curve_cache->deformed_nurbs, &nubase);
curve_calc_modifiers_post(
depsgraph, scene, ob, dispbase, for_render, force_mesh_conversion, r_final);
}
if (cu->flag & CU_DEFORM_FILL && !ob->runtime.data_eval) {
curve_to_filledpoly(cu, dispbase);
}
BKE_nurbList_free(&nubase);
BKE_displist_free(&dlbev);
}
if (!(cu->flag & CU_DEFORM_FILL)) {
curve_to_filledpoly(cu, dispbase);
}
if (!for_orco) {
if ((cu->flag & CU_PATH) ||
DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH) {
BKE_anim_path_calc_data(ob);
}
BKE_nurbList_duplicate(&ob->runtime.curve_cache->deformed_nurbs, &nubase);
curve_calc_modifiers_post(
depsgraph, scene, ob, dispbase, for_render, force_mesh_conversion, r_final);
}
if (cu->flag & CU_DEFORM_FILL && !ob->runtime.data_eval) {
curve_to_filledpoly(cu, dispbase);
}
BKE_nurbList_free(&nubase);
}
void BKE_displist_make_curveTypes(Depsgraph *depsgraph,
@@ -1689,8 +1689,8 @@ void BKE_displist_make_curveTypes_forRender(Depsgraph *depsgraph,
const Scene *scene,
Object *ob,
ListBase *dispbase,
Mesh **r_final,
const bool for_orco)
const bool for_orco,
Mesh **r_final)
{
if (ob->runtime.curve_cache == nullptr) {
ob->runtime.curve_cache = (CurveCache *)MEM_callocN(sizeof(CurveCache),

View File

@@ -472,6 +472,11 @@ static Mesh *join_mesh_topology_and_builtin_attributes(Span<GeometryInstanceGrou
poly_offset += mesh.totpoly;
}
}
const float3 point_normal{0.0f, 0.0f, 1.0f};
short point_normal_short[3];
normal_float_to_short_v3(point_normal_short, point_normal);
if (convert_points_to_vertices && set.has_pointcloud()) {
const PointCloud &pointcloud = *set.get_pointcloud_for_read();
for (const float4x4 &transform : set_group.transforms) {
@@ -480,6 +485,7 @@ static Mesh *join_mesh_topology_and_builtin_attributes(Span<GeometryInstanceGrou
const float3 old_position = pointcloud.co[i];
const float3 new_position = transform * old_position;
copy_v3_v3(new_vert.co, new_position);
memcpy(&new_vert.no, point_normal_short, sizeof(point_normal_short));
}
vert_offset += pointcloud.totpoint;
}

View File

@@ -1113,7 +1113,7 @@ static void curve_to_mesh_eval_ensure(Object *object)
* Brecht says hold off with that. */
Mesh *mesh_eval = NULL;
BKE_displist_make_curveTypes_forRender(
NULL, NULL, &remapped_object, &remapped_object.runtime.curve_cache->disp, &mesh_eval, false);
NULL, NULL, &remapped_object, &remapped_object.runtime.curve_cache->disp, false, &mesh_eval);
/* Note: this is to be consistent with `BKE_displist_make_curveTypes()`, however that is not a
* real issue currently, code here is broken in more than one way, fix(es) will be done

View File

@@ -3342,8 +3342,6 @@ static bNodeSocket *make_socket_interface(bNodeTree *ntree,
const char *name)
{
bNodeSocketType *stype = nodeSocketTypeFind(idname);
int own_index = ntree->cur_index++;
if (stype == nullptr) {
return nullptr;
}
@@ -3355,7 +3353,7 @@ static bNodeSocket *make_socket_interface(bNodeTree *ntree,
sock->type = SOCK_CUSTOM; /* int type undefined by default */
/* assign new unique index */
own_index = ntree->cur_index++;
const int own_index = ntree->cur_index++;
/* use the own_index as socket identifier */
if (in_out == SOCK_IN) {
BLI_snprintf(sock->identifier, MAX_NAME, "Input_%d", own_index);

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

@@ -591,6 +591,7 @@ static int node_add_texture_exec(bContext *C, wmOperator *op)
snode_notify(C, snode);
snode_dag_update(C, snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, texture_node);
@@ -696,6 +697,7 @@ static int node_add_collection_exec(bContext *C, wmOperator *op)
snode_notify(C, snode);
snode_dag_update(C, snode);
DEG_relations_tag_update(bmain);
ED_node_tag_update_nodetree(bmain, ntree, collection_node);
@@ -807,6 +809,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
snode_notify(C, snode);
snode_dag_update(C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;
}
@@ -902,6 +905,7 @@ static int node_add_mask_exec(bContext *C, wmOperator *op)
snode_notify(C, snode);
snode_dag_update(C, snode);
DEG_relations_tag_update(bmain);
return OPERATOR_FINISHED;
}

View File

@@ -82,6 +82,7 @@
# include "COM_compositor.h"
#endif
using blender::Map;
using blender::Set;
using blender::Span;
using blender::Vector;
@@ -1767,26 +1768,27 @@ static void node_update(const bContext *C, bNodeTree *ntree, bNode *node)
static void count_mutli_input_socket_links(bNodeTree *ntree, SpaceNode *snode)
{
Map<bNodeSocket *, int> counts;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (link->tosock->flag & SOCK_MULTI_INPUT) {
int &count = counts.lookup_or_add(link->tosock, 0);
count++;
}
}
/* Count temporary links going into this socket. */
LISTBASE_FOREACH (bNodeLinkDrag *, nldrag, &snode->runtime->linkdrag) {
LISTBASE_FOREACH (LinkData *, linkdata, &nldrag->links) {
bNodeLink *link = (bNodeLink *)linkdata->data;
if (link->tosock && (link->tosock->flag & SOCK_MULTI_INPUT)) {
int &count = counts.lookup_or_add(link->tosock, 0);
count++;
}
}
}
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
LISTBASE_FOREACH (struct bNodeSocket *, socket, &node->inputs) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
if (socket->flag & SOCK_MULTI_INPUT) {
Set<bNodeSocket *> visited_from_sockets;
socket->total_inputs = 0;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
if (link->tosock == socket) {
visited_from_sockets.add(link->fromsock);
}
}
/* Count temporary links going into this socket. */
LISTBASE_FOREACH (bNodeLinkDrag *, nldrag, &snode->runtime->linkdrag) {
LISTBASE_FOREACH (LinkData *, linkdata, &nldrag->links) {
bNodeLink *link = (bNodeLink *)linkdata->data;
if (link->tosock == socket) {
visited_from_sockets.add(link->fromsock);
}
}
}
socket->total_inputs = visited_from_sockets.size();
socket->total_inputs = counts.lookup_default(socket, 0);
}
}
}

View File

@@ -1283,6 +1283,13 @@ static bNodeLink *rna_NodeTree_link_new(bNodeTree *ntree,
if (nodeCountSocketLinks(ntree, tosock) + 1 > nodeSocketLinkLimit(tosock)) {
nodeRemSocketLinks(ntree, tosock);
}
if (tosock->flag & SOCK_MULTI_INPUT) {
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
if (link->fromsock == fromsock && link->tosock == tosock) {
nodeRemLink(ntree, link);
}
}
}
}
ret = nodeAddLink(ntree, fromnode, fromsock, tonode, tosock);

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