GPv3: Initial Geometry Nodes support #112535

Merged
Falk David merged 61 commits from filedescriptor/blender:gpv3-geometry-nodes into main 2023-10-10 16:49:39 +02:00
Member

This implements the core changes for this design: https://devtalk.blender.org/t/grease-pencil-integration-into-geometry-nodes/31220

The changes include:

  • Add CustomData for layer attributes
  • Add attribute support for the GreasePencilComponent to read/write layer attributes. Also introduce a Layer domain.
  • Implement a GreasePencilLayerFieldContext and make GeometryFieldContext work with grease pencil layers.
  • Implement Set Position node for Grease Pencil.

Note: These changes are only accessible/visible with the Grease Pencil 3.0 experimental flag enabled.

This implements the core changes for this design: https://devtalk.blender.org/t/grease-pencil-integration-into-geometry-nodes/31220 The changes include: * Add `CustomData` for layer attributes * Add attribute support for the `GreasePencilComponent` to read/write layer attributes. Also introduce a `Layer` domain. * Implement a `GreasePencilLayerFieldContext` and make `GeometryFieldContext` work with grease pencil layers. * Implement `Set Position` node for `Grease Pencil`. Note: These changes are only accessible/visible with the `Grease Pencil 3.0` experimental flag enabled.
Falk David force-pushed gpv3-geometry-nodes from 7d8fb1e96b to 9bff50909a 2023-09-19 16:15:25 +02:00 Compare
Falk David force-pushed gpv3-geometry-nodes from b17686a270 to fe3729bac4 2023-09-25 12:34:51 +02:00 Compare
Falk David force-pushed gpv3-geometry-nodes from fe3729bac4 to 0a140c6845 2023-09-28 11:41:01 +02:00 Compare
Jacques Lucke added 1 commit 2023-09-29 12:44:18 +02:00
Jacques Lucke added 5 commits 2023-09-29 14:52:07 +02:00
Jacques Lucke added 2 commits 2023-09-29 15:38:08 +02:00
Jacques Lucke added 2 commits 2023-09-29 16:00:44 +02:00
Jacques Lucke added 1 commit 2023-09-29 16:08:26 +02:00
Jacques Lucke added 1 commit 2023-09-29 21:15:13 +02:00
Falk David added 1 commit 2023-10-05 12:17:45 +02:00
Dalai Felinto approved these changes 2023-10-06 15:30:22 +02:00
Dismissed
@ -152,0 +167,4 @@
propagation_info,
dst_curves))
{
return;

This would make the node to skip the grease pencil part of it. It probably needs to be an if/else

This would make the node to skip the grease pencil part of it. It probably needs to be an if/else
filedescriptor marked this conversation as resolved
Dalai Felinto requested review from Dalai Felinto 2023-10-06 15:30:28 +02:00
Dalai Felinto refused to review 2023-10-06 15:30:35 +02:00
Falk David added 2 commits 2023-10-06 16:41:17 +02:00
Falk David added 1 commit 2023-10-06 16:42:27 +02:00
Falk David changed title from WIP: GPv3: Geometry Nodes to GPv3: Initial Geometry Nodes support 2023-10-06 17:52:17 +02:00
Falk David added 1 commit 2023-10-06 17:54:11 +02:00
Falk David added 1 commit 2023-10-06 17:54:31 +02:00
Falk David added 1 commit 2023-10-06 17:55:17 +02:00
Falk David added 1 commit 2023-10-06 17:59:20 +02:00
Falk David requested review from Jacques Lucke 2023-10-06 17:59:48 +02:00
Falk David requested review from Hans Goudey 2023-10-06 17:59:49 +02:00
Author
Member

I think this is ready to be reviewed.
Ideally anything shown in the UI related to Grease Pencil is hidden behind the experimental flag.

I think this is ready to be reviewed. Ideally anything shown in the UI related to Grease Pencil is hidden behind the experimental flag.
Falk David added 1 commit 2023-10-06 18:07:07 +02:00
Iliya Katushenock reviewed 2023-10-06 18:22:37 +02:00
@ -565,0 +686,4 @@
if (grease_pencil == nullptr) {
return false;
}
std::atomic<bool> any_success = false;

This can be regular bool, any writing will be atomic.

This can be regular bool, any writing will be atomic.
filedescriptor marked this conversation as resolved

is_empty()

`is_empty()`
filedescriptor marked this conversation as resolved
@ -1995,1 +2211,4 @@
}
if (node.is_layer()) {
const Span<const bke::greasepencil::Layer *> layers = this->layers();

const IndexRange

`const IndexRange`
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-10-06 19:20:45 +02:00
Jacques Lucke added 2 commits 2023-10-07 23:55:55 +02:00
Hans Goudey requested changes 2023-10-09 11:49:07 +02:00
Hans Goudey left a comment
Member
  • There should be a link to the design in the PR description, or a more complete description of the changes in the PR itself
  • I think GreasePencilFieldContext should first check for GeometryFieldInput, call that if possible, but otherwise use existing CurvesFieldInputs. That allows changing existing curves field inputs that do field evaluations, but not changing existing field inputs that don't. Otherwise we'd basically have to completely remove CurvesFieldInput
  • The set position node has a fair amount of duplication compared to the other nodes. It would be nice to at least reuse the default case of set_computed_position_and_offset, since it has the "is original" optimization and the devirtualization optimization.
- [x] There should be a link to the design in the PR description, or a more complete description of the changes in the PR itself - [x] I think `GreasePencilFieldContext` should first check for `GeometryFieldInput`, call that if possible, but otherwise use existing `CurvesFieldInput`s. That allows changing existing curves field inputs that do field evaluations, but not changing existing field inputs that don't. Otherwise we'd basically have to completely remove `CurvesFieldInput` - [x] The set position node has a fair amount of duplication compared to the other nodes. It would be nice to at least reuse the `default` case of `set_computed_position_and_offset`, since it has the "is original" optimization and the devirtualization optimization.
@ -99,12 +132,24 @@ class GeometryFieldContext : public fn::FieldContext {
const void *geometry_;
const GeometryComponent::Type type_;
const eAttrDomain domain_;
/** Only used when the type is grease pencil and the domain is either points or curves
Member
  /** 
   * Only used when the type is grease pencil and the domain is either points or curves
   * (not layers).
   */
``` /** * Only used when the type is grease pencil and the domain is either points or curves * (not layers). */
filedescriptor marked this conversation as resolved
@ -123,1 +168,4 @@
int grease_pencil_layer_index() const
{
return grease_pencil_layer_index_;
Member

Add an assert for the component type and domain

Add an assert for the component type and domain
filedescriptor marked this conversation as resolved
@ -686,3 +686,2 @@
* A geometry component that stores #GreasePencil data.
* This component does not implement an attribute API, because the #GreasePencil data itself does
* not store any attributes, only the individual drawings within it.
* The attributes on this component are only on the layer domain.
Member

Nice, but this should also mention the other domains are stored inside the curves for each layer, this is only about the "direct" attributes

Nice, but this should also mention the other domains are stored inside the curves for each layer, this is only about the "direct" attributes
filedescriptor marked this conversation as resolved
@ -98,0 +151,4 @@
}
};
fn.domain_supported = [](const void * /*owner*/, const eAttrDomain domain) {
return ELEM(domain, ATTR_DOMAIN_GREASE_PENCIL_LAYER);
Member

return domain == ATTR_DOMAIN_GREASE_PENCIL_LAYER;

`return domain == ATTR_DOMAIN_GREASE_PENCIL_LAYER;`
filedescriptor marked this conversation as resolved
@ -485,2 +603,2 @@
const fn::Field<bool> &selection,
const fn::GField &field)
static bool try_capture_field_on_geometry(MutableAttributeAccessor attributes,
GeometryFieldContext field_context,
Member

Pass by const reference

Pass by const reference
filedescriptor marked this conversation as resolved
@ -565,0 +697,4 @@
return false;
}
std::atomic<bool> any_success = false;
threading::parallel_for(
Member

Should use a much smaller grain size here, layers will usually be large enough for that

Should use a much smaller grain size here, layers will usually be large enough for that
filedescriptor marked this conversation as resolved
@ -1956,0 +2047,4 @@
}
}
else {
for (const int i : IndexRange(reorder_to, dist)) {
Member

Simpler with array_utils::fill_index_range(reorder_indices.slice(reorder_to, dist), i);

Or something like that anyway

Simpler with `array_utils::fill_index_range(reorder_indices.slice(reorder_to, dist), i);` Or something like that anyway
filedescriptor marked this conversation as resolved
@ -571,6 +571,13 @@ void *BLI_findlinkfrom(Link *start, int number)
link = link->next;
}
}
else {
Member

Not sure what's going on here, but this should be committed separately

Not sure what's going on here, but this should be committed separately
filedescriptor marked this conversation as resolved
@ -119,3 +118,1 @@
Field<float> &start_field,
Field<float> &end_field,
const AnonymousAttributePropagationInfo &propagation_info)
static bool set_curve_trim(const bke::CurvesGeometry &src_curves,
Member

"set_curve_trim" sounds weird. How about trim_curves?

"set_curve_trim" sounds weird. How about `trim_curves`?
filedescriptor marked this conversation as resolved
@ -130,3 +127,4 @@
return false;
}
const bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_CURVE};
Member

This needs to use the GP field context for GP

This needs to use the GP field context for GP
filedescriptor marked this conversation as resolved
@ -149,3 +145,1 @@
Curves *dst_curves_id = bke::curves_new_nomain(std::move(dst_curves));
bke::curves_copy_parameters(src_curves_id, *dst_curves_id);
geometry_set.replace_curves(dst_curves_id);
dst_curves = std::move(
Member

The result of geometry::trim_curves is already an R-value, no need to move it.

The result of `geometry::trim_curves` is already an R-value, no need to move it.
filedescriptor marked this conversation as resolved
@ -39,3 +39,2 @@
const bke::GeometryFieldContext value_context{
context.geometry(), context.type(), value_field_domain_};
const bke::GeometryFieldContext value_context{context.geometry(),
Member

Can't this use the simpler constructor you added? const bke::GeometryFieldContext value_context{context, value_field_domain_};

Can't this use the simpler constructor you added? `const bke::GeometryFieldContext value_context{context, value_field_domain_};`
filedescriptor marked this conversation as resolved
@ -114,0 +121,4 @@
(dst_domain == ATTR_DOMAIN_GREASE_PENCIL_LAYER))
{
/* Evaluate field just for the current layer. */
if (src_domain_ == ATTR_DOMAIN_GREASE_PENCIL_LAYER) {
Member

Pretty sure this check (or the previous one ;) is redundant

Pretty sure this check (or the previous one ;) is redundant
Author
Member

@JacquesLucke added this but I think it's right. The check before is basically "exactly one of src_domain_ or dst_domain is equal to ATTR_DOMAIN_GREASE_PENCIL_LAYER", so src_domain_ doesn't need to be ATTR_DOMAIN_GREASE_PENCIL_LAYER.

@JacquesLucke added this but I think it's right. The check before is basically "exactly one of `src_domain_` or `dst_domain` is equal to `ATTR_DOMAIN_GREASE_PENCIL_LAYER`", so `src_domain_` doesn't need to be `ATTR_DOMAIN_GREASE_PENCIL_LAYER`.
Member

It's not redundant as Falk pointed out.

It's not redundant as Falk pointed out.
Member

Yeah, I was just reading this too quickly!

Yeah, I was just reading this too quickly!
filedescriptor marked this conversation as resolved
@ -114,0 +126,4 @@
ATTR_DOMAIN_GREASE_PENCIL_LAYER};
const int layer_index = context.grease_pencil_layer_index();
const IndexMask single_layer_mask = IndexRange(layer_index, 1);
Member

I think you could avoid doing the field input manually here by using EvaluateAtIndexInput. You could probably just pass in the input field, the single value field for the layer index, and the layer domain. Seems sort of elegant that way-- avoiding reimplementing evaluating the field at a single index :)

I think you could avoid doing the field input manually here by using `EvaluateAtIndexInput`. You could probably just pass in the input field, the single value field for the layer index, and the layer domain. Seems sort of elegant that way-- avoiding reimplementing evaluating the field at a single index :)
Author
Member

@HooglyBoogly and I looked at this briefly, but it makes the code more complicated in the end. We'll keep it like it is for now.

@HooglyBoogly and I looked at this briefly, but it makes the code more complicated in the end. We'll keep it like it is for now.
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-10-09 12:24:53 +02:00
Falk David added 1 commit 2023-10-09 13:41:32 +02:00
Falk David added 1 commit 2023-10-09 13:42:30 +02:00
Falk David added 1 commit 2023-10-09 14:10:27 +02:00
Falk David added 1 commit 2023-10-09 14:19:56 +02:00
Falk David added 1 commit 2023-10-09 14:23:09 +02:00
Dalai Felinto dismissed dfelinto’s review 2023-10-09 14:54:28 +02:00
Falk David added 1 commit 2023-10-09 14:55:14 +02:00
Hans Goudey reviewed 2023-10-10 10:33:26 +02:00
@ -352,4 +404,9 @@ bool try_capture_field_on_geometry(GeometryComponent &component,
std::optional<eAttrDomain> try_detect_field_domain(const GeometryComponent &component,
const fn::GField &field);
const greasepencil::Drawing *get_eval_grease_pencil_layer_drawing(
Member

These seem unrelated to "geometry fields." Maybe they should go in the GP headers?

These seem unrelated to "geometry fields." Maybe they should go in the GP headers?
filedescriptor marked this conversation as resolved
@ -138,0 +209,4 @@
}
const greasepencil::Drawing *GeometryFieldContext::grease_pencil_layer_drawing() const
{
return this->type() == GeometryComponent::Type::GreasePencil &&
Member

Oof, there's a lot going on here. Could this be split to multiple lines with the typical

if (no) { return null;}
if (no_other) { return null; }
return actual_thing;

pattern?

Oof, there's a lot going on here. Could this be split to multiple lines with the typical ``` if (no) { return null;} if (no_other) { return null; } return actual_thing; ``` pattern?
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-10-10 11:14:04 +02:00
Falk David added 1 commit 2023-10-10 11:33:48 +02:00
Falk David added 1 commit 2023-10-10 12:43:25 +02:00
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke requested changes 2023-10-10 13:32:05 +02:00
Jacques Lucke left a comment
Member

The bf_blenkernel_tests failure is probably still caused by this patch. Likely the issue that I reported some time ago already that caused by wrong initialization of GreasePencil in tests.

The `bf_blenkernel_tests` failure is probably still caused by this patch. Likely the issue that I reported some time ago already that caused by wrong initialization of `GreasePencil` in tests.
@ -37,0 +54,4 @@
return field_input.get_varray_for_context(context, mask, scope);
}
}
return {};
Member

This seems to be missing the default case which is just field_input.get_array_for_context(*this).

I think this could be simplified. We just have do check if the field_input is a CurvesFieldInput. Then we do the conversion to CurvesFieldContext. Otherwise, we can just do the default operation mentioned above. The conversion to GeometryFieldContext is done in GeometryFieldInput::get_varray_for_context already.

This seems to be missing the default case which is just `field_input.get_array_for_context(*this)`. I think this could be simplified. We just have do check if the `field_input` is a `CurvesFieldInput`. Then we do the conversion to `CurvesFieldContext`. Otherwise, we can just do the default operation mentioned above. The conversion to `GeometryFieldContext` is done in `GeometryFieldInput::get_varray_for_context` already.
filedescriptor marked this conversation as resolved
@ -1967,1 +2117,4 @@
}
}
if (node.is_group()) {
BLI_assert_msg(0, "Reordering custom data when moving a group is not implemented");
Member

Not-implemented means it will be implemented? Is this protected against at a higher level so that we don't run into this assert in practice?

Not-implemented means it will be implemented? Is this protected against at a higher level so that we don't run into this assert in practice?
Author
Member

Yes, reordering of layer groups is not implemented at a high-level yet, but technically supported by the core functions. This assert basically acts as a reminder to implement this part once we can reorder layer groups.

Yes, reordering of layer groups is not implemented at a high-level yet, but technically supported by the core functions. This assert basically acts as a reminder to implement this part once we can reorder layer groups.
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-10-10 14:13:56 +02:00
Falk David added 1 commit 2023-10-10 15:09:12 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
378d43973f
Fix tests and fix insertion bug for empty groups
Author
Member

@blender-bot build

@blender-bot build
Falk David requested review from Hans Goudey 2023-10-10 15:09:39 +02:00
Falk David requested review from Jacques Lucke 2023-10-10 15:09:40 +02:00
Iliya Katushenock reviewed 2023-10-10 15:12:57 +02:00
@ -1947,0 +2000,4 @@
const IndexRange range_before(insertion_index + 1);
const IndexRange range_after(insertion_index + 1, size - insertion_index - 1);
if (range_before.size() > 0) {

!range_before.is_empty()

`!range_before.is_empty()`

There is still also few other .size() > 0..

There is still also few other `.size() > 0`..
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-10-10 15:17:45 +02:00
Hans Goudey approved these changes 2023-10-10 15:21:33 +02:00
Jacques Lucke added 1 commit 2023-10-10 16:08:21 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
0fb4cf0528
Merge branch 'main' into gpv3-geometry-nodes
Member

@blender-bot build

@blender-bot build
Jacques Lucke approved these changes 2023-10-10 16:20:06 +02:00
Falk David merged commit 3931a54e08 into main 2023-10-10 16:49:39 +02:00
Falk David deleted branch gpv3-geometry-nodes 2023-10-10 16:49:41 +02:00
Sign in to join this conversation.
No reviewers
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 project
No Assignees
5 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#112535
No description provided.