Commit Graph

24109 Commits

Author SHA1 Message Date
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
Sybren A. Stüvel f3be425e97 Fix Pose Library: crash when using partially-keyed quaternions
Remove the assumption that quaternions are always fully keyed in a pose
asset. Even though quaternions really should be fully keyed, better not
make Blender crash when this assumption doesn't hold.

If the quaternion is only partially keyed, the other components are taken
to be from the unit quaternion (`[1, 0, 0, 0]`) and the result is
normalized before blending into the existing pose.

This fixes blender/blender-addons#104591, which was reported against the
pose library add-on, but actually was caused by an issue in Blender.
2023-05-08 13:54:07 +02:00
Bastien Montagne 3c2dc42712 Fix (studio-reported) crash in liboverride resync code after recent changes. 2023-05-08 12:46:03 +02:00
Jacques Lucke ae1c52b3f2 Cleanup: remove dead code 2023-05-08 11:48:01 +02:00
Jacques Lucke c3365666e5 Fix #107637: crash when using density brush on empty hair 2023-05-08 09:26:15 +02:00
Campbell Barton bb5a22539c Cleanup: correct path size argument
BKE_appdir_folder_documents clamps to FILE_MAXDIR internally.
2023-05-08 12:49:44 +10:00
Campbell Barton 64674b10d1 Cleanup: quiet compiler warnings 2023-05-08 11:47:27 +10:00
Lukas Stockner 893bd37bc0 Cleanup: formatting 2023-05-08 01:20:41 +02:00
Damien Picard 31d71f39ad UI: fix or improve many messages
- The official spelling of FFMPEG is FFmpeg (upper, then lower case).
- The normal vector copy and paste operators shoud be singular because
  they can only be used on a single element.
- The "Parent File" file browser operator goes up one level in the
  file hierarchy. It should be called "Parent Directory", like the
  current description "Go to the parent directory".
- "Mass Vertex Group" used to define the mass, but was reused at some
  point and now actually defines cloth pinning so it should be called
  "Pin Vertex Group", as in the UI.
- The Transformation constraint's Map To Type suffered from a
  typo (probably of -> on).
- "Fall-off" is more commonly spelled "Falloff".
- "Effected" should really be "Affected" in this case.
- Rephrase the descriptions for the curve painting tools drawing
  plane, which did not seem to match what the settings do. Namely,
  they allow selecting in which plane to draw curves using the Curve
  Draw tool.

Reported by @Joan-Pujolar in #43295:
- Force exporting animation on every objects [objects singular]
- Color of the interface widgets text insertion cursor (caret) [delete
  interface widgets]
- Index of active aov [AOV in uppercase everywhere else]
- Does this tool use an painting canvas [an]
- This script was written Blender version %d.%d.%d ["for" missing
  before "Blender"]
- [fcurve -> F-curve]
- unknown error stating file [statting]
- Offset into each stroke before the beginning of  the dashed segment
  generation [Two spaces between of and the]
- Find the nearest element in the a group. [either "the" or "a"]

Pull Request: https://projects.blender.org/blender/blender/pulls/107699
2023-05-07 15:27:28 +02:00
Campbell Barton f7d3115d97 Cleanup: replace BLI_strncpy with memcpy when the size is known
Also remove temporary filename buffer which is no longer needed.
2023-05-07 16:55:40 +10:00
Campbell Barton 0d1362bfd7 Cleanup: spelling in comments 2023-05-07 16:46:37 +10:00
Campbell Barton df54b627b3 Cleanup: use of the term 'len' & 'maxlen'
Only use the term len & maxlen when they represent the length & maximum
length of a string. Instead of the available bytes to use.

Also include the data they're referencing as a suffix, otherwise it's
not always clear what the length is in reference to.
2023-05-07 16:46:37 +10:00
Bastien Montagne 07dfc6eccc LibOverride: Further fixes/improvements to partial recursive resync process.
This addresses the 'liboverrides still tagged for resync after resync
process' error reports.

Turns out, this situation is (unfortunately) normal in some rare cases,
hwne the hierarchies in the liboverride and the reference data have
drastically diverged.Since the detection of liboverrides to resync, and
which one are valid partial resync roots, happens on the 'old' override
hierarchy, it may not match the actual hierarchy recreated from the
reference data, leading to some part of it being ignored by the resync
code.

There is no real way to avoid this situation, the only thing that can be
done is detect it, and re-process the resync code again when it happens.

From quick limited tests in (extremely dirty/outdated) Pets production files,
most of the time only one resync process is needed. Worst case so far
required 5 reprocessing of the same set of data.

There is no error messages from resync anymore in these tests, so at the
very least resync process should now be significantly more reliable than
before...
2023-05-06 16:27:50 +02:00
Bastien Montagne 40d79e3d2b LibOverride: Fix/Improve partial resync detection code.
This issue tackled here is essentially the same as in ac1ac6be9a
(recursive Purge of unused IDs could delete actually used IDs): handling
of dependency loops is extremely delicate...

This commit essentially rewrites from scratch the code that ensures that
all liboverrides and their dependencies that need it are tagged for resync,
and identifies the partial resync roots.

Dependency loops whitin a hierarchy make this process very complex, as
they can lead to having to recursively process more than once some IDs.
Partial resync roots are also a source of complexity, since some IDs may
be detected a potential roots, and later as dependencies of another
partial resync hierarchy.

This new code generates waaaaaayyyyy less error messages when resyncing
nightmare-like production files (i.e. production files which libraries
have been _heavily_ modified). There are still a few error reports in
some cases though, which are the synptoms of another issue that will be
fixed in the next commit.
2023-05-06 16:21:46 +02:00
Bastien Montagne 370a2bb416 LibOverride: Resync: Do not ignore embedded IDs in hierarchy processing.
While in practice this was probably not a big issue (since usually e.g.
objects used by a nodetree would also be used by other objects or
collections in the liboverride hierarchy), in some corner cases it could
have caused missing 'tag for resync' and improper partial resync roots
detection.
2023-05-06 12:36:52 +02:00
Bastien Montagne bd412c9e71 Fix crash when accessing length of material_slots on evaluated Empty object.
`BKE_object_material_count_eval` did not take into account the Empty
object case at all.
2023-05-06 12:25:45 +02:00
Campbell Barton f665b73c89 RNA: replace BLI_strncpy with strcpy/memcpy when the size is known
Follow up on [0] handle remaining cases where BLI_strncpy was used
it RNA string get callbacks.

[0]: c891dbd162
2023-05-05 14:01:57 +10:00
Campbell Barton 6796cce11d Refactor: add a function to access images extensions from it's format
Previously accessing the extension needed to ensure an extension
on an empty path.

This conflicted with DEBUG_STRSIZE as it was assumed the input was
FILE_MAX, where as it was a small buffer with RNA, see: !107602.

Resolve by separating the function that ensures the extension
with the function that finds valid extensions for a format.

Also pass the size of the filepath to functions that ensure the
extension.
2023-05-05 14:01:57 +10:00
Joseph Eagar f15889a9f9 Sculpt: Split face set visibility invert into its own operator
Visibility invert should not use OPTYPE_DEPENDS_ON_CURSOR.
2023-05-04 17:49:40 -07:00
Campbell Barton e5598d067b BKE_image: simplify UDIM tile label access, return string length 2023-05-05 10:26:17 +10:00
Joseph Eagar a79272a790 Sculpt: fix broken pbvh draw
foreach_faces now passes looptri index instead of a
MLoopTri pointer.
2023-05-04 17:09:53 -07:00
Campbell Barton 831bacec92 Cleanup: use function style casts & nullptr in C++ code 2023-05-05 09:46:28 +10:00
Campbell Barton ba3d7499fa Cleanup: spelling, use term polygons in polygon callbacks 2023-05-05 09:46:28 +10:00
Campbell Barton 49c09d7640 Cleanup: remove inline pointcache extension stripping
No need to perform inline, and it would not have worked properly for
*.blend1 files.
2023-05-05 09:46:28 +10:00
Hans Goudey 730b11034f Cleanup: Move remaining modifier files to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107626
2023-05-04 18:35:37 +02:00
Sergey Sharybin eca8e6bf5e Refactor: Convert mask module to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/107615
2023-05-04 17:36:01 +02:00
illua1 239c1194a0 Fix #107545: Mistakes in recent node.cc cleanup
1. Early return needs inverted null checking.
2. `BLO_expand` macros expect value, not a pointer.

Pull Request: https://projects.blender.org/blender/blender/pulls/107622
2023-05-04 16:32:15 +02:00