Commit Graph

7027 Commits

Author SHA1 Message Date
Sergey Sharybin
7ceb4495c5 Refactor: OpenColorIO integration
Briefly about this change:
- OpenColorIO C-API is removed.
- The information about color spaces in ImBuf module is removed.
  It was stored in global ListBase in colormanagement.cc.
- Both OpenColorIO and fallback implementation supports GPU drawing.
- Fallback implementation supports white point, RGB curves, etc.
- Removed check for support of GPU drawing in IMB.

Historically it was implemented in a separate library with C-API, this
is because way back C++ code needed to stay in intern. This causes all
sort of overheads, and even calls that are strictly considered bad
level.

This change moves OpenColorIO integration into a module within imbuf,
next to movie, and next to IMB_colormanagement which is the main user
of it. This allows to avoid copy of color spaces, displays, views etc
in the ImBuf: they were used to help quickly querying information to
be shown on the interface. With this change it can be stored in the
same data structures as what is used by the OpenColorIO integration.
While it might not be fully avoiding duplication it is now less, and
there is no need in the user code to maintain the copies.

In a lot of cases this change also avoids allocations done per access
to the OpenColorIO. For example, it is not needed anymore to allocate
image descriptor in a heap.

The bigger user-visible change is that the fallback implementation now
supports GLSL drawing, with the whole list of supported features, such
as curve mapping and white point. This should help simplifying code
which relies on color space conversion on GPU: there is no need to
figure out fallback solution in such cases. The only case when drawing
will not work is when there is some actual bug, or driver issue, and
shader has failed to compile.

The change avoids having an opaque type for color space, and instead
uses forward declaration. It is a bit verbose on declaration, but helps
avoiding unsafe type-casts. There are ways to solve this in the future,
like having a header for forward declaration, or to flatten the name
space a bit.

There should be no user-level changes under normal operation.
When building without OpenColorIO or the configuration has a typo or
is missing a fuller set of color management tools is applies (such as the
white point correction).

Pull Request: https://projects.blender.org/blender/blender/pulls/138433
2025-05-09 14:01:43 +02:00
Philipp Oeser
34050dc865 Fix #138423: Some drivers remain active after deleting single
Symptoms were drivers still being active while others seemingly
disabled. Indices in the RNA path up to the `ANIM_remove_driver` call
are correct, so it is not entirely clear to me why this goes wrong, but
forcing an update by tagging animation resolves the issue.

NOTE from @dr.sybren : Without this fix, the old copy-for-evaluation
is still there, which still has the driver (because it's a copy)

NOTE: seems we are not handling ND_FCURVES_ORDER anywhere?
Pull Request: https://projects.blender.org/blender/blender/pulls/138490
2025-05-06 17:46:52 +02:00
Campbell Barton
7d97ba4c5f Cleanup: use float2, int2 types for cursor drawing callbacks
Ref !138172
2025-05-02 23:01:29 +00:00
Jacques Lucke
e8d1491e62 Refactor: Depsgraph: simplify query API further
* Remove `DEG_get_evaluated_object` in favor of `DEG_get_evaluated`.
* Remove `DEG_is_original_object` in favor of `DEG_is_original`.
* Remove `DEG_is_evaluated_object` in favor of `DEG_is_evaluated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138317
2025-05-02 15:08:29 +02:00
Jeroen Bakker
41a69b76a6 Partial Fix #129592: Vulkan: Add support for line size
Add-ons can call a batch draw command for lines using a surface shader.
This is not intended and polylines shaders should be used. This PR
lighten this restriction to automatically replace the shader with the
correct polyline shader, similar to immediate mode.

This change is done inside the python wrapper as internally we should
use the correct polyline shader.

For point shaders we don't have a work around in place and that needs
more discussion. Therefore this is only a partial fix.

Pull Request: https://projects.blender.org/blender/blender/pulls/138138
2025-05-01 15:44:40 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Campbell Barton
c90e8bae0b Cleanup: spelling in comments & replace some use of single quotes
Previously spell checker ignored text in single quotes however this
meant incorrect spelling was ignored in text where it shouldn't have
been.

In cases single quotes were used for literal strings
(such as variables, code & compiler flags),
replace these with back-ticks.

In cases they were used for UI labels,
replace these with double quotes.

In cases they were used to reference symbols,
replace them with doxygens symbol link syntax (leading hash).

Apply some spelling corrections & tweaks (for check_spelling_* targets).
2025-04-26 11:17:13 +00:00
Clément Foucault
59df50c326 GPU: Refactor Qualifier and ImageType
This allow to use types closer to GLSL in resource
declaration.

These are aliased for clarity in the GPU
module (i.e. `isampler2D` is shortened to `Int2D`).

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137954
2025-04-24 14:38:13 +02:00
Brecht Van Lommel
388a21e260 Refactor: Eliminate various void pointers passed to MEM_freeN
It's safer to pass a type so that it can be checked if delete should be
used instead. Also changes a few void pointer casts to const_cast so that
if the data becomes typed it's an error.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Jacques Lucke
f442c86197 Depsgraph: improve type safety when getting evaluated or original ID
The goal here is to avoid having to cast to and from `ID` when getting the
evaluated or original ID using the depsgraph API, which is often verbose and not
type safe. To solve this, there are now `DEG_get_original` and
`DEG_get_evaluated` methods which are templated on the type and use a new
`is_ID_v` static type check to make sure it's only used with valid types.

This allows removing quite some verbosity on all the call sites. I also removed
`DEG_get_original_object`, because that does not have to be a special case
anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/137629
2025-04-17 13:09:20 +02:00
Clément Foucault
a6fa1b5969 DRW: Rename common_*_lib.glsl to follow module prefix 2025-04-16 20:19:09 +02:00
Aras Pranckevicius
cc741fbf99 IO: New FBX importer (C++, via ufbx)
Adds a C++ based FBX importer, using 3rd party ufbx library (design task:
#131304). The old Python based importer is still there; the new one is marked
as "(experimental)" in the menu item. Drag-and-drop uses the old Python
importer; the new one is only in the menu item.

The new importer is generally 2x-5x faster than the old one, and often uses
less memory too. There's potential to make it several times faster still.

- ASCII FBX files are supported now
- Binary FBX files older than 7.1 (SDK 2012) version are supported now
- Better handling of "geometric transform" (common in 3dsmax), manifesting
  as wrong rotation for some objects when in a hierarchy (e.g. #131172)
- Some FBX files that the old importer was failing to read are supported now
  (e.g. cases 47344, 134983)
- Materials import more shader parameters (IOR, diffuse roughness,
  anisotropy, subsurface, transmission, coat, sheen, thin film) and shader
  models (e.g. OpenPBR or glTF2 materials from 3dsmax imports much better)
- Importer now creates layered/slotted animation actions. Each "take" inside
  FBX file creates one action, and animated object within it gets a slot.
- Materials that use the same texture several times no longer create
  duplicate images; the same image is used
- Material diffuse color animations were imported, but they only animated
  the viewport color. Now they also animate the nodetree base color too.
- "Ignore Leaf Bones" option no longer ignores leaf bones that are actually
  skinned to some parts of the mesh.
- Previous importer was creating orphan invisible Camera data objects for
  some files (mostly from MotionBuilder?), new one properly creates these
  cameras.

Import settings that existed in Python importer, but are NOT DONE in the new
one (mostly because not sure if they are useful, and no one asked for them
from feedback yet):

- Manual Orientation & Forward/Up Axis: not sure if actually useful. FBX
  file itself specifies the axes fairly clearly. USD/glTF/Alembic also do
  not have settings to override them.
- Use Pre/Post Rotation (defaults on): feels like it should just always be
  on. ufbx handles that internally.
- Apply Transform (defaults off, warning icon): not sure if needed at all.
- Decal Offset: Cycles specific. None of other importers have it.
- Automatic Bone Orientation (defaults off): feels like current behavior
  (either on or off) often produces "nonsensical bones" where bone direction
  does not go towards the children with either setting. There are discussions
  within I/O and Animation modules about different ways of bone
  visualizations and/or different bone length axes, that would solve this
  in general.
- Force Connect Children (defaults off): not sure when that would be useful.
  On several animated armatures I tried, it turns armature animation
  into garbage.
- Primary/Secondary Bone Axis: again not sure when would be useful.

Importer UI screenshots, performance benchmark details and TODOs for later
work are in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/132406
2025-04-16 09:55:00 +02:00
Jason C. Wenger
702efd6846 BMesh: add a BM_faces_join() to return a duplicate face (if found)
Every call to BM_faces_join and BM_faces_join_pair has been adjusted to
provide the new face pointer, and a BLI_assert_msg has been added so
that doubles are now consistently identified and flagged as a problem.
BM_faces_join is now also capable of automatically reusing a double
when it is found. This new behavior is currently unused at this point.
Future patch-sets will begin to use it, allowing simplification of
calling functions.

Ref: !137406
2025-04-15 11:03:15 +00:00
Campbell Barton
c49e6a7dd4 Cleanup: reference operators as symbols, spelling in comments 2025-04-15 15:22:53 +10:00
Andrej730
035c0c8606 Fix: PyDocs: document bpy_prop_collection.values() possible None values
Document `bpy_prop_collection.values()` possibility of having
`None` values, unlike `.items()` that seems returns only bpy structs as it's values.

Example snippet with `None` values:
```python
>>> C.object.data.materials
bpy.data.meshes['Cube'].materials
>>> type(C.object.data.materials)
<class 'bpy_prop_collection'>
>>> C.object.data.materials.append(None)
>>> C.object.data.materials.append(None)
>>> C.object.data.materials.append(None)
>>> C.object.data.materials.values()
[bpy.data.materials['Material'], None, None, None]
>>> C.object.data.materials.items()
[('Material', bpy.data.materials['Material'])]
```

Pull Request: https://projects.blender.org/blender/blender/pulls/137302
2025-04-14 11:26:04 +02:00
Campbell Barton
5affe5fc6d Cleanup: spelling in comments (make check_spelling_*) 2025-04-12 19:31:29 +10:00
Campbell Barton
10e1aaf02c PyAPI: add imbuf.load_from_buffer to support loading images from memory
Add a Python wrapper for IMB_load_image_from_memory.
2025-04-12 18:56:12 +10:00
Campbell Barton
3bf92a6e83 Cleanup: rename nullptr to null for null-characters 2025-04-11 23:55:00 +00:00
Clément Foucault
9990273d04 GPU: Change Type enum to use lower case values
This is to help for future resource declaration
using macros.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137367
2025-04-11 22:39:01 +02:00
RedMser
ba04393fde Cleanup: Remove deprecated Python and Rigid Body Joint constraints
Remove long-deprecated constraints that will likely never be
implemented in this form.

- Rigid Body Joint Constraint was removed in 2.80, but some references
  remained in the code. Versioning code was written that tried to
  remove them on load, but since constraint initialization code sets
  the type to CONSTRAINT_TYPE_NULL before versioning gets a chance,
  the versioning code ended up never running. This has all been
  removed.
- Python/Script Constraint never worked since 2.50 and showed an error
  message in the UI panel.

These constraints now load as 'null' constraint, as seems to be
(looking at the code) the way that Blender currently deals with
removed constraint types. These still show up in the outliner and
python API, but have no UI panel. Removing such constraints completely
will be left for another time, as it is beyond the scope of removing
these two specific constraint types.

Pull Request: https://projects.blender.org/blender/blender/pulls/136672
2025-04-11 11:38:29 +02:00
Campbell Barton
ab20edf469 RNA: support flagging properties as support blend file relative prefix
Some paths in Blender support the `//` prefix for blend-file relative
paths however this is not communicated anywhere.

Support declaring this with a new flag which can be applied to filepath
& dirpath typed properties.

This is used to:

- Show red-alert when "//" are used in paths which don't support a relative prefix.
- Show a warning in the tooltip that the relative suffix is used when unsupported.
- Python warns if this prefix is ever used in an assignment or
  function argument.

Resolves #133456.

Ref !137060
2025-04-10 23:27:21 +00:00
Sean Kim
5a5db5ea88 WM: Pass tablet tilt data to paint cursor draw callback
Part of #82877

When drawing specialized cursors for the different paint modes via the
`wmPaintCursor` draw callback, tablet tilt direction is unavailable to
use to customize the drawing for the user.

To enable this functionality, this commit adds the `x_tilt` and `y_tilt`
data read while processing MOUSEMOVE events to the `eventstate` variable
so it can be used by consuming functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/137189
2025-04-09 23:07:03 +02:00
Campbell Barton
12f0164eb0 CMake: match defines & CMake variable names
Avoid mistakes with these variables getting mixed up
(see: bf03a2684b).

Ref !137183
2025-04-09 08:44:36 +00:00
Campbell Barton
e94068e8d2 PyAPI: add "image_webp" build option
Match other image_* format booleans.
2025-04-09 10:26:55 +10:00
Campbell Barton
bf03a2684b Fix: error with CMake checking the wrong WEBP variable 2025-04-09 10:21:37 +10:00
Jacques Lucke
3a7dc6ed7f Cleanup: improve comment 2025-04-08 12:29:02 +02:00
Jacques Lucke
53072e7a67 Cleanup: remove unnecessary null check
The null check is not necessary, because the function does not fail
because `PyUnicode_Check` is used on the value already.
2025-04-08 12:29:02 +02:00
Jacques Lucke
82aa6a3b71 Cleanup: improve comment for GeometrySet.name 2025-04-08 12:29:01 +02:00
Jacques Lucke
9c89e9c6fd Fix: raise exception when passing arguments to GeometrySet constructor 2025-04-08 12:29:01 +02:00
Jacques Lucke
d8a959f34a Cleanup: avoid error-prone function cast 2025-04-08 09:54:39 +02:00
Jacques Lucke
6f022e0530 Fix #137127: missing null check when accessing GeometrySet.mesh 2025-04-08 09:50:10 +02:00
Campbell Barton
256d964879 Cleanup: avoid function casts for BlenderAppTranslationsType 2025-04-08 14:57:14 +10:00
Clément Foucault
9d06508837 Fix #137052: GPU: Crash on startup caused by legacy pyGPU API
The removed legacy API was still in used by the pyGPU API.
Add a deprecation warning instead.

This partially reverts commit 3179cb0069.
2025-04-07 12:27:48 +02:00
Campbell Barton
1c702f9c94 Cleanup: assign the property flag to a variable 2025-04-06 10:48:36 +00:00
Campbell Barton
e85c18eb92 Cleanup: remove redundant casts 2025-04-06 20:39:39 +10:00
Campbell Barton
b43159088c Fix: use of non UTF8 string copy for thick wrapped strings in Python
Avoid potential incomplete UTF8 sequences in the Python RNA API.
2025-04-06 19:40:29 +10:00
Clément Foucault
3562433ae7 pyGPU: Deprecate Shader.program getter
This is getting in the way of making the
GPUShader API more threadsafe.

This getter already doesn't work for vulkan
and Metal, and has very limited usage.

Keeping the python function to avoid errors
and display a deprecation warning.

Pull Request: https://projects.blender.org/blender/blender/pulls/136983
2025-04-04 14:23:09 +02:00
Campbell Barton
4139d4a8f0 Cleanup: spelling in comments (make check_spelling_*) 2025-04-04 12:48:04 +11:00
nutti
eb3fb565bd PyDoc: correct formatting for GPUShaderCreateInfo.depth_write
Ref !136846
2025-04-04 10:18:34 +11:00
Campbell Barton
cf7d119e94 PyDoc: clarify the "capsule" return type 2025-04-02 03:02:04 +00:00
Campbell Barton
e58574e1aa Cleanup: minor corrections to code-comments 2025-04-02 03:02:03 +00:00
Campbell Barton
90fd070c28 Cleanup: spelling in comments (make check_spelling_*) 2025-04-02 03:02:01 +00:00
Jacques Lucke
46fc5cb2cf Python: flush stdout and stderr after running Python script
When debugging with gdb in vscode, the stuff I print when executing a script in
the text editor does not show up in the terminal. It does work when I flush
explicitly though using `print(..., flush=True)`. This is quite annoying.

The solution is to always flush `stdout` and `stderr` automatically when running
a script. This is done using the CPython API, as just using
`fflush(stdout/stderr)` did not solve the issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/136632
2025-04-01 12:41:38 +02:00
Campbell Barton
3e496a5dfe Cleanup: add missing doxygen file headers 2025-04-01 12:35:01 +11:00
Campbell Barton
7ae020ecd1 Cleanup: use our utility function to create a PyUnicode from a std:str 2025-04-01 12:33:56 +11:00
Campbell Barton
e3d6051181 Cleanup: suppress cast-function-type warnings for CLANG
Extend the existing GCC pragma's and add the warning suppression
for Cycles & Freestyle.
2025-04-01 12:06:03 +11:00
Campbell Barton
ccbf8c0544 Cleanup: resolve unknown pragma warning for CLANG 2025-04-01 12:05:25 +11:00
Jeroen Bakker
5a5471b622 Python: Add GPUShaderCreateInfo.depth_write method
Setting depth_write option of ShaderCreateInfo isn't available in
python GPU module. This PR adds support of it.

References #136732

Pull Request: https://projects.blender.org/blender/blender/pulls/136752
2025-03-31 12:37:56 +02: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
38d9d971e5 WM: add a "Hyper" capability flag
Avoids the need to check against ghost backends.
2025-03-28 13:46:39 +11:00