Curves: Support for draw tool #115864

Merged
Hans Goudey merged 9 commits from laurynas/blender:curves-draw-tool into main 2023-12-11 19:44:28 +01:00
Contributor

Adds new curves support to "Draw Curve" operator.

Adds new curves support to "Draw Curve" operator. <video src="/attachments/46bf9c8c-3d29-4acd-a9d7-7d0156ccd32c" title="drawing-demo.mov" controls></video>
Laurynas Duburas added 1 commit 2023-12-06 23:45:05 +01:00
dd800b2307 Curves: Support for draw tool
Adds new curves support to Draw Curve operator
Laurynas Duburas requested review from Hans Goudey 2023-12-06 23:45:47 +01:00
Hans Goudey requested changes 2023-12-07 03:36:43 +01:00
Hans Goudey left a comment
Member

Thanks for working on this! I think people will really appreciate being able to use this operator for the new type. Overall I'd recommend focusing on separating the new and the old code more. It should be very easy to delete the old code when we remove the old object type. Concretely, that means:

  • Put the new code in the editors/curves/ folder in a new file
  • Add a new operator type
  • Don't worry at all about code duplication. That will be temporary anyway
  • Seems fine to use the same tool settings though.
  • Only use the code structure of the old operator if it's helpful to get this working. (that's where personal preference might come in)
Thanks for working on this! I think people will really appreciate being able to use this operator for the new type. Overall I'd recommend focusing on separating the new and the old code more. It should be very easy to delete the old code when we remove the old object type. Concretely, that means: - Put the new code in the `editors/curves/` folder in a new file - Add a new operator type - Don't worry at all about code duplication. That will be temporary anyway - Seems fine to use the same tool settings though. - Only use the code structure of the old operator if it's helpful to get this working. (that's where personal preference might come in)
Author
Contributor

That code duplication vs old code separation thing and was main reason to show you. I started to work in a separate operator and felt bad copying everything and decided to alter existing.
It will be easy to switch back, also couple of issues will fall off.

That code duplication vs old code separation thing and was main reason to show you. I started to work in a separate operator and felt bad copying everything and decided to alter existing. It will be easy to switch back, also couple of issues will fall off.
Laurynas Duburas added 1 commit 2023-12-07 20:52:12 +01:00
Author
Contributor
  1. What to do with curve_bevel_radius()?
    In legacy it is taken from Geometry>Bevel>Depth field and in operator adds thickness to preview while drawing
    preview.png.
    New curves do not have such concept and in this context it is not know if curve will have thickness.
    I'm thinking to add some small value for user to feel pen pressure change (maybe only with "Use Pressure" checked).

  2. What to do with is_curve_2d()? Again it doesn't exist in new curves. Maybe an option in operator panel?

  3. Does curves.resize(..) invalidate MutableSpans obtained with:

      MutableSpan<float3> handle_positions_l = curves.handle_positions_left_for_write();
      MutableSpan<float3> handle_positions_r = curves.handle_positions_right_for_write();
      MutableSpan<int8_t> handle_types_l = curves.handle_types_left_for_write();
      MutableSpan<int8_t> handle_types_r = curves.handle_types_right_for_write();
      MutableSpan<bool> cyclic = curves.cyclic_for_write();
      MutableSpan<int> resolution = curves.resolution_for_write();

I'd like to move resize(..) below curve.*_for_write();

  1. Can auto be used? For ex. auto resolution = curves.resolution_for_write(); vs. MutableSpan<int> resolution = curves.resolution_for_write();
1. What to do with `curve_bevel_radius()`? In legacy it is taken from Geometry>Bevel>Depth field and in operator adds thickness to preview while drawing ![preview.png](/attachments/4245b658-da55-47cc-abcd-6cf03526d5a8). New curves do not have such concept and in this context it is not know if curve will have thickness. I'm thinking to add some small value for user to feel pen pressure change (maybe only with "Use Pressure" checked). 2. What to do with `is_curve_2d()`? Again it doesn't exist in new curves. Maybe an option in operator panel? 3. Does `curves.resize(..)` invalidate `MutableSpans` obtained with: ``` MutableSpan<float3> handle_positions_l = curves.handle_positions_left_for_write(); MutableSpan<float3> handle_positions_r = curves.handle_positions_right_for_write(); MutableSpan<int8_t> handle_types_l = curves.handle_types_left_for_write(); MutableSpan<int8_t> handle_types_r = curves.handle_types_right_for_write(); MutableSpan<bool> cyclic = curves.cyclic_for_write(); MutableSpan<int> resolution = curves.resolution_for_write(); ``` I'd like to move `resize(..)` below `curve.*_for_write()`; 4. Can auto be used? For ex. `auto resolution = curves.resolution_for_write();` vs. ` MutableSpan<int> resolution = curves.resolution_for_write();`
Member

What to do with curve_bevel_radius()?

The radius is generally stored in the radius attribute-- there's no additional factor stored on the whole data-block. So yeah, there's nowhere to get this value from. Maybe a new operator property would work fine ("Radius" in distance units).

What to do with is_curve_2d()? Again it doesn't exist in new curves. Maybe an option in operator panel?

Same situation here I suppose, so yeah, an operator property makes sense.

Does curves.resize(..) invalidate MutableSpans obtained with:

Indeed it does, the spans should be retrieved after changing the size of the curves.

Can auto be used?

The cases we do use it are when it's required by template meta-programming and when it's redundant with a cast like const auto &value = static_cast<SomeType &>(data);. The types are helpful to the reader, so otherwise it isn't used.

> What to do with curve_bevel_radius()? The radius is generally stored in the `radius` attribute-- there's no additional factor stored on the whole data-block. So yeah, there's nowhere to get this value from. Maybe a new operator property would work fine ("Radius" in distance units). > What to do with is_curve_2d()? Again it doesn't exist in new curves. Maybe an option in operator panel? Same situation here I suppose, so yeah, an operator property makes sense. > Does curves.resize(..) invalidate MutableSpans obtained with: Indeed it does, the spans should be retrieved after changing the size of the curves. > Can auto be used? The cases we do use it are when it's required by template meta-programming and when it's redundant with a cast like `const auto &value = static_cast<SomeType &>(data);`. The types are helpful to the reader, so otherwise it isn't used.
Laurynas Duburas added 2 commits 2023-12-08 22:04:09 +01:00
Laurynas Duburas requested review from Hans Goudey 2023-12-08 22:05:33 +01:00
Hans Goudey reviewed 2023-12-09 00:07:17 +01:00
Hans Goudey left a comment
Member

Works pretty well in my tests. I'd suggest just calling the radius "Radius" for RNA and in the UI. It should be written to the curve points too (multiplied with the pressure factor).

Works pretty well in my tests. I'd suggest just calling the radius "Radius" for RNA and in the UI. It should be written to the curve points too (multiplied with the pressure factor).
@ -0,0 +1,1211 @@
#include "DNA_curve_types.h"
Member

Missing license header:

/* SPDX-FileCopyrightText: 2023 Blender Authors
 *
 * SPDX-License-Identifier: GPL-2.0-or-later */
Missing license header: ``` /* SPDX-FileCopyrightText: 2023 Blender Authors * * SPDX-License-Identifier: GPL-2.0-or-later */ ```
laurynas marked this conversation as resolved
@ -0,0 +618,4 @@
static int curves_draw_exec(bContext *C, wmOperator *op)
{
using namespace bke;
Member

Typically we'd avoid this sort of using namespace; Seeing the namespace in the code makes it clear where the types and functions come from (it replaces the BKE_ prefix from the C code.)

Typically we'd avoid this sort of `using namespace;` Seeing the namespace in the code makes it clear where the types and functions come from (it replaces the `BKE_` prefix from the C code.)
laurynas marked this conversation as resolved
@ -0,0 +650,4 @@
const float radius_range = cps->radius_max - cps->radius_min;
Curves *curves_id = static_cast<Curves *>(obedit->data);
blender::bke::CurvesGeometry &curves = curves_id->geometry.wrap();
Member

blender:: unnecessary here

`blender::` unnecessary here
laurynas marked this conversation as resolved
@ -0,0 +771,4 @@
MutableSpan<int> resolution = curves.resolution_for_write();
resolution[curve_index] = 12;
IndexRange points_of_curve = curves.points_by_curve()[curve_index];
Member

How about this naming, which is hopefully a bit more typical:

const IndexRange new_points = curves.points_by_curve()[curve_index];
How about this naming, which is hopefully a bit more typical: ``` const IndexRange new_points = curves.points_by_curve()[curve_index];
laurynas marked this conversation as resolved
@ -0,0 +777,4 @@
MutableAttributeAccessor curves_attributes = curves.attributes_for_write();
SpanAttributeWriter<float> radius_attribute =
curves_attributes.lookup_or_add_for_write_only_span<float>("radius", ATTR_DOMAIN_POINT);
SpanAttributeWriter<bool> selection_attribute =
Member

For the selection, we should support when it is stored as a float too. There are a few utility methods to help with that:

fill_selection_false can be called before the resize
fill_selection_true can be called with the new points

The curve domain should also be supported though, so I'd recommend something things like this:

bke::GSpanAttributeWriter selection = ensure_selection_attribute(
        curves, selection_domain, CD_PROP_BOOL);
fill_selection_true(selection.span, selection.domain == ATTR_DOMAIN_POINT ? new_points : IndexRange(curve_index,1));
For the selection, we should support when it is stored as a float too. There are a few utility methods to help with that: `fill_selection_false` can be called before the resize `fill_selection_true` can be called with the new points The curve domain should also be supported though, so I'd recommend something things like this: ```cpp bke::GSpanAttributeWriter selection = ensure_selection_attribute( curves, selection_domain, CD_PROP_BOOL); fill_selection_true(selection.span, selection.domain == ATTR_DOMAIN_POINT ? new_points : IndexRange(curve_index,1));
laurynas marked this conversation as resolved
@ -0,0 +818,4 @@
}
for (const auto i : IndexRange(i_start, i_end - i_start)) {
const int64_t corner_i = points_of_curve[corners_index[i]];
Member
/home/hans/blender-git/blender/source/blender/editors/curves/intern/curves_draw.cc: In function ‘int blender::ed::curves::curves_draw_exec(bContext*, wmOperator*)’:
/home/hans/blender-git/blender/source/blender/editors/curves/intern/curves_draw.cc:820:25: warning: unused variable ‘corner_i’ [-Wunused-variable]
  820 |           const int64_t corner_i = points_of_curve[corners_index[i]];
      |                         ^~~~~~~~
``` /home/hans/blender-git/blender/source/blender/editors/curves/intern/curves_draw.cc: In function ‘int blender::ed::curves::curves_draw_exec(bContext*, wmOperator*)’: /home/hans/blender-git/blender/source/blender/editors/curves/intern/curves_draw.cc:820:25: warning: unused variable ‘corner_i’ [-Wunused-variable] 820 | const int64_t corner_i = points_of_curve[corners_index[i]]; | ^~~~~~~~
laurynas marked this conversation as resolved
@ -0,0 +1149,4 @@
return ret;
}
bool editable_curves_in_edit_mode_poll(bContext *C);
Member

This declaration shouldn't be necessary here

This declaration shouldn't be necessary here
laurynas marked this conversation as resolved
@ -0,0 +1153,4 @@
void CURVES_OT_draw(wmOperatorType *ot)
{
using namespace blender::ed::curves;
Member

Should be unnecessary, since this is already in that namespace

Should be unnecessary, since this is already in that namespace
laurynas marked this conversation as resolved
@ -0,0 +1156,4 @@
using namespace blender::ed::curves;
ot->name = "Draw Curves";
ot->idname = __func__;
ot->description = "Draw a freehand spline";
Member

spline -> curve here, just for an attempt at consistency with the new type

`spline` -> `curve` here, just for an attempt at consistency with the new type
laurynas marked this conversation as resolved
@ -1244,6 +1244,8 @@ static void CURVES_OT_delete(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
void CURVES_OT_draw(wmOperatorType *ot);
Member

This declaration should be moved to ED_curves.hh

This declaration should be moved to `ED_curves.hh`
laurynas marked this conversation as resolved
Author
Contributor

Works pretty well in my tests. I'd suggest just calling the radius "Radius" for RNA and in the UI. It should be written to the curve points too (multiplied with the pressure factor).

If it is "Radius" then it is redundant as there are two radii already: "Radius Min" and "Max". "Max" would do the work. Why to have "Max" and then multiply it by some other, instead of writing final value directly into "Max". This "Preview Radius" (formerly "Bevel Radius") is leftover from legacy curves operator. In previous version "Bevel Radius" was curves attribute and in draw operator it was handy to preview final result. Though it was used in final geometry calculations, but it was happening outside the operator.

Now user could input some value close to profile size from latter stages and have some clue of final result while drawing.

Also if to remove it I hardly imagine preview implementation. For ex. if user set radii range from 0.0 to 1.0, with intention max value will mean original profile curve size. Draw operator knows nothing about profile and can't do decent preview. Here comes "Preview Radius".

What I don't like is the label I gave "Pvw Radius", but full didn't fit in UI.

Agree with all other comments, fixed them already.

> Works pretty well in my tests. I'd suggest just calling the radius "Radius" for RNA and in the UI. It should be written to the curve points too (multiplied with the pressure factor). If it is "Radius" then it is redundant as there are two radii already: "Radius Min" and "Max". "Max" would do the work. Why to have "Max" and then multiply it by some other, instead of writing final value directly into "Max". This "Preview Radius" (formerly "Bevel Radius") is leftover from legacy curves operator. In previous version "Bevel Radius" was curves attribute and in draw operator it was handy to preview final result. Though it was used in final geometry calculations, but it was happening outside the operator. Now user could input some value close to profile size from latter stages and have some clue of final result while drawing. Also if to remove it I hardly imagine preview implementation. For ex. if user set radii range from 0.0 to 1.0, with intention max value will mean original profile curve size. Draw operator knows nothing about profile and can't do decent preview. Here comes "Preview Radius". What I don't like is the label I gave "Pvw Radius", but full didn't fit in UI. Agree with all other comments, fixed them already.
Laurynas Duburas added 1 commit 2023-12-09 20:50:52 +01:00
Member

Hmm. I still think we should use this new property to determine the preview radius and the final radius. It's nice not to have a separate preview and final radius option. For now I think we can just imagine that the curves either don't have a separate profile with a different radius, or that the profile's radius is 1.0. The "Radius Min/Max" properties are more like a scaling factor for tapering.

When the curves are able to be rendered properly with radius in the viewport (like they are with Cycles now, sort of), this will probably make more sense.

Hmm. I still think we should use this new property to determine the preview radius and the final radius. It's nice not to have a separate preview and final radius option. For now I think we can just imagine that the curves either don't have a separate profile with a different radius, or that the profile's radius is 1.0. The "Radius Min/Max" properties are more like a scaling factor for tapering. When the curves are able to be rendered properly with radius in the viewport (like they are with Cycles now, sort of), this will probably make more sense.
Author
Contributor

For me separate preview option is also a compromise. Other two options I see to hide it from UI and hardcode value 0.1 or 0.0(no black line preview).

Could you try to play around with this file.? To draw curve in this branch with "Preview" 1.0. Current code doesn't take "Preview" into final result, but value 1.0 wouldn't change anything. Result is correct, but preview hardly.
Then say exactly what to do. I don't want to get stuck on this.

For me separate preview option is also a compromise. Other two options I see to hide it from UI and hardcode value 0.1 or 0.0(no black line preview). Could you try to play around with this file.? To draw curve in this branch with "Preview" 1.0. Current code doesn't take "Preview" into final result, but value 1.0 wouldn't change anything. Result is correct, but preview hardly. Then say exactly what to do. I don't want to get stuck on this.
Member

Thanks for the example file. I think we should just accept the results will be weird if the profile has non-unit size. The preview is still helpful though. So let's not add a new radius property to the operator, and just use the min and max radius properties directly for the preview. The legacy curve "Bevel Depth" property will basically just be 1.0 now.

Thanks for the example file. I think we should just accept the results will be weird if the profile has non-unit size. The preview is still helpful though. So let's not add a new radius property to the operator, and just use the min and max radius properties directly for the preview. The legacy curve "Bevel Depth" property will basically just be 1.0 now.
Laurynas Duburas added 1 commit 2023-12-11 18:25:26 +01:00
Author
Contributor

At last I understand how you saw things :)
I only played with this small profile.

Done

At last I understand how you saw things :) I only played with this small profile. Done
Member

Great! If you consider the PR finished, could you merge main into the branch and remove the WIP tag? I'll look into review later today then, and hopefully commit this.

Great! If you consider the PR finished, could you merge main into the branch and remove the WIP tag? I'll look into review later today then, and hopefully commit this.
Laurynas Duburas added 1 commit 2023-12-11 18:48:35 +01:00
Laurynas Duburas changed title from WIP: Curves: Support for draw tool to Curves: Support for draw tool 2023-12-11 18:49:00 +01:00
Hans Goudey added 1 commit 2023-12-11 19:19:06 +01:00
Hans Goudey approved these changes 2023-12-11 19:37:18 +01:00
Hans Goudey added 1 commit 2023-12-11 19:41:29 +01:00
Hans Goudey merged commit feae0b4173 into main 2023-12-11 19:44:28 +01:00
Laurynas Duburas deleted branch curves-draw-tool 2023-12-11 20:41:45 +01: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
2 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#115864
No description provided.