1
1

Compare commits

...

508 Commits

Author SHA1 Message Date
b3d34a6690 use new style for isect_seg_seg and cross_poly 2021-01-11 18:39:12 +01:00
3c112c5e46 Merge branch 'master' into math-refactor 2021-01-11 18:22:58 +01:00
e44e0e4e78 Cloth: add a vertex group setting to exclude from object collision.
This can be useful as a workaround on the boundary with the pinned
vertices in some situations among other things, and completely copies
the existing design of the self collision vertex group setting.

Differential Revision: https://developer.blender.org/D10043
2021-01-11 19:34:33 +03:00
ac290bfbe4 Collision: allow disabling collision without removing the modifier.
The `object.collision.use` flag was treated as a redundant marker
of the existence of the modifier, going as far as adding/removing
it when the value was changed, which is not actually very useful.
Removing the modifier loses its position in the stack, and requires
a dependency graph rebuild. It feels it may be a legacy flag?

What would be useful however is the ability to toggle collisions
dynamically without removing the modifier. This patch adjusts the
code to keep the modifier when the flag is disabled, and add it
if it doesn't exist when the flag is enabled. The modifier now
checks the flag at the start and quickly exits after cleaning
up stale data. The redesigned setting is exposed in the UI.

Collisions can't be disabled by simply using the modifier enable
flags because the modifier merely saves a snapshot of the mesh at
a certain point of the modifier stack for other objects to use,
and thus has to be able to clear the stale data.

Differential Revision: https://developer.blender.org/D10064
2021-01-11 19:34:32 +03:00
b271475a9e ImBuf: Add error handling to IMB_indexer_open
Handle return value of `fread()` by printing an error and closing the
file when it cannot be read from. Not only is error handing a good idea,
it also prevents GCC from warning that the return value of `fread()`
should not be ignored:

```
.../blender/source/blender/imbuf/intern/indexer.c: In function ‘IMB_indexer_open’:
.../blender/source/blender/imbuf/intern/indexer.c:201:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  201 |     fread(&idx->entries[i].frameno, sizeof(int), 1, fp);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:202:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  202 |     fread(&idx->entries[i].seek_pos, sizeof(unsigned long long), 1, fp);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:203:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  203 |     fread(&idx->entries[i].seek_pos_dts, sizeof(unsigned long long), 1, fp);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../blender/source/blender/imbuf/intern/indexer.c:204:5: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  204 |     fread(&idx->entries[i].pts, sizeof(unsigned long long), 1, fp);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

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

Reviewed by: campbellbarton
2021-01-11 17:29:21 +01:00
bf90fcda47 ID Creation: generate session_uuid in more cases.
Previous code would not generate a session uuid for embedded IDs (like
root node trees or master collections). While this is not a problem
currently since those are not directly stored in Main data-base, this is
conceptually wrong, since those IDs still pertain the Main data.

Further more, this is blocking using `session_uuid` more in depsgraph in
place from ID pointer itself, as identifier (related to T84397).
2021-01-11 16:44:19 +01:00
1a26d15763 Fix Embedded IDs creation bypassing ID management completely.
No ID (even remotely) related to Main database should ever be created
directly through MEM_mallocN. Using `BKE_libblock_alloc` is the bare
minimum.

Note that there is no behavior change expected here.
2021-01-11 16:44:19 +01:00
2f9073adb1 Fix missing IDType init in ViewLayer tests.
Kinda miracle this did not cause problems so far, but was breaking tests
with some upcoming changes.
2021-01-11 16:44:19 +01:00
9e1ec5033d Fix T84516: ID properties have incorrect names in Python dir() list
Caused by not going through the proper accessor function to access the
property identifier.
2021-01-11 16:10:29 +01:00
98268e5c68 Cleanup: remove trailing whitespace 2021-01-11 15:49:42 +01:00
28f99dda6c Merge branch 'master' into math-refactor 2021-01-11 15:04:19 +01:00
beb5863ed4 Geometry Nodes: transform Object Info outputs to local space
Ref T83670.

Differential Revision: https://developer.blender.org/D10071
2021-01-11 15:00:29 +01:00
c083398921 BLI: fix math operation
That fixes a stupid mistake of mine that was copied a couple of times.
2021-01-11 14:59:05 +01:00
7b6e55b933 Cleanup: remove redundant UV edge selection calls
Selecting vertices and faces first checked edge selection,
this was called to set vert1 & vert2 variables which have since been
removed.

These calls should have been removed in
51f04bf7b8.
2021-01-12 00:53:33 +11:00
2a297366f0 Fix T84565: UV face select fails when zoomed in
Exposed by recent commit 246efd7286

Although this was an existing logical error causing
`uv_find_nearest_face` to only work properly when the hit distance was
initialized to FLT_MAX, which wasn't the case in multi-object edit mode.
2021-01-12 00:31:54 +11:00
98262bb8cf move remaining types 2021-01-11 13:57:04 +01:00
3e251da3aa update float2 2021-01-11 13:11:46 +01:00
fe53b6a7fb Fluid: Adjusted viscosity strength step size in UI
Step size was too small.
2021-01-11 12:55:33 +01:00
a37164e11b update float3 2021-01-11 12:55:05 +01:00
Pi Lanningham
f0ae0f490e Fix T84327: outliner_id_copy_tag was only copying from expanded nodes.
If a node was closed in the hierarchy, we would only copy that node,
even if child nodes were selected.

Reviewed By: brecht, mont29

Maniphest Tasks: T84327

Differential Revision: https://developer.blender.org/D9995
2021-01-11 12:02:06 +01:00
6e7716f32e Cleanup: Added const to RenderLayersProg methods 2021-01-11 11:46:32 +01:00
445ebcaa30 VSE: store raw images in cache
Previously raw images were not cached if image wasn't preprocessed.
This caused issue, that image had to be read from disk on every redraw.

Effect strips must be excluded, because this would cause problem with
invalidation. Effect strips can use preprocessing however. This is
mainly to allow usimg modifiers on them.

This change should follow rBf448ff2afe7a77, but I have wrongly assumed,
that it has been implemented already.

ref T80278
2021-01-11 11:38:33 +01:00
54f8a5dd73 Tests: run suites instead of individual test cases
Group all tests of a test suite into a single test command invocation.
This reduces the number of invocations by `ctest` by an order of
magnitude.

Since rB56aa5b0d8c6b663, `bin/tests/blender_test` was run for every
individual test. Having over a 1000 tests made testing slower than
necessary. Individual tests can still be run if desired by invocation of
`bin/tests/blender_test --gtest_filter=suitename.testname`.

NOTE: For this commit to have an immediate effect, it may be necessary
to remove the `tests` and `Testing` directories and some CMake files
from your build directory and rebuild. Run `ctest -N` to see the list of
tests; there should be less than 200.

Reviewed By: sergey, LazyDodo, sebbas

Maniphest Tasks: T83222

Differential Revision: https://developer.blender.org/D9649
2021-01-11 11:29:30 +01:00
63cea2b793 Fix versioning code outside of version check
Bug introduced in f448ff2afe probably due to mistake when resolving
conflicts and not checking functionality.
2021-01-11 10:55:27 +01:00
d095411002 Fix T83544: Cycles crash when rendering with Save Buffers enabled
The issue is that the "Noisy Image" pass is added even though it should not.

`use_denoising` has to be enabled on the scene and on the view layer
to actually enable it.

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

Reviewers: lukasstockner97, brecht
2021-01-11 10:21:38 +01:00
4c44a5309c Fix T84459: Face normals not displaying (AMD GPU)
This is part two of the fix for T84459.
Issue appears to be caused by AMD graphics driver later than 20.11.1 and
affects older GPUs (Polaris/FIJI cards). Drawing normals in edit mode
uses the same OpenGL data type for storing normals that is known to be
faulty.

This change fixes the face dot normals by using GPU_COMP_I16.
2021-01-11 09:52:16 +01:00
618f7df7fc Cleanup: Incorrect comment 2021-01-11 09:52:16 +01:00
9fb32b2b29 Fix T84459: Wireframe not displaying with AMD GPU
Issue appears to be caused by AMD graphics driver later than 20.11.1 and
affects older GPUs (Polaris/FIJI cards). Wireframe drawing uses the same
OpenGL data type for storing normals what is known to be faulty.

This patch enabled storing the normals using GPU_COMP_I16. It also
solves the normals drawing in edit mode for vertex and loop normals.
2021-01-11 09:52:16 +01:00
64929398fb Cleanup: skip accessing sequence strip name/source when hidden 2021-01-11 17:58:08 +11:00
a83c67c183 Fix incorrect use of BLI_snprintf in sequencer text concatenation
The start of the text was stepped over without subtracting it's length
(introduced in fad80a95fd).

Replace this logic with BLI_string_join_array to simplify construction.
2021-01-11 17:51:42 +11:00
b01e62e399 Fix missing directory separator in image/movie strip identifier 2021-01-11 17:17:10 +11:00
16aefea9fa Cleanup: use switch statement for sequence types
Also remove duplicate NULL pointer check and replace
BLI_snprintf with BLI_strncpy.
2021-01-11 17:13:27 +11:00
50104b11a1 Fix T84582: WalkNavigation.mouse_speed ignored with tablet
Scale the speed up 4x instead of clamping the value to a minimum of 4.
2021-01-11 16:33:15 +11:00
ab5986cf3a Fix T84501: Wintab button lag.
Multiple Wintab tablets do not send relative button state when
configured to do so. This causes button events to be delayed until
processed as Win32 button events.

This commit fixes the issue by configuring Wintab to use absolute
button state and tracking changes manually.
2021-01-10 21:18:46 -08:00
af88d23ffa Revert "Fix typo; Documentation; Expose layer for framebuffer attachament; Add framebuffer viewport setter; Remove framebuffer restore; Expose framebuffer push/pop stack API; Remove blend modes; Remove depth_range_set; Implement GPU_face_culling, GPU_front_facing, GPU_point_size, GPU_line_width, GPU_viewport, GPU_color_mask and GPU_depth_mask"
This reverts commit 9db3d1951d.

This was an accidental commit of the patch D8826
2021-01-10 21:07:04 -03:00
d4330ae70b Transform: In the Header, show translation value in local space only with constraint
This partially reverts commit ad15e764dd.
The local value is only useful with constraint.
2021-01-10 20:58:45 -03:00
ad15e764dd Transform: In the Header, show the translation value in local space
Showing value in the global space was an unintentional change.
2021-01-10 20:30:25 -03:00
08e44b5e3e Fix Increment Snapping Without Constraints in Non-Axis-Aligned Views
The incremental snap was always operating in the local space, which in most
cases is the VIEW type orientation.

Use only local space when the operation is affected by constraint.

Differential Revision: https://developer.blender.org/D10052
2021-01-10 20:24:46 -03:00
9db3d1951d Fix typo; Documentation; Expose layer for framebuffer attachament; Add framebuffer viewport setter; Remove framebuffer restore; Expose framebuffer push/pop stack API; Remove blend modes; Remove depth_range_set; Implement GPU_face_culling, GPU_front_facing, GPU_point_size, GPU_line_width, GPU_viewport, GPU_color_mask and GPU_depth_mask 2021-01-10 19:01:53 -03:00
1d3b92bdea UI: Improve node group input / output list interface
This commit replaces the two-column list for editing node group inputs
and outputs with a cleaner solution with two panels. The new layout
has several benefits:
 - It uses the vertical space in the node editor sidebar better.
 - It should be more familiar because of similarity with other UI lists.
 - It should look better with consistent alignment and icons.

Note that displaying the "Name" property outside of the list itself is
a bit inconsistent and could possibly be removed in the future.

Differential Revision: https://developer.blender.org/D9683
2021-01-10 13:24:37 -06:00
30310a4fc8 Fix T83777: Crash when enabling guides
Also adjusted adjusted guiding UI parameters so that guiding will not get invalidated when changing domain values.
2021-01-10 19:16:44 +01:00
5b90ed6c06 Fluid: Fix cache saving issue with OpenVDB IO
Fixes issue where files would not be written when 'resumable' option was checked.
2021-01-10 19:16:44 +01:00
Peter Fog
544e371908 Fix T84529: Crash with strip using deleted scene
If scene strip has no scene assigned, leave source string empty.
Same goes for all other strips, that use ID datablocks.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D10058
2021-01-10 17:37:07 +01:00
e45630a99f Fix sequencer disk cache not writing data
Error handling added in 512a23c3d6 caused that reading header of new
file failed, since it is empty.

Don't attempt to read header if file is empty. If header can not be read
anyway, try to delete the file. Add asserts, as this should never
happen.

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9954
2021-01-10 16:50:08 +01:00
9441413cb2 VSE: Remove fit method tool setting from header
This property was intended to affect fit method for added strips prior
to running operator. However UI team did not agree with current
implementation.

ref T84535

Reviewed By: HooglyBoogly

Differential Revision: https://developer.blender.org/D10055
2021-01-10 16:37:18 +01:00
6154aa1529 Cleanup: remove redundant decorator for eevee 'overscan_size'
All eevee scene properties are not animatable due to
`RNA_define_animate_sdna(false)` so there is no need for an animation
decorator here (would not show anyways).

Not sure if setting use_property_decorate to False and then manually
adding one again was a hack in rB7fc60bff14a6 to get the alignment
right, but seems to work good now without it.

Note: there also seems to be an inconsistency here generally:
- Eevee reserves room for an animation decorator in almost every panel
(except for "Sampling" and "Indirect Lighting") even though almost none
are animatable (except for stuff in "Hair" and "Film"). This looks nice
if multiple panels are expanded (except for mentioned "Sampling" and
"Indirect Lighting" -- maybe these should also reserve the room?)
- Cycles does not use animation decorators at all (even though pretty
much everything is animatable here -- maybe these should also use
animation decorators?)
- Then there is also the 'shared' "Grease Pencil", "Freestyle" and
"Colormanagement" -- these dont use animation decorators, but some stuff
is animatable...

Regarding the note: not sure what the guidelines here are, if this is
isolated to each panel then there is lots of stuff for eevee that could
set use_property_decorate to False, if multiple open panels are
considered (for nice visual consistency between them), then there is
romm for improvement elsewhere, too.

Maniphest Tasks: T81411

Differential Revision: https://developer.blender.org/D9164
2021-01-09 15:02:14 +01:00
fa82a15676 Cleanup: remove unused struct members
Non-projection painting in the viewport is no longer supported,
remove struct members used for this.
2021-01-09 19:07:31 +11:00
e718004edf Cleanup: use bool arguments & variables 2021-01-09 19:07:14 +11:00
246efd7286 Fix UV selection threshold which ignored image aspect and zoom level
Selecting UVs wasn't properly scaling based on the zoom or image aspect.

This now matches vertex selection in the 3D view.
2021-01-09 18:42:36 +11:00
645298be29 Fix build error after last commit 2021-01-08 23:10:58 -06:00
1bb530745f Cleanup: Use bool instead of int 2021-01-08 23:09:31 -06:00
9c07454816 Keymap: Enable repeat for "Make Edge/Face" operator
The "repeat" property was turned off by default in rBf5080c82dd91, but
it's important to have repeat turned on for this operator since it can be
used to fill large areas. This commit is similar to rBaa77689f77b4.

Fixes T84531
2021-01-08 17:19:04 -06:00
69a22a70ac Geometry Nodes: Don't start with empty group nodes selected
The nodes were selected in new node groups because they are by default,
but there's no particular reason for them to be selected, and it can
be distracting.
2021-01-08 16:29:10 -06:00
7fd19c20e0 Geometry Nodes: Gray out "New" button when curve object is active
Currently curve objects aren't supported by the node modifier, so the
new node group and modifier operator shouldn't be available.
2021-01-08 15:04:38 -06:00
3c1fcec652 Fix T84517: Two geometry node trees added with "New" button
Adding the modifier itself already adds a new node tree, which is
then displayed in the node editor because of the active object and
active modifier context. So there's no need to create the node tree
in the python code in this case.
2021-01-08 12:12:43 -06:00
bc788929aa Scenes: forbid deleting last local scene
Previously, it was only forbidden to delete the last scene. This can
lead to the situation where a .blend file only contains linked scenes.
This is problematic, because linked data might not always be available
or can be removed from a .blend file without having an additional check
for remaining scenes.

Now there always has to be at least one local scene.

Reviewers: mont29

Differential Revision: https://developer.blender.org/D10049
2021-01-08 16:39:42 +01:00
2d3f96cace Fix T84453: Crash bezier curves transfrom
The pointer allocated to the `TransData` was being incorrectly incremented,
causing misalignment and consequently `heap-buffer-overflow`.

Because of this, `TD_NOTCONNECTED` was being set in a strange way that did
not correspond to other types of `TransData`.

The solution is to not increment the `TransData` pointer and set
`TD_NOTCONNECTED` only for "unconnected" segments.

The code was also a bit deduplicated.
2021-01-08 11:22:58 -03:00
c549d736cf Icons: Update script to generate icons from SVGs for Inkscape 1.0
The command line syntax for Inkscape changed quite a bit for the 1.0 release,
see https://wiki.inkscape.org/wiki/index.php/Release_notes/1.0#Command_Line.
Think it's reasonable to expect Inkscape 1.0 or later be installed if you want
to generate the icons with the script. It's easy to get via the website, if the
distribution doesn't provide new enough packages. Only few people would use the
script anyway.

I also had to change the path for command line access on macOS which apparently
changed (https://stackoverflow.com/a/60068607). Although I didn't find a
mention of this change in the Inkscape release notes.
2021-01-08 15:07:54 +01:00
c66f00dc26 Fix Cycles rendering with OptiX after instance limit increase when building with old SDK
Commit d259e7dcfb increased the instance limit, but only provided
a fall back for the host code for older OptiX SDKs, not for kernel code. This caused a mismatch when
an old SDK was used (as is currently the case on buildbot) and subsequent rendering artifacts. This
fixes that by moving the bit that is checked to a common location that works with both old an new
SDK versions.
2021-01-08 13:38:26 +01:00
e3ae7d1f2f Fix T83942: improve error checking when trying to render high resolution volume
Reviewers: fclem

Differential Revision: https://developer.blender.org/D10032
2021-01-08 12:14:12 +01:00
c889ec916c Cleanup: clang format 2021-01-08 11:54:53 +01:00
c44a17ec4b Fix T84475: Outliner missing update when adding IDs to main via RNA
Was reported for meshes, but was true for any type.
Now add appropriate notifier to refresh the Outliner.

Maniphest Tasks: T84475

Differential Revision: https://developer.blender.org/D10030
2021-01-08 11:50:36 +01:00
1698678231 GPU: Mark AMD Polaris 20.11+ drivers with limited support.
The issue does not render wireframes correctly.
2021-01-08 11:44:31 +01:00
03f1d8acab Use the term "N-gon" instead of "Polygon" for triangulation method
This was reported for the Triangulate geometry node, but was also true
for the triangulate modifier and in exporters.

Note the modifier was introduced with "Ngon Method" in rBa7b44c82e5b9 but
was renamed to "Polygon Method" in rBf4762eb12ba5.

Since quads are also polygons (and quads have their own method), the
term "N-gon" is more appropriate here and is also described in the
glossary https://docs.blender.org/manual/en/2.92/glossary/
index.html#term-N-gon

Docs have been updated in rBM7539 (partially - the method would also
have to be renamed once this patch lands).

Note this also fixes the wrong enum used for the alembic exporter.

Fixes T83907

Maniphest Tasks: T83907

Differential Revision: https://developer.blender.org/D10022
2021-01-08 11:20:42 +01:00
4a0b8c9427 Cloth: completely exclude fully pinned triangles from collision.
Currently such triangles are effectively already excluded, because
the calculated forces are not applied to pinned vertices. However
these forces are still being computed, which is inefficient.

This adds an early check for triangles where all vertices are
pinned during BVH overlap detection, which significantly speeds
up certain use cases with big fully pinned areas that happen to
overlap a collider. In case of self collision both triangles must
be fully pinned to exclude safely, because the computation is
symmetric and handles two triangles at the same time.

Differential Revision: https://developer.blender.org/D10041
2021-01-08 12:24:50 +03:00
8877e294df Surface Deform: the Strength setting is not bind-specific.
It is used during evaluation so it shouldn't be greyed out in the UI.

Ref D10040
2021-01-08 12:24:50 +03:00
662b7c3edf Surface Deform: optimize memory allocation in the evaluation code.
Using malloc to allocate a temporary array for each vertex,
which most commonly contains just 4 elements, is not efficient.
Checking the mode with a switch is also better.

Differential Revision: https://developer.blender.org/D10040
2021-01-08 12:24:50 +03:00
ceaed47bf9 GPU: Enable HQ normal work around on Linux.
Linux does not report the driver version. It does report the OpenGL
version. This change will check the OpenGL version to enable the HQ
normal work around.
2021-01-08 10:23:20 +01:00
f448ff2afe VSE: Hide cache settings and adjust defaults
Adjust default cache settings for all files to store raw and final
images.

All settings are still available when developer extras option is
enabled in user preferences.

This is part of design task T80278

Differential Revision: https://developer.blender.org/D9745
2021-01-08 07:24:55 +01:00
09ea339a6c Cleanup: Use LISTBASE_FOREACH macro 2021-01-07 21:24:46 -06:00
15bb8f9f93 Fix file-handle leak when parsing xdg user directories 2021-01-08 13:19:11 +11:00
61f1faac3f Fix T83868: Disabled or inactive list items are not grayed out
The cause for this was quite simple-- a misplaced bitwise operation
before passing a value to the function that grayed out buttons based on
their state, caused by refactoring in rB933bf62a611f before committing.

What makes the situation a little more confusing is that the theme colors
are overridden for list buttons in UI lists, necessitating a second
call to `ui_widget_color_disabled()`. Ideally that wouldn't be necessary.
2021-01-07 16:28:26 -06:00
5530d6f86f PyAPI Docs: Terminal instructions for Windows incorrect
Fixes T84498
2021-01-07 15:58:47 -05:00
95c63babbb Cleanup: Declare variables where initialized 2021-01-07 12:30:18 -06:00
d259e7dcfb Cycles: Increase instance limit for OptiX acceleration structure building
For a while now OptiX had support for 28-bits of instance IDs, instead of the initial 24-bits (see also
value reported by OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_ID). This change makes use of
that and also adds an error reported when the number of instances an OptiX acceleration structure is
created with goes beyond the limit, to make this clear instead of just rendering an image with artifacts.

Manifest Tasks: T81431
2021-01-07 19:23:13 +01:00
3db2bc82aa Surface Deform: optimize handling of the vertex group weight.
There is no need to first copy weights to a separate array,
or create the data layer if it doesn't exist. The threaded
code can retrieve the weight directly from the layer.

Differential Revision: https://developer.blender.org/D10015
2021-01-07 21:08:44 +03:00
Juanfran Matheu
64277e8f3a UI: Use Eyedropper Cursor with Sample Weight Tool
While using the Sample Weight tool in Weight Paint mode, user eyedropper mouse cursor.

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

Reviewed by Pablo Vazquez
2021-01-07 09:44:48 -08:00
Juanfran Matheu
e3d9241a05 UI: Show Weight Value with Sample Weight Tool
While using the Sample Weight tool in Weight Paint mode, show weight value in tool header.

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

Reviewed by Pablo Vazquez
2021-01-07 09:29:36 -08:00
3db975f30d Fix T84326: No ID for geometry nodes instances after scattering
Instances are created with an "index" parameter used for persistence over
time through animation. Currently the geometry nodes instancer passes
the index in the array for this value, but the arrays created by the
"Point Distribution" node aren't necessarily stable  in this way when
the input mesh is deformed. In D9832 we already mostly solved this
problem with an `id` attribute. The solution here is to create instances
with this attribute as well.

It's important to note that deforming the instanced points *after*
distribution will usually be a better solution for this problem. This
solution is likely still important though.

Differential Revision: https://developer.blender.org/D10024
2021-01-07 09:27:42 -06:00
4c0fc60105 UndoSystem: Early out from core undo/redo handlers when undo step is NULL.
Also added `undosys_stack_validate` debug check to redo case.
2021-01-07 15:58:23 +01:00
044dd42a05 Cleanup: Undo system: minor simplification in non-debug code. 2021-01-07 15:58:23 +01:00
987e9e2145 Fix T84469: Online manual raises an exception with key-map options
Report an error instead of raising a Python exception.

Currently these properties aren't written to the manual
so it's best to show an error.
2021-01-07 23:36:25 +11:00
c55b578c9e Fix T84142: crash when mirroring hair emitted from vertices
The hair mirroring code seems to expect that hair is emitted from faces.
The PE_mirror_x contains the following expression: mirrorfaces[pa->num * 2].
This only makes sense when pa->num is a face index.

The simplest short term solution is to disable the mirror operator when
the particles haven't been emitted from faces.

Diffferential Revision: https://developer.blender.org/D10002
2021-01-07 13:32:36 +01:00
c26f46cb95 Fix T83497: missing relations update when group node changes
Changing which node group a group node references needs a depsgraph
relations update in some cases.

Differential Revision: https://developer.blender.org/D10018
2021-01-07 13:31:17 +01:00
0d042c8cca RNA: document Python instancing for ID's and RNA types
Document some of the less obvious implications for
re-using Python instances.
2021-01-07 21:36:39 +11:00
4a771263fd Outliner: use the scene ID for ObjectBase PointerRNA
While this didn't cause any problems, `Base` structs are part of the
scene which is being set in other uses of this type.
2021-01-07 16:20:08 +11:00
Yevgeny Makarov
dd0df3c5d2 UI: Fix various issues with UI text
- Use the name "Point Cloud" instead of "Pointcloud"
 - Fix a typo in UV_OT_smart_project.
 - Use the name "Install Light" to for the installation
   operator for MatCaps, HDRIs, and Studio Lights.

Fixes T83585, T65291, and T54921

Differential Revision: https://developer.blender.org/D9867
2021-01-06 22:54:10 -06:00
2dfd117ab5 Fix memory leak duplicating a scene with "Copy Settings" 2021-01-07 15:04:26 +11:00
a9dea9cfaa PyAPI: don't raise & clear exceptions when setting context members
BPY_context_dict_clear_members_array used PyDict_DelItemString
which raised & cleared the exception when the key didn't exist.

Even though setting/clearing the exception is supported,
it's worth avoiding where possible as it adds some overhead as well as
overwriting the previous error which can free PyObject's which are
unrelated to the code being executed.

Possible fix for T82552, crashing on Windows when setting the exception.
2021-01-07 14:41:52 +11:00
f35a38fba7 Fix BKE_blender_atexit_unregister error removing from linked list
This is an old bug exposed by having multiple atexit calls since
c65c4149c9.
2021-01-07 13:31:57 +11:00
27426c05b1 PyAPI Docs: Link to user docs instead of describing in API doc 2021-01-06 19:52:13 -05:00
b138c8f5b3 PyAPI Docs: Update Indirect Data Access docs
Fixes T84432
2021-01-06 19:34:21 -05:00
a9c607e60e PyAPI Docs: Fix wrong modifier path usage
Fixes T84430
2021-01-06 18:54:56 -05:00
133bdac306 PyAPI Docs: Clarify quick start guide tips
Some of the text here was outdated with 2.8x.
See T84427
2021-01-06 18:45:34 -05:00
211e161d76 Fix T84416: Vertex color baking checks for UVMap
Since the introduction in rB2221389d6e8e, baking to vertex colors would
still check for the existence of a valid UVMap (as if baking to image
textures).

Now check for vertex colors instead if target is
R_BAKE_TARGET_VERTEX_COLORS.

Maniphest Tasks: T84416

Differential Revision: https://developer.blender.org/D10006
2021-01-06 22:26:20 +01:00
6ea01dc509 UI: Use the 3D cursor icon for the RNA struct
Since there is a specific icon to represent the 3D cursor it makes sense
to add it to the RNA struct. This struct's icon is only displayed in the
Data API section of the outliner.
2021-01-06 14:00:44 -06:00
3028de9527 UndoType: Refactor: replace use_context boolean by a bitflag.
We will soon need more options here, sinmpler and cleaner to use a
bitflag then.
2021-01-06 18:07:09 +01:00
5cdf279ef4 Fix T84420: Linking regular materials to gpencil
When using "Make Links"->"Materials" regular materials could be linked
onto grease pencil objects. This caused a number of issues.

The fix changes the `allow_make_links_data` function to make sure that
if one object is of type `OB_GPENCIL`, the other has to be aswell.

Reviewed By: antoniov

Maniphest Tasks: T84420

Differential Revision: https://developer.blender.org/D10014
2021-01-06 17:54:44 +01:00
6672cbeb23 Fix T84202: Sculpt lasso mask crash after remesh.
'Caused'/revealed by rBd29a720c45e5: Operators that fully re-create the
mesh would previously rely on `sculpt_update_object` called from update
code to get required sculpt-specific data layers re-added to the new
mesh.

Now instead put all code adding data to orig mesh for sculpt purpose
into a new util function (`BKE_sculpt_ensure_orig_mesh_data`), and call
that function when entering sculpt mode, and from voxel remesher code.

This is contonuing effort to more clearly separate orig data from evaluated
data handling/usage in sculpt code.

TODO: there are likely other code paths that would need to call that
new function?

Reviewers: @sergey, @pablodp606

Subscribers:
2021-01-06 16:25:39 +01:00
a584aef470 Undo: Further tweak/fixes the 'use context' flag of undo types.
Note that this is fairly fragile still, especially in cases like paint
cureve undo, which actually does not use context in most cases (and can
be called with a NULL context), but do need it in one case. This will
need a proper rework at some point.
2021-01-06 15:59:23 +01:00
691c021679 Fix T82952: Crash changing mesh data block and switching scenes
Regression in 33ac3582bb.
2021-01-07 01:35:05 +11:00
f0071dfa10 Fix T79779: Pick shortest UV face-path ignores sticky setting 2021-01-07 00:37:05 +11:00
0e4f8ed90e UndoType: Fix some incinsistencies re context usage flag.
`use_context_for_encode` was not properly set regarding actual `encode` code for a few types.
2021-01-06 14:11:25 +01:00
eb1ff4b3a4 Cleanup: CodeStyle format 2021-01-06 13:55:27 +01:00
1c72a2f47d Cleanup: CodeStyle Format 2021-01-06 13:54:12 +01:00
967cf303f3 Fix T83372: Point.select can be True when unselected 2021-01-06 23:27:03 +11:00
bc3e38ca3a Cleanup/refactor: UndoType: Clarify use_context variable.
Rename it to mark it is only for `encode` callbacks, fix `encode`
callback of text undo to early fail in case it gets a NULL context, add
an assert to `BKE_undosys_step_push_with_type` that context is not NULL
when undotype requires a valid one.

Note that in practice this should not change anything, currently it
seems that we always get a valid context in
`BKE_undosys_step_push_with_type`?
2021-01-06 12:28:06 +01:00
4e23f08807 Fix object moved to cursor when editing last operation after dropping object
Steps to reproduce were:
* Drag object icon from the Outliner into the 3D view (or an object asset from
  the Asset Browser)
* Open the "Adjust Last Operation" panel
* Edit options in there - the object would move to the mouse location

The same issue happens with collection instance and object data adding (e.g.
via drag & drop). This patch addresses them too.

The operator used the event state stored in the window. This shouldn't be
accessed from the operator execute callback generally which happened here.
Especially not if the operator supports editing properties.
2021-01-06 11:55:21 +01:00
290b6d7ef3 Fix T70316: Custom "Delete Keyframes" shortcut still requires
confirmation

Deleting keyframes in the dopesheet or graph editor always required
confirmation, even if used ouside of the "Delete" menus.

Now add a "confirm" option [same as for deleting objects], which can be
disabled for immediate keyframe deletion.

This will also change the default behavior and bring this in line with
how object deletion works so there is one shortcut for bringing up the
menu/confirmation and another shortcut to delete immediately without
requiring confirmation / another click:

- Blender Default keymap: "X" for menu, "Del" for immediate
- Industry Compatible: "Backspace" for menu, "Del" for immediate

Maniphest Tasks: T70316

Differential Revision: https://developer.blender.org/D9651
2021-01-06 11:35:06 +01:00
4b56c18290 Fix T84426: Limit dissolve ignores selection with custom normals
Regression in 9969c2dd16.

Add note that custom normal calculation functions write into to tags.
2021-01-06 19:04:53 +11:00
947dc92083 BMesh: assert when a mesh has two kinds of shake-key data
Assert with comment to avoid confusion caused by
mixing two kinds of shape-key data.

This problem was exposed when investigating T84364.
2021-01-06 18:11:46 +11:00
Yevgeny Makarov
5424b4821d Fix T83094: Alternate rows in the Sequencer are green (macOS)
The issue is that `UI_GetThemeColorBlendShade4fv()` creates a color
with alpha, but there is not any background underneath to blend in with.

The solution is just to draw an opaque background first, which also
halves the number of rects to draw. Note that the brighter rows get
very slightly darker after this change.

Differential Revision: https://developer.blender.org/D9947
2021-01-05 14:21:54 -06:00
2ed6055209 Fix T79146: Sculpt Mode lags until the entire mesh is visible
This was caused when the BKE_pbvh_draw_cb function was used with
update_only_visible set to false. In that case, all nodes with the flag
were updating, but the update flag was only cleared for visible nodes.
This was causing constant updates per redraw in no visible nodes until
they enter the view frustum and their flag was cleared.

In order to fix this and prevent it from happening again:
 - Updating the buffers, flushing the updates and clearing the flags are
now part of the same function. It does not make sense to do these in
separate places.

 - The BKE_pbvh_draw_cb function was refactored so the
pbvh_update_draw_buffers is only called once. It should now be easier to
understand what the function does when it is used to update only visible
nodes or all nodes.

Reviewed By: mont29

Maniphest Tasks: T79146

Differential Revision: https://developer.blender.org/D9935
2021-01-05 20:23:41 +01:00
c20e482714 Fix T78681: "Add Primitive" icons are cropped in tool header
The issue can be simply resolved by moving the primitives and plus
icons slightly. They still bump up against the top and bottom of the
header but it looks much better now.
2021-01-05 13:00:35 -06:00
4ade409a87 Cleanup: Reduce variable scope 2021-01-05 12:22:23 -06:00
3373d14b1b Fix T83925: Crash when rendering on the CPU with OptiX denoiser enabled
Rendering on the CPU uses the Embree BVH layout, whether the OptiX denoiser is enabled or not.
This means the "build_bvh" function gets a "BVHEmbree" object to fill and not a "BVHMulti" as it
was assuming before, which caused crashes due to memory geting overwritten incorrectly. This
fixes that by redirecting Embree BVH builds to the Embree device.

Manifest Tasks: T83925
2021-01-05 18:37:31 +01:00
491a9e9ec4 Cleanup: Undo code: poll function.
Remove obviously outdated comment, and explictely set `poll` to `NULL`
in the one case it is not actually defined (sculpt undo).
2021-01-05 18:21:09 +01:00
90a26f900c Cleanup: UndoType: use size_t for memory size of structs. 2021-01-05 18:21:09 +01:00
166c0db3f9 Fix T83915: Subdivision Surface modifier causes visual artifacts in Cycles rendered viewport - CPU and OptiX
Changing the geometry in the current scene caused the primitive offsets for all geometry to
change, but the values would not be updated in all bottom-level BVH structures. Rendering
artifacts and crashes where the result. This fixes that by ensuring all BVH structures are
updated when the primitive offsets change.
2021-01-05 17:59:38 +01:00
da9d471e1d Fix T84389: RGB Curves node shows "tone" option outside of compositor
Since the introduction in rB4de7c0c3105a, the option is only used in the
compositor, it has no effect elsewhere [texture nodes, shader nodes].

Now only show the option for the compositor.

Maniphest Tasks: T84389

Differential Revision: https://developer.blender.org/D10005
2021-01-05 17:04:56 +01:00
583006d0ef Cleanup: clang tidy 2021-01-05 17:04:02 +01:00
39f99fd05c Fix: tried to set error message on modifier that does not exist
Without this, the example file in T83730 crashes in a debug build
when deleting the hair edit bake in the particle settings.
2021-01-05 16:50:23 +01:00
9dbea1db66 Compositor: Alpha Mode
{D9211} introduced pre-multiplying the color for the keying node. This
pre-multiplication should also be done by other keying nodes and should be
the default operation for alpha node.

This patch will change the logic of keying nodes (Cryptomatte Node,
Channel Matte, Chroma Matte, Color Matte, Difference Matte, Distance
Matte, Luminance Matte) and breaks old files.

The Set alpha node has a mode parameter. This parameter changes
the logic to `Apply Mask` the alpha on the RGBA channels of the input color
or only replace the alpha channel (old behavior).

The replace mode is automatically set for older files. When adding
new files the the multiply mode is set.

Reviewed By: Sergey Sharybin

Differential Revision: https://developer.blender.org/D9630
2021-01-05 16:34:55 +01:00
357e519575 Fix T83282: division by zero when creating psys tasks 2021-01-05 16:17:37 +01:00
cffa39358f Cleanup: Compositor comment style 2021-01-05 15:50:58 +01:00
36ae6e66c1 Fix T84367: Fix crash when showing invalid/legacy constraints
Exposed by rBeaa44afe703e.

Definition for CONSTRAINT_TYPE_NULL is not totally clear (it is set for
constraints without data, see an old comment from Ton), but for these, a
TypeInfo cannot be fetched.

Avoid processing those constraints in UI code, just do nothing instead.

Maniphest Tasks: T84367

Differential Revision: https://developer.blender.org/D9987
2021-01-05 15:31:40 +01:00
Jeroen Bakker
1f41bdc6f3 Eevee Cryptomatte: Store hashes in render result meta data
Stores cryptomatte hashes as meta data to the render result. Compositors could
use this for lookup on names in stead of hashes.

Differential Revision: https://developer.blender.org/D9553
2021-01-05 15:03:05 +01:00
7cd6f667e3 Fix T84053: Mask overlay in image editor not working
The mask overlay wasn't part of the overlay engine. The reasoning nehind
this was that more editors used the mask overlay and most of them used
old drawing code. This patch adds the mask overlay drawing to the draw
overlay engine. This code path will only be used by the image editor
VSE, Compositor and Movie Clip editor will still use the previous
method.

During this patch some alternatives have been researched:
1. `ED_mask_draw_region`: this would lead to different code paths when
   drawing in the image editor, and some hacks to retrieve the correct
   framebuffer.
2. Add mask drawing to image engine: Would lead to incorrect color
   management when viewing the mask.
3. Add mask drawing to image engine and overlay engine: Would lead to
   duplicated code.
4. Add mask drawing to overlay engine and for combined overlay select
   the correct framebuffer.

Option 4 was chosen as the exception (switching framebuffers) can be
done without hacks. The code stays clean.
2021-01-05 13:53:33 +01:00
f41de6dc46 Fix T84404: Crash when using Skin Resize in mesh without Skin modifier
Caused by rB54ee4109143b

Before that commit `TD_SKIP` was marked for all vertices.

Now skip the whole operation as all vertices are skipped.
2021-01-05 09:46:07 -03:00
fab772860d Asset browser: workspace in the wrong category
Workspaces [FILTER_ID_WS] were in the `Environment` category
IDFilterBoolean, whereas they are in the `Miscellaneous` category in
`rna_def_fileselect_asset_params`.

Make this consistent ['Miscellaneous'] in both cases.

(note this was already done in rB2c317457cbf2 for the file browser case)

Spotted while looking into T83983.

Maniphest Tasks: T83983

Differential Revision: https://developer.blender.org/D9911
2021-01-05 13:30:51 +01:00
acfa7b102b Sculpt: use distance threshold for dyntopo symmetrize
This was only used for non-dyntopo symmetrize.
There is no reason to use a hard-coded value in this case.
2021-01-05 23:19:34 +11:00
1f6846fa4e Cleanup: remove UNUSED(..) from public function declarations
This doesn't serve any purpose and can become out of sync
with the function it's self without reporting warnings.
2021-01-05 23:09:50 +11:00
e4884d224c Cleanup: remove redundant RNA_types.h header from UI_interface.h 2021-01-05 23:04:51 +11:00
105d385e4b Fix T84364: Sculpt symmetrize fails with shape keys
Use the BMesh symmetrize operator instead of using the modifier code.

While we could support shape-keys with the existing code used by the
mirror modifier, we'd need to add code-paths for evaluated mesh & bmesh
conversion to handle shape-keys differently just for this one case,
since we want to avoid copying & processing shape-keys layers for
evaluated meshes in general.
2021-01-05 22:48:12 +11:00
7241104877 Enabled Physics Particle Instance test 2021-01-05 16:16:08 +05:30
c0a8dd943f Fix T84018: bulk selection (box, circle, lasso) - unwarranted selection
of islands in vertex mode if "UV Sync Selection" is on

Caused by rB72b422c1e101: UV: support select linked with sync-select in
vert/edge modes

If you had island selection mode enabled in the UV editor with UV Sync
Selection off, and switch UV Sync Selection on, then in vertex selection
mode all bulk selection ops (box, circle, lasso) will be selecting whole
islands.

Prior to culprit commit, for sync selection ON plus island selection ON,
BM_uv_vert_map_create would always return a NULL vmap (it was called
with `use_select` = True, no faces tagged selected). After said commit,
for sync selection ON plus island selection ON, BM_uv_vert_map_create
would return a valid vmap (it is now called with `use_select` = False,
no faces tagged selected - but if `use_select` is False, all UVs will be
added here).

If I am not mistaken, it is never wanted to actually select islands with
box/lasso/circle when sync selection is turned ON [after all you dont
have the UI for it showing], so solution is now to check for this
earlier and not even call uv_select_linked_multi in those cases. (Maybe
in the future this can be unified and we dont need separate selection
modes fo UV and 3D?)

Maniphest Tasks: T84018

Differential Revision: https://developer.blender.org/D9917
2021-01-05 10:26:23 +01:00
dc4014c676 Cleanup: Enum for mask overlay mode 2021-01-05 10:13:00 +01:00
7d152bedc5 Fix T84216: Drawing a paintcurve [vertexpaint / weightpaint] fails
Caused by rB35e3dc9192e7.

Above commit moved 'Weight Paint' & 'Vertex Paint' keymap also before
'Paint Curve' keymap.
This way, paintcurve.add_point_slide would be overriden by:
- paint.vertex_paint (inverted)
- paint.weight_sample

Now move 'Paint Curve' above again.

Reviewers: campbellbarton

Maniphest Tasks: T84216

Differential Revision: https://developer.blender.org/D9939
2021-01-05 10:02:03 +01:00
08f00f4f6e BMesh: Add shape-key support to edit-mesh symmetrize
Symmetrize now flips shape-keys too since using the un-flipped
locations creates an overlapping surface which isn't useful.
2021-01-05 18:03:56 +11:00
4150facd61 BMesh: add use_shapekey to BMesh transform operators
Currently unused, needed for symmetrize to support shape keys.
2021-01-05 15:51:50 +11:00
5370a7dd40 Cleanup: use scale's 'space' argument instead of two transform calls 2021-01-05 15:51:50 +11:00
d3c62b682d Fix bmesh.mirror operator
Checks for merging vertices assumed all the geometry was being mirrored.
2021-01-05 15:51:50 +11:00
a0db43cd7b Fix T84388: Invalid operator reference in the quick-start 2021-01-05 15:51:50 +11:00
6990b6ed3b Cleanup: typos (repeated words) 2021-01-05 15:51:50 +11:00
f359102589 VSE: Fix incorrect condition for skipping prefetch frames
This error was overlooked in commit be69f23b68.
2021-01-05 04:04:06 +01:00
9b17e71c23 Cleanup: Use flag type explicitly
Using the `uiButtonGroupFlag` type explicitly can avoid the need
to look up which enum should be used as an argument.
2021-01-04 17:35:14 -06:00
5a6dfb7571 Fix T78017: Broken layout in "View Lock" panel with armature
The property split layout was broken when the bone dialog appeared,
because the name field was not set. Theoretically property split should
work in this case, but it makes sense to use the label anyway.
2021-01-04 17:32:22 -06:00
9316cb33d8 Cleanup: Remove unused variables in transform mesh skin code
Differential Revision: https://developer.blender.org/D9992
2021-01-04 17:11:59 -06:00
102eff0bd4 Fix T84382: Geometry Nodes: Vertex group attributes are removed
In the report, the geometry is copied because it has two users and the
final join node needs to write to it. The join node also happens to
remove attributes apparently, because it exposed a mistake in the "copy"
method of the `MeshComponent` class. The copy is supposed to be
a deep copy, but the vertex group name map was not duplicated.

Differential Revision: https://developer.blender.org/D9991
2021-01-04 17:07:10 -06:00
ec90dda318 UI: Fix typo in operator description 2021-01-04 15:42:15 -06:00
Pi Lanningham
5a498e6a7b Fix T84183: Dark area in the bevel custom profile widget
If there was a control point at an extreme position when drawing a curve
profile (in the bottom corner), the fill's trianglulation could fail, giving
a misleading view of the curve. This is because the extra points added to
create a closed shape were exactly on the border of the view.

This commit adds a small margin to those points, so the triangulation
doesn't fail because the line overlaps itself.

Another possible solution is to use a different algorithm to fill
the polygon, such as scanfill, which is used by curve objects.
This seemed simpler, and seems to work fairly robustly.

Differential Revision: https://developer.blender.org/D9989
2021-01-04 15:13:08 -06:00
54ee410914 Fix T84376: Skin Resize(Ctrl + A) does not work in Symmetry
Since the `TransData` converted from vertices is the same used for other
transform modes (Move, Rotate, Resize), the logic used for mirroring
focused only on the position of the vertices.

The solution here is to create a specific `TansData` for `CD_MVERT_SKIN`.
2021-01-04 17:37:08 -03:00
8c80299fc4 Make mesh modifier tests not fail with optimized OSD lib
When building opensubdiv with more aggressive optimization flags
(-march=native -02) the output meshes would differ a bit from what we
expected in the current automated modifier test file.

The differences in vertex position is within the 1e-6 range, which I
would call is acceptable for floats. In addition to this, all the
modifier test that tests the subdiv modifier in particular pass without
any modifications. I've updated two tests in the modifier test file and
script to make it pass (listed below).

Updated following test categories:

1. Decimate test

Here there was a subdiv modifier applied before the actual decimate
modifier. Because the decimate modifier creates a queue of potential
vertices it can remove, it is highly sensitive to even small changes as
it drastically changes in which order the vertices are decimated in.

As this test should only be testing the decimate modifier, I pre-applied
the subdiv modifier in the test file.

2. RandomCubeModifier
For these tests I removed the subdiv modifier as well. As with decimate,
a small change in vertex position here can lead to quite different
results.

Reviewed By: Sergey, Bastien

Differential Revision: http://developer.blender.org/D9004
2021-01-04 19:30:20 +01:00
5aab7f66a0 Fix T83876: blender crashes when baking particles + smoke sim
This was introduced in rBe5c0d4613a8943c712b57fb336997ecd78e6508e.

The issue is that the new fluid system does not use the pointcache
system for caching anymore, but still relies on pointcache for
other things. For example, it uses DEG_add_collision_relations
which internally creates relations with pointcache. Not sure if
there are other issues.

Ideally, this dependence should be resolved in one way or another
at some point, but that is out of scope for this fix.

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

Reviewers: brecht
2021-01-04 15:58:51 +01:00
09c1cb8a17 Fix T84260: NURBS edit mode lines not showing
When in edit mode, the edit lines for de-selected surfaces did not
show up.

The bug was caused by the is_gpencil bool which reused another flag.
Both grease pencil and nurbs surfaces use the edit_curve_handle shader.
A dedicated flag was added to make sure the is_gpencil bool is
set correctly.

Reviewed By: fclem

Maniphest Tasks: T84260

Differential Revision: https://developer.blender.org/D9985
2021-01-04 15:34:02 +01:00
c6e5b3f42d Fix T84095: Eevee vextex color isn't working with hair
Regression introduced by {c766d9b9dc56}. When converting the vertex
buffer to a texture buffer the fetch mode wasn't checked and the short
was bitwise interpreted as a float. This change checks the fetch_mode
and select the correct texture buffer.

This could also be added to other places when needed. At this time it is
only added here to support vertex colors when used with hair particles.
2021-01-04 15:05:37 +01:00
c716b9862a Fix: Update normals when switching scene quality
Recent commits also updated normals for metaballs, curves and volumetric
objects. This change tags will tag to generate geometry for these new
types.
2021-01-04 13:04:37 +01:00
cb2517016b GPU: Enable HQ normal work around for AMD Polaris
THe high quality normals work around is enabled for Polaris cards using
the official drivers. Since driver version 2.11.2 they fail to render
using low quality normals.

The detection of polaris cards is done by matching the opengl renderer.
The renderer strings have been extracted from various reports linked to
{T82856} but isn't complete as some reports are missing the exact
renderer as users don't always report via the help menu.
2021-01-04 12:19:51 +01:00
a3fcbb54f4 GPU: Add HQ normals workaround.
This change makes it possible for platforms to only support high quality
normal rendering. This is part of {T82856} where current AMD drivers
running on the polaris architecture does not support the low quality
setting due to a driver bug.

In a next commit the work around will be enabled.
2021-01-04 12:19:51 +01:00
02d1f1482a Fix mistake in rBef90a8e12caf in data transfer code.
Old mistake from 2.80 era when we got rid of DerivedMesh...

Not critical, but could be backported to 2.90LTS too.
2021-01-04 11:30:04 +01:00
5e38384034 Fix T84362: Crash when use Vertex Paint in subdivide strokes
Maniphest Tasks: T84362

Differential Revision: https://developer.blender.org/D9983
2021-01-04 11:29:47 +01:00
c7085be6c6 Fix T84345: Transforming the cursor fails with absolute grid-snap
Absolute grid snapping was using the pivot, which doesn't make sense
when transforming the cursor.
2021-01-04 21:15:00 +11:00
d11a87b88c DrawManager: High quality normals for non meshes
This adds high quality normals for non meshes. These include

* Volumetric Object Wireframe
* Metaballs
* Extracted Curves
* Curves in edit mode

This is in preparation to fix a regression in recent AMD
drivers where the `GL_INT_2_10_10_10_REV` data type isn't
working in Polaris cards.
2021-01-04 11:09:56 +01:00
17be2149a8 Fix T84106: attribute mix node worked incorrectly on float attributes 2021-01-04 10:43:56 +01:00
b8e536f381 Fix imbuf.new & resize allowing zero & negative dimensions 2021-01-04 20:05:32 +11:00
a6285339ba Cleanup: remove unused optional argument to imbuf.new
While this didn't cause any problems, it was incorrect.
2021-01-04 20:00:27 +11:00
Philipp Oeser
80e720ee4a Fix T84191: remove python API limits for Image.scale() dimensions
Since the introduction in 2c23bb8389,
these were set to 10000 each.

This seems like an arbitrary limit (BKE_image_scale / IMB_scaleImBuf
don't have limits and I couldn't spot similar size restrictions in
image relating functions), now match what we do for creating images
(rna_Main_images_new), use INT_MAX.

Ref D9950
2021-01-04 19:05:46 +11:00
14ee48d898 Fix crash reading files with unknown modifier ID's
Missing NULL check for the modifier type.
2021-01-04 17:40:05 +11:00
f43e8cceb3 Fix early exit check in BKE_appdir_app_template_has_userpref
Logical error in 84f21c170d
This check was a no-op, replace this with a check for an empty string.
2021-01-04 17:40:05 +11:00
f17184bfeb Fix clang_array_check checking utility
Use python3 which is now supported,
only use CLANG_BIND_DIR & CLANG_LIB_DIR when they are set.

Also add immediate mode GPU API function calls.
2021-01-04 17:40:05 +11:00
3254a63218 Cleanup: correct array size in argument 2021-01-04 17:40:05 +11:00
dcdc0f177a Cleanup: use const variables 2021-01-04 17:40:05 +11:00
cd29d76ab6 Cleanup: typo in c484b54453 2021-01-04 17:38:11 +11:00
2008c24123 Cleanup: add NULL check for filename argument which could be NULL
While it's never NULL at the moment, checks elsewhere in this function
support passing in a NULL filename, so keep this working as intended
in case RNAProcessItem.filename is NULL in the future.
2021-01-04 17:38:11 +11:00
82bbe257ee Cleanup: redundant call to WM_modalkeymap_find 2021-01-04 17:38:11 +11:00
a5081896bc Cleanup: redundant code, minor inconsistencies
- Remove ternary operators when both values are the same.
- Remove break after return.
- Remove redundant NULL checks for code which handles
  those cases immediately beforehand.
2021-01-04 17:38:11 +11:00
b5c2a75d26 Cleanup: use ARRAY_SIZE when when looping over the array indicies 2021-01-04 17:38:11 +11:00
22895d0f32 Cleanup: remove self-assignment
Use CLAMP_MAX to remove redundant comparison.
2021-01-04 17:38:11 +11:00
b34eded930 Cleanup: remove redundant code
Fix for T62504 missed removing return call.
2021-01-04 17:38:11 +11:00
9ff4012711 Cleanup: sort cmake file lists 2021-01-04 17:38:11 +11:00
fea1026bb8 Cleanup: use 'pragma once'
Add explanations for cases the header-guard defines are still used.
2021-01-04 17:38:11 +11:00
dfbda59a66 Cleanup: redundant struct declarations 2021-01-04 17:38:11 +11:00
f03c25bda8 Cleanup: sort structs 2021-01-04 17:38:11 +11:00
54f89e8704 Cleanup: docy comments beginning with '/**' don't end with '**/' 2021-01-04 17:38:11 +11:00
9b10b3930b Cleanup: clang-format 2021-01-04 17:38:11 +11:00
c61c7d9926 Cleanup: spelling (use 'gimbal' instead of 'gimble') 2021-01-04 17:38:07 +11:00
613c568df2 Cleanup: use doxy sections for render_preview.c 2021-01-04 17:37:44 +11:00
12409b2069 Cleanup: rename get_brush_icon, make it a static function
Group with other icon preview API functions.
2021-01-04 17:37:44 +11:00
01f38c10cb Cleanup: use const casts in DerivedMesh.cc 2021-01-04 17:37:44 +11:00
1e8f266591 API Docs: CSS: Fix long enum list
This commit makes some adjustments to a previous fix which broke with 
new versions of sphinx/theme.

Fixes T76453
2021-01-02 20:04:25 -05:00
c7e92e379d Update RNA to manual url mappings 2021-01-02 17:51:56 -05:00
Aaron Carlisle
e1b8af9ba7 Fix Unreported: Run time error in UI code
Steps to reproduce:

1. Add clip to clip editor
2. Open the tracking settings & tracking settings extra panels

To fix this the sub panel is only drawn if a track is active.
The main panel will exit early and display a "No active track" message.
This is consistent with other panels in the clip editor.

Reviewed By: HooglyBoogly

Differential Revision: https://developer.blender.org/D9727
2021-01-02 16:11:14 -05:00
0330b0552b Cleanup: Explicitly pass icon size to generation function, not just bool
* This way you don't have to look up the function declaration to know what the
  boolean value means.
* You can call the function in a loop over the available sizes and pass the
  index as size.
* Makes it easier to add a new size in future if needed.
2021-01-02 15:36:51 +01:00
057a8afb87 Fix T84024: Empty image opacity labeled transparency
This value really is the opacity, or the alpha, since a value of 1.0 means
that the image is fully visible, not invisible like "full transparency"
would suggest. Mistake in rBea4d28aea0343a.

Differential Revision: https://developer.blender.org/D9920
2021-01-01 12:07:42 -06:00
0da1fc2fc4 Fix T84029: Point Distribution node crash on mesh with no faces
This bug exposes some ugliness in the implementation in poisson disk
distribution implementation with likely incorrect resizing of vectors and
some other assumptions. However, a simple quick fix is to return early
when the input mesh has no faces. This makes sense anyway because
there is no surface to scatter on.
2020-12-31 17:01:29 -06:00
cda8979005 Fix mistake in recent rB8c135fa9a834 commit. 2020-12-31 15:12:06 +01:00
8c135fa9a8 LibOverride/RNA: refactor rna_property_override_property_real_id_owner.
Makes it more in line with more generic `RNA_find_real_ID_and_path`, and
avoids generating the rna path string if we do not need it.
2020-12-31 14:25:29 +01:00
85951f8fde Cleanup: Move functions from sequencer_edit.c
These are utility functions that are not used in this file.

No functional changes.
2020-12-31 05:22:19 +01:00
e5e57fe0a2 Cleanup: Remove unused functions from sequencer_edit.c
No functional changes.
2020-12-31 05:02:10 +01:00
8373f497bd Add regression tests for curve conversion to mesh
This adds a basic set of tests for curve sampling and bevel generation.
At the moment there are basic test cases for bevels, caps, and the
filling of 2D curves, but more tests can be added in the future.

Curves are actually converted to "DispLists" for displaying them in the
viewport, so it's much simpler to rely on the mesh conversion operator
instead of building a new test framework for another data structure.

Differential Revision: https://developer.blender.org/D9958
2020-12-30 13:12:29 -06:00
Yevgeny Makarov
2d86175bac Fix unreported: Sequencer grid lines are not drawn
By design, there should be lines between the alternating horizontal
stripes in the Sequencer. But currently they are all drawn in one place,
on top of each other. Mistake in rBfae895125efe.

Differential Revision: https://developer.blender.org/D9962
2020-12-30 12:56:24 -06:00
2be2165dd6 Cleanup: Use LISTBASE_FOREACH macro
Differential Revision: https://developer.blender.org/D9960
2020-12-30 17:03:06 +01:00
f910342c8d Outliner: Fix useless assert in new liboverride showing code.
It is perfectly 'valid' to find invalid RNA properties references in
override properties list. Data change, RNA changes, IDProperties change,
some linked ID may become unavailable, etc.

Note that those invaldi override properties are cleaned up when updating
the override info (so typically on undo step storage, and .blend file save).
2020-12-30 12:38:53 +01:00
761ef45a24 Cleanup: Fix typo in tests error message 2020-12-29 20:46:29 -06:00
c1740e9ad0 Fix T83991: Pasting sound strip not working correctly
New UUID was generated for original strip not new one.

Bug caused "invisible" sound strip playing that is impossible to
remove. Especially noticable when transforming pasted strips. In such
case, file reload was necessary.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D9912
2020-12-29 19:57:56 +01:00
48e0e0e2ac Fix T83439: Sculpt: Radial symmetry combined with mirroring results in texture offsets
Looks like this has been wrong since the introduction in rB5505697ac508
10 years ago.

To get the proper texture lookup in the mirrored area, first rotate, then
translate/flip [instead of the other way around].

Maniphest Tasks: T83439

Differential Revision: https://developer.blender.org/D9897
2020-12-29 18:38:16 +01:00
ae82410329 Fix T83749: Better handling of alpha in generic Nodes material wrapper for IO add-ons.
Try to detect if a given image may have valid alpha data or not (based
on number of channels and depth). This may be a bit doggy in theory, but
in practice it should cover most fields as expected. We can always
adjust the euristic here in other wrong cases appear.

This will affect all import add-ons using that node shader wrapper (at
least OBJ and FBX ones).
2020-12-29 16:38:40 +01:00
e22a36e80a Cleanup: Use proper RNA_pointer_is_null helper.
Followup to rB7f3601e70dd and rBad63d2f60e2.
2020-12-29 12:11:18 +01:00
5428ad40e8 Test: Add utility to do near comparison for float[2] 2020-12-29 10:38:38 +01:00
81c57c9471 Fix T84144 cursor wrap broken for Windows.
Modifies WM_BUTTON processing to reuse existing mousemove logic. Fixes
case where cursor wrap was not being handled on mouse release.

Bonus: flattened mouse move logic so all paths lead to a single return.
Removed case where wrap is not handled until subsequent mousemove as
button press may rely on updated mouse move position.
2020-12-28 13:34:58 -08:00
1db27af38f Fix T84200: Rotating a paintcurve [all paintmodes] doesn’t work correctly
The transform code did not provide a 2d context to be used in 3d space.

The solution is to set all matrices for the screen space in these cases.

This commit also removes the dial3d drawing in these cases.
It was not correct anyway.
2020-12-28 16:19:37 -03:00
Erik Abrahamsson
6fbeb6e2e0 Add operator to copy a modifier to all selected objects
These two operators (one for grease pencil, one for other objects)
copy a single modifier from the active object to all selected objects.
The operators are exposed in the dropdown menus in modifier headers.

Note that It's currently possible to drag and drop modifiers between
objects in the outliner, but that only works for dragging to one object
at a time. Modifiers can also be copied with the "Make Links" operator,
but that copies *all* modifiers rather than just one. The placement
and scope of these new operators allow for more useful poll messages
and error messages as well.

Every object type that supports modifiers is supported. Although hook
and collision modifiers aren't supported because of an unexplained
comment in `BKE_object_copy_modifier`, other than that, every modifier
type is supported, including particle systems, nodes modifiers, etc.

The new modifiers are set active, which required two small tweaks to
`object.c` and `particle.c`.

Reviewed By: Hans Goudey (with additional edits)

Differential Revision: https://developer.blender.org/D9537
2020-12-28 11:18:52 -06:00
7f3601e70d Cleanup/refactor rna_idp_path code.
Factorize common processes and checks, early `continue` in invalid
cases, etc.
2020-12-28 17:40:27 +01:00
ad63d2f60e Fix T84091: IDProperties/RNA: Crash due to colliding name between custom data and static RNA property.
We have to check that the RNAProperty found in `rna_idp_path` from the
currently checked IDProperty name is actually a real runtime RNA-defined
one, and not a static C-defined RNAProperty...
2020-12-28 17:40:27 +01:00
b1d8aeeab2 Snap: Decrease the distance of the incremental snap in ortho view
This matches more the older versions (as shown in the T77819).
2020-12-28 11:44:43 -03:00
26c34a2a3a Tweak comment regarding Sculpt mode undo issues in object update code.
Original comment from rB8a9dedf82954. See also T84084.
2020-12-28 14:16:14 +01:00
823f0da702 Cleanup: UI messages fixes. 2020-12-28 10:22:02 +01:00
e6bb2cdec7 Cleanup: Typo: overriden -> overridden. 2020-12-28 10:22:02 +01:00
e0b6c8f777 Fix possible fall-through in outliner region listener
Reported as a strict compiler warning, and the need of fall-through is
not needed from just reading the code.

If it is something what must happen, the reasoning is to be explained
in the comment, and ATTR_FALLTHROUGH is to be used.
2020-12-28 09:57:59 +01:00
e590d2d167 Cleanup: Declare variables where initialized 2020-12-27 21:46:57 -06:00
57fe65b17e Cleanup: Reduce indentation
Since the if statement is just a NULL check, returning early is simpler
and makes reading the rest of the funtion easier.
2020-12-27 21:26:53 -06:00
aa64fd69e7 UI: List library overrides in the Outliner
Having a centeral place to find a list of all library overrides should be
useful for managing production scenes where library overrides are used a lot.
This change adds the individually overridden properties of a data-block under
the data-block itself. Just how we show modifiers, constraints or pose channels
there. This way we can also expose library override operations/options better
in future.

There's also a filter option for the library overrides now, so they can be
hidden. It is only available in the View Layer display mode though, like the
other filter options.

One internal change this has to do is adding more informative return values to
undo pushes and the library override functions called by it. That way we can
send a notifier when library overrides change for the Outliner to know when to
rebuild the tree.

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

Reviewed by: Andy Goralczyk, Bastien Montagne, William Reynish
2020-12-27 22:45:41 +01:00
960a0b892c Fix T84101: Duplicate operator not available for some data-block selectors
In some operators that previously allowed duplicating the selected data-block,
the operator would not be available now. 2250b5cefe split the "new" operators
into "new" and "delete" to allow clearly differentiating between the two. But I
apparently didn't amend all affected data-block selectors to use the added
"duplicate" operators.
I went over all operators that were split now and made sure all affected
data-block selectors are updated.
2020-12-27 15:55:58 +01:00
e56fe47748 Fix crash when saving render from temporarily maximized render window
Steps to reproduce were:
* Start with factory defaults
* Set "Render in" to "Maximized Area"
* Render
* Open "Save as"
* Click Cancel

Mistake in  78d2ce19c4. Was using the wrong area pointer, which I think
didn't make a difference in most cases, but here it did.
2020-12-27 15:11:26 +01:00
7916c59304 UI: Grammar: "Clean Up" vs "Cleanup" in operator name
"Cleanup" is a noun while "Clean Up" is the verb.
2020-12-26 16:50:44 -06:00
8491e4ab86 Fix unreported: Cycles CLI device override doesn't set peer memory usage flag
Reviewed By: brecht

Differential Revision: https://developer.blender.org/D9929
2020-12-25 23:13:03 +01:00
Nicholas Rishel
565ea3df60 Simplification of Wintab event handling.
Previously Wintab packets were added to a local queue to be processed
during Win32 mouse events, in order to correlate Wintab to Win32
mouse buttons. Wintab packets before Win32 mouse down events were
expired on a timer.

This commit drives mouse events during Wintab events when a device is
in range. When a Wintab button is found it is dispatched if an
equivalent event can be popped from the Win32 event queue. If a Win32
mouse button event is not associated with a Wintab event, it falls
through to WM_BUTTON handling. All Wintab packets are handled as they
are received.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D9908
2020-12-24 16:41:19 -08:00
Yevgeny Makarov
af316d2761 UI: Cleanup spelling of compound words
Approximately 138 changes in the spelling of compound words
and proper names like "Light Probe", "Shrink/Fatten", "Face Map".
In many cases, hyphens were used where they aren't correct, like
"re-fit". Other common changes include:
 - "Datablock" -> "data-block"
 - "Floating point" -> "floating-point"
 - "Ngons" -> "n-gons"

These changes help give the language used in the interface
a consistent, more professional feel.

Differential Revision: https://developer.blender.org/D9923
2020-12-24 13:11:22 -06:00
Yevgeny Makarov
2917f550ca Cleanup: Fix capitalization in various UI strings
Approximately 195 changes of capitalization to conform to MLA title style.
UI labels and property names should use MLA title case, while descriptions
should be capitalized like regular prose, generally with only the start of
a sentence capitalized.

Differential Revision: https://developer.blender.org/D9922
2020-12-24 11:07:32 -06:00
fe440a92e9 Cleanup: compiler warning 2020-12-24 14:19:21 +01:00
29cd99e7fd Cycles: remove surface area computation for meshes with OSL
This is relatively expensive and as per the OSL spec, this value is not
expected to be meaningful for non-light shaders. This makes viewport updates
a little faster.

As a side effect also fixes T82723, viewport refresh issue with volume density.
2020-12-24 13:53:33 +01:00
c4f8aedbc2 Fix T84016: Cycles baking crash with OptiX after recent changes
This worked for CPU + GPU, but not GPU only.
2020-12-24 12:59:35 +01:00
2221389d6e Bake: vertex color baking support for Cycles
In the Bake > Output panel, there is now a choice between Image Textures and
Vertex Colors. The active vertex color layer is used for baking. This works
with both existing per-corner and sculpt per-vertex vertex colors.
2020-12-24 12:40:48 +01:00
0b4fae7a51 Cleanup: refactoring of bake code in preparation of vertex color baking
Split of internal/external image bake target code off into smaller functions and
refactor associated data structures for clarity. Designed so that a vertex color
bake target is easy to fit in.

Also avoid passing in a huge number of arguments into the main baking function,
pass a struct instead.
2020-12-24 12:00:58 +01:00
58c697a9ec Audaspace: port accuracy improvement from upstream. 2020-12-24 10:42:16 +01:00
83ad35cb9c Fix T83997: Duplicated audio does not sound the same
The issue was that sounds were always faded from 0 volume when they
started and depending on the currently used buffer size, the fading took
longer or shorter.

The solution stores whether the sound has ever been played back and
consequently does not fade when starting to play back.
2020-12-24 10:42:16 +01:00
c9efb54240 Cleanup: Clang format 2020-12-23 12:13:44 -06:00
d8dc4c5b32 Geometry Nodes: new Rotate Points node
This node updates the "rotation" attribute on points.
Multiple ways to specify the rotation are supported.

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

Ref T83668.
2020-12-23 16:37:47 +01:00
8a9dedf829 Workaround T84084: Assert/crash when undoing from Sculpt mode to Object one.
Disclaimer: This workaround avoids crashing with current state of the
code and is only committed as temporary band-aid until we can assess the
full issue and decide if/how it needs to be adressed.
2020-12-23 16:03:42 +01:00
d29a720c45 Fix T84002: Sculpt: Masking operations crash if multires is in play.
This fixes the main issue there (essentially a followup to
rB90e12e823ff0: Fix T81854: crash when undoing switch between sculpt and
edit mode).

We basically remove more (hopefully all the remaining!) modifications of
orig mesh from `sculpt_update_object`, as those done here will not be
immediately available in the evaluated data (that specific bug happened
because masking data was added to orig mesh there, but not flushed to
depsgraph evaluated one).

This also goes towards a better separation between handling of evaluated
data and orig one.

Note that modification of orig mesh data can still happen, e.g. values
in some cdlayers, but at least all pointers should now be valid in the
evaluated mesh.

There are still some issues, e.g. we now get an assert/crash in
`multires_reshape_assign_final_coords_from_ccg` when undoing out of the
Sculpt mode, presumably because subdiv_ccg data remains unchanged then
(and hence still has the `has_mask` flag set), while actual mesh data do
not have that cdlayer anymore...

This commit also cleans up/simplifies some code,
`ED_object_sculptmode_enter_ex` was (indirectly) calling
`BKE_sculpt_face_sets_ensure_from_base_mesh_visibility` twice e.g.
2020-12-23 16:03:42 +01:00
9d04fa39d1 Fix T84063: crash reading pointer properties in Attribute shader node
Path resolving can find e.g. a datablock rather than a float or integer,
treat that as a failure to find a valid property.
2020-12-23 15:50:31 +01:00
635694c0ff Fluid: Added new viscosity solver
Mainly updated the Mantaflow version. It includes the new viscosity solver plugin based on the method from 'Accurate Viscous Free Surfaces for Buckling, Coiling, and Rotating Liquids' (Batty & Bridson).

In the UI, this update adds a new 'Viscosity' section to the fluid modifier UI (liquid domains only). For now, there is a single 'strength' value to control the viscosity of liquids.
2020-12-23 15:48:38 +01:00
5cfda8e7f7 Fix crash closing File Browser window after closing temporary render window
This seems to be a longer standing issue. Steps to reproduce were:
* With factory settings, Ctrl+O then F12
* Close the render window using the window close button
* Close the File Browser window using the window close button

This could be OS specific though, at least on macOS this caused a crash.
2020-12-23 15:31:31 +01:00
21cb288029 Fix incorrect debugging text in extra operator icons for buttons 2020-12-23 14:43:40 +01:00
27fcaa6173 Cleanup: Move functions to new ED (editor) operators file & general cleanup
With the new `ed_util_ops.c` introduced in 2250b5cefe, existing code can be
cleaned up to use it.

* Move new ID preview operators to `ed_util_ops.c`
* Move ED operator registration to `ed_util_ops.c`
* Use doxygen sections in `ed_util_ops.c`
* Rename ID related ED operators to use `ED_OT_lib_id_` prefix.
* Remove unused `#include`s
2020-12-23 14:34:24 +01:00
78d2ce19c4 Fix T84013: Crash closing maximized File Browser opened from Preferences
After 1e799dd26e, the logic to recognize a temporary File Browser window
didn't work correctly anymore. It would recognize a maximized File Browser
inside a temporary window as a temporary File Browser window, and attempt to
close this (rather than returning to the previous layout).
The logic there was pretty weak, and still is I think. A more stable solution
would need bigger refactoring.

With this, it's also not possible to maximize or fullscreen an area within a
temporary window (Preferences, File Browser, render window) anymore. Think that
won't make a noticable difference, since you couldn't open multiple areas there
anyway, and the area seems to be maximized already.

Cleaned up the code a bit to not become more confusing with the changes.
2020-12-23 14:34:24 +01:00
9460051c1a Sculpt Undo: Fix broken memory size and potential use of uninitialized variables.
That code looked really like a joke tbh... Random reported memory usage
is not really that important, but the uninitialized items counts was
potentially fairly severe.
2020-12-23 11:17:58 +01:00
b4b888fd2a Cleanup: Reduce Variable scope clip_buttons 2020-12-22 20:13:05 -05:00
8d3d4c8840 Cleanup: Use true and false for booleans 2020-12-22 14:58:57 -06:00
4b46afae09 WM: minor optimization for when there is a large number of notifiers
Don't add the same stats refresh notifiers multiple times, it can be slow to
search the full list of notifiers for duplicates when there are many.

Fundamentally the time complexity in searching for duplicates is still bad.

Inspired by D9901 from Erik Abrahamsson
2020-12-22 19:26:06 +01:00
ac82904c49 UI: keep image open button always visible in image editor datablock selector
Does not need to be hidden in the menu.
2020-12-22 18:18:22 +01:00
00ff3dfb23 Cleanup: Reduce variable scope in object.c 2020-12-22 10:35:18 -06:00
b2edc716c1 Fix Cycles OptiX runtime compilation broken after shader raytracing
Need to pass the appropriate flags as we do for compilation as part of the
CMake build.
2020-12-22 15:08:59 +01:00
dad5aded0c Fix T84006: Cycles AOV not written with some mix shader node set ups 2020-12-22 14:25:50 +01:00
2601501fce RNA: make bpy.data.orphans_purge() return number of deleted datablocks
Sometimes multiple calls to `bpy.data.orphans_purge()` are needed to
delete all orphans, because a call can turn previously-used datablocks
into orphans. Returning the number of deleted datablocks makes it
possible to keep looping until nothing can be deleted any more.

This patch keeps track of deletions in `id_delete()` so that it can be
returned up the call stack.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D9918
2020-12-22 14:05:49 +01:00
512a23c3d6 VSE: handle IO errors when reading disk cache header and version
Respond to return values of `fscanf()` and `fread()` to detect and
handle I/O errors. Not only is error handling a good idea, this also
prevents warnings from GCC that `fread()` and `fscanf()` return values
are ignored.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D9915
2020-12-22 11:43:33 +01:00
0e85d701c6 Animation: Bake Action, improved discontinuity filter for bones
Perform the same filtering as e5528904f1
introduced for object rotations, for bone rotations.
2020-12-22 10:04:21 +01:00
9f34f2b20d VSE: Fix animation versioning for bezier F-curves
`seq_convert_transform_animation()` converted only keyframed value, but
when bezier interpolation is used, posotion of handles was unchanged.
This caused significant difference in animation.

I have checked only linear interpolation when testing versioning originally.
2020-12-22 05:50:34 +01:00
ffacce5be4 UI: Properties editor popover and outliner sync
This adds a popover to the properties editor. Currently the only setting
is for controlling outliner to properties syncing.

Because we cannot define a perfect heuristic to determine when
properties editors should change tabs based on outliner icon selection,
we need an option to enable or disable this behavior per properties
editor.

There are 3 options for controlling the syncing. Auto uses the heuristic
to only allow tab switching when a properties editor and outliner share
a border. On and off enable and disable syncing respectively.

Differential Revision: https://developer.blender.org/D9758
2020-12-21 14:31:32 -07:00
Wayde Moss
2d6e6d035b Nla Refactor: Better blend function parm naming
**Renames parms**:
| **old name** | **new name**
| old_value | lower_value
| target_value | blended_value
| value | strip_value
| inf | influence

**Reason**: {D8296} allows full nla stack evaluation with proper
keyframing support. These names should make it more intuitive how all
the data gets processed and inverted. Note, that I do use the term
"strip_value" instead of something like "fcurve_value" of the tweak
strip. Technically, "strip_value" is closer to what is solved for.
For example, if a noise fmodifier was active for the fcurve, then the
remapping would appear to be wrong. In the future, further solving can
be done afterward, outside of the nla system, to remove the effects of
fmodifiers.

**Renames functions**:
| nla_invert_blend_value | nla_blend_get_inverted_strip_value
| nla_invert_combine_value | nla_combine_get_inverted_strip_value

**Reason**: D8296 adds get_inverted_lower_value() variants,
so "invert" alone is too vague.

**Renames NlaKeyframingContext member**:
| nla_channels | lower_eval_data

**Reason**: D8296 evaluates the upper stack. This name makes it more
obvious what data is stored there.

No functional changes (relative to the dependency below)
Split from {D9247}
Depends on {D9694} since the code was so close to eachother.

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9695
2020-12-21 14:07:16 -05:00
1e2c028a3a Fix/workaround geometry nodes not working with deformation motion blur
Always assume geometry nodes produce potentially animated meshes or point
clouds. In general it is hard to check if geometry nodes are animated, and
for modifiers this was already weak.

The better solution will likely involving checking which geometry was
modified by the depsgraph on frame change, to replace the current mechanism
of manually checking for certain types of modifiers and animation.
2020-12-21 19:19:59 +01:00
36b6ea6cb1 Weight Paint: fix Multi-Paint weight display after rB5502517c3.
Weight Paint Multi-Paint definitely depends on the weight specific
flag, and vertex group locking also involves group name symmetry
via BKE_object_defgroup_mirror_selection. These two are also
features implemented by me so I feel confident.

The rest of object_vgroup.c possibly should be changed too, but
that requires more consideration than these obvious cases.
2020-12-21 20:50:05 +03:00
be71bd8fcc Cleanup: Reduce indentation 2020-12-21 09:43:54 -06:00
Matteo Falduto
985528c9b9 UI: make light spot shape panel consistent between Cycles and Eevee
Differential Revision: https://developer.blender.org/D9906
2020-12-21 14:15:21 +01:00
d2239b685c UI: Use better icon for identifying assets
Use the `ASSET_MANAGER` icon which is more appropriate than the current one
which was just an unused icon that seemed sorta fitting, but was only meant to
be temporary.
The `ASSET_MANAGER` icon is already used for the Asset Browser, so it's being
reused which we normally avoid. So we may still want to create a dedicated one,
maybe a variation of this one.
2020-12-21 13:33:48 +01:00
626a9aae6d Fix part of T84004: Some 2.92 alpha UI strings can't be translated.
Adding 'new' (?) `heading` parameter of some UILayout functions...
2020-12-21 11:50:38 +01:00
5fe24ce295 Fix T84010: Missing scale animation versioning code
Code was removed in 247b10e6a2 but it was incorrect in first place.
Conversion was done for `offset_x` and `offset_y` channel originally,
but it should be done for `scale_x` and `scale_y`
2020-12-21 11:36:39 +01:00
c34ba26856 Fix part of T84004: Some 2.92 alpha UI strings can't be translated.
Not sure why, but py files from `bl_operators` were never considered for
i18n string extraction... They do define some UI strings though.
2020-12-21 11:35:02 +01:00
c9c3bf9833 Some more UI messages fixes... 2020-12-21 10:52:15 +01:00
42e2dd2178 Fix some UI messages and update i18n spellcheck utils. 2020-12-21 10:49:33 +01:00
720b2c6655 install-deps: Install OIIO utils, re-enable package on RPMs.
OIIO utils are mandatory for a whole set of tests (Cycles, VSE), and
it's a small package, no reason to not install it.

Also re-enabling package handling of OIIO on RPM-based distro, not sure
why it was disabled but this has become a fairly stable and standard
library now, would not expect issues anymore.
2020-12-21 09:49:08 +01:00
Matt Hill
fdb7623e09 Unix/macOS: support building with Ccache
This adds an option (WITH_COMPILER_CCACHE) to build using Ccache if it's
found. Makefiles-based, Ninja-based and Xcode generators are supported.

Pass `-DWITH_COMPILER_CCACHE=ON` to cmake to enable Ccache.
Utility option in GNUmakefile is also added: for e.g.,
`make ninja ccache`.

Reviewed By: brecht, ankitm
Differential Revision: https://developer.blender.org/D9665
2020-12-21 10:47:35 +05:30
Garry R. Osgood
84cc00f3b6 Fix T83989: Attribute Math node ignores its operation setting
T83989 observes that the Attribute Math node always adds its
operands regardless of its operator setting. This was caused
by an oversight committed in rB23233fcf056e42, which overlooked
adjusting the exec function to use the new storage location.

Differential Revision: https://developer.blender.org/D9909
2020-12-20 18:46:24 -06:00
c229d9876b Cleanup: Correct comment 2020-12-20 18:42:35 -06:00
d283a093d6 fix T83880: Added check for valid context object to avoid null pointer exception when no object in scene 2020-12-20 18:48:40 +01:00
Yevgeny Makarov
478ba53270 UI: Fix text padding in some list widgets
Normally, pure text buttons have no padding at their edges so they
align with edges of buttons, see D9058. However, in several cases
there are labels aligned to the right side of a list widget row,
so they're missing padding against the right edge.

The fix is to use emboss = 'NONE' for such labels, which changes
the drawing style, adding padding on the right edge. (Normally so
labels aligned with the text from non-embossed buttons). This is
not necessarily intended, but it works properly.

For more information, see the revision.

Differential Revision: https://developer.blender.org/D9874
2020-12-20 11:27:02 -06:00
16527ebaba UI: Slightly improve alignment in selection tool icons
Parts of the tool icons for box, circle, lasso, and tweak select that were
meant to be flat or at a 45 degree angle were slightly misaligned, making
the edge look blurry.
2020-12-20 10:53:23 -06:00
Peter Fog
5a69f70751 VSE: Add options to select neighboring handles
Options added to `sequencer.select_handles()` operator.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D7707
2020-12-20 06:23:08 +01:00
Yevgeny Makarov
864c806863 UI: Reorder enums in render results image editor header
The convention is to put the label at the bottom of the enum, or in the
spot furthest away from the button. This commit reorders the items in
the "Slot", "Layer", and "Pass" menus to be consistent with this
convention. It also reorders the numbering so that higher numbers are
lower.

The original patch was by Adrian Newton (@TFS), with slight changes
and additions.

Differential Revision: https://developer.blender.org/D7142
2020-12-19 21:52:45 -06:00
38b77ef8b2 VSE: Remove cost calculation from cache
This value was meant to be used for keeping images that are slowest to
render in cache. Method of measurement was flawed, because it doesn't
take UI overhead into consideration.

Cache panel is to be removed because users should not have to tweak
settings like this. It is not useful for development either, therefore
it is removed completely.
2020-12-20 03:58:38 +01:00
c4ff91aab7 VSE: Fix incorrect cache memory usage calculation
If image is cached twice, it's size has been counted twice as well, but
only image reference count is increased, not memory usage.

Use `MEM_get_memory_in_use()` instead of size own tracking.
2020-12-20 03:51:56 +01:00
Aaron Carlisle
0144b70948 Movie Clip: Annotation UI Improvements
Previously, the Annotation panels were a bit buggy in the movie clip editor.
This commit fixes the issue of the panel in the sidebar would disappear
when selecting  "Tracks" if no tracks were added to the clip.
To solve this issue the user if given a label text saying "No annotation source"

This commit also removes some grease pencil operators from the toolbar
that do not work with the new annotation system.

This commit also moves the data source choice from the toolbar to the sidebar.
This is needed to migrate the current toolbar to the new tool system
(see T83612)

Some old invalid code was also removed.

Reviewed By: #grease_pencil, antoniov

Differential Revision: https://developer.blender.org/D9729
2020-12-19 14:49:38 -05:00
Aaron Carlisle
6538f1e600 Compositor: New Exposure Node
This new node increases the radiance of an image by a scalar value.
Previously, the only way to adjust the the exposure of an image was with
math node or using the scene's color management.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D9677
2020-12-19 14:41:14 -05:00
09be4a0917 Cleanup: Use typedef for UI emboss type enum
Previously both `char` and `int` were used to represent this enum.

Differential Revision: https://developer.blender.org/D9903
2020-12-19 10:07:20 -06:00
a5a302bd18 Cleanup: Split SEQ_sequencer.h file 2020-12-19 07:25:01 +01:00
046ca0749a Cleanup: Rename BKE_sequencer functions
API functions get SEQ_ prefix.
Intern functions get seq_ prefix

Functions also have appropriate category included in name.
2020-12-19 06:29:15 +01:00
6942dd9f49 Fix T83868: Button animation states no longer visible without emboss
This bug was caused by making it so that non-embossed modifier icon
buttons could become an operator button and retain their red highlight
for disabled modifiers. The icon button needs emboss turned off, but
in earlier versions of Blender, `UI_EMBOSS_NONE` would be overridden
by animation or red alert states.

Instead of abusing "NONE" to mean "none unless there is animation or
red alert", this commit adds a new emboss flag for that situation,
`UI_EMBOSS_NONE_OR_STATUS`, which uses no emboss unless there is an
animation state, or another status. There are only a few situations
where this is necessary, so the change isn't too big.

Differential Revision: https://developer.blender.org/D9902
2020-12-18 17:13:15 -06:00
002722bb80 Fix build error after previous commit
I tested building so many times while making this patch, but somehow
the previous commit was missing a padding variable, I have no idea how.
2020-12-18 17:08:49 -06:00
c106b07e23 Cleanup: Remove unused variables from the bNode struct
In some cases the variables were set but never used anywhere.

Differential Revision: https://developer.blender.org/D9889
2020-12-18 17:04:52 -06:00
6367bc716a Cleanup: Use true and false for booleans 2020-12-18 15:12:15 -06:00
e298339289 Cleanup: Declare variables where initialized
Also decrease scope of some variable declarations.
2020-12-18 12:39:50 -06:00
6be9747b96 Cleanup: Use bool instead of int 2020-12-18 12:12:32 -06:00
2250b5cefe UI: Redesigned data-block selectors
The previous design is rather old and has a couple of problems:

* Scalability: The current solution of adding little icon buttons next to the
  data-block name field doesn't scale well. It only works if there's a small
  number of operations. We need to be able to place more items there for better
  data-block management. Especially with the introduction of library overrides.
* Discoverability: It's not obvious what some of the icons do. They appear and
  disappear, but it's not obvious why some are available at times and others
  not.
* Unclear Status: Currently their library status (linked, indirectly linked,
  broken link, library override) isn't really clear.
* Unusual behavior: Some of the icon buttons allow Shift or Ctrl clicking to
  invoke alternative behaviors. This is not a usual pattern in Blender.

This patch does the following changes:

* Adds a menu to the right of the name button to access all kinds of operations
  (create, delete, unlink, user management, library overrides, etc).
* Make good use of the "disabled hint" for tooltips, to explain why buttons are
  disabled. The UI team wants to establish this as a good practise.
* Use superimposed icons for duplicate and unlink, rather than extra buttons
  (uses less space, looks less distracting and is a nice + consistent design
  language).
* Remove fake user and user count button, they are available from the menu now.
* Support tooltips for superimposed icons (committed mouse hover feedback to
  master already).
* Slightly increase size of the name button - it was already a bit small
  before, and the move from real buttons to superimposed icons reduces usable
  space for the name itself.
* More clearly differentiate between duplicate and creating a new data-block.
  The latter is only available in the menu.
* Display library status icon on the left (linked, missing library, overridden,
  asset)
* Disables "Make Single User" button - in review we weren't sure if there are
  good use-cases for it, so better to see if we can remove it.

Note that I do expect some aspects of this design to change still. I think some
changes are problematic, but others disagreed. I will open a feedback thread on
devtalk to see what others think.

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

Reviewed by: Bastien Montagne

Design discussed and agreed on with the UI team, also see T79959.
2020-12-18 18:28:04 +01:00
7bee1489c1 UI: Rename "Float Color" attribute data type to "Color"
Since "Float Color" is more commonly used than "Byte Color",
which is not exposed in the interface yet anyway, it makes sense to
drop the "Float" label on the color data type name.
2020-12-18 09:34:21 -06:00
3deb21055a Geometry Nodes: support randomly picking instances from collection
This uses the "id" attribute to randomly pick instances from a collection
for each point.

There is one issue. When the collection is updated (e.g. when an object is
added to it), the nodes modifier is not automatically updated. It seems
like we don't have the infrastructure to support this dependency yet.
The same issue exists in the Boolean modifier and with collision collections.
This should be solved separately soonish.

When "Whole Collection" is disabled, one direct child of the input collection
is instanced at each point. A direct child can be an object or a collection.

Currently, all objects are picked approximately equally often. In the future,
we will provide more control over which point gets which instance.

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

Ref T82372.
2020-12-18 16:02:23 +01:00
1be465cccb GPencil: Fix potential error in interpolate frame
As now it is using a duplicated frame, the untag must be done before copying the frames.
2020-12-18 15:57:19 +01:00
f3b50380f0 Fix T83916: Cannot drag link from socket if node is inside frame
Caused by rB7470c10601d0 where iterating nodetree nodes was changed from
backwards to forwards by mistake.

Maniphest Tasks: T83916

Differential Revision: https://developer.blender.org/D9890
2020-12-18 14:41:38 +01:00
Vincent Blankfield
95afc53604 Fix T83716: Dope Sheet, incorrect scaling of channel UI elements
Change the top coordinate of the animation channel list UI elements to
`rect->ymin` so they correctly span from `rect->ymin` to
`channel_height`.

Some buttons in the dope sheet channels didn't scale properly with the
`Keyframe Scale Factor` preferences setting. This was caused by using
the `ymid` value (`ymid = BLI_rctf_cent_y(rect) - 0.5f * ICON_WIDTH`) to
position the buttons that supposed to fill all vertical space in the
channel (with `channel_height` height). The `ymid` value is only
appropriate for the UI elements that with `ICON_WIDTH` height.

Maniphest Tasks: T83716

Reviewed by: sybren

Differential Revision: https://developer.blender.org/D9841
2020-12-18 14:13:52 +01:00
e5764013b0 Geometry Nodes: move Boolean node to mesh category
This node works on meshes specifically.
2020-12-18 13:33:24 +01:00
c5569ba140 Geometry Nodes: do not crash when there are undefined nodes
Undefined geometry nodes will just output a default value now.
2020-12-18 13:28:55 +01:00
79d6bd9a22 Functions: add generic pointer class for const pointers
This adds a GPointer class, which is mostly the same as GMutablePointer.
The main difference is that GPointer references const data, while GMutablePointer
references non-const data.
2020-12-18 13:28:55 +01:00
f43561eae6 Function Nodes: Input Vector
Ref: T82651

Normally people use "Combine XYZ" to input a vector, but it is more
interesting to have an explicit vector input.

So this is basically "Combine XYZ" without any input sockets, the values
are stored in the node itself.

Differential Revision: https://developer.blender.org/D9885
2020-12-18 13:03:27 +01:00
b342e089c3 Fix mistake in Bake Action discontinuity fix
Fix mistake in e5528904f1 where one change accidentally wasn't included
in the commit.
2020-12-18 13:02:28 +01:00
e5528904f1 Fix T83351: Baked object rotation has discontinuities
Fix Euler discontinuities in the Bake Action operator, by explicitly
using the previous Euler angles when converting from matrix to rotation.

This basically follows the same approach as used in e4ca1fc4ea, although
the Euler Discontinuity Filter also performs single-channel filtering which
the Bake Action operator doesn't.
2020-12-18 12:50:36 +01:00
fe5d2448c6 Fix T83494: Eevee clamp node incorrect when min > max.
In glsl the clamp function has undefined behavior when min > max. For
the clamp node this resulted in differences between cycles and eevee.
This patch adds the expected implementation for minmax.

The old clamp function is still used in cases where we know for certain
that the input values are correct (math node clamp option). GPU uses
optimized code and silicon in these cases.
2020-12-18 10:26:02 +01:00
ffb6648a97 Fix T83625: Shading attribute names cause compilation error.
Some GPU platforms don't support having more than one underscore in
sequence in an attribute name. This change will remove the underscore
as a possible character when encoding to save names.
2020-12-18 09:56:28 +01:00
4f9e21bdc9 Fix T82591: Performance regression when rendering at very high resolution
This patch introduces a partial update of GPUTexture. When rendering
a large image the GPUTexture could have been scaled. The old implementation
would rescale the image on CPU and create a new GPUTexture. This
resulted in flooding the PCI bus.

The new solution would only scale and upload the parts of the GPUTexture
that has been changed. It does this by keeping track of areas of 256x256
pixels. When something changes the tiles that cover that changes will be
rescaled and uploaded the next time the GPUTexture is requested.

Test situation: Default Cube, 4 samples, 19200x10800 tile size 512.

Blender 2.83.9: 4m27s.
Blender 2.91:   20+m (regression)
This patch:     1m01s.

There is still room for more optimizations:
* Reduce the time that an image is locked.
** Use task scheduling to update the tiles of an image.
** Generic optimization of the ImBuf scale method.

Maniphest Tasks: T82591

Differential Revision: https://developer.blender.org/D9591
2020-12-18 09:18:44 +01:00
095b693614 Outliner: Set active modifier on click
The outliner already expands the panel for the modifier you click on,
this just extends that idea to also set it active, which is consistent
with behavior of active and selected items elsewhere in Blender.
2020-12-17 23:35:05 -06:00
9dbc014af7 Cleanup: Various clang tidy warnings
There are more in the new mesh fairing code and in the poisson
distribution code, this commit doesn't fix those.
2020-12-17 22:53:47 -06:00
7d25139eaf Fix T82960: Inaccurate selection on collapsed outliner rows
After rB15083d9e1 the outliner tree is not rebuilt after expanding or
collapsing rows. Because the tree is no longer rebuilt the positions
and flags of the elements are not cleared when collapsing a row. This
caused hover highlights and selections on the collapsed child icons to
be incorrect in many cases.

For example, only the direct children of a collapsed element are drawn
inline. If any grandchild elements had been previously icon row flagged
they would continue to be evaluated as icon row elements despite being
hidden. In this case the x coordinates of the child and grandchild would
overlap causing selection to appear erratic.

Now the flags for inline row icons are explicitly cleared, which was
previously only done because the tree was rebuilt on collapsing rows.
2020-12-17 20:10:20 -07:00
7cbcfb7f49 Cleanup: Use LISTBASE_FOREACH macro in outliner code
No functional changes.
2020-12-17 19:59:49 -07:00
f880fe2d66 Fix T82288 Wintab walk navigation erratic.
Walk navigation relies on tablet data being set to detect if motion is
absolute. This patch sets tablet data in Ghost to dummy values when a
tablet pen is in range and not handled by Wintab processing.
2020-12-17 17:21:15 -08:00
Yevgeny Makarov
ef17fb2715 UI: Don't use abbreviations in label text
Expand abbreviations for words like "Bright" (instead of "Brightness"),
"Premul", "Lib", "Dir", etc.

Differential Revision: https://developer.blender.org/D9862
2020-12-17 19:06:21 -06:00
23233fcf05 Cleanup: Use abstraction for attribute math node input
Since creating the attribute node, a helper function has been added to
automatically get the input attribute or a constant value, depending on
the "input type" values for the node. This commit replaces the specific
implementation of that behavior with the new helper function.

The versioning is necessary since the node now has a "storage" struct.
2020-12-17 14:43:01 -06:00
b10d8e330e Cleanup: renaming and code deduplication for color space clarity in picker
Ref T68926
2020-12-17 20:08:58 +01:00
f193b1afb3 Color Management: use scene linear HSV for number buttons in color pickers
Previously these HSV values were in the color picking space, which meant the
relation to the scene linear RGB values was confusing.

The new situation:
* RGB number buttons: scene linear color space
* HSV number buttons: scene linear color space
* Picker widgets: color picking color space
* Hex: sRGB color space

Fixes T69562, T83853, Ref T68926
2020-12-17 20:08:58 +01:00
48ddb94a26 Geometry Nodes: Point separate and attribute compare nodes
This patch adds two related nodes, a node for separating points
and mesh vertices based on a boolean attribute input, and a node
for creating boolean attributes with comparisons.

See the differential for an example file and video.

Point Separate (T83059)
The output in both geometries is just point data, contained in the mesh
and point cloud components, depending which components had data in the
input geometry. Any points with the mask attribute set to true will be
moved from the first geometry output to the second. This means that
for meshes, all edge and face data will be removed. Any point domain
attributes are moved to the correct output geometry as well.

Attribute Compare (T83057)
The attribute compare does the "Equal" and "Not Equal" operations by
comparing vectors and colors based on their distance from each other.
For other operations, the comparison is between the lengths of the
vector inputs. In general, the highest complexity data type is used
for the operation, and a new function to determine that is added.

Differential Revision: https://developer.blender.org/D9876
2020-12-17 12:22:47 -06:00
Himanshi Kalra
e7b698327c Updated and extended Regression Testing frameworks (Gsoc 2020)
This revision contains the following changes-

  - Updated the existing testing framework for Modifiers for Regression
  Testing.
  - Tests for Physics modifiers and remaining Generate and Deform modifiers are added.
  - The existing `ModifierSpec` is updated with backward compatibility to support Physics Modifiers.
  - Now there is support for frame number and giving nested parameters for attributes.
  - Some Deform modifiers required Object Operators, e.g. "Bind" in Mesh Deform, so a new class was added to support that functionality.
  - A separate class for holding Particles System, they are tested by converting all the particles to mesh and joining it to the mesh they were added.
  - Updated the format to add tests for Bevel, Boolean and Operators as
  well.

Reviewed By: zazizizou, mont29, campbellbarton

Differential Revision: https://developer.blender.org/D8507
2020-12-17 20:58:20 +05:30
fed995ced5 Fix T83888: Ctrl F in Asset Browser crashes blender
In case of being in Asset browsing mode, the search field is located in
the header (RGN_TYPE_HEADER not RGN_TYPE_UI as for file browsing mode).
To be future proof, now iterate all regions and act if the
"filter_search" can be activated.

Maniphest Tasks: T83888

Differential Revision: https://developer.blender.org/D9882
2020-12-17 16:05:20 +01:00
3fc07d1e74 Fix T83886: Particle instance modifier broken
Caused by Caused by rB83980506957c.

Since above commit, the modifier was created with wrong initial values
[amount was 0.0 and offset was 1.0 -- instead of the other way around].

Since there is no way to fix existing files in a reasonable way I guess,
all we can do here is to make sure that from now on, the defaults are
correct.

Maniphest Tasks: T83886

Differential Revision: https://developer.blender.org/D9881
2020-12-17 16:00:18 +01:00
c9f8f7915f Geometry Nodes: Make random attribute node stable
Currently, the random attribute node doesn't work well for most
workflows because for any change in the input data it outputs
completely different results.

This patch adds an implicit seed attribute input to the node, referred
to by "id". The attribute is hashed for each element using the CPPType
system's hash method, meaning the attribute can have any data type.
Supporting any data type is also important so any attribute can be
copied into the "id" attribute and used as a seed.

The "id" attribute is an example of a "reserved name" attribute,
meaning attributes with this name can be used implicitly by nodes like
the random attribute node. Although it makes it a bit more difficult
to dig deeper, using the name implicitly rather than exposing it as an
input should make the system more accessible and predictable.

Differential Revision: https://developer.blender.org/D9832
2020-12-17 07:43:31 -06:00
a9edf2c869 Geometry-Nodes: Point Distribute - Sockets Renaming
The size of the nodes is not enough to give enough context to users what
the sockets are about.

Minimum Distance -> Distance Min
Maximum Density -> Distance Min

Note this does not handle doversion. That means users will have to
manually.
2020-12-17 14:31:41 +01:00
9258b70453 Explicitly link X11 libraries
Fix X11 library underlinking, which was breaking Debian and Ubuntu
packages.

From Ubuntu Hirsute changelog:

```
blender (2.83.5+dfsg-4ubuntu1) hirsute; urgency=medium

  * Try to also link ghost library with x11, needed because of missing
    XConvertSelection symbol link (used in ghost static library).
  * Don't use gold, but switch to bfd linker that seems to be working better
    on ppc64el.

 -- Gianfranco Costamagna <locutusofborg@debian.org>  Wed, 11 Nov 2020 14:17:29 +0100
```

Reviewed by: sybren

Differential Revision: https://developer.blender.org/D9617
2020-12-17 13:24:35 +01:00
cf2ebaf27c Fix T83875: Converting Proxy to override crashes blender.
Some weird proxies apparently can have a local collection instancing...
Not sure this is even really valid for proxies, but in any case we
cannot override that, just detect and properly cancel the operation
then.

Should be backported to 2.91.1 should we do it.
2020-12-17 12:05:30 +01:00
0eedba328d Geometry Nodes: add Attribute Color Ramp node
Differential Revision: https://developer.blender.org/D9861

Ref T82585.
2020-12-17 11:56:18 +01:00
2945c1e3e5 Fix asset data-block name button not showing up in custom repositories
The Python syntax was wrong, as noted by Campbell in 0ae15e68c7.
2020-12-17 11:39:45 +01:00
6203a3ee68 Fix T83878: Crash right-clicking in Asset Browser with no asset active
Data of the File Browser context callback needs to be validated and
return `CTX_RESULT_NO_DATA` if the context member is valid but not set
in the current context.
2020-12-17 11:24:08 +01:00
7e535499d5 Clean-up: Fix build warning with MSVC
Callback function was using int while update_render_passes_cb_t was
using eNodeSocketDatatype leading to a build warning about different
argument types with MSVC.
2020-12-16 21:03:42 -07:00
8df6589585 VSE: Fix crash when adding image strip
Crash happens when using relative path to image in operator properties
and checking image dimensions by loading image with `IMB_loadiffname()`

Ensure path is absolute.
2020-12-17 02:32:24 +01:00
d11b219d40 Fix T83869: Crash when creating Sequencer in new scene
Crash on null dereference in `SEQ_timeline_boundbox()`. This function was
generalized in rB9e4a4c2e996c to work on arbitrary `seqbase`.

Fixed by refactoring `SEQ_timeline_boundbox()` functions to return default
sane values if `seqbase` is `NULL`

Reviewed By: HooglyBoogly

Differential Revision: https://developer.blender.org/D9878
2020-12-17 02:19:34 +01:00
3a1d1aaa86 Synchronize Wintab and Win32 time.
Time is synchronized by the difference between the WT_PACKET receive
time and the last received PACKET's pkTime. This is used to prevent
Wintab packets from being prematurely expired.
2020-12-16 15:32:18 -08:00
9f588432e9 Fix T83861: Snapping panel from shortcut dissapears after click
This simple change sets the call_panel operator's "keep_open" property
to True for the viewport snapping panel called with `ctrl-shift-tab`.
There are quite a few settings in this panel, it often makes sense to
change more than one of them at a time, especially because multiple
snap elements can be active at the same time.
2020-12-16 14:40:30 -06:00
07c4615431 Fix T83856: Sculpt: anchored brushes with spherical falloff ignore topology automasking
Anchored brushes with spherical falloff start off with zero radius, thus
we have no pbvh nodes on the first brush step. This would prevent
initializing the automasking cache [which only happens on the first brush
step].

Maniphest Tasks: T83856

Differential Revision: https://developer.blender.org/D9873
2020-12-16 21:36:15 +01:00
247b10e6a2 Fix sequencer transform test failing
This was casued by incorrect versioning keyframe conversion in
recent commit 5713626422.
2020-12-16 21:28:01 +01:00
Gaia Clary
ad7682ffdb Allow vertex tools to operate on weight groups when armature is in object mode
Since a few versions (even before 2.79) we have an option that allows to restrict the vertex tools to operate only on deform groups. This was originally implemented for working with vertex groups for skeletal animation. In that case it is fortunate to have weight tools operate only on deforming vertext groups (vgroups assigned to bones)

In previous versions of Blender (up to 2.79) we have been able to use this option in Mesh Edit mode regardless of the armature mode. The current implementation (since 2.80 as far as i know) enables this option only when the associated armature is in pose mode. this has a bad consequence:

It is not at all intuitive that you have to put the armature into Pose mode before you can make use of the option in mesh edit mode.
Besides this it is not even necessary in the case when the user wants to restrict the tool only to all pose bones. In that case the armature can safely be kept in Object mode. However, when the tool shall apply only to selected pose bones, then it actually makes sense to have the armature in pose mode (as it is implemented right now)

I do not know why this feature has been restricted as described above. It must have got lost somewhere on the way to Blender 2.90

This patch fixes the issue as it allows to select the "restrict to pose bones" option when the armature is in any mode. I see no downsides of this change, actually this is a fix for a feature that once worked and apparently got forgotten in newer releases.

Reviewed By: sybren, campbellbarton

Differential Revision: https://developer.blender.org/D9658
2020-12-16 20:46:50 +01:00
5713626422 VSE: Improve motion-picture workflow
This commit resolves problem introduced in e1665c3d31 - it was
difficult to import media at their original resolution.
This is done by using original resolution as reference for scale.

All crop and strip transform values and their animation is converted
form old files.

To make both workflows easy to use, sequencer tool settings have been
created with preset for preffered scaling method. This setting is in
sequencer timeline header and add image or movie strip operator
properties.

Two new operators have been added:
`sequencer.strip_transform_fit` operator with 3 options: Scale To Fit,
Scale to Fill and Stretch To Fill.
Operator can fail if strip image or video is not loaded currently, this
case should be either sanitized or data loaded on demand.

`sequencer.strip_transform_clear` operator with 4 options:
Clear position, scale, rotation and all (previous 3 options combined).

Reviewed By: sergey, fsiddi

Differential Revision: https://developer.blender.org/D9582
2020-12-16 20:38:28 +01:00
9d15226383 Ghost/Linux: Avoid error print if special directory can't be determined
The function is supposed to fail gracefully if there is some error. That
includes not being able to find `xdg-user-dir`. So don't let the error
be printed to the console, it's misleading/annoying.
From what I can tell we'll detect that problem fine and return NULL
then.
2020-12-16 20:36:37 +01:00
a8da70f70a Geometry Nodes: Add boolean attribute in utility function
This follows up rBc484b54453e607, adding the boolean custom property
data type in one more place that was missed.
2020-12-16 12:50:45 -06:00
c484b54453 Geometry Nodes: Boolean attribute type
This adds a boolean attribute and custom data type, to be used in the
point separate node. It also adds it as supported data types in the
random attribute and attribute fill nodes.

There are more clever ways of storing a boolean attribute that make
more sense in certain situations-- sets, bitfields, and others, this
commit keeps it simple, saving those changes for when there is a proper
use case for them. In any case, we will still probably always want the
idea of a boolean attribute.

Differential Revision: https://developer.blender.org/D9818
2020-12-16 12:33:13 -06:00
c06c5d617a Cleanup: Replace mempcpy with memcpy
There is no need of using mempcpy here, memcpy is enough.

Note: This also fix building in Windows which was broken since a7628ec22a.
2020-12-16 18:02:55 +01:00
ebd8a703cc Fix T83851: Python: operator macros cause a crash
Caused by rB7447eb7e7430.

This is just a copy-paste error [previous LISTBASE_FOREACH substitution
of marco loop in that file has a different starting point which is not
appropriate here]

Maniphest Tasks: T83851

Differential Revision: https://developer.blender.org/D9872
2020-12-16 17:16:01 +01:00
a7628ec22a Geometry Nodes: Poisson disk point distribution node/method
This patch does two things:
* Introduce a Seed to the random distribution method
* Bring in a new distribution method for the point scattering node

Patch Review: https://developer.blender.org/D9787

Note: This commit doesn't not handle doversion. Which means that users
need to manually update their files that were using the Point Distribute
node and reconnect inputs to the "Maximum Density" socket.

Original patch by Sebastian Parborg, with changes to not rely on the cy
libraries and overall cleanup.

Patch review by Jacques Lucke, besides help with the new "heap" system
that was required for this algorithm.

Based on Cem Yuksel. 2015. Sample Elimination for Generating Poisson Disk
Sample. Sets. Computer Graphics Forum 34, 2 (May 2015), 25-32
http://www.cemyuksel.com/research/sampleelimination/
2020-12-16 17:13:46 +01:00
Pablo Dobarro
d23894d3ef Sculpt: Multires Displacement Smear
This tool implements smearing for multires displacement over the limit
surface, similar to how smearing for colors and topology slide works.
When used the displacement values of the vertices "slide" over the
topology, creating the effect of smearing the surface detail.

As the brush just modifies displacement values instead of coordinates,
the total displacement of the affected area doesn't change. This means
that this smearing effect can be used multiple times over the same area
without generating any artifacts in the topology.

When the brush is used with the pinch or expand smear modes,
displacement differences are pushed into the same area, creating hard
surface effects without pinching the topology.

As any other brush that relies on the limit surface (like displacement
erasers), this will work better after using apply base.

Reviewed By: sergey, JulienKaspar, dbystedt

Differential Revision: https://developer.blender.org/D9659
2020-12-16 17:08:19 +01:00
f3ab123e33 Cleanup: Remove unused crop field from RenderResult.
The `crop` field was used by Blender Internal to do an overscan per
tile and merge it back to the render result.
2020-12-16 16:54:24 +01:00
5c5550f7b8 Asset Browser: For assets without preview, show type icon in sidebar
Otherwise it would just show empty space where the icon is supposed to
be.
Unfortunately this icon is upscaled quite a bit and doesn't look too
great. Would be good to improve but not a high priority.
2020-12-16 16:38:56 +01:00
7ed69bd672 Fix T83843: Crash in Asset Browser sidebar with geometry asset selected
No icon should be created if the preview doesn't exist.
2020-12-16 16:38:56 +01:00
4463087223 BLI: remove implicit casts between some span types
Casting pointers from one type to another does change the
value of the pointer in some cases. Therefore, casting a span
that contains pointers of one type to a span that contains
pointers of another type, is not generally safe. In practice, this
issue mainly comes up when dealing with classes that have a
vtable.

There are some special cases that are still allowed. For example,
adding const to the pointer does not change the address.
Also, casting to a void pointer is fine.

In cases where implicit conversion is disabled, but one is sure
that the cast is valid, an explicit call of `span.cast<NewType>()`
can be used.
2020-12-16 16:00:17 +01:00
684c771263 Fix: Python warning in windows debug builds
When doing a debug build on windows, blender will
start with the following warning:

"Unable to find the python binary, the multiprocessing
module may not be functional!"

The root cause for this issue is: for a debug build
the python binary is called python_d.exe rather than
just python.exe

This change fixes BKE_appdir_program_python_search
to look for the _d suffix for debug builds on windows

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

Reviewed by: Campbell Barton
2020-12-16 07:27:47 -07:00
25543e6983 LibOverride: Better handling of missing linked data during resync.
We do not generate overrides for missing data-blocks (aka placeholder
ones) anymore, and properly delete the remaining old overrides of those
during the resync process.

This should prevent constant 'missing data-blocks' messages when opening
blend files with overrides whose libraries have beed edited.

Issue reported by @andy from Blender studio, thanks.
2020-12-16 15:12:56 +01:00
8d590e4b86 Fix T83801: UVEditor translation ignores "Pixel Coordinates" and aspect
ratio

Caused by rB4eda60c2d82d.

T83801 reported not moving in pixel space, but even without that toggle
above commit caused the translation to not take apsect ratio into
account properly [a translation of 1 on the x axis for example on an
image with non 1:1 aspect ration caused the UVs to not end up in the
same place on the next 'tile']

Above commit removed 'removeAspectRatio()' [the counterpart of
applyAspectRatio -- which does the pixel coord correction internally]
from 'applyTranslation()'.

This was also reported in T83352 [which was closed by rBf3b08af24c9f --
but that only solved the displax in header, not the actual
transformation]

Now bring back 'removeAspectRatio()'.

Maniphest Tasks: T83801

Differential Revision: https://developer.blender.org/D9869
2020-12-16 15:03:46 +01:00
8da62a9a86 Fix T83547: UV Editor stitching preview is gone.
Issue was related that the draw manager didn't invoked the draw handlers
for image editors.
2020-12-16 15:02:48 +01:00
245450b144 Fix exported keymaps loading in 2.91 and older
The generated keymaps used a keyword argument that doesn't exist
in older Blender versions.
2020-12-17 00:53:28 +11:00
Valdemar Lindberg
69c3f4a46d Fix 3D View is red when using stereo
Fix T83415: 3D View is red when using stereo

The red view was caused by SRGB not being enabled for an SRGB texture attached to the framebuffer.
Currently, when configuring a framebuffer, the first texture attachment needs to be an SRGB format in order for the framebuffer to be binded with SRGB enabled.
Thus, simply changing the SRGB texture attachment as the first texture attachment removes the red color in the view.

Reviewed By: #eevee_viewport, jbakker

Maniphest Tasks: T83415

Differential Revision: https://developer.blender.org/D9845
2020-12-16 14:21:51 +01:00
29f923b27c Fix T83557: Alpha blend + emissive colors renders white artifacts
Issue was that not all code paths were taken to determine if
the GPU Texture was premultiplied or not. In this case the result
was set to unpremultiplied what is incorrect.

This fixes broken test case image alpha blend from image_colorspace.
2020-12-16 13:57:28 +01:00
4c26dd430d Geometry Nodes: rename node to Attribute Randomize
Previously, the node was called Random Attribute. For consistency reasons,
we move the "Attribute" part of the name to the front.
2020-12-16 13:31:56 +01:00
985d673374 BLI: add new InplacePriorityQueue data structure
This data structure adds priority queue functionality to an existing array.
The underlying array is not changed. Instead, the priority queue maintains
indices into the original array.

Changing priorities of elements dynamically is supported, but the priority
queue has to  be informed of such changes.

This data structure is needed for D9787.
2020-12-16 12:19:17 +01:00
Eric Cosky
4f128269b2 Fix possible crash with custom (add-on defined) icons
This change is a simple null check on the ID provided to icon_set_image() which
appears to be a legitimate value for the ID when used by some addins
(discovered with PowerSave shortly after syncing to main).

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

Reviewed by: Julian Eisel
2020-12-16 12:13:49 +01:00
3fc9fc1cb4 UI: Indicate asset data-blocks with an icon in Outliners & search menus
It's useful to easily see which data-blocks are assets and which not. So just
like we usually show the library linking/override icons, we show the asset icon
there (these are mutually exclusive data-block states).

Uses the `'MAT_SPHERE_SKY` icon, which wasn't used before (except by an
add-on!) and is sorta fitting, but not quite. We should either change this one
or add an own asset icon. Meanwhile this isn't too bad :)

Also adds an internal macro to check if a data-block is an asset, consistent to
how we do it for libraries and library overrides.
2020-12-16 12:10:58 +01:00
58d818f8be Assets: Add operator & button to regenerate the automatic preview
This makes it possible to trigger a refresh of the data-block preview,
available next to the preview in the Asset Browser sidebar. The previews get
easily outdated and automatically refreshing it all the time is not an option
because it would be a consistently running, quite expensive process. So a
button to cause a refresh should be reasonable.

This button can also be used to switch back from a custom preview to a
generated one. Although that may not be clear, and we should probably think of
a way to explain that better.

Addresses T82719.
2020-12-16 12:10:58 +01:00
c7a500e3a0 Asset Browser UI: Changes to the sidebar layout
The current layout wasn't great at all, and it was planned to polish this. This
does a first round of improvements, some more tweaking may follow.
* Place name button at the top, with no panel and no leading label.
* Add "Preview" panel, people may not want to see the preview all the time,
  it's already visible in the file list.
* Move button to browse for a custom preview to the right of the preview, as
  icon-only. We have a similar layout in other places (UI-lists, matcaps).
* Don't make the details panel a sub-panel. Looked weird because the parent
  doesn't have a header.
* Add info icon to "No asset selected", looks a bit friendlier.
* Minor cleanups in the UI script.

Based on designs and feedback by William Reynish.
2020-12-16 12:10:58 +01:00
19fc30c15f Assets UI: Tweak position of the "Add Asset Library" icon-button in Preferences
It's weird to have a button that adds a new item at the bottom be placed at the
top. So rather move it below the list of custom asset library paths.
2020-12-16 12:10:58 +01:00
0ae15e68c7 Asset Browser: Allow renaming asset data-blocks from the sidebar directly
This is something we wanted to support doing. It's confusing if users see the
name but it's always grayed out. So be convenient and avoid the confusion.
2020-12-16 12:10:58 +01:00
055ef5df61 Cleanup: Rename Asset Browser context member from "active_id" to "id"
This is the same name we use elsewhere for the focused/active ID context
member, so this should follow it.
2020-12-16 12:10:58 +01:00
Nathan Letwory
975ca91939 Steam Release: Script creation of Steam build files
Script tool for automation of Steam build files for tasks like {T77348}

This script automates creation of the Steam files: download of the archives,
extraction of the archives, preparation of the build scripts (VDF files), actual
building of the Steam game files.

Requirements
============

* MacOS machine - Tested on Catalina 10.15.6. Extracting contents from the DMG
  archive did not work Windows nor on Linux using 7-zip. All DMG archives tested
  failed to be extracted. As such only MacOS is known to work.
* Steam SDK downloaded from SteamWorks - The `steamcmd` is used to generate the
  Steam game files. The path to the `steamcmd` is what is actually needed.
* SteamWorks credentials - Needed to log in using `steamcmd`.
* Login to SteamWorks with the `steamcmd` from the command-line at least once -
  Needded to ensure the user is properly logged in. On a new machine the user
  will have to go through two-factor authentication.
* App ID and Depot IDs - Needed to create the VDF files.
* Python 3.x - 3.7 was tested.
* Base URL - for downloading the archives.

Reviewed By: Jeroen Bakker

Differential Revision: https://developer.blender.org/D8429
2020-12-16 11:15:18 +01:00
9cbfcc4af5 Revert "Steam Release: Script creation of Steam build files"
This reverts commit 1a375d6ece.
2020-12-16 11:11:15 +01:00
Nathan Letwory
1a375d6ece Steam Release: Script creation of Steam build files
Script tool for automation of Steam build files for tasks like {T77348}

For in-depth information see the README.

Related Wiki page: https://wiki.blender.org/wiki/Process/Release_On_Steam

Reviewed By: jbakker

Maniphest Tasks: T77348

Differential Revision: https://developer.blender.org/D8429
2020-12-16 11:07:10 +01:00
d23a5b1d88 BLI: constexpr Span, IndexRange, StringRef(Null/Base)
Motivated by `std::string_view` being usable in
const (compile-time) context.
One functional change was needed for StringRef:
`std::char_traits<char>::length(str)` instead of `strlen`.

Reviewed By: JacquesLucke, LazyDodo
Differential Revision: https://developer.blender.org/D9788
2020-12-16 13:03:46 +05:30
e671c548e6 Cleanup: pep8 2020-12-16 18:02:40 +11:00
Vincent Blankfield
f34ca933a8 UI: include the category for add-ons search
This lead to some confusion, see T83747.

Now the category is included in the search when the category is "All".

Ref D9848
2020-12-16 16:35:26 +11:00
a869a61c88 Cleanup: sort struct blocks 2020-12-16 16:26:23 +11:00
b347c4e9ca Cleanup: remove redundant struct declarations 2020-12-16 16:25:56 +11:00
588f107f11 Cleanup: clang-format 2020-12-16 16:13:05 +11:00
87fdb71438 Cleanup: use static declarations 2020-12-16 16:12:50 +11:00
977bd7937a Fix warnings introduced in previous commit 2020-12-16 00:20:20 +01:00
Peter Fog
fad80a95fd VSE: Add Overlay popover panels
Add panels with overlay settings for strips and preview and overlay
enable/disable button.

Entries from the View menus moved to the overlay panels, which will
simplify cluttered View menus.

Additional options have been added:
 - Strip Name
 - Strip Source(ex. path)
 - Strip Duration

So users can now select what info they need to see on the strips. When
No text is displayed, waveforms are drawn in full height.

Reviewed By: ISS, HooglyBoogly, pablovazquez

Differential Revision: https://developer.blender.org/D9751
2020-12-15 23:50:18 +01:00
Peter Fog
f44dea0558 VSE: Reorder Tools in Sequencer/Preview
When in Sequencer/Preview mode, the Sampler was on top, which normally
is the place of Select, and Annotation seems to be after Sampler in the
bottom in the various editors.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D9821
2020-12-15 22:30:01 +01:00
Peter Fog
dd9d12bf45 VSE: Paste strips after playhead by default
Paste copied strips after playhead, because this is more intuitive.

Previous functionality is still available by enabling "Keep Offset"
property, or under shortcut Ctrl+Shift+V.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D9734
2020-12-15 22:30:01 +01:00
Falk David
151e847b87 GPencil: Improve interpolation of strokes with unequal lengths
Use the BKE_gpencil_stroke_uniform_subdivide function to subdivide strokes
before interpolation. When the target/source stroke is smaller than the other
stroke, it is subdivided until the lengths match. This improves the overall quality
of the interpolation of different sized strokes.

Before/After video:
{F9511779}

Reviewed By: #grease_pencil, antoniov, pepeland, mendio

Differential Revision: https://developer.blender.org/D9839
2020-12-15 22:29:21 +01:00
Cody Winchester
5535b0b887 GPencil Array - Add option for uniform random scaling
This patch adds the option to make the random scaling from the grease pencil array modifier uniform.
The current settings allow a separate value for each of the 3 scaling axis. The modifier also creates different seed values for each axis so there is no way to keep the random scaling uniform.
This patch creates 1 random seed value and applies it to each of the scaling axis.

Here is a demonstration of the previous behavior and the new optional behavior.
{F9485973}
{F9485981}

{F9485798}

Reviewed By: #grease_pencil, antoniov, pepeland

Differential Revision: https://developer.blender.org/D9764
2020-12-15 22:16:49 +01:00
9e4a4c2e99 VSE: Move remove gaps operator logic to module code
Logic was broken into finding gaps and ofsetting strips.
Functions were modified so they work on explicitly defined seqbase,
so they can be used as python API functions.

Functional changes:
 - Improve performance by calculating gap length and offseting strips
   at once. Previously strips were offset by one frame.
 - Calculate gap from start frame. Previously gap was considered only
   inbetween strips.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D9730
2020-12-15 21:49:15 +01:00
7e8f6985d8 Fix crash selecting custom asset preview from maximized File Browser
If Preferences > Interface > Temporary Editors > File Browser is set to
"Maximized Area", "Load Custom Preview" in the Asset Browser would crash
after selecting the file.

1e799dd26e was important to get this issue fixed. This commit just
ensures the file-list is recreated correctly after closing the temporary
File Browser, so the custom preview operator can execute on valid
context.
2020-12-15 21:31:45 +01:00
1e799dd26e Fix various issues with temporary, maximized File Browsers
If Preferences > Interface > Temporary Editors > File Browser is set to
"Maximized Area", opening a File Browser from a File or Asset Browser as
regular editor would cause some issues. For example after closing the
temporary File Browser, the regular browser would take over the file
path and display settings from the temporary one. This is because they
used to share the same area data.

Some similar issues may have happend with temporary image editors.

Now, this commit finally separates the space data of temporary maximized
editors from the regular ones. So the editor data is entirely
independent now, as it should be.
2020-12-15 21:31:33 +01:00
c9b4d75336 Sculpt: Fair Face Sets operation for Face Set Edit
This implements a mesh fairing algorithm and implements the fair
operations for Face Set edit. This edit operations create a smooth as
possible geometry patch in the area of the selected Face Set.

The mesh fairing algorithm is designed by Brett Fedack for the addon
"Mesh Fairing": https://github.com/fedackb/mesh-fairing, with some
modifications:

- The main fairing function in BKE_mesh_fair.h does not triangulate
 the mesh. For the test I did in sculpt mode results are good enough
 without triangulating the topology. Depending on the use and the
 result quality needed for a particular tool, the mesh can be
 triangulate in the affected area before starting fairing.

- Cotangents loop weights are not implemented yet. The idea is to
also expose the vertex and loop weights in a different function in
 case a tool needs to set up custom weights.

This algorithm will also be used to solve the limitations of line
project and implement the Lasso Project and Polyline Project tools.
It can also be used in tools in other areas of Blender, like Edit Mode
or future retopology tools.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D9603
2020-12-15 20:32:58 +01:00
288f2efbd4 Fix T83504: Cancel trim operators when there is no geometry
The boolean solver crashes when there is no geometry in the mesh. Also,
using the trimming tools without a valid intersection in the PBVH will
make the orientation and position functionality of the trimming shape
not work, so this is the safer solution.

Reviewed By: mont29

Maniphest Tasks: T83504

Differential Revision: https://developer.blender.org/D9777
2020-12-15 20:23:17 +01:00
c9de65679b Fix T83201: Cloth brush performance regression
The if statement of the dynamic area mode branch should be an else if.
When using local mode, this was running both the local and global code.

I moved this code to sculpt_cloth and refactored it to use a switch case
to prevent this from happening again.

Reviewed By: mont29

Maniphest Tasks: T83201

Differential Revision: https://developer.blender.org/D9762
2020-12-15 20:22:26 +01:00
26e9c2147e Blenloader: Add utility function to write double array
It makes sense to support writing double arrays just like floats.
This is just split from a patch (D9697) to slim it down some.
2020-12-15 12:43:21 -06:00
d59e87acf0 Cleanup: Use nullptr instead of NULL in C++ code 2020-12-15 12:41:41 -06:00
8df167873a Cleanup: Clang tidy else after return 2020-12-15 12:39:27 -06:00
3834dc2f7b Fix Adjust Last Operation popup for operators relying on button context
This was reported for duplicating particle systems, then using F9 to
enable the 'Duplicate Settings' option (see T83317).
In this case, the operator gets the particle_system from (buttons)
context and if none can get found will duplicate all settings instead.

The reason why none gets found here is that buttons_context() doesnt
have a valid path when called from F9/SCREEN_OT_redo_last, path is
cleared when global undo does a file-read which clears the path (see
lib_link_workspace_layout_restore). It can be recomputed though to be
valid even from redo_last (at least when in the Properties Editor).

This was likely causing other operators (relying on buttons context)
from the Properties Editor to fail as well.

Fixes T83317

Maniphest Tasks: T83317

Differential Revision: https://developer.blender.org/D9825
2020-12-15 19:10:35 +01:00
ffe63b0440 Fix crash opening maximized File Browser from Asset Browser
If Preferences > Interface > Temporary Editors > File Browser is set to
"Maximized Area", opening a File Browser from an Asset Browser would
cause the new maximized editor to be an Asset Browser. Exiting it again
would crash.

This fixes the wrong behavior and the crash. There's still an issue with
exiting the editor again, it stays a File Browser then and doesn't go
back to being an Asset Browser. That's to be fixed separately.
2020-12-15 18:56:26 +01:00
b24712a9ca Fix (studio-reported) broken handling of relative font paths.
`blf_dir_search` BLF util would not properly handle relative fonts not
found in pre-defined 'system fonts' directoriesi stored in
`global_font_dir` global variable.

Now it rebases relative paths to current .blend file location as
expected.

Note: the fact that VSE is setting font ptaths relative by default is
probably not actually desired, but this is another issue really. See
`BKE_sequencer_text_font_load` code.
2020-12-15 18:22:22 +01:00
c6692014cf Fix redundant declaration warning
Function was declared twice (caused by merge conflicts) which GCC would
rightfully complain about.
2020-12-15 17:19:55 +01:00
990406e1ff Fix crash when deleting/renaming asset library while it's visible
Storing the asset library reference by name wasn't a good idea, I thought it
would work with a careful fallback, but it's easier to just use the index
instead. So change to using indices, make sure fallback methods work reliable
and make sure the file list is updated when asset libraries are removed.

I added a new notifier type for the latter, I prefer not using file notifiers
in asset-library/preferences code. We have more than enough values for
notifiers left.
2020-12-15 17:03:49 +01:00
7dc8db7cd1 Fix failing assert when generating material preview
The `!BKE_previewimg_is_finished()` in `icon_preview_startjob_all_sizes()`
would fail.

Caused by 990bd9acf243ae. We have to be more picky about tagging previews as
unfinished after file read. But we also have to consider files stored in old
versions and set the unfinished tag as needed.
2020-12-15 17:03:49 +01:00
9caeb9dfc7 Fix Asset Browser crash with undo in "Current File" library with sidebar
When the Asset Browser was showing the "Current File" repository and the
sidebar was open, undoing could crash, because the context API returned freed
data.

Don't let context return anything if a refresh is pending due to data changes
like undo/redo.
2020-12-15 17:03:49 +01:00
68e4a90240 Assets: Better path for the default asset library
In D9722 we agreed on using `[home-directory]/Documents/Blender/Assets` for
the default asset library. I just forgot to do the change before committing.

(The default repository is just a named path, it's *not* a default library with
bundled assets.)
2020-12-15 17:03:48 +01:00
303aceb917 Fix asset previews not showing in "Current File" repository after reading
Previews would be flagged as unfinished when reading. Instead clear the flag
and always consider them finished upon reading. If we wouldn't do this, the
File Browser would keep running the preview updating to wait for the preview to
finish. It could be smarter and also check if there's actually a preview job
running.
Instead, I think it will just display an unfilled buffer for now. Up until
today we wouldn't even know if a stored preview is finished or not, so it would
always assume they are finished. We do the same now, but have the option to
make it smarter.
2020-12-15 17:03:48 +01:00
2d6a69ae4e Asset System: New Asset Browser editor
This introduces the User Interface part of the Asset Browser, based on the
design in T54642.

Additions:
* New Asset Browser (internally a sub-editor of the File Browser).
* Navigation region showing asset categories.
* Main region showing the assets of the selected asset library with previews.
  The assets may be stored over multiple .blends in the directory that's
  "mounted" as asset library in the Preferences. They will all be shown in this
  list.
* Header with an asset library dropdown, allowing to choose the active asset
  library to show. Options are the "Current File" as asset library and all
  custom libraries.
* Display popover, filter popover and search box (partially dummies, see
  T82680).
* Sidebar showing the metadata of the currently active file (name, preview,
  description and tags), which can be edited for assets in the "Current File"
  asset library. (For others it will reset on reload.)
* The sidebar includes a button to load a custom preview image from a file.
* Make asset files draggable (with preview image).
* If a library with invalid path is selected, a message is drawn in the main
  region to help the user understand what's wrong.
* Operators to add and remove asset tags. Exposed in the sidebar.
* "Only Assets" option for Link/Append.
* Internal utilities for asset UI scripts.

For screenshots or demo videos, please see D9725. Or the 2.92 release notes.

Note that there are many things to be tweaked and polished in the Asset Browser
UI still. For example, the filter and display popovers are mostly dummies. See
T82680.

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-15 17:03:48 +01:00
70474e1a7c Asset System: Prepare File Browser backend for the Asset Browser
The Asset Browser will be a sub-editor of the File Browser. This prepares the
File Browser code for that.

**File-Lists**
* Support loading assets with metadata read from external files into the
  file-list.
* New main based file-list type, for the "Current File" asset library.
* Refresh file-list when switching between browse modes or asset libraries.
* Support empty file-lists (asset library with no assets).
* Store file previews as icons, so scripts can reference them via icon-id. See
  previous commit.

**Space Data**
* Introduce "browse mode" to differeniate between file and asset browsing.
* Add `FileAssetSelectParams` to `SpaceFile`, with `FileSelectParams` as base.
  Makes sure data is separated between asset and file browsing when switching
  between them. The active params can be obtained through
  `ED_fileselect_get_active_params()`.
* `FileAssetSelectParams` stores the currently visible asset library ID.
* Introduce file history abstraction so file and asset browsing can keep a
  separate history (previous and next directories).

**General**
* Option to only show asset data-blocks while file browsing (not exposed here).
* Add "active_file" context member, so scripts can get and display info about
  the active file.
* Add "active_id" context member, so `ED_OT_lib_id_load_custom_preview` can set
  a custom ID preview. (Only for "Current File" asset library)
* Expose some of `FileDirEntry` in RNA as (non-editable). That way scripts can
  obtain name, preview icon and asset-data.

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Bastien Montagne
2020-12-15 17:03:48 +01:00
e413c80371 Asset System: Support custom asset library paths through Preferences
One of the core design aspects of the Asset Browser is that users can "mount"
custom asset libraries via the Preferences. Currently an asset library is just
a directory with one or more .blend files in it. We could easily support a
single .blend file as asset library as well (rather than a directory). It's
just disabled currently.

Note that in earlier designs, asset libraries were called repositories.

Idea is simple: In Preferences > File Paths, you can create custom libraries,
by setting a name and selecting a path. The name is ensured to be unique. If
the name or path are empty, the Asset Browser will not show it in the list of
available asset libraries.
The library path is not checked for validity, the Asset Browser will allow
selecting invalid libraries, but show a message instead of the file list, to
help the user understand what's going on.
Of course the actual Asset Browser UI is not part of this commit, it's in one
of the following ones.

{F9497950}

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Brecht Van Lommel, Hans Goudey
2020-12-15 17:03:48 +01:00
b5d778a7d4 Asset System: Support dragging assets and appending on drop
For the Asset Browser, it needs to be possible to drag assets into various
editors, which may not come from the current .blend file. In other words, the
dragging needs to work with just the asset metadata, without direct access to
the data-block itself.

Idea is simple: When dragging an asset, store the source file-path and
data-block name and when dropping, append the data-block. It uses existing drop
operators, but the function to get the dropped data-block is replaced with one
that returns the local data-block, or, in case of an external asset, appends
the data-block first.

The drop operators need to be adjusted to use this new function that respects
assets. With this patch it only works for dragging assets into the 3D view.

Note that I expect this to be a short-lived change. A refactor like D4071 is
needed to make the drag & drop system more future proof for assets and other
use cases.

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-15 17:03:48 +01:00
9363132c86 Asset System: Various changes to previews in preparation for Asset Browser
* Support defining (not necessarily rendering) icons in threads. Needed so the
  File Browser can expose file previews with an icon-id to scripts.
** For that, ported `icons.c` to C++, to be able to use scope based mutex locks
   (cleaner & safer code). Had to do some cleanups and minor refactoring for
   that.
* Added support for ImBuf icons, as a decent way for icons to hold the file
  preview buffers.
* Tag previews as "unfinished" while they render in a thread, for the File
  Browser to dynamically load previews as they get finished.
* Better handle cases where threaded preview generation is requested, but the
  ID type doesn't support it (fallback to single threaded). This is for general
  sanity of the code (as in, safety and cleanness)
* Enabled asset notifier for custom preview loading operator, was just disabled
  because `NC_ASSET` wasn't defined in master yet.

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-15 17:03:45 +01:00
c25e031049 Asset System: "Mark Asset" & "Clear Asset" operators and UI integration
This makes it possible to turn data-blocks into assets and back into normal
data-blocks. A core design decision made for the asset system is that not every
data-block should be an asset, because not every data-block is made for reuse.
Users have to explicitly mark data-blocks as assets.

Exposes "Mark Asset" and "Clear Asset" in Outliner context menus (currently ID
Data submenu) and button context menus. We are still not too happy with the
names, they may change.

This uses the new context members to pass data-blocks to operators, added in
af008f5532 and 0c1d476923.

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Brecht Van Lommel
2020-12-15 17:03:00 +01:00
b71eb3a105 Asset System: Data-block asset metadata storage, reading and API
Asset metadata is what turns a regular data-block into an asset. It is a small
data-structure, but a key part of the technical design of the asset system.

The design foresees that asset data-blocks store an `ID.asset_data` pointer of
type `AssetMetaData`. This data **must not** have dependencies on other
data-blocks or data-block data, it must be an independent unit. That way we can
read asset-metadata from .blends without reading anything else from the file.
The Asset Browser will use this metadata (together with the data-block name,
preview and file path) to represent assets in the file list.

Includes:
* New `ID.asset_data` for asset metadata.
* Asset tags, description and custom properties.
* BKE code to manage asset meta-data and asset tags.
* Code to read asset data from files, without reading IDs.
* RNA for asset metadata (including tags)

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

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

Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-15 17:03:00 +01:00
82645ff739 Move Point Cloud object back to Experimental Features
The geometry-nodes features no longer depend on the point cloud object.
Therefore the point cloud object, although important in the future, can
be postponed until we have render and edit mode fully working.

This reverts commits:
* ea74ed5a7a.
* dc614c68ef.
2020-12-15 13:07:55 +01:00
0d58eabee6 Geometry Nodes: support evaluating mesh object to geometry set
This implements the design proposed in T83357.

The goal is to allow the geometry nodes modifier on mesh objects to
output instances and potentially other geometry types. Both problems
are tackled by allowing mesh objects to evaluate to a geometry set,
instead of just a single mesh id data block. The geometry set can
contain a mesh but also other data like instances and a point cloud.

I can't say that I'm sure that this commit won't introduce bugs. Mainly
the temporary object creation during rendering seems a bit brittle.
BUT, we can be reasonably sure that this commit will not introduce
regressions (at least not ones, that are hard to fix). This is because
the code has been written in a way that minimizes changes for existing
functionality.

Given that we intend to hide the point cloud object for the next release,
we won't even have to worry about temporary object creation for now.

An important part of the technical design is to make sure that
`ObjectRuntime->data_eval` contains the same data before and after this
patch. This helps to make sure, that existing code paths are impacted as
little as possible.

Instead of fully replacing `data_eval`, there is `geometry_set_eval`,
which contains all the geometry components an object evaluated to
(including the data referenced by `data_eval`).

For now, not much code has to be aware of `geometry_set_eval`. Mainly
the depsgraph object iterator and the instances system have to know
about it.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D9851
2020-12-15 12:42:10 +01:00
d8db5cb600 Fix: upward compatibility of cryptomatte matte id.
The matte_id is stored in a different structure in 2.92. This patch will
write the old matte_id field so the files can be opened correctly in
older versions.
2020-12-15 12:17:31 +01:00
ef2151d73d Fix T83776: Crashes with add-on's icon preview in menus
Apparently the ID pointer can be NULL, which most code here assumes is
not the case. But it's very fragile & finicky, there is one code path
were it's allowed to be NULL.

Add necessary NULL-checks, an assert as sanity check and a comment to
note the possibility of NULL.
2020-12-15 12:05:12 +01:00
1b130f17c9 Cleanup: make format 2020-12-15 12:01:45 +01:00
35368e8bfc Fix: mattes of cryptomatte node lost after write
Fix an issue introduced by {f4df036bc497} where the read/write
code missed to store and read the mattes from its new location.
2020-12-15 11:15:01 +01:00
12792ee70c Fix T83788: Topology mirror crashes for vertices aren't mirrored
Caused by da8dc204bd
2020-12-15 18:10:04 +11:00
e035d7301c Fix crash sliding effect sequence strips
Off by one error in array access.
2020-12-15 16:14:59 +11:00
a05d98884a RNA: disallow negative fcurve data-path array index 2020-12-15 12:48:33 +11:00
612598acd7 Cleanup: doxy comments (use colon after parameter name)
Also remove colon after `\note`.
2020-12-15 12:34:25 +11:00
001f2c5d50 Cleanup: spelling 2020-12-15 12:34:25 +11:00
e995296acb Cleanup: unused variables 2020-12-15 12:34:25 +11:00
525364be31 Cleanup: reduce indirect DNA header inclusion
Remove DNA headers, using forward declarations where possible.

Also removed duplicate header, header including it's self
and unnecessary inclusion of libc system headers from BKE header.
2020-12-15 12:34:14 +11:00
15f2f69694 Cleanup: Reduce variable scope 2020-12-14 17:48:57 -06:00
1e38e32cf6 Cleanup: type check failure, discarded-qualifiers warnings
Caused by 7f6ffe9195
2020-12-15 10:27:36 +11:00
7470c10601 Cleanup: Use LISTBASE_FOREACH macro, reduce variable scope 2020-12-14 17:19:43 -06:00
Wayde Moss
6074636387 NLA: Action Strip Defaults Sync Length On
See T82309#1055564 {T63675} and their duplicates for how Default-off
can cause confusion.

This is just for convenience since it allows animators to keyframe
outside of the strip's bounds by default. This was likely off by
default before since Syncing Length would undesirably shift the whole
animation after leaving tweak mode (fixed by {D7602}) and the animator
wasn't able to keyframe outside the strip bounds anyways
(fixed by {D7533}). Now it's better if the flag was on by default.
While the animator is still roughly developing their animation NLA-wise
they won't have to worry about strip bound keying failures. When they
are more certain of the strip bounds, they can disable the flag to
prevent affecting the rest of the NLA system.

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9661
2020-12-14 17:32:14 -05:00
Wayde Moss
7f6ffe9195 Nla Refactor: Blend functions explicit Div0 check
It's an explicit check to prevent division by zero if caller hasn't
done the check. Future patch {D8867} will not use the nla remap
function and thus not do the check. This patch also replaces some
float (==) equality checks with IS_EQF().

Split from {D9247}

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9694
2020-12-14 17:11:41 -05:00
Wayde Moss
fa6bf8f5b6 Nla Refactor: nlaevalchan_validate_index_ex()
And removes redundant index local variable. Future patches {D8296} and
{D8867} make use of this function.

No functional changes.
Split from {D9247}

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9693
2020-12-14 17:06:59 -05:00
Wayde Moss
04ca93ef9b NLA: Fix context.selected_nla_strips PointerRNA
The strips were given the wrong owner ID.  This only caused issues for
python based UI as far as I know. Property changes would not properly
update the viewport.

Reviewed By: lichtwerk

Differential Revision: https://developer.blender.org/D9685
2020-12-14 17:00:04 -05:00
20bc1ab275 Fix incorrect RNA type warning
Using the RNA type for regular modifiers instead of grease pencil
modifiers caused a warning in context.c.
2020-12-14 15:12:18 -06:00
49ec3cef69 Geometry Nodes: Input data type utility function
This commit adds a simple utility function for getting the data type of an
attribute or its "constant" socket counterparts. No functional changes.

Differential Revision: https://developer.blender.org/D9819
2020-12-14 11:43:54 -06:00
010f44b855 Fix several issues with handling of numpy in CMake.
Issues were:
* Abusing of `WITH_PYTHON_INSTALL_NUMPY` by both Audaspace and
  Mantaflow.
    - `PYTHON_INSTALL` options only decide whether we copy python (and
      some extra modules) in our Blender installation. On linux it
      makes much more sense to use global python installation.
    - Now we have instead a proper `WITH_PYTHON_NUMPY`
* Bad assumptions regarding path of headers relative to path of python
  module.
    - In current Debian testing, modules are under `python3.9`
      directory, while headers are under `python3` directory.
    - Now we properly `find_path` for headers as well, modifying
      `find_python_package` to take an optional argument for headers.

Note that the required changes done to `extern` libraries are in
blender-specific files that do not exist upstream.

Differential Revision: https://developer.blender.org/D9773
2020-12-14 16:44:55 +01:00
f4df036bc4 Cryptomatte: Data structure in compositor node
This changes the way how the mattes are stored in the compositor node. This used to
be a single string what was decoded/encoded when needed. The new data structure
stores all entries in `CryptomatteEntry` and is converted to the old `matte_id`
property on the fly.

This is done for some future changes in the workflow where a more structured
approach leads to less confusing and easier to read code.
2020-12-14 16:14:38 +01:00
07ce9910f7 Geometry Nodes: enabled supports-mapping in nodes modifier
Sometimes the geometry nodes modifier does support mapping and
sometimes it does not. We have no infrastruture to determine this ahead
of time currently. In order to support common use cases, it makes sense
to add this flag to the modifier.

One such common use case is to use the mesh as surface that other
things are distributed on. Often, the distribution is controlled by vertex
groups. Therefore, it would be helpful if the modifier is evaluated
when the object is in vertex paint mode. This allows the user to see the
distributed objects while painting.

If the nodes modifier transforms the mesh in any way, vertex painting
might not work as expected anymore, because the `deformMatrices`
callback is not implemented. I'm not sure how this can be solved nicely, yet.
2020-12-14 15:44:28 +01:00
9ee7270e0a Geometry Nodes: require vertex groups data in nodes modifier
Without this, the modifier evaluation code might remove any
vertex groups from the mesh for performance reasons.
We can't say for sure whether the node group will need the vertex
groups, but it is quite likely.

Ref T83357.
2020-12-14 15:29:50 +01:00
6714b800d1 Cryptomatte: apply volume transmittance to Eevee.
This patch will add volumetric transmittance to the cryptomatte coverage
data of all samples when post processing the cryptomatte passes.

It was discussed with Cycles that this is desired, but tricky to
implement in Cycles.
2020-12-14 15:03:29 +01:00
e3068f38c8 Fix memory leak and possible other issues with custom previews
Mistake in 812ea91842. Fixed that same one before in the branch, I may have
brought it back when resolving merge conflicts.
2020-12-14 14:57:30 +01:00
Joan Bonet Orantos
68d5ad9983 Fix T75539: Cycles missing geometry update when switching displacement method
The shaders were not tagged for a needed geometry update when the displacement method was modified, neither were the Geometry and Object managers.

Reviewed By: kevindietrich

Maniphest Tasks: T75539

Differential Revision: https://developer.blender.org/D8896
2020-12-14 13:44:29 +01:00
4b0396695c UI/Assets: Support generating object preview images
Object previews are really helpful for visual data-block selection, like asset
browsing. Having them be generative should also be quite handy and should work
well enough in many, if not most cases.

What this does is simple:
* Place the object (actually a deep copy of it, for thread safety) in a virtual
  .blend into an empty scene/view-layer.
* Add a camera, point it towards the front of the object, assuming that means
  pointing towards its +Y axis.
* Use "Camera Fit Frame to Selected" logic to put the object into frame.
* Create a threaded off-screen render.

Of course, such an automatic preview will not work in all situations. E.g. it
currently does a bad job capturing a single plane. We could add options for
more advanced automatic previews, but probably custom previews is more
important, which I committed already (812ea91842).

Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.

Reviewed as part of https://developer.blender.org/D9719.
Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-14 13:17:57 +01:00
732d0b458b Blenkernel: move DerivedMesh.c to c++
Required changes to make it compile with clang tidy:
* Use c++ includes like (e.g. climits instead limits.h).
* Insert type casts when casting from void* to something else.
* Replace NULL with nullptr.
* Insert casts from int to enum.
* Replace designed initializers (not supported in C++ yet).
* Use blender::Vector instead of BLI_array_staticdeclare (does not compile with C++).
* Replace typedef statements.

Ref T83357.
2020-12-14 13:08:02 +01:00
551856ed32 Revert "Fix several issues with handling of numpy in CMake."
This reverts commit 5d570c875e.

Buildbots are still borken, need more time to investigate.
2020-12-14 12:29:34 +01:00
fdc9350a9f Revert "Fix own error in rB5d570c875eda in CMake script."
This reverts commit 6da609fcb3.

Buildbots are still broken, need more time to investigate.
2020-12-14 12:29:08 +01:00
6da609fcb3 Fix own error in rB5d570c875eda in CMake script.
My mistake, though CMake could handle default arguments but it needs to
be explicitly passed actually.
2020-12-14 12:23:21 +01:00
812ea91842 UI/Assets: Operator to load custom preview images for data-blocks
No automatic preview generation will ever be good enough to cover all cases
well. So custom preview images are a must for a preview driven data-block
selection - like for asset browsing.

The operator simply allows selecting an image file, which will then be read and
copied into the data-blocks preview (resized if necessary).

There's no UI for this currently and the operator won't be available in the
search menu yet. It will later once the Asset Browser UI is merged.

Reviewed as part of https://developer.blender.org/D9719.
Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-14 12:16:59 +01:00
6f7ced77e3 Fix windows build. 2020-12-14 14:09:18 +03:00
Bastien Montagne
f5a019ed43 LibOverride: Do not store some heavy data from override IDs.
This commit removes geometry from meshes and shapekeys, and embedded
files, from liboverride IDs.

This data is never overrideable, there is no reason to store extra
useless copies of it in production files.

See T78944.

Note that we may add more data to be skipped on write for liboverrides
in the future, but this commit should address all the most important
cases already.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D9810
2020-12-14 11:37:01 +01:00
8e1b63d4bd GPencil: Add missing Pin icon for default eraser
This icon allows to set the default eraser when press Ctrl key and was removed by error in the brush refactor.
2020-12-14 11:31:01 +01:00
5d570c875e Fix several issues with handling of numpy in CMake.
Issues were:
* Abusing of `WITH_PYTHON_INSTALL_NUMPY` by both Audaspace and
  Mantaflow.
    - `PYTHON_INSTALL` options only decide whether we copy python (and
      some extra modules) in our Blender installation. On linux it
      makes much more sense to use global python installation.
    - Now we have instead a proper `WITH_PYTHON_NUMPY`
* Bad assumptions regarding path of headers relative to path of python
  module.
    - In current Debian testing, modules are under `python3.9`
      directory, while headers are under `python3` directory.
    - Now we properly `find_path` for headers as well, modifying
      `find_python_package` to take an optional argument for headers.

Note that the required changes done to `extern` libraries are in
blender-specific files that do not exist upstream.

Differential Revision: https://developer.blender.org/D9773
2020-12-14 11:00:28 +01:00
53ed96641c Cleanup: clang tidy 2020-12-14 10:48:11 +01:00
45bf470ee9 Fix T83712: arctangent math node does not work in Eevee
Caused by my refactoring of the math node.
Somehow this operation slipped through my double checking procedure.
2020-12-14 10:47:17 +01:00
067046c26a Cleanup: path_util.c comments 2020-12-14 20:44:26 +11:00
088df2bb03 Fix missing string escape for RNA path creation 2020-12-14 20:44:26 +11:00
b8ae90263a Fix version patching sequence strip alpha from 2.4x files
Regression in 4f5f868a52
2020-12-14 20:44:26 +11:00
7d4536cacc Fix enum-conversion, old-style-declaration warnings
Introduced in 8f3a401975
2020-12-14 20:44:26 +11:00
6327771bc9 Fix T83696: Add Additional menu to Effects panel
This adds the missing options for the effects as it is done in modifiers.

Reviewed By: HooglyBoogly

Maniphest Tasks: T83696

Differential Revision: https://developer.blender.org/D9838
2020-12-14 10:25:37 +01:00
8f3a401975 Eevee: Add Volume Transmittance to Color Render Passes.
In Cycles the volume transmittance is already composited into the color
passes. In Eevee the volume transmittance pass was separate and needed
to be composited in the compositor. This patch adds the volume
transmittance pass direct in the next render passes:

 * Diffuse Color
 * Specular Color
 * Emission
 * Environment

This patch includes the removal of the volume transmittance render pass.
It also renames the volume render passes to match Cycles. The setting
themselves aren't unified.

Maniphest Tasks: T81134
2020-12-14 09:27:58 +01:00
fddbcb5757 UI: Click modifier icon to set active modifier
This should be a final piece of the changes for the active modifier
interface. Before, it was necessary to click on the blank space of a
modifier panel to set it active (not the header), this commit allows
clicking on the icon also.

The spacing with the spacing with the expand button would ideally
be a bit larger, but the layout system doesn't offer much flexibility
here.
2020-12-13 23:49:14 -06:00
260fca5d08 Fix T83673: Custom node trees selectable in nodes modifier
Node tree types from addons were selectable in the modifier's drop-down.
Obviously they didn't do anything, but it shouldn't be possible anyway.
This was just caused by an unimplemented poll function.
2020-12-13 22:59:52 -06:00
Yevgeny Makarov
977ef04746 Cleanup: Fix capitalization in various places
Approximately 33 changes of capitalization to conform to MLA title style.

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

Reviewed by Julian Eisel
2020-12-13 13:12:56 -08:00
dd0520b93b Fix T83725 Inconsistent vertex group between exact and fast boolean.
This makes the exact boolean have zero weights for any vertex groups
on any newly created vertices, which is what the fast solver does.

The exact boolean solver was interpolating vertex data when interpolating
loop data in newly created faces. Not sure why I chose that. The Fast
boolean solver doesn't do that, so I stopped doing it too.
2020-12-13 16:04:05 -05:00
Yevgeny Makarov
a2693ba43e Cleanup: removing some uses of equal sign in descriptions
Using 'is/means/equal' words in place of equal sign in descriptions.

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

Reviewed by Hans Goudey
2020-12-13 12:59:36 -08:00
Yevgeny Makarov
afeaac8b18 Fix cursor position on HighDPI in stereo side-by-side mode
Could not select left quarter of the screen in stereo side-by-side mode on high dpi displays.

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

Reviewed by Julian Eisel
2020-12-13 12:48:50 -08:00
Yevgeny Makarov
2e5d9a73f7 UI: Improved Script Execution Warning
New dialog box layout with large alert icon for the Python script execution warning popup.

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

Reviewed by Hans Goudey
2020-12-13 12:39:28 -08:00
Yevgeny Makarov
bec583951d UI: Remove Unused 'U.wheellinescroll' Property
Remove 'U.wheellinescroll' preference, currently hidden and unused.

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

Reviewed by Brecht Van Lommel
2020-12-13 12:30:03 -08:00
9c0df8e275 Fix weird Swing+Twist decomposition with noncanonical quaternions.
It turns out that after the fix to T83196 (rB814b2787cadd) the matrix
to quaternion conversion can produce noncanonical results in large
areas of the rotation space, when previously this was limited to
way smaller areas. This in turn causes Swing+Twist math to produce
angles beyond 180 degrees, e.g. outputting a -120..240 range.

This fixes both issues, ensuring that conversion outputs a canonical
result, and decomposition canonifies its input.

This was reported in chat by @jpbouza.
2020-12-13 22:06:01 +03:00
c6075118d5 Cleanup: Reduce variable scope in view_2d_ops.c 2020-12-13 09:27:37 -06:00
4797c13e8f UI: Add more property editor operators to IC keymap
As a followup for rB2b3d85d7d6771, this commit adds the remove and
copy operators for grease pencil modifiers, effects, and constraints
where they apply.
2020-12-12 12:07:22 -06:00
57f900e4ef Fix T83705: GPencil - Duplicate strokes of destination layer when merge layer
If the destination layer hadn't keyframe, a new keyframe was added and later the merge layer strokes were added, but this could change the animation because the new frame replaced the old drawings of the target layer.

Now, before merge the layer, all keyframes are added in the target layer in order to keep the drawings.
2020-12-12 18:49:57 +01:00
3eb6649453 GPencil: Add uniform subdivide BKE to improve interpolation
This patch introduces a new BKE function that performs a uniform subdivide.

The goal of this function is to subdivide the stroke to reach a target number of points while maintaining its shape, color, and weights.
This is done by repeatedly subdividing the longest edge in the stroke. Every subdivision adds a new point at the exact middle point of an edge.

The function is intended to be used in the interpolation operators to give better results when interpolating between different sized strokes.

Reviewed By: antoniov

Differential Revision: https://developer.blender.org/D9835
2020-12-12 16:49:38 +01:00
ae94a390a7 Cleanup: clang tidy 2020-12-12 12:24:14 +01:00
0c1d476923 UI: Allow UI to pass focused data-block to operators via context
This is similar to c4a2067130130d, but applies to the general UI and is only
about single data-blocks. Here there was a similar problem: How can buttons
pass the data they represent to operators? We currently resort to ugly ad-hoc
solutions like `UI_context_active_but_get_tab_ID()`. So the operator would need
to know that it is executed on a tab button that represents a data-block.

A single button can now hand operators a data-block to operate on. The operator
can request it via the "id" context member (`CTX_data_pointer_get_type(C, "id",
&RNA_ID)` in C, `bpy.context.id` in .py).
In this commit, it is already set in the following places:
* Generic RNA button code sets it to the pointed to data-block, if the button
  represents a data-block RNA pointer property. (I.e for general data-block
  search buttons.)
* Data-block selectors (`templateID`) set it to the currently active data-block.
* The material slot UI-List sets it for each slot to the material it represents.
The button context menu code is modified so its operators use the context set
for the layout of its parent button (i.e. `layout.context_pointer_set()`).

No user visible changes. This new design isn't actually used yet. It will be
soon for asset operators.

Reviewed as part of https://developer.blender.org/D9717.
Reviewed by: Brecht Van Lommel
2020-12-11 23:08:29 +01:00
af008f5532 UI: Allow Outliners to pass selected data-blocks to operators via context
The way the Outliner integrates operations on selected tree elements is known
to be quite problematic amongst developers. The context menu is generated in an
unusual way and doesn't use the normal operator system. Instead, changes are
applied via a recursive callback system. Things are quite ad-hoc, and the
callbacks often implement logic that should not be in the Outliner, but in
entirely different modules. Often these modules already contain the logic, but
as proper operators.

This commit is a step into a hopefully better direction that should allow us to
put actual operators into Outliner context menus. It starts solving the problem
of: How can the Outliner pass selected data to operators. It implements it for
data-blocks only, but other data could do it in the same way.

Idea is to keep doing what operators were initially designed to do: Operate on
context.
Operators can now query a "selected_ids" context member
(`CTX_data_selected_ids()` in C, `bpy.context.selected_ids` in .py). If an
Outliner is active, it will generate a list of selected data-blocks as a
response, via its `SpaceType.context` callback.
Any other editor could do the same.

No user visible changes. This new design isn't actually used yet. It will be
soon for asset operators.

Reviewed as part of https://developer.blender.org/D9717.
Reviewed by: Brecht Van Lommel
2020-12-11 23:08:29 +01:00
ba83ad226d Fix error in recent commit
Introduced in rBcada56b1f72f537f9ab007cfafd430ac10c292fb
2020-12-11 17:54:27 -03:00
0dbbcaf1e6 Fix: Fix potential memory leak in BLI_getenv
Issue introduced in rB87b19b3aba0c and unlikely to occur
but no reason not to have correct code.
2020-12-11 12:09:18 -07:00
bbd7f94d8a Cleanup: Python GPU: change prefix 'bpygpu_' to 'py_' in static functions 2020-12-11 16:06:22 -03:00
cada56b1f7 Cleanup: GPU Python: Use 'PyC_ParseStringEnum' for string enum 2020-12-11 16:06:22 -03:00
87b19b3aba Fix: BLI_getenv returns ascii not UTF8 on windows
BLI_getenv has always incorrectly returned ascii rather
than UTF-8. This change corrects this behaviour.

This resolves issues when the `BLENDER_USER_CONFIG`
environment variable contains a path with Unicode characters
on windows as reported in T74510 (but unlikely the root
cause for the issue at hand there)

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

Reviewed by: brecht
2020-12-11 11:59:14 -07:00
92ab76c38f Cleanup: clang-format
Forgot to run Make Format on recent spelling changes
2020-12-11 10:48:30 -08:00
Valdemar Lindberg
93c67b0b8e Fix T83586: Cycles failing to load OpenEXR image with EXR RGBAZ channels
Don't refuse to load 5-channel images, instead drop any channels after the 4th
and hope that the first channels represent RGBA.

Differential Revision: https://developer.blender.org/D9820
2020-12-11 19:36:09 +01:00
97651f428b Fix T83050: Crash dragging shared collection to master collection
The flag syncing code expects to find collection flags in same view
layer before and after the move, it even has an assert for it. However,
there is one case where this doesn't happen, when dragging a collection
that exists in two scenes to the master collection.

This commit removes this assert, frees the temporary flag structs
separately, and updates some comments with this information.
There is more detail in the adjusted comment.

Differential Revision: https://developer.blender.org/D9785
2020-12-11 12:15:51 -06:00
b73ed882c0 Cleanup: clang tidy 2020-12-11 19:02:46 +01:00
cef5d0923b Readme file to extern libraries about the attribution document 2020-12-11 18:53:22 +01:00
561d9169fe Fix T83280: Crash when deleting hair collision collection.
Root of the issue was missing management of ID pointers in the cloth
modifier data stored in ParticleSystem for hair physics, in the
'foreach_id' particle system code.

Using modifier's 'foreach_id' code in psys one unfortunately requires
some ugly conversion gymnastics, but this is still better than having
dedicated code for that case.

Note that this is actually a fairly critical issue, fix should be
backported to 2.91.1 should we do it, and to 2.83 LTS as well I think.
2020-12-11 18:46:21 +01:00
85cb238820 Licenses: Attribution document
This document helps Blender users to known what is the library of each
individual 3rd party components that Blender depend on.

Generated using:
https://github.com/amzn/oss-attribution-builder

This is based on the libraries in extern and the svn libraries.

For the libraries in extern the README.blender was used as reference.
For the libraries in svn I used `cmake/versions.cmake`.

Note that the crediting is a bit of hit and miss. For some projects this
is very clear, while for others I had to do some digging. Either way I
gave my best shot.

The sources to (re-)generate this file is local at the moment. But it
should be moved to our infra-structure at some point.

Differential Revision: https://developer.blender.org/D9798
2020-12-11 18:44:11 +01:00
f5dc34ec9c Geometry Nodes: support instancing collections
The Point Instance node can instance entire collections now.
Before, only individual collections were supported.

Randomly selecting objects from the collection on a per point basis
is not support, yet.

Last part of D9739.

Ref T82372.
2020-12-11 18:00:37 +01:00
5ced167336 Geometry Nodes: support collection sockets
Part of D9739.
2020-12-11 17:47:58 +01:00
4885fbc07b Nodes: add Collection socket type
The implementation is pretty much the same as for Object sockets.
The socket color is the one that is used for collections in the outliner.

Part of D9739.
2020-12-11 17:38:32 +01:00
f762d37790 Cycles: enable OpenCL rendering on recent Intel GPUs
Based on testing by Intel, rendering on Iris GPUs and upcoming Xe GPUs
should work. This is enabled on Windows and Linux.

More testing is needed to verify correctness and performance in production
scenes, but our basic benchmark files seem to give correct results.
2020-12-11 17:37:54 +01:00
c6626a2f8a Cleanup: compiler warnings
If you mark one function as override in a class, all must be marked.
2020-12-11 17:37:31 +01:00
Yevgeny Makarov
f7069d71aa Trackpad: Fix wrong scroll deltas on Retina
Scale Mac trackpad scrolling changes by pixel size of output device.

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

Reviewed by Brecht Van Lommel
2020-12-11 08:28:56 -08:00
Yevgeny Makarov
badbf816b8 UI: Consistent Range Descriptions
Unifying range descriptions as a value 'to' a value.

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

Reviewed by Julian Eisel
2020-12-11 07:35:44 -08:00
273aca964e Refactor/extend BKE API to get special user directories
The previous `BKE_appdir_folder_default()` was confusing, it would return the
home directory on Linux and macOS, but the Documents directory on Windows.
Plus, for the Asset Browser, we want to use the Documents directory for the
default asset library on all platforms.
This attempts to clean up the API to avoid confusion, while adding the newly
needed functionality.

* `BKE_appdir_folder_default()` should behave as before, but the implementation
  changed:
** Removes apparently incorrect usage of `XDG_DOCUMENTS_DIR` on Unix systems -
   this seems to be a config file variable, not an environment variable. Always
   use `$HOME` instead, which this ended up using anyway.
** On Windows it doesn't attempt to use `%HOME%` anymore and gets the Documents
   directory directly.
* Add `BKE_appdir_folder_home()` to gives the top-level user directory on all
  platforms.
* Add `BKE_appdir_folder_documents()` to always get the user documents
  directory on all platforms.

There should be no user noticable behavior change.

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

Reviewed by: Brecht Van Lommel
2020-12-11 16:20:53 +01:00
6de85a0cc0 Ghost: Support queries for special user directories (desktop, documents, etc.)
When we had to get special user directories, we'd usually do it in varying,
rather ad-hoc ways. It would be done with a bunch of `#ifdef`s for the
different operating systems. Also, some of the used Win32 functions were legacy
ones and the API docs recommend using newer ones.
Further, seems `BKE_appdir_folder_default()` used `XDG_DOCUMENTS_DIR` wrong.
It's not supposed to be an environment variable but a value inside a config
file.

This adds the platform dependent logic to Ghost, so we can abstract it away
nicely using the `GHOST_ISystemPaths` interface. Getting the desktop directory
for example can now easily be done with:
`GHOST_getUserSpecialDir(GHOST_kUserSpecialDirDesktop).`

For now I added the logic for desktop, documents, downloads, videos, images and
music directories, even though we only use the Documents one. We can extend/
change this as needed, it's easy to do now.
On Windows and macOS, it uses pretty much the same way to access the
directories as elsewhere already. On Linux, it uses the `xdg-user-dir` command
that seems to be available by default on most Linux systems.

No functional changes. The new queries are not actually used yet.

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

Reviewed by: Brecht Van Lommel
2020-12-11 16:20:53 +01:00
c8a3d1a1fa GPencil: Add Link support to Effects using Ctrl+L
The effects were not supported in this operator, but it was supported in the Outliner.

Differential Revision: https://developer.blender.org/D9824
2020-12-11 15:53:22 +01:00
727d5013a7 Fix T82881: Paint mask 'deselect on nothing' missed viewport update
Was failing for weightpaint and vertexpaint.

Selection flags were actually changed, but the update in the viewport
wasnt immediate, leading to confusion when the update happened later
(e.g. when using the weight gradient tool as done in the report).

We need to tag ID_RECALC_SELECT and send ND_SELECT notifier here. This
could be done explicitly, but there is also existing functionality
available that does this.
Note: the way updates happen for paintfaces vs. paintverts looks a bit
inconsistent (so this could be part of a later cleanup commit)

Maniphest Tasks: T82881

Differential Revision: https://developer.blender.org/D9631
2020-12-11 15:32:31 +01:00
7c8e01341f UI: Correct help text in the Parent panel
Tracking Axis and Up Axis were still referring to duplis (DupliFrame) - changed it to be in line with Aaron's info about them in our manual
2020-12-11 14:11:17 +01:00
bfb6fce659 Cycles: Add CPU+GPU rendering support with OptiX
Adds support for building multiple BVH types in order to support using both CPU and OptiX
devices for rendering simultaneously. Primitive packing for Embree and OptiX is now
standalone, so it only needs to be run once and can be shared between the two. Additionally,
BVH building was made a device call, so that each device backend can decide how to
perform the building. The multi-device for instance creates a special multi-BVH that holds
references to several sub-BVHs, one for each sub-device.

Reviewed By: brecht, kevindietrich

Differential Revision: https://developer.blender.org/D9718
2020-12-11 13:24:29 +01:00
d72ec16e70 Geometry Nodes: add Attribute Mix node
This node can be used to mix two attributes in various ways.
The blend modes are the same as in the MixRGB shader node.

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

Ref T82374.
2020-12-11 12:00:48 +01:00
150a1d158a Cleanup: remove some forward declared enums
Forward declaring enums are not allowed in C++.

Differential Revision: https://developer.blender.org/D9811
2020-12-11 11:48:58 +01:00
f5c7246717 Fix wrong operator return values in Outliner code.
Mistakes in rBac8b641b77e0 and rBf254f66587f2.

Spotted while inverstigating T83592.
2020-12-11 11:05:28 +01:00
f7e5f96f56 GeometryNodes: Make properties exposed in modifier overridable. 2020-12-11 10:53:08 +01:00
b62a9ef66f Cleanup: Fix typo in comment. 2020-12-11 10:53:08 +01:00
Evan Wilson
6e4fccd9fa Correct the order of the last two arguments in eevee_cryptomatte_shading_group_create
When compiling on Windows, the following warnings occur:
```[3468/4560] Building C object source\blender\draw\CMakeFiles\bf_draw.dir\engines\eevee\eevee_cryptomatte.c.obj
C:\blender-git\blender\source\blender\draw\engines\eevee\eevee_cryptomatte.c(306): warning C4047: 'function': 'bool' differs in levels of indirection from 'void *'
C:\blender-git\blender\source\blender\draw\engines\eevee\eevee_cryptomatte.c(306): warning C4024: 'eevee_cryptomatte_shading_group_create': different types for formal and actual parameter 5```

As @Severin pointed out [here](https://developer.blender.org/rB76a0b322e4d3244e59a154c8255b84a4fbc33117#288960), this is due to the last two arguments being flipped.  This diff corrects the order.

Reviewed By: Severin, fclem

Differential Revision: https://developer.blender.org/D9809
2020-12-11 08:45:05 +01:00
219dba8506 Workaround T83651: Crash dragging multiple buttons in the clip editor
Avoid the crash, dragging multiple buttons still needs fixing.
2020-12-11 15:32:14 +11:00
392a8e2907 Cleanup: sort cmake file lists 2020-12-11 15:32:14 +11:00
8cc951d2ae Cleanup: trailing space 2020-12-11 15:32:14 +11:00
ff6d7e9072 Cleanup: spelling, expand on FCurve.rna_path docstring 2020-12-11 15:32:14 +11:00
Yevgeny Makarov
a4a42f3171 UI: Use 'and' Instead of '&' in Descriptions
Use 'and' instead of ampersand in descriptions and comments.

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

Reviewed by Aaron Carlisle
2020-12-10 18:22:16 -08:00
caed4849d0 Fix T83640: No immediate updates when changing the settings of a just-
duplicated particle system

When particle settings are duplicated along with the particle system,
this means a change in relations, was missing
'DEG_relations_tag_update'.

Maniphest Tasks: T83640

Differential Revision: https://developer.blender.org/D9823
2020-12-10 22:48:47 +01:00
a7fcca1062 UI: Use words instead of symbols for float comparison items
Though they are nice and concise, users should not be expected to know
the meaning of symbols like `!=`.
2020-12-10 11:07:26 -06:00
8bdd996cd0 Geometry Nodes: Add helper function to check if attribute exists 2020-12-10 10:50:37 -06:00
3d25312617 Nodes: fix incorrectly parameter name and type
The parameter type was incorrectly changed in rB6be56c13e96048cbc494ba5473a8deaf2cf5a6f8 by me.
This can be any id and does not have to be a node tree.
2020-12-10 16:15:28 +01:00
1d447dcd19 Fix T83630 Exact Boolean assert failure in Debug build.
I thought I had reasoned that the add_patch would only happen
when the patch was not already in a cell, but I missed reasoning
about merged cells. So switched to a set 'add' instead of 'add_new'.
2020-12-10 09:15:16 -05:00
1104 changed files with 36027 additions and 14727 deletions

View File

@@ -347,16 +347,21 @@ if(UNIX AND NOT APPLE)
endif()
option(WITH_PYTHON_INSTALL "Copy system python into the blender install folder" ON)
if((WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE) OR WITH_MOD_FLUID)
option(WITH_PYTHON_NUMPY "Include NumPy in Blender (used by Audaspace and Mantaflow)" ON)
endif()
if(WIN32 OR APPLE)
# Windows and macOS have this bundled with Python libraries.
elseif(WITH_PYTHON_INSTALL OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
elseif(WITH_PYTHON_INSTALL OR WITH_PYTHON_NUMPY)
set(PYTHON_NUMPY_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
mark_as_advanced(PYTHON_NUMPY_PATH)
set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
set(PYTHON_NUMPY_INCLUDE_DIRS "" CACHE PATH "Path to the include directory of the NumPy module")
mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
endif()
if(WITH_PYTHON_INSTALL)
option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder" ON)
option(WITH_PYTHON_INSTALL_NUMPY "Copy system NumPy into the blender install folder" ON)
if(UNIX AND NOT APPLE)
option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
@@ -605,6 +610,11 @@ if(WIN32)
endif()
if(UNIX)
# See WITH_WINDOWS_SCCACHE for Windows.
option(WITH_COMPILER_CCACHE "Use ccache to improve rebuild times (Works with Ninja, Makefiles and Xcode)" OFF)
endif()
# The following only works with the Ninja generator in CMake >= 3.0.
if("${CMAKE_GENERATOR}" MATCHES "Ninja")
option(WITH_NINJA_POOL_JOBS
@@ -1621,19 +1631,16 @@ if(WITH_PYTHON)
if(WIN32 OR APPLE)
# Windows and macOS have this bundled with Python libraries.
elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR WITH_PYTHON_NUMPY)
if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
find_python_package(numpy)
unset(PYTHON_NUMPY_INCLUDE_DIRS CACHE)
set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
find_python_package(numpy "core/include")
endif()
endif()
if(WIN32 OR APPLE)
# pass, we have this in lib/python/site-packages
elseif(WITH_PYTHON_INSTALL_REQUESTS)
find_python_package(requests)
find_python_package(requests "")
endif()
endif()
@@ -1766,6 +1773,10 @@ elseif(WITH_CYCLES_STANDALONE)
endif()
endif()
#-----------------------------------------------------------------------------
# Testing
add_subdirectory(tests)
#-----------------------------------------------------------------------------
# Blender Application
if(WITH_BLENDER)
@@ -1773,11 +1784,6 @@ if(WITH_BLENDER)
endif()
#-----------------------------------------------------------------------------
# Testing
add_subdirectory(tests)
#-----------------------------------------------------------------------------
# Define 'heavy' submodules (for Ninja builder when using pools).
setup_heavy_lib_pool()

View File

@@ -41,6 +41,7 @@ Convenience Targets
* developer: Enable faster builds, error checking and tests, recommended for developers.
* config: Run cmake configuration tool to set build options.
* ninja: Use ninja build tool for faster builds.
* ccache: Use ccache for faster rebuilds.
Note: passing the argument 'BUILD_DIR=path' when calling make will override the default build dir.
Note: passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments.
@@ -241,6 +242,10 @@ ifneq "$(findstring developer, $(MAKECMDGOALS))" ""
CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_developer.cmake" $(CMAKE_CONFIG_ARGS)
endif
ifneq "$(findstring ccache, $(MAKECMDGOALS))" ""
CMAKE_CONFIG_ARGS:=-DWITH_COMPILER_CCACHE=YES $(CMAKE_CONFIG_ARGS)
endif
# -----------------------------------------------------------------------------
# build tool
@@ -340,6 +345,7 @@ headless: all
bpy: all
developer: all
ninja: all
ccache: all
# -----------------------------------------------------------------------------
# Build dependencies

View File

@@ -2086,7 +2086,7 @@ compile_OIIO() {
cmake_d="$cmake_d -D USE_OPENCV=OFF"
cmake_d="$cmake_d -D BUILD_TESTING=OFF"
cmake_d="$cmake_d -D OIIO_BUILD_TESTS=OFF"
cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=OFF"
cmake_d="$cmake_d -D OIIO_BUILD_TOOLS=ON"
cmake_d="$cmake_d -D TXT2MAN="
#cmake_d="$cmake_d -D CMAKE_EXPORT_COMPILE_COMMANDS=ON"
#cmake_d="$cmake_d -D CMAKE_VERBOSE_MAKEFILE=ON"
@@ -4072,7 +4072,7 @@ install_DEB() {
else
check_package_version_ge_lt_DEB libopenimageio-dev $OIIO_VERSION_MIN $OIIO_VERSION_MAX
if [ $? -eq 0 -a "$_with_built_openexr" = false ]; then
install_packages_DEB libopenimageio-dev
install_packages_DEB libopenimageio-dev openimageio-tools
clean_OIIO
else
compile_OIIO
@@ -4714,13 +4714,13 @@ install_RPM() {
INFO "Forced OpenImageIO building, as requested..."
compile_OIIO
else
#check_package_version_ge_lt_RPM OpenImageIO-devel $OIIO_VERSION_MIN $OIIO_VERSION_MAX
#if [ $? -eq 0 -a $_with_built_openexr == false ]; then
# install_packages_RPM OpenImageIO-devel
# clean_OIIO
#else
check_package_version_ge_lt_RPM OpenImageIO-devel $OIIO_VERSION_MIN $OIIO_VERSION_MAX
if [ $? -eq 0 -a $_with_built_openexr == false ]; then
install_packages_RPM OpenImageIO-devel OpenImageIO-utils
clean_OIIO
else
compile_OIIO
#fi
fi
fi

View File

@@ -330,6 +330,9 @@ function(gtest_add_tests)
set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+) *, *([A-Za-z_0-9]+) *\\).*")
set(gtest_test_type_regex "(TYPED_TEST|TEST_?[FP]?)")
# This will get a filter for each test suite.
set(test_filters "")
foreach(source IN LISTS ARGS_SOURCES)
if(NOT ARGS_SKIP_DEPENDENCY)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source})
@@ -376,175 +379,32 @@ function(gtest_add_tests)
list(APPEND testList ${ctest_test_name})
endif()
else()
set(ctest_test_name ${ARGS_TEST_PREFIX}${gtest_test_name}${ARGS_TEST_SUFFIX})
add_test(NAME ${ctest_test_name}
${workDir}
COMMAND ${ARGS_TARGET}
--gtest_filter=${gtest_test_name}
${ARGS_EXTRA_ARGS}
)
list(APPEND testList ${ctest_test_name})
# BLENDER: collect tests named "suite.testcase" as list of "suite.*" filters.
string(REGEX REPLACE "\\..*$" "" gtest_suite_name ${gtest_test_name})
list(APPEND test_filters "${gtest_suite_name}.*")
endif()
endforeach()
endforeach()
# Join all found GTest suite names into one big filter.
list(REMOVE_DUPLICATES test_filters)
list(JOIN test_filters ":" gtest_filter)
add_test(NAME ${ARGS_TEST_PREFIX}
${workDir}
COMMAND ${ARGS_TARGET}
--gtest_filter=${gtest_filter}
${ARGS_EXTRA_ARGS}
)
list(APPEND testList ${ARGS_TEST_PREFIX})
if(ARGS_TEST_LIST)
set(${ARGS_TEST_LIST} ${testList} PARENT_SCOPE)
endif()
endfunction()
#------------------------------------------------------------------------------
function(gtest_discover_tests TARGET)
cmake_parse_arguments(
""
"NO_PRETTY_TYPES;NO_PRETTY_VALUES"
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;DISCOVERY_TIMEOUT;XML_OUTPUT_DIR;DISCOVERY_MODE"
"EXTRA_ARGS;PROPERTIES"
${ARGN}
)
if(NOT _WORKING_DIRECTORY)
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(NOT _TEST_LIST)
set(_TEST_LIST ${TARGET}_TESTS)
endif()
if(NOT _DISCOVERY_TIMEOUT)
set(_DISCOVERY_TIMEOUT 5)
endif()
if(NOT _DISCOVERY_MODE)
if(NOT CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE)
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "POST_BUILD")
endif()
set(_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE})
endif()
get_property(
has_counter
TARGET ${TARGET}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
SET
)
if(has_counter)
get_property(
counter
TARGET ${TARGET}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
)
math(EXPR counter "${counter} + 1")
else()
set(counter 1)
endif()
set_property(
TARGET ${TARGET}
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
${counter}
)
# Define rule to generate test list for aforementioned test executable
# Blender: use _ instead of [] to avoid problems with zsh regex.
set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_${counter}_")
set(ctest_include_file "${ctest_file_base}_include.cmake")
set(ctest_tests_file "${ctest_file_base}_tests.cmake")
get_property(crosscompiling_emulator
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR
)
if(_DISCOVERY_MODE STREQUAL "POST_BUILD")
add_custom_command(
TARGET ${TARGET} POST_BUILD
BYPRODUCTS "${ctest_tests_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TARGET=${TARGET}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
-D "TEST_PROPERTIES=${_PROPERTIES}"
-D "TEST_PREFIX=${_TEST_PREFIX}"
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
-D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}"
-D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}"
-D "TEST_LIST=${_TEST_LIST}"
-D "CTEST_FILE=${ctest_tests_file}"
-D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}"
-D "TEST_XML_OUTPUT_DIR=${_XML_OUTPUT_DIR}"
-P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}"
VERBATIM
)
file(WRITE "${ctest_include_file}"
"if(EXISTS \"${ctest_tests_file}\")\n"
" include(\"${ctest_tests_file}\")\n"
"else()\n"
" add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n"
"endif()\n"
)
elseif(_DISCOVERY_MODE STREQUAL "PRE_TEST")
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL
PROPERTY GENERATOR_IS_MULTI_CONFIG
)
if(GENERATOR_IS_MULTI_CONFIG)
set(ctest_tests_file "${ctest_file_base}_tests-$<CONFIG>.cmake")
endif()
string(CONCAT ctest_include_content
"if(EXISTS \"$<TARGET_FILE:${TARGET}>\")" "\n"
" if(\"$<TARGET_FILE:${TARGET}>\" IS_NEWER_THAN \"${ctest_tests_file}\")" "\n"
" include(\"${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}\")" "\n"
" gtest_discover_tests_impl(" "\n"
" TEST_EXECUTABLE" " [==[" "$<TARGET_FILE:${TARGET}>" "]==]" "\n"
" TEST_EXECUTOR" " [==[" "${crosscompiling_emulator}" "]==]" "\n"
" TEST_WORKING_DIR" " [==[" "${_WORKING_DIRECTORY}" "]==]" "\n"
" TEST_EXTRA_ARGS" " [==[" "${_EXTRA_ARGS}" "]==]" "\n"
" TEST_PROPERTIES" " [==[" "${_PROPERTIES}" "]==]" "\n"
" TEST_PREFIX" " [==[" "${_TEST_PREFIX}" "]==]" "\n"
" TEST_SUFFIX" " [==[" "${_TEST_SUFFIX}" "]==]" "\n"
" NO_PRETTY_TYPES" " [==[" "${_NO_PRETTY_TYPES}" "]==]" "\n"
" NO_PRETTY_VALUES" " [==[" "${_NO_PRETTY_VALUES}" "]==]" "\n"
" TEST_LIST" " [==[" "${_TEST_LIST}" "]==]" "\n"
" CTEST_FILE" " [==[" "${ctest_tests_file}" "]==]" "\n"
" TEST_DISCOVERY_TIMEOUT" " [==[" "${_DISCOVERY_TIMEOUT}" "]==]" "\n"
" TEST_XML_OUTPUT_DIR" " [==[" "${_XML_OUTPUT_DIR}" "]==]" "\n"
" )" "\n"
" endif()" "\n"
" include(\"${ctest_tests_file}\")" "\n"
"else()" "\n"
" add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)" "\n"
"endif()" "\n"
)
if(GENERATOR_IS_MULTI_CONFIG)
foreach(_config ${CMAKE_CONFIGURATION_TYPES})
file(GENERATE OUTPUT "${ctest_file_base}_include-${_config}.cmake" CONTENT "${ctest_include_content}" CONDITION $<CONFIG:${_config}>)
endforeach()
file(WRITE "${ctest_include_file}" "include(\"${ctest_file_base}_include-\${CTEST_CONFIGURATION_TYPE}.cmake\")")
else()
file(GENERATE OUTPUT "${ctest_file_base}_include.cmake" CONTENT "${ctest_include_content}")
file(WRITE "${ctest_include_file}" "include(\"${ctest_file_base}_include.cmake\")")
endif()
else()
message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}")
endif()
# Add discovered tests to directory TEST_INCLUDE_FILES
set_property(DIRECTORY
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
)
endfunction()
###############################################################################
set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT
${CMAKE_CURRENT_LIST_DIR}/GTestAddTests.cmake
)
# BLENDER: remove the discovery function gtest_discover_tests(). It's not used,
# as it generates too many test invocations.
# Restore project's policies
cmake_policy(POP)

View File

@@ -1,194 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License,
# see accompanying file BSD-3-Clause-license.txt for details.
# Changes made to this script have been marked with "BLENDER".
# BLENDER: disable ASAN leak detection when trying to discover tests.
set(ENV{ASAN_OPTIONS} "detect_leaks=0")
cmake_minimum_required(VERSION ${CMAKE_VERSION})
# Overwrite possibly existing ${_CTEST_FILE} with empty file
set(flush_tests_MODE WRITE)
# Flushes script to ${_CTEST_FILE}
macro(flush_script)
file(${flush_tests_MODE} "${_CTEST_FILE}" "${script}")
set(flush_tests_MODE APPEND)
set(script "")
endmacro()
# Flushes tests_buffer to tests
macro(flush_tests_buffer)
list(APPEND tests "${tests_buffer}")
set(tests_buffer "")
endmacro()
macro(add_command NAME)
set(_args "")
foreach(_arg ${ARGN})
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
string(APPEND _args " [==[${_arg}]==]")
else()
string(APPEND _args " ${_arg}")
endif()
endforeach()
string(APPEND script "${NAME}(${_args})\n")
string(LENGTH "${script}" _script_len)
if(${_script_len} GREATER "50000")
flush_script()
endif()
# Unsets macro local variables to prevent leakage outside of this macro.
unset(_args)
unset(_script_len)
endmacro()
function(gtest_discover_tests_impl)
cmake_parse_arguments(
""
""
"NO_PRETTY_TYPES;NO_PRETTY_VALUES;TEST_EXECUTABLE;TEST_EXECUTOR;TEST_WORKING_DIR;TEST_PREFIX;TEST_SUFFIX;TEST_LIST;CTEST_FILE;TEST_DISCOVERY_TIMEOUT;TEST_XML_OUTPUT_DIR"
"TEST_EXTRA_ARGS;TEST_PROPERTIES"
${ARGN}
)
set(prefix "${_TEST_PREFIX}")
set(suffix "${_TEST_SUFFIX}")
set(extra_args ${_TEST_EXTRA_ARGS})
set(properties ${_TEST_PROPERTIES})
set(script)
set(suite)
set(tests)
set(tests_buffer)
# Run test executable to get list of available tests
if(NOT EXISTS "${_TEST_EXECUTABLE}")
message(FATAL_ERROR
"Specified test executable does not exist.\n"
" Path: '${_TEST_EXECUTABLE}'"
)
endif()
execute_process(
COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" --gtest_list_tests
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
TIMEOUT ${_TEST_DISCOVERY_TIMEOUT}
OUTPUT_VARIABLE output
RESULT_VARIABLE result
)
if(NOT ${result} EQUAL 0)
string(REPLACE "\n" "\n " output "${output}")
message(FATAL_ERROR
"Error running test executable.\n"
" Path: '${_TEST_EXECUTABLE}'\n"
" Result: ${result}\n"
" Output:\n"
" ${output}\n"
)
endif()
# Preserve semicolon in test-parameters
string(REPLACE [[;]] [[\;]] output "${output}")
string(REPLACE "\n" ";" output "${output}")
# Parse output
foreach(line ${output})
# Skip header
if(NOT line MATCHES "gtest_main\\.cc")
# Do we have a module name or a test name?
if(NOT line MATCHES "^ ")
# Module; remove trailing '.' to get just the name...
string(REGEX REPLACE "\\.( *#.*)?" "" suite "${line}")
if(line MATCHES "#" AND NOT _NO_PRETTY_TYPES)
string(REGEX REPLACE "/[0-9]\\.+ +#.*= +" "/" pretty_suite "${line}")
else()
set(pretty_suite "${suite}")
endif()
string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}")
else()
# Test name; strip spaces and comments to get just the name...
string(REGEX REPLACE " +" "" test "${line}")
if(test MATCHES "#" AND NOT _NO_PRETTY_VALUES)
string(REGEX REPLACE "/[0-9]+#GetParam..=" "/" pretty_test "${test}")
else()
string(REGEX REPLACE "#.*" "" pretty_test "${test}")
endif()
string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}")
string(REGEX REPLACE "#.*" "" test "${test}")
if(NOT "${_TEST_XML_OUTPUT_DIR}" STREQUAL "")
set(TEST_XML_OUTPUT_PARAM "--gtest_output=xml:${_TEST_XML_OUTPUT_DIR}/${prefix}${suite}.${test}${suffix}.xml")
else()
unset(TEST_XML_OUTPUT_PARAM)
endif()
# sanitize test name for further processing downstream
set(testname "${prefix}${pretty_suite}.${pretty_test}${suffix}")
# escape \
string(REPLACE [[\]] [[\\]] testname "${testname}")
# escape ;
string(REPLACE [[;]] [[\;]] testname "${testname}")
# escape $
string(REPLACE [[$]] [[\$]] testname "${testname}")
# ...and add to script
add_command(add_test
"${testname}"
${_TEST_EXECUTOR}
"${_TEST_EXECUTABLE}"
"--gtest_filter=${suite}.${test}"
"--gtest_also_run_disabled_tests"
${TEST_XML_OUTPUT_PARAM}
${extra_args}
)
if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED")
add_command(set_tests_properties
"${testname}"
PROPERTIES DISABLED TRUE
)
endif()
add_command(set_tests_properties
"${testname}"
PROPERTIES
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
SKIP_REGULAR_EXPRESSION "\\\\[ SKIPPED \\\\]"
${properties}
)
list(APPEND tests_buffer "${testname}")
list(LENGTH tests_buffer tests_buffer_length)
if(${tests_buffer_length} GREATER "250")
flush_tests_buffer()
endif()
endif()
endif()
endforeach()
# Create a list of all discovered tests, which users may use to e.g. set
# properties on the tests
flush_tests_buffer()
add_command(set ${_TEST_LIST} ${tests})
# Write CTest script
flush_script()
endfunction()
if(CMAKE_SCRIPT_MODE_FILE)
gtest_discover_tests_impl(
NO_PRETTY_TYPES ${NO_PRETTY_TYPES}
NO_PRETTY_VALUES ${NO_PRETTY_VALUES}
TEST_EXECUTABLE ${TEST_EXECUTABLE}
TEST_EXECUTOR ${TEST_EXECUTOR}
TEST_WORKING_DIR ${TEST_WORKING_DIR}
TEST_PREFIX ${TEST_PREFIX}
TEST_SUFFIX ${TEST_SUFFIX}
TEST_LIST ${TEST_LIST}
CTEST_FILE ${CTEST_FILE}
TEST_DISCOVERY_TIMEOUT ${TEST_DISCOVERY_TIMEOUT}
TEST_XML_OUTPUT_DIR ${TEST_XML_OUTPUT_DIR}
TEST_EXTRA_ARGS ${TEST_EXTRA_ARGS}
TEST_PROPERTIES ${TEST_PROPERTIES}
)
endif()

View File

@@ -8,6 +8,17 @@
#
#=============================================================================
function(GET_BLENDER_TEST_INSTALL_DIR VARIABLE_NAME)
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(GENERATOR_IS_MULTI_CONFIG)
string(REPLACE "\${BUILD_TYPE}" "$<CONFIG>" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
else()
string(REPLACE "\${BUILD_TYPE}" "" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif()
set(${VARIABLE_NAME} "${TEST_INSTALL_DIR}" PARENT_SCOPE)
endfunction()
macro(BLENDER_SRC_GTEST_EX)
if(WITH_GTESTS)
set(options SKIP_ADD_TEST)
@@ -75,13 +86,7 @@ macro(BLENDER_SRC_GTEST_EX)
target_link_libraries(${TARGET_NAME} ${GMP_LIBRARIES})
endif()
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(GENERATOR_IS_MULTI_CONFIG)
string(REPLACE "\${BUILD_TYPE}" "$<CONFIG>" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
else()
string(REPLACE "\${BUILD_TYPE}" "" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif()
GET_BLENDER_TEST_INSTALL_DIR(TEST_INSTALL_DIR)
set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${TESTS_OUTPUT_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"

View File

@@ -13,7 +13,7 @@ Invocation:
export CLANG_BIND_DIR="/dsk/src/llvm/tools/clang/bindings/python"
export CLANG_LIB_DIR="/opt/llvm/lib"
python2 clang_array_check.py somefile.c -DSOME_DEFINE -I/some/include
python clang_array_check.py somefile.c -DSOME_DEFINE -I/some/include
... defines and includes are optional
@@ -76,6 +76,32 @@ defs_precalc = {
"glNormal3bv": {0: 3},
"glNormal3iv": {0: 3},
"glNormal3sv": {0: 3},
# GPU immediate mode.
"immVertex2iv": {1: 2},
"immVertex2fv": {1: 2},
"immVertex3fv": {1: 3},
"immAttr2fv": {1: 2},
"immAttr3fv": {1: 3},
"immAttr4fv": {1: 4},
"immAttr3ubv": {1: 3},
"immAttr4ubv": {1: 4},
"immUniform2fv": {1: 2},
"immUniform3fv": {1: 3},
"immUniform4fv": {1: 4},
"immUniformColor3fv": {0: 3},
"immUniformColor4fv": {0: 4},
"immUniformColor3ubv": {1: 3},
"immUniformColor4ubv": {1: 4},
"immUniformColor3fvAlpha": {0: 3},
"immUniformColor4fvAlpha": {0: 4},
}
# -----------------------------------------------------------------------------
@@ -100,7 +126,8 @@ else:
if CLANG_LIB_DIR is None:
print("$CLANG_LIB_DIR clang lib dir not set")
sys.path.append(CLANG_BIND_DIR)
if CLANG_BIND_DIR:
sys.path.append(CLANG_BIND_DIR)
import clang
import clang.cindex
@@ -108,7 +135,8 @@ from clang.cindex import (CursorKind,
TypeKind,
TokenKind)
clang.cindex.Config.set_library_path(CLANG_LIB_DIR)
if CLANG_LIB_DIR:
clang.cindex.Config.set_library_path(CLANG_LIB_DIR)
index = clang.cindex.Index.create()

View File

@@ -32,7 +32,7 @@ CHECKER_IGNORE_PREFIX = [
"intern/moto",
]
CHECKER_BIN = "python2"
CHECKER_BIN = "python3"
CHECKER_ARGS = [
os.path.join(os.path.dirname(__file__), "clang_array_check.py"),

View File

@@ -388,6 +388,43 @@ function(blender_add_lib
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
endfunction()
function(blender_add_test_suite)
if (ARGC LESS 1)
message(FATAL_ERROR "No arguments supplied to blender_add_test_suite()")
endif()
# Parse the arguments
set(oneValueArgs TARGET SUITE_NAME)
set(multiValueArgs SOURCES)
cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Figure out the release dir, as some tests need files from there.
GET_BLENDER_TEST_INSTALL_DIR(TEST_INSTALL_DIR)
if(APPLE)
set(_test_release_dir ${TEST_INSTALL_DIR}/Blender.app/Contents/Resources/${BLENDER_VERSION})
else()
if(WIN32 OR WITH_INSTALL_PORTABLE)
set(_test_release_dir ${TEST_INSTALL_DIR}/${BLENDER_VERSION})
else()
set(_test_release_dir ${TEST_INSTALL_DIR}/share/blender/${BLENDER_VERSION})
endif()
endif()
# Define a test case with our custom gtest_add_tests() command.
include(GTest)
gtest_add_tests(
TARGET ${ARGS_TARGET}
SOURCES "${ARGS_SOURCES}"
TEST_PREFIX ${ARGS_SUITE_NAME}
WORKING_DIRECTORY "${TEST_INSTALL_DIR}"
EXTRA_ARGS
--test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests"
--test-release-dir "${_test_release_dir}"
)
unset(_test_release_dir)
endfunction()
# Add tests for a Blender library, to be called in tandem with blender_add_lib().
# The tests will be part of the blender_test executable (see tests/gtests/runner).
function(blender_add_test_lib
@@ -421,6 +458,12 @@ function(blender_add_test_lib
blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}" "${library_deps}")
set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name})
blender_add_test_suite(
TARGET blender_test
SUITE_NAME ${name}
SOURCES "${sources}"
)
endfunction()
@@ -454,14 +497,10 @@ function(blender_add_test_executable
SKIP_ADD_TEST
)
include(GTest)
set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT
${CMAKE_SOURCE_DIR}/build_files/cmake/Modules/GTestAddTests.cmake
)
gtest_discover_tests(${name}_test
DISCOVERY_MODE PRE_TEST
WORKING_DIRECTORY "${TEST_INSTALL_DIR}"
blender_add_test_suite(
TARGET ${name}_test
SUITE_NAME ${name}
SOURCES "${sources}"
)
endfunction()
@@ -1139,6 +1178,7 @@ endfunction()
function(find_python_package
package
relative_include_dir
)
string(TOUPPER ${package} _upper_package)
@@ -1170,7 +1210,10 @@ function(find_python_package
dist-packages
vendor-packages
NO_DEFAULT_PATH
DOC
"Path to python site-packages or dist-packages containing '${package}' module"
)
mark_as_advanced(PYTHON_${_upper_package}_PATH)
if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
message(WARNING
@@ -1188,6 +1231,50 @@ function(find_python_package
set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
else()
message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
if(NOT "${relative_include_dir}" STREQUAL "")
set(_relative_include_dir "${package}/${relative_include_dir}")
unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
find_path(PYTHON_${_upper_package}_INCLUDE_DIRS
NAMES
"${_relative_include_dir}"
HINTS
"${PYTHON_LIBPATH}/"
"${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
"${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
PATH_SUFFIXES
"site-packages/"
"dist-packages/"
"vendor-packages/"
NO_DEFAULT_PATH
DOC
"Path to python site-packages or dist-packages containing '${package}' module header files"
)
mark_as_advanced(PYTHON_${_upper_package}_INCLUDE_DIRS)
if(NOT EXISTS "${PYTHON_${_upper_package}_INCLUDE_DIRS}")
message(WARNING
"Python package '${package}' include dir path could not be found in:\n"
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${_relative_include_dir}', "
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${_relative_include_dir}', "
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${_relative_include_dir}', "
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${_relative_include_dir}', "
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/vendor-packages/${_relative_include_dir}', "
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/vendor-packages/${_relative_include_dir}', "
"\n"
"The 'WITH_PYTHON_${_upper_package}' option will be disabled.\n"
"The build will be usable, only add-ons that depend on this package won't be functional."
)
set(WITH_PYTHON_${_upper_package} OFF PARENT_SCOPE)
else()
set(_temp "${PYTHON_${_upper_package}_INCLUDE_DIRS}/${package}/${relative_include_dir}")
unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
set(PYTHON_${_upper_package}_INCLUDE_DIRS "${_temp}"
CACHE PATH "Path to the include directory of the ${package} module")
message(STATUS "${package} include files found at '${PYTHON_${_upper_package}_INCLUDE_DIRS}'")
endif()
endif()
endif()
endif()
endfunction()

View File

@@ -470,3 +470,17 @@ set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
if(WITH_COMPILER_CCACHE)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
# Makefiles and ninja
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
else()
message(WARNING "Ccache NOT found, disabling WITH_COMPILER_CCACHE")
set(WITH_COMPILER_CCACHE OFF)
endif()
endif()
endif()

View File

@@ -154,3 +154,32 @@ if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
string(APPEND CMAKE_CXX_FLAGS " -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
if(WITH_COMPILER_CCACHE)
if(CMAKE_GENERATOR STREQUAL "Xcode")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
get_filename_component(ccompiler "${CMAKE_C_COMPILER}" NAME)
get_filename_component(cxxcompiler "${CMAKE_CXX_COMPILER}" NAME)
# Ccache can figure out which compiler to use if it's invoked from
# a symlink with the name of the compiler.
# https://ccache.dev/manual/4.1.html#_run_modes
set(_fake_compiler_dir "${CMAKE_BINARY_DIR}/ccache")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_fake_compiler_dir})
set(_fake_C_COMPILER "${_fake_compiler_dir}/${ccompiler}")
set(_fake_CXX_COMPILER "${_fake_compiler_dir}/${cxxcompiler}")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CCACHE_PROGRAM}" ${_fake_C_COMPILER})
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CCACHE_PROGRAM}" ${_fake_CXX_COMPILER})
set(CMAKE_XCODE_ATTRIBUTE_CC ${_fake_C_COMPILER} CACHE STRING "" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_CXX ${_fake_CXX_COMPILER} CACHE STRING "" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_LD ${_fake_C_COMPILER} CACHE STRING "" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS ${_fake_CXX_COMPILER} CACHE STRING "" FORCE)
unset(_fake_compiler_dir)
unset(_fake_C_COMPILER)
unset(_fake_CXX_COMPILER)
else()
message(WARNING "Ccache NOT found, disabling WITH_COMPILER_CCACHE")
set(WITH_COMPILER_CCACHE OFF)
endif()
endif()
endif()

View File

@@ -684,3 +684,15 @@ set(PLATFORM_LINKFLAGS
if(WITH_INSTALL_PORTABLE)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -no-pie")
endif()
if(WITH_COMPILER_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
# Makefiles and ninja
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
else()
message(WARNING "Ccache NOT found, disabling WITH_COMPILER_CCACHE")
set(WITH_COMPILER_CCACHE OFF)
endif()
endif()

View File

@@ -739,7 +739,7 @@ if(WINDOWS_PYTHON_DEBUG)
string(REPLACE "/" "\\" _group_path "${_source_path}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
# If the user scripts env var is set, include scripts from there otherwise
# include user scripts in the profile folder.
if(DEFINED ENV{BLENDER_USER_SCRIPTS})
@@ -750,7 +750,7 @@ if(WINDOWS_PYTHON_DEBUG)
# Include the user scripts from the profile folder in the blender_python_user_scripts project.
set(USER_SCRIPTS_ROOT "$ENV{appdata}/blender foundation/blender/${BLENDER_VERSION}/scripts")
endif()
file(TO_CMAKE_PATH ${USER_SCRIPTS_ROOT} USER_SCRIPTS_ROOT)
FILE(GLOB_RECURSE inFiles "${USER_SCRIPTS_ROOT}/*.*" )
ADD_CUSTOM_TARGET(blender_python_user_scripts SOURCES ${inFiles})

View File

@@ -121,6 +121,10 @@
* \ingroup editors
*/
/** \defgroup edasset asset
* \ingroup editors
*/
/** \defgroup edcurve curve
* \ingroup editors
*/

View File

@@ -163,13 +163,13 @@ Now in the button's context menu select *Copy Data Path*, then paste the result
.. code-block:: python
bpy.context.active_object.modifiers["Subsurf"].levels
bpy.context.active_object.modifiers["Subdivision"].levels
Press :kbd:`Return` and you'll get the current value of 1. Now try changing the value to 2:
.. code-block:: python
bpy.context.active_object.modifiers["Subsurf"].levels = 2
bpy.context.active_object.modifiers["Subdivision"].levels = 2
You can see the value update in the Subdivision Surface modifier's UI as well as the cube.
@@ -185,43 +185,31 @@ For example, if you want to access the texture of a brush via Python to adjust i
#. Start in the default scene and enable Sculpt Mode from the 3D Viewport header.
#. From the Sidebar expand the Brush Settings panel's *Texture* subpanel and add a new texture.
*Notice the texture data-block menu itself doesn't have very useful links (you can check the tooltips).*
#. The contrast setting isn't exposed in the Sidebar, so view the texture in the properties editor:
- In the properties editor select the Texture tab.
- Select brush texture.
- Expand the *Colors* panel to locate the *Contrast* number field.
#. The contrast setting isn't exposed in the Sidebar, so view the texture in the
:ref:`Properties Editor <blender_manual:bpy.types.Texture.contrast`
#. Open the context menu of the contrast field and select *Online Python Reference*.
This takes you to ``bpy.types.Texture.contrast``. Now you can see that ``contrast`` is a property of texture.
#. To find out how to access the texture from the brush check on the references at the bottom of the page.
Sometimes there are many references, and it may take some guesswork to find the right one,
but in this case it's ``Brush.texture``.
but in this case it's ``tool_settings.sculpt.brush.texture``.
#. Now you know that the texture can be accessed from ``bpy.data.brushes["BrushName"].texture``
but normally you *won't* want to access the brush by name, instead you want to access the active brush.
So the next step is to check on where brushes are accessed from via the references.
In this case there it is simply ``bpy.context.brush``.
Now you can use the Python console to form the nested properties needed to access brush textures contrast:
*Context -> Brush -> Texture -> Contrast*.
:menuselection:`Context --> Tool Settings --> Sculpt --> Brush --> Texture --> Contrast`.
Since the attribute for each is given along the way you can compose the data path in the Python console:
.. code-block:: python
bpy.context.brush.texture.contrast
There can be multiple ways to access the same data, which you choose often depends on the task.
An alternate path to access the same setting is:
.. code-block:: python
bpy.context.sculpt.brush.texture.contrast
bpy.context.tool_settings.sculpt.brush.texture.contrast
Or access the brush directly:
.. code-block:: python
bpy.data.brushes["BrushName"].texture.contrast
bpy.data.textures["Texture"].contrast
If you are writing a user tool normally you want to use the :mod:`bpy.context` since the user normally expects

View File

@@ -35,12 +35,13 @@ but not to fully cover each topic.
A quick list of helpful things to know before starting:
- Blender uses Python 3.x; some online documentation still assumes version 2.x.
- The interactive console is great for testing one-liners.
It also has autocompletion so you can inspect the API quickly.
- Button tooltips show Python attributes and operator names.
- The context menu of buttons directly links to this API documentation.
- More operator examples can be found in the text editor's template menu.
- Enable :ref:`Developer Extra <blender_manual:prefs-interface-dev-extras`
and :ref:`Python Tooltips <blender_manual:prefs-interface-tooltips-python>`.
- The :ref:`Python Console <blender_manual:bpy.types.SpaceConsole>`
is great for testing one-liners; it has autocompletion so you can inspect the API quickly.
- Button tooltips show Python attributes and operator names (when enabled see above).
- The context menu of buttons directly links to this API documentation (when enabled see above).
- Many python examples can be found in the text editor's template menu.
- To examine further scripts distributed with Blender, see:
- ``scripts/startup/bl_ui`` for the user interface.
@@ -237,7 +238,7 @@ Examples:
{'FINISHED'}
>>> bpy.ops.mesh.hide(unselected=False)
{'FINISHED'}
>>> bpy.ops.object.scale_apply()
>>> bpy.ops.object.transform_apply()
{'FINISHED'}
.. tip::

View File

@@ -24,10 +24,9 @@ The three main use cases for the terminal are:
- If the script runs for too long or you accidentally enter an infinite loop,
:kbd:`Ctrl-C` in the terminal (:kbd:`Ctrl-Break` on Windows) will quit the script early.
.. note::
.. seealso::
For Linux and macOS users this means starting the terminal first, then running Blender from within it.
On Windows the terminal can be enabled from the Help menu.
:ref:`blender_manual:command_line-launch-index`.
Interface Tricks

View File

@@ -1,7 +1,5 @@
/* Prevent Long enum lists */
.field-body {
display: block;
width: 100%;
/* T76453: Prevent Long enum lists */
.field-list li {
max-height: 245px;
overflow-y: auto !important;
}

4
extern/README vendored Normal file
View File

@@ -0,0 +1,4 @@
When updating a library remember to:
* Update the README.blender with the corresponding version.
* Update the THIRD-PARTY-LICENSE.txt document

View File

@@ -24,6 +24,6 @@ set(JACK_FOUND ${WITH_JACK})
set(LIBSNDFILE_FOUND ${WITH_CODEC_SNDFILE})
set(OPENAL_FOUND ${WITH_OPENAL})
set(PYTHONLIBS_FOUND TRUE)
set(NUMPY_FOUND TRUE)
set(NUMPY_FOUND ${WITH_PYTHON_NUMPY})
set(NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_INCLUDE_DIRS})
set(SDL_FOUND ${WITH_SDL})

View File

@@ -72,6 +72,9 @@ protected:
/// The channel mapper reader in between.
std::shared_ptr<ChannelMapperReader> m_mapper;
/// Whether the source is being read for the first time.
bool m_first_reading;
/// Whether to keep the source if end of it is reached.
bool m_keep;

View File

@@ -78,7 +78,7 @@ bool SoftwareDevice::SoftwareHandle::pause(bool keep)
}
SoftwareDevice::SoftwareHandle::SoftwareHandle(SoftwareDevice* device, std::shared_ptr<IReader> reader, std::shared_ptr<PitchReader> pitch, std::shared_ptr<ResampleReader> resampler, std::shared_ptr<ChannelMapperReader> mapper, bool keep) :
m_reader(reader), m_pitch(pitch), m_resampler(resampler), m_mapper(mapper), m_keep(keep), m_user_pitch(1.0f), m_user_volume(1.0f), m_user_pan(0.0f), m_volume(0.0f), m_old_volume(0.0f), m_loopcount(0),
m_reader(reader), m_pitch(pitch), m_resampler(resampler), m_mapper(mapper), m_first_reading(true), m_keep(keep), m_user_pitch(1.0f), m_user_volume(1.0f), m_user_pan(0.0f), m_volume(0.0f), m_old_volume(0.0f), m_loopcount(0),
m_relative(true), m_volume_max(1.0f), m_volume_min(0), m_distance_max(std::numeric_limits<float>::max()),
m_distance_reference(1.0f), m_attenuation(1.0f), m_cone_angle_outer(M_PI), m_cone_angle_inner(M_PI), m_cone_volume_outer(0),
m_flags(RENDER_CONE), m_stop(nullptr), m_stop_data(nullptr), m_status(STATUS_PLAYING), m_device(device)
@@ -106,6 +106,14 @@ void SoftwareDevice::SoftwareHandle::update()
if(m_pitch->getSpecs().channels != CHANNELS_MONO)
{
m_volume = m_user_volume;
// we don't know a previous volume if this source has never been read before
if(m_first_reading)
{
m_old_volume = m_volume;
m_first_reading = false;
}
m_pitch->setPitch(m_user_pitch);
return;
}
@@ -214,6 +222,13 @@ void SoftwareDevice::SoftwareHandle::update()
m_volume *= m_user_volume;
}
// we don't know a previous volume if this source has never been read before
if(m_first_reading)
{
m_old_volume = m_volume;
m_first_reading = false;
}
// 3D Cue
Quaternion orientation;
@@ -754,6 +769,8 @@ void SoftwareDevice::mix(data_t* buffer, int length)
{
m_mixer->mix(buf, pos, len, sound->m_volume, sound->m_old_volume);
sound->m_old_volume = sound->m_volume;
pos += len;
if(sound->m_loopcount > 0)

View File

@@ -22,6 +22,7 @@
#include <mutex>
#define KEEP_TIME 10
#define POSITION_EPSILON (1.0 / static_cast<double>(RATE_48000))
AUD_NAMESPACE_BEGIN
@@ -64,7 +65,7 @@ bool SequenceHandle::updatePosition(double position)
if(m_handle.get())
{
// we currently have a handle, let's check where we are
if(position >= m_entry->m_end)
if(position - POSITION_EPSILON >= m_entry->m_end)
{
if(position >= m_entry->m_end + KEEP_TIME)
// far end, stopping
@@ -76,7 +77,7 @@ bool SequenceHandle::updatePosition(double position)
return true;
}
}
else if(position >= m_entry->m_begin)
else if(position + POSITION_EPSILON >= m_entry->m_begin)
{
// inside, resuming
m_handle->resume();
@@ -98,7 +99,7 @@ bool SequenceHandle::updatePosition(double position)
else
{
// we don't have a handle, let's start if we should be playing
if(position >= m_entry->m_begin && position <= m_entry->m_end)
if(position + POSITION_EPSILON >= m_entry->m_begin && position - POSITION_EPSILON <= m_entry->m_end)
{
start();
return m_valid;

View File

@@ -268,4 +268,3 @@ set(INC
)
blender_add_lib(draco "${SRC}" "${INC}" "" "${LIB}")

View File

@@ -85,7 +85,7 @@ if(WIN32)
add_definitions(-D_USE_MATH_DEFINES)
endif()
if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
add_definitions(-DNUMPY=1)
endif()
@@ -109,7 +109,7 @@ set(INC_SYS
${ZLIB_INCLUDE_DIRS}
)
if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
list(APPEND INC_SYS
${PYTHON_NUMPY_INCLUDE_DIRS}
)
@@ -200,6 +200,7 @@ set(SRC
${MANTA_PP}/plugin/ptsplugins.cpp
${MANTA_PP}/plugin/secondaryparticles.cpp
${MANTA_PP}/plugin/surfaceturbulence.cpp
${MANTA_PP}/plugin/viscosity.cpp
${MANTA_PP}/plugin/vortexplugins.cpp
${MANTA_PP}/plugin/waveletturbulence.cpp
${MANTA_PP}/plugin/waves.cpp
@@ -255,8 +256,7 @@ if(WITH_MANTA_DEPENDENCIES)
${MANTA_DEP}/cnpy/cnpy.h
)
endif()
if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
list(APPEND SRC
${MANTA_PP}/plugin/numpyconvert.cpp
${MANTA_PP}/plugin/tfplugins.cpp

View File

@@ -1035,7 +1035,7 @@ template<class N, class T> struct RCFixedMatrix {
typedef RCMatrix<int, Real> Matrix;
typedef RCFixedMatrix<int, Real> FixedMatrix;
} // namespace Manta
}
#undef parallel_for
#undef parallel_end

View File

@@ -397,7 +397,7 @@ struct UpdateSearchVec : public KernelBase {
};
//*****************************************************************************
// CG class
// CG class
template<class APPLYMAT>
GridCg<APPLYMAT>::GridCg(Grid<Real> &dst,
@@ -406,10 +406,8 @@ GridCg<APPLYMAT>::GridCg(Grid<Real> &dst,
Grid<Real> &search,
const FlagGrid &flags,
Grid<Real> &tmp,
Grid<Real> *pA0,
Grid<Real> *pAi,
Grid<Real> *pAj,
Grid<Real> *pAk)
std::vector<Grid<Real> *> matrixAVec,
std::vector<Grid<Real> *> rhsVec)
: GridCgInterface(),
mInited(false),
mIterations(0),
@@ -419,10 +417,8 @@ GridCg<APPLYMAT>::GridCg(Grid<Real> &dst,
mSearch(search),
mFlags(flags),
mTmp(tmp),
mpA0(pA0),
mpAi(pAi),
mpAj(pAj),
mpAk(pAk),
mMatrixA(matrixAVec),
mVecRhs(rhsVec),
mPcMethod(PC_None),
mpPCA0(nullptr),
mpPCAi(nullptr),
@@ -445,19 +441,37 @@ template<class APPLYMAT> void GridCg<APPLYMAT>::doInit()
if (mPcMethod == PC_ICP) {
assertMsg(mDst.is3D(), "ICP only supports 3D grids so far");
InitPreconditionIncompCholesky(
mFlags, *mpPCA0, *mpPCAi, *mpPCAj, *mpPCAk, *mpA0, *mpAi, *mpAj, *mpAk);
ApplyPreconditionIncompCholesky(
mTmp, mResidual, mFlags, *mpPCA0, *mpPCAi, *mpPCAj, *mpPCAk, *mpA0, *mpAi, *mpAj, *mpAk);
InitPreconditionIncompCholesky(mFlags,
*mpPCA0,
*mpPCAi,
*mpPCAj,
*mpPCAk,
*mMatrixA[0],
*mMatrixA[1],
*mMatrixA[2],
*mMatrixA[3]);
ApplyPreconditionIncompCholesky(mTmp,
mResidual,
mFlags,
*mpPCA0,
*mpPCAi,
*mpPCAj,
*mpPCAk,
*mMatrixA[0],
*mMatrixA[1],
*mMatrixA[2],
*mMatrixA[3]);
}
else if (mPcMethod == PC_mICP) {
assertMsg(mDst.is3D(), "mICP only supports 3D grids so far");
InitPreconditionModifiedIncompCholesky2(mFlags, *mpPCA0, *mpA0, *mpAi, *mpAj, *mpAk);
InitPreconditionModifiedIncompCholesky2(
mFlags, *mpPCA0, *mMatrixA[0], *mMatrixA[1], *mMatrixA[2], *mMatrixA[3]);
ApplyPreconditionModifiedIncompCholesky2(
mTmp, mResidual, mFlags, *mpPCA0, *mpA0, *mpAi, *mpAj, *mpAk);
mTmp, mResidual, mFlags, *mpPCA0, *mMatrixA[0], *mMatrixA[1], *mMatrixA[2], *mMatrixA[3]);
}
else if (mPcMethod == PC_MGP) {
InitPreconditionMultigrid(mMG, *mpA0, *mpAi, *mpAj, *mpAk, mAccuracy);
InitPreconditionMultigrid(
mMG, *mMatrixA[0], *mMatrixA[1], *mMatrixA[2], *mMatrixA[3], mAccuracy);
ApplyPreconditionMultigrid(mMG, mTmp, mResidual);
}
else {
@@ -465,7 +479,6 @@ template<class APPLYMAT> void GridCg<APPLYMAT>::doInit()
}
mSearch.copyFrom(mTmp);
mSigma = GridDotProduct(mTmp, mResidual);
}
@@ -480,7 +493,7 @@ template<class APPLYMAT> bool GridCg<APPLYMAT>::iterate()
// this could reinterpret the mpA pointers (not so clean right now)
// tmp = applyMat(search)
APPLYMAT(mFlags, mTmp, mSearch, *mpA0, *mpAi, *mpAj, *mpAk);
APPLYMAT(mFlags, mTmp, mSearch, mMatrixA, mVecRhs);
// alpha = sigma/dot(tmp, search)
Real dp = GridDotProduct(mTmp, mSearch);
@@ -492,11 +505,20 @@ template<class APPLYMAT> bool GridCg<APPLYMAT>::iterate()
gridScaledAdd<Real, Real>(mResidual, mTmp, -alpha); // residual += tmp * -alpha
if (mPcMethod == PC_ICP)
ApplyPreconditionIncompCholesky(
mTmp, mResidual, mFlags, *mpPCA0, *mpPCAi, *mpPCAj, *mpPCAk, *mpA0, *mpAi, *mpAj, *mpAk);
ApplyPreconditionIncompCholesky(mTmp,
mResidual,
mFlags,
*mpPCA0,
*mpPCAi,
*mpPCAj,
*mpPCAk,
*mMatrixA[0],
*mMatrixA[1],
*mMatrixA[2],
*mMatrixA[3]);
else if (mPcMethod == PC_mICP)
ApplyPreconditionModifiedIncompCholesky2(
mTmp, mResidual, mFlags, *mpPCA0, *mpA0, *mpAi, *mpAj, *mpAk);
mTmp, mResidual, mFlags, *mpPCA0, *mMatrixA[0], *mMatrixA[1], *mMatrixA[2], *mMatrixA[3]);
else if (mPcMethod == PC_MGP)
ApplyPreconditionMultigrid(mMG, mTmp, mResidual);
else
@@ -584,13 +606,15 @@ void GridCg<APPLYMAT>::setMGPreconditioner(PreconditionType method, GridMg *MG)
assertMsg(method == PC_MGP, "GridCg<APPLYMAT>::setMGPreconditioner: Invalid method specified.");
mPcMethod = method;
mMG = MG;
}
// explicit instantiation
template class GridCg<ApplyMatrix>;
template class GridCg<ApplyMatrix2D>;
template class GridCg<ApplyMatrixViscosityU>;
template class GridCg<ApplyMatrixViscosityV>;
template class GridCg<ApplyMatrixViscosityW>;
//*****************************************************************************
// diffusion for real and vec grids, e.g. for viscosity
@@ -638,10 +662,15 @@ void cgSolveDiffusion(const FlagGrid &flags,
if (grid.getType() & GridBase::TypeReal) {
Grid<Real> &u = ((Grid<Real> &)grid);
rhs.copyFrom(u);
if (flags.is3D())
gcg = new GridCg<ApplyMatrix>(u, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
else
gcg = new GridCg<ApplyMatrix2D>(u, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
vector<Grid<Real> *> matA{&A0, &Ai, &Aj};
if (flags.is3D()) {
matA.push_back(&Ak);
gcg = new GridCg<ApplyMatrix>(u, rhs, residual, search, flags, tmp, matA);
}
else {
gcg = new GridCg<ApplyMatrix2D>(u, rhs, residual, search, flags, tmp, matA);
}
gcg->setAccuracy(cgAccuracy);
gcg->solve(maxIter);
@@ -653,12 +682,17 @@ void cgSolveDiffusion(const FlagGrid &flags,
else if ((grid.getType() & GridBase::TypeVec3) || (grid.getType() & GridBase::TypeMAC)) {
Grid<Vec3> &vec = ((Grid<Vec3> &)grid);
Grid<Real> u(parent);
vector<Grid<Real> *> matA{&A0, &Ai, &Aj};
// core solve is same as for a regular real grid
if (flags.is3D())
gcg = new GridCg<ApplyMatrix>(u, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
else
gcg = new GridCg<ApplyMatrix2D>(u, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
if (flags.is3D()) {
matA.push_back(&Ak);
gcg = new GridCg<ApplyMatrix>(u, rhs, residual, search, flags, tmp, matA);
}
else {
gcg = new GridCg<ApplyMatrix2D>(u, rhs, residual, search, flags, tmp, matA);
}
gcg->setAccuracy(cgAccuracy);
// diffuse every component separately

View File

@@ -78,13 +78,9 @@ template<class APPLYMAT> class GridCg : public GridCgInterface {
Grid<Real> &search,
const FlagGrid &flags,
Grid<Real> &tmp,
Grid<Real> *A0,
Grid<Real> *pAi,
Grid<Real> *pAj,
Grid<Real> *pAk);
~GridCg()
{
}
std::vector<Grid<Real> *> matrixAVec,
std::vector<Grid<Real> *> rhsVec = {});
~GridCg(){};
void doInit();
bool iterate();
@@ -133,7 +129,10 @@ template<class APPLYMAT> class GridCg : public GridCgInterface {
const FlagGrid &mFlags;
Grid<Real> &mTmp;
Grid<Real> *mpA0, *mpAi, *mpAj, *mpAk;
//! shape of A matrix defined here (e.g. diagonal, positive neighbor cells, etc)
std::vector<Grid<Real> *> mMatrixA;
//! shape of rhs vector defined here (e.g. 1 rhs for regular fluids solve, 3 rhs for viscosity)
std::vector<Grid<Real> *> mVecRhs;
PreconditionType mPcMethod;
//! preconditioning grids
@@ -154,11 +153,9 @@ struct ApplyMatrix : public KernelBase {
ApplyMatrix(const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
Grid<Real> &A0,
Grid<Real> &Ai,
Grid<Real> &Aj,
Grid<Real> &Ak)
: KernelBase(&flags, 0), flags(flags), dst(dst), src(src), A0(A0), Ai(Ai), Aj(Aj), Ak(Ak)
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs)
: KernelBase(&flags, 0), flags(flags), dst(dst), src(src), matrixA(matrixA), vecRhs(vecRhs)
{
runMessage();
run();
@@ -167,11 +164,18 @@ struct ApplyMatrix : public KernelBase {
const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
Grid<Real> &A0,
Grid<Real> &Ai,
Grid<Real> &Aj,
Grid<Real> &Ak) const
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
unusedParameter(vecRhs); // Not needed in this matrix application
if (matrixA.size() != 4)
errMsg("ConjugatedGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Ai = *matrixA[1];
Grid<Real> &Aj = *matrixA[2];
Grid<Real> &Ak = *matrixA[3];
if (!flags.isFluid(idx)) {
dst[idx] = src[idx];
return;
@@ -196,26 +200,16 @@ struct ApplyMatrix : public KernelBase {
return src;
}
typedef Grid<Real> type2;
inline Grid<Real> &getArg3()
inline const std::vector<Grid<Real> *> &getArg3()
{
return A0;
return matrixA;
}
typedef Grid<Real> type3;
inline Grid<Real> &getArg4()
typedef std::vector<Grid<Real> *> type3;
inline const std::vector<Grid<Real> *> &getArg4()
{
return Ai;
return vecRhs;
}
typedef Grid<Real> type4;
inline Grid<Real> &getArg5()
{
return Aj;
}
typedef Grid<Real> type5;
inline Grid<Real> &getArg6()
{
return Ak;
}
typedef Grid<Real> type6;
typedef std::vector<Grid<Real> *> type4;
void runMessage()
{
debMsg("Executing kernel ApplyMatrix ", 3);
@@ -226,7 +220,7 @@ struct ApplyMatrix : public KernelBase {
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
op(idx, flags, dst, src, A0, Ai, Aj, Ak);
op(idx, flags, dst, src, matrixA, vecRhs);
}
void run()
{
@@ -235,10 +229,8 @@ struct ApplyMatrix : public KernelBase {
const FlagGrid &flags;
Grid<Real> &dst;
const Grid<Real> &src;
Grid<Real> &A0;
Grid<Real> &Ai;
Grid<Real> &Aj;
Grid<Real> &Ak;
const std::vector<Grid<Real> *> matrixA;
const std::vector<Grid<Real> *> vecRhs;
};
//! Kernel: Apply symmetric stored Matrix. 2D version
@@ -247,11 +239,9 @@ struct ApplyMatrix2D : public KernelBase {
ApplyMatrix2D(const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
Grid<Real> &A0,
Grid<Real> &Ai,
Grid<Real> &Aj,
Grid<Real> &Ak)
: KernelBase(&flags, 0), flags(flags), dst(dst), src(src), A0(A0), Ai(Ai), Aj(Aj), Ak(Ak)
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs)
: KernelBase(&flags, 0), flags(flags), dst(dst), src(src), matrixA(matrixA), vecRhs(vecRhs)
{
runMessage();
run();
@@ -260,12 +250,16 @@ struct ApplyMatrix2D : public KernelBase {
const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
Grid<Real> &A0,
Grid<Real> &Ai,
Grid<Real> &Aj,
Grid<Real> &Ak) const
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
unusedParameter(Ak); // only there for parameter compatibility with ApplyMatrix
unusedParameter(vecRhs); // Not needed in this matrix application
if (matrixA.size() != 3)
errMsg("ConjugatedGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Ai = *matrixA[1];
Grid<Real> &Aj = *matrixA[2];
if (!flags.isFluid(idx)) {
dst[idx] = src[idx];
@@ -290,26 +284,16 @@ struct ApplyMatrix2D : public KernelBase {
return src;
}
typedef Grid<Real> type2;
inline Grid<Real> &getArg3()
inline const std::vector<Grid<Real> *> &getArg3()
{
return A0;
return matrixA;
}
typedef Grid<Real> type3;
inline Grid<Real> &getArg4()
typedef std::vector<Grid<Real> *> type3;
inline const std::vector<Grid<Real> *> &getArg4()
{
return Ai;
return vecRhs;
}
typedef Grid<Real> type4;
inline Grid<Real> &getArg5()
{
return Aj;
}
typedef Grid<Real> type5;
inline Grid<Real> &getArg6()
{
return Ak;
}
typedef Grid<Real> type6;
typedef std::vector<Grid<Real> *> type4;
void runMessage()
{
debMsg("Executing kernel ApplyMatrix2D ", 3);
@@ -320,7 +304,7 @@ struct ApplyMatrix2D : public KernelBase {
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
op(idx, flags, dst, src, A0, Ai, Aj, Ak);
op(idx, flags, dst, src, matrixA, vecRhs);
}
void run()
{
@@ -329,12 +313,358 @@ struct ApplyMatrix2D : public KernelBase {
const FlagGrid &flags;
Grid<Real> &dst;
const Grid<Real> &src;
Grid<Real> &A0;
Grid<Real> &Ai;
Grid<Real> &Aj;
Grid<Real> &Ak;
const std::vector<Grid<Real> *> matrixA;
const std::vector<Grid<Real> *> vecRhs;
};
struct ApplyMatrixViscosityU : public KernelBase {
ApplyMatrixViscosityU(const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs)
: KernelBase(&flags, 1), flags(flags), dst(dst), src(src), matrixA(matrixA), vecRhs(vecRhs)
{
runMessage();
run();
}
inline void op(int i,
int j,
int k,
const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
if (matrixA.size() != 15)
errMsg("ConjugatedGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
Grid<Real> &Aplusk = *matrixA[3];
Grid<Real> &Aminusi = *matrixA[4];
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
if (vecRhs.size() != 2)
errMsg("ConjugatedGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcV = *vecRhs[0];
Grid<Real> &srcW = *vecRhs[1];
dst(i, j, k) = src(i, j, k) * A0(i, j, k) + src(i + 1, j, k) * Aplusi(i, j, k) +
src(i, j + 1, k) * Aplusj(i, j, k) + src(i, j, k + 1) * Aplusk(i, j, k) +
src(i - 1, j, k) * Aminusi(i, j, k) + src(i, j - 1, k) * Aminusj(i, j, k) +
src(i, j, k - 1) * Aminusk(i, j, k);
dst(i, j, k) += srcV(i, j + 1, k) * (*matrixA[7])(i, j, k) +
srcV(i - 1, j + 1, k) * (*matrixA[8])(i, j, k) +
srcV(i, j, k) * (*matrixA[9])(i, j, k) +
srcV(i - 1, j, k) * (*matrixA[10])(i, j, k) +
srcW(i, j, k + 1) * (*matrixA[11])(i, j, k) +
srcW(i - 1, j, k + 1) * (*matrixA[12])(i, j, k) +
srcW(i, j, k) * (*matrixA[13])(i, j, k) +
srcW(i - 1, j, k) * (*matrixA[14])(i, j, k);
}
inline const FlagGrid &getArg0()
{
return flags;
}
typedef FlagGrid type0;
inline Grid<Real> &getArg1()
{
return dst;
}
typedef Grid<Real> type1;
inline const Grid<Real> &getArg2()
{
return src;
}
typedef Grid<Real> type2;
inline const std::vector<Grid<Real> *> &getArg3()
{
return matrixA;
}
typedef std::vector<Grid<Real> *> type3;
inline const std::vector<Grid<Real> *> &getArg4()
{
return vecRhs;
}
typedef std::vector<Grid<Real> *> type4;
void runMessage()
{
debMsg("Executing kernel ApplyMatrixViscosityU ", 3);
debMsg("Kernel range"
<< " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
4);
};
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
const int _maxX = maxX;
const int _maxY = maxY;
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
else {
const int k = 0;
for (int j = __r.begin(); j != (int)__r.end(); j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
}
void run()
{
if (maxZ > 1)
tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
else
tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
}
const FlagGrid &flags;
Grid<Real> &dst;
const Grid<Real> &src;
const std::vector<Grid<Real> *> matrixA;
const std::vector<Grid<Real> *> vecRhs;
};
struct ApplyMatrixViscosityV : public KernelBase {
ApplyMatrixViscosityV(const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs)
: KernelBase(&flags, 1), flags(flags), dst(dst), src(src), matrixA(matrixA), vecRhs(vecRhs)
{
runMessage();
run();
}
inline void op(int i,
int j,
int k,
const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
if (matrixA.size() != 15)
errMsg("ConjugatedGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
Grid<Real> &Aplusk = *matrixA[3];
Grid<Real> &Aminusi = *matrixA[4];
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
if (vecRhs.size() != 2)
errMsg("ConjugatedGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcU = *vecRhs[0];
Grid<Real> &srcW = *vecRhs[1];
dst(i, j, k) = src(i, j, k) * A0(i, j, k) + src(i + 1, j, k) * Aplusi(i, j, k) +
src(i, j + 1, k) * Aplusj(i, j, k) + src(i, j, k + 1) * Aplusk(i, j, k) +
src(i - 1, j, k) * Aminusi(i, j, k) + src(i, j - 1, k) * Aminusj(i, j, k) +
src(i, j, k - 1) * Aminusk(i, j, k);
dst(i, j, k) += srcU(i + 1, j, k) * (*matrixA[7])(i, j, k) +
srcU(i + 1, j - 1, k) * (*matrixA[8])(i, j, k) +
srcU(i, j, k) * (*matrixA[9])(i, j, k) +
srcU(i, j - 1, k) * (*matrixA[10])(i, j, k) +
srcW(i, j, k + 1) * (*matrixA[11])(i, j, k) +
srcW(i, j - 1, k + 1) * (*matrixA[12])(i, j, k) +
srcW(i, j, k) * (*matrixA[13])(i, j, k) +
srcW(i, j - 1, k) * (*matrixA[14])(i, j, k);
}
inline const FlagGrid &getArg0()
{
return flags;
}
typedef FlagGrid type0;
inline Grid<Real> &getArg1()
{
return dst;
}
typedef Grid<Real> type1;
inline const Grid<Real> &getArg2()
{
return src;
}
typedef Grid<Real> type2;
inline const std::vector<Grid<Real> *> &getArg3()
{
return matrixA;
}
typedef std::vector<Grid<Real> *> type3;
inline const std::vector<Grid<Real> *> &getArg4()
{
return vecRhs;
}
typedef std::vector<Grid<Real> *> type4;
void runMessage()
{
debMsg("Executing kernel ApplyMatrixViscosityV ", 3);
debMsg("Kernel range"
<< " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
4);
};
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
const int _maxX = maxX;
const int _maxY = maxY;
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
else {
const int k = 0;
for (int j = __r.begin(); j != (int)__r.end(); j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
}
void run()
{
if (maxZ > 1)
tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
else
tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
}
const FlagGrid &flags;
Grid<Real> &dst;
const Grid<Real> &src;
const std::vector<Grid<Real> *> matrixA;
const std::vector<Grid<Real> *> vecRhs;
};
struct ApplyMatrixViscosityW : public KernelBase {
ApplyMatrixViscosityW(const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs)
: KernelBase(&flags, 1), flags(flags), dst(dst), src(src), matrixA(matrixA), vecRhs(vecRhs)
{
runMessage();
run();
}
inline void op(int i,
int j,
int k,
const FlagGrid &flags,
Grid<Real> &dst,
const Grid<Real> &src,
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
if (matrixA.size() != 15)
errMsg("ConjugatedGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
Grid<Real> &Aplusk = *matrixA[3];
Grid<Real> &Aminusi = *matrixA[4];
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
if (vecRhs.size() != 2)
errMsg("ConjugatedGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcU = *vecRhs[0];
Grid<Real> &srcV = *vecRhs[1];
dst(i, j, k) = src(i, j, k) * A0(i, j, k) + src(i + 1, j, k) * Aplusi(i, j, k) +
src(i, j + 1, k) * Aplusj(i, j, k) + src(i, j, k + 1) * Aplusk(i, j, k) +
src(i - 1, j, k) * Aminusi(i, j, k) + src(i, j - 1, k) * Aminusj(i, j, k) +
src(i, j, k - 1) * Aminusk(i, j, k);
dst(i, j, k) += srcU(i + 1, j, k) * (*matrixA[7])(i, j, k) +
srcU(i + 1, j, k - 1) * (*matrixA[8])(i, j, k) +
srcU(i, j, k) * (*matrixA[9])(i, j, k) +
srcU(i, j, k - 1) * (*matrixA[10])(i, j, k) +
srcV(i, j + 1, k) * (*matrixA[11])(i, j, k) +
srcV(i, j + 1, k - 1) * (*matrixA[12])(i, j, k) +
srcV(i, j, k) * (*matrixA[13])(i, j, k) +
srcV(i, j, k - 1) * (*matrixA[14])(i, j, k);
}
inline const FlagGrid &getArg0()
{
return flags;
}
typedef FlagGrid type0;
inline Grid<Real> &getArg1()
{
return dst;
}
typedef Grid<Real> type1;
inline const Grid<Real> &getArg2()
{
return src;
}
typedef Grid<Real> type2;
inline const std::vector<Grid<Real> *> &getArg3()
{
return matrixA;
}
typedef std::vector<Grid<Real> *> type3;
inline const std::vector<Grid<Real> *> &getArg4()
{
return vecRhs;
}
typedef std::vector<Grid<Real> *> type4;
void runMessage()
{
debMsg("Executing kernel ApplyMatrixViscosityW ", 3);
debMsg("Kernel range"
<< " x " << maxX << " y " << maxY << " z " << minZ << " - " << maxZ << " ",
4);
};
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
const int _maxX = maxX;
const int _maxY = maxY;
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
else {
const int k = 0;
for (int j = __r.begin(); j != (int)__r.end(); j++)
for (int i = 1; i < _maxX; i++)
op(i, j, k, flags, dst, src, matrixA, vecRhs);
}
}
void run()
{
if (maxZ > 1)
tbb::parallel_for(tbb::blocked_range<IndexInt>(minZ, maxZ), *this);
else
tbb::parallel_for(tbb::blocked_range<IndexInt>(1, maxY), *this);
}
const FlagGrid &flags;
Grid<Real> &dst;
const Grid<Real> &src;
const std::vector<Grid<Real> *> matrixA;
const std::vector<Grid<Real> *> vecRhs;
};
/* NOTE: Use this template for new matrix application kernels
//! Template for matrix application kernels
KERNEL()
void ApplyMatrixTemplate (const FlagGrid& flags, Grid<Real>& dst, const Grid<Real>& src,
const std::vector<Grid<Real> *> matrixA, const std::vector<Grid<Real> *> vecRhs)
{
// The kernel must define how to use the grids from the matrixA and vecRhs lists
}
*/
//! Kernel: Construct the matrix for the poisson equation
struct MakeLaplaceMatrix : public KernelBase {

View File

@@ -423,13 +423,14 @@ int writeObjectsVDB(const string &filename,
if (GridBase *mantaGrid = dynamic_cast<GridBase *>(*iter)) {
if (clipGrid) {
assertMsg(clipGrid->getSize() == mantaGrid->getSize(),
"writeObjectsVDB: Clip grid and exported grid must have the same size");
}
if (mantaGrid->getType() & GridBase::TypeInt) {
debMsg("Writing int grid '" << mantaGrid->getName() << "' to vdb file " << filename, 1);
Grid<int> *mantaIntGrid = (Grid<int> *)mantaGrid;
if (clipGrid && mantaIntGrid->saveSparse()) {
assertMsg(clipGrid->getSize() == mantaGrid->getSize(),
"writeObjectsVDB: Clip grid and exported grid must have the same size "
<< clipGrid->getSize() << " vs " << mantaGrid->getSize());
}
vdbGrid = exportVDB<int, openvdb::Int32Grid>(mantaIntGrid, clip, vdbClipGrid);
gridsVDB.push_back(vdbGrid);
}
@@ -440,6 +441,11 @@ int writeObjectsVDB(const string &filename,
Grid<Real> *mantaRealGrid = (Grid<Real> *)mantaGrid;
// Only supply clip grid if real grid is not equal to the clip grid
openvdb::FloatGrid::Ptr tmpClipGrid = (mantaRealGrid == clipGrid) ? nullptr : vdbClipGrid;
if (clipGrid && mantaRealGrid->saveSparse()) {
assertMsg(clipGrid->getSize() == mantaGrid->getSize(),
"writeObjectsVDB: Clip grid and exported grid must have the same size "
<< clipGrid->getSize() << " vs " << mantaGrid->getSize());
}
vdbGrid = exportVDB<Real, openvdb::FloatGrid>(mantaRealGrid, clip, tmpClipGrid);
gridsVDB.push_back(vdbGrid);
}
@@ -448,6 +454,11 @@ int writeObjectsVDB(const string &filename,
gClass = (mantaGrid->getType() & GridBase::TypeMAC) ? openvdb::GRID_STAGGERED :
openvdb::GRID_UNKNOWN;
Grid<Vec3> *mantaVec3Grid = (Grid<Vec3> *)mantaGrid;
if (clipGrid && mantaVec3Grid->saveSparse()) {
assertMsg(clipGrid->getSize() == mantaGrid->getSize(),
"writeObjectsVDB: Clip grid and exported grid must have the same size "
<< clipGrid->getSize() << " vs " << mantaGrid->getSize());
}
vdbGrid = exportVDB<Vec3, openvdb::Vec3SGrid>(mantaVec3Grid, clip, vdbClipGrid);
gridsVDB.push_back(vdbGrid);
}

View File

@@ -42,7 +42,7 @@ inline void updateQtGui(bool full, int frame, float time, const std::string &cur
# ifdef _DEBUG
# define DEBUG 1
# endif // _DEBUG
#endif // DEBUG
#endif // DEBUG
// Standard exception
class Error : public std::exception {
@@ -242,6 +242,39 @@ inline bool c_isnan(float c)
return d != d;
}
//! Swap so that a<b
template<class T> inline void sort(T &a, T &b)
{
if (a > b)
std::swap(a, b);
}
//! Swap so that a<b<c
template<class T> inline void sort(T &a, T &b, T &c)
{
if (a > b)
std::swap(a, b);
if (a > c)
std::swap(a, c);
if (b > c)
std::swap(b, c);
}
//! Swap so that a<b<c<d
template<class T> inline void sort(T &a, T &b, T &c, T &d)
{
if (a > b)
std::swap(a, b);
if (c > d)
std::swap(c, d);
if (a > c)
std::swap(a, c);
if (b > d)
std::swap(b, d);
if (b > c)
std::swap(b, c);
}
} // namespace Manta
#endif

View File

@@ -1,3 +1,3 @@
#define MANTA_GIT_VERSION "commit 327917cd59b03bef3a953b5f58fc1637b3a83e01"
#define MANTA_GIT_VERSION "commit e2285cb9bc492987f728123be6cfc1fe11fe73d6"

View File

@@ -1135,26 +1135,27 @@ struct KnAddForceIfLower : public KernelBase {
if (!curFluid && !curEmpty)
return;
Real minVal, maxVal, sum;
if (flags.isFluid(i - 1, j, k) || (curFluid && flags.isEmpty(i - 1, j, k))) {
Real forceMACX = 0.5 * (force(i - 1, j, k).x + force(i, j, k).x);
Real min = std::min(vel(i, j, k).x, forceMACX);
Real max = std::max(vel(i, j, k).x, forceMACX);
Real sum = vel(i, j, k).x + forceMACX;
vel(i, j, k).x = (forceMACX > 0) ? std::min(sum, max) : std::max(sum, min);
minVal = min(vel(i, j, k).x, forceMACX);
maxVal = max(vel(i, j, k).x, forceMACX);
sum = vel(i, j, k).x + forceMACX;
vel(i, j, k).x = (forceMACX > 0) ? min(sum, maxVal) : max(sum, minVal);
}
if (flags.isFluid(i, j - 1, k) || (curFluid && flags.isEmpty(i, j - 1, k))) {
Real forceMACY = 0.5 * (force(i, j - 1, k).y + force(i, j, k).y);
Real min = std::min(vel(i, j, k).y, forceMACY);
Real max = std::max(vel(i, j, k).y, forceMACY);
Real sum = vel(i, j, k).y + forceMACY;
vel(i, j, k).y = (forceMACY > 0) ? std::min(sum, max) : std::max(sum, min);
minVal = min(vel(i, j, k).y, forceMACY);
maxVal = max(vel(i, j, k).y, forceMACY);
sum = vel(i, j, k).y + forceMACY;
vel(i, j, k).y = (forceMACY > 0) ? min(sum, maxVal) : max(sum, minVal);
}
if (vel.is3D() && (flags.isFluid(i, j, k - 1) || (curFluid && flags.isEmpty(i, j, k - 1)))) {
Real forceMACZ = 0.5 * (force(i, j, k - 1).z + force(i, j, k).z);
Real min = std::min(vel(i, j, k).z, forceMACZ);
Real max = std::max(vel(i, j, k).z, forceMACZ);
Real sum = vel(i, j, k).z + forceMACZ;
vel(i, j, k).z = (forceMACZ > 0) ? std::min(sum, max) : std::max(sum, min);
minVal = min(vel(i, j, k).z, forceMACZ);
maxVal = max(vel(i, j, k).z, forceMACZ);
sum = vel(i, j, k).z + forceMACZ;
vel(i, j, k).z = (forceMACZ > 0) ? min(sum, maxVal) : max(sum, minVal);
}
}
inline const FlagGrid &getArg0()

View File

@@ -1138,11 +1138,15 @@ void solvePressureSystem(Grid<Real> &rhs,
// note: the last factor increases the max iterations for 2d, which right now can't use a
// preconditioner
GridCgInterface *gcg;
if (vel.is3D())
gcg = new GridCg<ApplyMatrix>(pressure, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
else
gcg = new GridCg<ApplyMatrix2D>(
pressure, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
vector<Grid<Real> *> matA{&A0, &Ai, &Aj};
if (vel.is3D()) {
matA.push_back(&Ak);
gcg = new GridCg<ApplyMatrix>(pressure, rhs, residual, search, flags, tmp, matA);
}
else {
gcg = new GridCg<ApplyMatrix2D>(pressure, rhs, residual, search, flags, tmp, matA);
}
gcg->setAccuracy(cgAccuracy);
gcg->setUseL2Norm(useL2Norm);

File diff suppressed because it is too large Load Diff

View File

@@ -576,8 +576,10 @@ void VICintegration(VortexSheetMesh &mesh,
// prepare CG solver
const int maxIter = (int)(cgMaxIterFac * vel.getSize().max());
vector<Grid<Real> *> matA{&A0, &Ai, &Aj, &Ak};
GridCgInterface *gcg = new GridCg<ApplyMatrix>(
solution, rhs, residual, search, flags, temp1, &A0, &Ai, &Aj, &Ak);
solution, rhs, residual, search, flags, temp1, matA);
gcg->setAccuracy(cgAccuracy);
gcg->setUseL2Norm(true);
gcg->setICPreconditioner(

View File

@@ -423,10 +423,15 @@ void cgSolveWE(const FlagGrid &flags,
const int maxIter = (int)(cgMaxIterFac * flags.getSize().max()) * (flags.is3D() ? 1 : 4);
GridCgInterface *gcg;
if (flags.is3D())
gcg = new GridCg<ApplyMatrix>(out, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
else
gcg = new GridCg<ApplyMatrix2D>(out, rhs, residual, search, flags, tmp, &A0, &Ai, &Aj, &Ak);
vector<Grid<Real> *> matA{&A0, &Ai, &Aj};
if (flags.is3D()) {
matA.push_back(&Ak);
gcg = new GridCg<ApplyMatrix>(out, rhs, residual, search, flags, tmp, matA);
}
else {
gcg = new GridCg<ApplyMatrix2D>(out, rhs, residual, search, flags, tmp, matA);
}
gcg->setAccuracy(cgAccuracy);

View File

@@ -145,6 +145,7 @@ extern void PbRegister_flipComputeSurfaceNormals();
extern void PbRegister_flipUpdateNeighborRatio();
extern void PbRegister_particleSurfaceTurbulence();
extern void PbRegister_debugCheckParts();
extern void PbRegister_applyViscosity();
extern void PbRegister_markAsFixed();
extern void PbRegister_texcoordInflow();
extern void PbRegister_meshSmokeInflow();
@@ -342,6 +343,7 @@ void MantaEnsureRegistration()
PbRegister_flipUpdateNeighborRatio();
PbRegister_particleSurfaceTurbulence();
PbRegister_debugCheckParts();
PbRegister_applyViscosity();
PbRegister_markAsFixed();
PbRegister_texcoordInflow();
PbRegister_meshSmokeInflow();

View File

@@ -282,7 +282,7 @@ def list_render_passes(scene, srl):
yield ("CryptoAsset" + '{:02d}'.format(i), "RGBA", 'COLOR')
# Denoising passes.
if crl.use_denoising or crl.denoising_store_passes:
if (scene.cycles.use_denoising and crl.use_denoising) or crl.denoising_store_passes:
yield ("Noisy Image", "RGBA", 'COLOR')
if crl.denoising_store_passes:
yield ("Denoising Normal", "XYZ", 'VECTOR')

View File

@@ -1570,7 +1570,7 @@ class CyclesPreferences(bpy.types.AddonPreferences):
elif entry.type == 'CPU':
cpu_devices.append(entry)
# Extend all GPU devices with CPU.
if compute_device_type in {'CUDA', 'OPENCL'}:
if compute_device_type in {'CUDA', 'OPTIX', 'OPENCL'}:
devices.extend(cpu_devices)
return devices

View File

@@ -1148,7 +1148,7 @@ class CYCLES_PT_context_material(CyclesButtonsPanel, Panel):
split = layout.split(factor=0.65)
if ob:
split.template_ID(ob, "active_material", new="material.new")
split.template_ID(ob, "active_material", new="material.new", duplicate="material.duplicate")
row = split.row()
if slot:
@@ -1443,6 +1443,7 @@ class CYCLES_LIGHT_PT_nodes(CyclesButtonsPanel, Panel):
class CYCLES_LIGHT_PT_spot(CyclesButtonsPanel, Panel):
bl_label = "Spot Shape"
bl_parent_id = "CYCLES_LIGHT_PT_light"
bl_context = "data"
@classmethod
@@ -1454,7 +1455,6 @@ class CYCLES_LIGHT_PT_spot(CyclesButtonsPanel, Panel):
layout = self.layout
light = context.light
layout.use_property_split = True
layout.use_property_decorate = False
col = layout.column()
col.prop(light, "spot_size", text="Size")
@@ -1969,9 +1969,11 @@ class CYCLES_RENDER_PT_bake_output(CyclesButtonsPanel, Panel):
if rd.bake_type == 'DISPLACEMENT':
layout.prop(rd, "use_bake_lores_mesh")
else:
layout.prop(cbk, "target")
layout.prop(cbk, "margin")
layout.prop(cbk, "use_clear", text="Clear Image")
if cbk.target == 'IMAGE_TEXTURES':
layout.prop(cbk, "margin")
layout.prop(cbk, "use_clear", text="Clear Image")
class CYCLES_RENDER_PT_debug(CyclesButtonsPanel, Panel):

View File

@@ -43,42 +43,41 @@ int blender_device_threads(BL::Scene &b_scene)
DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scene, bool background)
{
if (BlenderSession::device_override != DEVICE_MASK_ALL) {
vector<DeviceInfo> devices = Device::available_devices(BlenderSession::device_override);
if (devices.empty()) {
return Device::dummy_device("Found no Cycles device of the specified type");
}
int threads = blender_device_threads(b_scene);
return Device::get_multi_device(devices, threads, background);
}
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
/* Find cycles preferences. */
PointerRNA cpreferences;
BL::Preferences::addons_iterator b_addon_iter;
for (b_preferences.addons.begin(b_addon_iter); b_addon_iter != b_preferences.addons.end();
++b_addon_iter) {
if (b_addon_iter->module() == "cycles") {
cpreferences = b_addon_iter->preferences().ptr;
break;
}
}
/* Default to CPU device. */
DeviceInfo device = Device::available_devices(DEVICE_MASK_CPU).front();
if (get_enum(cscene, "device") == 2) {
if (BlenderSession::device_override != DEVICE_MASK_ALL) {
vector<DeviceInfo> devices = Device::available_devices(BlenderSession::device_override);
if (devices.empty()) {
device = Device::dummy_device("Found no Cycles device of the specified type");
}
else {
int threads = blender_device_threads(b_scene);
device = Device::get_multi_device(devices, threads, background);
}
}
else if (get_enum(cscene, "device") == 2) {
/* Find network device. */
vector<DeviceInfo> devices = Device::available_devices(DEVICE_MASK_NETWORK);
if (!devices.empty()) {
return devices.front();
device = devices.front();
}
}
else if (get_enum(cscene, "device") == 1) {
/* Find cycles preferences. */
PointerRNA cpreferences;
BL::Preferences::addons_iterator b_addon_iter;
for (b_preferences.addons.begin(b_addon_iter); b_addon_iter != b_preferences.addons.end();
++b_addon_iter) {
if (b_addon_iter->module() == "cycles") {
cpreferences = b_addon_iter->preferences().ptr;
break;
}
}
/* Test if we are using GPU devices. */
ComputeDevice compute_device = (ComputeDevice)get_enum(
cpreferences, "compute_device_type", COMPUTE_DEVICE_NUM, COMPUTE_DEVICE_CPU);
@@ -90,8 +89,7 @@ DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scen
mask |= DEVICE_MASK_CUDA;
}
else if (compute_device == COMPUTE_DEVICE_OPTIX) {
/* Cannot use CPU and OptiX device at the same time right now, so replace mask. */
mask = DEVICE_MASK_OPTIX;
mask |= DEVICE_MASK_OPTIX;
}
else if (compute_device == COMPUTE_DEVICE_OPENCL) {
mask |= DEVICE_MASK_OPENCL;
@@ -118,13 +116,13 @@ DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scen
device = Device::get_multi_device(used_devices, threads, background);
}
/* Else keep using the CPU device that was set before. */
if (!get_boolean(cpreferences, "peer_memory")) {
device.has_peer_memory = false;
}
}
}
if (!get_boolean(cpreferences, "peer_memory")) {
device.has_peer_memory = false;
}
return device;
}

View File

@@ -351,6 +351,10 @@ static bool lookup_property(BL::ID b_id, const string &name, float4 *r_value)
return false;
}
if (prop == NULL) {
return false;
}
PropertyType type = RNA_property_type(prop);
int arraylen = RNA_property_array_length(&ptr, prop);

View File

@@ -25,6 +25,7 @@ set(SRC
bvh_binning.cpp
bvh_build.cpp
bvh_embree.cpp
bvh_multi.cpp
bvh_node.cpp
bvh_optix.cpp
bvh_sort.cpp
@@ -38,6 +39,7 @@ set(SRC_HEADERS
bvh_binning.h
bvh_build.h
bvh_embree.h
bvh_multi.h
bvh_node.h
bvh_optix.h
bvh_params.h

View File

@@ -17,17 +17,11 @@
#include "bvh/bvh.h"
#include "render/hair.h"
#include "render/mesh.h"
#include "render/object.h"
#include "bvh/bvh2.h"
#include "bvh/bvh_build.h"
#include "bvh/bvh_embree.h"
#include "bvh/bvh_node.h"
#include "bvh/bvh_multi.h"
#include "bvh/bvh_optix.h"
#include "util/util_foreach.h"
#include "util/util_logging.h"
#include "util/util_progress.h"
@@ -38,14 +32,17 @@ CCL_NAMESPACE_BEGIN
const char *bvh_layout_name(BVHLayout layout)
{
switch (layout) {
case BVH_LAYOUT_BVH2:
return "BVH2";
case BVH_LAYOUT_NONE:
return "NONE";
case BVH_LAYOUT_BVH2:
return "BVH2";
case BVH_LAYOUT_EMBREE:
return "EMBREE";
case BVH_LAYOUT_OPTIX:
return "OPTIX";
case BVH_LAYOUT_MULTI_OPTIX:
case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
return "MULTI";
case BVH_LAYOUT_ALL:
return "ALL";
}
@@ -76,17 +73,6 @@ BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask s
return (BVHLayout)(1 << widest_allowed_layout_mask);
}
/* Pack Utility */
BVHStackEntry::BVHStackEntry(const BVHNode *n, int i) : node(n), idx(i)
{
}
int BVHStackEntry::encodeIdx() const
{
return (node->is_leaf()) ? ~idx : idx;
}
/* BVH */
BVH::BVH(const BVHParams &params_,
@@ -99,24 +85,27 @@ BVH::BVH(const BVHParams &params_,
BVH *BVH::create(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects,
const Device *device)
Device *device)
{
switch (params.bvh_layout) {
case BVH_LAYOUT_BVH2:
return new BVH2(params, geometry, objects);
case BVH_LAYOUT_EMBREE:
#ifdef WITH_EMBREE
return new BVHEmbree(params, geometry, objects, device);
return new BVHEmbree(params, geometry, objects);
#else
(void)device;
break;
#endif
case BVH_LAYOUT_OPTIX:
#ifdef WITH_OPTIX
return new BVHOptiX(params, geometry, objects);
return new BVHOptiX(params, geometry, objects, device);
#else
(void)device;
break;
#endif
case BVH_LAYOUT_MULTI_OPTIX:
case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
return new BVHMulti(params, geometry, objects);
case BVH_LAYOUT_NONE:
case BVH_LAYOUT_ALL:
break;
@@ -125,399 +114,4 @@ BVH *BVH::create(const BVHParams &params,
return NULL;
}
/* Building */
void BVH::build(Progress &progress, Stats *)
{
progress.set_substatus("Building BVH");
/* build nodes */
BVHBuild bvh_build(objects,
pack.prim_type,
pack.prim_index,
pack.prim_object,
pack.prim_time,
params,
progress);
BVHNode *bvh2_root = bvh_build.run();
if (progress.get_cancel()) {
if (bvh2_root != NULL) {
bvh2_root->deleteSubtree();
}
return;
}
/* BVH builder returns tree in a binary mode (with two children per inner
* node. Need to adopt that for a wider BVH implementations. */
BVHNode *root = widen_children_nodes(bvh2_root);
if (root != bvh2_root) {
bvh2_root->deleteSubtree();
}
if (progress.get_cancel()) {
if (root != NULL) {
root->deleteSubtree();
}
return;
}
/* pack triangles */
progress.set_substatus("Packing BVH triangles and strands");
pack_primitives();
if (progress.get_cancel()) {
root->deleteSubtree();
return;
}
/* pack nodes */
progress.set_substatus("Packing BVH nodes");
pack_nodes(root);
/* free build nodes */
root->deleteSubtree();
}
/* Refitting */
void BVH::refit(Progress &progress)
{
progress.set_substatus("Packing BVH primitives");
pack_primitives();
if (progress.get_cancel())
return;
progress.set_substatus("Refitting BVH nodes");
refit_nodes();
}
void BVH::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility)
{
/* Refit range of primitives. */
for (int prim = start; prim < end; prim++) {
int pidx = pack.prim_index[prim];
int tob = pack.prim_object[prim];
Object *ob = objects[tob];
if (pidx == -1) {
/* Object instance. */
bbox.grow(ob->bounds);
}
else {
/* Primitives. */
if (pack.prim_type[prim] & PRIMITIVE_ALL_CURVE) {
/* Curves. */
const Hair *hair = static_cast<const Hair *>(ob->get_geometry());
int prim_offset = (params.top_level) ? hair->prim_offset : 0;
Hair::Curve curve = hair->get_curve(pidx - prim_offset);
int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]);
curve.bounds_grow(k, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], bbox);
/* Motion curves. */
if (hair->get_use_motion_blur()) {
Attribute *attr = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr) {
size_t hair_size = hair->get_curve_keys().size();
size_t steps = hair->get_motion_steps() - 1;
float3 *key_steps = attr->data_float3();
for (size_t i = 0; i < steps; i++)
curve.bounds_grow(k, key_steps + i * hair_size, &hair->get_curve_radius()[0], bbox);
}
}
}
else {
/* Triangles. */
const Mesh *mesh = static_cast<const Mesh *>(ob->get_geometry());
int prim_offset = (params.top_level) ? mesh->prim_offset : 0;
Mesh::Triangle triangle = mesh->get_triangle(pidx - prim_offset);
const float3 *vpos = &mesh->verts[0];
triangle.bounds_grow(vpos, bbox);
/* Motion triangles. */
if (mesh->use_motion_blur) {
Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr) {
size_t mesh_size = mesh->verts.size();
size_t steps = mesh->motion_steps - 1;
float3 *vert_steps = attr->data_float3();
for (size_t i = 0; i < steps; i++)
triangle.bounds_grow(vert_steps + i * mesh_size, bbox);
}
}
}
}
visibility |= ob->visibility_for_tracing();
}
}
/* Triangles */
void BVH::pack_triangle(int idx, float4 tri_verts[3])
{
int tob = pack.prim_object[idx];
assert(tob >= 0 && tob < objects.size());
const Mesh *mesh = static_cast<const Mesh *>(objects[tob]->get_geometry());
int tidx = pack.prim_index[idx];
Mesh::Triangle t = mesh->get_triangle(tidx);
const float3 *vpos = &mesh->verts[0];
float3 v0 = vpos[t.v[0]];
float3 v1 = vpos[t.v[1]];
float3 v2 = vpos[t.v[2]];
tri_verts[0] = float3_to_float4(v0);
tri_verts[1] = float3_to_float4(v1);
tri_verts[2] = float3_to_float4(v2);
}
void BVH::pack_primitives()
{
const size_t tidx_size = pack.prim_index.size();
size_t num_prim_triangles = 0;
/* Count number of triangles primitives in BVH. */
for (unsigned int i = 0; i < tidx_size; i++) {
if ((pack.prim_index[i] != -1)) {
if ((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) {
++num_prim_triangles;
}
}
}
/* Reserve size for arrays. */
pack.prim_tri_index.clear();
pack.prim_tri_index.resize(tidx_size);
pack.prim_tri_verts.clear();
pack.prim_tri_verts.resize(num_prim_triangles * 3);
pack.prim_visibility.clear();
pack.prim_visibility.resize(tidx_size);
/* Fill in all the arrays. */
size_t prim_triangle_index = 0;
for (unsigned int i = 0; i < tidx_size; i++) {
if (pack.prim_index[i] != -1) {
int tob = pack.prim_object[i];
Object *ob = objects[tob];
if ((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) {
pack_triangle(i, (float4 *)&pack.prim_tri_verts[3 * prim_triangle_index]);
pack.prim_tri_index[i] = 3 * prim_triangle_index;
++prim_triangle_index;
}
else {
pack.prim_tri_index[i] = -1;
}
pack.prim_visibility[i] = ob->visibility_for_tracing();
}
else {
pack.prim_tri_index[i] = -1;
pack.prim_visibility[i] = 0;
}
}
}
/* Pack Instances */
void BVH::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
{
/* Adjust primitive index to point to the triangle in the global array, for
* geometry with transform applied and already in the top level BVH.
*/
for (size_t i = 0; i < pack.prim_index.size(); i++) {
if (pack.prim_index[i] != -1) {
pack.prim_index[i] += objects[pack.prim_object[i]]->get_geometry()->prim_offset;
}
}
/* track offsets of instanced BVH data in global array */
size_t prim_offset = pack.prim_index.size();
size_t nodes_offset = nodes_size;
size_t nodes_leaf_offset = leaf_nodes_size;
/* clear array that gives the node indexes for instanced objects */
pack.object_node.clear();
/* reserve */
size_t prim_index_size = pack.prim_index.size();
size_t prim_tri_verts_size = pack.prim_tri_verts.size();
size_t pack_prim_index_offset = prim_index_size;
size_t pack_prim_tri_verts_offset = prim_tri_verts_size;
size_t pack_nodes_offset = nodes_size;
size_t pack_leaf_nodes_offset = leaf_nodes_size;
size_t object_offset = 0;
foreach (Geometry *geom, geometry) {
BVH *bvh = geom->bvh;
if (geom->need_build_bvh(params.bvh_layout)) {
prim_index_size += bvh->pack.prim_index.size();
prim_tri_verts_size += bvh->pack.prim_tri_verts.size();
nodes_size += bvh->pack.nodes.size();
leaf_nodes_size += bvh->pack.leaf_nodes.size();
}
}
pack.prim_index.resize(prim_index_size);
pack.prim_type.resize(prim_index_size);
pack.prim_object.resize(prim_index_size);
pack.prim_visibility.resize(prim_index_size);
pack.prim_tri_verts.resize(prim_tri_verts_size);
pack.prim_tri_index.resize(prim_index_size);
pack.nodes.resize(nodes_size);
pack.leaf_nodes.resize(leaf_nodes_size);
pack.object_node.resize(objects.size());
if (params.num_motion_curve_steps > 0 || params.num_motion_triangle_steps > 0) {
pack.prim_time.resize(prim_index_size);
}
int *pack_prim_index = (pack.prim_index.size()) ? &pack.prim_index[0] : NULL;
int *pack_prim_type = (pack.prim_type.size()) ? &pack.prim_type[0] : NULL;
int *pack_prim_object = (pack.prim_object.size()) ? &pack.prim_object[0] : NULL;
uint *pack_prim_visibility = (pack.prim_visibility.size()) ? &pack.prim_visibility[0] : NULL;
float4 *pack_prim_tri_verts = (pack.prim_tri_verts.size()) ? &pack.prim_tri_verts[0] : NULL;
uint *pack_prim_tri_index = (pack.prim_tri_index.size()) ? &pack.prim_tri_index[0] : NULL;
int4 *pack_nodes = (pack.nodes.size()) ? &pack.nodes[0] : NULL;
int4 *pack_leaf_nodes = (pack.leaf_nodes.size()) ? &pack.leaf_nodes[0] : NULL;
float2 *pack_prim_time = (pack.prim_time.size()) ? &pack.prim_time[0] : NULL;
map<Geometry *, int> geometry_map;
/* merge */
foreach (Object *ob, objects) {
Geometry *geom = ob->get_geometry();
/* We assume that if mesh doesn't need own BVH it was already included
* into a top-level BVH and no packing here is needed.
*/
if (!geom->need_build_bvh(params.bvh_layout)) {
pack.object_node[object_offset++] = 0;
continue;
}
/* if mesh already added once, don't add it again, but used set
* node offset for this object */
map<Geometry *, int>::iterator it = geometry_map.find(geom);
if (geometry_map.find(geom) != geometry_map.end()) {
int noffset = it->second;
pack.object_node[object_offset++] = noffset;
continue;
}
BVH *bvh = geom->bvh;
int noffset = nodes_offset;
int noffset_leaf = nodes_leaf_offset;
int geom_prim_offset = geom->prim_offset;
/* fill in node indexes for instances */
if (bvh->pack.root_index == -1)
pack.object_node[object_offset++] = -noffset_leaf - 1;
else
pack.object_node[object_offset++] = noffset;
geometry_map[geom] = pack.object_node[object_offset - 1];
/* merge primitive, object and triangle indexes */
if (bvh->pack.prim_index.size()) {
size_t bvh_prim_index_size = bvh->pack.prim_index.size();
int *bvh_prim_index = &bvh->pack.prim_index[0];
int *bvh_prim_type = &bvh->pack.prim_type[0];
uint *bvh_prim_visibility = &bvh->pack.prim_visibility[0];
uint *bvh_prim_tri_index = &bvh->pack.prim_tri_index[0];
float2 *bvh_prim_time = bvh->pack.prim_time.size() ? &bvh->pack.prim_time[0] : NULL;
for (size_t i = 0; i < bvh_prim_index_size; i++) {
if (bvh->pack.prim_type[i] & PRIMITIVE_ALL_CURVE) {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = -1;
}
else {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = bvh_prim_tri_index[i] +
pack_prim_tri_verts_offset;
}
pack_prim_type[pack_prim_index_offset] = bvh_prim_type[i];
pack_prim_visibility[pack_prim_index_offset] = bvh_prim_visibility[i];
pack_prim_object[pack_prim_index_offset] = 0; // unused for instances
if (bvh_prim_time != NULL) {
pack_prim_time[pack_prim_index_offset] = bvh_prim_time[i];
}
pack_prim_index_offset++;
}
}
/* Merge triangle vertices data. */
if (bvh->pack.prim_tri_verts.size()) {
const size_t prim_tri_size = bvh->pack.prim_tri_verts.size();
memcpy(pack_prim_tri_verts + pack_prim_tri_verts_offset,
&bvh->pack.prim_tri_verts[0],
prim_tri_size * sizeof(float4));
pack_prim_tri_verts_offset += prim_tri_size;
}
/* merge nodes */
if (bvh->pack.leaf_nodes.size()) {
int4 *leaf_nodes_offset = &bvh->pack.leaf_nodes[0];
size_t leaf_nodes_offset_size = bvh->pack.leaf_nodes.size();
for (size_t i = 0, j = 0; i < leaf_nodes_offset_size; i += BVH_NODE_LEAF_SIZE, j++) {
int4 data = leaf_nodes_offset[i];
data.x += prim_offset;
data.y += prim_offset;
pack_leaf_nodes[pack_leaf_nodes_offset] = data;
for (int j = 1; j < BVH_NODE_LEAF_SIZE; ++j) {
pack_leaf_nodes[pack_leaf_nodes_offset + j] = leaf_nodes_offset[i + j];
}
pack_leaf_nodes_offset += BVH_NODE_LEAF_SIZE;
}
}
if (bvh->pack.nodes.size()) {
int4 *bvh_nodes = &bvh->pack.nodes[0];
size_t bvh_nodes_size = bvh->pack.nodes.size();
for (size_t i = 0, j = 0; i < bvh_nodes_size; j++) {
size_t nsize, nsize_bbox;
if (bvh_nodes[i].x & PATH_RAY_NODE_UNALIGNED) {
nsize = BVH_UNALIGNED_NODE_SIZE;
nsize_bbox = 0;
}
else {
nsize = BVH_NODE_SIZE;
nsize_bbox = 0;
}
memcpy(pack_nodes + pack_nodes_offset, bvh_nodes + i, nsize_bbox * sizeof(int4));
/* Modify offsets into arrays */
int4 data = bvh_nodes[i + nsize_bbox];
data.z += (data.z < 0) ? -noffset_leaf : noffset;
data.w += (data.w < 0) ? -noffset_leaf : noffset;
pack_nodes[pack_nodes_offset + nsize_bbox] = data;
/* Usually this copies nothing, but we better
* be prepared for possible node size extension.
*/
memcpy(&pack_nodes[pack_nodes_offset + nsize_bbox + 1],
&bvh_nodes[i + nsize_bbox + 1],
sizeof(int4) * (nsize - (nsize_bbox + 1)));
pack_nodes_offset += nsize;
i += nsize;
}
}
nodes_offset += bvh->pack.nodes.size();
nodes_leaf_offset += bvh->pack.leaf_nodes.size();
prim_offset += bvh->pack.prim_index.size();
}
}
CCL_NAMESPACE_END

View File

@@ -25,17 +25,16 @@
CCL_NAMESPACE_BEGIN
class Stats;
class BoundBox;
class BVHNode;
class BVHParams;
class Device;
class DeviceScene;
class BVHNode;
struct BVHStackEntry;
class BVHParams;
class BoundBox;
class LeafNode;
class Geometry;
class LeafNode;
class Object;
class Progress;
class Stats;
#define BVH_ALIGN 4096
#define TRI_NODE_SIZE 3
@@ -76,13 +75,10 @@ struct PackedBVH {
}
};
enum BVH_TYPE { bvh2 };
/* BVH */
class BVH {
public:
PackedBVH pack;
BVHParams params;
vector<Geometry *> geometry;
vector<Object *> objects;
@@ -90,47 +86,15 @@ class BVH {
static BVH *create(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects,
const Device *device);
Device *device);
virtual ~BVH()
{
}
virtual void build(Progress &progress, Stats *stats = NULL);
virtual void copy_to_device(Progress & /*progress*/, DeviceScene * /*dscene*/)
{
}
void refit(Progress &progress);
protected:
BVH(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects);
/* Refit range of primitives. */
void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility);
/* triangles and strands */
void pack_primitives();
void pack_triangle(int idx, float4 storage[3]);
/* merge instance BVH's */
void pack_instances(size_t nodes_size, size_t leaf_nodes_size);
/* for subclasses to implement */
virtual void pack_nodes(const BVHNode *root) = 0;
virtual void refit_nodes() = 0;
virtual BVHNode *widen_children_nodes(const BVHNode *root) = 0;
};
/* Pack Utility */
struct BVHStackEntry {
const BVHNode *node;
int idx;
BVHStackEntry(const BVHNode *n = 0, int i = 0);
int encodeIdx() const;
};
CCL_NAMESPACE_END

View File

@@ -17,14 +17,28 @@
#include "bvh/bvh2.h"
#include "render/hair.h"
#include "render/mesh.h"
#include "render/object.h"
#include "bvh/bvh_build.h"
#include "bvh/bvh_node.h"
#include "bvh/bvh_unaligned.h"
#include "util/util_foreach.h"
#include "util/util_progress.h"
CCL_NAMESPACE_BEGIN
BVHStackEntry::BVHStackEntry(const BVHNode *n, int i) : node(n), idx(i)
{
}
int BVHStackEntry::encodeIdx() const
{
return (node->is_leaf()) ? ~idx : idx;
}
BVH2::BVH2(const BVHParams &params_,
const vector<Geometry *> &geometry_,
const vector<Object *> &objects_)
@@ -32,6 +46,70 @@ BVH2::BVH2(const BVHParams &params_,
{
}
void BVH2::build(Progress &progress, Stats *)
{
progress.set_substatus("Building BVH");
/* build nodes */
BVHBuild bvh_build(objects,
pack.prim_type,
pack.prim_index,
pack.prim_object,
pack.prim_time,
params,
progress);
BVHNode *bvh2_root = bvh_build.run();
if (progress.get_cancel()) {
if (bvh2_root != NULL) {
bvh2_root->deleteSubtree();
}
return;
}
/* BVH builder returns tree in a binary mode (with two children per inner
* node. Need to adopt that for a wider BVH implementations. */
BVHNode *root = widen_children_nodes(bvh2_root);
if (root != bvh2_root) {
bvh2_root->deleteSubtree();
}
if (progress.get_cancel()) {
if (root != NULL) {
root->deleteSubtree();
}
return;
}
/* pack triangles */
progress.set_substatus("Packing BVH triangles and strands");
pack_primitives();
if (progress.get_cancel()) {
root->deleteSubtree();
return;
}
/* pack nodes */
progress.set_substatus("Packing BVH nodes");
pack_nodes(root);
/* free build nodes */
root->deleteSubtree();
}
void BVH2::refit(Progress &progress)
{
progress.set_substatus("Packing BVH primitives");
pack_primitives();
if (progress.get_cancel())
return;
progress.set_substatus("Refitting BVH nodes");
refit_nodes();
}
BVHNode *BVH2::widen_children_nodes(const BVHNode *root)
{
return const_cast<BVHNode *>(root);
@@ -253,7 +331,7 @@ void BVH2::refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility)
const int c0 = data[0].x;
const int c1 = data[0].y;
BVH::refit_primitives(c0, c1, bbox, visibility);
refit_primitives(c0, c1, bbox, visibility);
/* TODO(sergey): De-duplicate with pack_leaf(). */
float4 leaf_data[BVH_NODE_LEAF_SIZE];
@@ -292,4 +370,333 @@ void BVH2::refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility)
}
}
/* Refitting */
void BVH2::refit_primitives(int start, int end, BoundBox &bbox, uint &visibility)
{
/* Refit range of primitives. */
for (int prim = start; prim < end; prim++) {
int pidx = pack.prim_index[prim];
int tob = pack.prim_object[prim];
Object *ob = objects[tob];
if (pidx == -1) {
/* Object instance. */
bbox.grow(ob->bounds);
}
else {
/* Primitives. */
if (pack.prim_type[prim] & PRIMITIVE_ALL_CURVE) {
/* Curves. */
const Hair *hair = static_cast<const Hair *>(ob->get_geometry());
int prim_offset = (params.top_level) ? hair->prim_offset : 0;
Hair::Curve curve = hair->get_curve(pidx - prim_offset);
int k = PRIMITIVE_UNPACK_SEGMENT(pack.prim_type[prim]);
curve.bounds_grow(k, &hair->get_curve_keys()[0], &hair->get_curve_radius()[0], bbox);
/* Motion curves. */
if (hair->get_use_motion_blur()) {
Attribute *attr = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr) {
size_t hair_size = hair->get_curve_keys().size();
size_t steps = hair->get_motion_steps() - 1;
float3 *key_steps = attr->data_float3();
for (size_t i = 0; i < steps; i++)
curve.bounds_grow(k, key_steps + i * hair_size, &hair->get_curve_radius()[0], bbox);
}
}
}
else {
/* Triangles. */
const Mesh *mesh = static_cast<const Mesh *>(ob->get_geometry());
int prim_offset = (params.top_level) ? mesh->prim_offset : 0;
Mesh::Triangle triangle = mesh->get_triangle(pidx - prim_offset);
const float3 *vpos = &mesh->verts[0];
triangle.bounds_grow(vpos, bbox);
/* Motion triangles. */
if (mesh->use_motion_blur) {
Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr) {
size_t mesh_size = mesh->verts.size();
size_t steps = mesh->motion_steps - 1;
float3 *vert_steps = attr->data_float3();
for (size_t i = 0; i < steps; i++)
triangle.bounds_grow(vert_steps + i * mesh_size, bbox);
}
}
}
}
visibility |= ob->visibility_for_tracing();
}
}
/* Triangles */
void BVH2::pack_triangle(int idx, float4 tri_verts[3])
{
int tob = pack.prim_object[idx];
assert(tob >= 0 && tob < objects.size());
const Mesh *mesh = static_cast<const Mesh *>(objects[tob]->get_geometry());
int tidx = pack.prim_index[idx];
Mesh::Triangle t = mesh->get_triangle(tidx);
const float3 *vpos = &mesh->verts[0];
float3 v0 = vpos[t.v[0]];
float3 v1 = vpos[t.v[1]];
float3 v2 = vpos[t.v[2]];
tri_verts[0] = float3_to_float4(v0);
tri_verts[1] = float3_to_float4(v1);
tri_verts[2] = float3_to_float4(v2);
}
void BVH2::pack_primitives()
{
const size_t tidx_size = pack.prim_index.size();
size_t num_prim_triangles = 0;
/* Count number of triangles primitives in BVH. */
for (unsigned int i = 0; i < tidx_size; i++) {
if ((pack.prim_index[i] != -1)) {
if ((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) {
++num_prim_triangles;
}
}
}
/* Reserve size for arrays. */
pack.prim_tri_index.clear();
pack.prim_tri_index.resize(tidx_size);
pack.prim_tri_verts.clear();
pack.prim_tri_verts.resize(num_prim_triangles * 3);
pack.prim_visibility.clear();
pack.prim_visibility.resize(tidx_size);
/* Fill in all the arrays. */
size_t prim_triangle_index = 0;
for (unsigned int i = 0; i < tidx_size; i++) {
if (pack.prim_index[i] != -1) {
int tob = pack.prim_object[i];
Object *ob = objects[tob];
if ((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) {
pack_triangle(i, (float4 *)&pack.prim_tri_verts[3 * prim_triangle_index]);
pack.prim_tri_index[i] = 3 * prim_triangle_index;
++prim_triangle_index;
}
else {
pack.prim_tri_index[i] = -1;
}
pack.prim_visibility[i] = ob->visibility_for_tracing();
}
else {
pack.prim_tri_index[i] = -1;
pack.prim_visibility[i] = 0;
}
}
}
/* Pack Instances */
void BVH2::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
{
/* Adjust primitive index to point to the triangle in the global array, for
* geometry with transform applied and already in the top level BVH.
*/
for (size_t i = 0; i < pack.prim_index.size(); i++) {
if (pack.prim_index[i] != -1) {
pack.prim_index[i] += objects[pack.prim_object[i]]->get_geometry()->prim_offset;
}
}
/* track offsets of instanced BVH data in global array */
size_t prim_offset = pack.prim_index.size();
size_t nodes_offset = nodes_size;
size_t nodes_leaf_offset = leaf_nodes_size;
/* clear array that gives the node indexes for instanced objects */
pack.object_node.clear();
/* reserve */
size_t prim_index_size = pack.prim_index.size();
size_t prim_tri_verts_size = pack.prim_tri_verts.size();
size_t pack_prim_index_offset = prim_index_size;
size_t pack_prim_tri_verts_offset = prim_tri_verts_size;
size_t pack_nodes_offset = nodes_size;
size_t pack_leaf_nodes_offset = leaf_nodes_size;
size_t object_offset = 0;
foreach (Geometry *geom, geometry) {
BVH2 *bvh = static_cast<BVH2 *>(geom->bvh);
if (geom->need_build_bvh(params.bvh_layout)) {
prim_index_size += bvh->pack.prim_index.size();
prim_tri_verts_size += bvh->pack.prim_tri_verts.size();
nodes_size += bvh->pack.nodes.size();
leaf_nodes_size += bvh->pack.leaf_nodes.size();
}
}
pack.prim_index.resize(prim_index_size);
pack.prim_type.resize(prim_index_size);
pack.prim_object.resize(prim_index_size);
pack.prim_visibility.resize(prim_index_size);
pack.prim_tri_verts.resize(prim_tri_verts_size);
pack.prim_tri_index.resize(prim_index_size);
pack.nodes.resize(nodes_size);
pack.leaf_nodes.resize(leaf_nodes_size);
pack.object_node.resize(objects.size());
if (params.num_motion_curve_steps > 0 || params.num_motion_triangle_steps > 0) {
pack.prim_time.resize(prim_index_size);
}
int *pack_prim_index = (pack.prim_index.size()) ? &pack.prim_index[0] : NULL;
int *pack_prim_type = (pack.prim_type.size()) ? &pack.prim_type[0] : NULL;
int *pack_prim_object = (pack.prim_object.size()) ? &pack.prim_object[0] : NULL;
uint *pack_prim_visibility = (pack.prim_visibility.size()) ? &pack.prim_visibility[0] : NULL;
float4 *pack_prim_tri_verts = (pack.prim_tri_verts.size()) ? &pack.prim_tri_verts[0] : NULL;
uint *pack_prim_tri_index = (pack.prim_tri_index.size()) ? &pack.prim_tri_index[0] : NULL;
int4 *pack_nodes = (pack.nodes.size()) ? &pack.nodes[0] : NULL;
int4 *pack_leaf_nodes = (pack.leaf_nodes.size()) ? &pack.leaf_nodes[0] : NULL;
float2 *pack_prim_time = (pack.prim_time.size()) ? &pack.prim_time[0] : NULL;
unordered_map<Geometry *, int> geometry_map;
/* merge */
foreach (Object *ob, objects) {
Geometry *geom = ob->get_geometry();
/* We assume that if mesh doesn't need own BVH it was already included
* into a top-level BVH and no packing here is needed.
*/
if (!geom->need_build_bvh(params.bvh_layout)) {
pack.object_node[object_offset++] = 0;
continue;
}
/* if mesh already added once, don't add it again, but used set
* node offset for this object */
unordered_map<Geometry *, int>::iterator it = geometry_map.find(geom);
if (geometry_map.find(geom) != geometry_map.end()) {
int noffset = it->second;
pack.object_node[object_offset++] = noffset;
continue;
}
BVH2 *bvh = static_cast<BVH2 *>(geom->bvh);
int noffset = nodes_offset;
int noffset_leaf = nodes_leaf_offset;
int geom_prim_offset = geom->prim_offset;
/* fill in node indexes for instances */
if (bvh->pack.root_index == -1)
pack.object_node[object_offset++] = -noffset_leaf - 1;
else
pack.object_node[object_offset++] = noffset;
geometry_map[geom] = pack.object_node[object_offset - 1];
/* merge primitive, object and triangle indexes */
if (bvh->pack.prim_index.size()) {
size_t bvh_prim_index_size = bvh->pack.prim_index.size();
int *bvh_prim_index = &bvh->pack.prim_index[0];
int *bvh_prim_type = &bvh->pack.prim_type[0];
uint *bvh_prim_visibility = &bvh->pack.prim_visibility[0];
uint *bvh_prim_tri_index = &bvh->pack.prim_tri_index[0];
float2 *bvh_prim_time = bvh->pack.prim_time.size() ? &bvh->pack.prim_time[0] : NULL;
for (size_t i = 0; i < bvh_prim_index_size; i++) {
if (bvh->pack.prim_type[i] & PRIMITIVE_ALL_CURVE) {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = -1;
}
else {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = bvh_prim_tri_index[i] +
pack_prim_tri_verts_offset;
}
pack_prim_type[pack_prim_index_offset] = bvh_prim_type[i];
pack_prim_visibility[pack_prim_index_offset] = bvh_prim_visibility[i];
pack_prim_object[pack_prim_index_offset] = 0; // unused for instances
if (bvh_prim_time != NULL) {
pack_prim_time[pack_prim_index_offset] = bvh_prim_time[i];
}
pack_prim_index_offset++;
}
}
/* Merge triangle vertices data. */
if (bvh->pack.prim_tri_verts.size()) {
const size_t prim_tri_size = bvh->pack.prim_tri_verts.size();
memcpy(pack_prim_tri_verts + pack_prim_tri_verts_offset,
&bvh->pack.prim_tri_verts[0],
prim_tri_size * sizeof(float4));
pack_prim_tri_verts_offset += prim_tri_size;
}
/* merge nodes */
if (bvh->pack.leaf_nodes.size()) {
int4 *leaf_nodes_offset = &bvh->pack.leaf_nodes[0];
size_t leaf_nodes_offset_size = bvh->pack.leaf_nodes.size();
for (size_t i = 0, j = 0; i < leaf_nodes_offset_size; i += BVH_NODE_LEAF_SIZE, j++) {
int4 data = leaf_nodes_offset[i];
data.x += prim_offset;
data.y += prim_offset;
pack_leaf_nodes[pack_leaf_nodes_offset] = data;
for (int j = 1; j < BVH_NODE_LEAF_SIZE; ++j) {
pack_leaf_nodes[pack_leaf_nodes_offset + j] = leaf_nodes_offset[i + j];
}
pack_leaf_nodes_offset += BVH_NODE_LEAF_SIZE;
}
}
if (bvh->pack.nodes.size()) {
int4 *bvh_nodes = &bvh->pack.nodes[0];
size_t bvh_nodes_size = bvh->pack.nodes.size();
for (size_t i = 0, j = 0; i < bvh_nodes_size; j++) {
size_t nsize, nsize_bbox;
if (bvh_nodes[i].x & PATH_RAY_NODE_UNALIGNED) {
nsize = BVH_UNALIGNED_NODE_SIZE;
nsize_bbox = 0;
}
else {
nsize = BVH_NODE_SIZE;
nsize_bbox = 0;
}
memcpy(pack_nodes + pack_nodes_offset, bvh_nodes + i, nsize_bbox * sizeof(int4));
/* Modify offsets into arrays */
int4 data = bvh_nodes[i + nsize_bbox];
data.z += (data.z < 0) ? -noffset_leaf : noffset;
data.w += (data.w < 0) ? -noffset_leaf : noffset;
pack_nodes[pack_nodes_offset + nsize_bbox] = data;
/* Usually this copies nothing, but we better
* be prepared for possible node size extension.
*/
memcpy(&pack_nodes[pack_nodes_offset + nsize_bbox + 1],
&bvh_nodes[i + nsize_bbox + 1],
sizeof(int4) * (nsize - (nsize_bbox + 1)));
pack_nodes_offset += nsize;
i += nsize;
}
}
nodes_offset += bvh->pack.nodes.size();
nodes_leaf_offset += bvh->pack.leaf_nodes.size();
prim_offset += bvh->pack.prim_index.size();
}
}
CCL_NAMESPACE_END

View File

@@ -26,23 +26,30 @@
CCL_NAMESPACE_BEGIN
class BVHNode;
struct BVHStackEntry;
class BVHParams;
class BoundBox;
class LeafNode;
class Object;
class Progress;
#define BVH_NODE_SIZE 4
#define BVH_NODE_LEAF_SIZE 1
#define BVH_UNALIGNED_NODE_SIZE 7
/* Pack Utility */
struct BVHStackEntry {
const BVHNode *node;
int idx;
BVHStackEntry(const BVHNode *n = 0, int i = 0);
int encodeIdx() const;
};
/* BVH2
*
* Typical BVH with each node having two children.
*/
class BVH2 : public BVH {
public:
void build(Progress &progress, Stats *stats);
void refit(Progress &progress);
PackedBVH pack;
protected:
/* constructor */
friend class BVH;
@@ -51,10 +58,10 @@ class BVH2 : public BVH {
const vector<Object *> &objects);
/* Building process. */
virtual BVHNode *widen_children_nodes(const BVHNode *root) override;
virtual BVHNode *widen_children_nodes(const BVHNode *root);
/* pack */
void pack_nodes(const BVHNode *root) override;
void pack_nodes(const BVHNode *root);
void pack_leaf(const BVHStackEntry &e, const LeafNode *leaf);
void pack_inner(const BVHStackEntry &e, const BVHStackEntry &e0, const BVHStackEntry &e1);
@@ -84,8 +91,18 @@ class BVH2 : public BVH {
uint visibility1);
/* refit */
void refit_nodes() override;
void refit_nodes();
void refit_node(int idx, bool leaf, BoundBox &bbox, uint &visibility);
/* Refit range of primitives. */
void refit_primitives(int start, int end, BoundBox &bbox, uint &visibility);
/* triangles and strands */
void pack_primitives();
void pack_triangle(int idx, float4 storage[3]);
/* merge instance BVH's */
void pack_instances(size_t nodes_size, size_t leaf_nodes_size);
};
CCL_NAMESPACE_END

View File

@@ -298,82 +298,31 @@ static bool rtc_progress_func(void *user_ptr, const double n)
return !progress->get_cancel();
}
static size_t count_primitives(Geometry *geom)
{
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
return mesh->num_triangles();
}
else if (geom->geometry_type == Geometry::HAIR) {
Hair *hair = static_cast<Hair *>(geom);
return hair->num_segments();
}
return 0;
}
BVHEmbree::BVHEmbree(const BVHParams &params_,
const vector<Geometry *> &geometry_,
const vector<Object *> &objects_,
const Device *device)
const vector<Object *> &objects_)
: BVH(params_, geometry_, objects_),
scene(NULL),
mem_used(0),
top_level(NULL),
rtc_device((RTCDevice)device->bvh_device()),
stats(NULL),
curve_subdivisions(params.curve_subdivisions),
build_quality(RTC_BUILD_QUALITY_REFIT),
dynamic_scene(true)
rtc_device(NULL),
build_quality(RTC_BUILD_QUALITY_REFIT)
{
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
rtcSetDeviceErrorFunction(rtc_device, rtc_error_func, NULL);
pack.root_index = -1;
}
BVHEmbree::~BVHEmbree()
{
if (!params.top_level) {
destroy(scene);
}
}
void BVHEmbree::destroy(RTCScene scene)
{
if (scene) {
rtcReleaseScene(scene);
scene = NULL;
}
}
void BVHEmbree::delete_rtcScene()
{
if (scene) {
/* When this BVH is used as an instance in a top level BVH, don't delete now
* Let the top_level BVH know that it should delete it later. */
if (top_level) {
top_level->add_delayed_delete_scene(scene);
}
else {
rtcReleaseScene(scene);
if (delayed_delete_scenes.size()) {
foreach (RTCScene s, delayed_delete_scenes) {
rtcReleaseScene(s);
}
}
delayed_delete_scenes.clear();
}
scene = NULL;
}
}
void BVHEmbree::build(Progress &progress, Stats *stats_)
void BVHEmbree::build(Progress &progress, Stats *stats, RTCDevice rtc_device_)
{
rtc_device = rtc_device_;
assert(rtc_device);
stats = stats_;
rtcSetDeviceErrorFunction(rtc_device, rtc_error_func, NULL);
rtcSetDeviceMemoryMonitorFunction(rtc_device, rtc_memory_monitor_func, stats);
progress.set_substatus("Building BVH");
@@ -394,35 +343,7 @@ void BVHEmbree::build(Progress &progress, Stats *stats_)
RTC_BUILD_QUALITY_MEDIUM);
rtcSetSceneBuildQuality(scene, build_quality);
/* Count triangles and curves first, reserve arrays once. */
size_t prim_count = 0;
foreach (Object *ob, objects) {
if (params.top_level) {
if (!ob->is_traceable()) {
continue;
}
if (!ob->get_geometry()->is_instanced()) {
prim_count += count_primitives(ob->get_geometry());
}
else {
++prim_count;
}
}
else {
prim_count += count_primitives(ob->get_geometry());
}
}
pack.prim_object.reserve(prim_count);
pack.prim_type.reserve(prim_count);
pack.prim_index.reserve(prim_count);
pack.prim_tri_index.reserve(prim_count);
int i = 0;
pack.object_node.clear();
foreach (Object *ob, objects) {
if (params.top_level) {
if (!ob->is_traceable()) {
@@ -445,37 +366,11 @@ void BVHEmbree::build(Progress &progress, Stats *stats_)
}
if (progress.get_cancel()) {
delete_rtcScene();
stats = NULL;
return;
}
rtcSetSceneProgressMonitorFunction(scene, rtc_progress_func, &progress);
rtcCommitScene(scene);
pack_primitives();
if (progress.get_cancel()) {
delete_rtcScene();
stats = NULL;
return;
}
progress.set_substatus("Packing geometry");
pack_nodes(NULL);
stats = NULL;
}
void BVHEmbree::copy_to_device(Progress & /*progress*/, DeviceScene *dscene)
{
dscene->data.bvh.scene = scene;
}
BVHNode *BVHEmbree::widen_children_nodes(const BVHNode * /*root*/)
{
assert(!"Must not be called.");
return NULL;
}
void BVHEmbree::add_object(Object *ob, int i)
@@ -498,15 +393,8 @@ void BVHEmbree::add_object(Object *ob, int i)
void BVHEmbree::add_instance(Object *ob, int i)
{
if (!ob || !ob->get_geometry()) {
assert(0);
return;
}
BVHEmbree *instance_bvh = (BVHEmbree *)(ob->get_geometry()->bvh);
if (instance_bvh->top_level != this) {
instance_bvh->top_level = this;
}
assert(instance_bvh != NULL);
const size_t num_object_motion_steps = ob->use_motion() ? ob->get_motion().size() : 1;
const size_t num_motion_steps = min(num_object_motion_steps, RTC_MAX_TIME_STEP_COUNT);
@@ -538,11 +426,6 @@ void BVHEmbree::add_instance(Object *ob, int i)
geom_id, 0, RTC_FORMAT_FLOAT3X4_ROW_MAJOR, (const float *)&ob->get_tfm());
}
pack.prim_index.push_back_slow(-1);
pack.prim_object.push_back_slow(i);
pack.prim_type.push_back_slow(PRIMITIVE_NONE);
pack.prim_tri_index.push_back_slow(-1);
rtcSetGeometryUserData(geom_id, (void *)instance_bvh->scene);
rtcSetGeometryMask(geom_id, ob->visibility_for_tracing());
@@ -553,20 +436,22 @@ void BVHEmbree::add_instance(Object *ob, int i)
void BVHEmbree::add_triangles(const Object *ob, const Mesh *mesh, int i)
{
size_t prim_offset = pack.prim_index.size();
size_t prim_offset = mesh->optix_prim_offset;
const Attribute *attr_mP = NULL;
size_t num_geometry_motion_steps = 1;
size_t num_motion_steps = 1;
if (mesh->has_motion_blur()) {
attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr_mP) {
num_geometry_motion_steps = mesh->get_motion_steps();
num_motion_steps = mesh->get_motion_steps();
}
}
const size_t num_motion_steps = min(num_geometry_motion_steps, RTC_MAX_TIME_STEP_COUNT);
assert(num_geometry_motion_steps <= RTC_MAX_TIME_STEP_COUNT);
assert(num_motion_steps <= RTC_MAX_TIME_STEP_COUNT);
num_motion_steps = min(num_motion_steps, RTC_MAX_TIME_STEP_COUNT);
const size_t num_triangles = mesh->num_triangles();
RTCGeometry geom_id = rtcNewGeometry(rtc_device, RTC_GEOMETRY_TYPE_TRIANGLE);
rtcSetGeometryBuildQuality(geom_id, build_quality);
rtcSetGeometryTimeStepCount(geom_id, num_motion_steps);
@@ -588,22 +473,6 @@ void BVHEmbree::add_triangles(const Object *ob, const Mesh *mesh, int i)
set_tri_vertex_buffer(geom_id, mesh, false);
size_t prim_object_size = pack.prim_object.size();
pack.prim_object.resize(prim_object_size + num_triangles);
size_t prim_type_size = pack.prim_type.size();
pack.prim_type.resize(prim_type_size + num_triangles);
size_t prim_index_size = pack.prim_index.size();
pack.prim_index.resize(prim_index_size + num_triangles);
pack.prim_tri_index.resize(prim_index_size + num_triangles);
int prim_type = (num_motion_steps > 1 ? PRIMITIVE_MOTION_TRIANGLE : PRIMITIVE_TRIANGLE);
for (size_t j = 0; j < num_triangles; ++j) {
pack.prim_object[prim_object_size + j] = i;
pack.prim_type[prim_type_size + j] = prim_type;
pack.prim_index[prim_index_size + j] = j;
pack.prim_tri_index[prim_index_size + j] = j;
}
rtcSetGeometryUserData(geom_id, (void *)prim_offset);
rtcSetGeometryOccludedFilterFunction(geom_id, rtc_filter_occluded_func);
rtcSetGeometryMask(geom_id, ob->visibility_for_tracing());
@@ -629,12 +498,12 @@ void BVHEmbree::set_tri_vertex_buffer(RTCGeometry geom_id, const Mesh *mesh, con
}
}
}
const size_t num_verts = mesh->verts.size();
const size_t num_verts = mesh->get_verts().size();
for (int t = 0; t < num_motion_steps; ++t) {
const float3 *verts;
if (t == t_mid) {
verts = &mesh->verts[0];
verts = mesh->get_verts().data();
}
else {
int t_ = (t > t_mid) ? (t - 1) : t;
@@ -736,24 +605,19 @@ void BVHEmbree::set_curve_vertex_buffer(RTCGeometry geom_id, const Hair *hair, c
void BVHEmbree::add_curves(const Object *ob, const Hair *hair, int i)
{
size_t prim_offset = pack.prim_index.size();
size_t prim_offset = hair->optix_prim_offset;
const Attribute *attr_mP = NULL;
size_t num_geometry_motion_steps = 1;
size_t num_motion_steps = 1;
if (hair->has_motion_blur()) {
attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
if (attr_mP) {
num_geometry_motion_steps = hair->get_motion_steps();
num_motion_steps = hair->get_motion_steps();
}
}
const size_t num_motion_steps = min(num_geometry_motion_steps, RTC_MAX_TIME_STEP_COUNT);
const PrimitiveType primitive_type =
(num_motion_steps > 1) ?
((hair->curve_shape == CURVE_RIBBON) ? PRIMITIVE_MOTION_CURVE_RIBBON :
PRIMITIVE_MOTION_CURVE_THICK) :
((hair->curve_shape == CURVE_RIBBON) ? PRIMITIVE_CURVE_RIBBON : PRIMITIVE_CURVE_THICK);
assert(num_geometry_motion_steps <= RTC_MAX_TIME_STEP_COUNT);
assert(num_motion_steps <= RTC_MAX_TIME_STEP_COUNT);
num_motion_steps = min(num_motion_steps, RTC_MAX_TIME_STEP_COUNT);
const size_t num_curves = hair->num_curves();
size_t num_segments = 0;
@@ -763,22 +627,12 @@ void BVHEmbree::add_curves(const Object *ob, const Hair *hair, int i)
num_segments += c.num_segments();
}
/* Make room for Cycles specific data. */
size_t prim_object_size = pack.prim_object.size();
pack.prim_object.resize(prim_object_size + num_segments);
size_t prim_type_size = pack.prim_type.size();
pack.prim_type.resize(prim_type_size + num_segments);
size_t prim_index_size = pack.prim_index.size();
pack.prim_index.resize(prim_index_size + num_segments);
size_t prim_tri_index_size = pack.prim_index.size();
pack.prim_tri_index.resize(prim_tri_index_size + num_segments);
enum RTCGeometryType type = (hair->curve_shape == CURVE_RIBBON ?
RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE :
RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE);
RTCGeometry geom_id = rtcNewGeometry(rtc_device, type);
rtcSetGeometryTessellationRate(geom_id, curve_subdivisions + 1);
rtcSetGeometryTessellationRate(geom_id, params.curve_subdivisions + 1);
unsigned *rtc_indices = (unsigned *)rtcSetNewGeometryBuffer(
geom_id, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT, sizeof(int), num_segments);
size_t rtc_index = 0;
@@ -788,11 +642,6 @@ void BVHEmbree::add_curves(const Object *ob, const Hair *hair, int i)
rtc_indices[rtc_index] = c.first_key + k;
/* Room for extra CVs at Catmull-Rom splines. */
rtc_indices[rtc_index] += j * 2;
/* Cycles specific data. */
pack.prim_object[prim_object_size + rtc_index] = i;
pack.prim_type[prim_type_size + rtc_index] = (PRIMITIVE_PACK_SEGMENT(primitive_type, k));
pack.prim_index[prim_index_size + rtc_index] = j;
pack.prim_tri_index[prim_tri_index_size + rtc_index] = rtc_index;
++rtc_index;
}
@@ -818,134 +667,10 @@ void BVHEmbree::add_curves(const Object *ob, const Hair *hair, int i)
rtcReleaseGeometry(geom_id);
}
void BVHEmbree::pack_nodes(const BVHNode *)
void BVHEmbree::refit(Progress &progress)
{
/* Quite a bit of this code is for compatibility with Cycles' native BVH. */
if (!params.top_level) {
return;
}
progress.set_substatus("Refitting BVH nodes");
for (size_t i = 0; i < pack.prim_index.size(); ++i) {
if (pack.prim_index[i] != -1) {
pack.prim_index[i] += objects[pack.prim_object[i]]->get_geometry()->prim_offset;
}
}
size_t prim_offset = pack.prim_index.size();
/* reserve */
size_t prim_index_size = pack.prim_index.size();
size_t prim_tri_verts_size = pack.prim_tri_verts.size();
size_t pack_prim_index_offset = prim_index_size;
size_t pack_prim_tri_verts_offset = prim_tri_verts_size;
size_t object_offset = 0;
map<Geometry *, int> geometry_map;
foreach (Object *ob, objects) {
Geometry *geom = ob->get_geometry();
BVH *bvh = geom->bvh;
if (geom->need_build_bvh(BVH_LAYOUT_EMBREE)) {
if (geometry_map.find(geom) == geometry_map.end()) {
prim_index_size += bvh->pack.prim_index.size();
prim_tri_verts_size += bvh->pack.prim_tri_verts.size();
geometry_map[geom] = 1;
}
}
}
geometry_map.clear();
pack.prim_index.resize(prim_index_size);
pack.prim_type.resize(prim_index_size);
pack.prim_object.resize(prim_index_size);
pack.prim_visibility.clear();
pack.prim_tri_verts.resize(prim_tri_verts_size);
pack.prim_tri_index.resize(prim_index_size);
pack.object_node.resize(objects.size());
int *pack_prim_index = (pack.prim_index.size()) ? &pack.prim_index[0] : NULL;
int *pack_prim_type = (pack.prim_type.size()) ? &pack.prim_type[0] : NULL;
int *pack_prim_object = (pack.prim_object.size()) ? &pack.prim_object[0] : NULL;
float4 *pack_prim_tri_verts = (pack.prim_tri_verts.size()) ? &pack.prim_tri_verts[0] : NULL;
uint *pack_prim_tri_index = (pack.prim_tri_index.size()) ? &pack.prim_tri_index[0] : NULL;
/* merge */
foreach (Object *ob, objects) {
Geometry *geom = ob->get_geometry();
/* We assume that if mesh doesn't need own BVH it was already included
* into a top-level BVH and no packing here is needed.
*/
if (!geom->need_build_bvh(BVH_LAYOUT_EMBREE)) {
pack.object_node[object_offset++] = prim_offset;
continue;
}
/* if geom already added once, don't add it again, but used set
* node offset for this object */
map<Geometry *, int>::iterator it = geometry_map.find(geom);
if (geometry_map.find(geom) != geometry_map.end()) {
int noffset = it->second;
pack.object_node[object_offset++] = noffset;
continue;
}
BVHEmbree *bvh = (BVHEmbree *)geom->bvh;
rtc_memory_monitor_func(stats, unaccounted_mem, true);
unaccounted_mem = 0;
int geom_prim_offset = geom->prim_offset;
/* fill in node indexes for instances */
pack.object_node[object_offset++] = prim_offset;
geometry_map[geom] = pack.object_node[object_offset - 1];
/* merge primitive, object and triangle indexes */
if (bvh->pack.prim_index.size()) {
size_t bvh_prim_index_size = bvh->pack.prim_index.size();
int *bvh_prim_index = &bvh->pack.prim_index[0];
int *bvh_prim_type = &bvh->pack.prim_type[0];
uint *bvh_prim_tri_index = &bvh->pack.prim_tri_index[0];
for (size_t i = 0; i < bvh_prim_index_size; ++i) {
if (bvh->pack.prim_type[i] & PRIMITIVE_ALL_CURVE) {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = -1;
}
else {
pack_prim_index[pack_prim_index_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_prim_index_offset] = bvh_prim_tri_index[i] +
pack_prim_tri_verts_offset;
}
pack_prim_type[pack_prim_index_offset] = bvh_prim_type[i];
pack_prim_object[pack_prim_index_offset] = 0;
++pack_prim_index_offset;
}
}
/* Merge triangle vertices data. */
if (bvh->pack.prim_tri_verts.size()) {
const size_t prim_tri_size = bvh->pack.prim_tri_verts.size();
memcpy(pack_prim_tri_verts + pack_prim_tri_verts_offset,
&bvh->pack.prim_tri_verts[0],
prim_tri_size * sizeof(float4));
pack_prim_tri_verts_offset += prim_tri_size;
}
prim_offset += bvh->pack.prim_index.size();
}
}
void BVHEmbree::refit_nodes()
{
/* Update all vertex buffers, then tell Embree to rebuild/-fit the BVHs. */
unsigned geom_id = 0;
foreach (Object *ob, objects) {
@@ -957,6 +682,7 @@ void BVHEmbree::refit_nodes()
if (mesh->num_triangles() > 0) {
RTCGeometry geom = rtcGetGeometry(scene, geom_id);
set_tri_vertex_buffer(geom, mesh, true);
rtcSetGeometryUserData(geom, (void *)mesh->optix_prim_offset);
rtcCommitGeometry(geom);
}
}
@@ -965,14 +691,17 @@ void BVHEmbree::refit_nodes()
if (hair->num_curves() > 0) {
RTCGeometry geom = rtcGetGeometry(scene, geom_id + 1);
set_curve_vertex_buffer(geom, hair, true);
rtcSetGeometryUserData(geom, (void *)hair->optix_prim_offset);
rtcCommitGeometry(geom);
}
}
}
geom_id += 2;
}
rtcCommitScene(scene);
}
CCL_NAMESPACE_END
#endif /* WITH_EMBREE */

View File

@@ -31,56 +31,34 @@
CCL_NAMESPACE_BEGIN
class Geometry;
class Hair;
class Mesh;
class BVHEmbree : public BVH {
public:
virtual void build(Progress &progress, Stats *stats) override;
virtual void copy_to_device(Progress &progress, DeviceScene *dscene) override;
virtual ~BVHEmbree();
RTCScene scene;
static void destroy(RTCScene);
void build(Progress &progress, Stats *stats, RTCDevice rtc_device);
void refit(Progress &progress);
/* Building process. */
virtual BVHNode *widen_children_nodes(const BVHNode *root) override;
RTCScene scene;
protected:
friend class BVH;
BVHEmbree(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects,
const Device *device);
virtual void pack_nodes(const BVHNode *) override;
virtual void refit_nodes() override;
const vector<Object *> &objects);
virtual ~BVHEmbree();
void add_object(Object *ob, int i);
void add_instance(Object *ob, int i);
void add_curves(const Object *ob, const Hair *hair, int i);
void add_triangles(const Object *ob, const Mesh *mesh, int i);
ssize_t mem_used;
void add_delayed_delete_scene(RTCScene scene)
{
delayed_delete_scenes.push_back(scene);
}
BVHEmbree *top_level;
private:
void delete_rtcScene();
void set_tri_vertex_buffer(RTCGeometry geom_id, const Mesh *mesh, const bool update);
void set_curve_vertex_buffer(RTCGeometry geom_id, const Hair *hair, const bool update);
RTCDevice rtc_device;
Stats *stats;
vector<RTCScene> delayed_delete_scenes;
int curve_subdivisions;
enum RTCBuildQuality build_quality;
bool dynamic_scene;
};
CCL_NAMESPACE_END

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2020, Blender Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bvh/bvh_multi.h"
#include "util/util_foreach.h"
CCL_NAMESPACE_BEGIN
BVHMulti::BVHMulti(const BVHParams &params_,
const vector<Geometry *> &geometry_,
const vector<Object *> &objects_)
: BVH(params_, geometry_, objects_)
{
}
BVHMulti::~BVHMulti()
{
foreach (BVH *bvh, sub_bvhs) {
delete bvh;
}
}
CCL_NAMESPACE_END

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2020, Blender Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BVH_MULTI_H__
#define __BVH_MULTI_H__
#include "bvh/bvh.h"
#include "bvh/bvh_params.h"
CCL_NAMESPACE_BEGIN
class BVHMulti : public BVH {
public:
vector<BVH *> sub_bvhs;
protected:
friend class BVH;
BVHMulti(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects);
virtual ~BVHMulti();
};
CCL_NAMESPACE_END
#endif /* __BVH_MULTI_H__ */

View File

@@ -19,212 +19,22 @@
# include "bvh/bvh_optix.h"
# include "device/device.h"
# include "render/geometry.h"
# include "render/hair.h"
# include "render/mesh.h"
# include "render/object.h"
# include "util/util_foreach.h"
# include "util/util_logging.h"
# include "util/util_progress.h"
CCL_NAMESPACE_BEGIN
BVHOptiX::BVHOptiX(const BVHParams &params_,
const vector<Geometry *> &geometry_,
const vector<Object *> &objects_)
: BVH(params_, geometry_, objects_)
const vector<Object *> &objects_,
Device *device)
: BVH(params_, geometry_, objects_),
traversable_handle(0),
as_data(device, params_.top_level ? "optix tlas" : "optix blas"),
motion_transform_data(device, "optix motion transform")
{
optix_handle = 0;
optix_data_handle = 0;
do_refit = false;
}
BVHOptiX::~BVHOptiX()
{
}
void BVHOptiX::build(Progress &, Stats *)
{
if (params.top_level)
pack_tlas();
else
pack_blas();
}
void BVHOptiX::copy_to_device(Progress &progress, DeviceScene *dscene)
{
progress.set_status("Updating Scene BVH", "Building OptiX acceleration structure");
Device *const device = dscene->bvh_nodes.device;
if (!device->build_optix_bvh(this))
progress.set_error("Failed to build OptiX acceleration structure");
}
void BVHOptiX::pack_blas()
{
// Bottom-level BVH can contain multiple primitive types, so merge them:
assert(geometry.size() == 1 && objects.size() == 1); // These are built per-mesh
Geometry *const geom = geometry[0];
if (geom->geometry_type == Geometry::HAIR) {
Hair *const hair = static_cast<Hair *const>(geom);
if (hair->num_curves() > 0) {
const size_t num_curves = hair->num_curves();
const size_t num_segments = hair->num_segments();
pack.prim_type.reserve(pack.prim_type.size() + num_segments);
pack.prim_index.reserve(pack.prim_index.size() + num_segments);
pack.prim_object.reserve(pack.prim_object.size() + num_segments);
// 'pack.prim_time' is only used in geom_curve_intersect.h
// It is not needed because of OPTIX_MOTION_FLAG_[START|END]_VANISH
uint type = (hair->get_use_motion_blur() &&
hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) ?
((hair->curve_shape == CURVE_RIBBON) ? PRIMITIVE_MOTION_CURVE_RIBBON :
PRIMITIVE_MOTION_CURVE_THICK) :
((hair->curve_shape == CURVE_RIBBON) ? PRIMITIVE_CURVE_RIBBON :
PRIMITIVE_CURVE_THICK);
for (size_t j = 0; j < num_curves; ++j) {
const Hair::Curve curve = hair->get_curve(j);
for (size_t k = 0; k < curve.num_segments(); ++k) {
pack.prim_type.push_back_reserved(PRIMITIVE_PACK_SEGMENT(type, k));
// Each curve segment points back to its curve index
pack.prim_index.push_back_reserved(j);
pack.prim_object.push_back_reserved(0);
}
}
}
}
else if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
Mesh *const mesh = static_cast<Mesh *const>(geom);
if (mesh->num_triangles() > 0) {
const size_t num_triangles = mesh->num_triangles();
pack.prim_type.reserve(pack.prim_type.size() + num_triangles);
pack.prim_index.reserve(pack.prim_index.size() + num_triangles);
pack.prim_object.reserve(pack.prim_object.size() + num_triangles);
uint type = PRIMITIVE_TRIANGLE;
if (mesh->get_use_motion_blur() && mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION))
type = PRIMITIVE_MOTION_TRIANGLE;
for (size_t k = 0; k < num_triangles; ++k) {
pack.prim_type.push_back_reserved(type);
pack.prim_index.push_back_reserved(k);
pack.prim_object.push_back_reserved(0);
}
}
}
// Initialize visibility to zero and later update it during top-level build
uint prev_visibility = objects[0]->get_visibility();
objects[0]->set_visibility(0);
// Update 'pack.prim_tri_index', 'pack.prim_tri_verts' and 'pack.prim_visibility'
pack_primitives();
// Reset visibility after packing
objects[0]->set_visibility(prev_visibility);
}
void BVHOptiX::pack_tlas()
{
// Calculate total packed size
size_t prim_index_size = 0;
size_t prim_tri_verts_size = 0;
foreach (Geometry *geom, geometry) {
BVH *const bvh = geom->bvh;
prim_index_size += bvh->pack.prim_index.size();
prim_tri_verts_size += bvh->pack.prim_tri_verts.size();
}
if (prim_index_size == 0)
return; // Abort right away if this is an empty BVH
size_t pack_offset = 0;
size_t pack_verts_offset = 0;
pack.prim_type.resize(prim_index_size);
int *pack_prim_type = pack.prim_type.data();
pack.prim_index.resize(prim_index_size);
int *pack_prim_index = pack.prim_index.data();
pack.prim_object.resize(prim_index_size);
int *pack_prim_object = pack.prim_object.data();
pack.prim_visibility.resize(prim_index_size);
uint *pack_prim_visibility = pack.prim_visibility.data();
pack.prim_tri_index.resize(prim_index_size);
uint *pack_prim_tri_index = pack.prim_tri_index.data();
pack.prim_tri_verts.resize(prim_tri_verts_size);
float4 *pack_prim_tri_verts = pack.prim_tri_verts.data();
// Top-level BVH should only contain instances, see 'Geometry::need_build_bvh'
// Iterate over scene mesh list instead of objects, since the 'prim_offset' is calculated based
// on that list, which may be ordered differently from the object list.
foreach (Geometry *geom, geometry) {
PackedBVH &bvh_pack = geom->bvh->pack;
int geom_prim_offset = geom->prim_offset;
// Merge visibility flags of all objects and fix object indices for non-instanced geometry
int object_index = 0; // Unused for instanced geometry
int object_visibility = 0;
foreach (Object *ob, objects) {
if (ob->get_geometry() == geom) {
object_visibility |= ob->visibility_for_tracing();
if (!geom->is_instanced()) {
object_index = ob->get_device_index();
break;
}
}
}
// Merge primitive, object and triangle indexes
if (!bvh_pack.prim_index.empty()) {
int *bvh_prim_type = &bvh_pack.prim_type[0];
int *bvh_prim_index = &bvh_pack.prim_index[0];
uint *bvh_prim_tri_index = &bvh_pack.prim_tri_index[0];
uint *bvh_prim_visibility = &bvh_pack.prim_visibility[0];
for (size_t i = 0; i < bvh_pack.prim_index.size(); i++, pack_offset++) {
if (bvh_pack.prim_type[i] & PRIMITIVE_ALL_CURVE) {
pack_prim_index[pack_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_offset] = -1;
}
else {
pack_prim_index[pack_offset] = bvh_prim_index[i] + geom_prim_offset;
pack_prim_tri_index[pack_offset] = bvh_prim_tri_index[i] + pack_verts_offset;
}
pack_prim_type[pack_offset] = bvh_prim_type[i];
pack_prim_object[pack_offset] = object_index;
pack_prim_visibility[pack_offset] = bvh_prim_visibility[i] | object_visibility;
}
}
// Merge triangle vertex data
if (!bvh_pack.prim_tri_verts.empty()) {
const size_t prim_tri_size = bvh_pack.prim_tri_verts.size();
memcpy(pack_prim_tri_verts + pack_verts_offset,
bvh_pack.prim_tri_verts.data(),
prim_tri_size * sizeof(float4));
pack_verts_offset += prim_tri_size;
}
}
}
void BVHOptiX::pack_nodes(const BVHNode *)
{
}
void BVHOptiX::refit_nodes()
{
do_refit = true;
}
BVHNode *BVHOptiX::widen_children_nodes(const BVHNode *)
{
return NULL;
// Acceleration structure memory is freed via the 'as_data' destructor
}
CCL_NAMESPACE_END

View File

@@ -26,33 +26,19 @@
CCL_NAMESPACE_BEGIN
class Geometry;
class Optix;
class BVHOptiX : public BVH {
friend class BVH;
public:
uint64_t optix_handle;
uint64_t optix_data_handle;
bool do_refit;
uint64_t traversable_handle;
device_only_memory<char> as_data;
device_only_memory<char> motion_transform_data;
protected:
friend class BVH;
BVHOptiX(const BVHParams &params,
const vector<Geometry *> &geometry,
const vector<Object *> &objects);
const vector<Object *> &objects,
Device *device);
virtual ~BVHOptiX();
virtual void build(Progress &progress, Stats *) override;
virtual void copy_to_device(Progress &progress, DeviceScene *dscene) override;
private:
void pack_blas();
void pack_tlas();
virtual void pack_nodes(const BVHNode *) override;
virtual void refit_nodes() override;
virtual BVHNode *widen_children_nodes(const BVHNode *) override;
};
CCL_NAMESPACE_END

View File

@@ -71,6 +71,7 @@ class CUDADevice : public Device {
};
typedef map<device_memory *, CUDAMem> CUDAMemMap;
CUDAMemMap cuda_mem_map;
thread_mutex cuda_mem_map_mutex;
struct PixelMem {
GLuint cuPBO;

View File

@@ -718,8 +718,10 @@ void CUDADevice::init_host_memory()
void CUDADevice::load_texture_info()
{
if (need_texture_info) {
texture_info.copy_to_device();
/* Unset flag before copying, so this does not loop indefinitely if the copy below calls
* into 'move_textures_to_host' (which calls 'load_texture_info' again). */
need_texture_info = false;
texture_info.copy_to_device();
}
}
@@ -988,6 +990,7 @@ void CUDADevice::mem_alloc(device_memory &mem)
assert(!"mem_alloc not supported for global memory.");
}
else {
thread_scoped_lock lock(cuda_mem_map_mutex);
generic_alloc(mem);
}
}
@@ -1006,10 +1009,10 @@ void CUDADevice::mem_copy_to(device_memory &mem)
tex_alloc((device_texture &)mem);
}
else {
thread_scoped_lock lock(cuda_mem_map_mutex);
if (!mem.device_pointer) {
generic_alloc(mem);
}
generic_copy_to(mem);
}
}
@@ -1048,6 +1051,7 @@ void CUDADevice::mem_zero(device_memory &mem)
/* If use_mapped_host of mem is false, mem.device_pointer currently refers to device memory
* regardless of mem.host_pointer and mem.shared_pointer. */
thread_scoped_lock lock(cuda_mem_map_mutex);
if (!cuda_mem_map[&mem].use_mapped_host || mem.host_pointer != mem.shared_pointer) {
const CUDAContextScope scope(this);
cuda_assert(cuMemsetD8((CUdeviceptr)mem.device_pointer, 0, mem.memory_size()));
@@ -1069,6 +1073,7 @@ void CUDADevice::mem_free(device_memory &mem)
tex_free((device_texture &)mem);
}
else {
thread_scoped_lock lock(cuda_mem_map_mutex);
generic_free(mem);
}
}
@@ -1092,6 +1097,7 @@ void CUDADevice::const_copy_to(const char *name, void *host, size_t size)
void CUDADevice::global_alloc(device_memory &mem)
{
if (mem.is_resident(this)) {
thread_scoped_lock lock(cuda_mem_map_mutex);
generic_alloc(mem);
generic_copy_to(mem);
}
@@ -1102,6 +1108,7 @@ void CUDADevice::global_alloc(device_memory &mem)
void CUDADevice::global_free(device_memory &mem)
{
if (mem.is_resident(this) && mem.device_pointer) {
thread_scoped_lock lock(cuda_mem_map_mutex);
generic_free(mem);
}
}
@@ -1170,6 +1177,8 @@ void CUDADevice::tex_alloc(device_texture &mem)
size_t src_pitch = mem.data_width * dsize * mem.data_elements;
size_t dst_pitch = src_pitch;
thread_scoped_lock lock(cuda_mem_map_mutex);
if (!mem.is_resident(this)) {
cmem = &cuda_mem_map[&mem];
cmem->texobject = 0;
@@ -1257,6 +1266,9 @@ void CUDADevice::tex_alloc(device_texture &mem)
cuda_assert(cuMemcpyHtoD(mem.device_pointer, mem.host_pointer, size));
}
/* Unlock mutex before resizing texture info, since that may attempt to lock it again. */
lock.unlock();
/* Resize once */
const uint slot = mem.slot;
if (slot >= texture_info.size()) {
@@ -1305,6 +1317,11 @@ void CUDADevice::tex_alloc(device_texture &mem)
texDesc.filterMode = filter_mode;
texDesc.flags = CU_TRSF_NORMALIZED_COORDINATES;
/* Lock again and refresh the data pointer (in case another thread modified the map in the
* meantime). */
lock.lock();
cmem = &cuda_mem_map[&mem];
cuda_assert(cuTexObjectCreate(&cmem->texobject, &resDesc, &texDesc, NULL));
texture_info[slot].data = (uint64_t)cmem->texobject;
@@ -1318,6 +1335,7 @@ void CUDADevice::tex_free(device_texture &mem)
{
if (mem.device_pointer) {
CUDAContextScope scope(this);
thread_scoped_lock lock(cuda_mem_map_mutex);
const CUDAMem &cmem = cuda_mem_map[&mem];
if (cmem.texobject) {

View File

@@ -17,6 +17,8 @@
#include <stdlib.h>
#include <string.h>
#include "bvh/bvh2.h"
#include "device/device.h"
#include "device/device_intern.h"
@@ -364,6 +366,19 @@ void Device::draw_pixels(device_memory &rgba,
}
}
void Device::build_bvh(BVH *bvh, Progress &progress, bool refit)
{
assert(bvh->params.bvh_layout == BVH_LAYOUT_BVH2);
BVH2 *const bvh2 = static_cast<BVH2 *>(bvh);
if (refit) {
bvh2->refit(progress);
}
else {
bvh2->build(progress, &stats);
}
}
Device *Device::create(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background)
{
#ifdef WITH_MULTI

View File

@@ -373,12 +373,6 @@ class Device {
return NULL;
}
/* Device specific pointer for BVH creation. Currently only used by Embree. */
virtual void *bvh_device() const
{
return NULL;
}
/* load/compile kernels, must be called before adding tasks */
virtual bool load_kernels(const DeviceRequestedFeatures & /*requested_features*/)
{
@@ -427,10 +421,7 @@ class Device {
const DeviceDrawParams &draw_params);
/* acceleration structure building */
virtual bool build_optix_bvh(BVH *)
{
return false;
}
virtual void build_bvh(BVH *bvh, Progress &progress, bool refit);
#ifdef WITH_NETWORK
/* networking */

View File

@@ -47,6 +47,8 @@
#include "kernel/osl/osl_globals.h"
// clang-format on
#include "bvh/bvh_embree.h"
#include "render/buffers.h"
#include "render/coverage.h"
@@ -188,6 +190,7 @@ class CPUDevice : public Device {
#endif
thread_spin_lock oidn_task_lock;
#ifdef WITH_EMBREE
RTCScene embree_scene = NULL;
RTCDevice embree_device;
#endif
@@ -472,6 +475,15 @@ class CPUDevice : public Device {
virtual void const_copy_to(const char *name, void *host, size_t size) override
{
#if WITH_EMBREE
if (strcmp(name, "__data") == 0) {
assert(size <= sizeof(KernelData));
// Update scene handle (since it is different for each device on multi devices)
KernelData *const data = (KernelData *)host;
data->bvh.scene = embree_scene;
}
#endif
kernel_const_copy(&kernel_globals, name, host, size);
}
@@ -537,13 +549,26 @@ class CPUDevice : public Device {
#endif
}
void *bvh_device() const override
void build_bvh(BVH *bvh, Progress &progress, bool refit) override
{
#ifdef WITH_EMBREE
return embree_device;
#else
return NULL;
if (bvh->params.bvh_layout == BVH_LAYOUT_EMBREE ||
bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE) {
BVHEmbree *const bvh_embree = static_cast<BVHEmbree *>(bvh);
if (refit) {
bvh_embree->refit(progress);
}
else {
bvh_embree->build(progress, &stats, embree_device);
}
if (bvh->params.top_level) {
embree_scene = bvh_embree->scene;
}
}
else
#endif
Device::build_bvh(bvh, progress, refit);
}
void thread_run(DeviceTask &task)

View File

@@ -17,11 +17,14 @@
#include <sstream>
#include <stdlib.h>
#include "bvh/bvh_multi.h"
#include "device/device.h"
#include "device/device_intern.h"
#include "device/device_network.h"
#include "render/buffers.h"
#include "render/geometry.h"
#include "util/util_foreach.h"
#include "util/util_list.h"
@@ -141,7 +144,7 @@ class MultiDevice : public Device {
delete sub.device;
}
const string &error_message()
const string &error_message() override
{
error_msg.clear();
@@ -153,7 +156,7 @@ class MultiDevice : public Device {
return error_msg;
}
virtual bool show_samples() const
virtual bool show_samples() const override
{
if (devices.size() > 1) {
return false;
@@ -161,16 +164,31 @@ class MultiDevice : public Device {
return devices.front().device->show_samples();
}
virtual BVHLayoutMask get_bvh_layout_mask() const
virtual BVHLayoutMask get_bvh_layout_mask() const override
{
BVHLayoutMask bvh_layout_mask = BVH_LAYOUT_ALL;
BVHLayoutMask bvh_layout_mask_all = BVH_LAYOUT_NONE;
foreach (const SubDevice &sub_device, devices) {
bvh_layout_mask &= sub_device.device->get_bvh_layout_mask();
BVHLayoutMask device_bvh_layout_mask = sub_device.device->get_bvh_layout_mask();
bvh_layout_mask &= device_bvh_layout_mask;
bvh_layout_mask_all |= device_bvh_layout_mask;
}
/* With multiple OptiX devices, every device needs its own acceleration structure */
if (bvh_layout_mask == BVH_LAYOUT_OPTIX) {
return BVH_LAYOUT_MULTI_OPTIX;
}
/* When devices do not share a common BVH layout, fall back to creating one for each */
const BVHLayoutMask BVH_LAYOUT_OPTIX_EMBREE = (BVH_LAYOUT_OPTIX | BVH_LAYOUT_EMBREE);
if ((bvh_layout_mask_all & BVH_LAYOUT_OPTIX_EMBREE) == BVH_LAYOUT_OPTIX_EMBREE) {
return BVH_LAYOUT_MULTI_OPTIX_EMBREE;
}
return bvh_layout_mask;
}
bool load_kernels(const DeviceRequestedFeatures &requested_features)
bool load_kernels(const DeviceRequestedFeatures &requested_features) override
{
foreach (SubDevice &sub, devices)
if (!sub.device->load_kernels(requested_features))
@@ -188,7 +206,7 @@ class MultiDevice : public Device {
return true;
}
bool wait_for_availability(const DeviceRequestedFeatures &requested_features)
bool wait_for_availability(const DeviceRequestedFeatures &requested_features) override
{
foreach (SubDevice &sub, devices)
if (!sub.device->wait_for_availability(requested_features))
@@ -203,7 +221,7 @@ class MultiDevice : public Device {
return true;
}
DeviceKernelStatus get_active_kernel_switch_state()
DeviceKernelStatus get_active_kernel_switch_state() override
{
DeviceKernelStatus result = DEVICE_KERNEL_USING_FEATURE_KERNEL;
@@ -227,24 +245,64 @@ class MultiDevice : public Device {
return result;
}
bool build_optix_bvh(BVH *bvh)
void build_bvh(BVH *bvh, Progress &progress, bool refit) override
{
/* Broadcast acceleration structure build to all render devices */
foreach (SubDevice &sub, devices) {
if (!sub.device->build_optix_bvh(bvh))
return false;
/* Try to build and share a single acceleration structure, if possible */
if (bvh->params.bvh_layout == BVH_LAYOUT_BVH2 || bvh->params.bvh_layout == BVH_LAYOUT_EMBREE) {
devices.back().device->build_bvh(bvh, progress, refit);
return;
}
assert(bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX ||
bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE);
BVHMulti *const bvh_multi = static_cast<BVHMulti *>(bvh);
bvh_multi->sub_bvhs.resize(devices.size());
vector<BVHMulti *> geom_bvhs;
geom_bvhs.reserve(bvh->geometry.size());
foreach (Geometry *geom, bvh->geometry) {
geom_bvhs.push_back(static_cast<BVHMulti *>(geom->bvh));
}
/* Broadcast acceleration structure build to all render devices */
size_t i = 0;
foreach (SubDevice &sub, devices) {
/* Change geometry BVH pointers to the sub BVH */
for (size_t k = 0; k < bvh->geometry.size(); ++k) {
bvh->geometry[k]->bvh = geom_bvhs[k]->sub_bvhs[i];
}
if (!bvh_multi->sub_bvhs[i]) {
BVHParams params = bvh->params;
if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX)
params.bvh_layout = BVH_LAYOUT_OPTIX;
else if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE)
params.bvh_layout = sub.device->info.type == DEVICE_OPTIX ? BVH_LAYOUT_OPTIX :
BVH_LAYOUT_EMBREE;
/* Skip building a bottom level acceleration structure for non-instanced geometry on Embree
* (since they are put into the top level directly, see bvh_embree.cpp) */
if (!params.top_level && params.bvh_layout == BVH_LAYOUT_EMBREE &&
!bvh->geometry[0]->is_instanced()) {
i++;
continue;
}
bvh_multi->sub_bvhs[i] = BVH::create(params, bvh->geometry, bvh->objects, sub.device);
}
sub.device->build_bvh(bvh_multi->sub_bvhs[i], progress, refit);
i++;
}
/* Change geomtry BVH pointers back to the multi BVH */
for (size_t k = 0; k < bvh->geometry.size(); ++k) {
bvh->geometry[k]->bvh = geom_bvhs[k];
}
return true;
}
virtual void *bvh_device() const
{
/* CPU devices will always be at the back, so simply choose the last one.
There should only ever be one CPU device anyway and we need the Embree device for it. */
return devices.back().device->bvh_device();
}
virtual void *osl_memory()
virtual void *osl_memory() override
{
if (devices.size() > 1) {
return NULL;
@@ -252,7 +310,7 @@ class MultiDevice : public Device {
return devices.front().device->osl_memory();
}
bool is_resident(device_ptr key, Device *sub_device)
bool is_resident(device_ptr key, Device *sub_device) override
{
foreach (SubDevice &sub, devices) {
if (sub.device == sub_device) {
@@ -299,7 +357,7 @@ class MultiDevice : public Device {
return find_matching_mem_device(key, sub)->ptr_map[key];
}
void mem_alloc(device_memory &mem)
void mem_alloc(device_memory &mem) override
{
device_ptr key = unique_key++;
@@ -335,7 +393,7 @@ class MultiDevice : public Device {
stats.mem_alloc(mem.device_size);
}
void mem_copy_to(device_memory &mem)
void mem_copy_to(device_memory &mem) override
{
device_ptr existing_key = mem.device_pointer;
device_ptr key = (existing_key) ? existing_key : unique_key++;
@@ -378,7 +436,7 @@ class MultiDevice : public Device {
stats.mem_alloc(mem.device_size - existing_size);
}
void mem_copy_from(device_memory &mem, int y, int w, int h, int elem)
void mem_copy_from(device_memory &mem, int y, int w, int h, int elem) override
{
device_ptr key = mem.device_pointer;
int i = 0, sub_h = h / devices.size();
@@ -399,7 +457,7 @@ class MultiDevice : public Device {
mem.device_pointer = key;
}
void mem_zero(device_memory &mem)
void mem_zero(device_memory &mem) override
{
device_ptr existing_key = mem.device_pointer;
device_ptr key = (existing_key) ? existing_key : unique_key++;
@@ -454,7 +512,7 @@ class MultiDevice : public Device {
stats.mem_alloc(mem.device_size - existing_size);
}
void mem_free(device_memory &mem)
void mem_free(device_memory &mem) override
{
device_ptr key = mem.device_pointer;
size_t existing_size = mem.device_size;
@@ -510,7 +568,7 @@ class MultiDevice : public Device {
stats.mem_free(existing_size);
}
void const_copy_to(const char *name, void *host, size_t size)
void const_copy_to(const char *name, void *host, size_t size) override
{
foreach (SubDevice &sub, devices)
sub.device->const_copy_to(name, host, size);
@@ -527,7 +585,7 @@ class MultiDevice : public Device {
int dw,
int dh,
bool transparent,
const DeviceDrawParams &draw_params)
const DeviceDrawParams &draw_params) override
{
assert(rgba.type == MEM_PIXELS);
@@ -551,7 +609,7 @@ class MultiDevice : public Device {
rgba.device_pointer = key;
}
void map_tile(Device *sub_device, RenderTile &tile)
void map_tile(Device *sub_device, RenderTile &tile) override
{
if (!tile.buffer) {
return;
@@ -572,7 +630,7 @@ class MultiDevice : public Device {
}
}
int device_number(Device *sub_device)
int device_number(Device *sub_device) override
{
int i = 0;
@@ -591,7 +649,7 @@ class MultiDevice : public Device {
return -1;
}
void map_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors)
void map_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors) override
{
for (int i = 0; i < RenderTileNeighbors::SIZE; i++) {
RenderTile &tile = neighbors.tiles[i];
@@ -643,7 +701,7 @@ class MultiDevice : public Device {
}
}
void unmap_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors)
void unmap_neighbor_tiles(Device *sub_device, RenderTileNeighbors &neighbors) override
{
RenderTile &target_tile = neighbors.target;
device_vector<float> &mem = target_tile.buffers->buffer;
@@ -677,7 +735,7 @@ class MultiDevice : public Device {
}
}
int get_split_task_count(DeviceTask &task)
int get_split_task_count(DeviceTask &task) override
{
int total_tasks = 0;
list<DeviceTask> tasks;
@@ -693,7 +751,7 @@ class MultiDevice : public Device {
return total_tasks;
}
void task_add(DeviceTask &task)
void task_add(DeviceTask &task) override
{
list<SubDevice> task_devices = devices;
if (!denoising_devices.empty()) {
@@ -743,7 +801,7 @@ class MultiDevice : public Device {
}
}
void task_wait()
void task_wait() override
{
foreach (SubDevice &sub, devices)
sub.device->task_wait();
@@ -751,7 +809,7 @@ class MultiDevice : public Device {
sub.device->task_wait();
}
void task_cancel()
void task_cancel() override
{
foreach (SubDevice &sub, devices)
sub.device->task_cancel();

View File

@@ -31,6 +31,7 @@
# include "util/util_logging.h"
# include "util/util_md5.h"
# include "util/util_path.h"
# include "util/util_progress.h"
# include "util/util_time.h"
# ifdef WITH_CUDA_DYNLOAD
@@ -186,7 +187,6 @@ class OptiXDevice : public CUDADevice {
bool motion_blur = false;
device_vector<SbtRecord> sbt_data;
device_only_memory<KernelParams> launch_params;
vector<CUdeviceptr> as_mem;
OptixTraversableHandle tlas_handle = 0;
OptixDenoiser denoiser = NULL;
@@ -258,11 +258,6 @@ class OptiXDevice : public CUDADevice {
// Make CUDA context current
const CUDAContextScope scope(cuContext);
// Free all acceleration structures
for (CUdeviceptr mem : as_mem) {
cuMemFree(mem);
}
sbt_data.free();
texture_info.free();
launch_params.free();
@@ -319,6 +314,14 @@ class OptiXDevice : public CUDADevice {
common_cflags += string_printf(" -I\"%s/include\"", optix_sdk_path);
}
// Specialization for shader raytracing
if (requested_features.use_shader_raytrace) {
common_cflags += " --keep-device-functions";
}
else {
common_cflags += " -D __NO_SHADER_RAYTRACE__";
}
return common_cflags;
}
@@ -1136,11 +1139,10 @@ class OptiXDevice : public CUDADevice {
}
}
bool build_optix_bvh(const OptixBuildInput &build_input,
uint16_t num_motion_steps,
OptixTraversableHandle &out_handle,
CUdeviceptr &out_data,
OptixBuildOperation operation)
bool build_optix_bvh(BVHOptiX *bvh,
OptixBuildOperation operation,
const OptixBuildInput &build_input,
uint16_t num_motion_steps)
{
const CUDAContextScope scope(cuContext);
@@ -1166,24 +1168,21 @@ class OptiXDevice : public CUDADevice {
optixAccelComputeMemoryUsage(context, &options, &build_input, 1, &sizes));
// Allocate required output buffers
device_only_memory<char> temp_mem(this, "temp_build_mem");
device_only_memory<char> temp_mem(this, "optix temp as build mem");
temp_mem.alloc_to_device(align_up(sizes.tempSizeInBytes, 8) + 8);
if (!temp_mem.device_pointer)
return false; // Make sure temporary memory allocation succeeded
// Move textures to host memory if there is not enough room
size_t size = 0, free = 0;
cuMemGetInfo(&free, &size);
size = sizes.outputSizeInBytes + device_working_headroom;
if (size >= free && can_map_host) {
move_textures_to_host(size - free, false);
}
device_only_memory<char> &out_data = bvh->as_data;
if (operation == OPTIX_BUILD_OPERATION_BUILD) {
check_result_cuda_ret(cuMemAlloc(&out_data, sizes.outputSizeInBytes));
assert(out_data.device == this);
out_data.alloc_to_device(sizes.outputSizeInBytes);
if (!out_data.device_pointer)
return false;
}
else {
assert(out_data.device_pointer && out_data.device_size >= sizes.outputSizeInBytes);
}
as_mem.push_back(out_data);
// Finally build the acceleration structure
OptixAccelEmitDesc compacted_size_prop;
@@ -1192,6 +1191,7 @@ class OptiXDevice : public CUDADevice {
// Make sure this pointer is 8-byte aligned
compacted_size_prop.result = align_up(temp_mem.device_pointer + sizes.tempSizeInBytes, 8);
OptixTraversableHandle out_handle = 0;
check_result_optix_ret(optixAccelBuild(context,
NULL,
&options,
@@ -1199,11 +1199,12 @@ class OptiXDevice : public CUDADevice {
1,
temp_mem.device_pointer,
sizes.tempSizeInBytes,
out_data,
out_data.device_pointer,
sizes.outputSizeInBytes,
&out_handle,
background ? &compacted_size_prop : NULL,
background ? 1 : 0));
bvh->traversable_handle = static_cast<uint64_t>(out_handle);
// Wait for all operations to finish
check_result_cuda_ret(cuStreamSynchronize(NULL));
@@ -1219,81 +1220,66 @@ class OptiXDevice : public CUDADevice {
// There is no point compacting if the size does not change
if (compacted_size < sizes.outputSizeInBytes) {
CUdeviceptr compacted_data = 0;
if (cuMemAlloc(&compacted_data, compacted_size) != CUDA_SUCCESS)
device_only_memory<char> compacted_data(this, "optix compacted as");
compacted_data.alloc_to_device(compacted_size);
if (!compacted_data.device_pointer)
// Do not compact if memory allocation for compacted acceleration structure fails
// Can just use the uncompacted one then, so succeed here regardless
return true;
as_mem.push_back(compacted_data);
check_result_optix_ret(optixAccelCompact(
context, NULL, out_handle, compacted_data, compacted_size, &out_handle));
check_result_optix_ret(optixAccelCompact(context,
NULL,
out_handle,
compacted_data.device_pointer,
compacted_size,
&out_handle));
bvh->traversable_handle = static_cast<uint64_t>(out_handle);
// Wait for compaction to finish
check_result_cuda_ret(cuStreamSynchronize(NULL));
// Free uncompacted acceleration structure
cuMemFree(out_data);
as_mem.erase(as_mem.end() - 2); // Remove 'out_data' from 'as_mem' array
std::swap(out_data.device_size, compacted_data.device_size);
std::swap(out_data.device_pointer, compacted_data.device_pointer);
}
}
return true;
}
bool build_optix_bvh(BVH *bvh) override
void build_bvh(BVH *bvh, Progress &progress, bool refit) override
{
assert(bvh->params.top_level);
unsigned int num_instances = 0;
unordered_map<Geometry *, OptixTraversableHandle> geometry;
geometry.reserve(bvh->geometry.size());
// Free all previous acceleration structures which can not be refit
std::set<CUdeviceptr> refit_mem;
for (Geometry *geom : bvh->geometry) {
if (static_cast<BVHOptiX *>(geom->bvh)->do_refit) {
refit_mem.insert(static_cast<BVHOptiX *>(geom->bvh)->optix_data_handle);
}
if (bvh->params.bvh_layout == BVH_LAYOUT_BVH2) {
/* For baking CUDA is used, build appropriate BVH for that. */
Device::build_bvh(bvh, progress, refit);
return;
}
for (CUdeviceptr mem : as_mem) {
if (refit_mem.find(mem) == refit_mem.end()) {
cuMemFree(mem);
}
}
BVHOptiX *const bvh_optix = static_cast<BVHOptiX *>(bvh);
as_mem.clear();
progress.set_substatus("Building OptiX acceleration structure");
// Build bottom level acceleration structures (BLAS)
// Note: Always keep this logic in sync with bvh_optix.cpp!
for (Object *ob : bvh->objects) {
// Skip geometry for which acceleration structure already exists
Geometry *geom = ob->get_geometry();
if (geometry.find(geom) != geometry.end())
continue;
if (!bvh->params.top_level) {
assert(bvh->objects.size() == 1 && bvh->geometry.size() == 1);
OptixTraversableHandle handle;
OptixBuildOperation operation;
CUdeviceptr out_data;
// Refit is only possible in viewport for now.
if (static_cast<BVHOptiX *>(geom->bvh)->do_refit && !background) {
out_data = static_cast<BVHOptiX *>(geom->bvh)->optix_data_handle;
handle = static_cast<BVHOptiX *>(geom->bvh)->optix_handle;
// Refit is only possible in viewport for now (because AS is built with
// OPTIX_BUILD_FLAG_ALLOW_UPDATE only there, see above)
OptixBuildOperation operation = OPTIX_BUILD_OPERATION_BUILD;
if (refit && !background) {
assert(bvh_optix->traversable_handle != 0);
operation = OPTIX_BUILD_OPERATION_UPDATE;
}
else {
out_data = 0;
handle = 0;
operation = OPTIX_BUILD_OPERATION_BUILD;
bvh_optix->as_data.free();
bvh_optix->traversable_handle = 0;
}
// Build bottom level acceleration structures (BLAS)
Geometry *const geom = bvh->geometry[0];
if (geom->geometry_type == Geometry::HAIR) {
// Build BLAS for curve primitives
Hair *const hair = static_cast<Hair *const>(ob->get_geometry());
Hair *const hair = static_cast<Hair *const>(geom);
if (hair->num_curves() == 0) {
continue;
return;
}
const size_t num_segments = hair->num_segments();
@@ -1304,10 +1290,10 @@ class OptiXDevice : public CUDADevice {
num_motion_steps = hair->get_motion_steps();
}
device_vector<OptixAabb> aabb_data(this, "temp_aabb_data", MEM_READ_ONLY);
device_vector<OptixAabb> aabb_data(this, "optix temp aabb data", MEM_READ_ONLY);
# if OPTIX_ABI_VERSION >= 36
device_vector<int> index_data(this, "temp_index_data", MEM_READ_ONLY);
device_vector<float4> vertex_data(this, "temp_vertex_data", MEM_READ_ONLY);
device_vector<int> index_data(this, "optix temp index data", MEM_READ_ONLY);
device_vector<float4> vertex_data(this, "optix temp vertex data", MEM_READ_ONLY);
// Four control points for each curve segment
const size_t num_vertices = num_segments * 4;
if (DebugFlags().optix.curves_api && hair->curve_shape == CURVE_THICK) {
@@ -1325,7 +1311,7 @@ class OptiXDevice : public CUDADevice {
size_t center_step = (num_motion_steps - 1) / 2;
if (step != center_step) {
size_t attr_offset = (step > center_step) ? step - 1 : step;
// Technically this is a float4 array, but sizeof(float3) is the same as sizeof(float4)
// Technically this is a float4 array, but sizeof(float3) == sizeof(float4)
keys = motion_keys->data_float3() + attr_offset * hair->get_curve_keys().size();
}
@@ -1452,22 +1438,15 @@ class OptiXDevice : public CUDADevice {
# endif
}
// Allocate memory for new BLAS and build it
if (build_optix_bvh(build_input, num_motion_steps, handle, out_data, operation)) {
geometry.insert({ob->get_geometry(), handle});
static_cast<BVHOptiX *>(geom->bvh)->optix_data_handle = out_data;
static_cast<BVHOptiX *>(geom->bvh)->optix_handle = handle;
static_cast<BVHOptiX *>(geom->bvh)->do_refit = false;
}
else {
return false;
if (!build_optix_bvh(bvh_optix, operation, build_input, num_motion_steps)) {
progress.set_error("Failed to build OptiX acceleration structure");
}
}
else if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
// Build BLAS for triangle primitives
Mesh *const mesh = static_cast<Mesh *const>(ob->get_geometry());
Mesh *const mesh = static_cast<Mesh *const>(geom);
if (mesh->num_triangles() == 0) {
continue;
return;
}
const size_t num_verts = mesh->get_verts().size();
@@ -1478,12 +1457,12 @@ class OptiXDevice : public CUDADevice {
num_motion_steps = mesh->get_motion_steps();
}
device_vector<int> index_data(this, "temp_index_data", MEM_READ_ONLY);
device_vector<int> index_data(this, "optix temp index data", MEM_READ_ONLY);
index_data.alloc(mesh->get_triangles().size());
memcpy(index_data.data(),
mesh->get_triangles().data(),
mesh->get_triangles().size() * sizeof(int));
device_vector<float3> vertex_data(this, "temp_vertex_data", MEM_READ_ONLY);
device_vector<float3> vertex_data(this, "optix temp vertex data", MEM_READ_ONLY);
vertex_data.alloc(num_verts * num_motion_steps);
for (size_t step = 0; step < num_motion_steps; ++step) {
@@ -1528,190 +1507,221 @@ class OptiXDevice : public CUDADevice {
build_input.triangleArray.numSbtRecords = 1;
build_input.triangleArray.primitiveIndexOffset = mesh->optix_prim_offset;
// Allocate memory for new BLAS and build it
if (build_optix_bvh(build_input, num_motion_steps, handle, out_data, operation)) {
geometry.insert({ob->get_geometry(), handle});
static_cast<BVHOptiX *>(geom->bvh)->optix_data_handle = out_data;
static_cast<BVHOptiX *>(geom->bvh)->optix_handle = handle;
static_cast<BVHOptiX *>(geom->bvh)->do_refit = false;
}
else {
return false;
if (!build_optix_bvh(bvh_optix, operation, build_input, num_motion_steps)) {
progress.set_error("Failed to build OptiX acceleration structure");
}
}
}
else {
unsigned int num_instances = 0;
unsigned int max_num_instances = 0xFFFFFFFF;
// Fill instance descriptions
# if OPTIX_ABI_VERSION < 41
device_vector<OptixAabb> aabbs(this, "tlas_aabbs", MEM_READ_ONLY);
aabbs.alloc(bvh->objects.size());
# endif
device_vector<OptixInstance> instances(this, "tlas_instances", MEM_READ_ONLY);
instances.alloc(bvh->objects.size());
bvh_optix->as_data.free();
bvh_optix->traversable_handle = 0;
bvh_optix->motion_transform_data.free();
for (Object *ob : bvh->objects) {
// Skip non-traceable objects
if (!ob->is_traceable())
continue;
// Create separate instance for triangle/curve meshes of an object
const auto handle_it = geometry.find(ob->get_geometry());
if (handle_it == geometry.end()) {
continue;
}
OptixTraversableHandle handle = handle_it->second;
# if OPTIX_ABI_VERSION < 41
OptixAabb &aabb = aabbs[num_instances];
aabb.minX = ob->bounds.min.x;
aabb.minY = ob->bounds.min.y;
aabb.minZ = ob->bounds.min.z;
aabb.maxX = ob->bounds.max.x;
aabb.maxY = ob->bounds.max.y;
aabb.maxZ = ob->bounds.max.z;
# endif
OptixInstance &instance = instances[num_instances++];
memset(&instance, 0, sizeof(instance));
// Clear transform to identity matrix
instance.transform[0] = 1.0f;
instance.transform[5] = 1.0f;
instance.transform[10] = 1.0f;
// Set user instance ID to object index
instance.instanceId = ob->get_device_index();
// Have to have at least one bit in the mask, or else instance would always be culled
instance.visibilityMask = 1;
if (ob->get_geometry()->has_volume) {
// Volumes have a special bit set in the visibility mask so a trace can mask only volumes
instance.visibilityMask |= 2;
optixDeviceContextGetProperty(context,
OPTIX_DEVICE_PROPERTY_LIMIT_MAX_INSTANCE_ID,
&max_num_instances,
sizeof(max_num_instances));
// Do not count first bit, which is used to distinguish instanced and non-instanced objects
max_num_instances >>= 1;
if (bvh->objects.size() > max_num_instances) {
progress.set_error(
"Failed to build OptiX acceleration structure because there are too many instances");
return;
}
if (ob->get_geometry()->geometry_type == Geometry::HAIR) {
// Same applies to curves (so they can be skipped in local trace calls)
instance.visibilityMask |= 4;
// Fill instance descriptions
# if OPTIX_ABI_VERSION < 41
device_vector<OptixAabb> aabbs(this, "optix tlas aabbs", MEM_READ_ONLY);
aabbs.alloc(bvh->objects.size());
# endif
device_vector<OptixInstance> instances(this, "optix tlas instances", MEM_READ_ONLY);
instances.alloc(bvh->objects.size());
// Calculate total motion transform size and allocate memory for them
size_t motion_transform_offset = 0;
if (motion_blur) {
size_t total_motion_transform_size = 0;
for (Object *const ob : bvh->objects) {
if (ob->is_traceable() && ob->use_motion()) {
total_motion_transform_size = align_up(total_motion_transform_size,
OPTIX_TRANSFORM_BYTE_ALIGNMENT);
const size_t motion_keys = max(ob->get_motion().size(), 2) - 2;
total_motion_transform_size = total_motion_transform_size +
sizeof(OptixSRTMotionTransform) +
motion_keys * sizeof(OptixSRTData);
}
}
assert(bvh_optix->motion_transform_data.device == this);
bvh_optix->motion_transform_data.alloc_to_device(total_motion_transform_size);
}
for (Object *ob : bvh->objects) {
// Skip non-traceable objects
if (!ob->is_traceable())
continue;
BVHOptiX *const blas = static_cast<BVHOptiX *>(ob->get_geometry()->bvh);
OptixTraversableHandle handle = blas->traversable_handle;
# if OPTIX_ABI_VERSION < 41
OptixAabb &aabb = aabbs[num_instances];
aabb.minX = ob->bounds.min.x;
aabb.minY = ob->bounds.min.y;
aabb.minZ = ob->bounds.min.z;
aabb.maxX = ob->bounds.max.x;
aabb.maxY = ob->bounds.max.y;
aabb.maxZ = ob->bounds.max.z;
# endif
OptixInstance &instance = instances[num_instances++];
memset(&instance, 0, sizeof(instance));
// Clear transform to identity matrix
instance.transform[0] = 1.0f;
instance.transform[5] = 1.0f;
instance.transform[10] = 1.0f;
// Set user instance ID to object index (but leave low bit blank)
instance.instanceId = ob->get_device_index() << 1;
// Have to have at least one bit in the mask, or else instance would always be culled
instance.visibilityMask = 1;
if (ob->get_geometry()->has_volume) {
// Volumes have a special bit set in the visibility mask so a trace can mask only volumes
instance.visibilityMask |= 2;
}
if (ob->get_geometry()->geometry_type == Geometry::HAIR) {
// Same applies to curves (so they can be skipped in local trace calls)
instance.visibilityMask |= 4;
# if OPTIX_ABI_VERSION >= 36
if (motion_blur && ob->get_geometry()->has_motion_blur() &&
DebugFlags().optix.curves_api &&
static_cast<const Hair *>(ob->get_geometry())->curve_shape == CURVE_THICK) {
// Select between motion blur and non-motion blur built-in intersection module
instance.sbtOffset = PG_HITD_MOTION - PG_HITD;
}
if (motion_blur && ob->get_geometry()->has_motion_blur() &&
DebugFlags().optix.curves_api &&
static_cast<const Hair *>(ob->get_geometry())->curve_shape == CURVE_THICK) {
// Select between motion blur and non-motion blur built-in intersection module
instance.sbtOffset = PG_HITD_MOTION - PG_HITD;
}
# endif
}
// Insert motion traversable if object has motion
if (motion_blur && ob->use_motion()) {
size_t motion_keys = max(ob->get_motion().size(), 2) - 2;
size_t motion_transform_size = sizeof(OptixSRTMotionTransform) +
motion_keys * sizeof(OptixSRTData);
const CUDAContextScope scope(cuContext);
CUdeviceptr motion_transform_gpu = 0;
check_result_cuda_ret(cuMemAlloc(&motion_transform_gpu, motion_transform_size));
as_mem.push_back(motion_transform_gpu);
// Allocate host side memory for motion transform and fill it with transform data
OptixSRTMotionTransform &motion_transform = *reinterpret_cast<OptixSRTMotionTransform *>(
new uint8_t[motion_transform_size]);
motion_transform.child = handle;
motion_transform.motionOptions.numKeys = ob->get_motion().size();
motion_transform.motionOptions.flags = OPTIX_MOTION_FLAG_NONE;
motion_transform.motionOptions.timeBegin = 0.0f;
motion_transform.motionOptions.timeEnd = 1.0f;
OptixSRTData *const srt_data = motion_transform.srtData;
array<DecomposedTransform> decomp(ob->get_motion().size());
transform_motion_decompose(
decomp.data(), ob->get_motion().data(), ob->get_motion().size());
for (size_t i = 0; i < ob->get_motion().size(); ++i) {
// Scale
srt_data[i].sx = decomp[i].y.w; // scale.x.x
srt_data[i].sy = decomp[i].z.w; // scale.y.y
srt_data[i].sz = decomp[i].w.w; // scale.z.z
// Shear
srt_data[i].a = decomp[i].z.x; // scale.x.y
srt_data[i].b = decomp[i].z.y; // scale.x.z
srt_data[i].c = decomp[i].w.x; // scale.y.z
assert(decomp[i].z.z == 0.0f); // scale.y.x
assert(decomp[i].w.y == 0.0f); // scale.z.x
assert(decomp[i].w.z == 0.0f); // scale.z.y
// Pivot point
srt_data[i].pvx = 0.0f;
srt_data[i].pvy = 0.0f;
srt_data[i].pvz = 0.0f;
// Rotation
srt_data[i].qx = decomp[i].x.x;
srt_data[i].qy = decomp[i].x.y;
srt_data[i].qz = decomp[i].x.z;
srt_data[i].qw = decomp[i].x.w;
// Translation
srt_data[i].tx = decomp[i].y.x;
srt_data[i].ty = decomp[i].y.y;
srt_data[i].tz = decomp[i].y.z;
}
// Upload motion transform to GPU
cuMemcpyHtoD(motion_transform_gpu, &motion_transform, motion_transform_size);
delete[] reinterpret_cast<uint8_t *>(&motion_transform);
// Insert motion traversable if object has motion
if (motion_blur && ob->use_motion()) {
size_t motion_keys = max(ob->get_motion().size(), 2) - 2;
size_t motion_transform_size = sizeof(OptixSRTMotionTransform) +
motion_keys * sizeof(OptixSRTData);
// Disable instance transform if object uses motion transform already
instance.flags = OPTIX_INSTANCE_FLAG_DISABLE_TRANSFORM;
const CUDAContextScope scope(cuContext);
// Get traversable handle to motion transform
optixConvertPointerToTraversableHandle(context,
motion_transform_gpu,
OPTIX_TRAVERSABLE_TYPE_SRT_MOTION_TRANSFORM,
&instance.traversableHandle);
}
else {
instance.traversableHandle = handle;
motion_transform_offset = align_up(motion_transform_offset,
OPTIX_TRANSFORM_BYTE_ALIGNMENT);
CUdeviceptr motion_transform_gpu = bvh_optix->motion_transform_data.device_pointer +
motion_transform_offset;
motion_transform_offset += motion_transform_size;
if (ob->get_geometry()->is_instanced()) {
// Set transform matrix
memcpy(instance.transform, &ob->get_tfm(), sizeof(instance.transform));
// Allocate host side memory for motion transform and fill it with transform data
OptixSRTMotionTransform &motion_transform = *reinterpret_cast<OptixSRTMotionTransform *>(
new uint8_t[motion_transform_size]);
motion_transform.child = handle;
motion_transform.motionOptions.numKeys = ob->get_motion().size();
motion_transform.motionOptions.flags = OPTIX_MOTION_FLAG_NONE;
motion_transform.motionOptions.timeBegin = 0.0f;
motion_transform.motionOptions.timeEnd = 1.0f;
OptixSRTData *const srt_data = motion_transform.srtData;
array<DecomposedTransform> decomp(ob->get_motion().size());
transform_motion_decompose(
decomp.data(), ob->get_motion().data(), ob->get_motion().size());
for (size_t i = 0; i < ob->get_motion().size(); ++i) {
// Scale
srt_data[i].sx = decomp[i].y.w; // scale.x.x
srt_data[i].sy = decomp[i].z.w; // scale.y.y
srt_data[i].sz = decomp[i].w.w; // scale.z.z
// Shear
srt_data[i].a = decomp[i].z.x; // scale.x.y
srt_data[i].b = decomp[i].z.y; // scale.x.z
srt_data[i].c = decomp[i].w.x; // scale.y.z
assert(decomp[i].z.z == 0.0f); // scale.y.x
assert(decomp[i].w.y == 0.0f); // scale.z.x
assert(decomp[i].w.z == 0.0f); // scale.z.y
// Pivot point
srt_data[i].pvx = 0.0f;
srt_data[i].pvy = 0.0f;
srt_data[i].pvz = 0.0f;
// Rotation
srt_data[i].qx = decomp[i].x.x;
srt_data[i].qy = decomp[i].x.y;
srt_data[i].qz = decomp[i].x.z;
srt_data[i].qw = decomp[i].x.w;
// Translation
srt_data[i].tx = decomp[i].y.x;
srt_data[i].ty = decomp[i].y.y;
srt_data[i].tz = decomp[i].y.z;
}
// Upload motion transform to GPU
cuMemcpyHtoD(motion_transform_gpu, &motion_transform, motion_transform_size);
delete[] reinterpret_cast<uint8_t *>(&motion_transform);
// Disable instance transform if object uses motion transform already
instance.flags = OPTIX_INSTANCE_FLAG_DISABLE_TRANSFORM;
// Get traversable handle to motion transform
optixConvertPointerToTraversableHandle(context,
motion_transform_gpu,
OPTIX_TRAVERSABLE_TYPE_SRT_MOTION_TRANSFORM,
&instance.traversableHandle);
}
else {
// Disable instance transform if geometry already has it applied to vertex data
instance.flags = OPTIX_INSTANCE_FLAG_DISABLE_TRANSFORM;
// Non-instanced objects read ID from prim_object, so
// distinguish them from instanced objects with high bit set
instance.instanceId |= 0x800000;
instance.traversableHandle = handle;
if (ob->get_geometry()->is_instanced()) {
// Set transform matrix
memcpy(instance.transform, &ob->get_tfm(), sizeof(instance.transform));
}
else {
// Disable instance transform if geometry already has it applied to vertex data
instance.flags = OPTIX_INSTANCE_FLAG_DISABLE_TRANSFORM;
// Non-instanced objects read ID from 'prim_object', so distinguish
// them from instanced objects with the low bit set
instance.instanceId |= 1;
}
}
}
}
// Upload instance descriptions
// Upload instance descriptions
# if OPTIX_ABI_VERSION < 41
aabbs.resize(num_instances);
aabbs.copy_to_device();
aabbs.resize(num_instances);
aabbs.copy_to_device();
# endif
instances.resize(num_instances);
instances.copy_to_device();
instances.resize(num_instances);
instances.copy_to_device();
// Build top-level acceleration structure (TLAS)
OptixBuildInput build_input = {};
build_input.type = OPTIX_BUILD_INPUT_TYPE_INSTANCES;
// Build top-level acceleration structure (TLAS)
OptixBuildInput build_input = {};
build_input.type = OPTIX_BUILD_INPUT_TYPE_INSTANCES;
# if OPTIX_ABI_VERSION < 41 // Instance AABBs no longer need to be set since OptiX 7.2
build_input.instanceArray.aabbs = aabbs.device_pointer;
build_input.instanceArray.numAabbs = num_instances;
build_input.instanceArray.aabbs = aabbs.device_pointer;
build_input.instanceArray.numAabbs = num_instances;
# endif
build_input.instanceArray.instances = instances.device_pointer;
build_input.instanceArray.numInstances = num_instances;
build_input.instanceArray.instances = instances.device_pointer;
build_input.instanceArray.numInstances = num_instances;
CUdeviceptr out_data = 0;
tlas_handle = 0;
return build_optix_bvh(build_input, 0, tlas_handle, out_data, OPTIX_BUILD_OPERATION_BUILD);
if (!build_optix_bvh(bvh_optix, OPTIX_BUILD_OPERATION_BUILD, build_input, 0)) {
progress.set_error("Failed to build OptiX acceleration structure");
}
tlas_handle = bvh_optix->traversable_handle;
}
}
void const_copy_to(const char *name, void *host, size_t size) override
@@ -1724,7 +1734,7 @@ class OptiXDevice : public CUDADevice {
if (strcmp(name, "__data") == 0) {
assert(size <= sizeof(KernelData));
// Fix traversable handle on multi devices
// Update traversable handle (since it is different for each device on multi devices)
KernelData *const data = (KernelData *)host;
*(OptixTraversableHandle *)&data->bvh.scene = tlas_handle;

View File

@@ -780,13 +780,25 @@ bool OpenCLInfo::device_supported(const string &platform_name, const cl_device_i
return true;
}
/* It is possible to have Iris GPU on AMD/Apple OpenCL framework
* (aka, it will not be on Intel framework). This isn't supported
* and needs an explicit blacklist.
*/
if (strstr(device_name.c_str(), "Iris")) {
/* Allow Intel GPUs on Intel OpenCL platform. */
if (platform_name.find("Intel") != string::npos) {
if (device_type != CL_DEVICE_TYPE_GPU) {
/* OpenCL on Intel CPU is not an officially supported configuration.
* Use hybrid CPU+GPU rendering to utilize both GPU and CPU. */
return false;
}
# ifdef __APPLE__
/* Apple uses own framework, which can also put Iris onto AMD frame-work.
* This isn't supported configuration. */
return false;
# else
if (device_name.find("Iris") != string::npos || device_name.find("Xe") != string::npos) {
return true;
}
# endif
}
if (platform_name == "AMD Accelerated Parallel Processing" &&
device_type == CL_DEVICE_TYPE_GPU) {
if (driver_major < 2236) {

View File

@@ -112,8 +112,7 @@ ccl_device_inline void kernel_embree_convert_hit(KernelGlobals *kg,
RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData(
rtcGetGeometry(kernel_data.bvh.scene, hit->instID[0]));
isect->prim = hit->primID +
(intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID)) +
kernel_tex_fetch(__object_node, hit->instID[0] / 2);
(intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID));
isect->object = hit->instID[0] / 2;
}
else {
@@ -137,8 +136,7 @@ ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals *kg,
RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData(
rtcGetGeometry(kernel_data.bvh.scene, local_object_id * 2));
isect->prim = hit->primID +
(intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID)) +
kernel_tex_fetch(__object_node, local_object_id);
(intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID));
isect->object = local_object_id;
isect->type = kernel_tex_fetch(__prim_type, isect->prim);
}

View File

@@ -214,13 +214,6 @@ ccl_device_inline float3 object_location(KernelGlobals *kg, const ShaderData *sd
#endif
}
/* Total surface area of object */
ccl_device_inline float object_surface_area(KernelGlobals *kg, int object)
{
return kernel_tex_fetch(__objects, object).surface_area;
}
/* Color of the object */
ccl_device_inline float3 object_color(KernelGlobals *kg, int object)
@@ -328,7 +321,7 @@ ccl_device_inline float object_volume_density(KernelGlobals *kg, int object)
return 1.0f;
}
return kernel_tex_fetch(__objects, object).surface_area;
return kernel_tex_fetch(__objects, object).volume_density;
}
ccl_device_inline float object_volume_step_size(KernelGlobals *kg, int object)

View File

@@ -1397,10 +1397,12 @@ typedef enum KernelBVHLayout {
BVH_LAYOUT_BVH2 = (1 << 0),
BVH_LAYOUT_EMBREE = (1 << 1),
BVH_LAYOUT_OPTIX = (1 << 2),
BVH_LAYOUT_MULTI_OPTIX = (1 << 3),
BVH_LAYOUT_MULTI_OPTIX_EMBREE = (1 << 4),
/* Default BVH layout to use for CPU. */
BVH_LAYOUT_AUTO = BVH_LAYOUT_EMBREE,
BVH_LAYOUT_ALL = (unsigned int)(~0u),
BVH_LAYOUT_ALL = BVH_LAYOUT_BVH2 | BVH_LAYOUT_EMBREE | BVH_LAYOUT_OPTIX,
} KernelBVHLayout;
typedef struct KernelBVH {
@@ -1459,7 +1461,7 @@ typedef struct KernelObject {
Transform tfm;
Transform itfm;
float surface_area;
float volume_density;
float pass_id;
float random_number;
float color[3];

View File

@@ -45,13 +45,12 @@ template<bool always = false> ccl_device_forceinline uint get_object_id()
uint object = optixGetInstanceId();
#endif
// Choose between always returning object ID or only for instances
if (always)
// Can just remove the high bit since instance always contains object ID
return object & 0x7FFFFF;
// Set to OBJECT_NONE if this is not an instanced object
else if (object & 0x800000)
object = OBJECT_NONE;
return object;
if (always || (object & 1) == 0)
// Can just remove the low bit since instance always contains object ID
return object >> 1;
else
// Set to OBJECT_NONE if this is not an instanced object
return OBJECT_NONE;
}
extern "C" __global__ void __raygen__kernel_optix_path_trace()

View File

@@ -109,7 +109,7 @@ static void shaderdata_to_shaderglobals(
globals->dvdy = sd->dv.dy;
globals->dPdu = TO_VEC3(sd->dPdu);
globals->dPdv = TO_VEC3(sd->dPdv);
globals->surfacearea = (sd->object == OBJECT_NONE) ? 1.0f : object_surface_area(kg, sd->object);
globals->surfacearea = 1.0f;
globals->time = sd->time;
/* booleans */

View File

@@ -15,8 +15,7 @@
*/
#include "bvh/bvh.h"
#include "bvh/bvh_build.h"
#include "bvh/bvh_embree.h"
#include "bvh/bvh2.h"
#include "device/device.h"
@@ -41,6 +40,7 @@
#include "util/util_foreach.h"
#include "util/util_logging.h"
#include "util/util_progress.h"
#include "util/util_task.h"
CCL_NAMESPACE_BEGIN
@@ -162,7 +162,8 @@ int Geometry::motion_step(float time) const
bool Geometry::need_build_bvh(BVHLayout layout) const
{
return !transform_applied || has_surface_bssrdf || layout == BVH_LAYOUT_OPTIX;
return is_instanced() || layout == BVH_LAYOUT_OPTIX || layout == BVH_LAYOUT_MULTI_OPTIX ||
layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE;
}
bool Geometry::is_instanced() const
@@ -218,7 +219,7 @@ void Geometry::compute_bvh(
bvh->geometry = geometry;
bvh->objects = objects;
bvh->refit(*progress);
device->build_bvh(bvh, *progress, true);
}
else {
progress->set_status(msg, "Building BVH");
@@ -235,7 +236,7 @@ void Geometry::compute_bvh(
delete bvh;
bvh = BVH::create(bparams, geometry, objects, device);
MEM_GUARDED_CALL(progress, bvh->build, *progress);
MEM_GUARDED_CALL(progress, device->build_bvh, bvh, *progress, false);
}
}
@@ -279,6 +280,15 @@ void Geometry::tag_update(Scene *scene, bool rebuild)
scene->object_manager->need_update = true;
}
void Geometry::tag_bvh_update(bool rebuild)
{
tag_modified();
if (rebuild) {
need_update_rebuild = true;
}
}
/* Geometry Manager */
GeometryManager::GeometryManager()
@@ -914,7 +924,7 @@ void GeometryManager::device_update_attributes(Device *device,
scene->object_manager->device_update_mesh_offsets(device, dscene, scene);
}
void GeometryManager::mesh_calc_offset(Scene *scene)
void GeometryManager::mesh_calc_offset(Scene *scene, BVHLayout bvh_layout)
{
size_t vert_size = 0;
size_t tri_size = 0;
@@ -929,6 +939,14 @@ void GeometryManager::mesh_calc_offset(Scene *scene)
size_t optix_prim_size = 0;
foreach (Geometry *geom, scene->geometry) {
if (geom->optix_prim_offset != optix_prim_size) {
/* Need to rebuild BVH in OptiX, since refit only allows modified mesh data there */
const bool has_optix_bvh = bvh_layout == BVH_LAYOUT_OPTIX ||
bvh_layout == BVH_LAYOUT_MULTI_OPTIX ||
bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE;
geom->tag_bvh_update(has_optix_bvh);
}
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
@@ -1162,25 +1180,66 @@ void GeometryManager::device_update_bvh(Device *device,
VLOG(1) << "Using " << bvh_layout_name(bparams.bvh_layout) << " layout.";
BVH *bvh = BVH::create(bparams, scene->geometry, scene->objects, device);
bvh->build(progress, &device->stats);
delete scene->bvh;
BVH *bvh = scene->bvh = BVH::create(bparams, scene->geometry, scene->objects, device);
device->build_bvh(bvh, progress, false);
if (progress.get_cancel()) {
#ifdef WITH_EMBREE
if (dscene->data.bvh.scene) {
BVHEmbree::destroy(dscene->data.bvh.scene);
dscene->data.bvh.scene = NULL;
}
#endif
delete bvh;
return;
}
PackedBVH pack;
if (bparams.bvh_layout == BVH_LAYOUT_BVH2) {
pack = std::move(static_cast<BVH2 *>(bvh)->pack);
}
else {
progress.set_status("Updating Scene BVH", "Packing BVH primitives");
size_t num_prims = 0;
size_t num_tri_verts = 0;
foreach (Geometry *geom, scene->geometry) {
if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) {
Mesh *mesh = static_cast<Mesh *>(geom);
num_prims += mesh->num_triangles();
num_tri_verts += 3 * mesh->num_triangles();
}
else if (geom->is_hair()) {
Hair *hair = static_cast<Hair *>(geom);
num_prims += hair->num_segments();
}
}
pack.root_index = -1;
pack.prim_tri_index.reserve(num_prims);
pack.prim_tri_verts.reserve(num_tri_verts);
pack.prim_type.reserve(num_prims);
pack.prim_index.reserve(num_prims);
pack.prim_object.reserve(num_prims);
pack.prim_visibility.reserve(num_prims);
// Merge visibility flags of all objects and find object index for non-instanced geometry
unordered_map<const Geometry *, pair<int, uint>> geometry_to_object_info;
geometry_to_object_info.reserve(scene->geometry.size());
foreach (Object *ob, scene->objects) {
const Geometry *const geom = ob->get_geometry();
pair<int, uint> &info = geometry_to_object_info[geom];
info.second |= ob->visibility_for_tracing();
if (!geom->is_instanced()) {
info.first = ob->get_device_index();
}
}
// Iterate over scene mesh list instead of objects, since 'optix_prim_offset' was calculated
// based on that list, which may be ordered differently from the object list.
foreach (Geometry *geom, scene->geometry) {
const pair<int, uint> &info = geometry_to_object_info[geom];
geom->pack_primitives(pack, info.first, info.second);
}
}
/* copy to device */
progress.set_status("Updating Scene BVH", "Copying BVH to device");
PackedBVH &pack = bvh->pack;
if (pack.nodes.size()) {
dscene->bvh_nodes.steal_data(pack.nodes);
dscene->bvh_nodes.copy_to_device();
@@ -1226,10 +1285,8 @@ void GeometryManager::device_update_bvh(Device *device,
dscene->data.bvh.bvh_layout = bparams.bvh_layout;
dscene->data.bvh.use_bvh_steps = (scene->params.num_bvh_time_steps != 0);
dscene->data.bvh.curve_subdivisions = scene->params.curve_subdivisions();
bvh->copy_to_device(progress, dscene);
delete bvh;
/* The scene handle is set in 'CPUDevice::const_copy_to' and 'OptiXDevice::const_copy_to' */
dscene->data.bvh.scene = NULL;
}
void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Progress &progress)
@@ -1486,7 +1543,9 @@ void GeometryManager::device_update(Device *device,
/* Device update. */
device_free(device, dscene);
mesh_calc_offset(scene);
const BVHLayout bvh_layout = BVHParams::best_bvh_layout(scene->params.bvh_layout,
device->get_bvh_layout_mask());
mesh_calc_offset(scene, bvh_layout);
if (true_displacement_used) {
scoped_callback_timer timer([scene](double time) {
if (scene->update_stats) {
@@ -1513,8 +1572,6 @@ void GeometryManager::device_update(Device *device,
}
/* Update displacement. */
BVHLayout bvh_layout = BVHParams::best_bvh_layout(scene->params.bvh_layout,
device->get_bvh_layout_mask());
bool displacement_done = false;
size_t num_bvh = 0;
@@ -1653,14 +1710,6 @@ void GeometryManager::device_update(Device *device,
void GeometryManager::device_free(Device *device, DeviceScene *dscene)
{
#ifdef WITH_EMBREE
if (dscene->data.bvh.scene) {
if (dscene->data.bvh.bvh_layout == BVH_LAYOUT_EMBREE)
BVHEmbree::destroy(dscene->data.bvh.scene);
dscene->data.bvh.scene = NULL;
}
#endif
dscene->bvh_nodes.free();
dscene->bvh_leaf_nodes.free();
dscene->object_node.free();

View File

@@ -41,6 +41,7 @@ class Scene;
class SceneParams;
class Shader;
class Volume;
struct PackedBVH;
/* Geometry
*
@@ -124,6 +125,8 @@ class Geometry : public Node {
int n,
int total);
virtual void pack_primitives(PackedBVH &pack, int object, uint visibility) = 0;
/* Check whether the geometry should have own BVH built separately. Briefly,
* own BVH is needed for geometry, if:
*
@@ -154,6 +157,8 @@ class Geometry : public Node {
/* Updates */
void tag_update(Scene *scene, bool rebuild);
void tag_bvh_update(bool rebuild);
};
/* Geometry Manager */
@@ -195,7 +200,7 @@ class GeometryManager {
vector<AttributeRequestSet> &object_attributes);
/* Compute verts/triangles/curves offsets in global arrays. */
void mesh_calc_offset(Scene *scene);
void mesh_calc_offset(Scene *scene, BVHLayout bvh_layout);
void device_update_object(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);

View File

@@ -14,8 +14,10 @@
* limitations under the License.
*/
#include "render/hair.h"
#include "bvh/bvh.h"
#include "render/curves.h"
#include "render/hair.h"
#include "render/scene.h"
CCL_NAMESPACE_BEGIN
@@ -492,4 +494,35 @@ void Hair::pack_curves(Scene *scene,
}
}
void Hair::pack_primitives(PackedBVH &pack, int object, uint visibility)
{
if (curve_first_key.empty())
return;
const size_t num_prims = num_segments();
pack.prim_tri_index.reserve(pack.prim_tri_index.size() + num_prims);
pack.prim_type.reserve(pack.prim_type.size() + num_prims);
pack.prim_visibility.reserve(pack.prim_visibility.size() + num_prims);
pack.prim_index.reserve(pack.prim_index.size() + num_prims);
pack.prim_object.reserve(pack.prim_object.size() + num_prims);
// 'pack.prim_time' is unused by Embree and OptiX
uint type = has_motion_blur() ?
((curve_shape == CURVE_RIBBON) ? PRIMITIVE_MOTION_CURVE_RIBBON :
PRIMITIVE_MOTION_CURVE_THICK) :
((curve_shape == CURVE_RIBBON) ? PRIMITIVE_CURVE_RIBBON : PRIMITIVE_CURVE_THICK);
for (size_t j = 0; j < num_curves(); ++j) {
Curve curve = get_curve(j);
for (size_t k = 0; k < curve.num_segments(); ++k) {
pack.prim_tri_index.push_back_reserved(-1);
pack.prim_type.push_back_reserved(PRIMITIVE_PACK_SEGMENT(type, k));
pack.prim_visibility.push_back_reserved(visibility);
// Each curve segment points back to its curve index
pack.prim_index.push_back_reserved(j + prim_offset);
pack.prim_object.push_back_reserved(object);
}
}
}
CCL_NAMESPACE_END

View File

@@ -145,6 +145,8 @@ class Hair : public Geometry {
/* BVH */
void pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset);
void pack_primitives(PackedBVH &pack, int object, uint visibility) override;
};
CCL_NAMESPACE_END

View File

@@ -493,8 +493,8 @@ static bool image_associate_alpha(ImageManager::Image *img)
template<TypeDesc::BASETYPE FileFormat, typename StorageType>
bool ImageManager::file_load_image(Image *img, int texture_limit)
{
/* we only handle certain number of components */
if (!(img->metadata.channels >= 1 && img->metadata.channels <= 4)) {
/* Ignore empty images. */
if (!(img->metadata.channels > 0)) {
return false;
}

View File

@@ -805,4 +805,35 @@ void Mesh::pack_patches(uint *patch_data, uint vert_offset, uint face_offset, ui
}
}
void Mesh::pack_primitives(PackedBVH &pack, int object, uint visibility)
{
if (triangles.empty())
return;
const size_t num_prims = num_triangles();
pack.prim_tri_index.reserve(pack.prim_tri_index.size() + num_prims);
pack.prim_tri_verts.reserve(pack.prim_tri_verts.size() + num_prims * 3);
pack.prim_type.reserve(pack.prim_type.size() + num_prims);
pack.prim_visibility.reserve(pack.prim_visibility.size() + num_prims);
pack.prim_index.reserve(pack.prim_index.size() + num_prims);
pack.prim_object.reserve(pack.prim_object.size() + num_prims);
// 'pack.prim_time' is unused by Embree and OptiX
uint type = has_motion_blur() ? PRIMITIVE_MOTION_TRIANGLE : PRIMITIVE_TRIANGLE;
for (size_t k = 0; k < num_prims; ++k) {
pack.prim_tri_index.push_back_reserved(pack.prim_tri_verts.size());
const Mesh::Triangle t = get_triangle(k);
pack.prim_tri_verts.push_back_reserved(float3_to_float4(verts[t.v[0]]));
pack.prim_tri_verts.push_back_reserved(float3_to_float4(verts[t.v[1]]));
pack.prim_tri_verts.push_back_reserved(float3_to_float4(verts[t.v[2]]));
pack.prim_type.push_back_reserved(type);
pack.prim_visibility.push_back_reserved(visibility);
pack.prim_index.push_back_reserved(k + prim_offset);
pack.prim_object.push_back_reserved(object);
}
}
CCL_NAMESPACE_END

View File

@@ -184,9 +184,8 @@ class Mesh : public Geometry {
unordered_multimap<int, int>
vert_stitching_map; /* stitching index -> multiple real vert indices */
friend class BVH;
friend class BVH2;
friend class BVHBuild;
friend class BVHEmbree;
friend class BVHSpatialSplit;
friend class DiagSplit;
friend class EdgeDice;
@@ -233,6 +232,8 @@ class Mesh : public Geometry {
size_t tri_offset);
void pack_patches(uint *patch_data, uint vert_offset, uint face_offset, uint corner_offset);
void pack_primitives(PackedBVH &pack, int object, uint visibility) override;
void tessellate(DiagSplit *split);
SubdFace get_subd_face(size_t index) const;

View File

@@ -55,12 +55,6 @@ struct UpdateObjectTransformState {
*/
map<ParticleSystem *, int> particle_offset;
/* Mesh area.
* Used to avoid calculation of mesh area multiple times. Used for both
* read and write. Acquire surface_area_lock to keep it all thread safe.
*/
map<Mesh *, float> surface_area_map;
/* Motion offsets for each object. */
array<uint> motion_offset;
@@ -76,12 +70,8 @@ struct UpdateObjectTransformState {
bool have_curves;
/* ** Scheduling queue. ** */
Scene *scene;
/* Some locks to keep everything thread-safe. */
thread_spin_lock surface_area_lock;
/* First unused object index in the queue. */
int queue_start_object;
};
@@ -379,80 +369,17 @@ ObjectManager::~ObjectManager()
{
}
static float object_surface_area(UpdateObjectTransformState *state,
const Transform &tfm,
Geometry *geom)
static float object_volume_density(const Transform &tfm, Geometry *geom)
{
if (geom->geometry_type != Geometry::MESH && geom->geometry_type != Geometry::VOLUME) {
return 0.0f;
}
Mesh *mesh = static_cast<Mesh *>(geom);
if (mesh->has_volume || geom->geometry_type == Geometry::VOLUME) {
if (geom->geometry_type == Geometry::VOLUME) {
/* Volume density automatically adjust to object scale. */
if (geom->geometry_type == Geometry::VOLUME &&
static_cast<Volume *>(geom)->get_object_space()) {
if (static_cast<Volume *>(geom)->get_object_space()) {
const float3 unit = normalize(make_float3(1.0f, 1.0f, 1.0f));
return 1.0f / len(transform_direction(&tfm, unit));
}
else {
return 1.0f;
}
}
/* Compute surface area. for uniform scale we can do avoid the many
* transform calls and share computation for instances.
*
* TODO(brecht): Correct for displacement, and move to a better place.
*/
float surface_area = 0.0f;
float uniform_scale;
if (transform_uniform_scale(tfm, uniform_scale)) {
map<Mesh *, float>::iterator it;
/* NOTE: This isn't fully optimal and could in theory lead to multiple
* threads calculating area of the same mesh in parallel. However, this
* also prevents suspending all the threads when some mesh's area is
* not yet known.
*/
state->surface_area_lock.lock();
it = state->surface_area_map.find(mesh);
state->surface_area_lock.unlock();
if (it == state->surface_area_map.end()) {
size_t num_triangles = mesh->num_triangles();
for (size_t j = 0; j < num_triangles; j++) {
Mesh::Triangle t = mesh->get_triangle(j);
float3 p1 = mesh->get_verts()[t.v[0]];
float3 p2 = mesh->get_verts()[t.v[1]];
float3 p3 = mesh->get_verts()[t.v[2]];
surface_area += triangle_area(p1, p2, p3);
}
state->surface_area_lock.lock();
state->surface_area_map[mesh] = surface_area;
state->surface_area_lock.unlock();
}
else {
surface_area = it->second;
}
surface_area *= uniform_scale;
}
else {
size_t num_triangles = mesh->num_triangles();
for (size_t j = 0; j < num_triangles; j++) {
Mesh::Triangle t = mesh->get_triangle(j);
float3 p1 = transform_point(&tfm, mesh->get_verts()[t.v[0]]);
float3 p2 = transform_point(&tfm, mesh->get_verts()[t.v[1]]);
float3 p3 = transform_point(&tfm, mesh->get_verts()[t.v[2]]);
surface_area += triangle_area(p1, p2, p3);
}
}
return surface_area;
return 1.0f;
}
void ObjectManager::device_update_object_transform(UpdateObjectTransformState *state, Object *ob)
@@ -476,7 +403,7 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
kobject.tfm = tfm;
kobject.itfm = itfm;
kobject.surface_area = object_surface_area(state, tfm, geom);
kobject.volume_density = object_volume_density(tfm, geom);
kobject.color[0] = color.x;
kobject.color[1] = color.y;
kobject.color[2] = color.z;

View File

@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "bvh/bvh.h"
#include "device/device.h"
#include "render/background.h"
#include "render/bake.h"
@@ -100,6 +101,7 @@ Scene::Scene(const SceneParams &params_, Device *device)
{
memset((void *)&dscene.data, 0, sizeof(dscene.data));
bvh = NULL;
camera = create_node<Camera>();
dicing_camera = create_node<Camera>();
lookup_tables = new LookupTables();
@@ -135,6 +137,9 @@ Scene::~Scene()
void Scene::free_memory(bool final)
{
delete bvh;
bvh = NULL;
foreach (Shader *s, shaders)
delete s;
foreach (Geometry *g, geometry)

View File

@@ -38,6 +38,7 @@ CCL_NAMESPACE_BEGIN
class AttributeRequestSet;
class Background;
class BVH;
class Camera;
class Device;
class DeviceInfo;
@@ -220,6 +221,7 @@ class Scene : public NodeOwner {
string name;
/* data */
BVH *bvh;
Camera *camera;
Camera *dicing_camera;
LookupTables *lookup_tables;

View File

@@ -347,8 +347,15 @@ void Shader::tag_update(Scene *scene)
foreach (ShaderNode *node, graph->nodes)
node->attributes(this, &attributes);
if (has_displacement && displacement_method == DISPLACE_BOTH) {
attributes.add(ATTR_STD_POSITION_UNDISPLACED);
if (has_displacement) {
if (displacement_method == DISPLACE_BOTH) {
attributes.add(ATTR_STD_POSITION_UNDISPLACED);
}
if (displacement_method_is_modified()) {
need_update_geometry = true;
scene->geometry_manager->need_update = true;
scene->object_manager->need_flags_update = true;
}
}
/* compare if the attributes changed, mesh manager will check

View File

@@ -548,22 +548,23 @@ void SVMCompiler::generated_shared_closure_nodes(ShaderNode *root_node,
}
}
void SVMCompiler::generate_aov_node(ShaderNode *node, CompilerState *state)
void SVMCompiler::find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes,
ShaderGraph *graph,
CompilerState *state)
{
/* execute dependencies for node */
foreach (ShaderInput *in, node->inputs) {
if (in->link != NULL) {
ShaderNodeSet dependencies;
find_dependencies(dependencies, state->nodes_done, in);
generate_svm_nodes(dependencies, state);
foreach (ShaderNode *node, graph->nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
OutputAOVNode *aov_node = static_cast<OutputAOVNode *>(node);
if (aov_node->slot >= 0) {
aov_nodes.insert(aov_node);
foreach (ShaderInput *in, node->inputs) {
if (in->link != NULL) {
find_dependencies(aov_nodes, state->nodes_done, in);
}
}
}
}
}
/* compile node itself */
generate_node(node, state->nodes_done);
state->nodes_done.insert(node);
state->nodes_done_flag[node->id] = true;
}
void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
@@ -631,6 +632,25 @@ void SVMCompiler::generate_multi_closure(ShaderNode *root_node,
}
}
/* For dependencies AOV nodes, prevent them from being categorized
* as exclusive deps of one or the other closure, since the need to
* execute them for AOV writing is not dependent on the closure
* weights. */
if (state->aov_nodes.size()) {
set_intersection(state->aov_nodes.begin(),
state->aov_nodes.end(),
cl1deps.begin(),
cl1deps.end(),
std::inserter(shareddeps, shareddeps.begin()),
node_id_comp);
set_intersection(state->aov_nodes.begin(),
state->aov_nodes.end(),
cl2deps.begin(),
cl2deps.end(),
std::inserter(shareddeps, shareddeps.begin()),
node_id_comp);
}
if (!shareddeps.empty()) {
if (cl1in->link) {
generated_shared_closure_nodes(root_node, cl1in->link->parent, state, shareddeps);
@@ -782,6 +802,9 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
}
if (generate) {
if (type == SHADER_TYPE_SURFACE) {
find_aov_nodes_and_dependencies(state.aov_nodes, graph, &state);
}
generate_multi_closure(clin->link->parent, clin->link->parent, &state);
}
}
@@ -789,28 +812,15 @@ void SVMCompiler::compile_type(Shader *shader, ShaderGraph *graph, ShaderType ty
/* compile output node */
output->compile(*this);
if (type == SHADER_TYPE_SURFACE) {
vector<OutputAOVNode *> aov_outputs;
foreach (ShaderNode *node, graph->nodes) {
if (node->special_type == SHADER_SPECIAL_TYPE_OUTPUT_AOV) {
OutputAOVNode *aov_node = static_cast<OutputAOVNode *>(node);
if (aov_node->slot >= 0) {
aov_outputs.push_back(aov_node);
}
}
}
if (aov_outputs.size() > 0) {
/* AOV passes are only written if the object is directly visible, so
* there is no point in evaluating all the nodes generated only for the
* AOV outputs if that's not the case. Therefore, we insert
* NODE_AOV_START into the shader before the AOV-only nodes are
* generated which tells the kernel that it can stop evaluation
* early if AOVs will not be written. */
add_node(NODE_AOV_START, 0, 0, 0);
foreach (OutputAOVNode *node, aov_outputs) {
generate_aov_node(node, &state);
}
}
if (!state.aov_nodes.empty()) {
/* AOV passes are only written if the object is directly visible, so
* there is no point in evaluating all the nodes generated only for the
* AOV outputs if that's not the case. Therefore, we insert
* NODE_AOV_START into the shader before the AOV-only nodes are
* generated which tells the kernel that it can stop evaluation
* early if AOVs will not be written. */
add_node(NODE_AOV_START, 0, 0, 0);
generate_svm_nodes(state.aov_nodes, &state);
}
}

View File

@@ -176,6 +176,9 @@ class SVMCompiler {
/* Set of closures which were already compiled. */
ShaderNodeSet closure_done;
/* Set of nodes used for writing AOVs. */
ShaderNodeSet aov_nodes;
/* ** SVM nodes generation state ** */
/* Flag whether the node with corresponding ID was already compiled or
@@ -197,6 +200,9 @@ class SVMCompiler {
const ShaderNodeSet &done,
ShaderInput *input,
ShaderNode *skip_node = NULL);
void find_aov_nodes_and_dependencies(ShaderNodeSet &aov_nodes,
ShaderGraph *graph,
CompilerState *state);
void generate_node(ShaderNode *node, ShaderNodeSet &done);
void generate_aov_node(ShaderNode *node, CompilerState *state);
void generate_closure_node(ShaderNode *node, CompilerState *state);

View File

@@ -187,6 +187,11 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
${X11_X11_INCLUDE_PATH}
)
list(APPEND LIB
${X11_X11_LIB}
${X11_Xrender_LIB}
)
list(APPEND SRC
intern/GHOST_DisplayManagerX11.cpp
intern/GHOST_SystemX11.cpp
@@ -238,6 +243,9 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
list(APPEND INC_SYS
${X11_xf86vmode_INCLUDE_PATH}
)
list(APPEND LIB
${X11_Xf86vmode_LIB}
)
endif()
if(WITH_X11_XFIXES)
@@ -245,6 +253,9 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
list(APPEND INC_SYS
${X11_Xfixes_INCLUDE_PATH}
)
list(APPEND LIB
${X11_Xfixes_LIB}
)
endif()
if(WITH_X11_ALPHA)
@@ -256,6 +267,9 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND)
list(APPEND INC_SYS
${X11_Xinput_INCLUDE_PATH}
)
list(APPEND LIB
${X11_Xinput_LIB}
)
endif()
add_definitions(-DWITH_GHOST_X11)

View File

@@ -1052,7 +1052,7 @@ int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_context);
/**
* Check if \a xr_context has a session that requires an upside-down frame-buffer (compared to
* OpenGL). If true, the render result should be flipped vertically for correct output.
* \note: Only to be called after session start, may otherwise result in a false negative.
* \note Only to be called after session start, may otherwise result in a false negative.
*/
int GHOST_XrSessionNeedsUpsideDownDrawing(const GHOST_XrContextHandle xr_context);

View File

@@ -77,6 +77,12 @@ class GHOST_ISystemPaths {
*/
virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const = 0;
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user dir (eg `~/Documents/`).
*/
virtual const GHOST_TUns8 *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const = 0;
/**
* Determine the directory of the current binary
* \return Unsigned char string pointing to the binary dir

View File

@@ -56,6 +56,12 @@ extern const GHOST_TUns8 *GHOST_getSystemDir(int version, const char *versionstr
*/
extern const GHOST_TUns8 *GHOST_getUserDir(int version, const char *versionstr);
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user dir (eg `~/Documents/`).
*/
extern const GHOST_TUns8 *GHOST_getUserSpecialDir(GHOST_TUserSpecialDirTypes type);
/**
* Determine the dir in which the binary file is found.
* \return Unsigned char string pointing to binary dir (eg ~/usr/local/bin/).

View File

@@ -565,6 +565,16 @@ typedef struct {
char is_repeat;
} GHOST_TEventKeyData;
typedef enum {
GHOST_kUserSpecialDirDesktop,
GHOST_kUserSpecialDirDocuments,
GHOST_kUserSpecialDirDownloads,
GHOST_kUserSpecialDirMusic,
GHOST_kUserSpecialDirPictures,
GHOST_kUserSpecialDirVideos,
/* Can be extended as needed. */
} GHOST_TUserSpecialDirTypes;
typedef struct {
/** Number of pixels on a line. */
GHOST_TUns32 xPixels;

View File

@@ -50,6 +50,12 @@ const GHOST_TUns8 *GHOST_getUserDir(int version, const char *versionstr)
return systemPaths ? systemPaths->getUserDir(version, versionstr) : NULL; /* shouldn't be NULL */
}
const GHOST_TUns8 *GHOST_getUserSpecialDir(GHOST_TUserSpecialDirTypes type)
{
GHOST_ISystemPaths *systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getUserSpecialDir(type) : NULL; /* shouldn't be NULL */
}
const GHOST_TUns8 *GHOST_getBinaryDir()
{
GHOST_ISystemPaths *systemPaths = GHOST_ISystemPaths::get();

View File

@@ -82,8 +82,8 @@ static GHOST_TButtonMask convertButton(int button)
/**
* Converts Mac rawkey codes (same for Cocoa & Carbon)
* into GHOST key codes
* \param rawCode The raw physical key code
* \param recvChar the character ignoring modifiers (except for shift)
* \param rawCode: The raw physical key code
* \param recvChar: the character ignoring modifiers (except for shift)
* \return Ghost key code
*/
static GHOST_TKey convertKey(int rawCode, unichar recvChar, UInt16 keyAction)
@@ -783,7 +783,7 @@ GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext(GHOST_GLSettings glSet
/**
* Dispose of a context.
* \param context Pointer to the context to be disposed.
* \param context: Pointer to the context to be disposed.
* \return Indication of success.
*/
GHOST_TSuccess GHOST_SystemCocoa::disposeContext(GHOST_IContext *context)
@@ -1730,13 +1730,14 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
}
window->clientToScreenIntern(mousePos.x, mousePos.y, x, y);
NSPoint delta = [[cocoawindow contentView] convertPointToBacking:NSMakePoint(dx, dy)];
pushEvent(new GHOST_EventTrackpad([event timestamp] * 1000,
window,
GHOST_kTrackpadEventScroll,
x,
y,
dx,
dy,
delta.x,
delta.y,
[event isDirectionInvertedFromDevice]));
}
} break;

View File

@@ -55,6 +55,12 @@ class GHOST_SystemPathsCocoa : public GHOST_SystemPaths {
*/
const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const;
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user dir (eg `~/Documents/`).
*/
const GHOST_TUns8 *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const;
/**
* Determine the directory of the current binary
* \return Unsigned char string pointing to the binary dir

View File

@@ -21,6 +21,7 @@
#import <Foundation/Foundation.h>
#include "GHOST_Debug.h"
#include "GHOST_SystemPathsCocoa.h"
#pragma mark initialization/finalization
@@ -89,6 +90,57 @@ const GHOST_TUns8 *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionst
return (GHOST_TUns8 *)tempPath;
}
const GHOST_TUns8 *GHOST_SystemPathsCocoa::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
{
static char tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
NSSearchPathDirectory ns_directory;
switch (type) {
case GHOST_kUserSpecialDirDesktop:
ns_directory = NSDesktopDirectory;
break;
case GHOST_kUserSpecialDirDocuments:
ns_directory = NSDocumentDirectory;
break;
case GHOST_kUserSpecialDirDownloads:
ns_directory = NSDownloadsDirectory;
break;
case GHOST_kUserSpecialDirMusic:
ns_directory = NSMusicDirectory;
break;
case GHOST_kUserSpecialDirPictures:
ns_directory = NSPicturesDirectory;
break;
case GHOST_kUserSpecialDirVideos:
ns_directory = NSMoviesDirectory;
break;
default:
GHOST_ASSERT(
false,
"GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
[pool drain];
return NULL;
}
paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strncpy(
(char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
[pool drain];
return (GHOST_TUns8 *)tempPath;
}
const GHOST_TUns8 *GHOST_SystemPathsCocoa::getBinaryDir() const
{
static GHOST_TUns8 tempPath[512] = "";

View File

@@ -21,6 +21,9 @@
* \ingroup GHOST
*/
#include <cstdio>
#include <sstream>
#include "GHOST_SystemPathsUnix.h"
#include "GHOST_Debug.h"
@@ -108,6 +111,62 @@ const GHOST_TUns8 *GHOST_SystemPathsUnix::getUserDir(int version, const char *ve
}
}
const GHOST_TUns8 *GHOST_SystemPathsUnix::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
{
const char *type_str;
switch (type) {
case GHOST_kUserSpecialDirDesktop:
type_str = "DESKTOP";
break;
case GHOST_kUserSpecialDirDocuments:
type_str = "DOCUMENTS";
break;
case GHOST_kUserSpecialDirDownloads:
type_str = "DOWNLOAD";
break;
case GHOST_kUserSpecialDirMusic:
type_str = "MUSIC";
break;
case GHOST_kUserSpecialDirPictures:
type_str = "PICTURES";
break;
case GHOST_kUserSpecialDirVideos:
type_str = "VIDEOS";
break;
default:
GHOST_ASSERT(
false,
"GHOST_SystemPathsUnix::getUserSpecialDir(): Invalid enum value for type parameter");
return NULL;
}
static string path = "";
/* Pipe stderr to /dev/null to avoid error prints. We will fail gracefully still. */
string command = string("xdg-user-dir ") + type_str + " 2> /dev/null";
FILE *fstream = popen(command.c_str(), "r");
if (fstream == NULL) {
return NULL;
}
std::stringstream path_stream;
while (!feof(fstream)) {
char c = fgetc(fstream);
/* xdg-user-dir ends the path with '\n'. */
if (c == '\n') {
break;
}
path_stream << c;
}
if (pclose(fstream) == -1) {
perror("GHOST_SystemPathsUnix::getUserSpecialDir failed at pclose()");
return NULL;
}
path = path_stream.str();
return path[0] ? (const GHOST_TUns8 *)path.c_str() : NULL;
}
const GHOST_TUns8 *GHOST_SystemPathsUnix::getBinaryDir() const
{
return NULL;

View File

@@ -53,6 +53,12 @@ class GHOST_SystemPathsUnix : public GHOST_SystemPaths {
*/
const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const;
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user dir (eg `~/Documents/`).
*/
const GHOST_TUns8 *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const;
/**
* Determine the directory of the current binary
* \return Unsigned char string pointing to the binary dir

View File

@@ -22,6 +22,7 @@
*/
#include "GHOST_SystemPathsWin32.h"
#include "GHOST_Debug.h"
#ifndef _WIN32_IE
# define _WIN32_IE 0x0501
@@ -76,6 +77,50 @@ const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir(int, const char *versionst
return NULL;
}
const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
{
GUID folderid;
switch (type) {
case GHOST_kUserSpecialDirDesktop:
folderid = FOLDERID_Desktop;
break;
case GHOST_kUserSpecialDirDocuments:
folderid = FOLDERID_Documents;
break;
case GHOST_kUserSpecialDirDownloads:
folderid = FOLDERID_Downloads;
break;
case GHOST_kUserSpecialDirMusic:
folderid = FOLDERID_Music;
break;
case GHOST_kUserSpecialDirPictures:
folderid = FOLDERID_Pictures;
break;
case GHOST_kUserSpecialDirVideos:
folderid = FOLDERID_Videos;
break;
default:
GHOST_ASSERT(
false,
"GHOST_SystemPathsWin32::getUserSpecialDir(): Invalid enum value for type parameter");
return NULL;
}
static char knownpath[MAX_PATH * 3] = {0};
PWSTR knownpath_16 = NULL;
HRESULT hResult = SHGetKnownFolderPath(folderid, KF_FLAG_DEFAULT, NULL, &knownpath_16);
if (hResult == S_OK) {
conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
CoTaskMemFree(knownpath_16);
return (GHOST_TUns8 *)knownpath;
}
CoTaskMemFree(knownpath_16);
return NULL;
}
const GHOST_TUns8 *GHOST_SystemPathsWin32::getBinaryDir() const
{
static char fullname[MAX_PATH * 3] = {0};

View File

@@ -62,6 +62,12 @@ class GHOST_SystemPathsWin32 : public GHOST_SystemPaths {
*/
const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const;
/**
* Determine a special ("well known") and easy to reach user directory.
* \return Unsigned char string pointing to user dir (eg `~/Documents/`).
*/
const GHOST_TUns8 *getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const;
/**
* Determine the directory of the current binary
* \return Unsigned char string pointing to the binary dir

View File

@@ -422,7 +422,7 @@ finished:
/**
* Dispose of a context.
* \param context Pointer to the context to be disposed.
* \param context: Pointer to the context to be disposed.
* \return Indication of success.
*/
GHOST_TSuccess GHOST_SystemWin32::disposeContext(GHOST_IContext *context)
@@ -569,13 +569,13 @@ GHOST_TSuccess GHOST_SystemWin32::getButtons(GHOST_Buttons &buttons) const
*/
bool swapped = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE;
bool down = HIBYTE(::GetKeyState(VK_LBUTTON)) != 0;
bool down = HIBYTE(::GetAsyncKeyState(VK_LBUTTON)) != 0;
buttons.set(swapped ? GHOST_kButtonMaskRight : GHOST_kButtonMaskLeft, down);
down = HIBYTE(::GetKeyState(VK_MBUTTON)) != 0;
down = HIBYTE(::GetAsyncKeyState(VK_MBUTTON)) != 0;
buttons.set(GHOST_kButtonMaskMiddle, down);
down = HIBYTE(::GetKeyState(VK_RBUTTON)) != 0;
down = HIBYTE(::GetAsyncKeyState(VK_RBUTTON)) != 0;
buttons.set(swapped ? GHOST_kButtonMaskLeft : GHOST_kButtonMaskRight, down);
return GHOST_kSuccess;
}
@@ -939,148 +939,103 @@ GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type,
{
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
if (type == GHOST_kEventButtonDown) {
window->updateMouseCapture(MousePressed);
}
else if (type == GHOST_kEventButtonUp) {
window->updateMouseCapture(MouseReleased);
}
GHOST_TabletData td = window->m_tabletInRange ? window->getLastTabletData() :
GHOST_TABLET_DATA_NONE;
/* Check for active Wintab mouse emulation in addition to a tablet in range because a proximity
* leave event might have fired before the Windows mouse up event, thus there are still tablet
* events to grab. The described behavior was observed in a Wacom Bamboo CTE-450. */
if (window->useTabletAPI(GHOST_kTabletWintab) &&
(window->m_tabletInRange || window->wintabSysButPressed()) &&
processWintabEvent(type, window, mask, window->getMousePressed())) {
/* Wintab processing only handles in-contact events. */
return NULL;
}
/* Ensure button click occurs at its intended position. */
processCursorEvent(window);
return new GHOST_EventButton(
system->getMilliSeconds(), type, window, mask, GHOST_TABLET_DATA_NONE);
window->updateMouseCapture(type == GHOST_kEventButtonDown ? MousePressed : MouseReleased);
return new GHOST_EventButton(system->getMilliSeconds(), type, window, mask, td);
}
GHOST_TSuccess GHOST_SystemWin32::processWintabEvent(GHOST_TEventType type,
GHOST_WindowWin32 *window,
GHOST_TButtonMask mask,
bool mousePressed)
void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window)
{
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
/* Only process Wintab packets if we can correlate them to a Window's mouse button event. When a
* button event associated to a mouse button by Wintab occurs outside of WM_*BUTTON events,
* there's no way to tell if other simultaneously pressed non-mouse mapped buttons are associated
* to a modifier key (shift, alt, ctrl) or a system event (scroll, etc.) and thus it is not
* possible to determine if a mouse click event should occur. */
if (!mousePressed && !window->wintabSysButPressed()) {
return GHOST_kFailure;
}
std::vector<GHOST_WintabInfoWin32> wintabInfo;
if (!window->getWintabInfo(wintabInfo)) {
return GHOST_kFailure;
return;
}
auto wtiIter = wintabInfo.begin();
/* We only process events that correlate to a mouse button events, so there may exist Wintab
* button down events that were instead mapped to e.g. scroll still in the queue. We need to
* skip those and find the last button down mapped to mouse buttons. */
if (!window->wintabSysButPressed()) {
/* Assume there may be no button down event currently in the queue. */
wtiIter = wintabInfo.end();
for (auto it = wintabInfo.begin(); it != wintabInfo.end(); it++) {
if (it->type == GHOST_kEventButtonDown) {
wtiIter = it;
}
}
}
bool unhandledButton = type != GHOST_kEventCursorMove;
for (; wtiIter != wintabInfo.end(); wtiIter++) {
auto info = *wtiIter;
for (auto info : wintabInfo) {
switch (info.type) {
case GHOST_kEventButtonDown: {
/* While changing windows with a tablet, Window's mouse button events normally occur before
* tablet proximity events, so a button up event can't be differentiated as occurring from
* a Wintab tablet or a normal mouse and a Ghost button event will always be generated.
*
* If we were called during a button down event create a ghost button down event, otherwise
* don't duplicate the prior button down as it interrupts drawing immediately after
* changing a window. */
case GHOST_kEventCursorMove: {
system->pushEvent(new GHOST_EventCursor(
info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData));
if (type == GHOST_kEventButtonDown && mask == info.button) {
break;
}
case GHOST_kEventButtonDown: {
system->pushEvent(new GHOST_EventCursor(
info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData));
UINT message;
switch (info.button) {
case GHOST_kButtonMaskLeft:
message = WM_LBUTTONDOWN;
break;
case GHOST_kButtonMaskRight:
message = WM_RBUTTONDOWN;
break;
case GHOST_kButtonMaskMiddle:
message = WM_MBUTTONDOWN;
break;
default:
continue;
}
MSG msg;
if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) &&
WM_QUIT != msg.message) {
window->updateMouseCapture(MousePressed);
system->pushEvent(
new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData));
unhandledButton = false;
}
window->updateWintabSysBut(MousePressed);
break;
}
case GHOST_kEventCursorMove:
system->pushEvent(new GHOST_EventCursor(
info.time, GHOST_kEventCursorMove, window, info.x, info.y, info.tabletData));
break;
case GHOST_kEventButtonUp:
system->pushEvent(
new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData));
if (type == GHOST_kEventButtonUp && mask == info.button) {
unhandledButton = false;
case GHOST_kEventButtonUp: {
UINT message;
switch (info.button) {
case GHOST_kButtonMaskLeft:
message = WM_LBUTTONUP;
break;
case GHOST_kButtonMaskRight:
message = WM_RBUTTONUP;
break;
case GHOST_kButtonMaskMiddle:
message = WM_MBUTTONUP;
break;
default:
continue;
}
MSG msg;
if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) &&
WM_QUIT != msg.message) {
window->updateMouseCapture(MouseReleased);
system->pushEvent(
new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData));
}
window->updateWintabSysBut(MouseReleased);
break;
}
default:
break;
}
}
/* No Wintab button found correlating to the system button event, handle it too.
*
* Wintab button up events may be handled during WM_MOUSEMOVE, before their corresponding
* WM_*BUTTONUP event has fired, which results in two GHOST Button up events for a single Wintab
* associated button event. Alternatively this Windows button up event may have been generated
* from a non-stylus device such as a button on the tablet pad and needs to be handled for some
* workflows.
*
* The ambiguity introduced by Windows and Wintab buttons being asynchronous and having no
* definitive way to associate each, and that the Wintab API does not provide enough information
* to differentiate whether the stylus down is or is not modified by another button to a
* non-mouse mapping, means that we must pessimistically generate mouse up events when we are
* unsure of an association to prevent the mouse locking into a down state. */
if (unhandledButton) {
if (!window->wintabSysButPressed()) {
GHOST_TInt32 x, y;
system->getCursorPosition(x, y);
system->pushEvent(new GHOST_EventCursor(system->getMilliSeconds(),
GHOST_kEventCursorMove,
window,
x,
y,
GHOST_TABLET_DATA_NONE));
}
system->pushEvent(new GHOST_EventButton(
system->getMilliSeconds(), type, window, mask, GHOST_TABLET_DATA_NONE));
}
return GHOST_kSuccess;
}
void GHOST_SystemWin32::processPointerEvent(
UINT type, GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam, bool &eventHandled)
{
std::vector<GHOST_PointerInfoWin32> pointerInfo;
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
/* Pointer events might fire when changing windows for a device which is set to use Wintab, even
* when when Wintab is left enabled but set to the bottom of Wintab overlap order. */
if (!window->useTabletAPI(GHOST_kTabletNative)) {
return;
}
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
std::vector<GHOST_PointerInfoWin32> pointerInfo;
if (window->getPointerInfo(pointerInfo, wParam, lParam) != GHOST_kSuccess) {
return;
}
@@ -1148,35 +1103,19 @@ void GHOST_SystemWin32::processPointerEvent(
GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *window)
{
GHOST_TInt32 x_screen, y_screen;
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
if (window->m_tabletInRange || window->wintabSysButPressed()) {
if (window->useTabletAPI(GHOST_kTabletWintab) &&
processWintabEvent(
GHOST_kEventCursorMove, window, GHOST_kButtonMaskNone, window->getMousePressed())) {
return NULL;
}
else if (window->useTabletAPI(GHOST_kTabletNative)) {
/* Tablet input handled in WM_POINTER* events. WM_MOUSEMOVE events in response to tablet
* input aren't normally generated when using WM_POINTER events, but manually moving the
* system cursor as we do in WM_POINTER handling does. */
return NULL;
}
/* If using Wintab but no button event is currently active,
* fall through to default handling. */
}
system->getCursorPosition(x_screen, y_screen);
DWORD msgPos = ::GetMessagePos();
GHOST_TInt32 x_screen = GET_X_LPARAM(msgPos);
GHOST_TInt32 y_screen = GET_Y_LPARAM(msgPos);
GHOST_TInt32 x_accum = 0, y_accum = 0;
if (window->getCursorGrabModeIsWarp() && !window->m_tabletInRange) {
GHOST_TInt32 x_new = x_screen;
GHOST_TInt32 y_new = y_screen;
GHOST_TInt32 x_accum, y_accum;
GHOST_Rect bounds;
/* fallback to window bounds */
/* Fallback to window bounds. */
if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) {
window->getClientBounds(bounds);
}
@@ -1187,29 +1126,19 @@ GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_WindowWin32 *wind
window->getCursorGrabAccum(x_accum, y_accum);
if (x_new != x_screen || y_new != y_screen) {
/* when wrapping we don't need to add an event because the
* setCursorPosition call will cause a new event after */
system->setCursorPosition(x_new, y_new); /* wrap */
window->setCursorGrabAccum(x_accum + (x_screen - x_new), y_accum + (y_screen - y_new));
}
else {
return new GHOST_EventCursor(system->getMilliSeconds(),
GHOST_kEventCursorMove,
window,
x_screen + x_accum,
y_screen + y_accum,
GHOST_TABLET_DATA_NONE);
}
}
else {
return new GHOST_EventCursor(system->getMilliSeconds(),
GHOST_kEventCursorMove,
window,
x_screen,
y_screen,
GHOST_TABLET_DATA_NONE);
}
return NULL;
GHOST_TabletData td = window->m_tabletInRange ? window->getLastTabletData() :
GHOST_TABLET_DATA_NONE;
return new GHOST_EventCursor(system->getMilliSeconds(),
GHOST_kEventCursorMove,
window,
x_screen + x_accum,
y_screen + y_accum,
td);
}
void GHOST_SystemWin32::processWheelEvent(GHOST_WindowWin32 *window, WPARAM wParam, LPARAM lParam)
@@ -1317,6 +1246,23 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
return event;
}
GHOST_Event *GHOST_SystemWin32::processWindowSizeEvent(GHOST_WindowWin32 *window)
{
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)getSystem();
GHOST_Event *sizeEvent = new GHOST_Event(
system->getMilliSeconds(), GHOST_kEventWindowSize, window);
/* We get WM_SIZE before we fully init. Do not dispatch before we are continuously resizing. */
if (window->m_inLiveResize) {
system->pushEvent(sizeEvent);
system->dispatchEvents();
return NULL;
}
else {
return sizeEvent;
}
}
GHOST_Event *GHOST_SystemWin32::processWindowEvent(GHOST_TEventType type,
GHOST_WindowWin32 *window)
{
@@ -1356,12 +1302,10 @@ void GHOST_SystemWin32::setTabletAPI(GHOST_TTabletAPI api)
GHOST_System::setTabletAPI(api);
GHOST_WindowManager *wm = getWindowManager();
GHOST_WindowWin32 *activeWindow = (GHOST_WindowWin32 *)wm->getActiveWindow();
for (GHOST_IWindow *win : wm->getWindows()) {
GHOST_WindowWin32 *windowsWindow = (GHOST_WindowWin32 *)win;
windowsWindow->updateWintab(windowsWindow == activeWindow,
!::IsIconic(windowsWindow->getHWND()));
GHOST_WindowWin32 *windowWin32 = (GHOST_WindowWin32 *)win;
windowWin32->setWintabEnabled(windowWin32->useTabletAPI(GHOST_kTabletWintab));
}
}
@@ -1606,15 +1550,28 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
////////////////////////////////////////////////////////////////////////
case WT_INFOCHANGE: {
window->processWintabInfoChangeEvent(lParam);
eventHandled = true;
break;
}
case WT_CSRCHANGE:
window->updateWintabCursorInfo();
eventHandled = true;
break;
case WT_PROXIMITY: {
bool inRange = LOWORD(lParam);
window->processWintabProximityEvent(inRange);
if (window->useTabletAPI(GHOST_kTabletWintab)) {
if (LOWORD(lParam)) {
window->m_tabletInRange = true;
}
else {
window->processWintabLeave();
}
}
eventHandled = true;
break;
}
case WT_PACKET:
window->updatePendingWintabEvents();
processWintabEvent(window);
eventHandled = true;
break;
////////////////////////////////////////////////////////////////////////
// Pointer events, processed
@@ -1664,7 +1621,18 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
}
break;
case WM_MOUSEMOVE:
event = processCursorEvent(window);
if (!window->m_mousePresent) {
TRACKMOUSEEVENT tme = {sizeof(tme)};
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
TrackMouseEvent(&tme);
window->m_mousePresent = true;
window->setWintabOverlap(true);
}
if (!window->m_tabletInRange) {
event = processCursorEvent(window);
}
break;
case WM_MOUSEWHEEL: {
/* The WM_MOUSEWHEEL message is sent to the focus window
@@ -1706,7 +1674,10 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
window->loadCursor(true, GHOST_kStandardCursorDefault);
}
break;
case WM_MOUSELEAVE:
window->m_mousePresent = false;
window->setWintabOverlap(false);
break;
////////////////////////////////////////////////////////////////////////
// Mouse events, ignored
////////////////////////////////////////////////////////////////////////
@@ -1722,7 +1693,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
* is sent to the window that has captured the mouse.
*/
break;
////////////////////////////////////////////////////////////////////////
// Window events, processed
////////////////////////////////////////////////////////////////////////
@@ -1755,8 +1725,6 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
if (LOWORD(wParam) == WA_INACTIVE)
window->lostMouseCapture();
window->updateWintab(LOWORD(wParam) != WA_INACTIVE, !::IsIconic(window->getHWND()));
lResult = ::DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
@@ -1798,6 +1766,8 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
/* Let DefWindowProc handle it. */
break;
case WM_SIZING:
event = processWindowSizeEvent(window);
break;
case WM_SIZE:
/* The WM_SIZE message is sent to a window after its size has changed.
* The WM_SIZE and WM_MOVE messages are not sent if an application handles the
@@ -1805,21 +1775,13 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
* to perform any move or size change processing during the WM_WINDOWPOSCHANGED
* message without calling DefWindowProc.
*/
/* we get first WM_SIZE before we fully init.
* So, do not dispatch before we continuously resizing. */
if (window->m_inLiveResize) {
system->pushEvent(processWindowEvent(GHOST_kEventWindowSize, window));
system->dispatchEvents();
}
else {
event = processWindowEvent(GHOST_kEventWindowSize, window);
}
event = processWindowSizeEvent(window);
/* Window might be minimized while inactive. When a window is inactive but not minimized,
* Wintab is left enabled (to catch the case where a pen is used to activate a window).
* When an inactive window is minimized, we need to disable Wintab. */
if (msg == WM_SIZE && wParam == SIZE_MINIMIZED) {
window->updateWintab(false, false);
if (wParam == SIZE_MINIMIZED) {
window->setWintabEnabled(false);
}
else if (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED) {
window->setWintabEnabled(true);
}
break;

View File

@@ -322,16 +322,9 @@ class GHOST_SystemWin32 : public GHOST_System {
/**
* Creates tablet events from Wintab events.
* \param type: The type of pointer event.
* \param window: The window receiving the event (the active window).
* \param mask: The button mask of the calling event.
* \param mousePressed: Whether the mouse is currently pressed.
* \return True if the method handled the event.
*/
static GHOST_TSuccess processWintabEvent(GHOST_TEventType type,
GHOST_WindowWin32 *window,
GHOST_TButtonMask mask,
bool mousePressed);
static void processWintabEvent(GHOST_WindowWin32 *window);
/**
* Creates tablet events from pointer events.
@@ -376,6 +369,13 @@ class GHOST_SystemWin32 : public GHOST_System {
*/
GHOST_TKey processSpecialKey(short vKey, short scanCode) const;
/**
* Creates a window size event.
* \param window: The window receiving the event (the active window).
* \return The event created.
*/
static GHOST_Event *processWindowSizeEvent(GHOST_WindowWin32 *window);
/**
* Creates a window event.
* \param type: The type of event to create.

View File

@@ -905,8 +905,8 @@ GHOST_TSuccess GHOST_WindowCocoa::setProgressBar(float progress)
static void postNotification()
{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = @"Blender progress notification";
notification.informativeText = @"Calculation is finished";
notification.title = @"Blender Progress Notification";
notification.informativeText = @"Calculation is finished.";
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[notification release];

View File

@@ -407,7 +407,7 @@ void GHOST_WindowWayland::setOpaque() const
#endif
/**
* \param type The type of rendering context create.
* \param type: The type of rendering context create.
* \return Indication of success.
*/
GHOST_Context *GHOST_WindowWayland::newDrawingContext(GHOST_TDrawingContextType type)

View File

@@ -72,6 +72,7 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
bool is_debug,
bool dialog)
: GHOST_Window(width, height, state, wantStereoVisual, false),
m_mousePresent(false),
m_tabletInRange(false),
m_inLiveResize(false),
m_system(system),
@@ -309,8 +310,7 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
(m_wintab.enable = (GHOST_WIN32_WTEnable)::GetProcAddress(m_wintab.handle, "WTEnable")) &&
(m_wintab.overlap = (GHOST_WIN32_WTOverlap)::GetProcAddress(m_wintab.handle, "WTOverlap"))) {
initializeWintab();
// Determine which tablet API to use and enable it.
updateWintab(m_system->m_windowFocus, m_system->m_windowFocus);
setWintabEnabled(true);
}
CoCreateInstance(
@@ -326,13 +326,12 @@ GHOST_WindowWin32::~GHOST_WindowWin32()
}
if (m_wintab.handle) {
updateWintab(false, false);
setWintabEnabled(false);
if (m_wintab.close && m_wintab.context) {
m_wintab.close(m_wintab.context);
}
FreeLibrary(m_wintab.handle);
memset(&m_wintab, 0, sizeof(m_wintab));
}
if (m_user32) {
@@ -771,32 +770,6 @@ void GHOST_WindowWin32::updateMouseCapture(GHOST_MouseCaptureEventWin32 event)
}
}
bool GHOST_WindowWin32::getMousePressed() const
{
return m_nPressedButtons;
}
bool GHOST_WindowWin32::wintabSysButPressed() const
{
return m_wintab.numSysButtons;
}
void GHOST_WindowWin32::updateWintabSysBut(GHOST_MouseCaptureEventWin32 event)
{
switch (event) {
case MousePressed:
m_wintab.numSysButtons++;
break;
case MouseReleased:
if (m_wintab.numSysButtons)
m_wintab.numSysButtons--;
break;
case OperatorGrab:
case OperatorUngrab:
break;
}
}
HCURSOR GHOST_WindowWin32::getStandardCursor(GHOST_TStandardCursor shape) const
{
// Convert GHOST cursor to Windows OEM cursor
@@ -1000,28 +973,6 @@ GHOST_TSuccess GHOST_WindowWin32::hasCursorShape(GHOST_TStandardCursor cursorSha
return (getStandardCursor(cursorShape)) ? GHOST_kSuccess : GHOST_kFailure;
}
void GHOST_WindowWin32::updateWintab(bool active, bool visible)
{
if (m_wintab.enable && m_wintab.overlap && m_wintab.context) {
bool enable = useTabletAPI(GHOST_kTabletWintab) && visible;
bool overlap = enable && active;
/* Disabling context while the Window is not minimized can cause issues on receiving Wintab
* input while changing a window for some drivers, so only disable if either Wintab had been
* disabled or the window is minimized. */
m_wintab.enable(m_wintab.context, enable);
m_wintab.overlap(m_wintab.context, overlap);
if (!overlap) {
/* WT_PROXIMITY event doesn't occur unless tablet's cursor leaves the proximity while the
* window is active. */
m_tabletInRange = false;
m_wintab.numSysButtons = 0;
m_wintab.sysButtonsPressed = 0;
}
}
}
void GHOST_WindowWin32::initializeWintab()
{
/* Return if wintab library handle doesn't exist or wintab is already initialized. */
@@ -1034,8 +985,6 @@ void GHOST_WindowWin32::initializeWintab()
if (m_wintab.open && m_wintab.info && m_wintab.queueSizeGet && m_wintab.queueSizeSet &&
m_wintab.info(WTI_DEFSYSCTX, 0, &lc)) {
/* The pressure and orientation (tilt) */
AXIS Pressure, Orientation[3];
lc.lcPktData = PACKETDATA;
lc.lcPktMode = PACKETMODE;
lc.lcMoveMask = PACKETDATA;
@@ -1046,19 +995,7 @@ void GHOST_WindowWin32::initializeWintab()
m_wintab.info(WTI_INTERFACE, IFC_NDEVICES, &m_wintab.numDevices);
BOOL pressureSupport = m_wintab.info(WTI_DEVICES, DVC_NPRESSURE, &Pressure);
m_wintab.maxPressure = pressureSupport ? Pressure.axMax : 0;
BOOL tiltSupport = m_wintab.info(WTI_DEVICES, DVC_ORIENTATION, &Orientation);
/* Does the tablet support azimuth ([0]) and altitude ([1])? */
if (tiltSupport && Orientation[0].axResolution && Orientation[1].axResolution) {
/* All this assumes the minimum is 0. */
m_wintab.maxAzimuth = Orientation[0].axMax;
m_wintab.maxAltitude = Orientation[1].axMax;
}
else { /* No so dont do tilt stuff. */
m_wintab.maxAzimuth = m_wintab.maxAltitude = 0;
}
updateWintabCursorInfo();
/* The Wintab spec says we must open the context disabled if we are using cursor masks. */
m_wintab.context = m_wintab.open(m_hWnd, &lc, FALSE);
@@ -1171,9 +1108,68 @@ GHOST_TSuccess GHOST_WindowWin32::getPointerInfo(
}
}
if (!outPointerInfo.empty()) {
lastTabletData = outPointerInfo.back().tabletData;
}
return GHOST_kSuccess;
}
void GHOST_WindowWin32::setWintabEnabled(bool enable)
{
if (m_wintab.enable && m_wintab.get && m_wintab.context) {
LOGCONTEXT context = {0};
if (m_wintab.get(m_wintab.context, &context)) {
if (enable && context.lcStatus & CXS_DISABLED && useTabletAPI(GHOST_kTabletWintab)) {
m_wintab.enable(m_wintab.context, true);
POINT cursorPos;
::GetCursorPos(&cursorPos);
GHOST_Rect bounds;
getClientBounds(bounds);
if (bounds.isInside(cursorPos.x, cursorPos.y)) {
setWintabOverlap(true);
}
}
else if (!enable && !(context.lcStatus & CXS_DISABLED)) {
setWintabOverlap(false);
m_wintab.enable(m_wintab.context, false);
}
}
}
}
void GHOST_WindowWin32::setWintabOverlap(bool overlap)
{
if (m_wintab.overlap && m_wintab.get && m_wintab.packetsGet && m_wintab.context) {
LOGCONTEXT context = {0};
if (m_wintab.get(m_wintab.context, &context)) {
if (overlap && context.lcStatus & CXS_OBSCURED && useTabletAPI(GHOST_kTabletWintab)) {
m_wintab.overlap(m_wintab.context, true);
}
else if (!overlap && context.lcStatus & CXS_ONTOP) {
m_wintab.overlap(m_wintab.context, false);
/* If context is disabled, Windows Ink may be active and managing m_tabletInRange. Don't
* modify it. */
if (!(context.lcStatus & CXS_DISABLED)) {
processWintabLeave();
}
}
}
}
}
void GHOST_WindowWin32::processWintabLeave()
{
m_tabletInRange = false;
m_wintab.buttons = 0;
/* Clear the packet queue. */
m_wintab.packetsGet(m_wintab.context, m_wintab.pkts.size(), m_wintab.pkts.data());
}
void GHOST_WindowWin32::processWintabDisplayChangeEvent()
{
LOGCONTEXT lc_sys = {0}, lc_curr = {0};
@@ -1207,48 +1203,38 @@ bool GHOST_WindowWin32::useTabletAPI(GHOST_TTabletAPI api) const
}
}
void GHOST_WindowWin32::processWintabProximityEvent(bool inRange)
void GHOST_WindowWin32::updateWintabCursorInfo()
{
if (!useTabletAPI(GHOST_kTabletWintab)) {
return;
}
// Let's see if we can initialize tablet here
if (m_wintab.info && m_wintab.context) {
AXIS Pressure, Orientation[3]; /* The maximum tablet size */
AXIS Pressure, Orientation[3];
BOOL pressureSupport = m_wintab.info(WTI_DEVICES, DVC_NPRESSURE, &Pressure);
m_wintab.maxPressure = pressureSupport ? Pressure.axMax : 0;
BOOL tiltSupport = m_wintab.info(WTI_DEVICES, DVC_ORIENTATION, &Orientation);
/* does the tablet support azimuth ([0]) and altitude ([1]) */
/* Does the tablet support azimuth ([0]) and altitude ([1]). */
if (tiltSupport && Orientation[0].axResolution && Orientation[1].axResolution) {
m_wintab.maxAzimuth = Orientation[0].axMax;
m_wintab.maxAltitude = Orientation[1].axMax;
}
else { /* no so dont do tilt stuff */
else {
m_wintab.maxAzimuth = m_wintab.maxAltitude = 0;
}
}
m_tabletInRange = inRange;
}
void GHOST_WindowWin32::processWintabInfoChangeEvent(LPARAM lParam)
{
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)GHOST_System::getSystem();
// Update number of connected Wintab digitizers
/* Update number of connected Wintab digitizers */
if (LOWORD(lParam) == WTI_INTERFACE && HIWORD(lParam) == IFC_NDEVICES) {
m_wintab.info(WTI_INTERFACE, IFC_NDEVICES, &m_wintab.numDevices);
updateWintab((GHOST_WindowWin32 *)system->getWindowManager()->getActiveWindow() == this,
!::IsIconic(m_hWnd));
if (useTabletAPI(GHOST_kTabletWintab)) {
setWintabEnabled(true);
}
}
}
GHOST_TSuccess GHOST_WindowWin32::wintabMouseToGhost(UINT cursor,
WORD physicalButton,
GHOST_TButtonMask &ghostButton)
GHOST_TButtonMask GHOST_WindowWin32::wintabMouseToGhost(UINT cursor, WORD physicalButton)
{
const WORD numButtons = 32;
BYTE logicalButtons[numButtons] = {0};
@@ -1258,183 +1244,135 @@ GHOST_TSuccess GHOST_WindowWin32::wintabMouseToGhost(UINT cursor,
m_wintab.info(WTI_CURSORS + cursor, CSR_SYSBTNMAP, &systemButtons);
if (physicalButton >= numButtons) {
return GHOST_kFailure;
return GHOST_kButtonMaskNone;
}
BYTE lb = logicalButtons[physicalButton];
if (lb >= numButtons) {
return GHOST_kFailure;
return GHOST_kButtonMaskNone;
}
switch (systemButtons[lb]) {
case SBN_LCLICK:
ghostButton = GHOST_kButtonMaskLeft;
return GHOST_kSuccess;
return GHOST_kButtonMaskLeft;
case SBN_RCLICK:
ghostButton = GHOST_kButtonMaskRight;
return GHOST_kSuccess;
return GHOST_kButtonMaskRight;
case SBN_MCLICK:
ghostButton = GHOST_kButtonMaskMiddle;
return GHOST_kSuccess;
return GHOST_kButtonMaskMiddle;
default:
return GHOST_kFailure;
return GHOST_kButtonMaskNone;
}
}
GHOST_TSuccess GHOST_WindowWin32::getWintabInfo(std::vector<GHOST_WintabInfoWin32> &outWintabInfo)
{
if (!useTabletAPI(GHOST_kTabletWintab)) {
return GHOST_kFailure;
}
if (!(m_wintab.packetsGet && m_wintab.context)) {
if (!(useTabletAPI(GHOST_kTabletWintab) && m_wintab.packetsGet && m_wintab.context)) {
return GHOST_kFailure;
}
GHOST_SystemWin32 *system = (GHOST_SystemWin32 *)GHOST_System::getSystem();
updatePendingWintabEvents();
const int numPackets = m_wintab.packetsGet(
m_wintab.context, m_wintab.pkts.size(), m_wintab.pkts.data());
outWintabInfo.resize(numPackets);
auto &pendingEvents = m_wintab.pendingEvents;
size_t pendingEventSize = pendingEvents.size();
outWintabInfo.resize(pendingEventSize);
for (int i = 0; i < numPackets; i++) {
PACKET pkt = m_wintab.pkts[i];
GHOST_WintabInfoWin32 &out = outWintabInfo[i];
for (int i = 0; i < pendingEventSize; i++) {
PACKET pkt = pendingEvents.front();
pendingEvents.pop();
GHOST_TabletData tabletData = GHOST_TABLET_DATA_NONE;
switch (pkt.pkCursor % 3) { /* % 3 for multiple devices ("DualTrack") */
out.tabletData = GHOST_TABLET_DATA_NONE;
/* % 3 for multiple devices ("DualTrack"). */
switch (pkt.pkCursor % 3) {
case 0:
tabletData.Active = GHOST_kTabletModeNone; /* puck - not yet supported */
/* Puck - processed as mouse. */
out.tabletData.Active = GHOST_kTabletModeNone;
break;
case 1:
tabletData.Active = GHOST_kTabletModeStylus; /* stylus */
out.tabletData.Active = GHOST_kTabletModeStylus;
break;
case 2:
tabletData.Active = GHOST_kTabletModeEraser; /* eraser */
out.tabletData.Active = GHOST_kTabletModeEraser;
break;
}
out.x = pkt.pkX;
out.y = pkt.pkY;
if (m_wintab.maxPressure > 0) {
tabletData.Pressure = (float)pkt.pkNormalPressure / (float)m_wintab.maxPressure;
out.tabletData.Pressure = (float)pkt.pkNormalPressure / (float)m_wintab.maxPressure;
}
if ((m_wintab.maxAzimuth > 0) && (m_wintab.maxAltitude > 0)) {
ORIENTATION ort = pkt.pkOrientation;
float vecLen;
float altRad, azmRad; /* in radians */
float altRad, azmRad; /* In radians. */
/*
* from the wintab spec:
* orAzimuth Specifies the clockwise rotation of the
* cursor about the z axis through a full circular range.
* From the wintab spec:
* orAzimuth: Specifies the clockwise rotation of the cursor about the z axis through a
* full circular range.
* orAltitude: Specifies the angle with the x-y plane through a signed, semicircular range.
* Positive values specify an angle upward toward the positive z axis; negative values
* specify an angle downward toward the negative z axis.
*
* orAltitude Specifies the angle with the x-y plane
* through a signed, semicircular range. Positive values
* specify an angle upward toward the positive z axis;
* negative values specify an angle downward toward the negative z axis.
*
* wintab.h defines .orAltitude as a UINT but documents .orAltitude
* as positive for upward angles and negative for downward angles.
* WACOM uses negative altitude values to show that the pen is inverted;
* therefore we cast .orAltitude as an (int) and then use the absolute value.
* wintab.h defines orAltitude as a UINT but documents orAltitude as positive for upward
* angles and negative for downward angles. WACOM uses negative altitude values to show that
* the pen is inverted; therefore we cast orAltitude as an (int) and then use the absolute
* value.
*/
/* convert raw fixed point data to radians */
/* Convert raw fixed point data to radians. */
altRad = (float)((fabs((float)ort.orAltitude) / (float)m_wintab.maxAltitude) * M_PI / 2.0);
azmRad = (float)(((float)ort.orAzimuth / (float)m_wintab.maxAzimuth) * M_PI * 2.0);
/* find length of the stylus' projected vector on the XY plane */
/* Find length of the stylus' projected vector on the XY plane. */
vecLen = cos(altRad);
/* from there calculate X and Y components based on azimuth */
tabletData.Xtilt = sin(azmRad) * vecLen;
tabletData.Ytilt = (float)(sin(M_PI / 2.0 - azmRad) * vecLen);
/* From there calculate X and Y components based on azimuth. */
out.tabletData.Xtilt = sin(azmRad) * vecLen;
out.tabletData.Ytilt = (float)(sin(M_PI / 2.0 - azmRad) * vecLen);
}
outWintabInfo[i].x = pkt.pkX;
outWintabInfo[i].y = pkt.pkY;
/* Some Wintab libraries don't handle relative button input, so we track button presses
* manually. */
out.button = GHOST_kButtonMaskNone;
out.type = GHOST_kEventCursorMove;
/* Some Wintab libraries don't handle relative button input correctly, so we track button
* presses manually. Examples include Wacom's Bamboo modifying button events in the queue when
* peeked, or missing events when entering the window when the context is not on top. */
DWORD buttonsChanged = m_wintab.sysButtonsPressed ^ pkt.pkButtons;
/* Find the index for the changed button from the button map. */
WORD physicalButton = 0;
for (DWORD diff = (unsigned)buttonsChanged >> 1; diff > 0; diff = (unsigned)diff >> 1) {
physicalButton++;
}
if (buttonsChanged &&
wintabMouseToGhost(pkt.pkCursor, physicalButton, outWintabInfo[i].button)) {
if (buttonsChanged & pkt.pkButtons) {
outWintabInfo[i].type = GHOST_kEventButtonDown;
DWORD buttonsChanged = m_wintab.buttons ^ pkt.pkButtons;
if (buttonsChanged) {
/* Find the index for the changed button from the button map. */
WORD physicalButton = 0;
for (DWORD diff = (unsigned)buttonsChanged >> 1; diff > 0; diff = (unsigned)diff >> 1) {
physicalButton++;
}
else {
outWintabInfo[i].type = GHOST_kEventButtonUp;
out.button = wintabMouseToGhost(pkt.pkCursor, physicalButton);
if (out.button != GHOST_kButtonMaskNone) {
if (buttonsChanged & pkt.pkButtons) {
out.type = GHOST_kEventButtonDown;
}
else {
out.type = GHOST_kEventButtonUp;
}
}
}
else {
outWintabInfo[i].type = GHOST_kEventCursorMove;
/* Only update handled button, in case multiple button events arrived simultaneously. */
m_wintab.buttons ^= 1 << physicalButton;
}
m_wintab.sysButtonsPressed = pkt.pkButtons;
out.time = system->tickCountToMillis(pkt.pkTime);
}
outWintabInfo[i].time = system->millisSinceStart(pkt.pkTime);
outWintabInfo[i].tabletData = tabletData;
if (!outWintabInfo.empty()) {
lastTabletData = outWintabInfo.back().tabletData;
}
return GHOST_kSuccess;
}
/* Wintab (per documentation but may vary with implementation) does not update when its event
* buffer is full. This is an issue because we need some synchronization point between Wintab
* events and Win32 events, so we can't drain and process the queue immediately. We need to
* associate Wintab mouse events to Win32 mouse events because Wintab buttons are modal (a button
* associated to left click is not always a left click) and there's no way to reconstruct their
* mode from the Wintab API alone. There is no guaranteed ordering between Wintab and Win32 mouse
* events and no documented time stamp shared between the two, so we synchronize on mouse button
* events. */
void GHOST_WindowWin32::updatePendingWintabEvents()
GHOST_TabletData GHOST_WindowWin32::getLastTabletData()
{
if (!(m_wintab.packetsGet && m_wintab.context)) {
return;
}
auto &pendingEvents = m_wintab.pendingEvents;
/* Clear outdated events from queue. */
DWORD currTime = ::GetTickCount();
DWORD millisTimeout = 500;
while (!pendingEvents.empty()) {
DWORD pkTime = pendingEvents.front().pkTime;
if (currTime > pkTime + millisTimeout) {
pendingEvents.pop();
}
else {
break;
}
}
/* Get new packets. */
const int numPackets = m_wintab.packetsGet(
m_wintab.context, m_wintab.pkts.size(), m_wintab.pkts.data());
int i = 0;
/* Don't queue outdated packets, such events can include packets that occurred before the current
* window lost and regained focus. */
for (; i < numPackets; i++) {
DWORD pkTime = m_wintab.pkts[i].pkTime;
if (currTime < pkTime + millisTimeout) {
break;
}
}
for (; i < numPackets; i++) {
pendingEvents.push(m_wintab.pkts[i]);
}
return lastTabletData;
}
GHOST_TUns16 GHOST_WindowWin32::getDPIHint()

View File

@@ -437,13 +437,6 @@ class GHOST_WindowWin32 : public GHOST_Window {
HCURSOR getStandardCursor(GHOST_TStandardCursor shape) const;
void loadCursor(bool visible, GHOST_TStandardCursor cursorShape) const;
/**
* Handle setup and switch between Wintab and Pointer APIs.
* \param active: Whether the window is or will be in an active state.
* \param visible: Whether the window is currently (or will be) visible).
*/
void updateWintab(bool active, bool visible);
/**
* Query whether given tablet API should be used.
* \param api: Tablet API to test.
@@ -461,16 +454,32 @@ class GHOST_WindowWin32 : public GHOST_Window {
WPARAM wParam,
LPARAM lParam);
/**
* Enables or disables Wintab context.
* \param enable: Whether the context should be enabled.
*/
void setWintabEnabled(bool enable);
/**
* Changes Wintab context overlap.
* \param overlap: Whether context should be brought to top of overlap order.
*/
void setWintabOverlap(bool overlap);
/**
* Resets Wintab state.
*/
void processWintabLeave();
/**
* Handle Wintab coordinate changes when DisplayChange events occur.
*/
void processWintabDisplayChangeEvent();
/**
* Set tablet details when a cursor enters range.
* \param inRange: Whether the Wintab device is in tracking range.
* Updates cached Wintab properties for current cursor.
*/
void processWintabProximityEvent(bool inRange);
void updateWintabCursorInfo();
/**
* Handle Wintab info changes such as change in number of connected tablets.
@@ -486,9 +495,10 @@ class GHOST_WindowWin32 : public GHOST_Window {
GHOST_TSuccess getWintabInfo(std::vector<GHOST_WintabInfoWin32> &outWintabInfo);
/**
* Updates stored pending Wintab events.
* Get the most recent tablet data.
* \return Most recent tablet data.
*/
void updatePendingWintabEvents();
GHOST_TabletData getLastTabletData();
GHOST_TSuccess beginFullScreen() const
{
@@ -502,24 +512,8 @@ class GHOST_WindowWin32 : public GHOST_Window {
GHOST_TUns16 getDPIHint() override;
/**
* Get whether there are currently any mouse buttons pressed.
* \return True if there are any currently pressed mouse buttons.
*/
bool getMousePressed() const;
/**
* Get if there are currently pressed Wintab buttons associated to a Windows mouse button press.
* \return True if there are currently any pressed Wintab buttons associated to a Windows
* mouse button press.
*/
bool wintabSysButPressed() const;
/**
* Register a Wintab button has been associated to a Windows mouse button press.
* \param event: Whether the button was pressed or released.
*/
void updateWintabSysBut(GHOST_MouseCaptureEventWin32 event);
/** Whether the mouse is either over or captured by the window. */
bool m_mousePresent;
/** Whether a tablet stylus is being tracked. */
bool m_tabletInRange;
@@ -577,28 +571,28 @@ class GHOST_WindowWin32 : public GHOST_Window {
int hotY,
bool canInvertColor);
/** Pointer to system */
/** Pointer to system. */
GHOST_SystemWin32 *m_system;
/** Pointer to COM IDropTarget implementor */
/** Pointer to COM IDropTarget implementor. */
GHOST_DropTargetWin32 *m_dropTarget;
/** Window handle. */
HWND m_hWnd;
/** Device context handle. */
HDC m_hDC;
/** Flag for if window has captured the mouse */
/** Flag for if window has captured the mouse. */
bool m_hasMouseCaptured;
/** Flag if an operator grabs the mouse with WM_cursor_grab_enable/ungrab()
* Multiple grabs must be released with a single ungrab */
/** Flag if an operator grabs the mouse with WM_cursor_grab_enable/ungrab().
* Multiple grabs must be released with a single ungrab. */
bool m_hasGrabMouse;
/** Count of number of pressed buttons */
/** Count of number of pressed buttons. */
int m_nPressedButtons;
/** HCURSOR structure of the custom cursor */
/** HCURSOR structure of the custom cursor. */
HCURSOR m_customCursor;
/** request GL context aith alpha channel */
/** Request GL context aith alpha channel. */
bool m_wantAlphaBackground;
/** ITaskbarList3 structure for progress bar*/
/** ITaskbarList3 structure for progress bar. */
ITaskbarList3 *m_Bar;
static const wchar_t *s_windowClassName;
@@ -621,22 +615,21 @@ class GHOST_WindowWin32 : public GHOST_Window {
GHOST_WIN32_WTEnable enable = NULL;
GHOST_WIN32_WTOverlap overlap = NULL;
/** Stores the Tablet context if detected Tablet features using WinTab.dll */
/** Stores the Tablet context if detected Tablet features using WinTab.dll. */
HCTX context = NULL;
/** Number of connected Wintab digitizers */
/** Number of connected Wintab digitizers. */
UINT numDevices = 0;
/** Number of cursors currently in contact mapped to system buttons */
GHOST_TUns8 numSysButtons = 0;
/** Cursors currently in contact mapped to system buttons */
DWORD sysButtonsPressed = 0;
/** Pressed button map. */
GHOST_TUns8 buttons = 0;
LONG maxPressure = 0;
LONG maxAzimuth = 0, maxAltitude = 0;
/** Reusable buffer to read in Wintab Packets. */
std::vector<PACKET> pkts;
/** Queue of packets to process. */
std::queue<PACKET> pendingEvents;
} m_wintab;
/** Most recent tablet data. */
GHOST_TabletData lastTabletData = GHOST_TABLET_DATA_NONE;
/**
* Wintab setup.
*/
@@ -646,12 +639,9 @@ class GHOST_WindowWin32 : public GHOST_Window {
* Convert Wintab system mapped (mouse) buttons into Ghost button mask.
* \param cursor: The Wintab cursor associated to the button.
* \param physicalButton: The physical button ID to inspect.
* \param buttonMask: Return pointer for button found.
* \return Whether an associated button was found.
* \return The system mapped button.
*/
GHOST_TSuccess wintabMouseToGhost(UINT cursor,
WORD physicalButton,
GHOST_TButtonMask &buttonMask);
GHOST_TButtonMask wintabMouseToGhost(UINT cursor, WORD physicalButton);
GHOST_TWindowState m_normal_state;

View File

@@ -118,27 +118,27 @@ void MEM_lockfree_freeN(void *vmemh);
void *MEM_lockfree_dupallocN(const void *vmemh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
void *MEM_lockfree_reallocN_id(void *vmemh,
size_t len,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(2);
void *MEM_lockfree_recallocN_id(void *vmemh,
size_t len,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(2);
void *MEM_lockfree_callocN(size_t len, const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void *MEM_lockfree_callocN(size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
void *MEM_lockfree_calloc_arrayN(size_t len,
size_t size,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
void *MEM_lockfree_mallocN(size_t len, const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void *MEM_lockfree_mallocN(size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
void *MEM_lockfree_malloc_arrayN(size_t len,
size_t size,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
void *MEM_lockfree_mallocN_aligned(size_t len,
size_t alignment,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
void MEM_lockfree_printmemlist_pydict(void);
void MEM_lockfree_printmemlist(void);
@@ -161,27 +161,27 @@ void MEM_guarded_freeN(void *vmemh);
void *MEM_guarded_dupallocN(const void *vmemh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
void *MEM_guarded_reallocN_id(void *vmemh,
size_t len,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(2);
void *MEM_guarded_recallocN_id(void *vmemh,
size_t len,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(2);
void *MEM_guarded_callocN(size_t len, const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void *MEM_guarded_callocN(size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
void *MEM_guarded_calloc_arrayN(size_t len,
size_t size,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
void *MEM_guarded_mallocN(size_t len, const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void *MEM_guarded_mallocN(size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
void *MEM_guarded_malloc_arrayN(size_t len,
size_t size,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
void *MEM_guarded_mallocN_aligned(size_t len,
size_t alignment,
const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
void MEM_guarded_printmemlist_pydict(void);
void MEM_guarded_printmemlist(void);

View File

@@ -72,6 +72,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd)
mUsingFractions = (fds->flags & FLUID_DOMAIN_USE_FRACTIONS) && mUsingLiquid;
mUsingMesh = (fds->flags & FLUID_DOMAIN_USE_MESH) && mUsingLiquid;
mUsingDiffusion = (fds->flags & FLUID_DOMAIN_USE_DIFFUSION) && mUsingLiquid;
mUsingViscosity = (fds->flags & FLUID_DOMAIN_USE_VISCOSITY) && mUsingLiquid;
mUsingMVel = (fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS) && mUsingLiquid;
mUsingGuiding = (fds->flags & FLUID_DOMAIN_USE_GUIDE);
mUsingDrops = (fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY) && mUsingLiquid;
@@ -221,6 +222,10 @@ MANTA::MANTA(int *res, FluidModifierData *fmd)
initSuccess &= initLiquidMesh();
}
if (mUsingViscosity) {
initSuccess &= initLiquidViscosity();
}
if (mUsingDiffusion) {
initSuccess &= initCurvature();
}
@@ -440,6 +445,17 @@ bool MANTA::initLiquidMesh(FluidModifierData *fmd)
return runPythonString(pythonCommands);
}
bool MANTA::initLiquidViscosity(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = fluid_variables_viscosity + fluid_solver_viscosity + liquid_alloc_viscosity;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
mUsingViscosity = true;
return runPythonString(pythonCommands);
}
bool MANTA::initCurvature(FluidModifierData *fmd)
{
std::vector<std::string> pythonCommands;
@@ -871,8 +887,10 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
mRNAMap["CACHE_DIR"] = cacheDirectory;
mRNAMap["COMPRESSION_OPENVDB"] = vdbCompressionMethod;
mRNAMap["PRECISION_OPENVDB"] = vdbPrecisionHalf;
mRNAMap["CLIP_OPENVDB"] = to_string(fds->clipping);
mRNAMap["CLIP_OPENVDB"] = to_string(fds->clipping);
mRNAMap["PP_PARTICLE_MAXIMUM"] = to_string(fds->sys_particle_maximum);
mRNAMap["USING_VISCOSITY"] = getBooleanString(fds->flags & FLUID_DOMAIN_USE_VISCOSITY);
mRNAMap["VISCOSITY_VALUE"] = to_string(fds->viscosity_value);
/* Fluid object names. */
mRNAMap["NAME_FLAGS"] = FLUID_NAME_FLAGS;
@@ -1376,15 +1394,14 @@ bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain)
if (with_debug)
cout << "MANTA::readGuiding()" << endl;
FluidDomainSettings *fds = fmd->domain;
if (!mUsingGuiding)
return false;
if (!fds)
if (!fmd)
return false;
ostringstream ss;
vector<string> pythonCommands;
FluidDomainSettings *fds = fmd->domain;
string directory = (sourceDomain) ? getDirectory(fmd, FLUID_DOMAIN_DIR_DATA) :
getDirectory(fmd, FLUID_DOMAIN_DIR_GUIDE);
@@ -1728,6 +1745,7 @@ bool MANTA::exportLiquidScript(FluidModifierData *fmd)
bool guiding = fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
bool invel = fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
bool outflow = fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
bool viscosity = fds->flags & FLUID_DOMAIN_USE_VISCOSITY;
string manta_script;
@@ -1742,6 +1760,8 @@ bool MANTA::exportLiquidScript(FluidModifierData *fmd)
manta_script += fluid_variables_particles + liquid_variables_particles;
if (guiding)
manta_script += fluid_variables_guiding;
if (viscosity)
manta_script += fluid_variables_viscosity;
/* Solvers. */
manta_script += header_solvers + fluid_solver;
@@ -1751,6 +1771,8 @@ bool MANTA::exportLiquidScript(FluidModifierData *fmd)
manta_script += fluid_solver_particles;
if (guiding)
manta_script += fluid_solver_guiding;
if (viscosity)
manta_script += fluid_solver_viscosity;
/* Grids. */
manta_script += header_grids + fluid_alloc + liquid_alloc;
@@ -1768,6 +1790,8 @@ bool MANTA::exportLiquidScript(FluidModifierData *fmd)
manta_script += fluid_alloc_invel;
if (outflow)
manta_script += fluid_alloc_outflow;
if (viscosity)
manta_script += liquid_alloc_viscosity;
/* Domain init. */
manta_script += header_gridinit + liquid_init_phi;

Some files were not shown because too many files have changed in this diff Show More