Commit Graph

815 Commits

Author SHA1 Message Date
Campbell Barton
84694bf635 Cleanup: add inline array size comments and minor corrections 2025-05-23 14:03:20 +10:00
Eqkoss / T1NT1N
bb9d5cdaad Lights: Add normalize property
When enabled, this normalize the strength by the light area, to keep
the total output the same regardless of shape or size. This is the
existing behavior.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA.

For add-ons, an API function to compute the area is added for conversion,
in case there is no native support for normalization.

area = light.area(matrix_world=ob.matrix_world)

Co-authored-by: Brecht Van Lommel <brecht@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/136958
2025-05-22 16:32:44 +02:00
Eqkoss / T1NT1N
a12bce039f Lights: Add temperature property
Similar to other renderers, this adds a temperature property to set the
light color using blackbody emission. This can be more convenient than
using nodes, and can improve interop with other software.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA and FBX.

Pull Request: https://projects.blender.org/blender/blender/pulls/134303
2025-05-22 16:32:44 +02:00
Eqkoss / T1NT1N
7e0dad0580 Lights: Add exposure property
Similar to other renderers, this adds an exposure property to multiply
the light power by 2^exposure. This can be more convenient to control
a wide range of values.

This is supported in Cycles, EEVEE, Hydra, USD, COLLADA and FBX.

Pull Request: https://projects.blender.org/blender/blender/pulls/134528
2025-05-22 16:32:44 +02:00
Jesse Yurkovich
46ec277713 USD: Add support for UsdPrimvarReader_TYPE in materials
Add support for the UsdPrimvarReader_TYPE templates for both import and
export. These are used by several USD test assets and support here
represents the last major piece of the UsdPreviewSurface spec to be
implemented.

On import these become `Attribute` nodes and on export the `Attribute`
nodes will become `UsdPrimvarReader_TYPE`'s accordingly.

Import:
- `UsdPrimvarReader_float` and `UsdPrimvarReader_int` will use the `Fac`
  output
- `UsdPrimvarReader_float3` and `UsdPrimvarReader_float4` will use the
  `Color` output
- `UsdPrimvarReader_vector`, `UsdPrimvarReader_normal`, and
  `UsdPrimvarReader_point` will use the `Vector` output

Export (only `Geometry` Attribute types are considered):
- `Fac` will use `UsdPrimvarReader_float`
- `Color` will use `UsdPrimvarReader_float3`
- `Vector` will use `UsdPrimvarReader_vector`
- `Alpha` is not considered

MaterialX note:
Hydra-native support is a bit more involved and will have to be done
separately. Hydra w/USD sync is trivial to implement but those changes
have been left out here.

Pull Request: https://projects.blender.org/blender/blender/pulls/135143
2025-05-19 19:47:22 +02:00
Jesse Yurkovich
3b2bbad609 USD: Add support for Text objects during export
Similar to the existing meta-ball export, and the other exporters,
convert Text objects to meshes for export.

Ref #138883

Pull Request: https://projects.blender.org/blender/blender/pulls/138903
2025-05-16 22:12:48 +02:00
Jesse Yurkovich
2b4eb5ccfd Fix: USD: Don't attempt to export the special sharp_face attribute
While it hasn't seemed to affect anything currently, it's unnecessarily
wasteful in the resulting file and risky to be importing back in.

Pull Request: https://projects.blender.org/blender/blender/pulls/138699
2025-05-10 08:08:16 +02:00
Brecht Van Lommel
321e9e049e Fix: USD material reader uses fixed colorspace names
For other OpenColorIO configurations these may not exist or have a
different meaning.
2025-05-02 17:39:56 +02:00
Jesse Yurkovich
4a0391c4a1 Cleanup: USD: Shrink the USDPrimReader base class
Shrinks the USDPrimReader base class by 24 bytes
- Uses `StringRefNull` in place of a full `string` (prevents additional
  runtime allocations)
- The `prim_path` field is only used sparingly, mostly for tracing, and
  a few non-perf-critical paths. No use keeping it around when it's
  easily, and quickly, accessible through other means.

Pull Request: https://projects.blender.org/blender/blender/pulls/138232
2025-05-01 06:30:55 +02:00
Michael B Johnson
79c318f692 Fix #137973: Add MaterialX version info on USD export
This change adds MaterialX version information to the exported MaterialX
USD materials.

Details:

In USD 25.02, the MaterialXConfigAPI schema was introduced to allow
recording the MaterialX version used to author a material. When loading
MaterialX documents into USD, this schema is automatically applied and
the associated version attribute is created on the material.

Due to how the MaterialX export works (via copying the composed
MaterialX spec from a temporary stage), the MaterialXConfigAPI needs to
be explicitly applied to the final material being exported.

This change applies this MaterialXConfigAPI schema and copies the
version attribute from the temporary MaterialX stage to the final stage.

Authored by Apple: Dan Knowlton

Co-authored-by: Dan Knowlton <d_knowlton@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/137974
2025-04-30 19:54:17 +02:00
Hans Goudey
a2fac05e9d BLI: Add configurable inline buffer to VectorSet
Allow configuring the inline buffer capacity for the slots array, and
add an inline buffer for the keys vector. Previously there was always
an allocation when adding an element.

The inline capacity is manually configured in a few places as part of
this commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/136461
2025-04-29 18:52:30 +02: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
Jesse Yurkovich
cdaa1ebe56 Cleanup: Fix type-limits warning with GCC
Pull Request: https://projects.blender.org/blender/blender/pulls/138020
2025-04-25 23:59:15 +02:00
Jesse Yurkovich
ba60868477 USD: Animated camera property import
Imports in the following animated data from UsdGeomCameras:
- Focal length
- DOF distance
- DOF fstop
- Clip start, Clip end
- Tilt shift x, Tilt shift y
- Aperture sizes (with caveats)

Implementation wise, it's more complicated than I'd like due to needing
to read in both non-animated and animated data for each property. And
because I've tried to reduce the duplication of various transforms we
have to do on each value. E.g. scaling values by "tenth of scene units"
or the extraction of the USD clipping range from a GfVec2f into 2
separate properties, and 2 separate fcurves, in Blender etc. The current
approach was the best I could come up with so far.

Aperture sizes remain problematic for import, with animation data and
without, due to how Blender selects the largest sensor dimension to base
downstream calculations on and for which there's no concept in USD to
strictly dictate which dimension to use. Additionally, changing the
sensor size will impact the Tilt values as well. This means that if the
Aperture sizes are animated, we must also animate the tilt values; leads
to more fcurves being created than perhaps expected.

The `projection` attribute (perspective and orthographic) remains
unchanged (non animated only) due to differences in how USD<>Blender
interoperate with the Orthographic projection method. Note: Blender only
exports perspective cameras due to the same reason.

Pull Request: https://projects.blender.org/blender/blender/pulls/137487
2025-04-25 19:57:12 +02:00
Jesse Yurkovich
bc0a9d31e5 Cleanup: USD: Various non-functional cleanups to usd_reader_material
Changes
- `Main` and `NodePlacementContext` are never-null, so use references
  where possible for these types.
- Move the node placement and node caching logic inside the
  NodePlacementContext class itself.
- Remove effectively dead code which checked return value of
  `node_add_static_node` for built-in node types.

Pull Request: https://projects.blender.org/blender/blender/pulls/137797
2025-04-22 20:24:23 +02:00
Hans Goudey
685894b665 Cleanup: Use Span argument for KeyBlock conversion function 2025-04-22 09:39:52 -04:00
Campbell Barton
2196d365f2 Cleanup: various non functional changes 2025-04-22 17:36:20 +10:00
Campbell Barton
4935672317 Cleanup: replace inline check with BLI_path_is_rel 2025-04-22 17:30:54 +10:00
Brecht Van Lommel
d0477ffe2d Fix: Incorrect use of StringRef in USD logging
From refactor in b6372b3af3
2025-04-21 17:59:41 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Jesse Yurkovich
b6372b3af3 Cleanup: USD: Use StringRef in more places
Reduce the usage of raw `char *` and `std::string` in a variety of
places where they weren't needed.

General notes:
- Anything used for output or reporting needs to be `StringRefNull`
- No additional strlen calls should be incurred beyond what was already
  present
- Memory lifetime is still valid according to ASAN

Pull Request: https://projects.blender.org/blender/blender/pulls/137747
2025-04-19 04:48:34 +02:00
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Aras Pranckevicius
6b9de30ff1 Anim: Add function for batch-creation of many f-curves, use in USD import
Creating f-curves one by one is quadratic complexity due to:
1) scanning all existing f-curves for possible name+index duplicates,
2) channelbag invariants recalculation after each f-curve addition.
3) f-curve array storage is reallocated for each f-curve addition.

In cases when many f-curves are created at once (primary case:
importing an animated character), using the newly added
fcurve_create_many is much faster, because it:
1) uses a hashtable for duplicate name+index checking, instead of
   linear scan, and
2) recalculates channelbag invariants just once.
3) does f-curve array reallocation just once.

Importing USD file exported out of Blender Studio "Rain Restaurant"
scene (about 20k f-curves), on Ryzen 5950X goes 2.0 sec -> 0.9 sec.

Pull Request: https://projects.blender.org/blender/blender/pulls/137004
2025-04-15 13:58:01 +02:00
Jesse Yurkovich
e45a13118d Fix #116612: Load in USD skeleton rest transforms
Import the initial set of rest transforms as the Armature's rest pose,
even if there's no animation for the bones. The rest transforms are
already being written out during export.

Pull Request: https://projects.blender.org/blender/blender/pulls/135079
2025-04-11 22:47:49 +02:00
Bastien Montagne
bb39cfc4ee Fix compiling Blender with USD in clang19.
Some headers are missing again it'd seem...

Pull Request: https://projects.blender.org/blender/blender/pulls/137212
2025-04-09 19:07:36 +02:00
Jesse Yurkovich
778e96c033 Cleanup: USD: Remove duplicate implementation of get_unique_path
Put it in a common place.

Pull Request: https://projects.blender.org/blender/blender/pulls/136953
2025-04-03 21:27:15 +02:00
Laurynas Duburas
8f6af72a3f Curves: Custom NURBS knots
Adds new NURBS knot mode NURBS_KNOT_MODE_FREE. Knots are stored in
`CurvesGeometry::custom_knots`. Knot offsets binding them to their
curves are calculated at runtime and held in a cache. This commit adds
custom knots support to OBJ import. It is the only way create such
curves for now. Legacy curve's tools don't support this knot mode,
thus on any modification knots get regenerated and whole shape changes.
If to convert imported legacy curve to new curves, point deletion,
duplicate and extrude preserve custom knots.

Rel #99891

Pull Request: https://projects.blender.org/blender/blender/pulls/130132
2025-04-01 20:22:47 +02:00
Brecht Van Lommel
a02e0fa147 Refactor: Improve image buffer save/load function names and arguments 2025-03-27 22:07:51 +01:00
Jesse Yurkovich
b6f432254c Cleanup: USD: Remove unused argument for create_object
The `motionSampleTime` argument to `create_object` has been unused since
the dawn of time, and it's not expected to be used in the future either.

Remove the clutter.

Pull Request: https://projects.blender.org/blender/blender/pulls/136587
2025-03-27 03:52:05 +01:00
Campbell Barton
42ad772a1f Cleanup: spelling & repeated terms (make check_spelling_*)
Also use comment blocks for English text.
2025-03-27 01:13:34 +00:00
Sybren A. Stüvel
a7d787f5b9 Fix #136347: Keyframe interpolation behavior changed for BoolProperty
F-Curve interpolation uses the `FCURVE_INT_VALUES` and
`FCURVE_DISCRETE_VALUES` flags, which were not set in the keyframe
insertion function for slotted Actions. This is now resolved by making
the RNA property type part of the `FCurveDescriptor`.

Existing code has been refactored a bit, mostly to allow calling
`update_autoflags_fcurve_direct()` with just the RNA property type,
instead of passing the property itself. This avoided the need to include
pointers to RNA properties in `FCurveDescriptor`, which I think is a
slightly nicer design. It also makes it more explicit which aspect of
the property is used.

Because there's now another `std::optional<>` in the `FCurveDescriptor`,
I've also changed some `std::nullopt` to `{}` for brevity of the code,
as repeating that another time would have caused longer lines with more
rewrapping.

Pull Request: https://projects.blender.org/blender/blender/pulls/136446
2025-03-25 10:34:19 +01:00
Jesse Yurkovich
7e70e93345 Cleanup: USD: Small header adjustment to usd_asset_utils
Adjustment from recent clang19 build problems. Only use the more
expensive stage.h header in the implementation file where it's needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/136159
2025-03-20 18:58:31 +01:00
Brecht Van Lommel
9526fe9993 Refactor: Add BKE_mesh_new_from_object argument to ignore subdivision
Pull Request: https://projects.blender.org/blender/blender/pulls/135895
2025-03-19 14:08:37 +01:00
Bastien Montagne
9139005e82 Fix building on Clang19 on Linux.
Commit e9a21cf14c seems to have removed a bit too many includes, this
reverts one change, which seems to be enough to get it working again.

Will let @deadpin decide whether we keep this 'include all' header
include here, or go more refined in our includes.
2025-03-18 11:23:39 +01:00
Jesse Yurkovich
e9a21cf14c Cleanup: USD: various non-functional changes
- Use const in more places
- Use more appropriate headers and forward decls elsewhere
- Remove one instance of variable shadowing
- Rename an internal rna enum list and the USD operator property object
  to follow surrounding code and naming guidelines

Pull Request: https://projects.blender.org/blender/blender/pulls/136112
2025-03-18 07:18:19 +01:00
Jesse Yurkovich
e93c6e5f74 USD: Eliminate some unintentional VtArray copies
The `pxr::VtArray<T>` type is based on a copy-on-write scheme that is
very easy to trigger unnecessarily because of how the C++ type system
works[1].

Here we bypass unneeded copies by ensuring we always call the `const`
version of various accessor functions. The offending call-sites were
found by using the `VT_LOG_STACK_ON_ARRAY_DETACH_COPY` env variable.

This yields a very small 2-3% performance benefit when loading in a
typical, mixed-use, asset like e.g. the "4004 Moore Lane" scene.

[1] https://github.com/PixarAnimationStudios/OpenUSD/blob/dev/pxr/base/vt/array.h#L139

Pull Request: https://projects.blender.org/blender/blender/pulls/136014
2025-03-17 17:59:17 +01:00
Bastien Montagne
1e976ec37b Cleanup: io: 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/135976
2025-03-14 14:52:16 +01:00
Campbell Barton
bd06baf6e6 WM: rename WM_report* to WM_global_report*, note it's often bad practice
WM_report was originally added for special cases however new code
has been using this in operators for example, where reports should be
sent to the operator via BKE_report, so the caller can handle,
and so Python can catch the errors.

Rename the functions to make them less easily confused with BKE_report
and add a code-comment on why their use should be avoided.
2025-03-11 12:36:17 +11:00
Aras Pranckevicius
cc2c6692c0 Cleanup: Name more IMB things as "byte" or "float" instead of "rect" and "rectFloat"
- IB_rect -> IB_byte_data
- IB_rectfloat -> IB_float_data
- Rename some functions:
	- IMB_get_rect_len -> IMB_get_pixel_count
	- IMB_rect_from_float -> IMB_byte_from_float
	- IMB_float_from_rect_ex -> IMB_float_from_byte_ex
	- IMB_float_from_rect -> IMB_float_from_byte
	- imb_addrectImBuf -> IMB_alloc_byte_pixels
	- imb_freerectImBuf -> IMB_free_byte_pixels
	- imb_addrectfloatImBuf -> IMB_alloc_float_pixels
	- imb_freerectfloatImBuf -> IMB_free_float_pixels
	- imb_freemipmapImBuf -> IMB_free_mipmaps
	- imb_freerectImbuf_all -> IMB_free_all_data
- Remove IB_multiview (not used at all)
- Remove obsolete "module" comments in public IMB headers

Pull Request: https://projects.blender.org/blender/blender/pulls/135348
2025-03-03 17:11:45 +01:00
Hans Goudey
8b297ab168 Cleanup: Use bNodeTree all_nodes() accessor method
This is always built at runtime.

Pull Request: https://projects.blender.org/blender/blender/pulls/135321
2025-02-28 22:12:34 +01:00
Jesse Yurkovich
ea5ed269ae Merge branch 'blender-v4.4-release' 2025-02-27 16:48:42 -08:00
Jesse Yurkovich
1833d79231 Fix: USD: Don't attempt to export the special custom_normal attribute
Suppress exporting this attribute as there's no conversion to USD that
supports its data type (2d, 16-bit int) and because mesh normals (from
the `corner_normals` API) are already exported. This causes a rather
annoying UI Warning notification that the attribute isn't convertible
during export.

Pull Request: https://projects.blender.org/blender/blender/pulls/135271
2025-02-28 01:47:37 +01:00
Jesse Yurkovich
d6cdaff0c0 Cleanup: USD: remove now unneeded PXR_VERSION guards
These were primarily put in place during the library update period of
4.2 to ease the in-between time when not all platforms had updated
libraries. Also, now that we've begun depending on later version of USD
and MaterialX, there's little reason to pretend that using versions
prior to 24.03 is still supported.

Pull Request: https://projects.blender.org/blender/blender/pulls/135202
2025-02-27 00:15:41 +01:00
Jesse Yurkovich
1254cb7e03 Cleanup: USD: Use newly enabled BKE_fcurve_bezt_resize API
Pull Request: https://projects.blender.org/blender/blender/pulls/135147
2025-02-26 07:31:59 +01:00
Falk David
0db9486057 Merge branch 'blender-v4.4-release' 2025-02-24 14:12:27 +01:00
Sybren A. Stüvel
857743db9d USD: import skeletal animation as slotted Actions
The USD importer was still creating legacy Actions, which are no longer
supported in Blender 4.4. This commit updates the code to produce
slotted Actions instead.

This also avoids the need to create F-Curves "from scratch", but rather
uses the available functionality. This makes the code somewhat easier to
maintain.

Pull Request: https://projects.blender.org/blender/blender/pulls/134866
2025-02-24 12:39:52 +01:00
Maxime-Cots
92aab7c3db USD: Add Capsule_1 and Cylinder_1 Shapes to USD importer
This PR adds support for 2 additional USD Prim Shape Schemas :
* Cylinder_1
* Capsule_1

Additional tests will be added afterwards but a simple test is simply to
import the resulting file:
```python
from pxr import Usd, UsdGeom
stage = Usd.Stage.CreateNew('shapes.usda')
UsdGeom.Xform.Define(stage, '/world')
UsdGeom.Cylinder_1.Define(stage, '/world/cylinder_1')
UsdGeom.Capsule_1.Define(stage, '/world/capsule_1')
stage.GetRootLayer().Save()
```

Linked issue : https://projects.blender.org/blender/blender/issues/134138

Co-authored-by: Nig3l <nig3lpro@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/134944
2025-02-21 22:54:09 +01:00
Jesse Yurkovich
a810737716 USD: Improved sanitation of names with leading digits
USD identifiers cannot start with a digit and, like all unsupported
characters, they will be turned into an `_`. This is a bit unfortunate
since object names like "1" or "2" both become "_" in the output file.
This not only generates a naming collision, which is not currently
handled, but it needlessly loses information even when there is no
collision.

Treat leading digits separately and turn names like "1" and "2" into
"_1" and "_2" respectively. This will allow us to eventually enable the
`light_tree_node_subtended_angle` render test which uses such names for
the lights. Another recent test required investigation and then rework
due to the same problem.

Pull Request: https://projects.blender.org/blender/blender/pulls/134595
2025-02-21 20:17:42 +01:00
Jesse Yurkovich
c5b34ff17f Cleanup: IO: Use recently added radius accessors for USD and Alembic IO
Use recently added `radius` accessors for USD and Alembic PointClouds
and Curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/134704
2025-02-20 00:23:25 +01:00
Jesse Yurkovich
de5c38e969 Merge branch 'blender-v4.4-release' 2025-02-19 14:09:48 -08:00