Geometry Nodes: Simulation Zone drawing updates #107043

Closed
Dalai Felinto wants to merge 5 commits from geometry-nodes-simulation-background into geometry-nodes-simulation

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 43 additions and 15 deletions

View File

@ -869,7 +869,7 @@ const bTheme U_theme_default = {
.nodeclass_layout = RGBA(0x6c696fff),
.nodeclass_geometry = RGBA(0x00d6a3ff),
.nodeclass_attribute = RGBA(0x001566ff),
.node_zone_simulation = RGBA(0x00000011),
.node_zone_simulation = RGBA(0x66416233),
.movie = RGBA(0x0f0f0fcc),
.gp_vertex_size = 3,
.gp_vertex = RGBA(0x97979700),

View File

@ -108,10 +108,7 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
*/
{
/* Keep this block, even when empty. */
if (btheme->space_node.node_zone_simulation[3] == 0) {
btheme->space_node.node_zone_simulation[3] = 0x11;
}
FROM_DEFAULT_V4_UCHAR(space_node.node_zone_simulation);
}
#undef FROM_DEFAULT_V4_UCHAR

View File

@ -3122,6 +3122,7 @@ static void find_bounds_by_zone_recursive(const SpaceNode &snode,
}
static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
const ARegion &region,
const SpaceNode &snode,
const bNodeTree &ntree)
{
@ -3131,6 +3132,8 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
}
Array<Vector<float2>> bounds_by_zone(zones->zones.size());
Array<bke::CurvesGeometry> fillet_curve_by_zone(zones->zones.size());
for (const int zone_i : zones->zones.index_range()) {
const TreeZone &zone = *zones->zones[zone_i];
@ -3151,27 +3154,56 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
}
boundary_curve.tag_topology_changed();
bke::CurvesGeometry fillet_curve = geometry::fillet_curves_poly(
fillet_curve_by_zone[zone_i] = geometry::fillet_curves_poly(
boundary_curve,
IndexRange(1),
VArray<float>::ForSingle(UI_UNIT_X / 2, boundary_positions_num),
VArray<float>::ForSingle(BASIS_RAD, boundary_positions_num),
VArray<int>::ForSingle(5, boundary_positions_num),
true,
{});
const Span<float3> fillet_boundary_positions = fillet_curve.positions();
}
const uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
const View2D &v2d = region.v2d;
float scale;
UI_view2d_scale_get(&v2d, &scale, nullptr);
float line_width = 1.0f * scale;

What about using immUniformColor4fv here so TH_NODE_ZONE_SIMULATION doesn't have to be passed twice? I'd think that would give the same result.

What about using `immUniformColor4fv` here so `TH_NODE_ZONE_SIMULATION` doesn't have to be passed twice? I'd think that would give the same result.
float viewport[4] = {};
GPU_viewport_size_get_f(viewport);
float zone_color[4];
UI_GetThemeColor4fv(TH_NODE_ZONE_SIMULATION, zone_color);
const uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
/**
* Draw all the countour lines after to prevent them from getting hidden.
* Once we support other zones (e.g., for loops) we will need to sort them in a smarter way.
*/
for (const int zone_i : zones->zones.index_range()) {
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]);
GPU_blend(GPU_BLEND_ALPHA);
immUniformThemeColor(TH_NODE_ZONE_SIMULATION);
immBegin(GPU_PRIM_TRI_FAN, fillet_boundary_positions.size() + 1);
for (const float3 &p : fillet_boundary_positions) {
immVertex3fv(pos, p);
}
immVertex3fv(pos, fillet_boundary_positions[0]);
immEnd();
}
for (const int zone_i : zones->zones.index_range()) {
const Span<float3> fillet_boundary_positions = fillet_curve_by_zone[zone_i].positions();
/* Draw the countour lines. */
immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
immUniform2fv("viewportSize", &viewport[2]);
immUniform1f("lineWidth", line_width * U.pixelsize);
immUniformThemeColorAlpha(TH_NODE_ZONE_SIMULATION, 1.0f);
immBegin(GPU_PRIM_LINE_STRIP, fillet_boundary_positions.size() + 1);
for (const float3 &p : fillet_boundary_positions) {
@ -3181,7 +3213,6 @@ static void node_draw_zones(TreeDrawContext & /*tree_draw_ctx*/,
immEnd();
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
}
}
@ -3352,7 +3383,7 @@ static void draw_nodetree(const bContext &C,
}
node_update_nodetree(C, tree_draw_ctx, ntree, nodes, blocks);
node_draw_zones(tree_draw_ctx, *snode, ntree);
node_draw_zones(tree_draw_ctx, region, *snode, ntree);
node_draw_nodetree(C, tree_draw_ctx, region, *snode, ntree, nodes, blocks, parent_key);
}

View File

@ -3057,7 +3057,7 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Attribute Node", "");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "simulation_region", PROP_FLOAT, PROP_COLOR_GAMMA);
prop = RNA_def_property(srna, "simulation_zone", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "node_zone_simulation");
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Simulation Zone", "");