GPv3: Join Geometry/Realize Instances node #113844

Closed
Falk David wants to merge 11 commits from filedescriptor/blender:gpv3-join-geometry-node into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Implements the Join Geometry and Realize Instances node.

Note that the layers are joined in the order of the indices. This means that the layers plugged into the top of the multi-input socket will appear "behind" the other layers.
The data inside the layers themselves is not changed, e.g. layers are not merged.
If the geometries have layers with the same name, the output will rename layers such that the names are unique.

Implements the Join Geometry and Realize Instances node. Note that the layers are joined in the order of the indices. This means that the layers plugged into the top of the multi-input socket will appear "behind" the other layers. The data inside the layers themselves is not changed, e.g. layers are not merged. If the geometries have layers with the same name, the output will rename layers such that the names are unique.
Falk David added 2 commits 2023-10-17 15:49:12 +02:00
Falk David requested review from Jacques Lucke 2023-10-17 17:09:27 +02:00
Falk David requested review from Hans Goudey 2023-10-17 17:09:27 +02:00
Hans Goudey requested changes 2023-10-18 09:51:31 +02:00
Hans Goudey left a comment
Member

Edit: Commented on the wrong PR, oops

Edit: Commented on the wrong PR, oops
@ -144,0 +145,4 @@
static void join_grease_pencil(const Span<const GeometryComponent *> src_components,
GeometrySet &result)
{
int tot_drawings = 0;
Member

drawings_num

`drawings_num`
filedescriptor marked this conversation as resolved
@ -144,0 +146,4 @@
GeometrySet &result)
{
int tot_drawings = 0;
Vector<int> start_offsets;
Member

Array, since the size is known ahead of time

`Array`, since the size is known ahead of time
filedescriptor marked this conversation as resolved
@ -144,0 +164,4 @@
const bke::GreasePencilComponent &src_grease_pencil_component =
static_cast<const bke::GreasePencilComponent &>(*src_components[index]);
const int start_offset = start_offsets[index];
for (int i = 0; i < src_grease_pencil_component.get()->drawing_array_num; i++) {
Member

->drawings().index_range()`?

->drawings().index_range()`?
filedescriptor marked this conversation as resolved
@ -144,0 +180,4 @@
const GreasePencilDrawingReference *src_drawing_reference =
reinterpret_cast<const GreasePencilDrawingReference *>(src_drawing_base);
dst_grease_pencil->drawing_array[start_offset + i] =
reinterpret_cast<GreasePencilDrawingBase *>(MEM_dupallocN(src_drawing_reference));
Member

MEM_new(__func__, src_drawing_reference); seems like a safer way to do this IMO

`MEM_new(__func__, src_drawing_reference);` seems like a safer way to do this IMO
filedescriptor marked this conversation as resolved
@ -144,0 +192,4 @@
const bke::GreasePencilComponent &src_grease_pencil_component =
static_cast<const bke::GreasePencilComponent &>(*src_components[index]);
const int start_offset = start_offsets[index];
const blender::Span<const bke::greasepencil::Layer *> src_layers =
Member

Remove blender::

Remove `blender::`
filedescriptor marked this conversation as resolved
Falk David added 2 commits 2023-10-18 10:38:17 +02:00
Falk David requested review from Hans Goudey 2023-10-18 10:38:26 +02:00
Hans Goudey approved these changes 2023-10-18 10:55:34 +02:00
@ -144,0 +164,4 @@
const bke::GreasePencilComponent &src_grease_pencil_component =
static_cast<const bke::GreasePencilComponent &>(*src_components[index]);
const int start_offset = start_offsets[index];
for (const int i : src_grease_pencil_component.get()->drawings().index_range()) {
Member

Maybe put the drawings in a temporary Span variable to avoid combining the use of drawings() and drawing_array, and to avoid calling component.get() many times.

Maybe put the drawings in a temporary `Span` variable to avoid combining the use of `drawings()` and `drawing_array`, and to avoid calling `component.get()` many times.
filedescriptor marked this conversation as resolved
Member

Also, the PR/commit description should mention the behavior we decided on about concatenating the layers vs. merging them by name.

Also, the PR/commit description should mention the behavior we decided on about concatenating the layers vs. merging them by name.

Having redundant information doesn’t hurt, but I’ll make sure that design decision is mentioned on the overview task, where we mention the instancing as well. (done)

Once we are done (soon?) this can move to the wiki.

~~Having redundant information doesn’t hurt, but I’ll make sure that design decision is mentioned on the overview task, where we mention the instancing as well.~~ (done) Once we are done (soon?) this can move to the wiki.
Jacques Lucke requested changes 2023-10-18 11:20:48 +02:00
Jacques Lucke left a comment
Member

I think this should use the same approach we use for meshes, point clouds and curves: reuse the realize instances code.
When the realize instances code is implemented, only a one line change should be necessary to make the Join Geometry node work as well.

I think this should use the same approach we use for meshes, point clouds and curves: reuse the realize instances code. When the realize instances code is implemented, only a one line change should be necessary to make the Join Geometry node work as well.
Falk David added 2 commits 2023-10-18 11:47:20 +02:00
Falk David added 2 commits 2023-10-18 15:08:25 +02:00
Falk David changed title from GPv3: Join Geometry node to GPv3: Join Geometry/Realize Instances node 2023-10-18 15:08:41 +02:00
Author
Member

I've updated the code to implement the realize_instance function instead.

There are some todos right now:

  • Ensure unique names of layers (could be done in the preprocess_grease_pencils where we populate an array of all names)
  • Custom attribute initialization (e.g. float attribute seem to be initialized to -inf)
  • Propagate instance attributes to layer attributes?
I've updated the code to implement the `realize_instance` function instead. There are some todos right now: - [ ] Ensure unique names of layers (could be done in the `preprocess_grease_pencils` where we populate an array of all names) - [ ] Custom attribute initialization (e.g. float attribute seem to be initialized to `-inf`) - [ ] Propagate instance attributes to layer attributes?
Falk David requested review from Hans Goudey 2023-10-18 15:15:42 +02:00
Falk David requested review from Jacques Lucke 2023-10-18 15:15:43 +02:00
Falk David added 1 commit 2023-10-18 15:16:57 +02:00
Falk David added 1 commit 2023-10-18 15:47:51 +02:00
Falk David added 1 commit 2023-10-18 16:46:21 +02:00
Jacques Lucke requested changes 2023-10-18 18:16:23 +02:00
@ -505,0 +512,4 @@
TreeNode &TreeNode::operator=(const TreeNode &other)
{
copy_tree_node(other, *this);
Member

Few issues here:

  • Does not protect against self-assignment.
  • Has a memory leak because it does not free the original data in the TreeNode that is being replaced.

Currently, I'd recommend against using copy-assignment for layers. It's not always trivial to get these things right. And here it's even harder because the layer has a pointer to its parent, and the parent also has a pointer to the children.

Few issues here: * Does not protect against self-assignment. * Has a memory leak because it does not free the original data in the `TreeNode` that is being replaced. Currently, I'd recommend against using copy-assignment for layers. It's not always trivial to get these things right. And here it's even harder because the layer has a pointer to its parent, and the parent also has a pointer to the children.
Author
Member

Ok apart from fixing the issues you mentioned, what would be the alternative to using the copy assignment?

Ok apart from fixing the issues you mentioned, what would be the alternative to using the copy assignment?
Member

A method or normal function that copies that data you care about from one layer to another (but probably does not change the parent pointer).

A method or normal function that copies that data you care about from one layer to another (but probably does not change the parent pointer).
@ -1494,0 +1623,4 @@
const Span<const bke::greasepencil::Layer *> layers = grease_pencil->layers();
for (const int layer_i : layers.index_range()) {
char unique_name[MAX_NAME];
Member

Seems like layer names can be quite a bit longer in generally? At least based on the DNA definition.

Seems like layer names can be quite a bit longer in generally? At least based on the DNA definition.
Author
Member

Right, I think we'd need a better BLI_uniquename function like #113901 to support arbitrary long unique names.

Right, I think we'd need a better `BLI_uniquename` function like #113901 to support arbitrary long unique names.
Hans Goudey requested changes 2024-01-30 04:50:00 +01:00
Hans Goudey left a comment
Member

Just requesting changes based on existing comments to remove this from my queue.

Just requesting changes based on existing comments to remove this from my queue.
Author
Member

Closing this since it's replaced by #124361.

Closing this since it's replaced by #124361.
Falk David closed this pull request 2024-07-11 11:12:03 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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 project
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#113844
No description provided.