Commit Graph

23224 Commits

Author SHA1 Message Date
Hans Goudey
fba7671205 Cleanup: Const correctness, unused variable warning in GP draw code 2023-10-19 15:03:32 +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
0488117548 Unbreak debug build 2023-10-19 22:43:26 +11:00
Falk David
26816931c4 Fix: GPv3: Remap materials
Also fixes a crash when moving the first material of the default Grease Pencil Suzanne down by one.

Pull Request: https://projects.blender.org/blender/blender/pulls/113855
2023-10-19 13:19:41 +02:00
Lukas Tönne
367320a0f5 Merge branch 'blender-v4.0-release' 2023-10-19 11:48:54 +02:00
Lukas Tönne
dfc3f75e77 Fix #113860: Nullptr checks for node socket and panel name pointers
In 3.6 the names of node group sockets were using char arrays, but now
use allocated strings. The RNA system assigns nullptr to such strings
when assigning an empty string through python (UI assignment appears to
always generate a valid string). This creates issues with many STL
functions, in particular assigning nullptr to `std::string` will crash.

We have to check for valid pointers before using them in places that
don't handle nullptrs.

Pull Request: https://projects.blender.org/blender/blender/pulls/113924
2023-10-19 11:48:08 +02:00
Campbell Barton
e7e4e63313 Cleanup: spelling in comments, white-space in comments 2023-10-19 18:53:16 +11:00
Hans Goudey
86bf9b1163 Cleanup: Remove disabled PBVH BMesh code
The large amount of disabled code makes this area trickier to deal with,
and this particular code wasn't helpful to the reader anyway.
2023-10-18 19:40:32 +02:00
Hans Goudey
062169698a Cleanup: Use C++ types instead of BLI_buffer in pbvh_bmesh.cc 2023-10-18 18:54:34 +02:00
Hans Goudey
45478706b8 Cleanup: Comment style, reduce variable scope in pbvh_bmesh.cc
Just superfical cleanups to make working int his file more pleasant.
2023-10-18 18:54:34 +02:00
Falk David
37d2eaee4e Fix: GPv3: Crash renaming a layer
When renaming a layer to a (long) name that was already taken
by another layer, Blender would crash.
This was because the memory for the unique string was held by
`std::string` which cannot grow.
The solution is to use `char unique_name[MAX_NAME]`.
2023-10-18 17:01:25 +02:00
Brecht Van Lommel
b867f16e27 Cleanup: compiler warnings 2023-10-18 16:57:08 +02:00
Falk David
a89bb7632a GPv3: Separate/Delete Geometry node
This implements deleting a selection of layers on a grease pencil geometry.

Pull Request: https://projects.blender.org/blender/blender/pulls/113828
2023-10-18 11:54:56 +02:00
Falk David
080823f93c Fix: GPv3: Memory leak in set_name
The `set_name` function was not freeing the previously
allocated string and would leak the memory.
2023-10-18 11:50:41 +02:00
Falk David
bc0e5cf8bd Cleanup: GPv3: Use helper to duplicate drawings 2023-10-18 11:27:01 +02:00
Falk David
74facf9841 GPv3: Add wrapper class for DrawingReference
Adds a simple C++ wrapper so we don't have to use
`MEM_dupallocN`, `MEM_freeN` etc.
2023-10-18 11:27:01 +02:00
Jacques Lucke
6e35e30ba8 Merge branch 'blender-v4.0-release' 2023-10-18 09:57:26 +02:00
Jacques Lucke
4f3262a128 Fix: update curve types before using them 2023-10-18 09:56:22 +02:00
Falk David
ed124d23d1 Fix: GPv3: Crash when storing deformed points
The issue was that the optional array was not correctly initialized.

Ref !113858
2023-10-17 19:29:52 +02:00
Falk David
78cb2776bb Fix #113740: Crash adding layer into empty group
This crash was cause by some mismatch in the indices.
We need to make sure to clamp the insertion index to the size of the
span of the layers.

Pull Request: https://projects.blender.org/blender/blender/pulls/113852
2023-10-17 18:34:42 +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
Falk David
f59827de74 GPv3: Add API to copy and add a layer
This adds a core API to add a new layer by copying a source layer.
2023-10-17 15:41:50 +02:00
Hans Goudey
d7e501ce3b Fix #112448: Leading deform modifiers skip adding original coordinates
Previously the first group of deform modifiers didn't need to access
original coordinates explicitly because the deformation wasn't included
in the mesh positions. After d20f992322 the mesh is deformed
directly though, so the original coordinates need to be added first.

In the case of this report, the particle system (which is a "deform"
modifier for reasons) didn't have original coordinates to work with, so
it created the child particles at the deformed positions from the shape
keys every time. Though for some reason it only did that for renders.

Pull Request: https://projects.blender.org/blender/blender/pulls/113679
2023-10-17 10:28:19 +02:00
Hans Goudey
30d66a4eaf Merge branch 'blender-v4.0-release' 2023-10-17 09:56:58 +02:00
Hans Goudey
bd4c310a19 Fix: Missing edge domain in node tool set selection node
This wasn't implemented in the initial commit because we didn't have
a function to flush edge selections to vertices and faces. But using the
existing domain interpolations makes that trivial, so it may as well be
added now to avoid the arbitrary limitation from the user perspective.

See https://devtalk.blender.org/t/node-tools-feedback/31388/5

Pull Request: https://projects.blender.org/blender/blender/pulls/113367
2023-10-17 09:56:24 +02:00
Hans Goudey
4ae4e25dc2 Merge branch 'blender-v4.0-release' 2023-10-17 09:25:51 +02:00
Hans Goudey
820f0c24c4 Mesh: Add versioning to convert old face maps to boolean attributes
See #105317

In 46cf093270, face maps were just converted to an integer
attribute. While the internal data remains the same that way, we lose
the names and some convenient methods of interaction. This commit
additionally converts each face map to a separate boolean attribute
using the old name. This does require that no attributes were using that
name already.

Each boolean attribute can be thought of as a selection, accessible in
geometry nodes and properly interpolated by mesh processing
algorithms. The selections no longer have to be unique, meaning
one face can be part of multiple selections.

Pull Request: https://projects.blender.org/blender/blender/pulls/113769
2023-10-17 09:17:07 +02:00
Jacques Lucke
006380aaca Cleanup: deduplicate field socket type check 2023-10-16 19:13:27 +02:00
Sergey Sharybin
f8ee27c88b Sculpt: Preserve edge attribute on split with dyntopo
Copy custom data and flag from the original edge to the ones created
from it when splitting a long edge.

Unfortunately, can not use generic "example" edge approach as there
is a temporary flag BM_ELEM_TAG is re-applied in a loop: the new
edges can not be tagged with this tag. Additional complication is
that even we clear this tag from the input edge before splitting it
this tag is re=applied via long_edge_queue_face_add().

Hence, use our own simple function to copy minimal subset of data and
tags.

Co-Authored-By: Hans Goudey <hans@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/113783
2023-10-16 19:12:10 +02:00
Sergey Sharybin
a19a36c631 Cleanup: More proper C++ usage in PBVH edge split
- More consistent naming of variables in diagram and code.
- Use C++ array and span, and make them short-lived, without
  trying to reuse them.

Co-Authored-By: Hans Goudey <hans@blender.org>
2023-10-16 19:12:08 +02:00
Iliya Katueshenock
bd6db0acea Cleanup: Nodes: unify data type conversion functions
Pull Request: https://projects.blender.org/blender/blender/pulls/113744
2023-10-16 19:09:07 +02:00
Jacques Lucke
b47372356d Cleanup: remove now unused CustomDataAttributes
This is not used anymore, because there are better alternatives:
* Higher level `AttributeAccessor` interface.
* Lower level `CustomData` interface.
2023-10-16 18:44:48 +02:00
Jacques Lucke
ff4d5b6f04 Geometry Nodes: don't use CustomDataAttributes in Instances
This was the last use of `CustomDataAttributes`. It's not very useful
nowadays because we have a lower level (`CustomData`) and higher level
(`AttributeAccessor`) API.

As part of this I removed the ability to `reserve` instances which was
useful when adding instances one by one. Generally, such code should
eventually be rewritten to handle more instances at once, instead of
handling them one by one. This will lead to better performance and
is more in line with how other geometry types (like mesh) are handled.

This also adds the ability to move and assign `Instances` just like we can
move and assign `CurvesGeometry`.
2023-10-16 18:41:32 +02:00
Germano Cavalcante
dae06c7562 Merge branch 'blender-v4.0-release' into main 2023-10-16 11:48:02 -03:00
Germano Cavalcante
88a6df24aa Fix #113552: NLA Markers do not reset when length reaches 0.0
Before bd00324c26, strip lengths were changed in
`rna_NlaStrip_frame_start_ui_set` and `rna_NlaStrip_frame_end_ui_set`
so as not to be shorter than NLASTRIP_MIN_LEN_THRESH.

This prevented `BKE_nlameta_flush_transforms` from working with
zero-length strips.

But now, in some cases, strip can be zero length.

Therefore, consider this case and avoid division by zero.

Pull Request: https://projects.blender.org/blender/blender/pulls/110121
2023-10-16 16:46:47 +02:00
Jacques Lucke
5f80242bc2 Cleanup: use CustomDataAttributes from Instances interface
It's still used internally currently. `CustomDataAttributes` will be removed
soon because there are better alternatives (`AttributeAccessor`).
2023-10-16 16:39:39 +02:00
Omar Emara
9f1538b586 Cleanup: Move compositor headers to c++
Pull Request: https://projects.blender.org/blender/blender/pulls/113758
2023-10-16 10:45:54 +02:00
Jacques Lucke
38813a7441 Nodes: unify static and dynamic declarations
This helps solving the problem encountered in #113553. The problem is that we
currently can't support link-drag-search for nodes which have a dynamic declaration.

With this patch, there is only a single `declare` function per node type, instead of
the separate `declare` and `declare_dynamic` functions. The new `declare` function
has access to the node and tree. However, both are allowed to be null. The final
node declaration has a flag for whether it depends on the node context or not.

Nodes that previously had a dynamic declaration should now create as much of
the declaration as possible that does not depend on the node. This allows code
like for link-drag-search to take those sockets into account even if the other
sockets are dynamic.

For node declarations that have dynamic types (e.g. Switch node), we can also
add extra information to the static node declaration, like the identifier of the socket
with the dynamic type. This is not part of this patch though.

I can think of two main alternatives to the approach implemented here:
* Define two separate functions for dynamic nodes. One that creates the "static
  declaration" without node context, and on that creates the actual declaration with
  node context.
* Have a single declare function that generates "build instructions" for the actual
  node declaration. So instead of building the final declaration directly, one can for
  example add a socket whose type depends on a specific rna path in the node.
  The actual node declaration is then automatically generated based on the build
  instructions. This becomes quite a bit more tricky with dynamic amounts of sockets
  and introduces another indirection between declarations and what sockets the node
  actually has.

I found the approach implemented in this patch to lead to the least amount of
boilerplate (doesn't require a seperate "build instructions" data structure) and code
duplication (socket properties are still only defined in one place). At the same time,
it offers more flexibility to how nodes can be dynamic.

Pull Request: https://projects.blender.org/blender/blender/pulls/113742
2023-10-15 20:28:23 +02:00
Dalai Felinto
7a73f792ed GPv3: Fix Normal Field
Part of #113602.
Ref !113704.
2023-10-14 00:58:02 +02:00
Hans Goudey
9b0188db03 Fix #112448: Leading deform modifiers skip adding original coordinates
Previously the first group of deform modifiers didn't need to access
original coordinates explicitly because the deformation wasn't included
in the mesh positions. After d20f992322 the mesh is deformed
directly though, so the original coordinates need to be added first.

In the case of this report, the particle system (which is a "deform"
modifier for reasons) didn't have original coordinates to work with, so
it created the child particles at the deformed positions from the shape
keys every time. Though for some reason it only did that for renders.

Pull Request: https://projects.blender.org/blender/blender/pulls/113679
2023-10-13 20:35:16 +02:00
Hans Goudey
e1fb095f0e GPv3: Fix Field inputs that had no inputs
For example:
* Curve Tangent
* Spline Parameter
2023-10-13 18:51:03 +02:00
Dalai Felinto
6853d787db Geometry Nodes: Util function to propagate attributes
This propagates from layer to instances, which is required by some
of the Grease Pencil nodes.

Part of #113602.
Ref !113634.
2023-10-13 16:33:54 +02:00
Christoph Lendenfeld
6922cb4683 Refactor: keyingsets.cc
No functional changes

Make the code more readable by doing the following
* rename `BKE_keyingset_free` to `BKE_keyingset_free_paths` since that is what it does
* invert `if` and return early to reduce indentation
* add enum value `MODIFYKEY_SUCCESS` to explicitly state the return value, instead of eModifyKey_Returns(0)
* return `INSERTKEY_NOFLAGS` instead of eInsertKeyFlags(0)
* move variables closer to their usage

Pull Request: https://projects.blender.org/blender/blender/pulls/113666
2023-10-13 12:55:54 +02:00
Bastien Montagne
9859622a66 BKE_reports: make the API thread-safe.
This commit makes using (most of) `BKE_report` API safe in
multi-threaded situation.

This is achieved by adding a `std::mutex` lock to the `ReportList`
struct (in a slightly convoluted way unfortunately, due to this being a
DNA struct). This lock is then used to make most operations on
`Reportlist` data thread-safe.

Note that while working on this, a few other minor issues aroze in
existing usages of Reportlist by the WM code, mainly the fact that
`wm_init_reports` and `wm_free_reports` were both useless:
  - init was called in a context where there is not yet any WM, so it
    was doing nothing.
  - free was called on a WM that would be later freed (as part of Main
    freeing), which would also call cleanup code for its `reports` data.
Both have been removed.

Further more, `wm_add_default` (which is the only place where a WM ID is
created) did not initialize properly it reports data, this has been
fixed.

This change is related to the wmJob thread-safety tasks and PRs (#112537,
!113548).

Pull Request: https://projects.blender.org/blender/blender/pulls/113561
2023-10-13 11:29:59 +02: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
Bastien Montagne
86fb43d57a Merge commit '2d703e9200985122b4b953be67b452f7679bf113'
Conflicts:
	source/blender/nodes/NOD_node_declaration.hh
2023-10-12 18:56:12 +02:00
Damien Picard
2d703e9200 I18n: add label declaration to node sockets so they can be shortened
In !112591, nodes got the ability to group sockets into panels. The
labels for these sockets are automatically shortened if they begin
with the same text as their parent labels. For instance, "Transmission
Weight" will be shortened to just "Weight" because it is under the
"Transmission" panel.

While this is a good heuristic for English, it breaks down in
languages which do not have the same word order.

This commit adds a `.short_label()` callback to socket declarations so
that a shortened label can be explicitly declared.

It also adds two regexps to the translation script so that these new
fields can be extracted to the .po translation files. One extracts the
label with a translation context, the other without. Only the one
without context is currently in use.

The current automatic shortening logic is kept and will be used only
if a shortened label is not manually provided.

Fixes #112970: Node socket labels under panels are not shortened when
translated.

Pull Request: https://projects.blender.org/blender/blender/pulls/113070
2023-10-12 17:51:37 +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
de47c2a8b4 Cleanup: Use const pbvh node pointers for some accessor functions 2023-10-12 14:51:51 +02:00