Commit Graph

103 Commits

Author SHA1 Message Date
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10: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
YimingWu
a143a99634 Fix #128247: Show warning when applying rotation on invalid matrix
When a object matrix has a determinant of 0 (which typically means 0s on
one or more of the scale axes), the matrix inversion would become
invalid thus the inversion matrix will be quietly set to diag(0). This
would basically reset all vertices to the origin of the object after
applying the inversion matrix. This happens in the "apply rotation"
stage.

Now addtional warnings will be shown to the user when there are
objects that tries to go through such operation, and they will be
skipped.

-------

It will look like this when some objects failed, if you want to test, just scale some objects to 0 and apply rotation:

![图片](/attachments/8c80cf13-895f-4ec9-a631-9951bc961fca)

Pull Request: https://projects.blender.org/blender/blender/pulls/128273
2025-04-30 06:16:38 +02:00
YimingWu
031755b9df Fix #137792: Animation: Auto-keying for Light Track to Cursor operator
The operator "Interactive Light Track to Cursor" did not auto-key
rotation values previously, this fix makes sure that rotation property
is keyed after the operator has finished transforming the object. The
rotation property that's keyed depends on the rotation mode of the
object.

Pull Request: https://projects.blender.org/blender/blender/pulls/137796
2025-04-21 16:12:56 +02:00
Hans Goudey
448d3d04d9 Cleanup: Unify and clean up mesh transform & translation functions
Use C++ types, move to C++ header, use them consistently in the
geometry transform function.
2025-03-28 11:36:39 -04:00
Patrick Huang
8fd0a0e3f1 Fix #136361: Change empty size when applying scale transform.
Apply transform behavior for empties is now consistent.
Applying scale always changes empty size to keep apparent size.
Previously, empty size is only changed when applying scale only.

Pull Request: https://projects.blender.org/blender/blender/pulls/136534
2025-03-27 08:09:04 +01:00
Campbell Barton
10233e95dd Cleanup: use a typed enum for operator & gizmo callbacks
Callbacks: exec invoke & modal now use a typed enum wmOperatorStatus.

This helps avoid mistakes returning incompatible booleans or other
values which don't make sense for operators to return.

It also makes it more obvious functions in the WM API are intended
to be used to calculate return values for operator callbacks.

Operator enums have been moved into DNA_windowmanager_enums.h
so this can be used in other headers without loading other includes
indirectly.

No functional changes expected.

Ref !136227
2025-03-20 21:11:06 +00:00
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +01:00
Campbell Barton
007d46ef6d Cleanup: rename "opengl" to "gpu" for 3D viewport utilities 2025-02-04 21:19:28 +11:00
Hans Goudey
c6f5c44350 Cleanup: Remove unused includes in editors modules
Pull Request: https://projects.blender.org/blender/blender/pulls/133166
2025-01-16 23:17:51 +01:00
Hans Goudey
c62a032fab Cleanup: Use C++ math API for some object dimensions and bounds functions
To enable a fix and further cleanup in this area.
2024-12-20 19:29:18 -05:00
Campbell Barton
ababc2e01b Fix #120778: depth navigation ignores camera & light objects
Restore overlay depth drawing which was removed in [0].
For viewport navigation this is useful. Disable overlays
for other operations such as painting & object placement.

Also disable color drawing in the overlay_next engine drawing
when drawing depth, since it caused the viewport to show a
checkered backdrop.

Details:

A boolean argument has been added to ED_view3d_depth_override instead
of new enums in eV3DDepthOverrideMode since mixing object-filtering
and draw-type in the one enum gets verbose & awkward, where most
existing enums would have needed to include NO_OVERLAY in their name.

V3D_DEPTH_NO_OVERLAYS has been renamed to V3D_DEPTH_ALL,
the caller must pass in use_overlay as false.

[0]: 5fea1eda36
2024-12-03 11:00:27 +11:00
Christoph Lendenfeld
b38d8ecb86 Refactor: move keyingsets to animrig
No functional changes intended.

This patch moves the relevant keying set code from editors to animrig.
All functions are in the animrig namespace, and as such have lost their
`ANIM_` prefix.
Other than that, the code has been moved as is into `animrig/intern/keyingsets.cc`

Note that I also had to move `id_frame_has_keyframe` and `fcurve_frame_has_keyframe`.
I moved that into `ANIM_keyframing.hh` and `ANIM_fcurve.hh` since I found that more fitting.

Due to Windows defining `DELETE` as macro I had to rename `ModifyKeyMode::DELETE`
to `ModifyKeyMode::DELETE_KEY`

As a result of this two includes from animrig to editors were removed.

This is part of #121336

Pull Request: https://projects.blender.org/blender/blender/pulls/129980
2024-11-15 10:51:41 +01:00
Hans Goudey
a804320138 Cleanup: Remove unused grease pencil legacy handling in some operators
See #123468.
2024-11-02 23:14:41 +01:00
Jesse Yurkovich
81f439ff37 Fix #128916: Tag Light ID when applying scale
When applying scale on a light in the viewport, ensure we tag the light
itself for updating. Otherwise, the viewport get confused over which
size to use.

Pull Request: https://projects.blender.org/blender/blender/pulls/129030
2024-10-15 20:24:32 +02:00
Falk David
3c8d4becc8 Cleanup: GPv3: Return reference from GreasePencil::layer() functions
Since we only assert and never return `nullptr`, it's better to just return a reference.
The access into the span already asserts anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/128025
2024-09-23 13:54:02 +02:00
casey bianco-davis
421d6c55ae GPv3: Implement the set_origin operator.
Add support the "Set Origin" operator for Grease Pencil objects.
Unlike GPv2, this will update radius properly.

Pull Request: https://projects.blender.org/blender/blender/pulls/127543
2024-09-19 15:27:29 +02:00
casey bianco-davis
4fc665e4a1 GPv3: Apply Transform operator
Add support for the `Apply Object Transform` operator.

Unlike GPv2, this will update the radius properly.

Pull Request: https://projects.blender.org/blender/blender/pulls/126442
2024-09-13 11:08:37 +02:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
Campbell Barton
f1febee83f Cleanup: use "num" as a variable suffix 2024-07-23 15:50:05 +10:00
Christoph Lendenfeld
6ef77a0d22 Anim: Deselect Keys before inserting new keys
This commit changes the keying code to deselect keyframes when inserting new keys.
This has been discussed in the Animation & Rigging module meeting [1].
There is also an RCS post about that [2].
Doing this brings key creation in line with object creation,
where only the newly created object is selected.
There has been a previous attempt [3] to do a similar thing.

### Changes
When inserting keys by pressing `I` in the viewport or choosing a keying set,
all keys of the `Action` get deselected before inserting new keys.
New keys are selected by default.
Python RNA functions are **NOT** affected, meaning addons using
those functions will not deselect any keys by default.
The developer has to choose to do so.
To make that easier, there is a new RNA function on the action
`deselect_keys`

[1]: https://devtalk.blender.org/t/2024-05-02-animation-rigging-module-meeting/34493#patches-review-decision-time-5
[2]: https://blender.community/c/rightclickselect/K0hbbc
[3]: https://archive.blender.org/developer/D11623

Pull Request: https://projects.blender.org/blender/blender/pulls/121908
2024-07-18 14:48:00 +02:00
Brecht Van Lommel
a926f5b67d Refactor: Replace ID_IS_LINKED by !ID_IS_EDITABLE
Add new ID_IS_EDITABLE macro that checks if the ID can be edited in the
user interface. Replace usage of ID_IS_LINKED where it is used with this
meaning.

Also add a corresponding ID.is_editable property for Python.

This prepares for the ability to edit some linked datablocks for brush
assets.

Pull Request: https://projects.blender.org/blender/blender/pulls/121838
2024-05-16 14:53:09 +02:00
Hans Goudey
d95b1f120b Mesh: Store BMEditMesh in shared pointer
The main motivation for this is that it's part of a fix for #113377,
where I want to propagate the edit mesh pointers through copied
meshes in modifiers and geometry nodes, instead of just setting the
edit mesh pointer at the end of the modifier stack. That would have
two main benefits:
1. We avoid the need to write to the evaluated mesh, after evaluation
  which means it can be shared directly among evaluated objects.
2. When an object's mesh is completely replaced by the mesh from another
   object during evaluation (with the object info node), the final edit
   mesh pointer will not be "wrong", allowing us to skip index-mapped
   GPU data extraction.

Beyond that, using a shared pointer just makes things more automatic.
Handling of edit mesh data is already complicated enough, this way some
of the worry and complexity can be handled by RAII.

One thing to keep in mind is that the edit mesh's BMesh is still freed
manually with `EDBM_mesh_free_data` when leaving edit mode. I figured
that was a more conservative approach for now. Maybe eventually that
could be handled automatically with RAII too.

Pull Request: https://projects.blender.org/blender/blender/pulls/120276
2024-04-18 13:52:20 +02:00
Hans Goudey
c28db1f0a0 Cleanup: Use C++ namespace for object editors module
Move the public functions from the editors/object (`ED_object.hh`)
header to the `blender::ed::object` namespace, and move all of the
implementation files to the namespace too. This provides better code
completion, makes it easier to use other C++ code, removes unnecessary
redundancy and verbosity from local uses of public functions, and more
cleanly separates different modules.

See the diff in `ED_object.hh` for the main renaming changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/119947
2024-03-28 01:30:38 +01:00
Hans Goudey
b8b745ae1e Cleanup: Move remaining editors internal headers to C++ 2024-03-27 02:45:27 +01:00
Hans Goudey
c61ecf1f40 Cleanup: Move Mesh edit_mesh pointer to runtime data
The edit mesh is never saved to files, so it should be in the runtime struct.

Pull Request: https://projects.blender.org/blender/blender/pulls/119766
2024-03-21 23:18:49 +01:00
Sergey Sharybin
87a98c361c Fix: Crash when parenting mesh to armature with automatic weights
There probably are more cases where crash will happen as it is
rooting into the issue with BKE_object_workob_calc_parent() which
is used in multiple places.

The issue is caused by the access to a runtime field of workob
outside of the BKE_object_workob_calc_parent(): the runtime field
is stack-allocated in the function, and can not be accessed outside
of the function.

The easiest way to reproduce is to use ASAN, and parent mesh to an
armature with automatic weights. Although, on macOS ASAN did not
report issues, so setting workob->runtime to nullptr at the end of
of the BKE_object_workob_calc_parent() was the easiest.

The solution is simple: make the function to return the matrix,
and take care of the working object inside of it, so all tricky
parts are hidden from the API.

The patch is targeting the main branch, as in 4.1 it is not
required to do such change because all uses of the function only
access object_to_world, which is stored in the object in 4.1.

A double-check in the what_does_obaction() might be needed as it
follows the similar pattern, but it does not seem that runtime
field of the workob is accessed in usages of the what_does_obaction().

Pull Request: https://projects.blender.org/blender/blender/pulls/118847
2024-02-28 15:06:02 +01:00
Harley Acheson
2c8a3243ee UI: Improvements to Confirmation of Apply Transforms
A more informative confirmation dialog to confirm that the user wishes
to apply transforms to an object with multiple users.

Pull Request: https://projects.blender.org/blender/blender/pulls/117157
2024-02-24 01:32:53 +01:00
Hans Goudey
81a63153d0 Despgraph: Rename "copy-on-write" to "copy-on-evaluation"
The depsgraph CoW mechanism is a bit of a misnomer. It creates an
evaluated copy for data-blocks regardless of whether the copy will
actually be written to. The point is to have physical separation between
original and evaluated data. This is in contrast to the commonly used
performance improvement of keeping a user count and copying data
implicitly when it needs to be changed. In Blender code we call this
"implicit sharing" instead. Importantly, the dependency graph has no
idea about the _actual_ CoW behavior in Blender.

Renaming this functionality in the despgraph removes some of the
confusion that comes up when talking about this, and will hopefully
make the depsgraph less confusing to understand initially too. Wording
like "the evaluated copy" (as opposed to the original data-block) has
also become common anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118338
2024-02-19 15:54:08 +01:00
Hans Goudey
1c0f374ec3 Object: Move transform matrices to runtime struct
The `object_to_world` and `world_to_object` matrices are set during
depsgraph evaluation, calculated from the object's animated location,
rotation, scale, parenting, and constraints. It's confusing and
unnecessary to store them with the original data in DNA.

This commit moves them to `ObjectRuntime` and moves the matrices to
use the C++ `float4x4` type, giving the potential for simplified code
using the C++ abstractions. The matrices are accessible with functions
on `Object` directly since they are used so commonly. Though for write
access, directly using the runtime struct is necessary.

The inverse `world_to_object` matrix is often calculated before it's
used, even though it's calculated as part of depsgraph evaluation.
Long term we might not want to store this in `ObjectRuntime` at all,
and just calculate it on demand. Or at least we should remove the
redundant calculations. That should be done separately though.

Pull Request: https://projects.blender.org/blender/blender/pulls/118210
2024-02-14 16:14:49 +01:00
Campbell Barton
b372ebae68 Cleanup: unused headers for source/blender/editors
Remove 1317 includes from editors.
2024-02-13 10:02:53 +11:00
Bastien Montagne
5aaadebbe4 Cleanup: Make BKE_scene.h a full Cpp header. 2024-02-10 19:16:25 +01:00
Bastien Montagne
29fe777445 Cleanup: Make BKE_report.h a full Cpp header. 2024-02-10 18:34:29 +01:00
Hans Goudey
500f09b88a Cleanup: Move metaball BKE headers to C++ 2024-01-24 11:46:39 -05:00
Hans Goudey
02582213de Cleanup: Move BKE_layer.hh to C++ 2024-01-24 10:55:16 -05:00
Bastien Montagne
af5731ce03 Cleanup: Move BKE_idtype.h to Cpp header BKE_idtype.hh 2024-01-20 19:17:36 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Jacques Lucke
a94146b82c Cleanup: move BKE_pointcloud.h to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/116990
2024-01-11 10:54:47 +01:00
Hans Goudey
7f24972911 Cleanup: Use accessor functions for point cloud positions 2023-12-20 13:25:28 -05:00
Hans Goudey
19001c9e6c Cleanup: Move attribute domain enum to C++ header, use enum class
Each value is now out of the global namespace, so they can be shorter
and easier to read. Most of this commit just adds the necessary casting
and namespace specification. `enum class` can be forward declared since
it has a specified size. We will make use of that in the next commit.
2023-12-20 13:25:28 -05:00
Hans Goudey
854cdd1180 Cleanup: Use consistent "mesh" variable name (replace "me")
"mesh" reads much better than "me" since "me" is a different word.
There's no reason to avoid using two more characters here. Replacing
all of these at once is better than encountering it repeatedly and
doing the same change bit by bit.
2023-12-08 16:40:06 -05:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Hans Goudey
14e3523ac2 Refactor: Further improvements to geometry bounds
Implement the next phases of bounds improvement design #96968.
Mainly the following changes:

Don't use `Object.runtime.bb` for performance caching volume bounds.
This is redundant with the cache in most geometry data-block types.
Instead, this becomes `Object.runtime.bounds_eval`, and is only used
where it's actually needed: syncing the bounds from the evaluated
geometry in the active depsgraph to the original object.

Remove all redundant functions to access geometry bounds with an
Object argument. These make the whole design confusing, since they
access geometry bounds at an object level.

Use `std::optional<Bounds<float3>>` to pass and store bounds instead
of an allocated `BoundBox` struct. This uses less space, avoids
small heap allocations, and generally simplifies code, since we
usually only want the min and max anyway.

After this, to avoid performance regressions, we should also cache
bounds in volumes, and maybe the legacy curve and GP data types
(though it might not be worth the effort for those legacy types).

Pull Request: https://projects.blender.org/blender/blender/pulls/114933
2023-11-27 16:14:49 +01:00
Hans Goudey
3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Hans Goudey
4bcdc57fc8 Refactor: Move object runtime data to separate allocation
Move object runtime data to a separate header and allocate it separately
as `blender::bke::ObjectRuntime`. This is how node, mesh, curves, and
point cloud runtime data is stored.

Benefits:
- Allow using C++ types in object runtime data
- Reduce space required for Object struct in files
- Increase conceptual separation between DNA and runtime data
- Remove the need to add manual padding in runtime data
- Include runtime struct definition only in files that require it

Pull Request: https://projects.blender.org/blender/blender/pulls/113957
2023-11-15 18:46:07 +01:00
Falk David
a945d938e3 Cleanup: Rename static function
Renames `calculate_mean` to `arithmetic_mean`.
2023-10-23 19:41:49 +02:00
Falk David
b164ce0cbf Refactor: Return ViewContext by value
This makes `ED_view3d_viewcontext_init` return the `ViewContext` by value instead of writing to a pointer.
No functional changes expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/113761
2023-10-17 10:34:59 +02:00
Christoph Lendenfeld
3792c2720d Refactor: remove ED_ prefix from autokeying functions
No functional changes

Since the functions now live in a namespace,
they no longer need the prefix

as a result there are now 2 functions named
`autokeyframe_object`
which is fine because they take different parameters

If both are needed is for a future patch to investigate

Pull Request: https://projects.blender.org/blender/blender/pulls/113612
2023-10-12 16:32:29 +02:00
Christoph Lendenfeld
a3831fe7af Refactor: Move autokeyframing functions to animrig
No functional changes

The following functions have been moved
`autokeyframe_cfra_can_key`
`autokeyframe_object`
`ED_autokeyframe_object`
`ED_autokeyframe_pchan`
`ED_autokeyframe_property`

they are all in a new file
keyframing_auto.cc
while the declarations are in
ANIM_keyframing.cc

The autokeyframe makros also have been moved

Pull Request: https://projects.blender.org/blender/blender/pulls/113607
2023-10-12 15:44:58 +02:00
Hans Goudey
976eaae02f Cleanup: Move BKE_object.hh to C++
Simplifies the fix to #111120, where the object bounds functions
may return a C++ type instead of `BoundBox`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113462
2023-10-09 23:41:53 +02:00