Commit Graph

82 Commits

Author SHA1 Message Date
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 7b51d32dd9 Cleanup: Move BKE_modifier.h to C++ 2023-11-14 09:30:40 +01: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
Hans Goudey 867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Jacques Lucke cc4d5c432c RNA: move headers to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/111022
2023-08-10 22:40:27 +02:00
Hans Goudey ffe4fbe832 Cleanup: Move editors headers to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110820
2023-08-05 02:57:52 +02:00
Hans Goudey bc8c892c65 Cleanup: Move WM headers to C++
Also move a few more headers that included WM headers.

Pull Request: https://projects.blender.org/blender/blender/pulls/110815
2023-08-04 23:11:22 +02:00
Hans Goudey 731d296f35 Cleanup: Move mesh related blenkernel headers to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110730
2023-08-02 22:14:18 +02:00
Campbell Barton cfffd813c1 Cleanup: use typed enum for UI_ITEM_* flags
Using an int lead to confusion with other flags often used with buttons.
For e.g. these flags could be easily confused with uiItem::flag.
2023-07-29 15:32:45 +10:00
Hans Goudey 5a86705d4c Cleanup: Move ED_curves.h to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/110115
2023-07-15 03:44:58 +02:00
Campbell Barton 74dd0ed09e Cleanup: remove redundant struct qualifiers 2023-06-03 08:54:37 +10:00
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
Jacques Lucke 2cfcb8b0b8 BLI: refactor IndexMask for better performance and memory usage
Goals of this refactor:
* Reduce memory consumption of `IndexMask`. The old `IndexMask` uses an
  `int64_t` for each index which is more than necessary in pretty much all
  practical cases currently. Using `int32_t` might still become limiting
  in the future in case we use this to index e.g. byte buffers larger than
  a few gigabytes. We also don't want to template `IndexMask`, because
  that would cause a split in the "ecosystem", or everything would have to
  be implemented twice or templated.
* Allow for more multi-threading. The old `IndexMask` contains a single
  array. This is generally good but has the problem that it is hard to fill
  from multiple-threads when the final size is not known from the beginning.
  This is commonly the case when e.g. converting an array of bool to an
  index mask. Currently, this kind of code only runs on a single thread.
* Allow for efficient set operations like join, intersect and difference.
  It should be possible to multi-thread those operations.
* It should be possible to iterate over an `IndexMask` very efficiently.
  The most important part of that is to avoid all memory access when iterating
  over continuous ranges. For some core nodes (e.g. math nodes), we generate
  optimized code for the cases of irregular index masks and simple index ranges.

To achieve these goals, a few compromises had to made:
* Slicing of the mask (at specific indices) and random element access is
  `O(log #indices)` now, but with a low constant factor. It should be possible
  to split a mask into n approximately equally sized parts in `O(n)` though,
  making the time per split `O(1)`.
* Using range-based for loops does not work well when iterating over a nested
  data structure like the new `IndexMask`. Therefor, `foreach_*` functions with
  callbacks have to be used. To avoid extra code complexity at the call site,
  the `foreach_*` methods support multi-threading out of the box.

The new data structure splits an `IndexMask` into an arbitrary number of ordered
`IndexMaskSegment`. Each segment can contain at most `2^14 = 16384` indices. The
indices within a segment are stored as `int16_t`. Each segment has an additional
`int64_t` offset which allows storing arbitrary `int64_t` indices. This approach
has the main benefits that segments can be processed/constructed individually on
multiple threads without a serial bottleneck. Also it reduces the memory
requirements significantly.

For more details see comments in `BLI_index_mask.hh`.

I did a few tests to verify that the data structure generally improves
performance and does not cause regressions:
* Our field evaluation benchmarks take about as much as before. This is to be
  expected because we already made sure that e.g. add node evaluation is
  vectorized. The important thing here is to check that changes to the way we
  iterate over the indices still allows for auto-vectorization.
* Memory usage by a mask is about 1/4 of what it was before in the average case.
  That's mainly caused by the switch from `int64_t` to `int16_t` for indices.
  In the worst case, the memory requirements can be larger when there are many
  indices that are very far away. However, when they are far away from each other,
  that indicates that there aren't many indices in total. In common cases, memory
  usage can be way lower than 1/4 of before, because sub-ranges use static memory.
* For some more specific numbers I benchmarked `IndexMask::from_bools` in
  `index_mask_from_selection` on 10.000.000 elements at various probabilities for
  `true` at every index:
  ```
  Probability      Old        New
  0              4.6 ms     0.8 ms
  0.001          5.1 ms     1.3 ms
  0.2            8.4 ms     1.8 ms
  0.5           15.3 ms     3.0 ms
  0.8           20.1 ms     3.0 ms
  0.999         25.1 ms     1.7 ms
  1             13.5 ms     1.1 ms
  ```

Pull Request: https://projects.blender.org/blender/blender/pulls/104629
2023-05-24 18:11:41 +02:00
Hans Goudey 150943e084 Cleanup: Move remaining sculpt_paint files to C++
See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107757
2023-05-08 23:48:38 +02:00
Campbell Barton 635cccc54e Fix curve-sculpt invoke function accessing the wrong brush
The brush used to check if curve sculpt should run didn't necessarily
match the brush which was used for curve sculpt.
2023-04-30 15:08:27 +10:00
Miguel Pozo e2f0a63e55 Fix #105118: Wrong point size in sculpt density overlay
Missed the GPU_program_point_size call in acd5889e50
2023-02-23 15:15:35 +01:00
Miguel Pozo acd5889e50 Fix #105042: Regression: Sculpt density overlay not working
Fix regression after d165d6aa2a
2023-02-22 18:49:47 +01:00
Philipp Oeser e5a0a14a27 Fix #101518: Curves sculptmode Stabilize Stroke misses indicator line
Drawing code `paint_draw_smooth_cursor` would be called correctly, it
was just the color not being initialized.

This is usually done with `BKE_paint_init`, but in the case of curves
sculpting brushes this would create an additional (unnamed) brush which
should be avoided since the workspace toolsystem creates the "right"
brush anyways.

So this patch just does the minimal work to get the Stabilize Stroke
indicator line to draw (which is initializing the color).

Brought over from https://archive.blender.org/developer/D16793

(cherry picked from commit 612a4382c443bcd02e0bb5ffd1b1fdbb251f6e7b)

Pull Request #105021
2023-02-22 11:31:40 +01:00
Clément Foucault f4db58844d GPU: Fix wrong 2D shader used from 3D drawing
Regression introduced by d165d6aa2a.
2023-02-14 18:32:42 +01:00
Clément Foucault d165d6aa2a GPU: Remove GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR
This replaces `GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR` by
GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA`.

None of the usage made sense to not use the AA shader.
Scale the point size to account for the rounded shape.
2023-02-13 11:22:38 +01:00
Hans Goudey 3c8f7b1a64 Cleanup: Remove unused/redundant includes from BKE_curves.hh
Avoid including headers that are obviously redundant, and don't
include BLI_task.hh in the header file, since it isn't really related.
2023-02-08 20:29:52 -05:00
Clément Foucault b0b9e746fa BLI: Use BLI_math_matrix_type.hh instead of BLI_math_float4x4.hh
Straightforward port. I took the oportunity to remove some C vector
functions (ex: copy_v2_v2).

This makes some changes to DRWView to accomodate the alignement
requirements of the float4x4 type.
2023-02-06 21:25:45 +01:00
Ray Molenkamp b5e00a1482 Revert "BLI: Use BLI_math_matrix_type.hh instead of BLI_math_float4x4.hh"
This reverts commit 52de84b0db.

had some build issues on windows i can't quickly resolve, revert for
now while we fix the problems
2023-02-02 11:46:23 -07:00
Clément Foucault 52de84b0db BLI: Use BLI_math_matrix_type.hh instead of BLI_math_float4x4.hh
Straightforward port. I took the oportunity to remove some C vector
functions (ex: `copy_v2_v2`).

This makes some changes to DRWView to accomodate the alignement
requirements of the float4x4 type.
2023-02-02 18:11:35 +01:00
Jacques Lucke 2995165148 Cleanup: simplify wrapping CurvesGeometry in C++ 2023-01-31 18:45:55 +01:00
Falk David 70ca15670d Curves: Edit mode selection operators
This adds the following operators to edit mode:
 - `select_all`
 - `select_random`
 - `select_end`

Differential Revision: https://developer.blender.org/D17047
2023-01-20 16:40:51 +01:00
Jacques Lucke 2c2178549b Curves: add OffsetIndices abstraction
This changes how we access the points that correspond to each curve in a `CurvesGeometry`.
Previously, `CurvesGeometry::points_for_curve(int curve_index) -> IndexRange`
was called for every curve in many loops. Now one has to call
`CurvesGeometry::points_by_curve() -> OffsetIndices` before the
loop and use the returned value inside the loop.

While this is a little bit more verbose in general, it has some benefits:
* Better standardization of how "offset indices" are used. The new data
  structure can be used independent of curves.
* Allows for better data oriented design. Generally, we want to retrieve
  all the arrays we need for a loop first and then do the processing.
  Accessing the old `CurvesGeometry::points_for_curve(...)` did not follow
  that design because it hid the underlying offset array.
* Makes it easier to pass the offsets to a function without having to
  pass the entire `CurvesGeometry`.
* Can improve performance in theory due to one less memory access
  because `this` does not have to be dereferenced every time.
  This likely doesn't have a noticable impact in practice.

Differential Revision: https://developer.blender.org/D17025
2023-01-18 11:52:37 +01:00
Joseph Eagar 325105ee6f Sculpt: add support for curves sculpt to paint_init_pivot
Uses BKE_object_boundbox_get.
2023-01-13 19:58:42 -08:00
Hans Goudey c26616b2c1 Curves: Support boolean attribute selection type, simplifications
Use the same `".selection"` attribute for both curve and point domains,
instead of a different name for each. The attribute can now have
either boolean or float type. Some tools create boolean selections.
Other tools create float selections. Some tools "upgrade" the attribute
from boolean to float.

Edit mode tools that create selections from scratch can create boolean
selections, but edit mode should generally be able to handle both
selection types. Sculpt mode should be able to read boolean selections,
but can also and write float values between zero and one.

Theoretically we could just always use floats to store selections,
but the type-agnosticism doesn't cost too much complexity given the
existing APIs for dealing with it, and being able to use booleans is
clearer in edit mode, and may allow future optimizations like more
efficient ways to store boolean attributes.

The attribute API is usually used directly for accessing the selection
attribute. We rely on implicit type conversion and domain interpolation
to simplify the rest of the code.

Differential Revision: https://developer.blender.org/D16057
2023-01-03 23:05:29 -05:00
Hans Goudey 03ccf37162 Cleanup: Rename curves sculpt selection variable
It's a bit simpler to skip the "indices" in the name, that can be
assumed from the type.
2022-11-11 15:32:51 -06:00
Hans Goudey a304dfdb69 Cleanup: Improve curves sculpt code section names 2022-11-11 08:50:28 -06:00
Philipp Oeser 3f91540cef Fix T101062: sculpt curves crash using a paintcurve brush
For one, paintcurves were not considered in curves sculpt mode at all
(so you couldnt draw them). This is now enabled.

And the second issue was that since curves sculpt mode uses the reguar
paint_stroke_modal() [which handles paintcurves], this was actually
excuted, freeing the PaintStroke from SculptCurvesBrushStrokeData (but
not the CurvesSculptStrokeOperation) and immediately return
OPERATOR_FINISHED from modal (resulting in a double MEM_delete of
SculptCurvesBrushStrokeData -- in both invoke and modal).

There might be better ways to handle the memory free, for now the double
freeing is prevented by setting the operator customdata to NULL (and
check for that later).

Maniphest Tasks: T101062

Differential Revision: https://developer.blender.org/D16099
2022-11-01 12:19:14 +01: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
Hans Goudey 97746129d5 Cleanup: replace UNUSED macro with commented args in C++ code
This is the conventional way of dealing with unused arguments in C++,
since it works on all compilers.

Regex find and replace: `UNUSED\((\w+)\)` -> `/*$1*/`
2022-10-03 17:38:16 -05:00
Campbell Barton f68cfd6bb0 Cleanup: replace C-style casts with functional casts for numeric types 2022-09-25 20:17:08 +10:00
Campbell Barton c7b247a118 Cleanup: replace static_casts with functional casts for numeric types 2022-09-25 18:31:10 +10:00
Campbell Barton 77ed4651ee Cleanup: float literals 2022-09-23 15:28:48 +10:00
Germano Cavalcante 223665b994 GPU: remove 'GPU_SHADER_2D_UNIFORM_COLOR'
The only real difference between `GPU_SHADER_2D_UNIFORM_COLOR` and
`GPU_SHADER_3D_UNIFORM_COLOR` is that in the vertex shader the 2D
version uses `vec4(pos, 0.0, 1.0)` and the 3D version uses
`vec4(pos, 1.0)`.

But VBOs with 2D attributes work perfectly in shaders that use 3D
attributes. Components not specified are filled with components from
`vec4(0.0, 0.0, 0.0, 1.0)`.

So there is no real benefit to having two different shader versions.

This will simplify porting shaders to python as it will not be
necessary to use a 3D and a 2D version of the shaders.

In python the new name for '2D_UNIFORM_COLOR'' and '3D_UNIFORM_COLOR'
is 'UNIFORM_COLOR', but the old names still work for backward
compatibility.

Differential Revision: https://developer.blender.org/D15836
2022-09-05 16:34:05 -03:00
Iliay Katueshenock c94ca54cda BLI: add use_threading parameter to parallel_invoke
`parallel_invoke` allows executing functions on separate threads.
However, creating tasks in tbb has a measurable amount of overhead.
Therefore, it can be benefitial to disable parallelization when
the amount of work done per function is small.

See D15539 for some benchmark results.

Differential Revision: https://developer.blender.org/D15539
2022-07-26 11:10:16 +02:00
Hans Goudey 00a3533429 Curves: Unify poll functions, add message with no surface
The "snap to surface" operators now have "disabled" poll messages
when there is no surface object.

The implementation in most curves operators is also unified.
The goal is to avoid having to define and use the poll failure messages
in multiple places, to reduce the boilerplate that tends to be
necessary to add an operator, and to increase the likelihood that
operators are implemented with proper poll messages.

Differential Revision: https://developer.blender.org/D15528
2022-07-25 11:59:33 -05:00
Jacques Lucke 1f94b56d77 Curves: support sculpting on deformed curves
Previously, curves sculpt tools only worked on original data. This was
very limiting, because one could effectively only sculpt the curves when
all procedural effects were turned off. This patch adds support for curves
sculpting while looking the result of procedural effects (like deformation
based on the surface mesh). This functionality is also known as "crazy space"
support in Blender.

For more details see D15407.

Differential Revision: https://developer.blender.org/D15407
2022-07-22 15:39:41 +02:00
Joseph Eagar cd1e4ae448 Fix T99644: Anchored brush mode fails for negative brushes
The stroke code now supports raycasting the original mesh.
This fixes anchored mode not working for negative brushes,
which might move the mesh out of the initial mouse cursor
position.
2022-07-16 17:27:25 -07:00
Campbell Barton 8bf9d482da Cleanup: colon after params, move text into public doc-strings, spelling 2022-06-30 23:48:22 +10:00
Jacques Lucke 416aef4e13 Curves: New tools for curves sculpt mode.
This commit contains various new features for curves sculpt mode
that have been developed in parallel.

* Selection:
  * Operator to select points/curves randomly.
  * Operator to select endpoints of curves.
  * Operator to grow/shrink an existing selection.
* New Brushes:
  * Pinch: Moves points towards the brush center.
  * Smooth: Makes individual curves straight without changing the root
    or tip position.
  * Puff: Makes curves stand up, aligning them with the surface normal.
  * Density: Add or remove curves to achieve a certain density defined
    by a minimum distance value.
  * Slide: Move root points on the surface.

Differential Revision: https://developer.blender.org/D15134
2022-06-30 15:09:13 +02:00
Hans Goudey 1c61db5346 Fix: Flush mode to evaluated object when exiting curves sculpt mode
Tagging the object for copy on write in order to change the mode on the
evaluated object was already done when entering sculpt mode, it should
happen when exiting sculpt mode as well.

Also use the message system to tag updates of the mode property.
This is commonly done for other "mode switch" operators. It's
best to be consistent here, though I don't know that lacking that
caused any issues.
2022-06-28 15:57:22 -05:00
Hans Goudey f6290cd2a4 Cleanup: Remove unnecessary includes 2022-06-24 15:47:24 -05:00
Campbell Barton 84906d47dc Cleanup: format 2022-06-09 10:11:25 +10:00
Joseph Eagar 371fc68678 Paint: Fix Image Editor Cursor Disappearing (T90120)
This patch fixes T90120.  The fundamental problem is that 2d and the old 3d paint modes share a single Paint struct, ToolSettings->imapaint.  This patch is a temporary fix until the new 3d paint mode (which has its own Paint struct) is released.

The patch works by listening for `NC_SCENE|ND_MODE` inside `image_listener` in `space_image.c`.   It does not use `ED_space_image_paint_update` since that requires a `bMain.`  Instead it calls `paint_cursor_start` (which is promoted to `ED_paint_cursor_start`).  `image_paint_poll` is also promoted to an `ED_` function.

Reviewed By: Campbell Barton
Differential Revision: https://developer.blender.org/D14946
Ref D14946
2022-06-08 12:37:29 -07:00
Hans Goudey 10488d54d9 Cleanup: Use const pointers 2022-06-02 18:02:48 +02:00