Commit Graph

7194 Commits

Author SHA1 Message Date
Campbell Barton
c5d7d58209 Cleanup: correct terminating macro
Harmless but the begin/end macros didn't match.
2025-09-26 21:58:34 +10:00
Brecht Van Lommel
712c507519 Logging: Do not print Python API errors that will throw an exception
Python API functions would both report an error through CLOG and throw an
exception. However this is a problem when --debug-exit-on-error is used,
as tests and other scripts will not have the opportunity to catch the exception
before Blender exits.

Now don't print such reports through CLOG. Note that these usages of
BKE_reports_init have their print level set to error, so were already not
printing info and warning reports (which is not something we generally
want Python API calls to do, they should be silent).

Ref #146256

Pull Request: https://projects.blender.org/blender/blender/pulls/146801
2025-09-26 12:57:39 +02:00
Jacques Lucke
4e4976804e Core: Add packed linked data-blocks
This adds support for packed linked data. This is a key part of an improved
asset workflow in Blender.

Packed IDs remain considered as linked data (i.e. they cannot be edited),
but they are stored in the current blendfile. This means that they:
* Are not lost in case the library data becomes unavailable.
* Are not changed in case the library data is updated.

These packed IDs are de-duplicated across blend-files, so e.g. if a shot
file and several of its dependencies all use the same util geometry node,
there will be a single copy of that geometry node in the shot file.

In case there are several versions of a same ID (e.g. linked at different
moments from a same library, which has been modified in-between), there
will be several packed IDs.

Name collisions are averted by storing these packed IDs into a new type of
'archive' libraries (and their namespaces). These libraries:
* Only contain packed IDs.
* Are owned and managed by their 'real' library data-block, called an
  'archive parent'.

For more in-depth, technical design: #132167
UI/UX design: #140870

Co-authored-by: Bastien Montagne <bastien@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/133801
2025-09-26 10:53:40 +02:00
Campbell Barton
2f3e6e69df Cleanup: rename BM_mesh_{validate=>is_valid}
The term validate is often used to make the data valid
(e.g. BKE_mesh_validate) where is this only checks the mesh is valid.
2025-09-25 11:22:23 +10:00
Campbell Barton
f313540686 Cleanup: rename flushing functions for clarity
It wasn't clear how `*_flush` and `*_flush_mode` were different,
rename `*_flush` to `*_flush_from_verts`.
2025-09-24 14:26:28 +10:00
Campbell Barton
30485e6122 Cleanup: grammar, confusing wording 2025-09-24 03:06:11 +00:00
Oxicid
a714472194 PyAPI: Implement vectorcall support for rna_func
Use vectorcall for ~20-30% speedup calling Python/RNA functions.

Ref !146366
2025-09-24 02:41:08 +00:00
Campbell Barton
580af50709 Cleanup: minor naming changes for RNA functions
Split out from !146366.
2025-09-24 02:41:07 +00:00
Campbell Barton
4b82edd53c Cleanup: minor changes to the BMesh Python API
- Add typed array access functions, avoiding the need for casting.
- Share error prefix for exceptions.
- Use "num" suffix instead of "len".
2025-09-23 13:35:33 +10:00
Oxicid
3dffbb7e35 Cleanup: correct misleading PyError message formatting
Removed duplicated "Error" in `PyErr_SetString` messages

Pull Request: https://projects.blender.org/blender/blender/pulls/146473
2025-09-22 15:20:17 +02:00
Brecht Van Lommel
bb57ab3598 Fix #146448: Object copy/paste has wrong colors with working space
Write proper colorspace information into copy buffer blend files.

Pull Request: https://projects.blender.org/blender/blender/pulls/146450
2025-09-22 13:17:49 +02:00
Campbell Barton
d857c48216 Cleanup: replace select/deselect flush functions with a select argument
The naming was confusing as only some selection flushing functions
were intended to be used when elements had been selected or de-selected.

Replace these with a single function that takes a "select" argument.
2025-09-21 20:32:27 +10:00
Nick Alberelli
439fe8a1a0 PyAPI: support logging for Context.temp_override
Adds comprehensive logging system for temp_override context manager to
help developers debug "context is incorrect" operator poll failures.
The logging tracks all context member access during temp_override
sessions and provides detailed summaries to identify context
availability issues.

Features:
- Command-line logging: `./blender --log-level trace --log "context" `
- Python programmatic control: `temp_override_handle.logging_set(True)`
- C-level API: CTX_temp_override_logging_set/get() functions
- Tracks individual member access
- Uses CLOG logging infrastructure

The logging helps identify which context members are accessed during
temp_override sessions and whether they return valid data, making it
easier to debug operator poll functions that fail with context errors.

Ref !144810
2025-09-19 06:48:07 +00:00
Campbell Barton
c2766d2058 Cleanup: use a typed enum for context data type
Ensure all types are handled in switch statements (see !144810).
2025-09-19 08:21:30 +10:00
Clément Foucault
9d0fe5573b GPU: FrameBuffer: Remove GPUFrameBuffer wrapper opaque type
This is the first step into merging DRW_gpu_wrapper.hh into
the GPU module.

This is very similar to #119825.

Pull Request: https://projects.blender.org/blender/blender/pulls/146372
2025-09-16 17:50:48 +02:00
Sean Kim
7eb84ebd90 Python: Print script errors with CLOG
Currently, when a python error is encountered when rendering the UI, the
corresponding message is printed to stdout / stderr via `PyErr_Print`,
this patch modifies behavior so that a cursory message is also printed
with CLOG

This has the benefit of allowing for testing via
`--debug-exit-on-error`, which aborts Blender when an error message is
printed.

Pull Request: https://projects.blender.org/blender/blender/pulls/146296
2025-09-16 14:34:14 +02:00
Campbell Barton
96d7c5c4cd Cleanup: use braces in mathutils switch statements
Also move error checking before variable declarations.
2025-09-16 14:53:58 +10:00
Oxicid
b2176bfdd7 PyAPI: use the vectorcall protocol for mathutils types
The Vectorcall protocol avoids creating a tuple, and also provides the
number of arguments in advance, providing a ~1.6x speedup for creation
of mathutils types.

Ref !146237
2025-09-16 04:50:38 +00:00
Clément Foucault
680fec144c Cleanup: GPU: Remove prefix 'e' from enum types
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/146034
2025-09-15 15:11:02 +02:00
Campbell Barton
62d791c8d6 Cleanup: only use "r_" prefix for return arguments 2025-09-14 23:03:01 +10:00
Namit Bhutani
2110391058 PyAPI: rename undo memory usage method, improve doc-string
Ref !146095
2025-09-12 22:05:53 +10:00
Campbell Barton
84511b8509 Core: add type checks to ID property accessors
Since moving the C++ ID property access macros cast "const" away,
replace with get/set accessors and add asserts that correct types
are used.
2025-09-12 06:29:42 +00:00
Campbell Barton
9dc6a2d7f3 Cleanup: correct misleading PyArg_Parser formatting 2025-09-11 15:20:20 +10:00
Jacques Lucke
c3f49cd24e Shader Nodes: add Python API for inlined shader nodes
This makes the shader node inlining from #141936 available to external renderers
which use the Python API. Existing external renderer add-ons need to be updated
to get the inlined node tree from a material like below instead of using the
original node tree of the material directly.

The main contribution are these three methods: `Material.inline_shader_nodes()`,
`Light.inline_shader_nodes()` and `World.inline_shader_nodes()`.

In theory, there could be an inlining API for node trees more generally, but
some aspects of the inlining are specific to shader nodes currently. For example
the detection of output nodes and implicit input handling. Furthermore, having
the method on e.g. `Material` instead of on the node tree might be more future
proof for the case when we want to store input properties of the material on the
`Material` which are then passed into the shader node tree.

Example from API docs:
```python
import bpy

# The materials should be retrieved from the evaluated object to make sure that
# e.g. edits of Geometry Nodes are applied.
depsgraph = bpy.context.view_layer.depsgraph
ob = bpy.context.active_object
ob_eval = depsgraph.id_eval_get(ob)
material_eval = ob_eval.material_slots[0].material

# Compute the inlined shader nodes.
# Important: Do not loose the reference to this object while accessing the inlined
#   node tree. Otherwise there will be a crash due to a dangling pointer.
inline_shader_nodes = material_eval.inline_shader_nodes()

# Get the actual inlined `bpy.types.NodeTree`.
tree = inline_shader_nodes.node_tree

for node in tree.nodes:
    print(node.name)
```

Pull Request: https://projects.blender.org/blender/blender/pulls/145811
2025-09-11 06:08:30 +02:00
Campbell Barton
1e7587f761 Cleanup: follow our API naming conventions
Minor changes to recently added undo API call.
2025-09-11 12:59:32 +10:00
Brecht Van Lommel
ea0fab21d4 Color Management: Builtin support for ACEScg and Rec.2020 linear spaces
With new functions to convert to/from scene linear in the Python API. ACEScg
in particular is common in USD and MaterialX files.

Pull Request: https://projects.blender.org/blender/blender/pulls/145755
2025-09-05 11:11:32 +02:00
Namit Bhutani
8536fd1223 Sculpt: Compress position undo step data
Stored undo step data for position changes in sculpt mode are now
automatically compressed. Compression is run in background threads,
reducing memory consumption during sculpting sessions while adding
little performance overhead.

For testing and benchmarks, memory usage is now available through
`bpy.app.undo_memory_info()`. Undo memory usage is now tracked by the
existing automated benchmark tests. Some changes to the web benchmark
visualization present the data a bit better.

ZSTD compression is run asynchronously in a backround task pool.
Compression is only blocking if the data is requested immediately for
undo/redo.

Co-authored-by: Hans Goudey <hans@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/141310
2025-09-03 19:15:05 +02:00
Campbell Barton
90764de24d Fix: Python memory leak when deferred property registration fails
Regression in [0], resolve by moving error handling
before creating new objects.

[0] a7b3047cef
2025-09-03 22:10:31 +10:00
Bastien Montagne
469f54f484 BPY: Implement get_transform and set_transform for runtime-defined RNA properties.
Improve handling of runtime defined python RNA properties. Mainly:
* Add `get_transform` and `set_transform` new callbacks.
  These allow to edit the value, while still using the default
  (IDProperty-based) storage system.
* Read-only properties should now be defined using a new `options` flag,
  `READ_ONLY`.
* `get`/`set` should only be used when storing data outside of the
  default system now.
  * Having a `get` without a `set` defined forces property to be
    read-only (same behavior as before).
  * Having a `set` without a `get` is now an error.
* Just like with existing `get/set` callbacks, `get_/set_transform`
  callbacks must always generate values matching the constraints defined
  by their `bpy.props` property definition (same type, within required
  range, same dimensions/sizes for the `Vector` properties, etc.).
* To simplify handling of non-statically sized strings, the relevant
  RNA API has been modified, to use `std::string` instead of
  (allocated) char arrays.

Relevant unittests and benchmarking have been added or updated as part
of this project.

Note: From initial benchmarking, 'transform' versions of get/set are
several times faster than 'real' get/set.

Implements #141042.

Pull Request: https://projects.blender.org/blender/blender/pulls/141303
2025-09-02 11:30:09 +02:00
Campbell Barton
9ff2ccd350 Fix: incorrect handling of 3x3 matrices with RNA get/set callbacks
Thanks to @mont29 for spotting the error.
2025-08-29 22:16:39 +10:00
Campbell Barton
38b13f7aa8 Fix: uninitialized memory use in RNA slice assignment
Resolve run-time error caught by UBSAN & script_pyapi_prop_array test.
2025-08-29 07:27:40 +00:00
Campbell Barton
6c7513b9ac Cleanup: spelling (make check_spelling_*) 2025-08-29 11:27:33 +10:00
Jeroen Bakker
56784c2681 Fix: Python: incorrect assert when reading back framebuffers
Detected when looking into #144887

Pull Request: https://projects.blender.org/blender/blender/pulls/145165
2025-08-28 09:19:29 +02:00
Campbell Barton
4b35760354 Fix: incorrect doc-strings for bpy.props type argument 2025-08-26 02:14:31 +00:00
Campbell Barton
753b6c031b PyDoc: include keyword only parameter in doc-strings 2025-08-26 02:14:30 +00:00
Sybren A. Stüvel
494b041585 Python: Improve bpy.data.user_map() argument documentation
Update the call signature in the docstring so that it is clear that the
arguments to `bpy.data.user_map()` are all optional:

```
.. method:: user_map(*, subset=None, key_types=None, value_types=None)
```

This is important for Python stubs that are generated from the
docstrings; see https://github.com/michaelgold/buildbpy/issues/3.

This change feels a bit weird, as the function behaves differently
depending on whether the arguments are there or not. For example,
`subset=None` is not actually valid, as it should be a dictionary and
the function will raise a `TypeError`. But documenting `subset=dict()`
is also incorrect, because explicitly passing that will make the
function behave differently: it reports an empty dictionary, instead of
reporting everything. The same goes for the other parameters.

A better approach (IMO) would be to either add "empty dict/set means
'everything'" logic, or to allow `None` values for these parameters so
that the documented call can actually be made.

Note that this is the case for other calls as well, such as
`bpy.data.file_path_map()`. As such, I don't want to address this in
this commit; this is just for making the docstring reflect the optional
nature of the parameters.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/144933
2025-08-25 11:53:23 +02:00
Campbell Barton
e964f078b5 PyDoc: correct use of back ticks for literal text 2025-08-22 15:10:29 +10:00
Campbell Barton
78c9d16919 PyDoc: correct types, consistent formatting for doc-strings in C++
Correct some types, ensure multi-line docs end with a newline,
sentences end with a full stop.
2025-08-22 14:05:28 +10:00
Andrej730
e41fdebf3a PyDoc: UILayout.introspect(), add missing return value type
Ref !143353
2025-08-22 03:42:34 +00:00
Brecht Van Lommel
235fdc6356 Color Management: Fix wrong use of display color space
* PROP_COLOR_GAMMA is sRGB, not display space
* Hex colors are always sRGB
* Image byte buffers are in byte_buffer.colorspace

Fixes for sequencer text, image painting, render stamp and tooltips.
The default display space is sRGB, so this change will not be noticed
in most files.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/144565
2025-08-21 15:24:40 +02:00
Sybren A. Stüvel
f5ba4dbfe6 Python: Fix parameter name in error message from bpy.data.file_path_map()
When `bpy.data.file_path_map(subset=X)` is called, where `X` has the
wrong type, it now correctly shows `subset` as the erroneous parameter.

Pull Request: https://projects.blender.org/blender/blender/pulls/144914
2025-08-21 14:11:26 +02:00
Jeroen Bakker
5767da3b49 Fix #144758: Python: Inversed unicode comparison in GPUFramebuffer
Regression introduced by d9f38fca5f

Pull Request: https://projects.blender.org/blender/blender/pulls/144908
2025-08-21 11:52:24 +02:00
Clément Foucault
5681d41ca5 Fix: GPU: Wrong default size for compute local group size
The doc string was updated by 16430b10f1
but the default were not changed.
2025-08-21 11:32:43 +02:00
Bastien Montagne
27a613d9ea Fix: BPY props: broken custom set function for strings.
Another dummy mistake in BPY accessors refactor from yesterday (134d66201a)...
We critically need more unittests in this area!
2025-08-20 12:48:47 +02:00
Campbell Barton
b8ce7d419e Cleanup: use PyErr_SetString when formatting isn't needed 2025-08-20 16:10:54 +10:00
Bastien Montagne
59201ddc28 BPY props: Fix own mistake in recent refactor.
New code from 134d66201a was using uninitialized variable. Not sure how
I missed the compiler warning... :(
2025-08-19 17:49:46 +02:00
Bastien Montagne
134d66201a Cleanup: BPY prop: Move get/set... py callbacks into own scope.
Moving the python call itself into a dedicated sub-scope allows to
ensure local variables (arguments) do not risk leaking into the
rest of the code after being released.

Also use helper macro `PyTuple_SET_ITEMS`.

Pull Request: https://projects.blender.org/blender/blender/pulls/144798
2025-08-19 17:16:31 +02:00
nutti
99aa76035d Fix: typo in mathutils.Vector doc-string
Ref !144731
2025-08-19 02:36:42 +00:00
Oxicid
b856b6010e PyAPI: buffer protocol support for mathutils types
Adding buffer protocol support increases the speed of copying a Vector
(3D) array into a `numpy.array` by up to x3.8.

Ref !144401
2025-08-16 06:14:19 +00:00
Campbell Barton
248a9653f6 Fix: exception types in last commit
Missed changing exception types & messages in
25c69382fc.
2025-08-14 13:10:30 +10:00