Commit Graph

24135 Commits

Author SHA1 Message Date
Erik Abrahamsson
3195c1a669 Geometry Nodes: Add Sample Volume node
This commit adds a new experimental node "Sample Volume".
It's purpose is to be able to sample values from a volume grid given
a position field.
The 'Grid' input accepts a named attribute input with the name
of the volume grid to sample. Values will be implicitly converted
from the grid type to the specified value type.

Pull Request: #107656
2023-05-16 19:08:08 +02:00
Bastien Montagne
cc498697ab Cleanup: Core: lib_query: Make names of self and owner ID data consistent.
Internal private struct was using `owner_id`/`self_id`, while the public
callback data struct was using `id_owner`/`id_self`.

Now using internal naming everywhere in lib_query related code, as
`owner_id` is already used in very low-level 'fundamental' part of the
code, e.g. in the `PointerRNA` struct, or in ID's 'loopback' pointers
for embedded data.

Note that this is only a very small first step toward proper naming
consistency for these type of data, the mismatch is currently spread all
over the code base.

We also need to document more formally the meaning and differences
between `self` and `owner` here.
2023-05-16 18:37:35 +02:00
Hans Goudey
859c0d9edf Cleanup: Remove redundant node type lookup function
Using the topology map gives a constant time lookup, since it has a map
of nodes per type. The collada code used the old function, but had been
ifdef'd for four years, so it's removed here.
2023-05-16 11:09:42 -04:00
Hans Goudey
d87547abd5 Cleanup: Remove unused node function for finding link
Nowadays it's much better to use the topology cache.
2023-05-16 09:44:41 -04:00
Hans Goudey
320ac28f75 Cleanup: Remove unnecessary struct keywords in node header 2023-05-16 09:43:05 -04:00
Hans Goudey
f3babec2df Cleanup: Undo move of functions in previous node cleanup commit
Functions were moved as part of f7388e3be5, which was
unnecessarily noisy. Instead of reverting, move the definitions back
to their original place in node.cc. Also move a few more things to
the blender::bke namespace.
2023-05-16 09:39:53 -04:00
Germano Cavalcante
932baa18b7 Fix #106558: Add Primitive tool options not saving
Since a generic snap cursor was implemented (which can be used by Tools and by DragDrop), the Placement Settings are no longer a settings of the "VIEW3D_OT_interactive_add" Operator.

With that implementation, those properties started to be defined in a
static struct, filled in at runtime and accessed in the UI through
workarrounds.

As they are properties initialized at runtime, they are not saved in
the file.

The solution is to move the Placement Settings to `ToolSettings`.

Co-authored-by: Germano Cavalcante <germano.costa@ig.com.br>
Pull Request: https://projects.blender.org/blender/blender/pulls/107951
2023-05-16 15:00:45 +02:00
Campbell Barton
36c682c551 Cleanup: remove redundant call to mat4_to_size 2023-05-16 14:41:21 +10:00
Campbell Barton
802af4e04b BLI_file: split BLI_rename into two functions
Include the term "overwrite" so users of this function are aware
this function will delete the destination file (unlike LIBC rename).

- Add BLI_rename_overwrite (previously called BLI_rename).
- BLI_rename is now a wrapper for rename.

Use BLI_rename when renaming in the file selector.
2023-05-16 13:15:48 +10:00
Iliya Katueshenock
f7388e3be5 Cleanup: Move BKE_node.h to C++
See: https://projects.blender.org/blender/blender/issues/103343

Changes:
1. Added `BKE_node.hh` file. New file includes old one.
2. Functions moved to new file. Redundant `(void)`, `struct` are removed.
3. All cpp includes replaced from `.h` on `.hh`.
4. Everything in `BKE_node.hh` is on `blender::bke` namespace.
5. All implementation functions moved in namespace.
6. Function names (`BKE_node_*`) changed to `blender::bke::node_*`.
7. `eNodeSizePreset` now is a class, with renamed items.

Pull Request: https://projects.blender.org/blender/blender/pulls/107790
2023-05-15 15:14:22 +02:00
Bastien Montagne
2a8c20853c Fix LibOverride broken resync behavior in some cases after recent changes.
The issue was that in case an ID was only related to its liboverride
hierarchy through a 'to' pointer (e.g. the parent pointer of an object),
it would now be tagged as 'isolated' from its hierarchy, since nothing
in said hierarchy actually points to it. It would then be deleted during
resync process.

This is once again the infamous 'inverted dependency logic of object
parenting' case...

Note that this did not have any consequences on typical liboverride
usages (based on using a hierarchy of collections0, since all objects
would then be referenced by one or more collection.

Reported by @dr.sybren while investigating #102662.
2023-05-15 13:47:15 +02:00
Campbell Barton
5285cd9a7b BLI_path: use native normalize (avoids // prefix on UNIX) 2023-05-15 19:58:39 +10:00
Sybren A. Stüvel
51c2a0f816 Fix #104606: iTaSC solver moves root bone to origin and imobilizes it
Add a new flag that determines whether root bones (i.e. bones without a
parent) should be translated to the armature object's origin. This can
be found in the Armature's IK properties panel.

By default this flag is disabled, so new rigs will not see this 'locking
to the origin' behaviour. Versioning code ensures that the flag is
enabled on older files, to preserve the behaviour of existing rigs.

This also bumps the Blender subversion and at the same time fixes an
incorrect bump in ee08b2ddff (where the
'minimum compatible version' was updated instead of the current Blender
version).

Pull request: https://projects.blender.org/blender/blender/pulls/107869
2023-05-15 10:46:26 +02:00
Campbell Barton
13a3dfd788 BLI_path: remove FILE_MAX limit on BLI_path_frame{_range} functions
- Use BLI_str_replace_range to avoid a temporary string copy.
- Also add a buffer size argument to BLI_path_frame_range.
2023-05-15 09:09:08 +10:00
Bastien Montagne
b960a4fdb8 Fix (unreported) BKE_main_id_refcount_recompute wrong handling of some ID types.
Scene, WindowManager and Workspace types of IDs should always have a
'virtual' user, to ensure they are always written to file.
2023-05-13 19:26:02 +02:00
Bastien Montagne
5a2f159ba4 Cleanup: Minor fixes to comments and CLOG reports. 2023-05-13 19:24:41 +02:00
Campbell Barton
bfeb687cb4 Remove use of FILENAME_MAX
GCC documented FILENAME_MAX is the maximum length of a file that can
be opened, not to be used for allocation as it may be INT_MAX for e.g.

Even though this wasn't the case on supported systems,
prefer FILE_MAX which is used for full paths in most places.
2023-05-13 17:54:16 +10:00
Campbell Barton
169dd2a2b4 Use UTF8 copy function to ensure valid UTF8 output 2023-05-13 17:38:48 +10:00
Campbell Barton
a534e05476 Cleanup: use dirpath & filename for directories and file names
Use `filename` instead of `names`, `dirpath` instead of `dir`.
2023-05-13 17:34:29 +10:00
Campbell Barton
e89939ca26 Cleanup: reserve the term 'len' for string length 2023-05-13 17:34:23 +10:00
Hans Goudey
ee08b2ddff Geometry Nodes: Add display toggle for simulation cache in timeline
Similar to the existing options for toggling physics cache display.
2023-05-12 13:48:52 -04:00
Hans Goudey
34e29440f7 Fix #107151: Multires data from external file is not loaded
Making the custom data API const correct in 3a3d9488a1 caused
the issue, because it previously relied on non-threadsafe behavior. As a
workaround, just restore the thread-unsafety, and note the issue in a
new comment.
2023-05-12 13:48:11 -04:00
Bastien Montagne
3b647faec8 Fix (unreported) three wrong next/prev pointers order in ListBase link structs.
There was even one case in BLI ListBase tests!

Order was opposite of the one expected by the BLI ListBase code... Not
sure how, but this did not cause any issue apparently? But would expect
it to at least affect the order in which items in the list would be
iterated.
2023-05-12 19:02:39 +02:00
Bastien Montagne
ddd6e05c8d BKE: Collection: Add a basic validation tool for collections.
Mainly for debug purposes, makes it easy to detect invalid collections
(e.g. having more than once a same collection as child).
2023-05-12 19:02:39 +02:00
Bastien Montagne
4ecbb3f1d5 Fix IDManagement remapping missing some required remapping with some liboverrides.
`BKE_library_id_can_use_filter_id` would not handle properly cases where
the ID is a liboverride - it's hierarchy root pointer can point back to
virtually any kind of ID (although typically a Collection or Object).

This was breaking liboverride resync process in some rare cases, by
failing to remap the 'hierarchy root' pointer of some liboverrides.
2023-05-12 17:02:18 +02:00
Hans Goudey
4f2ac09886 Cleanup: Reduce binary size by deduplicating attribute processing
This makes the Blender binary 350 KB smaller. The largest change comes
from using `FunctionRef` instead of a template when gathering indices to
mix in the extrude node (which has no performance cost). The rest of the
change comes from consolidating uses of code generation for all
attribute types. This brings us a bit further in the direction of
unifying attribute propagation.

Pull Request: https://projects.blender.org/blender/blender/pulls/107823
2023-05-12 14:44:39 +02:00
Erik Abrahamsson
36983fb5e4 Geometry Nodes: Add 'Signed Distance' input node
Adds an input node Signed Distance that can
be used to refer to the distance-grid of an SDF volume.
Right now it's experimental and can be enabled by enabling
"New Volume Nodes" in the preferences.

It returns a float AttributeFieldInput called 'distance' which
can tell Volume nodes which grid to get.

See #103248.
2023-05-11 18:25:34 +02:00
Bastien Montagne
6f3cf1e436 LibOverride: Fix resync process no properly tagging newly used linked data as directly linked.
LibOverride resync process would not properly 'make local' newly created
overrides (copied from their linked reference). The main consequence was
that some linked data used by these new liboverrides would not be
properly tagged as directly linked.

While this would not be an issue in current codebase, this was breaking
upcomming readfile undo refactor, since some linked data did not get
their local 'placeholder reference' data written in memfile blendfiles.

NOTE: this is more of a quick fix, whole handling of library data in
complex copying cases like that need some more general work, see #107848
and #107847.
2023-05-11 15:55:57 +02:00
Chris Blackbourn
8612dfea44 Cleanup: format 2023-05-11 12:08:28 +12:00
Iliya Katueshenock
939f7e8010 Fix: Empty built-in attributes are duplicated by some nodes
The attributes API does not have the error that a null attribute
does not exist and requires a new layer to be created.

Pull Request: https://projects.blender.org/blender/blender/pulls/107814
2023-05-10 17:40:37 +02:00
Bastien Montagne
de21a0c901 Fix (unreported) remapping code wrongly skipping UI data when it should not.
Issue was that, when UI-related code _is_ requested in foreach_id
processing, `ID_SCR` screen ID type can actually use any kind of ID
(through e.g. the Outliner space).

So `BKE_library_id_can_use_filter_id` had to be updated with a new
parameter (whether UI-related data should be taken into account or not).
2023-05-10 16:36:29 +02:00
Bastien Montagne
ade83b21d1 Fix (unreported) crash in readfile code when deleting an invalid shapekey.
The root of the issue was that while reading a new blendfile, the
current `G_MAIN` is still the old one, not the one in which new data is
being read.

Since the remapping callback taking care of UI data during ID remapping
is using `G_MAIN`, it is processing the wrong data, so when deleting the
invalid shapekey (from `BLO_main_validate_shapekeys`), the UI data of
the new bmain would not be properly remapped, causing invalid memory
access later when recomputing user counts (calls to
`BKE_main_id_refcount_recompute`).

This is fixed by adding a new `BKE_id_delete_ex` function that takes
extra remapping options parameter, and calling it from
`BLO_main_validate_shapekeys` with extra option to enforce handling of
UI data by remapping code.

NOTE: At some point we have to check if that whole UI-callback thing is
still needed, would be good to get rid of it and systematically process
UI-related ID pointers like any others. Current situation is... fragile
to say the least.
2023-05-10 16:35:49 +02:00
Hans Goudey
8efd6d5f82 Geometry Nodes: Make simulation caching optional
For realtime use cases, storing the geometry's state in memory at every
frame can be prohibitively expensive. This commit adds an option to
disable the caching, stored per object and accessible in the baking
panel. The default is still to enable caching.

Pull Request: https://projects.blender.org/blender/blender/pulls/107767
2023-05-10 16:01:38 +02:00
Philipp Oeser
c7e9932c46 Fix #107677: Hair particle edit wrong on object with mirror modifier
Caused by 2fb31f34af.

Since above commit, we are now calling `BKE_mesh_orco_verts_transform`
not only from `psys_face_mat` and `psys_mat_hair_to_orco`, but now also
from `psys_particle_on_dm` > `psys_interpolate_face`, so we get double
transforms with mirror.

Remove the "extra" call in `psys_mat_hair_to_orco`.

Should be backported to 3.3 LTS as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/107804
2023-05-10 15:16:18 +02:00
Philipp Oeser
179c419115 Fix #107608 : Changing color for simulation zone doesn't save
This looks like a missing version bump for 0de54b84c6, now added.
Also included the change for 493c4dd65b here.

Pull Request: https://projects.blender.org/blender/blender/pulls/107808
2023-05-10 15:06:50 +02:00
Jacques Lucke
db6eda6c60 Geometry Nodes: show simulated frames only when there is a simulation
Previously, the timeline would sometimes show cached frames even when
there is no simulation zone in the node tree.
2023-05-10 14:41:37 +02:00
Hans Goudey
17d161f565 Mesh: Reduce custom normal calculation memory usage
Avoid storing redundant and unnecessary data in temporary arrays during
face corner normal calculation with custom normals. Previously we used
96 bytes per normal space (`MLoopNorSpace` (64), `MLoopNorSpace *` (8),
`LinkData` (24)), now we use 36 (`CornerNormalSpace` (32), `int` (4)).
This is achieved with a few changes:
- Avoid sharing the data storage with the BMesh implementation
- Use indices to refer to normal fan spaces rather than pointers
- Only calculate indices of all corners in each fan when necessary
- Don't duplicate automatic normal in space storage
- Avoid storing redundant flags in space struct

Reducing memory usage gives a significant performance improvement in
my test files, which is consistent with findings from previous commits
(see 9fcfba4aae). In my test, the time used to calculate
normals for a character model with 196 thousand faces reduced from
20.2 ms to 14.0 ms, a 44% improvement.

Edit mode isn't affected by this change.

A note about the `reverse_index_array` function added here: this is the
same as the mesh mapping functions (for example for mapping from
vertices to face corners). I'm planning on working this area and hoping
to generalize/reuse the implementation in the near future.

Pull Request: https://projects.blender.org/blender/blender/pulls/107592
2023-05-10 14:41:10 +02:00
Campbell Barton
ee09d75e80 Cleanup: naming of looptri indexing variables
looptris were referred to as both tris & faces, sometimes polygons
were referred to as faces too. Was especially error prone with
callbacks that took both a tri and a tri_i arguments.
Sometimes tri_i represented a looptri index, other times the corner of
the triangle from 0-2. Causing expressions such as:
`args->mlooptri[tri].tri[tri_i]`

- Rename tri & tri_index -> looptri_i.
- Rename faces -> looptris.
- Rename face_index/poly_index/poly -> poly_i.
- Declare looptri_i at the start of the loop and reuse it,
  in some cases it was declared with args->prim_indices[i] being
  used as well.
2023-05-10 14:21:39 +10:00
Hans Goudey
ac02f94caf Fix #107123: Refactor sculpt normal calculation to require vert poly map
Change PBVH normal calculation to also update vertices connected to
vertices with an update tag. This is necessary because vertex normals
are the mixed face normals, so changing any face's normal will change
the normals of all connected faces.

This change requires that the PBVH always have a vertex to face
topology map available. In the future this will likely be cached on
meshes though, which will reduce the delay it adds when entering sculpt
mode.

Now, first all face normals are updated, then the normals for
connected vertices are mixed from the face normals. This is a
significant simplification to the whole process, which previously
worked with atomics and normals at the triangle level. Similar changes
changes for regular non-sculpt normal calculation are being worked on
in #105920.

Pull Request: https://projects.blender.org/blender/blender/pulls/107458
2023-05-09 22:36:30 +02:00
Hans Goudey
3a0d17ceea Cleanup: Correct commet about curves bounds
Missing from 97a8bb450c
2023-05-09 13:03:08 -04:00
Sybren A. Stüvel
8ce040cf1a Anim: avoid increasing NULL pointer
Avoid calling `next++` when `next` is `NULL`.

In practice this should be a non-functional change, but it avoids ASAN
messages.
2023-05-09 16:05:40 +02:00
Sybren A. Stüvel
5532d05622 Anim: remove assumption of array_index order when blending quaternions
The pose library blending code assumed that quaternions would be keyed
in order of `array_index`. This is normally the case when creating a
pose asset, but when manually editing a pose asset Action this
assumption may not hold.

The code still assumes that all FCurves of a single quaternion are
sequential, i.e. are not inter-mixed with other keyed properties. They
just no longer have to be ordered by array index.

Ref: blender-addons/issues#104591
2023-05-09 11:26:27 +02:00
Campbell Barton
788a57c6ef Cleanup: reserve the suffix 'len' for string length 2023-05-09 15:02:12 +10:00
Campbell Barton
3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Hans Goudey
e151425c5c Fix #107694: Assert adding custom normals to empty mesh 2023-05-08 18:41:06 -04:00
Hans Goudey
150943e084 Cleanup: Move remaining sculpt_paint files to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107757
2023-05-08 23:48:38 +02:00
Hans Goudey
ce96abd33a Fix: Build error after simulation header cleanup
Making the geometry state's geometry public to remove
the accessors didn't work without the constructor.
2023-05-08 17:21:15 -04:00
Hans Goudey
2f349ce884 Cleanup: Add comments to simulation state header
Pull Request: https://projects.blender.org/blender/blender/pulls/107744
2023-05-08 21:42:38 +02:00
Bastien Montagne
527b21f0ae LibOverride: Restore local references to virtual linked liboverrides on resync.
When resyncing linked liboverride data, new IDs may be created that do
not exist in actual library file (since the lib file has not been resynced).

If such 'virtual linked liboverrides' data-blocks are used locally (e.g.
by adding such object to a local collection), on next file read they will be
detected as missing.

Now resync code will list such missing linked IDs that were
liboverrides, and try to re-use them when matching (by root name and
library) with newly generated virtual liboverrides.

The process may not be 100% perfect, especially a perfect one-to-one
remapping cannot be ensured if source data keep being changed over and
over (because of the order in which virtual linked liboverrides
generated by resync may change over time). However, in practice this
should fix the vast majority of issues, especially if sane naming
practices are used on IDs.

---------------

For the record, an attempt was made to write liboverride data together
with the placeholders for linked IDs in .blendfile. In theory, this
should ensure a perfect and fully valid re-usage of such IDs.

However, for this to work, not only the liboverride data of linked IDs need
to be written on disk, but also all ID references in this data has to be
considered as directly linked, to ensure that such liboverride data can
be re-read properly.

Otherwise, these placeholders would get a liboverride data with NULL ID
pointers, which is useless.

Such change feels way to intrusive for the very limited benefit, so for
now would consider current solution as the best option.

Pull Request: https://projects.blender.org/blender/blender/pulls/107144
2023-05-08 18:22:33 +02:00
Lukas Tönne
304e8a842d Fix: editor crashes during simulation bake
Fixes crashes in timeline and spreadsheet editors during simulation
nodes baking:
* Timeline tries to access the `states_at_frames_` list of the cache to
  determine which frames to draw as baked. This can collide with the
  baking thread. Needs a mutex to safely access the cache state.
  Note: the old point cache has a pre-allocated flag array
  `cached_frames` which the baking thread writes into while timeline is
  reading it concurrently - not thread-safe but harmless.
* Spreadsheet keeps a data pointer during drawing, which may become
  deallocated when the cache is updated. Common approach here is to use
  `G.is_rendering` to lock the editor while baking.

Pull Request: https://projects.blender.org/blender/blender/pulls/107621
2023-05-08 14:34:21 +02:00