336 Commits

Author SHA1 Message Date
Jeroen Bakker
e2dc63c5de Fix #147618: PyGPU incorrect colors when drawing images
644fb2b679 fixed a long standing issue
that offscreen example showed the wrong colors. However the fix assumes
that input texture color space is always sRGB.

This adds a shader variation that draws textures that are stored in scene referred
linear color space (like all of our Image data-block).

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/147788
2025-10-16 19:12:16 +02:00
Nick Alberelli
0d9ea9d11c PyAPI: add Context.temp_override documentation & examples
Add a new section to the `Context` page that includes an explanation
on how to invoke "on demand" logging for context member access.

Design task: #144746
Logging added in: !144810

Ref !146862
2025-10-08 16:08:09 +11:00
Julian Eisel
eef971e377 UI/BPY: Remove grid layout for UI lists
The grid layout for UI lists wasn't used in practice from all we can
tell. It was badly maintained for a long time (bugs went unnoticed). I
think it was added for an earlier version of the asset UI design.

This was planned for removal in 5.0, see blender/blender#110461.

Usages in bundled scripts were already removed in efa8d942b8.

Pull Request: https://projects.blender.org/blender/blender/pulls/146656
2025-09-29 13:07:31 +02:00
Nick Alberelli
db88381e75 Docs: Include get_prim_map() in bpy.types.USDHook example code
Provide an example of using the `get_prim_map()` in the existing USD
Hook sample.

Related: blender/blender@0df5d8220b

Pull Request: https://projects.blender.org/blender/blender/pulls/146866
2025-09-27 01:58:44 +02:00
Habib Gahbiche
1b4daf9d2e Nodes: remove "Use Nodes" in Shader Editor for Object Materials
"Use Nodes" was removed in the compositor to simplify the compositing
workflow. This introduced a slight inconsistency with the Shader Node
Editor.

This PR removes "Use Nodes" for object materials.

For Line Style, no changes are planned (not sure how to preserve
compatibility yet).
This simplifies the state of objects; either they have a material or
they don't.

Backward compatibility:
- If Use Nodes is turned Off, new nodes are added to the node tree to
simulate the same material:
- DNA: Only `use_nodes` is marked deprecated
- Python API:
  - `material.use_nodes` is marked deprecated and will be removed in
6.0. Reading it always returns `True` and setting it has no effect.
  - `material.diffuse_color`, `material.specular` etc.. Are not used by
EEVEE anymore but are kept because they are used by Workbench.

Forward compatibility:
Always enable 'Use Nodes' when writing blend files.

Known Issues:
Some UI tests are failing on macOS

Pull Request: https://projects.blender.org/blender/blender/pulls/141278
2025-09-14 17:53:54 +02: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
luz paz
656c3f65ad Cleanup: fix typos in doc subdirectory
Fix several documentation related typos.
Found via `codespell -S "*.desktop,*.diff,./intern,./extern,./locale,./AUTHORS,./source/blender/blenlib/tests/BLI_string_utf8_test.cc,./doc/license/bf-members.txt" -L accessort,abd,aci,alo,ans,ba,bording,childrens,clen,constructin,datas,dependees,domin,eary,ege,eiter,elemt,eles,endianess,enew,espace,finded,fiter,fpt,groupd,hist,implementating,indext,ine,infront,inout,inouts,inpt,ist,lene,listenter,lod,maks,masia,mata,mis,mke,nam,nd,ned,opose,ot,outlow,parm,parms,passt,pinter,pixelx,poin,pres,ptd,re-usable,re-use,re-used,re-uses,re-using,ridiculus,schem,soler,strack,suh,te,tesselate,tham,ue,vai,varius,wew`

Pull Request: https://projects.blender.org/blender/blender/pulls/145824
2025-09-06 08:03:16 +02:00
Bastien Montagne
ede8e3af91 Docs: Update bpy.props docs/examples for getters and setters.
Mostly addresses recent changes in the area (adding 'transform'
accessors), but also tweak/fix some minor issues with existing doc.

Pull Request: https://projects.blender.org/blender/blender/pulls/145582
2025-09-03 17:25:55 +02:00
Campbell Barton
e964f078b5 PyDoc: correct use of back ticks for literal text 2025-08-22 15:10:29 +10:00
Campbell Barton
990f0863e8 PyDoc: include buffer access in examples, cleanup
Note that buffer access is possible, also minor mathutils test cleanup.
2025-08-16 17:39:35 +10:00
clankill3r
ac962c02f6 Fix: PyDocs: typo fix in example
by -> be

Pull Request: https://projects.blender.org/blender/blender/pulls/144448
2025-08-12 17:20:04 +02:00
Aaron Carlisle
9188ce10e7 Cleanup: Format 2025-08-09 19:01:39 -04:00
Aaron Carlisle
86cd240c57 PyDocs: Add Macro example
- Adds a doc string for the Macro class
- Adds a basic example

Fixes #blender-manual/issues/51387
2025-08-09 18:43:14 -04:00
Campbell Barton
53cae68ee8 Cleanup: hyphenate the term data-blocks in strings/doc-strings 2025-08-08 08:47:13 +10:00
Campbell Barton
6d899a6726 Cleanup: naming & reduce declaration scope in the PyAPI for lib loading
Use terms source/destination instead of from/to.
2025-08-02 02:10:59 +00:00
Andrej730
6e70b755ce Fix: PyAPI Docs: Document more msgbus limitations
Added the following notes to documentation:
- `msgbus` interaction with undo system that particularly makes
 it not completely reliable, since users they easily skip it's effect.
- Details on when and how often message bus updates are triggered.

Pull Request: https://projects.blender.org/blender/blender/pulls/138557
2025-06-06 10:58:23 +02:00
Jesse Yurkovich
0fa8c0f62a Docs: Grammar and wording cleanups for FileHandler examples
Cleanup grammar and simplify the wording used in the FileHandler
Python API examples.

Pull Request: https://projects.blender.org/blender/blender/pulls/139366
2025-06-02 19:21:38 +02:00
Jacques Lucke
a010c1c8b8 Python Docs: remove example for using timers with separate threads
This appears to be unreliable.

Resolves #139602.
2025-05-30 09:15:40 +02:00
Jeroen Bakker
a06c7fddbb Fix #139565: Update GPU polyline examples
Update GPU line examples to use polyline shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/139587
2025-05-30 09:10:51 +02:00
Jeroen Bakker
c56a855b9f Fix #139565: PyGPU: Add builtin point shaders
This PR adds builtin shaders for drawing points. Using `FLAT_COLOR`,
`SMOOTH_COLOR`, `UNIFORM_COLOR` can lead to undesired behavior
on Metal and Vulkan backends. To ensure future compatibility this PR
adds `POINT_FLAT_COLOR` and `POINT_UNIFORM_COLOR`.

The point size can be set using `gpu.state.point_size_set`.

Pull Request: https://projects.blender.org/blender/blender/pulls/139583
2025-05-29 14:36:32 +02:00
Campbell Barton
72f24fcbab Cleanup: resolve pylint warnings 2025-05-23 14:03:20 +10:00
Clément Foucault
f55e97a83a Documentation: Python: Add notice about MSL compatibility
See #139185
2025-05-22 11:47:06 +02:00
Andrej730
670fc012e5 Fix: PyDocs: bpy.ops document behavior on error reports
When submitting #135854 I've assumed that `RuntimeError` is
connected particularly to `{'CANCELLED'}` return status. Turned
out error is raised regardless of what return status is and it's
only based on the presence of error reports during operator
execution. Submitting a clarification for this.

Pull Request: https://projects.blender.org/blender/blender/pulls/138558
2025-05-08 06:58:34 +02:00
Campbell Barton
fd6ac498b0 Cleanup: spelling in comments, strings (make check_spelling_*)
Also replace some triple-quoted non-doc-string strings with commented
blocks in examples.
2025-05-06 00:18:39 +00:00
Jesse Yurkovich
0a3e4b0fd4 Fix #138365: Define and use 'use_filter_orderby_invert' for UIList example
The property in question was undefined since the first commit[1]

[1] b7e2cd5948

Pull Request: https://projects.blender.org/blender/blender/pulls/138373
2025-05-05 19:40:59 +02:00
Campbell Barton
4f04f6f8af Docs: add warning regarding operators that use the file selector 2025-04-25 16:24:24 +10:00
Andrej730
e09d59f9de Fix duplicated dirpath in fileselect_add docs (0314f9318c)
Ref: !137985
2025-04-25 16:04:18 +10:00
Campbell Barton
575600d540 Docs: correct use of FILE_PATH for directories
Also correct own error in recent doc-update regarding the expected
return value for fileselect_add.
2025-04-25 10:27:30 +10:00
Andrej730
e9c0029316 Docs: add the WindowManager.fileselect_add check_existing property
Ref: !137416
2025-04-25 10:20:08 +10:00
Campbell Barton
0314f9318c Docs: move WindowManager.fileselect_add descriptions into an example
- Allow for formatting and expanded descriptions.
- Clarify the expected types of each property.
2025-04-25 10:18:36 +10:00
Jan-Hendrik-Muller
e1163bf133 Fix Python: broken format string in API docs
This example was currently broken:
https://docs.blender.org/api/current/bpy.props.html#operator-example

Pull Request: https://projects.blender.org/blender/blender/pulls/136937
2025-04-14 11:38:43 +02:00
Campbell Barton
b2c57fd877 PyDoc: use complete sentences in comments for templates & examples 2025-04-02 23:46:58 +00:00
Jacques Lucke
29fddf4710 Python: Geometry: create GeometrySet wrapper for Python
In Geometry Nodes a geometry is represented by a `GeometrySet`. This is a
container that can contain one geometry of each of the supported types (mesh,
curves, volume, grease pencil, pointcloud, instances). It's possible for a
`GeometrySet` to contain e.g. a mesh and a point cloud.

This patch creates a Python  wrapper for the built-in `GeometrySet`. For now,
it's main purpose is to consume the complete evaluated geometry of an object
without having to go through complex hoops via `depsgraph.object_instances`. It
also also allows retrieving instances that have been created with legacy
instancing systems such as dupli-verts or particles.

In the future, the `GeometrySet` API could also be used for more kinds of
geometry processing from Python, similar to how we use `GeometrySet` internally
as generic geometry storage.

Since we can't really have constness guarantees in Python currently, it's
enforced that the `GeometrySet` wrapper always has its own copy of each geometry
type (so e.g. it does not share a `Mesh` data-block pointer with any other place
in Blender). Without the copy, changes to the mesh in the geometry set would
also affect the evaluated geometry that Blender sees. The copy has a small cost,
but typically the overhead should be low, because attributes and other run-time
data can still be shared. This should be entirely thread-safe, assuming that no
code modifies implicitly shared data, which is forbidden. For historic reasons
there are still cases like #132423 where this assumption does not hold in all
cases. Those cases should be fixed. To my knowledge, this patch does not
introduce any new such issues or makes existing issues worse.

Pull Request: https://projects.blender.org/blender/blender/pulls/135318
2025-03-28 22:40:01 +01:00
Campbell Barton
e436b9638e Cleanup: replace references to "C" to C++ or the C-API
Also capitalize Blender, Python & API in docs & code-comments.
2025-03-26 17:23:33 +11:00
Andrej730
ad5494d7ac PyDoc: bpy.types.Operator docs - add note on execution context
Clarify the default behavior when invoke and execute is called.

Ref: !135854
2025-03-26 17:02:40 +11:00
Campbell Barton
c3e5a35ecd PyAPI: add blf.bind_imbuf(..) context manager
Add support for using BLF to draw into an ImBuf image buffer.
Once the imbuf context has been set, draw calls for that font_id will draw into the image.

This works by binding an imbuf to BLF which is then used as the target when drawing.
```
with blf.bind_imbuf(font_id, imbuf):
    blf.draw_buffer(font_id, text)
```
See the example in the Python API documentation for reference.

The following BLF API's have been added to support a Python context manager.

- `BLF_buffer_state_push`.
- `BLF_buffer_state_pop`
- `BLF_buffer_state_free`

Ref !135772
2025-03-15 11:00:51 +11:00
Campbell Barton
b85fc32cae Cleanup: spelling & repeated words in comments
Address warnings from check_spelling.py
2025-03-06 10:33:21 +11:00
Campbell Barton
c9bbc767db Docs: correct context.temp_override example
Address #134296
2025-02-11 10:51:05 +11:00
Campbell Barton
4cd827870d Cleanup: quiet check_spelling_* targets
Also correct outdated references to `ghash`.
2025-02-02 13:58:34 +11:00
Campbell Barton
9d4b48b107 Cleanup: spelling in build-files & docs 2025-01-31 15:22:50 +11:00
Campbell Barton
18783c5699 Cleanup: correct RST syntax, spelling & adjust quotes 2025-01-21 16:51:40 +11:00
Brecht Van Lommel
a6b293daac Python Module: Bundle VFX library python bindings
When calling bpy.utils.expose_bundled_modules(), these modules are
added to sys.path.

This provides a solution/workaround to two problems:
* Using bpy together with packages like usd-core is problematic. Besides
  crashing due to C++ symbol conflicts, it's just impossible to import
  different versions of the same module, or to have distinct environment
  variables for both. (#127132)
* Blender add-ons using these VFX modules do not currently work with
  the bpy module.

This adds about 15MB to the bpy package.

Pull Request: https://projects.blender.org/blender/blender/pulls/133082
2025-01-17 10:13:31 +01:00
Campbell Barton
7481355397 Cleanup: scripts, unused variables & re-declaring built-ins 2025-01-02 15:11:15 +11:00
Campbell Barton
d64bd41ee9 Cleanup: wrap long lines 2025-01-02 15:11:14 +11:00
Campbell Barton
54e655f06a PyDoc: correct unbalanced back-tick 2025-01-02 15:03:54 +11:00
nutti
848ec77911 Fix: PyDocs: Title inconsistency on bpy.types.USDHook
Due to 8285d2d, titles "Inherited Properties" and "Inherited Functions" become hidden.
This PR fixes this issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/132481
2025-01-01 07:40:37 +01:00
Michael Kowalski
9abe161b58 USD: USDHook.py format fix 2024-12-30 10:17:35 -05:00
Michael Kowalski
8285d2d82e USD: update USDHook.py example
Updated the example to include new hook functions
material_import_poll and on_material_import as well
as the new import_texture and export_texture
utilities which were introduced in #131559.

Also reformatted the existing documentation to include
subheaders and internal links, as the previous paragraph
format became difficult to follow.

Pull Request: https://projects.blender.org/blender/blender/pulls/132259
2024-12-30 15:50:08 +01:00
Charles Flèche
0df5d8220b USD: Add new get_prim_map API callable from python on_import hooks
When importing an USD, the Blender object names do not necessarily match
Prim names:

```
#usda 1.0
def Xform "xform1"
{
  def Mesh "MyObject"  # Will be imported as "MyObject"
}
def Xform "xform2"
{
  def Mesh "MyObject"  # Will be imported as "MyObject.001"
}
def Xform "xform2"
{
  def Mesh "MyObject"  # Will be imported as "MyObject.002"
}
```

This makes it difficult in the [USD Import Hooks]
(https://docs.blender.org/api/current/bpy.types.USDHook.html) to link a
Blender object back to its source Prim for additional processing. A
typical use cases for games is to generate UVs, create and apply a
material on the fly when importing a collision shape that does not have
a visual representation (hence no materials) based on some Prim
attributes, but that the artist needs to differenciate in Blender's
viewport.

The Import context exposes a new method `get_prim_map()` that returns a
`dict` of `prim path` / `list of Blender ID`.

For example, given the following USD scene,
```
/
 |--XformThenCube [def Xform]
 |   `--Cube [def Cube]
 |--XformThenXformCube [def Xform]
 |   `--XformIntermediate [def Xform]
 |       `--Cube [def Mesh]
 |--Cube [def Cube]
 `--Material [def Material]
     `--Principled_BSDF [def Shader]
```

the `get_prim_map()` method will return a map as:

```python
@static_method
def on_import(import_context):
  pprint(import_context.get_prim_map())
```

```json
{
  "/Cube": [bpy.data.objects["Cube.002"], bpy.data.meshes["Cube.002"]],
  "/XformThenCube": [bpy.data.objects["XformThenCube"]],
  "/XformThenCube/Cube": [bpy.data.objects["Cube"], bpy.data.meshes["Cube"]],
  "/XformThenXformCube": [bpy.data.objects["XformThenXformCube"]],
  "/XformThenXformCube/XformIntermediate": [bpy.data.objects["XformIntermediate"]],
  "/XformThenXformCube/XformIntermediate/Cube": [bpy.data.objects["Cube.001"], bpy.data.meshes["Cube.001"]],
  "/Material": [bpy.data.materials["Material"]],
}
```

Co-authored-by: Odréanne Breton <odreanne.breton@ubisoft.com>
Co-authored-by: Sttevan Carnali Joga <sttevan.carnali-joga@ubisoft.com>
Co-authored-by: Charles Flèche <charles.fleche@ubisoft.com>
2024-12-11 21:36:09 +01:00
Bastien Montagne
fcc1c89923 API Doc: improvements/fixes regarding new requirements for __init__/__del__ 2024-11-19 15:37:04 +01:00