GPv3: Add access functions for opacity and radius attributes #109733
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109733
Loading…
Reference in New Issue
No description provided.
Delete Branch "amelief/blender:gpv3-attributes-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We need setters and getters for these two very commonly accessed attributes of grease pencil.
The code is based on the implementation of
CurvesGeometry::positions()
andCurvesGeometry::positions_for_write()
.Add getters and setters for opacity and radius of a grease pencil drawingto GPv3 : Add getters and setters for opacity and radius of a grease pencil drawingAlthough, we needed to copy/paste the functions
get_span_attribute
,get_mutable_attribute
,domain_num
,domain_custom_data
that are only defined incurves_geometry.cc
and not visible from the API.Is that ok, or should we make these functions visibles instead ?
Make
domain_num
,domain_custom_data
,domain_custom_data
functions through a switch. This should return 0 for an unsupported domains. Now it will be the size of the curves, which is not always correct.. This may not work correctly if used in conjunction with other attribute components in geometry processing code.Also, make sure you don't use C-cast (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
The radii accessor makes just as much sense on the base
CurvesGeometry
class. We didn't add it yet though because unfortunately different code uses different defaults when the radii don't exist, this hasn't been standardized yet.Maybe you could add an example of before and after?
The following isn't too bad when you get used to it IMO. But I understand the reasoning for avoiding writing it.
const VArray<float> opacity = *attributes.lookup_default<float>("opacity", ATTR_DOMAIN_POINT);
@HooglyBoogly For the radii default value, I'm wondering if it would make sense to have a parameter in the function with a sensible default value. E.g. something like
Span<float> radii(float default_radius = 1.0f) const;
. So you can still just callcurves.radii()
.I'd like to have those function on the drawing, because
opacity
should really be a default attribute. And it's nice to not have to think about how the attribute is spelled, what the default should be etc.The idea behind unifying the radius attribute was that every place shouldn't have to manage its own default. But that is a bit tricky since it may not be intuitive for the curve to mesh node main input, for example. I still think its worth exploring though.
What do you mean by "default attribute"? Makes sense though!
@HooglyBoogly Something that we expect every stroke to have.
That seems a bit vague to me honestly, maybe it can be "expected" but code still has to handle the case where it doesn't exist, in which case the default should probably be 1.0, right? If so, the
opacities()
function should return a single-value virtual array.@HooglyBoogly Ok I see. Yes, we should instead use what
CurvesGeometry
is using now:get_varray_attribute
. And the_for_write()
functions can stay the same I think?GPv3 : Add getters and setters for opacity and radius of a grease pencil drawingto GPv3: Add getters and setters for opacity and radius of a grease pencil drawing@ -79,0 +81,4 @@
/**
* Per-point opacity value
*/
const VArray<float> opacities() const;
Making a return value
const
when it's not a reference or a pointer doesn't have any effect. For example, you can still do this:@ -79,0 +87,4 @@
/**
* Per-point radius value
*/
const VArray<float> radii() const;
Hmm, my point with my comment about radii earlier is that we should wait to add this to
CurvesGeometry
directly when the current inconsistent situation is figured out.Could we refactor that together with when that PR is happening?
Sure, I guess that's fine too
Yes, because we actually need that for the smoothing algorithm and we are gonna need it for further development in the next weeks.
Would you consider using
0.01
for the default radius? That's the "most consistent" with curves, and it probably makes more sense at the scale most people work at anyway.@ -78,1 +79,4 @@
void tag_positions_changed();
/**
* Per-point radius value.
For these high-level doc strings, I'd suggest going beyond the bare minimum of documentation. For example-- "the radius is mainly used to determine the thickness of the stroke when rendering" or "how transparent each point is, also affecting the influence of the blah blah"
If there really is nothing more to add that's less basic, maybe that's fine, but it's nice to help out all future readers of this header file :)
@ -346,1 +381,4 @@
VArray<float> Drawing::radii() const
{
return *strokes().attributes().lookup_or_default<float>(ATTR_RADIUS, ATTR_DOMAIN_POINT, 1.0f);
this->strokes()
Generally class methods are referred to with that prefix.
const int num = domain_num(curves, domain);
->curves.attributes().domain_size(domain)
const int num
->const int domain_size
MutableSpan<T> span = {data, num};
->MutableSpan<T> values(data, num);
T *data = (T *)Cu..
->T *data = static_cast<T *>(Cu
num > 0
really necessary?span.first() != default_value
why might this be so? There after all or garbage, or zeros?template<typename T> static MutableSpan<T> get_mutable_attribute
can be generic?@mod_moder I appreciate the feedback, but it would be nice if you could add these comments to the lines in the diff.
@filedescriptor After issuecomment i'm trying to be more careful in this part
@mod_moder Right, you can use the
Start Review
button instead of adding single comments, to bunch them all up into one.Noted one mistake inline, other than that looks good. Some of Iliya's comments are reasonable too, though I understand this code is a copy & paste so that could be handled separately.
@ -347,0 +386,4 @@
MutableSpan<float> Drawing::radii_for_write()
{
return get_mutable_attribute<float>(this->geometry.wrap(), ATTR_DOMAIN_POINT, ATTR_RADIUS);
specify the default value here too
GPv3: Add getters and setters for opacity and radius of a grease pencil drawingto GPv3: Add access functions for opacity and radius attributes