Commit Graph

461 Commits

Author SHA1 Message Date
Campbell Barton
e97e2e4b6d Merge branch 'blender-v4.3-release' 2024-11-03 22:04:42 +11:00
Campbell Barton
901359abf7 Cleanup: replace doc-strings with comments for internal logic
There is no need to store text in memory for comments on functions
that aren't exposed publicly and are only of used when reading
the code.
2024-11-03 21:50:33 +11:00
Campbell Barton
ca8d00d0bb Cleanup: add doc-strings for bpy_extras.id_map_utils 2024-11-03 21:50:29 +11:00
Campbell Barton
f17379a5d0 Merge branch 'blender-v4.3-release' 2024-11-03 16:07:40 +11:00
Campbell Barton
3bcfb151c1 PyDoc: use Python's type annotation syntax for doc-strings
Replace plain-text type information with the type syntax used
for Python's type annotations as it's more concise, especially for
callbacks which often didn't include useful type information.

Note that this change only applies to inline doc-strings,
generated doc-strings from RNA need to be updated separately.

Details:

- Many minor corrections were made when "list" was incorrectly used
  instead of "sequence".
- Some type information wasn't defined in the doc-strings and has been
  added.
- Verbose type info would benefit from support for type aliases.
2024-11-03 15:44:35 +11:00
Campbell Barton
71a38df6fa Merge branch 'blender-v4.3-release' 2024-11-02 18:02:15 +11:00
Campbell Barton
a05345e139 PyDoc: various corrections to function doc-strings
Add missing arguments, corrections & remove unchecked type info.
2024-11-02 17:48:21 +11:00
Falk David
859e4c8465 Merge branch 'blender-v4.3-release' 2024-10-31 17:11:44 +01:00
Falk David
7e87da72ab Fix #129637: GPv3: Python: add_points raises exception
Introduced by 68c665ffa1.
This fix forgot to change parameters of `GreasePencilStrokePointSlice`
in `add_points`.
The fix also adds a test for `add_points` and `remove_points`.

Pull Request: https://projects.blender.org/blender/blender/pulls/129640
2024-10-31 16:22:44 +01:00
Sergey Sharybin
981ab904ba Merge branch 'blender-v4.3-release' 2024-10-31 16:05:22 +01:00
Falk David
ab3186120c Fix #129239: GPv3: Python: Vertex color is initialized as white
The default value for `FLOAT_COLOR` attributes is white. We can't
change this default easily.
This fix will initialize the attributes accessed through the high-level
python API with their expected default value. In the case of
vertex colors, this is fully transparent black.

Pull Request: https://projects.blender.org/blender/blender/pulls/129638
2024-10-31 15:37:02 +01:00
Bastien Montagne
1dbe94c8ac RNA: Make the PointerRNA struct non-trivial.
For now, PointerRNA is made non-trivial by giving explicit default
values to its members.

Besides of BPY python binding code, the change is relatively trivial.
The main change (besides the creation/deletion part) is the replacement
of `memset` by zero-initialized assignment (using `{}`).

makesrna required changes are quite small too.

The big piece of this PR is the refactor of the BPY RNA code.

It essentially brings back allocation and deletion of the BPy_StructRNA,
BPy_Pointer etc. python objects into 'cannonical process', using `__new__`,
and `__init__` callbacks (and there matching CAPI functions).

Existing code was doing very low-level manipulations to create these
data, which is not really easy to understand, and AFAICT incompatible
with handling C++ data that needs to be constructed and destructed.

Unfortunately, similar change in destruction code (using `__del__` and
matching `tp_finalize` CAPI callback) is not possible, because of technical
low-level implementation details in CPython (see [1] for details).

`std::optional` pointer management is used to encapsulate PointerRNA
data. This allows to keep control on _when_ actual RNA creation is done,
and to have a safe destruction in `tp_dealloc` callbacks.

Note that a critical change in Blender's Python API will be that classes
inherinting from `bpy_struct` etc. will now have to properly call the
base class `__new__` and/or `__init__`if they define them.

Implements #122431.

[1] https://discuss.python.org/t/cpython-usage-of-tp-finalize-in-c-defined-static-types-with-no-custom-tp-dealloc/64100
2024-10-30 15:08:37 +01:00
Christoph Lendenfeld
2fb0847dd1 Fix #129385: Bake Action operator not working with slots
This fixes the issue by traversing the new data structure for actions.
* When a slot is assigned, the action is baked into the slot.
* if no slot is assigned, it creates a new slot and bakes into that. However since no slot was assigned, the animation will be static.

Pull Request: https://projects.blender.org/blender/blender/pulls/129525
2024-10-29 16:39:10 +01:00
Campbell Barton
1cf7781596 Cleanup: quiet Python warnings from ruff 2024-10-27 22:35:58 +11:00
Campbell Barton
a0453ab87a Cleanup: update use of typing in for Python scripts 2024-10-23 12:48:09 +11:00
Falk David
3075bd3f2c Merge branch 'blender-v4.3-release' 2024-10-21 14:12:40 +02:00
Falk David
b05e9f7bd6 Fix #127523: Missing update when updating positions with Python
The issue was that the strokes were not using the `POLY` type and
needed to be tagged.

This adds a function `tag_positions_changed` on the `GreasePencilDrawing`
so that the high-level python API can tag the positions if
the `point.position` attibute is written to.

Pull Request: https://projects.blender.org/blender/blender/pulls/129292
2024-10-21 14:10:32 +02:00
Bastien Montagne
779d70f80e Merge branch 'blender-v4.3-release' 2024-10-20 18:24:10 +02:00
Bastien Montagne
2e6c24c58e I18N: Enable Romanian UI translation. 2024-10-20 18:20:01 +02:00
Bastien Montagne
387502ec53 I18N: Add Lithuanian UI translation. 2024-10-20 18:05:18 +02:00
Campbell Barton
6d1e235f15 Cleanup: remove use of deprecated typing from scripts/modules/
Also use comments for typing that can't be checked.
2024-10-18 10:43:14 +11:00
Campbell Barton
d4bbc79f9e Merge branch 'blender-v4.3-release' 2024-10-18 10:27:23 +11:00
Campbell Barton
6cd4ad171d Merge branch 'blender-v4.3-release' 2024-10-18 10:27:19 +11:00
Campbell Barton
528df90336 Cleanup: remove use of deprecated types for extensions (#2)
Missed these in a66601ee95.
2024-10-18 10:21:03 +11:00
Campbell Barton
f4f50fa2c5 Cleanup: replace typing.Union/Option with logical OR for extensions
Also remove use of deprecated typing.Sequence.
2024-10-18 10:08:12 +11:00
Bastien Montagne
1e55d034a1 Fix massive amount of memleaks on exit in BPY.
Essentially, our current code would not properly remove (dereference)
its python objects matching various RNA data created during execution.

Some cases are fairly trivial to understand (like the lack of handling
of unregstering for our 'startup' operators and UI), other were more
subtle (like unregistered PropertyGroups who would remove/free their RNA
struct definition, without releasing first the potential matching python
object).

Co-authored-by: Campbell Barton <campbell@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/128899
2024-10-17 18:05:31 +02:00
Campbell Barton
aa083140fb Merge branch 'blender-v4.3-release' 2024-10-17 19:12:14 +11:00
Campbell Barton
a66601ee95 Cleanup: remove deprecated typing built-ins for extension logic
Deprecated since Python 3.9 but still used in many docs/examples.
2024-10-17 19:11:40 +11:00
Campbell Barton
3e6565b9d7 Merge branch 'blender-v4.3-release' 2024-10-17 15:48:06 +11:00
Campbell Barton
e2862ed7ca Cleanup: rename variables handling modules loaded at startup
The term "global" isn't meaningful in this context,
use "registered" instead.
2024-10-17 15:46:42 +11:00
Campbell Barton
d02c603816 Merge branch 'blender-v4.3-release' 2024-10-17 13:02:19 +11:00
Campbell Barton
6d24201045 Fix error on script reload if the modules aren't found in sys.modules
While unlikely, account for modules loaded on startup not being in
`sys.modules` when reloading scripts.
2024-10-17 12:59:07 +11:00
Campbell Barton
b3c9c7c496 Merge branch 'blender-v4.3-release' 2024-10-16 21:08:17 +11:00
Christoph Lendenfeld
88f298f66f Fix: Error when baking custom properties of unavailable addon
When baking an Action on an object which has custom properties that come
from an addon or python script that isn't loaded, the baking would fail with:
```
TypeError: Cannot assign a 'dict' value to the existing 'hops' Group IDProperty
```

This comes from an addon that isn't present or loaded on a users machine.
The fix is to check for `IDProperty` and skip those.

Pull Request: https://projects.blender.org/blender/blender/pulls/129057
2024-10-16 10:42:32 +02:00
Campbell Barton
9bd2e3554a Merge branch 'blender-v4.3-release' 2024-10-16 15:07:33 +11:00
Campbell Barton
c3b067dc80 Cleanup: single/double quote use in scripts 2024-10-16 14:45:08 +11:00
Sybren A. Stüvel
43d7558e5b Anim: Remove 'Slotted Actions' experimental flag
This commit takes the 'Slotted Actions' out of the experimental phase.
As a result:

- All newly created Actions will be slotted Actions.
- Legacy Actions loaded from disk will be versioned to slotted Actions.
- The new Python API for slots, layers, strips, and channel bags is
  available.
- The legacy Python API for accessing F-Curves and Action Groups is
  still available, and will operate on the F-Curves/Groups for the first
  slot only.
- Creating an Action by keying (via the UI, operators, or the
  `rna_struct.keyframe_insert` function) will try and share Actions
  between related data-blocks. See !126655 for more info about this.
- Assigning an Action to a data-block will auto-assign a suitable Action
  Slot. The logic for this is described below. However, There are cases
  where this does _not_ automatically assign a slot, and thus the Action
  will effectively _not_ animate the data-block. Effort has been spent
  to make Action selection work both reliably for Blender users as well
  as keep the behaviour the same for Python scripts. Where these two
  goals did not converge, reliability and understandability for users
  was prioritised.

Auto-selection of the Action Slot upon assigning the Action works as
follows. The first rule to find a slot wins.

1. The data-block remembers the slot name that was last assigned. If the
    newly assigned Action has a slot with that name, it is chosen.
2. If the Action has a slot with the same name as the data-block, it is
    chosen.
3. If the Action has only one slot, and it has never been assigned to
    anything, it is chosen.
4. If the Action is assigned to an NLA strip or an Action constraint,
    and the Action has a single slot, and that slot has a suitable ID
    type, it is chosen.

This last step is what I was referring to with "Where these two goals
did not converge, reliability and understandability for users was
prioritised." For regular Action assignments (like via the Action
selectors in the Properties editor) this rule doesn't apply, even though
with legacy Actions the final state ("it is animated by this Action")
differs from the final state with slotted Actions ("it has no slot so is
not animated"). This is done to support the following workflow:

- Create an Action by animating Cube.
- In order to animate Suzanne with that same Action, assign the Action
  to Suzanne.
- Start keying Suzanne. This auto-creates and auto-assigns a new slot
  for Suzanne.

If rule 4. above would apply in this case, the 2nd step would
automatically select the Cube slot for Suzanne as well, which would
immediately overwrite Suzanne's properties with the Cube animation.

Technically, this commit:
- removes the `WITH_ANIM_BAKLAVA` build flag,
- removes the `use_animation_baklava` experimental flag in preferences,
- updates the code to properly deal with the fact that empty Actions are
  now always considered slotted/layered Actions (instead of that relying
  on the user preference).

Note that 'slotted Actions' and 'layered Actions' are the exact same
thing, just focusing on different aspects (slot & layers) of the new
data model.

The "Baklava phase 1" assumptions are still asserted. This means that:
- an Action can have zero or one layer,
- that layer can have zero or one strip,
- that strip must be of type 'keyframe' and be infinite with zero
  offset.

The code to handle legacy Actions is NOT removed in this commit. It will
be removed later. For now it's likely better to keep it around as
reference to the old behaviour in order to aid in some inevitable
bugfixing.

Ref: #120406
2024-10-15 16:29:53 +02:00
Falk David
5fbf747b55 Merge branch 'blender-v4.3-release' 2024-10-15 12:27:48 +02:00
Falk David
251250a3fb Fix #128991: GPv3: Python: Writing to invalid properties doesn't raise exception
When writing to a property that doesn't exist e.g. `frame.drawing.strokes.test = 42`
no exception would be raised and it would silently fail.

The fix defines the `__slots__` on the classes explicitly which then raises an exception
if the user tries to write something that wasn't previously defined.

Pull Request: https://projects.blender.org/blender/blender/pulls/129047
2024-10-15 12:23:02 +02:00
Falk David
39675bb0fb Fix: GPv3: Python: Setting attribute value always creates new attribute
When e.g. executing `drawing.strokes[0].softness = 3`, the API would
always create a new attribute `softness` even if that attribute existed
already.

The issue was that the code was using the `.get(value, fallback)` syntax
but the `fallback` expression is always evaluated by python.

The fix removes the use of the `fallback` and uses a simple `if/else` to
check if the attribute doesn't exist yet and only then create it.

Pull Request: https://projects.blender.org/blender/blender/pulls/129044
2024-10-15 12:22:32 +02:00
Bastien Montagne
78a3ef1d53 Merge branch 'blender-v4.3-release' 2024-10-14 10:55:42 +02:00
Falk David
89e3ab2a45 Fix: GPv3: Error when calling add_points or remove_points
The `drawing.resize_curves` function had been renamed in
1899ea25d5 but this wasn't
updated in the strokes API.
2024-10-14 10:40:52 +02:00
Philipp Oeser
e89cf5ecc0 Merge branch 'blender-v4.3-release' 2024-10-10 13:55:29 +02:00
Philipp Oeser
9baf082dc5 Fix #128760: NLA bake action throws error
Caused by db6113048d

Above commit was accessing action properties which are only available if
experimental baklava is enabled.
Now check for this.

Pull Request: https://projects.blender.org/blender/blender/pulls/128762
2024-10-10 13:54:58 +02:00
Campbell Barton
52ced621c7 Merge branch 'blender-v4.3-release' 2024-10-09 17:42:05 +11:00
nutti
e7747c0d93 PyAPI: add type of bpy.types.NodeSocket.links
Ref !128626
2024-10-09 17:41:09 +11:00
Falk David
da339407a9 Fix: Python: Empty list of drawing.strokes doesn't have length of 0
The API would return `None` if the number of strokes in the drawing was `0`.
Instead this should return a slice that has a length of 0 to be consistent.
2024-10-08 12:43:58 +02:00
Falk David
09ca5a4c5f Fix: Python: Empty list of drawing.strokes doesn't have length of 0
The API would return `None` if the number of strokes in the drawing was `0`.
Instead this should return a slice that has a length of 0 to be consistent.
2024-10-08 11:43:56 +02:00
Campbell Barton
3525b83c6b Cleanup: use specific exception types where appropriate 2024-10-08 09:41:53 +11:00
Campbell Barton
1a1e75c253 Cleanup: replace implicit BaseException with Exception
Exception is more appropriate as a general exception in these cases.
2024-10-08 09:41:51 +11:00