WIP: Sculpt: cleanup sculpt attribute API #106920
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#106920
Loading…
Reference in New Issue
No description provided.
Delete Branch "temp-sculpt-attr-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?
This PR cleans up the sculpt attribute API a bit to make greater use of C++ templates.
BKE_sculpt_vertex_attr_get
(and it's aliasSCULPT_vertex_attr_get
)is now
blender::bke::paint::vertex_attr_ptr
. Same for the faceversions of those functions. The SCULPT_XXX aliases are removed.
[vertex/face]_attr_ptr
are now implemented viaa generic template (
elem_attr_ptr
).[vertex/face]_attr_get
and[vertex/face]_attr_set
functionsto get/set attribute data without pointer wrangling.
blender::bke::paint::
it's recommendedto do a
using blender::bke::paint;
at the top of sculpt files.Example:
float w = vertex_attr_get<float>(vertex, ss->attrs.automasking_factor);
In isolation, this is a nice cleanup, so I think with a few changes this PR makes sense.
However, I'm generally skeptical about making an API that processes a single element at a time.
For example, these functions take a single
PBVHVertRef
, abstract away the PBVH type, and return a value.Given enough templating, some of these branches can be removed, but at the cost of templates being required everywhere and generating a lot of code. A different API might be one that processes spans of indices/bmesh pointers, and values, only abstracting away the PBVH type at the node level. That makes it easier to specialize the implementation for certain types, aligns more generally with methods of removing constant checks from hot loops, and avoids the downsides of one PBVH implementation leaking into another.
That's a fairly general comment about the design of C++ usage in the sculpt/paint area though, so maybe it's better to have that conversion elsewhere.
Generally adding
using namespace
at the top of files is discouraged since it makes it more difficult to see where code is coming from and makes name conflict resolution harder. I think the best solution here is to move entire files to the proper namespace when that becomes possible. Thenblender::
will be unnecessary everywhere, andbke::
and::paint
will often become unnecessary too.@ -946,0 +907,4 @@
/* Base implementation for vertex_attr_*** and face_attr_*** methods.
* Returns a pointer to the attribute data (as defined by attr) for elem.
*/
template<typename Tptr, typename ElemRef = PBVHVertRef>
I think it might be clearer to avoid
Tptr
and just useT *
in the code below.@ -946,0 +910,4 @@
template<typename Tptr, typename ElemRef = PBVHVertRef>
static Tptr elem_attr_ptr(const ElemRef elem, const SculptAttribute *attr)
{
void *ptr = nullptr;
Could avoid the temporary variable here and return the pointer inside the if statement.
@ -946,0 +937,4 @@
* Example: float *persistent_co = vertex_attr_ptr<float*>(vertex, ss->attrs.persistent_co);
*/
template<typename Tptr>
static Tptr vertex_attr_ptr(const PBVHVertRef vertex, const SculptAttribute *attr)
I think exposing the pointer where a value is stored might not work well with different attribute storage methods in the future, and exposes the internal of the system a bit more than necessary. (For example, virtual arrays don't provide that ability, not that we would use them here exactly). The alternative is using a
get
/set
combo when that's actually necessary.@ -268,3 +269,3 @@
if (stroke_id != automasking->current_stroke_id) {
f = *(char *)SCULPT_vertex_attr_get(
f = *vertex_attr_ptr<char *>(
Can this use
vertex_attr_get
instead of*vertex_attr_ptr
?Same with a few places below.
I do in fact plan to use templates pretty much everywhere in the sculpt code. The node span approach is basically how the
PBVHVertIter
works, but there are times when you really do need an element-wise API. I think it's hard to avoid templates if you want clearly written, polymorphic code that can be plugged into very different implementing back-ends.If you think about it there's a trade off between code clarity, compiled code generation size and runtime performance. You can only optimize two of those three.
Pull request closed