Geometry Nodes: new repeat zone #109164

Merged
Jacques Lucke merged 98 commits from JacquesLucke/blender:serial-loop into main 2023-07-11 22:36:17 +02:00
8 changed files with 53 additions and 8 deletions
Showing only changes of commit 0608348666 - Show all commits

View File

@ -871,6 +871,7 @@ const bTheme U_theme_default = {
.nodeclass_geometry = RGBA(0x00d6a3ff),
.nodeclass_attribute = RGBA(0x001566ff),
.node_zone_simulation = RGBA(0x66416233),
.node_zone_serial_loop = RGBA(0x41666233),
.movie = RGBA(0x0f0f0fcc),
.gp_vertex_size = 3,
.gp_vertex = RGBA(0x97979700),

View File

@ -28,7 +28,10 @@ static Vector<std::unique_ptr<TreeZone>> find_zone_nodes(
const bNodeTree &tree, TreeZones &owner, Map<const bNode *, TreeZone *> &r_zone_by_inout_node)
{
Vector<std::unique_ptr<TreeZone>> zones;
for (const bNode *node : tree.nodes_by_type("GeometryNodeSimulationOutput")) {
Vector<const bNode *> zone_output_nodes;
zone_output_nodes.extend(tree.nodes_by_type("GeometryNodeSimulationOutput"));
zone_output_nodes.extend(tree.nodes_by_type("GeometryNodeSerialLoopOutput"));
for (const bNode *node : zone_output_nodes) {
auto zone = std::make_unique<TreeZone>();
zone->owner = &owner;
zone->index = zones.size();
@ -45,6 +48,17 @@ static Vector<std::unique_ptr<TreeZone>> find_zone_nodes(
}
}
}
for (const bNode *node : tree.nodes_by_type("GeometryNodeSerialLoopInput")) {
auto serial_loop_outputs = tree.nodes_by_type("GeometryNodeSerialLoopOutput");
if (serial_loop_outputs.is_empty()) {
continue;
}
const bNode *loop_output_node = serial_loop_outputs[0];
if (TreeZone *zone = r_zone_by_inout_node.lookup_default(loop_output_node, nullptr)) {
zone->input_node = node;
r_zone_by_inout_node.add(node, zone);
}
}
return zones;
}
@ -169,13 +183,13 @@ static std::unique_ptr<TreeZones> discover_tree_zones(const bNodeTree &tree)
depend_on_output_flags |= depend_on_output_flag_array[from_node_i];
}
}
if (node->type == GEO_NODE_SIMULATION_INPUT) {
if (ELEM(node->type, GEO_NODE_SIMULATION_INPUT, GEO_NODE_SERIAL_LOOP_INPUT)) {
if (const TreeZone *zone = zone_by_inout_node.lookup_default(node, nullptr)) {
/* Now entering a zone, so set the corresponding bit. */
depend_on_input_flags[zone->index].set();
}
}
else if (node->type == GEO_NODE_SIMULATION_OUTPUT) {
else if (ELEM(node->type, GEO_NODE_SIMULATION_OUTPUT, GEO_NODE_SERIAL_LOOP_OUTPUT)) {
if (const TreeZone *zone = zone_by_inout_node.lookup_default(node, nullptr)) {
/* The output is implicitly linked to the input, so also propagate the bits from there. */
if (const bNode *zone_input_node = zone->input_node) {

View File

@ -112,6 +112,7 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
*/
{
/* Keep this block, even when empty. */
FROM_DEFAULT_V4_UCHAR(space_node.node_zone_serial_loop);
}
#undef FROM_DEFAULT_V4_UCHAR

View File

@ -180,6 +180,7 @@ typedef enum ThemeColorID {
TH_NODE_ATTRIBUTE,
TH_NODE_ZONE_SIMULATION,
TH_NODE_ZONE_SERIAL_LOOP,
TH_SIMULATED_FRAMES,
TH_CONSOLE_OUTPUT,

View File

@ -644,6 +644,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_NODE_ZONE_SIMULATION:
cp = ts->node_zone_simulation;
break;
case TH_NODE_ZONE_SERIAL_LOOP:
cp = ts->node_zone_serial_loop;
break;
case TH_SIMULATED_FRAMES:
cp = ts->simulated_frames;
break;

View File

@ -2151,7 +2151,12 @@ static void node_draw_basis(const bContext &C,
}
/* Shadow. */
if (!ELEM(node.type, GEO_NODE_SIMULATION_INPUT, GEO_NODE_SIMULATION_OUTPUT)) {
if (!ELEM(node.type,
GEO_NODE_SIMULATION_INPUT,
GEO_NODE_SIMULATION_OUTPUT,
GEO_NODE_SERIAL_LOOP_INPUT,
GEO_NODE_SERIAL_LOOP_OUTPUT))
{
node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
}
@ -2431,6 +2436,10 @@ static void node_draw_basis(const bContext &C,
UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, color_outline);
color_outline[3] = 1.0f;
}
else if (ELEM(node.type, GEO_NODE_SERIAL_LOOP_INPUT, GEO_NODE_SERIAL_LOOP_OUTPUT)) {
UI_GetThemeColor4fv(TH_NODE_ZONE_SERIAL_LOOP, color_outline);
color_outline[3] = 1.0f;
}
else {
UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color_outline);
}
@ -3165,21 +3174,29 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
float line_width = 1.0f * scale;
float viewport[4] = {};
GPU_viewport_size_get_f(viewport);
float zone_color[4];
UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color);
const auto get_theme_id = [&](const int zone_i) {
const bNode *node = zones->zones[zone_i]->output_node;
if (node->type == GEO_NODE_SIMULATION_OUTPUT) {
return TH_NODE_ZONE_SIMULATION;
}
return TH_NODE_ZONE_SERIAL_LOOP;
};
const uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
/* Draw all the contour lines after to prevent them from getting hidden by overlapping zones. */
for (const int zone_i : zones->zones.index_range()) {
float zone_color[4];
UI_GetThemeColor4fv(get_theme_id(zone_i), zone_color);
if (zone_color[3] == 0.0f) {
break;
}
const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions();
/* Draw the background. */
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColorBlend(TH_BACK, TH_NODE_ZONE_SIMULATION, zone_color[3]);
immUniformThemeColorBlend(TH_BACK, get_theme_id(zone_i), zone_color[3]);
immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1);
for (const float3 &p : fillet_boundary_positions) {
@ -3199,7 +3216,7 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
immUniform2fv("viewportSize", &viewport[2]);
immUniform1f("lineWidth", line_width * U.pixelsize);
immUniformThemeColorAlpha(TH_NODE_ZONE_SIMULATION, 1.0f);
immUniformThemeColorAlpha(get_theme_id(zone_i), 1.0f);
immBegin(GPU_PRIM_LINE_STRIP, fillet_boundary_positions.size() + 1);
for (const float3 &p : fillet_boundary_positions) {
immVertex3fv(pos, p);

View File

@ -345,6 +345,8 @@ typedef struct ThemeSpace {
unsigned char nodeclass_geometry[4], nodeclass_attribute[4];
unsigned char node_zone_simulation[4];
unsigned char node_zone_serial_loop[4];
unsigned char _pad9[4];
unsigned char simulated_frames[4];
/** For sequence editor. */

View File

@ -3062,6 +3062,12 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna)
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Simulation Zone", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "serial_loop_zone", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "node_zone_serial_loop");
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Serial Loop Zone", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
}
static void rna_def_userdef_theme_space_buts(BlenderRNA *brna)