Commit Graph

4430 Commits

Author SHA1 Message Date
Falk David 44e2681459 Fix: GPv3: Drawing tool didn't initialize all attributes
Attributes that were not immediatly written to after the `curves.resize(...)` did not get initialized to default values in the new stroke.

Pull Request: https://projects.blender.org/blender/blender/pulls/114005
2023-10-21 17:33:53 +02:00
Hans Goudey 89e3ba4e25 Mesh: Replace auto smooth with node group
Design task: #93551

This PR replaces the auto smooth option with a geometry nodes modifier
that sets the sharp edge attribute. This solves a fair number of long-
standing problems related to auto smooth, simplifies the process of
normal computation, and allows Blender to automatically choose between
face, vertex, and face corner normals based on the sharp edge and face
attributes.

Versioning adds a geometry node group to objects with meshes that had
auto-smooth enabled. The modifier can be applied, which also improves
performance.

Auto smooth is now unnecessary to get a combination of sharp and smooth
edges. In general workflows are changed a bit. Separate procedural and
destructive workflows are available. Custom normals can be used
immediately without turning on the removed auto smooth option.

**Procedural**

The node group asset "Smooth by Angle" is the main way to set sharp
normals based on the edge angle. It can be accessed directly in the add
modifier menu. Of course the modifier can be reordered, muted, or
applied like any other, or changed internally like any geometry nodes
modifier.

**Destructive**
Often the sharp edges don't need to be dynamic. This can give better
performance since edge angles don't need to be recalculated. In edit
mode the two operators "Select Sharp Edges" and "Mark Sharp" can be
used. In other modes, the "Shade Smooth by Angle" controls the edge
sharpness directly.

### Breaking API Changes
- `use_auto_smooth` is removed. Face corner normals are now used
  automatically   if there are mixed smooth vs. not smooth tags. Meshes
  now always use custom normals if they exist.
- In Cycles, the lack of the separate auto smooth state makes normals look
  triangulated when all faces are shaded smooth.
- `auto_smooth_angle` is removed. Replaced by a modifier (or operator)
  controlling the sharp edge attribute. This means the mesh itself
  (without an object) doesn't know anything about automatically smoothing
  by angle anymore.
- `create_normals_split`, `calc_normals_split`, and `free_normals_split`
  are removed, and are replaced by the simpler `Mesh.corner_normals`
  collection property. Since it gives access to the normals cache, it
  is automatically updated when relevant data changes.

Addons are updated here: https://projects.blender.org/blender/blender-addons/pulls/104609

### Tests
- `geo_node_curves_test_deform_curves_on_surface` has slightly different
   results because face corner normals are used instead of interpolated
   vertex normals.
- `bf_wavefront_obj_tests` has different export results for one file
  which mixed sharp and smooth faces without turning on auto smooth.
- `cycles_mesh_cpu` has one object which is completely flat shaded.
  Previously every edge was split before rendering, now it looks triangulated.

Pull Request: https://projects.blender.org/blender/blender/pulls/108014
2023-10-20 16:54:08 +02:00
Philipp Oeser 83c64c1b60 Merge branch 'blender-v4.0-release' 2023-10-20 14:21:53 +02:00
Philipp Oeser eed4f950d8 Fix #113798: Weight paint gradient tool paints over hidden vertices
Note 0a0a29887d / 4c99043a85 were supposed to fix this.
This was mostly working, but verts could still obtain wrong weights
(most notably "outside" the gradient range).

Code from above commits would correctly skip hidden verts in
`gradientVertUpdate__mapFunc`.
However, `gradientVertInit__mapFunc` (called prior) already does
`gradientVert_update` once [not entirely sure why it does this, but
wouldnt want to remove the call there due to unforseen behavioral
changes] and we dont early out there.

So now move the check for hidden verts from
`gradientVertUpdate__mapFunc` to `gradientVertInit__mapFunc` and early
out (also saves us from doing other unneccessary stuff there).

Pull Request: https://projects.blender.org/blender/blender/pulls/113825
2023-10-20 14:21:23 +02:00
Philipp Oeser 17a950f570 Merge branch 'blender-v4.0-release' 2023-10-20 14:15:30 +02:00
Philipp Oeser 3cb659faa8 Fix #107920: Weight gradient tool auto normalizes over locked groups
Locking wasnt respected, now use `BKE_defvert_normalize_lock_map`
instead (and only use `BKE_defvert_normalize_lock_single` in case no
groups are locked).

Pull Request: https://projects.blender.org/blender/blender/pulls/113853
2023-10-20 14:14:49 +02:00
Sergey Sharybin 85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Hans Goudey 1cbd0f5a85 Refactor: Improve access to object data bounds
Currently object bounds (`object.runtime.bb`) are lazily initialized
when accessed. This access happens from arbitrary threads, and
is unprotected by a mutex. This can cause access to stale data at
best, and crashes at worst. Eager calculation is meant to keep this
working, but it's fragile.

Since e8f4010611, geometry bounds are cached in the geometry
itself, which makes this object-level cache redundant. So, it's clearer
to build the  `BoundBox` from those cached bounds and return it by
value, without interacting with the object's cached bounding box.

The code change is is mostly a move from `const BoundBox *` to
`std::optional<BoundBox>`. This is only one step of a larger change
described in #96968. Followup steps would include switching to
a simpler and smaller `Bounds` type, removing redundant object-
level access, and eventually removing `object.runtime.bb`.

Access of bounds from the object for mesh, curves, and point cloud
objects should now be thread-safe. Other object types still lazily
initialize the object `BoundBox` cache since they don't have
a data-level cache.

Pull Request: https://projects.blender.org/blender/blender/pulls/113465
2023-10-19 14:18:40 +02:00
Hans Goudey 40080f618c Sculpt: Use C++ Set to store PBVH Node BMesh elements
Mainly to simplify code and also add some add type safety, replace
`GSet` with `blender::Set` for the storage of BMesh triangles and
vertices on each PBVH node. Some initial tests point to better
performance too, but the numbers are hard to verify so far.

Because of the larger `PBVHNode`, memory usage slightly increases
(observed a 2% increase with a 1M face grid) for regular Mesh sculpting,
but it seems `Set` is more memory efficient than `GSet`, because I also
observed a 10% decrease in memory usage for dynamic topology.
In the future nodes can be split in a more data-oriented fashion to
reduce memory usage overall.

This also makes it simpler to switch to another type in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/113907
2023-10-19 14:18:15 +02:00
Campbell Barton e7e4e63313 Cleanup: spelling in comments, white-space in comments 2023-10-19 18:53:16 +11:00
Campbell Barton 6ed3b4a5a6 Cleanup: format, quiet unused argument warning 2023-10-18 22:09:27 +11:00
Falk David 48e60dcbff Fix: GPv3: Compile error 2023-10-17 17:13:13 +02:00
Falk David 07749b389d GPv3: Convert radius to blender units
Previously, Grease Pencil used a radius convention where
1 "px" = 0.001 units. This "px" was the brush size which would be
stored in the stroke thickness and then scaled by the point pressure
factor. Finally, the render engine would divide this thickness value by
2000 (we're going from a thickness to a radius, hence the factor of
two) to convert back into blender units.

Store the radius now directly in blender units. This makes it
consistent with how hair curves handle the radius.

* Removes the scaling in the render engine.
* Makes sure the grease pencil primitives use the correct radii
* Changes the drawing tool to work with screen space radius
* Draws the drawing tool cursor in screen space
* Makes sure the scaling is done when converting from legacy
grease pencil objects
* Makes sure the scaling is done when loading previous files

Consequences for the draw tool:
* Since the tool has a radius input in pixels, it now works in screen space. This is a pretty big change to how it works by default before, so a new option will have to be added that allows the brush to be in "Scene" space. This is similar to how it works in sculpt mode. But this is a bigger change, so I would like to split that into a separate PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/113770
2023-10-17 17:00:35 +02:00
Jeroen Bakker da2e951512 Cleanup: Make format 2023-10-17 12:45:19 +02:00
Falk David b164ce0cbf Refactor: Return `ViewContext` by value
This makes `ED_view3d_viewcontext_init` return the `ViewContext` by value instead of writing to a pointer.
No functional changes expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/113761
2023-10-17 10:34:59 +02:00
Campbell Barton 2e0b844b36 Cleanup: spelling in comments 2023-10-14 13:53:00 +11:00
Hans Goudey 3e81f66998 Cleanup: Use C++ arrays for SculptUndoNode
Significantly reduce the amount of manual memory management by
replacing owning pointers with `blender::Array`. This also simplifies
counting the size of the undo steps and iterating over the array values
in some cases.
2023-10-13 09:44:35 +02:00
Christoph Lendenfeld 1f995917a9 Refactor: Replace autokey macros with functions
No functional changes

The following macros have been replaced with identically named functions
* IS_AUTOKEY_ON
* IS_AUTOKEY_MODE
* IS_AUTOKEY_FLAG

Pull Request: https://projects.blender.org/blender/blender/pulls/113610
2023-10-12 16:20:18 +02:00
Christoph Lendenfeld a3831fe7af Refactor: Move autokeyframing functions to animrig
No functional changes

The following functions have been moved
`autokeyframe_cfra_can_key`
`autokeyframe_object`
`ED_autokeyframe_object`
`ED_autokeyframe_pchan`
`ED_autokeyframe_property`

they are all in a new file
keyframing_auto.cc
while the declarations are in
ANIM_keyframing.cc

The autokeyframe makros also have been moved

Pull Request: https://projects.blender.org/blender/blender/pulls/113607
2023-10-12 15:44:58 +02:00
Falk David 49b21eba11 GPv3: Support crazyspace in selection code
This adds `GreasePencilEditHints` and correctly implements
`crazyspace::get_evaluated_grease_pencil_drawing_deformation`
to support querying the deformation of points after evaluation.
This is needed for users to properly select points in edit mode while
seeing the effects of the modifiers.

Pull Request: https://projects.blender.org/blender/blender/pulls/113586
2023-10-12 15:42:04 +02:00
Hans Goudey 9ab290e1b3 Cleanup: Simplify sculpt faces mask undo loop
This is already separated per PBVH type, we can make use of that
to simplify the loops for the types with the aim of sharing code in
a simpler and more performance-friendly way. Ideally this could
be written as `array_utils::scatter`, but we don't have that utility
function now, so just write the raw loop for now.
2023-10-12 14:51:51 +02:00
Hans Goudey cbb4ae80ba Cleanup: Return PBVH node vertex indices with span instead of pointer 2023-10-12 14:29:34 +02:00
Philipp Oeser 54f326e951 Merge branch 'blender-v4.0-release' 2023-10-11 13:36:18 +02:00
Philipp Oeser 40ea1cdb97 Fix #113323: Paint Secondary color not working in the Image Editor
Caused by c30d6571bb .

Above commit only updated the `BrushPainterCache` `invert` only when the
requirements for a float imbuf changed.
This however always needs to be updated.

Pull Request: https://projects.blender.org/blender/blender/pulls/113334
2023-10-11 13:35:36 +02:00
Falk David 4e05da2648 Fix: GPv3: Crash when drawing new stroke
The crash was happening because the storage buffer for active smoothing
was not resized correctly as the active smoothing window changed.

This fix makes sure the storage buffer is resized correctly.
2023-10-11 12:20:21 +02:00
Falk David 559c271a53 Clang-format 2023-10-10 16:59:56 +02:00
Falk David fa2a05ef86 Fix: GPv3 sometimes crashes when drawing
This was because the size and bounds of points were not properly
checked in some places.
Additionally, the smoothing algorithm should only be run if the
smoothing window is larg enough.
2023-10-10 16:22:25 +02:00
Falk David cf2ea5979c Fix: GPv3 draw tool sometimes draws a cyclic curve
The issue was that the drawing tool did not write to the "cyclic" attribute.

Resolves #113423.

Pull Request: https://projects.blender.org/blender/blender/pulls/113500
2023-10-10 16:15:43 +02:00
Hans Goudey 8f27baf388 Merge branch 'blender-v4.0-release' 2023-10-09 23:54:43 +02:00
Hans Goudey 976eaae02f Cleanup: Move BKE_object.hh to C++
Simplifies the fix to #111120, where the object bounds functions
may return a C++ type instead of `BoundBox`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113462
2023-10-09 23:41:53 +02:00
Pratik Borhade f37a8cda30 GPv3: Insert keyframe when drawing if no key exists at current frame
Code to insert new keyframe when drawing is included in
7e87435cf4 . But current condition fails
to add new frame. In `frame_key_at()`, last drawing or the next drawing is
returned (instead of -1). Hence, no new drawing/frame was added in draw-invoke
function.
So add keyframe if no keyframe exists already at `current_number`

Pull Request: https://projects.blender.org/blender/blender/pulls/113408
2023-10-09 12:54:42 +02:00
Falk David e7e1ec55d2 GPv3: Add `DrawingTransforms`
This makes sure that when the object is transformed, the painting code will take that
transformation into account.

Resolves #113424.

Pull Request: https://projects.blender.org/blender/blender/pulls/113442
2023-10-09 12:42:01 +02:00
Sergey Sharybin 12e9894a75 Sculpt: Improve support of face sets with dyntopo
Two aspects to this change:

- Do not clear face sets when enabling dynamic topology
- Draw face sets in viewport when dynamic topology is enabled

Newly added faces in the dynamic topology will have face
sets properly assigned. It is only edge collapse which can
potentially lead to undesired results w.r.t face set boundaries.
That will be worked on further as follow up development.

Pull Request: https://projects.blender.org/blender/blender/pulls/113348
2023-10-06 15:42:22 +02:00
Falk David 7e87435cf4 GPv3: Initial drawing tool
This PR implements an initial drawing tool that can already be used for testing.
While this is not fully feature complete (compared to the current grease pencil draw tool) the following is already implemented:

* Pressure support for radius and opacity.
* Material color and vertex color support.
* New active smoothing algorithm based on curve fitting.
* Simplify algorithm as a post-process step.

Some deliberate limitations include:
* The drawing plane is always the front plane. Drawing on surfaces is also not supported.
*

The current approach has not been optimized for performance yet. The goal was to have a straightforward implementation
first and then focus on performance later.

There are numerous parameters in the code that are hard-coded for now. These should be exposed at some point, potentially as user settings.

Pull Request: https://projects.blender.org/blender/blender/pulls/110093
2023-10-06 10:49:54 +02:00
Germano Cavalcante 99a3a4a330 Cleanup: Move select engine headers to C++
See #103343

tmp
2023-10-04 14:34:12 -03:00
Hans Goudey 4bc2ff71af Merge branch 'blender-v4.0-release' 2023-10-02 17:37:34 -04:00
Hans Goudey 85580c5835 Fix #113142: Sculpt fairing operators don't update normals
Tagging the PBVH nodes isn't enough, each vertex has to be tagged too.
2023-10-02 17:36:44 -04:00
Germano Cavalcante 90ec11b823 Revert "3D View: Do not recalculate the depth buffer for 'Auto Depth'"
This reverts commit d33eb78de3 and c26efccf61

They came in without a review.
2023-09-29 17:55:50 -03:00
Germano Cavalcante d33eb78de3 3D View: Do not recalculate the depth buffer for 'Auto Depth'
This is a solution to avoid redrawing the depth buffer for each Zoom
with `Auto Depth`.

The solution is to move the `ED_view3d_depth_override` function out of
`ED_view3d_autodist`.

`ED_view3d_depth_override` is now only called for navigation operations
if it does not meet the following condition:

```
    bool has_depth_buffer = !(v3d->flag2 & V3D_HIDE_OVERLAYS) ||
                            ELEM(v3d->shading.type, OB_SOLID, OB_MATERIAL) ||
                            XRAY_FLAG_ENABLED(v3d) ||
                            v3d->shading.type == OB_RENDER &&
                                (strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
                                        RE_engine_id_BLENDER_EEVEE) == 0 ||
                                 strcmp(DEG_get_evaluated_scene(depsgraph)->r.engine,
                                        RE_engine_id_BLENDER_WORKBENCH) == 0);
```
2023-09-28 13:30:14 -03:00
Hans Goudey 9e5cf73b4d Cleanup: Make PBVH iter mask not a pointer
After 97f2b01ea9, the iterator's mask data is just read only,
so there's no point in storing it as a pointer. This simplifies the code
using the mask data, since the default only needs to be handled once.
2023-09-27 18:21:36 -04:00
Hans Goudey 8e188ed55b Fix #112817: Nodes incorrectly "fully masked" after expand face sets
The expand operator reused `SCULPT_UPDATE_MASK` even when it
changed face sets, not the mask. That triggered incorrect behavior in
`node_update_mask_redraw` when there was no mask layer, which caused
nodes to be incorrectly marked as fully masked (and therefore optimized
out of later operations).
2023-09-27 17:11:35 -04:00
Hans Goudey ca447ef542 Cleanup: Move sculpt mask update to a separate function
There's no reason to use a general "update vertex data" function,
that just confuses things.
2023-09-27 17:11:28 -04:00
Hans Goudey 406de58674 Fix #112817: Nodes incorrectly "fully masked" after expand face sets
The expand operator reused `SCULPT_UPDATE_MASK` even when it
changed face sets, not the mask. That triggered incorrect behavior in
`node_update_mask_redraw` when there was no mask layer, which caused
nodes to be incorrectly marked as fully masked (and therefore optimized
out of later operations).
2023-09-27 17:10:24 -04:00
Hans Goudey a3698d0577 Cleanup: Move sculpt mask update to a separate function
There's no reason to use a general "update vertex data" function,
that just confuses things.
2023-09-27 17:10:24 -04:00
Philipp Oeser 0b1d2d63fe Allow setting weights (Ctrl+X) without paintmask enabled
Currently if there is no selection mode enabled the operator is disabled and greyed
out in the menu. The shortcut doesn't do anything, which can be unexpected and jarring.

With this PR the operator will work when no selection mode is enabled and in that case
fill the entire mesh using the Weight from the active tool.
This is then consistent with vertex paint mode and the "Set Vertex Color" operator.

So now remove the overly-strict `mask_paint_poll` poll (and replace with
more appropriate `weight_paint_mode_poll`).

NOTE: `mask_paint_poll` is now unused, could be removed
Pull Request: https://projects.blender.org/blender/blender/pulls/112413
2023-09-27 09:13:04 +02:00
Hans Goudey 97f2b01ea9 Fix #112351: Sculpt implicit sharing thread safety crash
Currently the iteration over a PBVH node's vertices retrieves mutable
access to the mask custom data layer. This isn't threadsafe, but it is
done in the multithreaded loops over all nodes.

In general, we need to be more careful and conservative about storage
of non-const pointers to mesh data. Ideally we would only have one
mutable reference to a resource at a time. And we should avoid doing
work like looking up custom data layers more than we need to.

To that end, make the pointer to the custom data layer used everywhere
const, and retrieve mutable access before parallel node iteration with
a specific function, and write to the mask data with that in mind.

This pushes us in the direction of sharing less code per PBVH type.
In my opinion that's a good thing, because we can actually optimize for
each type. For example, `write_mask_data` gives a picture of
how each of these hot loops could become much simpler.

Pull Request: https://projects.blender.org/blender/blender/pulls/112690
2023-09-26 14:21:07 +02:00
Hans Goudey 916d4c9d9b Cleanup: Move BKE_screen.h to C++
See #103343
2023-09-25 17:53:11 -04:00
Campbell Barton e38ff7c06d Cleanup: use C++ comments for disabled code 2023-09-25 17:06:04 +10:00
Campbell Barton d4dbbab5d9 Cleanup: locate break statements inside the case body
Follow the convention used almost everywhere in Blender's code.
2023-09-23 21:17:50 +10:00
Hans Goudey b838c34afa Cleanup: Remove unused sculpt mask expand operator
The "mask expand" operator from 0083c96125 is not exposed in
the UI and is redundant with the addition of the more general "expand"
operator from 82e7032477. The latter commit even mentioned
that the first mask expand operator was made obsolete.

Pull Request: https://projects.blender.org/blender/blender/pulls/112726
2023-09-22 17:30:28 +02:00
Philipp Oeser 1b7d257ce5 Fix #112664: Expand face sets freeze when cursor is on mesh boundaries
Mistake/typo in f4505e7b0a (not actually setting the bit).

Pull Request: https://projects.blender.org/blender/blender/pulls/112706
2023-09-22 14:52:07 +02:00
Hans Goudey 867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Hans Goudey 72a33623e6 Cleanup: Sculpt: Use C++ threading API
Also remove unnecessarily parallelized loop that was just setting a
flag for every PBVH node.
2023-09-21 13:42:13 -04:00
Hans Goudey 64ce21aa2a Cleanup: Move sculpt mask fill to lambda, remove data struct
The actual logic in the callback is quite short, most of the lines are
dedicated to moving arguments in and out of a local "data" struct.
2023-09-21 12:45:17 -04:00
Hans Goudey 0fd0539f04 Cleanup: Rename grease pencil function to access layer at index
The plural was confusing when only one layer was returned.
2023-09-20 08:39:30 -04:00
Campbell Barton edc47d3d5a Cleanup: split ID property access into get/ensure functions
- Add IDP_EnsureProperties,
- Remove create_if_needed argument from IDP_GetProperties.

Split access & creation so intention reads more clearly without
looking up function arguments.
2023-09-17 12:16:40 +10:00
Campbell Barton c7cd1c8d0b Cleanup: use enum literals for space_type & region_type arguments
Also remove unique names for grease pencil keymaps.
There was not advantage in having separate names for each grease pencil
key-map.
2023-09-14 13:36:34 +10:00
Campbell Barton b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Philipp Oeser 564716d5a2 Fix #112285: Sculpt Mode: Mask brush smoothing is broken
Mistake in cc01bb83f6.

Above commit tried to be smart about early out, but wasnt.
Now corrected.

NOTE: fix needs to go into 3.6 LTS

Pull Request: https://projects.blender.org/blender/blender/pulls/112292
2023-09-13 11:04:52 +02:00
Campbell Barton 4fc5d287ac Cleanup: doxygen parameters, blank comment lines 2023-09-08 16:53:30 +10:00
Jacques Lucke b5c89822ac RNA: return PointerRNA from rna create functions
There are a couple of functions that create rna pointers. For example
`RNA_main_pointer_create` and `RNA_pointer_create`. Currently, those
take an output parameter `r_ptr` as last argument. This patch changes
it so that the functions actually return a` PointerRNA` instead of using
the output parameters.

This has a few benefits:
* Output parameters should only be used when there is an actual benefit.
  Otherwise, one should default to returning the value.
* It's simpler to use the API in the large majority of cases (note that this
  patch reduces the number of lines of code).
* It allows the `PointerRNA` to be const on the call-site, if that is desired.

No performance regression has been measured in production files.
If one of these functions happened to be called in a hot loop where
there is a regression, the solution should be to use an inline function
there which allows the compiler to optimize it even better.

Pull Request: https://projects.blender.org/blender/blender/pulls/111976
2023-09-06 00:48:50 +02:00
Hans Goudey 644297cc6e Cleanup: Remove mistanly committed timer
Mistake in afdbb734cf
2023-09-04 22:47:59 -04:00
Hans Goudey 646b3555ff Cleanup: Use C++ Set for expand snap enabled face sets
Instead of the less-type-safe and slower `GSet`.
2023-09-04 22:23:27 -04:00
Hans Goudey e52404db95 Cleanup: Use simpler face vert iteration in sculpt expand 2023-09-04 22:23:26 -04:00
Hans Goudey f4505e7b0a Cleanup: Use BitVector instead of BLI_Bitmap in sculpt expand 2023-09-04 22:23:26 -04:00
Hans Goudey 96f761a17c Cleanup: Use const arguments to sculpt "get" functions 2023-09-04 22:23:26 -04:00
Hans Goudey 8bc1e5a0e9 Cleanup: Use consistent static function names in sculpt_geodesic.cc
The capital prefixes are meant for non-static functions in C code.
2023-09-04 22:23:26 -04:00
Hans Goudey afdbb734cf Cleanup: Avoid mesh positions copy applying sculpt to shape key
`BKE_pbvh_vert_coords_alloc` is unnecessary after 1af62cb3bf
since PBVH vertex positions are stored in a contiguous array.
2023-09-04 22:23:26 -04:00
Hans Goudey fa34992def Cleanup: Remove unnecessary includes from C++ data structure headers
The hash tables and vector blenlib headers were pulling many more
headers than they actually need, including the C base math header,
our C string API header, and the StringRef header. All of this
potentially slows down compilation and polutes autocomplete
with unrelated information.

Also remove the `ListBase` constructor for `Vector`. It wasn't used
much, and making it easy to use `ListBase` isn't worth it for the
same reasons mentioned above.

It turns out a lot of files depended on indirect includes of
`BLI_string.h` and `BLI_listbase.h`, so those are fixed here.

Pull Request: https://projects.blender.org/blender/blender/pulls/111801
2023-09-01 21:37:11 +02:00
Hans Goudey 4e94db97e2 Mesh: Add three cached topology maps
Add three cached topology maps to `Mesh`, to avoid computations when
mesh data isn't changed. Choosing the right maps to cache is a bit
arbitrary, but generally we have to start somewhere. The limiting
factor is memory usage (all the new caches combined have a
comparable footprint to a UV map).

For now, the caches added are:
- Vertex to face corner
- Vertex to face
- Face corner to face

These caches are used in quite a few places already;
- Face corner normal calculation
- UV value merging
- Setting sharp edges from face angles
- Data transfer modifier
- Voxel remesh attribute remapping
- Sculpt mode painting
- Sculpt mode normal calculation
- Vertex paint mode
- Split edges geometry node
- Mesh topology geometry nodes

Caching topology maps means they don't have to be rebuilt every time
they're used. Meshes copied but without topology changes can share
the cache, further reducing re-computations. For example, FPS with a
large mesh using the "Corners of Vertex" node went from 1.8 to 2.3.
Entering sculpt mode is slightly faster too.

There is some obvious work for future commits:
- Use caches in attribute domain interpolation
- More multithreading of second phase of map building
- Update/build caches eagerly in some geometry nodes

Pull Request: https://projects.blender.org/blender/blender/pulls/107816
2023-08-30 23:41:59 +02:00
Petar Dosev 5894ab2e07 Fix #104022: Expand Mask inverted fill
A small new feature that clears the mask completely on the current mesh island.
Closes #104022

When hovering outside the object the Expand operator is running on, it will get floodfilled with the mask/face set.

Previously, when the Invert option was used, it wouldn't also clear the mask/face set when hovering outside the object.

Pull Request: https://projects.blender.org/blender/blender/pulls/111665
2023-08-30 09:28:46 +02:00
Hans Goudey 3f0eba32d4 Cleanup: Fix unused variable warning 2023-08-29 12:00:18 -04:00
Hans Goudey 69c498084a Cleanup: Remove unnecessary Mesh C API functions 2023-08-29 11:47:29 -04:00
Hans Goudey b339e3937d Fix: Crash in sculpt mode with shared normals caches
Since the normals are stored in a shared cache, tagging them dirty
recreated the cache from scratch when it was shared. Instead,
add a function that updates the cache in the same call as tagging
it dirty. This keeps the old state of the cache around even if it was
shared, and reflects the way that it's really the PBVH and sculpt
mode managing the dirty status of normals while sculpt mode
is active.

One consequence is that the BVH cache and the triangulation
cache need to be tagged dirty manually. I'd like to avoid abstracting
this more than necessary, because I'm hoping in the long term
different caching abstractions like a more global cache that takes
implicit sharing versions into account will make this complexity
unnecessary.

Fixes #111628, #111563

Pull Request: https://projects.blender.org/blender/blender/pulls/111641
2023-08-29 17:07:42 +02:00
Hans Goudey 425b871607 Mesh: Replace EdgeHash and EdgeSet with C++ classes
The `EdgeHash` and `EdgeSet` data structures are designed specifically
as a hash of an order agnostic pair of integers. This specialization can
be achieved much more easily with the templated C++ data structures,
which gives improved performance, readability, and type safety.

This PR removes the older data structures and replaces their use with
`Map`, `Set`, or `VectorSet` depending on the situation. The changes
are mostly straightforward, but there are a few places where the old
API made the goals of the code confusing.

The last time these removed data structures were significantly changed,
they were already moving closer to the implementation of the newer
C++ data structures (aa63a87d37).

Pull Request: https://projects.blender.org/blender/blender/pulls/111391
2023-08-29 17:00:33 +02:00
Hans Goudey c9621a002d Cleanup: Sculpt: Remove duplicate visibility update function
`node_update_visibility_redraw` and `BKE_pbvh_update_visibility`
do the same thing, and the latter is better specialized for the three
PBVH types, so remove the first.

The two update methods were added in:
- f4411b58ad
- 38d6533f21

Pull Request: https://projects.blender.org/blender/blender/pulls/110709
2023-08-29 14:23:04 +02:00
Philipp Oeser cc01bb83f6 Fix #111490: paint radius set to 1 (shift-smoothing but brush missing)
This affected sculpt, vertex- and weightpaint.

So attempting to (temporarily) switching to the smooth/blur tools from
another tool using the "Shift" shortcut can fail if the corresponding
smooth/blur brush is not found/missing [which was the case in the report
because the brush was deleted].

In this case, brushes dont really get switched, but blender would still
try to cache the size (because the smooth/blur brush temporarily uses
the same size as the previous brush) of the smooth brush in
`StrokeCache` (see `smooth_brush_toggle_on`). Then in
`smooth_brush_toggle_off` it was assumed brushes were actually switched
and the (non-existing) size of the (missing) smooth brush was applied to
the **actual** brush.

Now restructure code a bit so in the case of a missing brush we can
early out (without affecting the **actual** brush then).

Pull Request: https://projects.blender.org/blender/blender/pulls/111516
2023-08-29 13:44:35 +02:00
Sergey Sharybin 42473099b4 Cleanup: Braces around initialization
Pull Request: https://projects.blender.org/blender/blender/pulls/111605
2023-08-28 12:46:27 +02:00
Campbell Barton 19850496cb Cleanup: remove unused function, format 2023-08-26 17:05:19 +10:00
Harley Acheson eb0a9346df Cleanup: Make format
Only formatting changes.
2023-08-25 12:18:13 -07:00
Hans Goudey cf9fcbf24e Cleanup: Use C++ threading API in sculpt/paint code
Remove the global `SculptThreadedTaskData` struct which contained
the arguments to ALL multi-threaded sculpt functions. Use the C++
threading API instead of the old task API, moving the arguments
previously stored in the shared struct to actual function arguments.

Pull Request: https://projects.blender.org/blender/blender/pulls/111525
2023-08-25 18:18:35 +02:00
Pratik Borhade faff3d1d15 Cleanup: Comment style
Pull Request: https://projects.blender.org/blender/blender/pulls/111509
2023-08-25 11:14:19 +02:00
Campbell Barton 09f61f6881 Cleanup: enforce documented convention for RNA enum naming
This was noted in code comments and checked in Python documentation
generation but not at build time.

Since these enums are identifiers that end up included in various places
enforce the `rna_enum_*_items` convention which was noted as
the convention but not followed strictly.

Partially reverts [0], avoids having to deal with multiple prefix types.

[0]: 3ea7117ed1
2023-08-25 13:35:58 +10:00
Hans Goudey 111e586424 Cleanup: Sculpt: Avoid unnecessarily changing vertex normals
Keeping a mutable reference to vertex normals for the entire lifetime
of the PBVH structure makes caching the normals and sharing the cache
harder than it should be. Generally code is safer when we reduce the
number of mutable references to data.

Currently the normals are modified in two places. First is the sculpt
mesh normal recalculation. There we can just retrieve the normals from
the mesh each time. Second is the restore from an undo step. That is
unnecessary because the normals are marked for recalculation anyway.
It doesn't even make much sense to store the normals in an undo step
when we can easily recalculate them based on new positions.

This change helps with #110479. These were also the last place that
kept a mutable reference to normals. I tested undo and redo after
sculpting, and it works well for each PBVH type.

Pull Request: https://projects.blender.org/blender/blender/pulls/111470
2023-08-24 16:47:55 +02:00
Hans Goudey 7fc7441a7b Cleanup: Separate sculpt undo restore into types
Though this means a few loops are duplicated, overall the code is
easier to reason about because the cases are separated more. This
makes potential changes to the way normals are stored clearer
(related to !110479), and makes potential optimizations easier too.
2023-08-24 07:37:07 -04:00
Hans Goudey 4a0581eca2 Fix: Missing multires to faces visibility sync after box hide
The operator handled faces visibility change correctly but not
multires. Use the existing PBVH API function for that, also remove
a redundant call to the function that fetched the attribute pointers
again after the change.
2023-08-24 07:37:07 -04:00
Campbell Barton 3ec489000f Cleanup: spelling in comments 2023-08-24 10:43:45 +10:00
Amelie Fondevilla 1193f2d7ec GPv3: Refactor code for the hard eraser
This patch refactors most of the code of the hard eraser, both for readability purpose, and to prepare the integration of the soft mode of the eraser.
The refactoring includes :
 - the use of specific structures and enum types `SegmentCircleIntersection`, `PointCircleSide`, and `PointTransferData` to handle the data more easily,
 - improve readability of the intersections functions (better naming, and more accurate and generic comments),
 - definition of a more generic `compute_topology_change` function that handles point insertion, removal, and curve splitting for curves geometry.

Pull Request: https://projects.blender.org/blender/blender/pulls/111390
2023-08-23 14:13:50 +02:00
Sergey Sharybin beaf4854b1 Fix #110328: Clay Strip symmetry does not mirror rotation
Caused by 351034891e

This change is a partial revert of the change.

The SCULPT_cube_tip_init() does not deal with the symmetry passes.

Additionally, the commit changed the way how the Z component of
the matrix was constructed: displaced vs. non-displaced area
coordinate.

While the code duplication is often to be avoided, sometimes it is
more clear than a centralized place with a lot of arguments passed
to a function. We can have a pass of de-duplication later on, and
make a better decision, but for now restore user level behavior to
what it is expected to be.

Pull Request: https://projects.blender.org/blender/blender/pulls/111425
2023-08-23 12:21:44 +02:00
Campbell Barton 24ef5e097a Cleanup: balance doxy sections 2023-08-23 14:54:46 +10:00
Hans Goudey 1857df8d5b Cleanup: Use FunctionRef for PBVH filtering callback
Call functions directly in lambdas rather than passing their
arguments in a separate void * argument. This can be changed
more in the future to move callback arguments out of smaller
structs.
2023-08-22 15:06:42 -04:00
Amelie Fondevilla 6cfda322a6 Fix: GPv3: Stroke Eraser does not work with one-point strokes.
The stroke mode of the eraser only tests distance with segments of the strokes, so it does not take into account strokes that only have one point, and thus no segment. This patch fixes the issue by testing if the point is inside the eraser in the case of a one-point stroke.

Pull Request: https://projects.blender.org/blender/blender/pulls/111387
2023-08-22 17:04:51 +02:00
Campbell Barton c713c70781 CMake: quiet uninitialized warnings 2023-08-17 11:53:56 +10:00
Aras Pranckevicius 2f060706a4 Cleanup: fewer BLI_color.hh et al includes
Include counts of some headers while making full blender build:
- BLI_color.hh 1771 -> 1718
- BLI_math_color.h 1828 -> 1783
- BLI_math_vector.hh 496 -> 405
- BLI_index_mask.hh 1341 -> 1267
- BLI_task.hh 958 -> 903
- BLI_generic_virtual_array.hh 509 -> 435
- IMB_colormanagement.h 437 -> 130
- GPU_texture.h 806 -> 780
- FN_multi_function.hh 331 -> 257

Note: DNA_node_tree_interface_types.h needs color include only
for the currently unused (but soon to be used) socket_color function.
Future step is to figure out how to include
DNA_node_tree_interface_types.h less.

Pull Request: #111113
2023-08-16 14:48:53 +03:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Hans Goudey f0467b4615 Cleanup: Return std::string from operator name and description callbacks
With the end goal of simplifying ownership and memory management,
and allowing the use of `get_name` in contexts without statically
allocated strings, use `std::string` for the return values of these two
operator type callbacks instead of `const char *` and `char *`.

In the meantime things get uglier in some places. I'd expect `std::string`
to be used more in the future elsewhere in Blender though.

Pull Request: https://projects.blender.org/blender/blender/pulls/110823
2023-08-11 19:11:27 +02:00
Bastien Montagne 203e6e2b41 Fix (unreported) Several `OperatorType.get_name` not doing translation.
`OperatorType.get_name` callback is supposed to return strings directly
usable in the UI, i.e. translated if needed.

Several callbacks did not, noticiably the generic
`ED_select_pick_get_name` and `ED_select_circle_get_name` ones.

And the `sculpt_color_filter_get_name` was not using available RNA
helpers for enum items has it should have.

Finally, `RNA_property_enum_name_gettexted` and
`RNA_property_enum_item_from_value_gettexted` were also not using the
optimal higher-level translation API.

Noticed while reviewing !110776.
2023-08-11 12:00:16 +02:00
Philipp Oeser 3c26f84225 Vertex Paint: Add option to lock alpha for 'Set Vertex Colors'
It is a common practice in gamedev to rely on coding various data into
the alpha channel of the mesh and there was no way to preserve that when
using the `Set Vertex Colors` operator (would always sets the Alpha component to '1').

Now add an "Affect Alpha" option (similar to what we have for brushes)
and when that is disabled, existing alpha is locked.

Fixes #110014

Pull Request: https://projects.blender.org/blender/blender/pulls/111002
2023-08-11 10:39:13 +02:00
Jacques Lucke cc4d5c432c RNA: move headers to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/111022
2023-08-10 22:40:27 +02:00
Aras Pranckevicius d973355b3a Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).

However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.

This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.

Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
  to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).

Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.

Pull Request #110944
2023-08-10 14:51:40 +03:00