Commit Graph

23469 Commits

Author SHA1 Message Date
Philipp Oeser
481094ff5c Fix #114760: new attribute does not get active for some domains
Problem here is that `BKE_id_attribute_to_index` [which
`BKE_id_attributes_active_set` uses] does not match
`BKE_id_attribute_from_index` which can lead to "wrong" indices (there
are "wrong" layers included while iterating such as ".corner_vert" or
".corner_edge" for faces).

Deeper reason is that `get_domains_types` swaps `ATTR_DOMAIN_FACE` and
`ATTR_DOMAIN_CORNER` (originally introduced in eae36be372 -- but unclear
at this point why this was done). Historically, this was used for operators
[vertex color rotate/inverse] introduced in c75e1598dd & 771a4dee0b,
assumption is that eae36be372 was trying to make this more generic and make
it work for other domains as well (ATTR_DOMAIN_MASK_COLOR -- the tootip
was also changed from "Rotate vertex colors inside faces" to "Rotate color
attributes inside faces"), however, at this point in time the tools clearly only work
for the corner domain (and this was made more specific in ee18b625ca as well).

So now, remove the swapping all together and make
`BKE_id_attribute_from_index` & `BKE_id_attribute_to_index` in sync.

Also change the tooltip of said operators to use "face corner color attribute".

Pull Request: https://projects.blender.org/blender/blender/pulls/114797
2023-12-07 15:33:28 +01:00
Christoph Lendenfeld
e0806e6d51 Refactor: combine x and y for insert_vert_fcurve into float2
No functional changes.

To reduce the argument count of `insert_vert_fcurve`,
the x and y argumentsto define the position
of a keyframe can be merged into a single `float2`

Pull Request: https://projects.blender.org/blender/blender/pulls/115886
2023-12-07 12:05:09 +01:00
Hans Goudey
a86658a58a Fix #115856: Sculpt Face sets drawing sometimes uses wrong default
In some cases the value that defines which ID is displayed as white is
mismatched between the original and evaluated mesh. Use the original
as the source of truth, since that's the mesh that's actively edited.
2023-12-06 23:50:30 -05:00
Hans Goudey
f3dd1a3260 Sculpt: Refactor face sets storage and access
Similar to previous changes for masks and visibility, remove the mutable
pointer to face sets from the sculpt session. With implicit sharing,
this avoids a duplicate copy of face sets on the evaluated object when
face sets aren't edited.

Most retrieval of face sets now goes through the Mesh attribute API
instead of the pointer in sculpt session. This integrates sculpt code
with the rest of Blender, avoiding the need to reinvent things like
basic attribute access.

Similar to previous refactors to mask and visibility operators, refactor
the face set gesture and edit operators to be multithreaded and only
push undo steps and tag updates for actually changed nodes.

There is opportunity for more code deduplication in the future.
For now the aim is to reduce the number of confusing abstraction
levels though.
2023-12-06 23:50:30 -05:00
Hans Goudey
184418b6d0 Fix: Incorrect use of Vector resize in mesh_fair
Wrong since c9b4d75336
2023-12-06 23:33:46 -05:00
Hans Goudey
4e7e539b33 Sculpt: Make hide poly pointer in sculpt session const
This avoids having to make the original data layer mutable when we
aren't going to modify it, meaning the memory can still be shared with
the evaluated mesh-- saving 1 byte per face in some situations. This was
made possible by previous commits that moved to using the Mesh attribute
API instead of the SculptSession pointer to edit this data. Eventually the
`hide_poly` pointer should be completely removed.
2023-12-06 23:33:46 -05:00
Hans Goudey
466dca07d5 Cleanup: Move mesh visibility and selection flushing to C++ namespace
Also rename the functions and move a sculpt function that depended on
the mesh functions to a more proper place. And also use references and
nicer variable names for meshes.
2023-12-06 23:33:46 -05:00
Hans Goudey
251069ae5b Sculpt: Reimplement face sets visibility operator
Iterate over faces instead of vertices, and multithread the logic over
all PBVH nodes. The result is about 3 times faster in my tests;
noticeably snappier for large meshes. Add a new sculpt undo type for
face hide storage (as opposed to vertex storage), and use that only
when the data actually changed, which should reduce memory usage too.
Internally some code is shared with the other visibility operators,
since this operation always affects base mesh faces, most isn't.

Similar to 4e66769ec0
2023-12-06 23:33:46 -05:00
Hans Goudey
f61b271458 Cleanup: Remove unused sculpt functions 2023-12-06 23:33:46 -05:00
Campbell Barton
497600e49e Cleanup: spelling in comments, strings 2023-12-07 12:45:27 +11:00
Campbell Barton
9d9764c1c9 Cleanup: remove redundant define checks
Also reformat checks to quiet warnings so they don't read as empty
define checks.
2023-12-07 10:39:03 +11:00
Campbell Barton
9898602e9d Cleanup: clarify #ifndef checks in trailing #endif comments 2023-12-07 10:38:54 +11:00
Bastien Montagne
1e50987d94 LibOverride: Refactor some part of hierarchy handling code.
This commit is a preparation for an actual change in behavior of
automatic liboverride hierarchies creation. Although it may introduce
some minor changes (fixes) in behavior in some corner-cases, it is
not expected to have any noticeable end-user changes.

The main change is some refactor of the `LibOverrideGroupTagData` util
struct, to make it more clear and easy to manage data (IDs) from linked
reference, and data from liboverrides.

In addition, some minor changes in code logic, either optimizations or
hardened checks, e.g. to skip any processing of hierarchies when the
linked reference of its root is missing, or to ensure that libraries are
matching, etc.
2023-12-06 18:32:48 +01:00
Bastien Montagne
d24a49da84 Fix (unreported) missing Viewlayer update in liboverride code.
In post-processing of objects & collections after liboverrides creation,
viewlayer could be accessed while tagged as dirty, since the
object/collection hierarchy may be modified several times during this
process.
2023-12-06 17:11:56 +01:00
Brecht Van Lommel
e06561a27a Build: replace Blender specific DEBUG by standard NDEBUG
NDEBUG is part of the C standard and disables asserts. Only this will
now be used to decide if asserts are enabled.

DEBUG was a Blender specific define, that has now been removed.

_DEBUG is a Visual Studio define for builds in Debug configuration.
Blender defines this for all platforms. This is still used in a few
places in the draw code, and in external libraries Bullet and Mantaflow.

Pull Request: https://projects.blender.org/blender/blender/pulls/115774
2023-12-06 16:05:14 +01:00
Hans Goudey
79552f87f2 Fix: Protect against access of empty geometry bounds optional 2023-12-06 09:12:09 -05:00
Hans Goudey
865b806811 BMesh: Use simpler element copy within the same mesh
After previous commits, there is a new function to copy a BMesh
custom data block that doesn't go through the "find common layers
between two formats" code. This is *much* faster when there is a
large amount of layers with the same type, since that code is
quadratic currently. It may not be noticeable in many simpler
setups though.

Related to #115776
2023-12-05 22:09:37 -05:00
Hans Goudey
66da875488 BMesh: Improve performance when copying attributes in same mesh
When the BMesh source and result arguments are the same, restore
performance lost by 9175d9b7c2, which made copying layers
have quadratic time complexity. When we know the custom data format
is the same between the source and result, the copying can be much
simpler, so it's worth specializing this case. There is still more
to be done, because often we only know that the two meshes are the
same at runtime. A followup commit will add that check.

The quadratic runtime means performance is fine for low layer counts,
and terrible with higher layer counts. For example, in my testing with
47 boolean attributes, copying 250k vertices went from 2.3 seconds to
316 ms.

The implementation uses a new CustomData function that copies an entire
BMesh custom data block, called by a function in the BMesh module
overloaded for every BMesh element type. That handles the extra data
like flags, normals, and material indices.

Related to #115776
2023-12-05 22:09:37 -05:00
Hans Goudey
cc7080b8b0 Cleanup: Remove unnecessary size argument to CustomData free function
The size of the data is already known, there's no need to pass it
to the type's callback.
2023-12-05 22:09:37 -05:00
Hans Goudey
353d000f15 Cleanup: Remove unusd custom data function 2023-12-05 22:09:37 -05:00
Hans Goudey
7a96c4672c Cleanup: Move BMesh headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/115817
2023-12-05 23:01:12 +01:00
Sybren A. Stüvel
d63b68b01b Cleanup: run make format
Just running `make format`, no functional changes.
2023-12-05 16:01:28 +01:00
Hans Goudey
3a075a95ee Cleanup: Remove unused modifier functions 2023-12-05 09:36:13 -05:00
Hans Goudey
fe3b8b6e9b Cleanup: Remove remnants of old color layer preview system
For context, see 6d09fa3577. Overall, these values were still
written in some cases, but never used. Nowadays the viewer node and
attribute overlays give even better answers to these needs.
2023-12-05 09:36:13 -05:00
Hans Goudey
874f83c42e Cleanup: Use FunctionRef for PBVH batch drawing
Also use const arguments, move a null check from the callback to the
PBVH function, and reorganice the PBVH code to be in a consistent
place in the file and to simplify the logic.
2023-12-05 09:36:13 -05:00
Sybren A. Stüvel
42083c8357 Refactor: move ANIM_bone_collections.h into the .hh file
Move the contents of `ANIM_bone_collections.h` into its C++
`ANIM_bone_collections.hh` sibling. Blender is C++ by now that we can do
without the C header.

No functional changes.
2023-12-05 15:10:27 +01:00
Jacques Lucke
822cb1afd7 Fix: ensure function does not create geometry instances in all cases
This caused a crash further down the line where the code expected geometry
instances after calling `ensure_geometry_instances`, which seems reasonable
to assume.
2023-12-05 13:28:29 +01:00
Bastien Montagne
fa25a286d8 Refactor: BKE: Move BKE_library header to full CPP. 2023-12-05 11:53:55 +01:00
Falk David
5fea1eda36 GPv3: Drawing Placements
This PR adds the drawing placement modes from GPv2.

The drawing placement defines the depth (origin, view, surface, etc.) and a plane (view, cursor, xz, etc.).

This introduces a new helper class `DrawingPlacement` that does all of the internals to find the correct projection and just exposes a simple function to project from screen space to the drawing plane/surface.

Note: Drawing on other strokes currently doesn't work, because GPv3 can't be rendered to image yet. We use the depth buffer of the grease pencil render result to find the right depth.

Pull Request: https://projects.blender.org/blender/blender/pulls/115602
2023-12-05 11:01:42 +01:00
Nathan Vegdahl
9e7a70d6c6 Anim: store BoneCollections in a flat array
This is in preparation for eventual hierarchical bone collections.

The motivation here is that this will allow us to efficiently specify
children as an index range, which would be inefficient with a listbase
due to the list traversal overhead incurred for index-based look ups.

We're still saving to blend files as a list base for forwards compatibility
with Blender 4.0, but storing as an array at runtime for efficient indexing.

This should not result in any user-visible changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/115354
2023-12-05 10:39:45 +01:00
Z-Map
c9dd5ce4cc Fix #115715: Boolean behaves as if the object is on it's origin
Resolve regression in [0] which replaced a null check with an
identity comparison. This wasn't correct as the null check indicated
that transform was applied or not, where situations that require a
transform could have an identity matrix.

Resolve by checking if the matrix that would transform vertices is an
identity which is a reliable way to know if any transformation is needed.

Ref: !115736

[0]: e24c7f1954
2023-12-05 18:03:13 +11:00
Campbell Barton
20fd012adb Valgrind: suppress warnings with MemPool & MEM_* trailing padding
Suppress false positive Valgrind warnings which flooded the output.

- BLI_mempool alloc/free & iteration.
- Set alignment padding bytes at the end of MEM_* allocations
  as "defined" since this causes many false positive warnings
  in blend file writing and MEMFILE comparisons.
- Set MEM_* allocations as undefined when `--debug-memory`
  is passed in to account for debug initialization.
- Initialize pad bytes in TextLine allocations.
2023-12-05 17:12:32 +11:00
Campbell Barton
86f1fd5d8b BLI_idprop: simplify string creation logic, support unterminated strings
- Support passing in unterminated C-strings when clamped by the size
  argument.
- Pair string and it's size arguments together in IDP_NewStringMaxSize.
- Remove redundant size check which made it seem as if the string
  might not be null terminated.
- Replace clamping the result of strlen(..) with BLI_strnlen,
  to avoid calculating the length past the size checked.
- Add doc-string for unclamped string creation.
2023-12-05 17:11:03 +11:00
Hans Goudey
ce81bdc284 Fix #115775: Curve object to mesh conversion crash
Caused by 4bcdc57fc8.
These objects are "half evaluated" in a very ugly way and have
no runtime data.
2023-12-04 19:14:50 -05:00
Hans Goudey
c293c75975 Cleanup: Avoid passing context to shrinkwrap blenkernel function
Such lower level functions generally shouldn't know about Blender's
overall context. If that spreads everywhere, things get hard to reason
about.
2023-12-04 15:29:40 -05:00
Hans Goudey
695e626d3f Cleanup: Store more mesh runtime data with unique_ptr
Convert shrinkwrap data arrays to use C++ arrays and BitVector,
use references in "EditMeshData" code, and store both structs
with `std::unique_ptr` instead of a raw allocation.
2023-12-04 15:23:24 -05:00
Brecht Van Lommel
56cc47ee2e Cleanup: compiler warning 2023-12-04 20:37:11 +01:00
Hans Goudey
cc3c5e2329 Fix: Debug build error after recent PBVH bounds change 2023-12-04 14:10:38 -05:00
Hans Goudey
8a705ffd11 PBVH: Use C++ Bounds type for node bounds
This is just a bit more ergonomic and works a bit better with our C++
math vector types. Also, during PBVH build, don't store the center of
each triangle/grid. That's redundant and can always be recalculated
from the bounds.
2023-12-04 12:45:23 -05:00
Sybren A. Stüvel
562e9b9f4c Refactor: remove unused argument to BKE_constraint_remove_ex()
Remove the `bool clear_dep` argument of `BKE_constraint_remove_ex()`, as
it was always `true` on every call anyway.

No functional changes.
2023-12-04 17:13:47 +01:00
Hans Goudey
e9f4f8b52a PBVH: Specialize node bounds update, expose functions
Similar to previous commits (7332a1eb90), use three separate
functions for updating the bounds of different PBVH types. This avoids
the use of the vertex iteration macro. Also make the functions reusable,
so they can be called directly after a brush update in the future.
2023-12-04 08:36:02 -05:00
Hans Goudey
869ea79da0 Cleanup: Return PBVH vertex data arrays as spans 2023-12-04 07:55:47 -05:00
Hans Goudey
3b1d5d14f2 Cleanup: Remove unused DMFlagMat struct
Arrays were allocated and filled with data, but never read.
2023-12-04 07:55:47 -05:00
Hans Goudey
8171f719fe Subdiv: Remove unnecessary CCG derived flag structs
The copied the material index and its smoothness to every grid,
resulting in 4 bytes of memory per base mesh face corner. That's
wasteful, since it's trivial to loop up the original data from the base
mesh attributes as necessary. This way we can also avoid the
dereference.
2023-12-04 07:55:47 -05:00
Hans Goudey
5cd6a05f5e Cleanup: Store SubdivCCG in unique_ptr
Automatic memory management and clearer ownership! Requires
removing `MEM_CXX_CLASS_ALLOC_FUNCS` from `MeshRuntime`,
but that's used very inconsistently anyway, and `MeshRuntime` isn't
that large.
2023-12-04 07:55:47 -05:00
Hans Goudey
d73868d5a1 Subdiv: Inline grid to face map lookup function
I've seen this appear in profiles sometimes, which it really shouldn't,
since it's just a single array access. I didn't detect an observable
difference, but we don't have to think about that anymore anyway.
2023-12-04 07:55:47 -05:00
Hans Goudey
0b9ae3df4c Subdiv: Use base mesh faces and topology map for SubdivCCG
Instead of storing a redundant array of faces, use the base mesh faces
and corner_to_face map. This saves 8 bytes per base mesh face with
multires sculpting, and avoids recalculating the topology map whenever
reevaluating the object. There is a lot of other duplicate data between
base meshes and faces, particularly in `MeshTopology`. This is just
a first step of untangling that.
2023-12-04 07:55:47 -05:00
Hans Goudey
881ec8b1ed Cleanup: Return multires grid key by value 2023-12-04 07:55:47 -05:00
Hans Goudey
a9f847f94c Fix: Various issues with multires visibility undo
Push the undo step before changing any grid hide data, fix a missing
allocation in the undo step, and workaround some issue with temporary
BitVector<> construction that I couldn't quite figure out. Also fix a
crash when there is vertex mask attribute but no multires hiding.
2023-12-04 07:55:47 -05:00
Hans Goudey
7332a1eb90 PBVH: Refactor hide and mask update to be data oriented and reusable
Specialize the mask update for each PBVH type, simplifying hot loops,
reducing reliance on complex shared state and clarifying which data is
used. Expose functions to update the visibility and masks tags for a
specific node. It can be helpful to call these after modifying the data
to update the flags while the data is more likely to be in CPU caches.
2023-12-04 07:55:46 -05:00