Transform: support properly transforming implicitly shared curve's positions #120824

Merged
Jacques Lucke merged 6 commits from laurynas/blender:transform-data-copy into main 2024-04-22 20:03:04 +02:00
Contributor

The alternative implementation of #120631

The alternative implementation of #120631
Laurynas Duburas added 1 commit 2024-04-19 13:29:29 +02:00
Laurynas Duburas requested review from Germano Cavalcante 2024-04-19 13:30:15 +02:00
Laurynas Duburas requested review from Jacques Lucke 2024-04-19 13:30:15 +02:00
Laurynas Duburas requested review from Hans Goudey 2024-04-19 13:30:15 +02:00
Hans Goudey requested changes 2024-04-19 14:33:52 +02:00
@ -65,0 +88,4 @@
const int64_t points_num = selection.size();
const Vector<IndexRange> ranges{selection.to_ranges()};
void *data = MEM_callocN(sizeof(int64_t) * 2 + sizeof(float3) * points_num +
Member

Could you make the customdata point to a struct like TransformArrays that contains a Array for each dhunk it needs to hold?

Could you make the customdata point to a struct like `TransformArrays` that contains a `Array` for each dhunk it needs to hold?
Author
Contributor

I was trying to avoid new struct, it will change a lot.

I was trying to avoid new struct, it will change a lot.
laurynas marked this conversation as resolved
@ -65,0 +101,4 @@
Span<float3> positions = curves.positions();
int64_t offset_dst = 0;
for (const IndexRange &range : ranges) {
Member

Might it be simpler to use array_utils::gather instead of using an intermediate step of building index ranges?

Might it be simpler to use `array_utils::gather` instead of using an intermediate step of building index ranges?
Author
Contributor

If to go with array_utils::gather selection as IndexMask needs to be stored in tc.custom.type.data for latter use by array_utils::scatter. I didn't find how to make deep copy of IndexMask and that forces in function createTransCurvesVerts to use IndexMaskMemory instance from tc.custom.type.data instead of local variable.
And it is doable, but curve_populate_trans_data_structs is also called from grease pencil code. Selections there also has to be attached to tc.custom.type.data and it's data type (currentlyTransformArrays) exposed outside from transform_convert_curves.cc. Here things get messier.

Also with ranges I like fact that copying is done in chunks, though this advantage is selection dependent.

Can you check current version? It would transfer to grease pencil a lot easier.

If to go with `array_utils::gather` selection as `IndexMask` needs to be stored in `tc.custom.type.data` for latter use by `array_utils::scatter`. I didn't find how to make deep copy of `IndexMask` and that forces in function `createTransCurvesVerts` to use `IndexMaskMemory` instance from `tc.custom.type.data` instead of local variable. And it is doable, but `curve_populate_trans_data_structs` is also called from grease pencil code. Selections there also has to be attached to `tc.custom.type.data` and it's data type (currently`TransformArrays`) exposed outside from `transform_convert_curves.cc`. Here things get messier. Also with ranges I like fact that copying is done in chunks, though this advantage is selection dependent. Can you check current version? It would transfer to grease pencil a lot easier.

You need to do that:

Array<int> mapping(mask.size());
mask.to_indices(mapping);
array_utils::gather(src_positions, mapping.as_span(), dst_positions);

And after this:

for (const int i : mapping.index_range()) {
  dst_positions[mapping[i]] = src_positions[i];
}

No need for to_ranges and Array<int> offsets.

You need to do that: ```Cpp Array<int> mapping(mask.size()); mask.to_indices(mapping); array_utils::gather(src_positions, mapping.as_span(), dst_positions); ``` And after this: ```Cpp for (const int i : mapping.index_range()) { dst_positions[mapping[i]] = src_positions[i]; } ``` No need for `to_ranges` and `Array<int> offsets`.
Member

Storing the selection for later would really just be an optimization anyway, it can always be recomputed from the current attributes. Anyway, I'm not convinced that storing Array<IndexRange> is faster than IndexMask general. Especially since there's a lot of single threaded work going on computing the offsets, etc, it doesn't seem worth the complexity.

I would suggest moving IndexMaskMemory and IndexMask into TransformArrays. Since TransformArrays is becoming more general that way, maybe it should be renamed CurvesTransformData or something.

You're right about that being more different for grease pencil, but to me it seems better to find the optimal solution separately for each case. GP is doing a different thing by combining the data from multiple CurvesGeometry into one container.

Storing the selection for later would really just be an optimization anyway, it can always be recomputed from the current attributes. Anyway, I'm not convinced that storing `Array<IndexRange>` is faster than `IndexMask` general. Especially since there's a lot of single threaded work going on computing the offsets, etc, it doesn't seem worth the complexity. I would suggest moving `IndexMaskMemory` and `IndexMask` into `TransformArrays`. Since `TransformArrays` is becoming more general that way, maybe it should be renamed `CurvesTransformData` or something. You're right about that being more different for grease pencil, but to me it seems better to find the optimal solution separately for each case. GP is doing a different thing by combining the data from multiple `CurvesGeometry` into one container.
Author
Contributor

I don't see to separate GP without two separate curve_populate_trans_data_structs functions.
Current version works for both, also I think it'll be handy for Bezier handles also.

I don't see to separate GP without two separate `curve_populate_trans_data_structs` functions. Current version works for both, also I think it'll be handy for Bezier handles also.
Author
Contributor

No need for to_ranges and Array<int> offsets.

Thanks for suggestion.
I wanted ranges to copy in chunks. I was frightened by fact that many curves with all vertices selected will be copied point by point.
Anyway I think I solved it with IndexMasks.

> No need for `to_ranges` and `Array<int> offsets`. Thanks for suggestion. I wanted ranges to copy in chunks. I was frightened by fact that many curves with all vertices selected will be copied point by point. Anyway I think I solved it with `IndexMask`s.
laurynas marked this conversation as resolved
@ -170,3 +236,2 @@
pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
MutableSpan<float3> positions = curves.positions_for_write();
int64_t position_num = *blender::ed::transform::curves::custom_data_to_point_num(
Member

I think you can remove the blender:: from here

I think you can remove the `blender::` from here
laurynas marked this conversation as resolved
Laurynas Duburas changed title from Transform: support properly transforming implicitly shared curve's positions to WIP: Transform: support properly transforming implicitly shared curve's positions 2024-04-19 14:47:51 +02:00
Laurynas Duburas added 1 commit 2024-04-19 18:03:17 +02:00
Laurynas Duburas added 1 commit 2024-04-20 00:23:50 +02:00
Laurynas Duburas changed title from WIP: Transform: support properly transforming implicitly shared curve's positions to Transform: support properly transforming implicitly shared curve's positions 2024-04-20 00:48:16 +02:00
Laurynas Duburas added 1 commit 2024-04-20 09:07:12 +02:00
Jacques Lucke requested changes 2024-04-22 11:46:06 +02:00
Dismissed
@ -83,0 +87,4 @@
struct CurvesTransformData {
blender::IndexMaskMemory memory;
blender::Vector<blender::IndexMask> selection_by_layer;
blender::Vector<int> layer_offsets;
Member

Add comments for what layer_offsets and positions contain.

Add comments for what `layer_offsets` and `positions` contain.
laurynas marked this conversation as resolved
@ -161,6 +172,12 @@ void curve_populate_trans_data_structs(TransDataContainer &tc,
bool use_connected_only,
int trans_data_offset);
CurvesTransformData *create_curves_custom_data(TransCustomData &custom_data);
Member

These functions are in the global namespace, so they should have a bit more specific names.

These functions are in the global namespace, so they should have a bit more specific names.
laurynas marked this conversation as resolved
@ -65,0 +73,4 @@
transform_data.layer_offsets.append(data_offset + selection.size());
array_utils::gather(
positions,
transform_data.selection_by_layer.last(),
Member

selection

`selection`
laurynas marked this conversation as resolved
Laurynas Duburas added 1 commit 2024-04-22 14:26:28 +02:00
Hans Goudey approved these changes 2024-04-22 15:09:00 +02:00
@ -82,2 +101,3 @@
else {
selection_per_object[i] = ed::curves::retrieve_selected_points(curves, memory);
selection_per_object[i] = ed::curves::retrieve_selected_points(
curves, curves_transform_data->memory);
Member

IndexMaskMemory memory; is unused above

`IndexMaskMemory memory;` is unused above
Laurynas Duburas added 1 commit 2024-04-22 15:13:30 +02:00
Jacques Lucke approved these changes 2024-04-22 17:35:24 +02:00
Jacques Lucke left a comment
Member

LGTM, can you update the patch description a bit?

LGTM, can you update the patch description a bit?
Jacques Lucke merged commit 3d9519544d into main 2024-04-22 20:03:04 +02:00
Laurynas Duburas deleted branch transform-data-copy 2024-04-22 21:17:20 +02: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 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#120824
No description provided.