Commit Graph

137 Commits

Author SHA1 Message Date
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 91346755ce Cleanup: use '#' prefix for issues instead of 'T'
Match the convention from Gitea instead of Phabricator's T for tasks.
2023-02-12 14:56:05 +11:00
Chris Blackbourn 6769acbbba BLI_math: simplify matrix multiply logic
Improve safety and correctness of matrix multiplication by using
temporary storage if one of the inputs is also the output.

No functional changes.

Differential Revision: https://developer.blender.org/D16876
Reviewed By: Campbell Barton, Sergey Sharybin
2023-01-17 11:18:33 +13:00
Sergey Sharybin f17fbf8065 Refactor: Rename Object->obmat to Object->object_to_world
Motivation is to disambiguate on the naming level what the matrix
actually means. It is very easy to understand the meaning backwards,
especially since in Python the name goes the opposite way (it is
called `world_matrix` in the Python API).

It is important to disambiguate the naming without making developers
to look into the comment in the header file (which is also not super
clear either). Additionally, more clear naming facilitates the unit
verification (or, in this case, space validation) when reading an
expression.

This patch calls the matrix `object_to_world` which makes it clear
from the local code what is it exactly going on. This is only done
on DNA level, and a lot of local variables still follow the old
naming.

A DNA rename is setup in a way that there is no change on the file
level, so there should be no regressions at all.

The possibility is to add `_matrix` or `_mat` suffix to the name
to make it explicit that it is a matrix. Although, not sure if it
really helps the readability, or is it something redundant.

Differential Revision: https://developer.blender.org/D16328
2022-11-01 10:48:18 +01:00
Antonio Vazquez 51bd26d0fa New math function to add small bias to zero axis
In some situations the zero axis can produce problems and need to add a small bias.

This function adds a small bias using the orthogonal result of the others valid axis.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D16158
6d
2022-10-05 22:11:08 +02:00
Omar Emara ac66a819c1 Realtime Compositor: Implement pixelate node
This patch implements the pixelate node for the realtime compositor.

Differential Revision: https://developer.blender.org/D15662

Reviewed By: Clement Foucault
2022-09-09 13:15:01 +02:00
Campbell Barton a7650c6206 BLI_math: ensure non-negative matrices for mat3_to_quat calculations
Making the callers responsible for this isn't practical as matrices are
often passed indirectly to a functions such as mat3_to_axis_angle,
BKE_object_mat3_to_rot & BKE_pchan_mat3_to_rot.
Or the matrix is combined from other matrices which could be negative.

Given quaternions calculated from negative matrices are completely
invalid and checking only needs to negate matrices with a negative
determinant, move the check into mat3_to_quat and related functions.

Add mat3_normalized_to_quat_fast for cases no error checking on the
input matrix is needed such as blending rotations.
2022-08-25 13:48:31 +10:00
Campbell Barton 4fb64068a7 Cleanup: use determinant_m3(m) < 0 to implement is_negative_m3/m4
Use a more direct method of checking if a matrix is negative instead of
using cross & dot product.

Also replace some determinant_m3() < 0 checks with is_negative_m3.
2022-08-24 16:34:04 +10:00
Campbell Barton b04514da5d Cleanup: match names between functions & declarations
Mostly update the declarations, in some cases rename in the function
especially when the names used were inconstant with related functions.
2022-08-22 11:20:40 +10:00
Chris Blackbourn 931779197a Fix T99684: Upgrade Averages Island Scale with options Scale UV and Shear
Differential Revision: https://developer.blender.org/D15421
2022-07-14 15:42:08 +12:00
Campbell Barton 2918a3a2a3 Cleanup: spelling in comments, minor formatting tweaks 2022-06-07 21:22:55 +10:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Campbell Barton 68a21697be Cleanup: remove "The Original Code is: ..." from code comments
This is almost always meaningless as most code has changed
since the comment was added. Besides this, version control can be used
to check if/when a file was modified.

Some cases of this were kept when they contain details
about the original copyright holder.
2022-02-09 16:04:31 +11:00
Campbell Barton 3267c91b4d Fix T91253: Slow pose bone selection with many bones
Viewport cull bones during selection to avoid depth-picking
reading the depth buffer for bones that aren't in the viewport.

Files with thousands of bones could hang blender for seconds while
selecting. The issue could still happen with overlapping bones or when
zoomed out so all bones are under the cursor, however in practice this
rarely happens.

Now files with many bones select quickly.

Related changes include:

- Split `BKE_pchan_minmax` out of `BKE_pose_minmax`.
- Add `mat3_to_size_max_axis` to return the length of the largest
  axis (used for scaling the radius).

Reviewed By: sybren

Maniphest Tasks: T91253

Ref D13990
2022-02-08 22:16:51 +11:00
Jeroen Bakker bdd74e1e93 DrawManager: Image engine support huge images.
Adding better support for drawing huge images in the image/uv editor. Also solved tearing artifacts.
The approach is that for each image/uv editor a screen space gpu texture is created that only contains
the visible pixels. When zooming or panning the gpu texture is rebuild.

Although the solution isn't memory intensive other parts of blender memory usage scales together with
the image size.

* Due to complexity we didn't implement partial updates when drawing images tiled (wrap repeat).
  This could be added, but is complicated as a change in the source could mean many different
  changes on the GPU texture. The work around for now is to tag all gpu textures to be dirty when
  changes are detected.

Original plan was to have 4 screen space images to support panning without gpu texture creation.
For now we don't see the need to implement it as the solution is already fast. Especially when
GPU memory is shared with CPU ram.

Reviewed By: fclem

Maniphest Tasks: T92525, T92903

Differential Revision: https://developer.blender.org/D13424
2022-01-28 08:37:45 +01:00
Campbell Barton 3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Campbell Barton fdb2167b4a Docs: use doxygen formatting for BLI
Differentiate doc-strings from title/section text.
2021-12-20 19:07:10 +11:00
Campbell Barton c097c7b855 Cleanup: correct unbalanced doxygen groups
Also add groups in some files.
2021-12-14 16:17:10 +11:00
Campbell Barton 9e365069af Cleanup: move public doc-strings into headers for 'blenlib'
- Added space below non doc-string comments to make it clear
  these aren't comments for the symbols directly below them.
- Use doxy sections for some headers.
- Minor improvements to doc-strings.

Ref T92709
2021-12-09 20:01:44 +11:00
Alexander Gavrilov dfa1c7e554 Split and extend unit tests for vec_roll_to_mat3_normalized.
Separate the huge test into huge logical parts and add more cases
to check. Also add a utility to check that the matrix is orthogonal,
with arbitrary epsilon values and calculations in double.

A couple of tests deliberately fail, to be fixed in following commits.

Ref D9551
2021-10-20 12:58:19 +03:00
Richard Antalik e11b33fec3 Remove math for 2D affine transform
Commit e1665c3d31 added math to do 2D affine transformations with 3x3
matrices, but these matrices are also used for 3D transformations.

Remove added functions and use 4x4 matrices for 2D transformation.

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D12510
2021-10-15 23:20:45 +02:00
Campbell Barton 9b89de2571 Cleanup: consistent use of tags: NOTE/TODO/FIXME/XXX
Also use doxy style function reference `#` prefix chars when
referencing identifiers.
2021-07-04 00:43:40 +10:00
Alexander Gavrilov bc8ae58727 Copy Transforms: implement Remove Target Shear and more Mix options.
This constraint can be naturally viewed as a prototype for a future
4x4 matrix math node (or subset thereof), since its basic semantics
already is matrix assignment. Thus it makes sense to add math options
to this constraint to increase flexibility in the meantime.

This patch adds support for several operations that would be useful:

- An option to remove shear in the incoming target matrix.

  Shear is known to cause issues for various mathematical operations,
  so an option to remove it at key points is useful.

  Constraints based on Euler like Copy Rotation and Limit Rotation
  already have always enabled shear removal built in, because their
  math doesn't work correctly with shear.

  In the future node system shear removal would be a separate node
  (and currently Limit Rotation can be used as a Remove Shear constraint).
  However removing shear from the result of the target space conversion
  before mixing (similar to Copy Rotation) has to be built into
  Copy Transforms itself as an option.

- More ways to combine the target and owner matrices.

  Similar to multiple Inherit Scale modes for parenting, there are
  multiple ways one may want to combine matrices based on context.
  This implements 3 variants for each of the Before/After modes
  (one of them already existing).

  - Full implements regular matrix multiplication as the most basic
    option. The downside is the risk of creating shear.
  - Aligned emulates the 'anti-shear' Aligned Inherit Scale mode,
    and basically uses Full for location, and Split for rotation/scale.
    (This choice already existed.)
  - Split Channels combines location, rotation and scale separately.

  Looking at D7547 there is demand for Split Channels in some cases,
  so I think it makes sense to include it in Copy Transforms too, so that
  the Mix menu items can be identical for it and the Action constraint.

Differential Revision: https://developer.blender.org/D9469
2021-07-02 15:15:05 +03:00
Hans Goudey 1012e9bbfa Cleanup: Fix inconcistent array lengths in function declarations
In some cases functions were defined with arguments of different array
lengths in headers vs. implementations. This commit fixes some of the
cases I ran into, but probably not all of them.
2021-04-28 13:13:43 -05:00
Campbell Barton 8a144b73c0 BLI_math: add orthogonalize_m#_zero_axes
Expose a this function to initialize any zeroed axes
to an orthogonal vector based on other non-zeroed axes.

This functionality already existed for `invert_m#_m#_safe_ortho`,
expose as a public function as it's useful to be able to fill in zeroed
axes of transformation matrices since they may be used in matrix
multiplication which would create degenerate matrices.
2021-04-01 21:34:35 +11:00
Hans Goudey 84a4f2ae68 Geometry Nodes: Improve performance of point distribute node
This commit refactors the point distribute node to skip realizing
the instances created by the point instance node or the collection
and object info nodes. Realizing instances is not necessary here
because it copies all the mesh data and and interpolates all
attributes from the instances when this operation does not
need to modify the input geometry at all.

In the tree leaves test file this patch improves the performance of
the node by about 14%. That's not very much, the gain is likely larger
for more complicated input instances with more attributes (especially
attributes on different domains, where interpolation would be necessary
to join all of the instances). Another possible performance improvement
would be to parallelize the code in this node where possible.

The point distribution code unfortunately gets quite a bit more
complicated because it has to handle the complexity of having many
inputs instead of just one.

Note that this commit changes the randomness of the distribution
in some cases, as if the seed input had changed.

Differential Revision: https://developer.blender.org/D10596
2021-03-08 12:45:06 -05:00
Campbell Barton b2a6e2abdb Cleanup: remove extra in trailing asterisk
Comment blocks not conforming to convention.
2021-01-20 16:14:00 +11:00
Richard Antalik e1665c3d31 VSE: Media transform redesign
This patch changes behavior of strip transform and crop feature.

Purpose of this change is to allow display arbitrary portion of input
image, simplify user interface and workflow.
Offset and Crop values in old files are converted in versioning.
Offset animation is also converted. Crop animation and animation of
crop or offset enable properties is not taken into account

Changes in behavior and interface:
- If image is added to timeline it is scaled to fit inside preview area
while maintaining aspect ratio. Image is centered. This is considered
as a baseline for further transformation.
- Scale and rotation was added, so it is possible to transform image at
it's original resolution.
- Crop will not affect image transformation (does not move image).
- Values of Crop and Transform Position are in pixels, these values are
corrected if preview is fraction of project resolution.
- Transform and Mirror panel has been removed and new Transform panel
and Crop panel is moved to Adjust panel. Mirror is now part of new
Transform panel.

Technical changes:
- Preprocessing stage must work on duplicated image, because original is
cached. Previously Crop and Offset could run at once and required only
one duplication of image. This is not the case with new algorithms, so
duplication on demand is implemented. Transformation can read original
image and will output new image that is safe to modify. It should be
possible to add crop step to transform algorithm, so that Crop won't
require previous duplication though.
- Use Crop and Use Translation checkboxes were removed. Individual
values are compared to default values to check if image needs to be
processed. In case of transform this will be done also if resolution of
source.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D8393
2020-11-02 22:15:52 +01:00
Richard Antalik 6b3eca661d Revert "VSE: Media transform redesign"
This reverts commit 0277579b28.

This commit caused build errors on Linux.
2020-11-02 20:59:21 +01:00
Richard Antalik 0277579b28 VSE: Media transform redesign
This patch changes behavior of strip transform and crop feature.

Purpose of this change is to allow display arbitrary portion of input
image, simplify user interface and workflow.
Offset and Crop values in old files are converted in versioning.
Offset animation is also converted. Crop animation and animation of
crop or offset enable properties is not taken into account

Changes in behavior and interface:
- If image is added to timeline it is scaled to fit inside preview area
while maintaining aspect ratio. Image is centered. This is considered
as a baseline for further transformation.
- Scale and rotation was added, so it is possible to transform image at
it's original resolution.
- Crop will not affect image transformation (does not move image).
- Values of Crop and Transform Position are in pixels, these values are
corrected if preview is fraction of project resolution.
- Transform and Mirror panel has been removed and new Transform panel
and Crop panel is moved to Adjust panel. Mirror is now part of new
Transform panel.

Technical changes:
- Preprocessing stage must work on duplicated image, because original is
cached. Previously Crop and Offset could run at once and required only
one duplication of image. This is not the case with new algorithms, so
duplication on demand is implemented. Transformation can read original
image and will output new image that is safe to modify. It should be
possible to add crop step to transform algorithm, so that Crop won't
require previous duplication though.
- Use Crop and Use Translation checkboxes were removed. Individual
values are compared to default values to check if image needs to be
processed. In case of transform this will be done also if resolution of
source.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D8393
2020-11-02 20:19:16 +01:00
Sebastian Parborg 2115232a16 Cleanup: Clang-Tidy readability-inconsistent-declaration-parameter-name fix
No functional changes
2020-09-04 21:04:16 +02:00
Campbell Barton 96401e2ef8 BLI_math_matrix: add invert_m4_m4_safe_ortho (m3 version too)
Unlike invert_m4_m4_safe, this calculates zeroed axes.
Useful when we need to use the inverse of an objects matrix,
keeping the valid axis, only filling in the zeroed ones.
2020-08-25 12:57:56 +10:00
Jacques Lucke 91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Jacques Lucke 725973485a Clang Tidy: enable readability-non-const-parameter warning
Clang Tidy reported a couple of false positives. I disabled
those `NOLINTNEXTLINE`.

Differential Revision: https://developer.blender.org/D8199
2020-07-13 11:27:09 +02:00
Jacques Lucke 6f985574b7 Cleanup: take includes out of 'extern "C"' blocks
Surrounding includes with an 'extern "C"' block is not necessary anymore.
Also that made it harder to add any C++ code to some headers, or include headers
that have "optional" C++ code like `MEM_guardedalloc.h`.

I tested compilation on linux and windows (and got help from @LazyDodo).
If this still breaks compilation due to some linker error, the header containing
the symbol in question is probably missing an 'extern "C"' block.

Differential Revision: https://developer.blender.org/D7653
2020-05-08 18:22:41 +02:00
Dalai Felinto 96e2bd8493 Cleanup: Fix forward declaration of headers 2020-03-06 17:26:32 +01:00
Tiago Chaves 0115568ca6 BLI_math: add 2x2 matrix utilities 2020-02-20 13:58:46 +11:00
Campbell Barton e233e492df Cleanup: rename mul_m2v2 to mul_m2_v2
Matches mul_m3_v3
2020-02-20 13:58:46 +11:00
Lukas Stockner f6aafd5186 Modifiers: Add option to directly specify a 2D transform for UVWarp
Currently the only option is to warp based on the transform of other
objects, which is inconvenient if you want to e.g. control it through
a driver - you need to set up a dummy object and go through that,
which is clunky and should be unneccessary.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6690
2020-02-15 03:37:20 +01:00
Alexander Gavrilov 33eabb8220 Action Constraint: introduce a mix mode setting.
Currently the action channels are applied after the existing
transformation, as if the action controlled a child of the
bone. This is not very natural, but more importantly, the
transform tools are not designed to work conveniently with an
additional 'pseudo-child' transformation, resulting in effects
like an unexpected pivot location.

Implementing a Before mode that integrates the action channels
as if applied to a parent allows using the special transform
tool code intended for dealing with such constraints.

Note that in either mode, Action constraints should be added
in reverse order, putting a new constraint before the existing
ones that the Action was keyframed to work together.

In order to implement the option, extract a utility from
the Copy Transform constraint code for combining transforms
with special anti-shear scale handling that matches the
Aligned Inherit Scale mode.

The Before mode also requires switching the constraint to
the Local owner space, while the After mode can still use the
World space for efficiency as before. Since the constraint
doesn't have an Owner space option in the UI, this has to be
handled in an RNA setter.

For full backward compatibility, the original simple matrix
multiplication mode is preserved as the third option, but it
is not recommended due to creating shear.

Differential Revision: https://developer.blender.org/D6297
2019-12-24 19:58:09 +03:00
Alexander Gavrilov f4056e9ec3 Copy Rotation: implement new mixing modes that actually work.
Upon close inspection, the way the Offset mode works in the
Copy Rotation constraint makes no sense, and in fact, destroys
the rotation of its owner unless either it's single axis, or
the order is set specifically to `ZYX Euler`.

Since it can't simply be changed because of backward compatibility
concerns, replace the checkbox with a dropdown that provides a set
of new modes that actually make sense.

Specifically, add a mode that simply adds Euler components together,
and two options that use matrix multiplication in different order.

The Python use_offset property is replaced with compatibility stubs.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D5640
2019-09-06 07:57:16 +03:00
Alexander Gavrilov fcf2a712ec Armature: add Inherit Scale options to remove shear or average the scale.
As an inherent property of matrix-based transformation math, non-
uniform scaling of a parent bone induces shear into the transform
matrix of any rotated child. Such matrices cannot be cleanly
decomposed into a combination of location/rotation/scale, which
causes issues for rigging and animation tools.

Blender bones have options to exclude rotation and/or scale from the
inherited transformation, but don't have any support for removing the
often undesired shear component. That goal requires replacing simple
parenting with a combination of multiple bones and constraints. The
same is true about the goal of inheriting some scale, but completely
avoiding shear.

This patch replaces the old Inherit Scale checkbox with a enum that
supports multiple options:

* Full: inherit all effects of scale, like with enabled Inherit Scale.

* Fix Shear: removes shear from the final inherited transformation.

  The cleanup math is specifically designed to preserve the main
  axis of the bone, its length and total volume, and minimally
  affect roll on average. It however will not prevent reappearance
  of shear due to local rotation of the child or its children.

* Average: inherit uniform scale that represents the parent volume.

  This is the simplest foolproof solution that will inherit some
  scale without ever causing shear.

* None: completely remove scale and shear.

* None (Legacy): old disabled Inherit Scale checkbox.

  This mode does not handle parent shear in any way, so the child
  is likely to end up having both scale and shear. It is retained
  for backward compatibility.

Since many rigging-related addons access the use_inherit_scale
property from Python, it is retained as a backward compatibility
stub that provides the old functionality.

As a side effect of reworking the code, this also fixes a matrix
multiplication order bug in the Inherit Rotation code, which caused
the parent local scale to be applied in world space. In rigger
opinion this option is useless in production rigs, so this fix
should not be a problem.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D5588
2019-09-04 10:34:21 +03:00
YimingWu 8bee9af462 BLI: double version of some math functions. 2019-08-20 21:09:55 +08:00
Philipp Oeser 036e95bb21 Fix T57767: Pivot point broken after scaling to 0 in a dimension
matrix inversion was changed in rB01c75c3765eb from own code to EIGEN
for performance reasons. EIGEN would return a zero matrix on failure
(resulting in the pivot always being at the object origin).
This brings back the "old" matrix inversion code (which has the benifit
of providing a partial solution which makes the local transform center
appear correct)

Reviewers: campbellbarton

Maniphest Tasks: T57767

Differential Revision: https://developer.blender.org/D4804
2019-05-07 10:47:19 +02:00
Alexander Gavrilov 1854cccad7 Drivers: add an Average Scale option to the Transform Channel driver vars.
Unlike location and rotation, there is a meaningful definition of
overall/average scaling via the total change in the volume. This
adds an option to retrieve that via a single driver variable,
instead of having to use three and an expression.

Using the determinant to compute the volume scaling also allows
detecting flipping due to negative scale - this is impossible
to do via the three variable approach.

The volume_scale functions are added purely for code readability:
'volume scale factor' is easier to understand than determinant.

Differential Revision: https://developer.blender.org/D4803
2019-05-06 19:03:26 +03:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Alexander Gavrilov 3380fb3646 Complete the set of matrix multiplication functions.
Also, mul_m3_m3m4 was named incorrectly.
2019-04-14 18:14:06 +03:00
Alexander Gavrilov 51c8a6f491 Fix T37500: implement Bendy bone segment deformation interpolation.
Previously B-Bone deformation mapped every vertex to just one
B-Bone segment. This results in abrupt transformation differences
between the sides of each threshold plane, reducing the quality
of B-Bone deformation and making the use of shape keys impractical.

This commit replaces this approach with a linear blend between
the two closest segment transformations, effectively representing
the B-Bone as two weight-blended plain bones for each vertex.

In order to distribute the interpolation more evenly along the
bone, segment matrices for deformation are now computed at points
between the segments and at the ends of the B-Bone. The computation
also uses the true tangents of the Bezier curve for the orientation.
The nodes at the end of the bone require some special handling to
deal with zero-length Bezier handles caused by a zero ease value.

The Copy Transforms constraint now also smoothly interpolates
rotation and scaling along the bone shape when enabled.

The initial version of the patch was submitted by @Sam200.

Differential Revision: https://developer.blender.org/D4635
2019-04-13 16:27:42 +03:00
Campbell Barton e7fd6c8f30 Cleanup: comment blocks 2019-03-19 15:17:46 +11:00
Campbell Barton de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00