Commit Graph

1549 Commits

Author SHA1 Message Date
Lukas Tönne
5c57e24fea Cleanup: GPv3: Remove unused BKE functions from GPv2
Removes unused GPv2 functions in blenkernel.

Notes:
-  Functions for layer masks are still in use, but annotations never
  have layer masks in the first place. Would be good to remove the data
  structures so we can remove the functions too.
- Some multi-frame edit functions are also still nominally used, but
multi-frame editing is not an active feature for annotations. This
  should also be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/128709
2024-10-09 10:27:45 +02:00
Campbell Barton
8c3ef77a35 Cleanup: spelling in comments 2024-10-08 09:03:49 +11:00
Pablo Delgado Krämer
384f64f215 Fix Hydra crash with UsdPreviewSurface render delegates
When a render delegate does not use MaterialX (by setting
`bl_use_materialx = False` in engine.py), a crash can occur because the
worker_status is null.

Pull Request: https://projects.blender.org/blender/blender/pulls/128607
2024-10-07 21:29:48 +02:00
Lukas Tönne
a57206dd59 GPv3: Remove unused legacy editor functions for GPv2
Removes all unused functions in ED_gpencil_legacy.hh

Pull Request: https://projects.blender.org/blender/blender/pulls/128597
2024-10-07 18:21:28 +02:00
Jesse Yurkovich
1676c06386 Fix #128504: check instancer purpose and visibility before processing
During stage load we first look for Prototype prims which are used for
instancing. However, if the instancer itself at the root of that
Prototype hierarchy would later be excluded because of either purpose or
visibility checks, the Prototypes would still be processed. These would
correctly be imported but would end up orphaned because nothing would
later add them to the view layer. Code expecting these objects to be
found within the scene would then fail.

In Animal Logic ALab this situation played out where there was a
`/root/instancer` prim with purpose "render" and we proceeded to load
the prims under the `/root/instancer/Prototypes/...` hierarchy. Since we
were attempting to load just the "proxy" purpose, the `/root/instancer`
was later excluded and the orphaning of those prototypes happened.

The change here moves `collect_point_instancer_proto_paths` to a method
of `USDStageReader` so it can now access `include_by_purpose` and
`include_by_visibility`. And these are now used to prevent unnecessary
Prototype loading.

Pull Request: https://projects.blender.org/blender/blender/pulls/128564
2024-10-07 18:08:22 +02:00
Campbell Barton
0b8ce96bc1 Cleanup: quiet warnings, spelling 2024-10-04 11:45:26 +10:00
Jesse Yurkovich
80cf6b99c3 USD: Provide Import option for Material Purpose
USD has the concept of material "purposes" which allows different
materials to be associated for a prim and gives special meaning to them.
These are somewhat similar to display purposes, which we already allow
to be chosen, but are distinct concepts. This PR adds an option for
Import allowing the user to chose which material purpose to load.

Blender currently attempts to load purposes automatically. It starts
with "allPurpose" and then moves to "preview" and "full" in that order.
This behavior is now changed and the automated search is removed to
instead give the user control which purpose to load. Additionally, USD
already has its own fallback behavior during material resolution[1]:
- When given "full" it will first check "full" and fallback to
  "allPurpose" if not found. An additional, Blender-specific fallback
  to "preview" is also implemented here upon request.
- When given "preview" it will first check "preview" and fallback to
  "allPurpose" if not found
- When given "allPurpose", it will only check "allPurpose"

I have opt'd to keep this behavior directly as-is to not introduce
differences that may surprise those already familiar with USD elsewhere.

Additionally, I've set Blender's default import purpose to "full" to
ensure we're loading in the highest quality assets first. Though this
has the obvious risk that "full" assets tend to be quite heavy. We can
change to "preview" if this proves too problematic later.

This does not change how Blender exports materials. Blender always uses
the "allPurpose" binding when writing its USD files.

--------
[1] USD docs:
https://openusd.org/release/api/class_usd_shade_material_binding_a_p_i.html#details
https://openusd.org/release/api/class_usd_shade_material_binding_a_p_i.html#UsdShadeMaterialBindingAPI_MaterialResolution

Pull Request: https://projects.blender.org/blender/blender/pulls/128206
2024-10-03 20:16:27 +02:00
Campbell Barton
4fa3dc0dd4 Cleanup: spelling in comments, use uppercase tags 2024-10-03 12:11:52 +10:00
Jesse Yurkovich
4a679470b6 Fix: USD: collection creation during import assigned extra fake user
When using the `create_collection` parameter during import, the newly
created Collection would be assigned a fake user which isn't necessary
and caused the user count to be 2 instead of the more natural 1 here.

Remove the fake user and add test coverage for the scenario in general.

Pull Request: https://projects.blender.org/blender/blender/pulls/128348
2024-10-02 19:53:50 +02:00
Pratik Borhade
d7fb60be4d Fix #128461: GPv3: Crash importing svg with more than one drawing
Wrong `points_num` when resizing the `CurvesGeometry`.
Otherwise, any attriute span will have wrong size, this triggers crash
when writing value in these attribute spans.

Pull Request: https://projects.blender.org/blender/blender/pulls/128472
2024-10-02 11:48:28 +02:00
Campbell Barton
0f3fdd25bc Cleanup: various non-functional changes for C++
- Remove redundant parenthesis
- Use strings macros
- NULL -> nullptr
2024-10-02 15:47:05 +10:00
Hans Goudey
751e009898 Cleanup: Remove unused variables in USD attribute writing 2024-09-28 10:26:22 -04:00
Jesse Yurkovich
63a4b45b43 Cleanup: USD: take advantage of new AttributeIter::get API
Make use of the potentially more efficient `AttributeIter::get` API.

Pull Request: https://projects.blender.org/blender/blender/pulls/128211
2024-09-27 21:38:01 +02:00
Jesse Yurkovich
6c62fe7ac8 Fix: Hydra memory leak when generated images are saved
When attempting to cache a generated image, the ImageFormatData's
view_settings would inadvertently be leaked due to the settings being
assigned a different set of values without first being free'd.

Additionally, there was another missed free from an early return a bit
later in the same function.

Pull Request: https://projects.blender.org/blender/blender/pulls/128229
2024-09-27 19:21:11 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Jacques Lucke
6810084a47 Attributes: improve API to iterate over attributes
This improve the API in multiple aspects:
* No need for an additional `lookup` call to get the current attribute. This
  would internally iterate over all attributes again. This leads to O(n^2)
  behavior. Note that there are still other reasons for O(n^2) behavior when
  processing attributes (where n is the number of attributes).
* Remove the need to return a value from the iteration code to indicate that the
  iteration should continue. This is now the default behavior. The iteration can
  still be stopped by calling `iter.stop()`.
* Easier access to `is_builtin` property.
* Iterator callback only has a single parameter instead of two (of which one is
  sometimes unused).

Pull Request: https://projects.blender.org/blender/blender/pulls/128128
2024-09-26 12:59:00 +02:00
Campbell Barton
473bd60164 Cleanup: clarify arguments using const or r_ prefixed return args 2024-09-26 15:03:24 +10:00
Bastien Montagne
91e4bcd204 Refactor: Move BPY intern bpy_rna headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Jesse Yurkovich
9e11e95817 Cleanup: remove unused CacheReader_incref APIs
These were unused since 89826e0a0d.

Pull Request: https://projects.blender.org/blender/blender/pulls/128091
2024-09-24 22:40:06 +02:00
Jesse Yurkovich
e045471259 Cleanup: remove unused functions from usd_blend_shape_utils
These have been unused since the initial commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/128049
2024-09-24 19:07:03 +02:00
Jesse Yurkovich
2cdbe7b5f3 Fix: USD: Support color attributes on all relevant domains
Color primvars/attributes were historically treated as a special case
for both import and export. This was mostly done to align with how
painting and viewport display works in Blender. Export would generally
ignore color attributes except when they were found on a Mesh's Point or
FaceCorner domains. And import went out of its way to map incoming color
primvars to the FaceCorner domain in more situations than necessary.

To facilitate better roundtripping in Blender<=>USD workflows, and to
reduce code duplication, this PR teaches the common attribute utilities
how to handle color types. The color attributes will now work on all
relevant Mesh and Curve domains.

There were tests in place for this already but they were set to verify
the inverse state, i.e. the technically broken state, until this could
be fixed.

There remains one special case: "displayColor" primvars and attributes.
The "displayColor" is a special primvar in USD and is the de-facto way
to set a simple viewport color in that ecosystem. It must also be a
color3f type. In order to not regress import, if a "displayColor"
primvar is found on the Face domain we will map it to FaceCorner instead
so it can be displayed in the viewport; which has been the case for the
past several releases. We can drop this special-case if/when Blender can
display Face colors through the Viewport Shading "Attribute" color type.
Additionally, Blender will export this, and only this, color attribute
as a color3f.

Note: As was the case prior to this PR, the following 2 discrepancies
still prevent "perfect" round-trips:
- USD does not have an equivalent to Blender's byte colors; they are
  treated as float during IO
- Blender does not have an equivalent to USD's color3 types; they are
  treated as color4 during IO

Pull Request: https://projects.blender.org/blender/blender/pulls/127784
2024-09-24 19:05:55 +02:00
Nathan Vegdahl
629b3ccd42 Anim: update collada export code for slotted actions
The collada export code was directly using `action->curves` in its
export code, which doesn't work with slotted actions. This commit
updates that code to use wrapper functions that provide access to the
correct fcurves regardless of whether the action is slotted or not.

Note that the import code has not yet been updated, and is left for
a future PR.

Ref: #123424
Pull Request: https://projects.blender.org/blender/blender/pulls/128061
2024-09-24 17:47:57 +02:00
Nathan Vegdahl
4bfa0de388 Anim: update some uses of listbases of fcurves
Because we're moving to layered actions, which don't store their
fcurves in a list base, we need to update the places that assume the old
listbase-based structure.

This commit addresses the low-hanging fruit where code was previously
using the `LISTBASE_FOREACH` macro on a listbase of fcurves and it was
fairly obvious how to correctly update the code with minimal changes.
Other cases that either weren't immediately obvious or required
non-trivial code changes (or both) have been left for future PRs.
Additionally, uses of the list base that didn't use `LISTBASE_FOREACH`
were not investigated as part of this PR, whether trivial to update or
not.

Ref: #123424
Pull Request: https://projects.blender.org/blender/blender/pulls/127920
2024-09-24 09:59:48 +02:00
Jesse Yurkovich
e1a44ad129 Cleanup: various non-functional changes when reading usd attribute data
- Use `lookup_or_add_for_write_only_span` in more places
- Use `copy_from` when reading in positions for the few readers where
  this wasn't already being done
- Remove manual memory management when processing corner normals

Pull Request: https://projects.blender.org/blender/blender/pulls/128043
2024-09-23 21:16:44 +02:00
Jesse Yurkovich
bd841a92e2 Cleanup: move some constants inside the usd namespace and use constexpr
Pull Request: https://projects.blender.org/blender/blender/pulls/128042
2024-09-23 20:39:59 +02:00
Jesse Yurkovich
9be3c356d1 Fix: allow use of UDIM tile 1100 in USD
The UsdPreviewSurface spec was recently[1] updated to version 2.5 where
they now specify a full 10x10 grid as being supported. This just makes a
minor change on our side to accommodate this adjustment (as rare as it
may be).

[1] Looks to have been added as part of USD 23.11
https://openusd.org/release/spec_usdpreviewsurface.html#version-2-5-current-head

Pull Request: https://projects.blender.org/blender/blender/pulls/127989
2024-09-23 18:22:15 +02:00
Aras Pranckevicius
5a1cf200aa Fix #127542: OBJ material groups are not written unless .mtl file is also written
These two settings are not coupled together, one should be able to
export face material groups without exporting the .mtl file.
2024-09-23 10:16:25 +03:00
Aras Pranckevicius
958433194e Fix #127932: STL importer was not setting faces as sharp
To match what the previous Python STL importer was doing, and what
the documentation / tooltips say is happening, the imported mesh
faces should be marked as sharp. Do that.
2024-09-22 14:19:38 +03:00
Campbell Barton
b302f37952 Cleanup: remove/comment unused struct members & variables 2024-09-22 18:25:40 +10:00
Jesse Yurkovich
460aa3c231 USD: Point Cloud export support
Export Blender Point Clouds as `UsdGeomPoints` primitives.

Summary
- Adds the `USDPointsWriter` class
- Adds tests to ensure that animated positions, velocities, radii, and
  regular attributes are all written correctly (in a sparse format)
- Adds a new `export_points` operator property, mirroring the existing
  `import_points` option

Pull Request: https://projects.blender.org/blender/blender/pulls/126389
2024-09-20 19:57:12 +02:00
Bastien Montagne
3e03576b09 Add more control over ID renaming behavior.
This commit adds low-level logic in BKE to support three behaviors in
case of name conflict when renaming an ID:
1. Always tweak new name of the renamed ID (never modify the other ID
  name).
2. Always set requested name in renamed ID, modifying as needed the
  other ID name.
3. Only modify the other ID name if it shares the same root name with the
  current renamed ID's name.

It also adds quite some changes to IDTemplate, Outliner code, and
RNA-defined UILayout code, and the lower-level UI button API, to allow
for the new behavior defined in the design (i.e. option three from above list).

When renaming from the UI either 'fails' (falls back to adjusted name) or forces
renaming another ID, an INFO report is displayed.

This commit also fixes several issues in existing code, especially
regarding undo handling in rename operations (which could lead to saving
the wrong name in undo step, and/or over-generating undo steps).

API wise, the bahavior when directly assigning a name to the `ID.name`
property remains unchanged (option one from the list above). But a new
API call `ID.rename` has been added, which offers all three behaviors.

Unittests were added to cover the new implemented behaviors (both at
BKE level, and the RNA/Py API).

This commit implements #119139 design.

Pull Request: https://projects.blender.org/blender/blender/pulls/126996
2024-09-20 13:36:50 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
notrudyyy
1939eb03a7 Refactor: Mesh: Normalize input normals in set custom normals
To reduce code duplication in importers, modifies the C++
set_custom_normals API functions to normalize the input normals.

Reverts !124336, !124267, and !124261 as the normalization now
occurs in the API call.

Resolves #124358.

Pull Request: https://projects.blender.org/blender/blender/pulls/127814
2024-09-19 20:12:40 +02:00
Campbell Barton
b63aa7f713 Cleanup: use bool return value for image write functions 2024-09-19 13:08:14 +10:00
Campbell Barton
1d21c98fc8 Cleanup: quiet dangling-reference GCC warning 2024-09-15 23:14:05 +10:00
Campbell Barton
81e2ccbf2b Cleanup: spelling in comments 2024-09-13 10:56:26 +10:00
Jesse Yurkovich
cbdc7d7636 Cleanup: Remove old USD version guards
Remove old version guards relating to USD versions prior to 2111 which
released in Nov 2021.

The oldest supported version of Blender, 3.3 LTS which goes end of life
this month, was already using USD version 2203 released in March 2022.
Additionally, these guards give the illusion that compiling with old
versions prior to 2111 might work, which is neither guaranteed nor
tested for at this point.

Pull Request: https://projects.blender.org/blender/blender/pulls/127380
2024-09-11 21:45:22 +02:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Sybren A. Stüvel
3fdc9e9637 Refactor: convert BKE_action.h to C++
Move the contents of `BKE_action.h` into `BKE_action.hh` and remove
C-isms.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127407
2024-09-10 14:55:47 +02:00
Lukas Tönne
8aead3a6d9 Fix #126707: SVG export nodes wrong hierarchy ignores clipping
SVG was exported with all the paths in the base node, which breaks the
`clipPath` reference.

Pull Request: https://projects.blender.org/blender/blender/pulls/127355
2024-09-09 18:42:20 +02:00
Pratik Borhade
29160edd0b Fix #126702: GPv3: Export PDF selected frames exports some unselected frames
`frame_at()` returns previous keyframe of which the drawing is visible
at current framec. When previous keyframe is selected, all the intermediate frames
till iteration reach the next keyframe are also exported.
To fix this, look inside `frames()` map instead of `frame_at()`.

Pull Request: https://projects.blender.org/blender/blender/pulls/126779
2024-09-09 10:44:15 +02:00
Jesse Yurkovich
b520ae6efe Cleanup: Small non-functional cleanup in usd_writer_mesh
Changes include:
- Simplify active_uvmap_name handling
- Remove unneeded defaultTime global variable

Pull Request: https://projects.blender.org/blender/blender/pulls/127268
2024-09-06 23:34:51 +02:00
Jesse Yurkovich
832d243249 Fix #116615: Store Blender bone lengths on USD Skeletons
USD Skeletons (armatures) are joint-based rather than bone-based in
construction. This means that there's no native bone concept nor is
there any bone lengths. Currently, Blender's USD import uses an
estimation, roughly corresponding to the average distance between
joints in the entire Skeleton, to set the bone length in situations
where it's not obvious that 2 joints are directly connected. This is
imperfect but shouldn't affect actual functioning of the rig.

For armatures coming from external software this is probably the best we
can do. However, for armatures originating from Blender, we can use a
custom primvar to store the bone lengths directly. This allows Blender
armatures to be exported and re-imported in much better fidelity.

This is superior to prior techniques, like those employed by FBX, which
alter the actual Skeleton, inserting extra joints where unnecessary. Not
only is this detrimental when using these files in external software,
but it's still imperfect when importing back into Blender too.

Pull Request: https://projects.blender.org/blender/blender/pulls/126954
2024-09-05 20:37:22 +02:00
Jacques Lucke
871b25b219 Geometry: generalize attribute filters beyond just for anonymous attributes
This introduces the concept of an #AttributeFilter. It's used to tell a geometry
algorithm which attributes it should process/propagate and which can be ignored.

We already had something similar before named
`AnonymousAttributePropagationInfo`. However, as the name implies, this was
specific to anonymous attributes. This had some downsides:
* A lot of code had to be aware of the concept of anonymous attributes even if
  it did nothing special with anonymous attributes.
* For non-anonymous attributes we often had a separate `Set<std::string> skip`
  parameter. It's not nice to have to pass two kinds of filters around and to
  have to construct a `Set<std::string>` in many cases.

`AttributeFilter` solves both of these downsides.

Technically, `AttributeFilter` could also just be a `FunctionRef<bool(StringRef
attribute_name)>`, but that also has some issues:
* The `bool` return value is often ambiguous, i.e. it's not clear if it means
  that the attribute should be processed or not. Using an enum works better.
* Passing function refs around and combining them works, but can very easily
  lead to dangling references.
* The default value of a `FunctionRef` is "empty", i.e. it can't be called. It's
  generally more nice to not have a special case for the default value. Now the
  default `AttributeFilter` propagates all attributes without any extra handling
  on the call-site.

Pull Request: https://projects.blender.org/blender/blender/pulls/127155
2024-09-05 11:33:35 +02:00
Jacques Lucke
89ae1ba38a Attributes: remove AttributeIDRef in favor of just using strings
Previously, the `AttributeIDRef` wrapper was needed because it also had to
contain a pointer to an `AnonymousAttributeID`. However, since
b279a6d703 this is not necessary anymore.
Therefore we can use "raw" `StringRef` now which reduces the mental overhead
when working with attributes and also simplifies code.

Pull Request: https://projects.blender.org/blender/blender/pulls/127140
2024-09-04 16:13:03 +02:00
Campbell Barton
e34d9eeac7 Cleanup: use C-style comments, double quote Python text 2024-09-03 21:22:34 +10:00
Aras Pranckevicius
c4a67ec3c7 Fix #127022: PLY export does not properly clamp vertex colors
PLY always exports vertex colors as bytes currently, but the input
values were not properly clamped to 0..1 range.
2024-09-02 20:28:36 +03:00
Jesse Yurkovich
f78d3af9c8 USD: Fix UsdStage leak occurring when python hooks throw exceptions
If a USD python hook throws an exception during processing, the USD
stage ptr is "leaked" because the destructor is not called on the
argument class we pass into the python call.

This leak prevents the stage from reaching a reference count of 0 later
and the file is kept open. All attempts to use the same USD file again
will be met with the following error:
`Coding Error: in _CreateNew at line 617 of C:\db\build\S\VS1564R\build\usd\src\external_usd\pxr\usd\sdf\layer.cpp -- A layer already exists with identifier 'path.usda'`

Instead of passing our class into the call normally, which boost::python
would see as needing to make a copy, use a `ref` instead, bypassing the
problem.

Additional details and repro in the PR. Test coverage to follow.
Pull Request: https://projects.blender.org/blender/blender/pulls/126298
2024-08-27 04:03:30 +02:00
Bastien Montagne
bb24677a76 Cleanup: Rename CustomData_copy to CustomData_initi_from.
And same for the `copy_layout` function. These functions do not free any
potentially existing data in destination, but expect it to be uninitialized.
Hopefully these new names will make it more clear and avoid bugs like #122160.
2024-08-26 19:11:02 +02:00
Campbell Barton
40f96afa61 Cleanup: various non-functional changes
- Use const arguments.
- Remove redundant cast.
- Use ELEM macro.
- Use boolean & nullptr literals.
2024-08-26 11:50:12 +10:00