Commit Graph

3033 Commits

Author SHA1 Message Date
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
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
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
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
Campbell Barton
4139d4a8f0 Cleanup: spelling in comments (make check_spelling_*) 2025-04-04 12:48:04 +11:00
Campbell Barton
cf7d119e94 PyDoc: clarify the "capsule" return type 2025-04-02 03:02:04 +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
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
Andrej730
224b8bb116 PyDoc: add node classes to register_class doc-string
Ref: !136375
2025-03-26 16:33:34 +11:00
Campbell Barton
6960d05df8 Fix: exception showing touch-pad preferences
Regression in [0] returned null without an exception set.

[0]: d9f38fca5f
2025-03-26 15:34:07 +11:00
Bastien Montagne
14913a447c Fix #136294: Blender 4.4 is discarding exceptions occurred in operator's constructor
While using constructors in Operator classes is _really_ not
recommended, BPY code was a bit too eager to overwrite existing errors
with its own generic messages.

Now only generate these exceptions if there is no other exception
already set.
2025-03-21 11:29:59 +01:00
Campbell Barton
e1f91c2dba Cleanup: replace int with wmOperatorStatus, consistent naming
- Manually check over all direct calls to operator callbacks
  ensuring the result isn't assigned to an int.
- OPERATOR_RETVAL_CHECK() now fails unless a wmOperatorStatus is used.
- Check the return values of direct calls to callbacks.
- Remove invalid check for the return value of rna_operator_check_cb.
- Use the variable name `retval` as it's most widely used.
- Move the assignment of `retval` out of the `if` statement in
  sculpt/paint operators because it prevents assigning the result
  `const` variable.
2025-03-21 00:13:30 +00:00
Campbell Barton
2659ec12f5 Cleanup: replace int with wmOperatorStatus
Follow up to adding wmOperatorStatus, these cases were missed as they
didn't cause compiler warnings.
2025-03-21 08:34:21 +11:00
Bastien Montagne
bb89c89e7f Cleanup: python: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135852
2025-03-12 11:21:53 +01:00
Campbell Barton
9b9ed06467 Merge branch 'blender-v4.4-release' 2025-03-06 10:19:49 +11:00
Campbell Barton
2d705f90c2 PyAPI: disable assertion when building Blender as a Python module
When adding the assert I thought this wasn't happening on Linux
(since I'm unable to redo it locally).
However the builtbot hits this assert on Linux, causing tests to fail.

Resolves #135195
2025-03-06 10:17:37 +11:00
Campbell Barton
c7cde524fb Revert "PyAPI: document never none pointer/collection properties"
This reverts commit
48abc7aabc &
62599317dd.

Revert !126755 as it was only meant to impact document generation
but it infact made functional changes, see: !135352.
2025-03-04 22:20:40 +11:00
Campbell Barton
8a78a6dc61 Merge branch 'blender-v4.4-release' 2025-02-28 17:09:51 +11:00
Campbell Barton
bba5b88b29 Fix #135245: Crash passing a dict for OperatorProperties to RNA funcs
The code-path for coercing a dictionary to operator/gizmo properties
was being used RNA functions where it's not supported.

Raise a type exception instead of crashing.
2025-02-28 16:59:53 +11:00
Campbell Barton
62599317dd Fix #135009: Python: Can't Set PointerProperty to None
Correct own error applying !126755.
2025-02-25 11:04:48 +11:00
Bastien Montagne
6b0ad2e16b Refactor: Replace RNA_POINTER_INVALIDATE RNA/BPY macro usages.
Add `PointerRNA::reset()` and `PointerRNA::invalidate()` utils functions
(both simply reset the PointerRNA data to empty state).

Replace `RNA_POINTER_INVALIDATE` macro by `PointerRNA::invalidate()`.

Follow-up to !134393 and e55d478c64.
2025-02-18 12:43:43 +01:00
Andrej730
48abc7aabc PyAPI: document never none pointer/collection properties
Set never null for pointer props automatically during RNA generation.

Ref: !126755
2025-02-18 11:27:19 +11:00
Campbell Barton
9b0df7c60a Merge branch 'blender-v4.4-release' 2025-02-16 18:32:17 +11:00
Campbell Barton
c80980d10b Fix #125376: Standalone bpy module can crash on exit 2025-02-16 18:27:02 +11:00
Brecht Van Lommel
4786fbe774 Refactor: Remove extern "C" from most headers
The only remaining code in source/blender that must be compiled as C
is now datatoc generated code and the DNA defaults that use designated
initializers.

Pull Request: https://projects.blender.org/blender/blender/pulls/134469
2025-02-13 18:58:08 +01:00
Campbell Barton
e52f85b33c Cleanup: move Python's GIL ensure/release to the function start/end
Avoid errors accessing state without the GIL (#127767) by moving
GIL ensure/release to the star/end of the function body.
2025-02-13 17:56:42 +11:00
Campbell Barton
886e40f136 Merge branch 'blender-v4.4-release' 2025-02-13 17:47:20 +11:00
Campbell Barton
39e23e29fe Cleanup: remove unnecessary call to PyGILState_Ensure
There is no need to aquire the GIL for Python methods.
2025-02-13 17:09:10 +11:00
Campbell Barton
516b39ad22 Merge branch 'blender-v4.4-release' 2025-02-13 16:57:40 +11:00