Geometry Nodes: Index switch node #115250

Merged
Hans Goudey merged 30 commits from HooglyBoogly/blender:geometry-nodes-index-switch into main 2023-11-22 16:11:41 +01:00
Member

Add an "Index Switch" node which is meant as a simpler version of
the "Menu Switch" from #113445 that doesn't allow naming items
or displaying them in a dropdown, but still allows choosing between
an arbitrary number of items, unlike the regular "Switch" node.
Even when the Menu Switch is included (which should be in the
same release as this), it may still be helpful to have explicit mapping
of indices, and a fair amount of the internals can be shared anyway.


image

Add an "Index Switch" node which is meant as a simpler version of the "Menu Switch" from #113445 that doesn't allow naming items or displaying them in a dropdown, but still allows choosing between an arbitrary number of items, unlike the regular "Switch" node. Even when the Menu Switch is included (which should be in the same release as this), it may still be helpful to have explicit mapping of indices, and a fair amount of the internals can be shared anyway. --- ![image](/attachments/dd1d18cf-3e98-4641-9c5e-b873414b58cb)
Hans Goudey added 15 commits 2023-11-22 01:46:24 +01:00
Hans Goudey requested review from Lukas Tönne 2023-11-22 01:46:38 +01:00
Hans Goudey requested review from Jacques Lucke 2023-11-22 01:46:39 +01:00
Hans Goudey added the
Interest
Geometry Nodes
label 2023-11-22 01:46:50 +01:00
Hans Goudey added this to the Nodes & Physics project 2023-11-22 01:47:08 +01:00
Hans Goudey added 7 commits 2023-11-22 01:47:09 +01:00
Jacques Lucke requested changes 2023-11-22 10:40:12 +01:00
Jacques Lucke left a comment
Member

Generally looks good and how I'd expect it to work. Got some inline comments.

Generally looks good and how I'd expect it to work. Got some inline comments.
@ -4,3 +4,3 @@
import bpy
from bpy.types import Operator
from bpy.types import Operator, IntProperty
Member

Don't include IntProperty from bpy.types.

Don't include `IntProperty` from `bpy.types`.
HooglyBoogly marked this conversation as resolved
@ -459,6 +460,55 @@ class RepeatZoneItemMoveOperator(RepeatZoneOperator, ZoneMoveItemOperator, Opera
bl_options = {'REGISTER', 'UNDO'}
def _editable_tree_with_active_node_type(context, node_type):
Member

node_type is unused

`node_type` is unused
HooglyBoogly marked this conversation as resolved
@ -1148,0 +1167,4 @@
node = context.active_node
layout.operator("node.index_switch_item_add", icon='ADD', text="Add Item")
for i, item in enumerate(node.index_switch_items):
row = layout.row()
Member

I'd expect all these row to be in a column.

I'd expect all these row to be in a column.
HooglyBoogly marked this conversation as resolved
@ -39,10 +39,18 @@ struct SimulationItemsAccessor {
}
static void blend_write(BlendWriter *writer, const bNode &node);
static void blend_read_data(BlendDataReader *reader, bNode &node);
static constexpr bool has_type()
Member

This can also be a constexpr static member, instead of a function.

This can also be a `constexpr` static member, instead of a function.
HooglyBoogly marked this conversation as resolved
@ -0,0 +120,4 @@
void call(const IndexMask &mask, mf::Params params, mf::Context /*context*/) const
{
const int inputs_num = signature_.params.size() - 2;
const VArray<int> indices = params.readonly_single_input<int>(0, "Index");
Member

Optimize for the case when this is a single value. This can still happen, even if it was a field before.

Optimize for the case when this is a single value. This can still happen, even if it was a field before.
Author
Member

Ah, I didn't realize that, but it makes sense.

Ah, I didn't realize that, but it makes sense.
HooglyBoogly marked this conversation as resolved
@ -0,0 +126,4 @@
const int invalid_index = inputs_num;
IndexMaskMemory memory;
Array<IndexMask> masks(inputs_num + 1);
IndexMask::from_groups<int64_t>(
Member

Feels like something that is very optimizable in the future by using spans etc. directly instead of using higher level abstractions. Could be fine for now though.

Feels like something that is very optimizable in the future by using spans etc. directly instead of using higher level abstractions. Could be fine for now though.
Author
Member

Yeah, probably. The implementation of IndexMask::from_groups isn't optimal right now, that's somewhere to start. I've been trying to use IndexMask::from_groups everywhere we're solving this problem though, so that we can optimize things with all of that in mind. I also used IndexMask here thinking about branching multi-function evaluation. Evaluating each input on a smaller mask would be nice.

Yeah, probably. The implementation of `IndexMask::from_groups` isn't optimal right now, that's somewhere to start. I've been trying to use `IndexMask::from_groups` everywhere we're solving this problem though, so that we can optimize things with all of that in mind. I also used `IndexMask` here thinking about branching multi-function evaluation. Evaluating each input on a smaller mask would be nice.
In case if such method is even needed at all: https://projects.blender.org/blender/blender/pulls/111081/files#diff-90d4677ddd507912e8848534ef60d6dfef4f3154
@ -0,0 +141,4 @@
for (const int i : IndexRange(inputs_num)) {
if (!masks[i].is_empty()) {
const GVArray inputs = params.readonly_single_input(value_inputs_start + i);
array_utils::copy(inputs, masks[i], output);
Member

output points to uninitialized memory, therefor using array_utils::copy is semantically wrong.

`output` points to uninitialized memory, therefor using `array_utils::copy` is semantically wrong.
HooglyBoogly marked this conversation as resolved
Member

node_zone_socket_items.cc should be renamed to reflect that it's not just "zones" now. Fine for now.

`node_zone_socket_items.cc` should be renamed to reflect that it's not just "zones" now. Fine for now.
Hans Goudey added 1 commit 2023-11-22 15:22:41 +01:00
Hans Goudey added 6 commits 2023-11-22 15:38:46 +01:00
Author
Member

Thanks for the review. I've found a memory leak I need to fix too, not sure where it's coming from yet though.

Thanks for the review. I've found a memory leak I need to fix too, not sure where it's coming from yet though.
Hans Goudey requested review from Jacques Lucke 2023-11-22 15:39:00 +01:00
Jacques Lucke approved these changes 2023-11-22 16:01:58 +01:00
Jacques Lucke left a comment
Member

Can you add a regression file with some decent code coverage afterwards?

Can you add a regression file with some decent code coverage afterwards?
Author
Member

Yeah, will do!

Yeah, will do!
Hans Goudey added 1 commit 2023-11-22 16:07:28 +01:00
Hans Goudey merged commit 8d5aa6eed4 into main 2023-11-22 16:11:41 +01:00
Hans Goudey deleted branch geometry-nodes-index-switch 2023-11-22 16:11:43 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#115250
No description provided.