[Bf-blender-cvs] [f448ff2afe7] master: VSE: Hide cache settings and adjust defaults

2021-01-07 Thread Richard Antalik
Commit: f448ff2afe7a77279fe96282447912a6f7773ed3
Author: Richard Antalik
Date:   Fri Jan 8 07:24:55 2021 +0100
Branches: master
https://developer.blender.org/rBf448ff2afe7a77279fe96282447912a6f7773ed3

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

===

M   release/scripts/startup/bl_ui/space_sequencer.py
M   source/blender/blenkernel/BKE_blender_version.h
M   source/blender/blenloader/intern/versioning_290.c
M   source/blender/sequencer/intern/sequencer.c

===

diff --git a/release/scripts/startup/bl_ui/space_sequencer.py 
b/release/scripts/startup/bl_ui/space_sequencer.py
index 29f0bd1d6fb..b5c1ea8aa96 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -412,7 +412,19 @@ class SEQUENCER_MT_view(Menu):
 layout.separator()
 layout.prop(st, "show_seconds")
 layout.prop(st, "show_markers")
-layout.menu("SEQUENCER_MT_view_cache", text="Show Cache")
+if context.preferences.view.show_developer_ui:
+layout.menu("SEQUENCER_MT_view_cache", text="Show Cache")
+
+if is_preview:
+layout.separator()
+if st.display_mode == 'IMAGE':
+layout.prop(st, "use_zoom_to_fit")
+layout.prop(ed, "show_overlay", text="Show Frame Overlay")
+layout.prop(st, "show_safe_areas", text="Show Safe Areas")
+layout.prop(st, "show_metadata", text="Show Metadata")
+layout.prop(st, "show_annotation", text="Show Annotations")
+elif st.display_mode == 'WAVEFORM':
+layout.prop(st, "show_separate_color", text="Show Separate 
Color Channels")
 
 layout.separator()
 
@@ -1877,11 +1889,12 @@ class SEQUENCER_PT_adjust_color(SequencerButtonsPanel, 
Panel):
 
 class SEQUENCER_PT_cache_settings(SequencerButtonsPanel, Panel):
 bl_label = "Cache Settings"
-bl_category = "Proxy & Cache"
+bl_category = "Cache"
 
 @classmethod
 def poll(cls, context):
-return cls.has_sequencer(context) and context.scene.sequence_editor
+show_developer_ui = context.preferences.view.show_developer_ui
+return cls.has_sequencer(context) and  context.scene.sequence_editor 
and show_developer_ui
 
 def draw(self, context):
 layout = self.layout
@@ -1900,7 +1913,7 @@ class SEQUENCER_PT_cache_settings(SequencerButtonsPanel, 
Panel):
 
 class SEQUENCER_PT_proxy_settings(SequencerButtonsPanel, Panel):
 bl_label = "Proxy Settings"
-bl_category = "Proxy & Cache"
+bl_category = "Proxy"
 
 @classmethod
 def poll(cls, context):
@@ -1925,7 +1938,7 @@ class SEQUENCER_PT_proxy_settings(SequencerButtonsPanel, 
Panel):
 
 class SEQUENCER_PT_strip_proxy(SequencerButtonsPanel, Panel):
 bl_label = "Strip Proxy & Timecode"
-bl_category = "Proxy & Cache"
+bl_category = "Proxy"
 
 @classmethod
 def poll(cls, context):
@@ -1987,14 +2000,15 @@ class SEQUENCER_PT_strip_proxy(SequencerButtonsPanel, 
Panel):
 
 class SEQUENCER_PT_strip_cache(SequencerButtonsPanel, Panel):
 bl_label = "Strip Cache"
-bl_category = "Proxy & Cache"
+bl_category = "Cache"
 bl_options = {'DEFAULT_CLOSED'}
 
 @classmethod
 def poll(cls, context):
+show_developer_ui = context.preferences.view.show_developer_ui
 if not cls.has_sequencer(context):
 return False
-if act_strip(context) is not None:
+if act_strip(context) is not None and show_developer_ui:
 return True
 return False
 
diff --git a/source/blender/blenkernel/BKE_blender_version.h 
b/source/blender/blenkernel/BKE_blender_version.h
index 06a11fc8d1d..6e596c94cee 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 9
+#define BLENDER_FILE_SUBVERSION 10
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the 
file
diff --git a/source/blender/blenloader/intern/versioning_290.c 
b/source/blender/blenloader/intern/versioning_290.c
index de59075559d..e5e04afc927 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -698,6 +698,16 @@ static void do_versions_291_fcurve_handles_limit(FCurve 
*fcu)
   }
 }
 
+static void do_versions_strip_ca

[Bf-blender-cvs] [09ea339a6c2] master: Cleanup: Use LISTBASE_FOREACH macro

2021-01-07 Thread Hans Goudey
Commit: 09ea339a6c247a2de3ca97cdfdc8c7f7b85e7665
Author: Hans Goudey
Date:   Thu Jan 7 21:24:46 2021 -0600
Branches: master
https://developer.blender.org/rB09ea339a6c247a2de3ca97cdfdc8c7f7b85e7665

Cleanup: Use LISTBASE_FOREACH macro

===

M   source/blender/editors/object/object_edit.c

===

diff --git a/source/blender/editors/object/object_edit.c 
b/source/blender/editors/object/object_edit.c
index 3eb77df96b3..c6a70f9b866 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -504,7 +504,7 @@ static bool mesh_needs_keyindex(Main *bmain, const Mesh *me)
 return false; /* will be added */
   }
 
-  for (const Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
+  LISTBASE_FOREACH (const Object *, ob, &bmain->objects) {
 if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, 
PARVERT1, PARVERT3)) {
   return true;
 }
@@ -650,12 +650,10 @@ bool ED_object_editmode_exit_ex(Main *bmain, Scene 
*scene, Object *obedit, int f
 
   /* freedata only 0 now on file saves and render */
   if (freedata) {
-ListBase pidlist;
-PTCacheID *pid;
-
 /* flag object caches as outdated */
+ListBase pidlist;
 BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0);
-for (pid = pidlist.first; pid; pid = pid->next) {
+LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) {
   /* particles don't need reset on geometry change */
   if (pid->type != PTCACHE_TYPE_PARTICLES) {
 pid->cache->flag |= PTCACHE_OUTDATED;
@@ -1398,7 +1396,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
 CTX_data_selected_editable_objects(C, &ctx_objects);
   }
 
-  for (CollectionPointerLink *ctx_ob = ctx_objects.first; ctx_ob; ctx_ob = 
ctx_ob->next) {
+  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
 Object *ob = ctx_ob->ptr.data;
 ID *data = ob->data;
 if (data != NULL) {
@@ -1406,7 +1404,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
 }
   }
 
-  for (CollectionPointerLink *ctx_ob = ctx_objects.first; ctx_ob; ctx_ob = 
ctx_ob->next) {
+  LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) {
 /* Always un-tag all object data-blocks irrespective of our ability to 
operate on them. */
 Object *ob = ctx_ob->ptr.data;
 ID *data = ob->data;
@@ -1817,11 +1815,9 @@ struct MoveToCollectionData {
 static int move_to_collection_menus_create(wmOperator *op, 
MoveToCollectionData *menu)
 {
   int index = menu->index;
-  for (CollectionChild *child = menu->collection->children.first; child != 
NULL;
-   child = child->next) {
+  LISTBASE_FOREACH (CollectionChild *, child, &menu->collection->children) {
 Collection *collection = child->collection;
-MoveToCollectionData *submenu = MEM_callocN(sizeof(MoveToCollectionData),
-"MoveToCollectionData submenu 
- expected memleak");
+MoveToCollectionData *submenu = MEM_callocN(sizeof(MoveToCollectionData), 
__func__);
 BLI_addtail(&menu->submenus, submenu);
 submenu->collection = collection;
 submenu->index = ++index;
@@ -1833,8 +1829,7 @@ static int move_to_collection_menus_create(wmOperator 
*op, MoveToCollectionData
 
 static void move_to_collection_menus_free_recursive(MoveToCollectionData *menu)
 {
-  for (MoveToCollectionData *submenu = menu->submenus.first; submenu != NULL;
-   submenu = submenu->next) {
+  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
 move_to_collection_menus_free_recursive(submenu);
   }
   BLI_freelistN(&menu->submenus);
@@ -1873,8 +1868,7 @@ static void move_to_collection_menu_create(bContext *C, 
uiLayout *layout, void *
UI_icon_color_from_collection(menu->collection);
   uiItemIntO(layout, name, icon, menu->ot->idname, "collection_index", 
menu->index);
 
-  for (MoveToCollectionData *submenu = menu->submenus.first; submenu != NULL;
-   submenu = submenu->next) {
+  LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
 move_to_collection_menus_items(layout, submenu);
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [15bb8f9f936] master: Fix file-handle leak when parsing xdg user directories

2021-01-07 Thread Campbell Barton
Commit: 15bb8f9f936ee5ff50d6c6951d03bc1cd051f466
Author: Campbell Barton
Date:   Fri Jan 8 13:19:11 2021 +1100
Branches: master
https://developer.blender.org/rB15bb8f9f936ee5ff50d6c6951d03bc1cd051f466

Fix file-handle leak when parsing xdg user directories

===

M   source/blender/editors/space_file/fsmenu.c

===

diff --git a/source/blender/editors/space_file/fsmenu.c 
b/source/blender/editors/space_file/fsmenu.c
index d8556711c55..2d1151c8f4d 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -171,6 +171,8 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
   }
 }
   }
+  fclose(fp);
+
   return xdg_map;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [61f1faac3f2] master: Fix T83868: Disabled or inactive list items are not grayed out

2021-01-07 Thread Hans Goudey
Commit: 61f1faac3f2154de27cedbb100b938e447e5046f
Author: Hans Goudey
Date:   Thu Jan 7 16:28:26 2021 -0600
Branches: master
https://developer.blender.org/rB61f1faac3f2154de27cedbb100b938e447e5046f

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.

===

M   source/blender/editors/interface/interface_widgets.c

===

diff --git a/source/blender/editors/interface/interface_widgets.c 
b/source/blender/editors/interface/interface_widgets.c
index 7cd8cc7a13b..a99f05730bb 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2558,7 +2558,7 @@ static void widget_state(uiWidgetType *wt, int state, int 
drawflag, eUIEmbossTyp
 wt->wcol_theme = &btheme->tui.wcol_list_item;
 
 if (state & (UI_BUT_DISABLED | UI_BUT_INACTIVE | 
UI_SEARCH_FILTER_NO_MATCH)) {
-  ui_widget_color_disabled(wt, state & UI_SEARCH_FILTER_NO_MATCH);
+  ui_widget_color_disabled(wt, state);
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5530d6f86fb] master: PyAPI Docs: Terminal instructions for Windows incorrect

2021-01-07 Thread Aaron Carlisle
Commit: 5530d6f86fb802c2fa514f7ccc2219af419d2702
Author: Aaron Carlisle
Date:   Thu Jan 7 15:58:18 2021 -0500
Branches: master
https://developer.blender.org/rB5530d6f86fb802c2fa514f7ccc2219af419d2702

PyAPI Docs: Terminal instructions for Windows incorrect

Fixes T84498

===

M   doc/python_api/rst/info_tips_and_tricks.rst

===

diff --git a/doc/python_api/rst/info_tips_and_tricks.rst 
b/doc/python_api/rst/info_tips_and_tricks.rst
index 0b5e1910902..d16dcc077df 100644
--- a/doc/python_api/rst/info_tips_and_tricks.rst
+++ b/doc/python_api/rst/info_tips_and_tricks.rst
@@ -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

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [97d76ecba73] temp-angavrilov-constraints: Surface Deform: fix binding vertex artifacts causing spikes.

2021-01-07 Thread Alexander Gavrilov
Commit: 97d76ecba73551aa8acbf035346f02b877d61909
Author: Alexander Gavrilov
Date:   Thu Jan 7 20:40:29 2021 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB97d76ecba73551aa8acbf035346f02b877d61909

Surface Deform: fix binding vertex artifacts causing spikes.

There are two issues here. First, like in T81988 there are cases
where the modifier would deform some vertices immediately after
bind. This is caused by wrong assumptions in the code about the
possible relative angles between various vectors, which can cause
negative weights that don't blend correctly to appear.

Specifically, it seems originally the code assumes that the
centroid-point vector in the polygon plane lies somewhere
between the mid-edge vectors. This is however not necessarily
the case for distant vertices, because the polygon is not
guaranteed to be truly planar, so normal projection may be
a bit off. The code has to use signed angles and checks to
support all possible angular arrangements.

The second issue is very thin and long triangles, which tend
to be very spatially unstable in their thin dimension, resulting
in excess deformation. The code was weighting distance using
the distances between the centroid and the mid-edge points, which
in this case end up as nearly opposite vectors of sizable length
and don't correctly represent how thin the triangle actually is.
It is thus better to use centroid-to-line distances, and an
additional even stricter value for the midpoint that will use
only 3 vertices at evaluation time.

===

M   source/blender/modifiers/intern/MOD_surfacedeform.c

===

diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c 
b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 0fad78683eb..4c3047d8e2e 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -115,6 +115,7 @@ typedef struct SDefBindPoly {
   float weight_dist;
   float weight;
   float scales[2];
+  float scale_mid;
   /** Center of `coords` */
   float centroid[3];
   /** Center of `coords_v2` */
@@ -460,9 +461,13 @@ static void freeBindData(SDefBindWeightData *const bwdata)
   MEM_freeN(bwdata);
 }
 
-BLI_INLINE float computeAngularWeight(const float point_angle)
+BLI_INLINE float computeAngularWeight(const float point_angle, const float 
edgemid_angle)
 {
-  return sinf(point_angle * M_PI_2);
+  if (edgemid_angle <= FLT_EPSILON) {
+return point_angle > 0 ? 1 : 0;
+  }
+
+  return sinf(min_ff(point_angle / edgemid_angle, 1) * M_PI_2);
 }
 
 BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData *const data,
@@ -603,33 +608,40 @@ BLI_INLINE SDefBindWeightData 
*computeBindWeights(SDefBindCalcData *const data,
 
 avg_point_dist += bpoly->weight_dist;
 
-/* Compute centroid to mid-edge vectors */
-mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[0],
-bpoly->coords_v2[bpoly->edge_vert_inds[0]],
-bpoly->coords_v2[bpoly->corner_ind]);
+/* Common vertex coordinates. */
+const float *const vert0_v2 = 
bpoly->coords_v2[bpoly->edge_vert_inds[0]];
+const float *const vert1_v2 = 
bpoly->coords_v2[bpoly->edge_vert_inds[1]];
+const float *const corner_v2 = bpoly->coords_v2[bpoly->corner_ind];
 
-mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[1],
-bpoly->coords_v2[bpoly->edge_vert_inds[1]],
-bpoly->coords_v2[bpoly->corner_ind]);
+/* Compute centroid to mid-edge vectors */
+mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[0], vert0_v2, corner_v2);
+mid_v2_v2v2(bpoly->cent_edgemid_vecs_v2[1], vert1_v2, corner_v2);
 
 sub_v2_v2(bpoly->cent_edgemid_vecs_v2[0], bpoly->centroid_v2);
 sub_v2_v2(bpoly->cent_edgemid_vecs_v2[1], bpoly->centroid_v2);
 
-/* Compute poly scales with respect to mid-edges, and normalize the 
vectors */
-bpoly->scales[0] = normalize_v2(bpoly->cent_edgemid_vecs_v2[0]);
-bpoly->scales[1] = normalize_v2(bpoly->cent_edgemid_vecs_v2[1]);
+normalize_v2(bpoly->cent_edgemid_vecs_v2[0]);
+normalize_v2(bpoly->cent_edgemid_vecs_v2[1]);
 
-/* Compute the required polygon angles */
+/* Compute poly scales with respect to the two edges. */
+bpoly->scales[0] = dist_to_line_v2(bpoly->centroid_v2, vert0_v2, 
corner_v2);
+bpoly->scales[1] = dist_to_line_v2(bpoly->centroid_v2, vert1_v2, 
corner_v2);
+
+/* Compute the angle between the edge mid vectors. */
 bpoly->edgemid_angle = 
angle_normalized_v2v2(bpoly->cent_edgemid_vecs_v2[0],
  
bpoly->cent_edgemid_vecs_v2[1]);
 
-sub_v2_v2v2(tmp_vec_v2, bpoly->coords_v2[bpoly->corner_ind], 
bpoly->centroid_v2);
+/* Compute the angles between the corner and the 

[Bf-blender-cvs] [b2611ff3ccc] temp-angavrilov-constraints: Copy Transforms: implement Invert, Fix Shear and more Mix options.

2021-01-07 Thread Alexander Gavrilov
Commit: b2611ff3ccc49d59ecc333bc82c7e483cc624270
Author: Alexander Gavrilov
Date:   Wed Nov 4 19:29:27 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBb2611ff3ccc49d59ecc333bc82c7e483cc624270

Copy Transforms: implement Invert, Fix Shear and more Mix options.

This constraint can be naturally viewed as a prototype for a future
4x4 matrix math node (or subset thereof), since its basic semantics
already is matrix assignment. Thus it makes sense to add math options
to this constraint to increase flexibility in the meantime.

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

- An option to fix shear in the incoming target matrix.
- An option to invert the target matrix.
- More ways to combine target and owner matrix.

Shear is known to cause issues for various mathematical operations,
so an option to remove it at key points is useful. In the future node
system this would be a separate operation, but due to the limits of
the constraint stack it has to be built in for now.

Inverting a matrix is also an operation that can be useful to have.
For some uses it may be useful to invert components separately, so
implement this by checking the Mix mode setting to avoid UI options.

Finally, add two more ways to combine the matrices (multiplied by
two due to the necessity for the Before/After choice). Now there
are three combine modes:

Full implements regular matrix multiplication as the most basic option.

Split Channels combines location, rotation and scale separately.
Looking at D7547 there is demand for such a mode in some cases,
and even with nodes it's cumbersome to rig manually every time.

Finally, Aligned emulates the 'anti-shear' Aligned Inherit Scale mode,
and basically uses Full for location, and Split for rotation/scale.

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

===

M   release/scripts/startup/bl_ui/properties_constraint.py
M   source/blender/blenkernel/intern/constraint.c
M   source/blender/blenlib/BLI_math_matrix.h
M   source/blender/blenlib/intern/math_matrix.c
M   source/blender/editors/transform/transform_convert.c
M   source/blender/makesdna/DNA_constraint_types.h
M   source/blender/makesrna/intern/rna_constraint.c

===

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py 
b/release/scripts/startup/bl_ui/properties_constraint.py
index a7ac96508f4..3d358b2db5d 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -505,6 +505,8 @@ class ConstraintButtonsPanel(Panel):
 
 self.target_template(layout, con)
 
+layout.prop(con, "fix_target_shear")
+layout.prop(con, "invert")
 layout.prop(con, "mix_mode", text="Mix")
 
 self.space_template(layout, con)
diff --git a/source/blender/blenkernel/intern/constraint.c 
b/source/blender/blenkernel/intern/constraint.c
index 5bd8a2bc576..9da17282a4f 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -2232,17 +2232,62 @@ static void translike_evaluate(bConstraint *con, 
bConstraintOb *cob, ListBase *t
   bConstraintTarget *ct = targets->first;
 
   if (VALID_CONS_TARGET(ct)) {
+float target_mat[4][4];
+
+copy_m4_m4(target_mat, ct->matrix);
+
+/* Fix the shear of the target matrix if enabled.
+ * Use Y as the axis since it's the natural default for bones. */
+if (data->flag & TRANSLIKE_FIX_TARGET_SHEAR) {
+  orthogonalize_m4_stable(target_mat, 1, false);
+}
+
+/* Invert the transformation. */
+if (data->flag & TRANSLIKE_INVERT) {
+  /* For modes that split channels, split during invert too. */
+  if (ELEM(data->mix_mode,
+   TRANSLIKE_MIX_BEFORE,
+   TRANSLIKE_MIX_AFTER,
+   TRANSLIKE_MIX_BEFORE_SPLIT,
+   TRANSLIKE_MIX_AFTER_SPLIT)) {
+invert_m4_m4_split_channels(target_mat, target_mat);
+  }
+  else {
+invert_m4(target_mat);
+  }
+}
+
+/* Finally, combine the matrices. */
 switch (data->mix_mode) {
   case TRANSLIKE_MIX_REPLACE:
-copy_m4_m4(cob->matrix, ct->matrix);
+copy_m4_m4(cob->matrix, target_mat);
 break;
 
+  /* Simple matrix multiplication. */
+  case TRANSLIKE_MIX_BEFORE_FULL:
+mul_m4_m4m4(cob->matrix, target_mat, cob->matrix);
+break;
+
+  case TRANSLIKE_MIX_AFTER_FULL:
+mul_m4_m4m4(cob->matrix, cob->matrix, target_mat);
+break;
+
+  /* Aligned Inherit Scale emulation. */
   case TRANSLIKE_MIX_BEFORE:
-mul_m4_m4m4_aligned_scale(cob->matrix, ct->matrix, cob->matrix);
+mul_m4_m4m4_aligned_scale(cob->matrix, target_mat, cob->matrix);
 break;
 
   case TRANSLIKE_MIX_AFTER:
-mul_m4_m4m4_aligned_scale(co

[Bf-blender-cvs] [5bd1718093d] temp-angavrilov-constraints: Bone Overlay: support bone wireframe opacity settings.

2021-01-07 Thread Alexander Gavrilov
Commit: 5bd1718093db975578c3084c71b19b549d530df2
Author: Alexander Gavrilov
Date:   Sun Jan 3 23:40:44 2021 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB5bd1718093db975578c3084c71b19b549d530df2

Bone Overlay: support bone wireframe opacity settings.

When weight painting the bone overlay is extremely intrusive,
effectively requiring either extensive use of hiding individual
bones, or disabling the whole bone overlay between selections.

This addresses the issue by adding two bone opacity sliders that
are used for the 'wireframe' armature drawing mode. One directly
controls the opacity in a uniform way. The other one allows fade
based on the depth between the near and far clip planes in order
to provide an automatic visual cue about which bones are closest.

===

M   release/scripts/startup/bl_ui/space_view3d.py
M   source/blender/blenloader/intern/versioning_290.c
M   source/blender/draw/CMakeLists.txt
M   source/blender/draw/engines/overlay/overlay_armature.c
M   source/blender/draw/engines/overlay/overlay_private.h
M   source/blender/draw/engines/overlay/overlay_shader.c
A   source/blender/draw/engines/overlay/shaders/armature_alpha_lib.glsl
M   source/blender/draw/engines/overlay/shaders/armature_dof_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/armature_envelope_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/armature_shape_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/armature_sphere_solid_frag.glsl
M   source/blender/draw/engines/overlay/shaders/armature_stick_frag.glsl
M   source/blender/draw/engines/overlay/shaders/armature_wire_frag.glsl
M   source/blender/makesdna/DNA_view3d_defaults.h
M   source/blender/makesdna/DNA_view3d_types.h
M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index 55cb110177f..4748ec6a1ee 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6473,17 +6473,18 @@ class VIEW3D_PT_overlay_sculpt(Panel):
 row.prop(overlay, "sculpt_mode_face_sets_opacity", text="Face Sets")
 
 
-class VIEW3D_PT_overlay_pose(Panel):
+class VIEW3D_PT_overlay_bones(Panel):
 bl_space_type = 'VIEW_3D'
 bl_region_type = 'HEADER'
 bl_parent_id = 'VIEW3D_PT_overlay'
-bl_label = "Pose Mode"
+bl_label = "Bones"
 
 @classmethod
 def poll(cls, context):
 mode = context.mode
 return (
 (mode == 'POSE') or
+(mode == 'EDIT_ARMATURE') or
 (mode == 'PAINT_WEIGHT' and context.pose_object)
 )
 
@@ -6503,10 +6504,14 @@ class VIEW3D_PT_overlay_pose(Panel):
 sub = row.row()
 sub.active = display_all and overlay.show_xray_bone
 sub.prop(overlay, "xray_alpha_bone", text="Fade Geometry")
-else:
+elif mode == 'PAINT_WEIGHT':
 row = col.row()
 row.prop(overlay, "show_xray_bone")
 
+row = col.row()
+row.prop(overlay, "bone_wire_alpha")
+row.prop(overlay, "bone_wire_fade")
+
 
 class VIEW3D_PT_overlay_texture_paint(Panel):
 bl_space_type = 'VIEW_3D'
@@ -7675,7 +7680,7 @@ classes = (
 VIEW3D_PT_overlay_texture_paint,
 VIEW3D_PT_overlay_vertex_paint,
 VIEW3D_PT_overlay_weight_paint,
-VIEW3D_PT_overlay_pose,
+VIEW3D_PT_overlay_bones,
 VIEW3D_PT_overlay_sculpt,
 VIEW3D_PT_snapping,
 VIEW3D_PT_proportional_edit,
diff --git a/source/blender/blenloader/intern/versioning_290.c 
b/source/blender/blenloader/intern/versioning_290.c
index 78936140a60..eef5ce5085f 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1536,5 +1536,18 @@ void blo_do_versions_290(FileData *fd, Library 
*UNUSED(lib), Main *bmain)
 }
   }
 }
+
+if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", 
"bone_wire_alpha")) {
+  for (bScreen *screen = bmain->screens.first; screen; screen = 
screen->id.next) {
+LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+  LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+if (sl->spacetype == SPACE_VIEW3D) {
+  View3D *v3d = (View3D *)sl;
+  v3d->overlay.bone_wire_alpha = 1.0f;
+}
+  }
+}
+  }
+}
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index 9b716d3..382f0dae001 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -331,6 +331,7 @@ data_to_c_simple(engines/basic/shaders/depth_frag.glsl SRC)
 data_to_c_simple(engines/overlay/shaders/common_overlay_lib.glsl SRC)
 

[Bf-blender-cvs] [d6cc80765a7] temp-angavrilov-constraints: Armature: add B-Bone lengthwise scaling and custom handle scaling options.

2021-01-07 Thread Alexander Gavrilov
Commit: d6cc80765a7a7c21a69f7d7ee3d84fa8640bfcb1
Author: Alexander Gavrilov
Date:   Fri Dec 11 19:17:39 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBd6cc80765a7a7c21a69f7d7ee3d84fa8640bfcb1

Armature: add B-Bone lengthwise scaling and custom handle scaling options.

In addition to the base bone transformation itself, B-Bones have
controls that affect transformation of its segments. For rotation
the features are quite complete, allowing to both reorient the
Bezier handles via properties, and to control them using custom
handle bones. However for scaling there are two deficiencies.

First, there are only X and Y scale factors (actually X and Z,
but this is the legacy naming), while lengthwise all segments
have the same scaling. The ease option merely affects the shape
of the curve, and does not cause actual scaling.

Second, scaling can only be controlled via properties, thus
requiring up to 6 drivers per joint between B-Bones to transfer
scaling factors from the handle bone. This is very inefficient.

This patch addresses these deficiencies by adding Length scale
inputs, and providing toggles to apply custom handle local scale
channels to the now four scale-related properties. The 'Length'
name is used to avoid confusion due to the X/Y vs X/Z naming.

The two Length scale inputs control the ratio between the lengths
of the start and end segments of the bone: although for convenience
two inputs are provided, the whole chain is still uniformly scaled
to fit the curve.

A Scale Easing option is provided to multiply the easing value
by the Length scale factors to synchronize them - this produces
a natural scaling effect where both the shape of the curve and
the scale is affected.

The second issue is addressed by providing toggles for each handle
that multiply each of the X, Z, Length and Ease values by the matching
Local Scale channel of the handle bone, thus replacing trivial drivers.
The Scale Easing option has no effect on this process since it's easy
to just enable both Length and Ease buttons.

Finally, this fixes a strange behavior where the segments were not
actually scaled in the Y direction to match their actual length, thus
producing gaps or overlap depending on the shape of the curve. For
transformation the change should be very small if enough segments
are used, but this will affect the results of the Copy Transforms
and Armature constraints, so a backwards compatibility option is
provided. Newly created bones default to the new behavior.

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

===

M   release/scripts/startup/bl_ui/properties_data_bone.py
M   source/blender/blenkernel/BKE_armature.h
M   source/blender/blenkernel/intern/action.c
M   source/blender/blenkernel/intern/armature.c
M   source/blender/blenloader/intern/versioning_290.c
M   source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
M   source/blender/draw/engines/overlay/overlay_armature.c
M   source/blender/editors/armature/armature_add.c
M   source/blender/editors/armature/armature_intern.h
M   source/blender/editors/armature/armature_utils.c
M   source/blender/editors/armature/pose_transform.c
M   source/blender/editors/armature/pose_utils.c
M   source/blender/makesdna/DNA_action_types.h
M   source/blender/makesdna/DNA_armature_types.h
M   source/blender/makesrna/intern/rna_armature.c

===

diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py 
b/release/scripts/startup/bl_ui/properties_data_bone.py
index 170d7910339..5911994bcb9 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -170,28 +170,57 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
 col = topcol.column(align=True)
 col.prop(bbone, "bbone_scaleinx", text="Scale In X")
 col.prop(bbone, "bbone_scaleiny", text="In Y")
+col.prop(bbone, "bbone_scalein_len", text="In Len")
 
 col = topcol.column(align=True)
 col.prop(bbone, "bbone_scaleoutx", text="Scale Out X")
 col.prop(bbone, "bbone_scaleouty", text="Out Y")
+col.prop(bbone, "bbone_scaleout_len", text="Out Len")
 
 col = topcol.column(align=True)
 col.prop(bbone, "bbone_easein", text="Ease In")
 col.prop(bbone, "bbone_easeout", text="Out")
+col.prop(bone, "use_scale_easing")
+
+topcol.prop(bone, "use_unscaled_segments")
 
 col = topcol.column(align=True)
 col.prop(bone, "bbone_handle_type_start", text="Start Handle")
 
-col = col.column(align=True)
-col.active = (bone.bbone_handle_type_start != 'AUTO')
-col.prop_search(bone, "bbone_custom_handle_start", arm, bone_list, 
text="Custom")
+col2 = col.column(align=True)
+col2.active = 

[Bf-blender-cvs] [6460f4ad027] temp-angavrilov-constraints: Weight Paint: avoid creating very small values with locked weights.

2021-01-07 Thread Alexander Gavrilov
Commit: 6460f4ad0273e15032b5812c70e70b31c4099d7b
Author: Alexander Gavrilov
Date:   Thu Dec 24 14:30:51 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB6460f4ad0273e15032b5812c70e70b31c4099d7b

Weight Paint: avoid creating very small values with locked weights.

When painting using Auto-Normalize or Lock Relative with some
groups locked, the locked weights may not add up precisely to
1 because of precision limitations, which results in creating
nonzero weights close to FLT_EPSILON. With Lock Relative display
mode this is very obvious and annoying (random red points amid
black or blue), so add an epsilon check to consider less than
1e-6 unlocked weight to be the same as 0.

In addition, in cases when no weight can be painted due to locks,
don't create vertex group entries at all if they don't exist yet.

===

M   source/blender/blenkernel/BKE_deform.h
M   source/blender/blenkernel/intern/deform.c
M   source/blender/editors/sculpt_paint/paint_vertex.c

===

diff --git a/source/blender/blenkernel/BKE_deform.h 
b/source/blender/blenkernel/BKE_deform.h
index 2f3ec69418f..5d581b695af 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -80,6 +80,9 @@ float BKE_defvert_multipaint_collective_weight(const struct 
MDeformVert *dv,
int defbase_tot_sel,
bool is_normalized);
 
+/* This much unlocked weight is considered equivalent to none. */
+#define VERTEX_WEIGHT_EPSILON 1e-6f
+
 float BKE_defvert_calc_lock_relative_weight(float weight,
 float locked_weight,
 float unlocked_weight);
diff --git a/source/blender/blenkernel/intern/deform.c 
b/source/blender/blenkernel/intern/deform.c
index f7cf4faf7cb..23a23013d3d 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -899,7 +899,7 @@ float BKE_defvert_calc_lock_relative_weight(float weight,
   }
 
   /* handle division by zero */
-  if (locked_weight >= 1.0f) {
+  if (locked_weight >= 1.0f - VERTEX_WEIGHT_EPSILON) {
 if (weight != 0.0f) {
   return 1.0f;
 }
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c 
b/source/blender/editors/sculpt_paint/paint_vertex.c
index 9e9e0f441f7..0cbc7600aa5 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -415,7 +415,12 @@ static float wpaint_undo_lock_relative(
   /* In auto-normalize mode, or when there is no unlocked weight,
* compute based on locked weight. */
   if (auto_normalize || free_weight <= 0.0f) {
-weight *= (1.0f - locked_weight);
+if (locked_weight < 1.0f - VERTEX_WEIGHT_EPSILON) {
+  weight *= (1.0f - locked_weight);
+}
+else {
+  weight = 0;
+}
   }
   else {
 /* When dealing with full unlocked weight, don't paint, as it is always 
displayed as 1. */
@@ -518,7 +523,7 @@ static bool 
do_weight_paint_normalize_all_locked(MDeformVert *dvert,
 return false;
   }
 
-  if (lock_weight >= 1.0f) {
+  if (lock_weight >= 1.0f - VERTEX_WEIGHT_EPSILON) {
 /* locked groups make it impossible to fully normalize,
  * zero out what we can and return false */
 for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
@@ -779,7 +784,25 @@ static void do_weight_paint_vertex_single(
 index_mirr = vgroup_mirr = -1;
   }
 
-  if (wp->flag & VP_FLAG_VGROUP_RESTRICT) {
+  /* Check if painting should create new deform weight entries. */
+  bool restrict_to_existing = (wp->flag & VP_FLAG_VGROUP_RESTRICT) != 0;
+
+  if (wpi->do_lock_relative || wpi->do_auto_normalize) {
+/* Without do_lock_relative only dw_rel_locked is reliable, while 
dw_rel_free may be fake 0. */
+dw_rel_free = BKE_defvert_total_selected_weight(dv, wpi->defbase_tot, 
wpi->vgroup_unlocked);
+dw_rel_locked = BKE_defvert_total_selected_weight(dv, wpi->defbase_tot, 
wpi->vgroup_locked);
+CLAMP(dw_rel_locked, 0.0f, 1.0f);
+
+/* Do not create entries if there is not enough free weight to paint.
+ * This logic is the same as in wpaint_undo_lock_relative and 
auto-normalize. */
+if (wpi->do_auto_normalize || dw_rel_free <= 0.0f) {
+  if (dw_rel_locked >= 1.0f - VERTEX_WEIGHT_EPSILON) {
+restrict_to_existing = true;
+  }
+}
+  }
+
+  if (restrict_to_existing) {
 dw = BKE_defvert_find_index(dv, wpi->active.index);
   }
   else {
@@ -827,10 +850,6 @@ static void do_weight_paint_vertex_single(
 
   /* Handle weight caught up in locked defgroups for Lock Relative. */
   if (wpi->do_lock_relative) {
-dw_rel_free = BKE_defvert_total_selected_weight(dv, wpi->defbase_tot, 
wpi->vgroup_unlocked);
-dw_rel_locked = BKE_defvert_tot

[Bf-blender-cvs] [06119f88226] temp-angavrilov-constraints: Armature: fix bad B-Bone deformation blending with Preserve Volume.

2021-01-07 Thread Alexander Gavrilov
Commit: 06119f882263d0a8c5392dcb6cd43720cfcf4d96
Author: Alexander Gavrilov
Date:   Tue Dec 29 19:55:29 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB06119f882263d0a8c5392dcb6cd43720cfcf4d96

Armature: fix bad B-Bone deformation blending with Preserve Volume.

The double quaternion blending method in addition to the deformation
matrix of each bone requires their rest matrices. For ordinary bones
this literally should use the bone rest matrix without any ambiguity.

However, it was also using the bone rest matrix for all of its
B-Bone segments, which is incorrect and causes strange deformation
in some cases involving extreme non-uniform scale, especially
at boundaries between different B-Bones.

This changes both the Armature modifier and the Armature constraint
to use the actual segment rest matrices. Unlike bones, these can have
scale even in rest pose, so normalization is required.

===

M   source/blender/blenkernel/intern/armature.c
M   source/blender/blenkernel/intern/constraint.c

===

diff --git a/source/blender/blenkernel/intern/armature.c 
b/source/blender/blenkernel/intern/armature.c
index 5d3375cdb5e..8cd58968e04 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -1582,7 +1582,11 @@ void BKE_pchan_bbone_segments_cache_compute(bPoseChannel 
*pchan)
   tmat,
   b_bone_mats[0].mat);
 
-mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a + 
1].mat);
+/* Compute the orthonormal object space rest matrix of the segment. */
+mul_m4_m4m4(tmat, bone->arm_mat, b_bone_rest[a].mat);
+normalize_m4(tmat);
+
+mat4_to_dquat(&b_bone_dual_quats[a], tmat, b_bone_mats[a + 1].mat);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/constraint.c 
b/source/blender/blenkernel/intern/constraint.c
index 9da17282a4f..51ffbf7feb8 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -2592,9 +2592,14 @@ static void armdef_accumulate_matrix(const float 
obmat[4][4],
 
   /* Accumulate the transformation. */
   if (r_sum_dq != NULL) {
+float basemat_world[4][4];
 DualQuat tmpdq;
 
-mat4_to_dquat(&tmpdq, basemat, mat);
+/* Compute the orthonormal rest matrix in world space. */
+mul_m4_m4m4(basemat_world, obmat, basemat);
+orthogonalize_m4_stable(basemat_world, 1, true);
+
+mat4_to_dquat(&tmpdq, basemat_world, mat);
 add_weighted_dq_dq(r_sum_dq, &tmpdq, weight);
   }
   else {
@@ -2611,7 +2616,7 @@ static void armdef_accumulate_bone(bConstraintTarget *ct,
float r_sum_mat[4][4],
DualQuat *r_sum_dq)
 {
-  float iobmat[4][4], basemat[4][4], co[3];
+  float iobmat[4][4], co[3];
   Bone *bone = pchan->bone;
   float weight = ct->weight;
 
@@ -2625,15 +2630,12 @@ static void armdef_accumulate_bone(bConstraintTarget 
*ct,
 co, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, 
bone->dist);
   }
 
-  /* Compute the quaternion base matrix. */
-  if (r_sum_dq != NULL) {
-mul_m4_series(basemat, ct->tar->obmat, bone->arm_mat, iobmat);
-  }
-
   /* Find the correct bone transform matrix in world space. */
   if (bone->segments > 1 && bone->segments == pchan->runtime.bbone_segments) {
 Mat4 *b_bone_mats = pchan->runtime.bbone_deform_mats;
+Mat4 *b_bone_rest_mats = pchan->runtime.bbone_rest_mats;
 float(*iamat)[4] = b_bone_mats[0].mat;
+float basemat[4][4];
 
 /* The target is a B-Bone:
  * FIRST: find the segment (see b_bone_deform in armature.c)
@@ -2645,6 +2647,11 @@ static void armdef_accumulate_bone(bConstraintTarget *ct,
 float blend;
 BKE_pchan_bbone_deform_segment_index(pchan, y / bone->length, &index, 
&blend);
 
+if (r_sum_dq != NULL) {
+  /* Compute the object space rest matrix of the segment. */
+  mul_m4_m4m4(basemat, bone->arm_mat, b_bone_rest_mats[index].mat);
+}
+
 armdef_accumulate_matrix(ct->tar->obmat,
  iobmat,
  basemat,
@@ -2652,6 +2659,12 @@ static void armdef_accumulate_bone(bConstraintTarget *ct,
  weight * (1.0f - blend),
  r_sum_mat,
  r_sum_dq);
+
+if (r_sum_dq != NULL) {
+  /* Compute the object space rest matrix of the segment. */
+  mul_m4_m4m4(basemat, bone->arm_mat, b_bone_rest_mats[index + 1].mat);
+}
+
 armdef_accumulate_matrix(ct->tar->obmat,
  iobmat,
  basemat,
@@ -2663,7 +2676,7 @@ static void armdef_accumulate_bone(bConstraintTarget *ct,
   else {
 /* Simple bone. This requires DEG_OPCODE_BONE_DONE dependency due to 
chan_mat. */
 armdef_accumulate_mat

[Bf-blender-cvs] [b88edf16bf4] temp-angavrilov-constraints: Constraints: add support for a new Owner Local Space for targets.

2021-01-07 Thread Alexander Gavrilov
Commit: b88edf16bf42a59dcf57fc88ef308f14a14702fb
Author: Alexander Gavrilov
Date:   Fri Dec 11 11:53:25 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBb88edf16bf42a59dcf57fc88ef308f14a14702fb

Constraints: add support for a new Owner Local Space for targets.

Add a new transformation space choice for bone constraints, which
represent the local transformation of the bone in the constraint
owner's local space.

The use case for this is transferring the local (i.e. excluding the
effect of parents) transformation of one bone to another one, while
ignoring the difference between their rest pose orientations.

Owner Local Space replaces the following setup:

* A `child` bone of the `target`, rotated the same as `owner` in rest pose.
* A `sibling` bone of the `target`, positioned same as `child` in rest
  pose and using Copy Transforms in World Space from `child`.
* The `owner` bone constraint uses Local Space of `sibling`.

(This analogy applies provided both bones use Local Location)

Since the space list is getting long, this adds a couple of separators.

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

===

M   source/blender/blenkernel/intern/constraint.c
M   source/blender/editors/armature/armature_add.c
M   source/blender/makesdna/DNA_constraint_types.h
M   source/blender/makesrna/intern/rna_constraint.c
M   source/blender/makesrna/intern/rna_object_api.c

===

diff --git a/source/blender/blenkernel/intern/constraint.c 
b/source/blender/blenkernel/intern/constraint.c
index 87370b78810..9b3c6e3c955 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -299,7 +299,7 @@ void BKE_constraint_mat_convertspace(Object *ob,
   mul_m4_m4m4(mat, imat, mat);
 
   /* Use pose-space as stepping stone for other spaces. */
-  if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) {
+  if (to != CONSTRAINT_SPACE_POSE) {
 /* Call self with slightly different values. */
 BKE_constraint_mat_convertspace(
 ob, pchan, cob, mat, CONSTRAINT_SPACE_POSE, to, keep_scale);
@@ -310,9 +310,22 @@ void BKE_constraint_mat_convertspace(Object *ob,
   case CONSTRAINT_SPACE_POSE: /* -- FROM POSESPACE -- */
   {
 /* pose to local */
-if (to == CONSTRAINT_SPACE_LOCAL) {
+if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_OWNLOCAL)) {
   if (pchan->bone) {
 BKE_armature_mat_pose_to_bone(pchan, mat, mat);
+
+if (to == CONSTRAINT_SPACE_OWNLOCAL) {
+  copy_m4_m4(diff_mat, pchan->bone->arm_mat);
+
+  if (cob && cob->pchan && cob->pchan->bone) {
+invert_m4_m4(imat, cob->pchan->bone->arm_mat);
+mul_m4_m4m4(diff_mat, imat, diff_mat);
+  }
+
+  zero_v3(diff_mat[3]);
+  invert_m4_m4(imat, diff_mat);
+  mul_m4_series(mat, diff_mat, mat, imat);
+}
   }
 }
 /* pose to local with parent */
@@ -335,15 +348,28 @@ void BKE_constraint_mat_convertspace(Object *ob,
 break;
   }
   case CONSTRAINT_SPACE_LOCAL: /*  FROM LOCALSPACE - */
-  {
+  case CONSTRAINT_SPACE_OWNLOCAL: {
 /* local to pose - do inverse procedure that was done for pose to 
local */
 if (pchan->bone) {
+  if (from == CONSTRAINT_SPACE_OWNLOCAL) {
+copy_m4_m4(diff_mat, pchan->bone->arm_mat);
+
+if (cob && cob->pchan && cob->pchan->bone) {
+  invert_m4_m4(imat, cob->pchan->bone->arm_mat);
+  mul_m4_m4m4(diff_mat, imat, diff_mat);
+}
+
+zero_v3(diff_mat[3]);
+invert_m4_m4(imat, diff_mat);
+mul_m4_series(mat, imat, mat, diff_mat);
+  }
+
   /* we need the posespace_matrix = local_matrix + 
(parent_posespace_matrix + restpos) */
   BKE_armature_mat_bone_to_pose(pchan, mat, mat);
 }
 
 /* use pose-space as stepping stone for other spaces */
-if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 
CONSTRAINT_SPACE_CUSTOM)) {
+if (to != CONSTRAINT_SPACE_POSE) {
   /* call self with slightly different values */
   BKE_constraint_mat_convertspace(
   ob, pchan, cob, mat, CONSTRAINT_SPACE_POSE, to, keep_scale);
@@ -358,7 +384,7 @@ void BKE_constraint_mat_convertspace(Object *ob,
 }
 
 /* use pose-space as stepping stone for other spaces */
-if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 
CONSTRAINT_SPACE_CUSTOM)) {
+if (to != CONSTRAINT_SPACE_POSE) {
   /* call self with slightly different values */
   BKE_constraint_mat_convertspace(

[Bf-blender-cvs] [7dee1a8789f] temp-angavrilov-constraints: Limit Rotation: add an Euler Order option and orthogonalize the matrix.

2021-01-07 Thread Alexander Gavrilov
Commit: 7dee1a8789fc3aa864b3edb7ce4fd19f0bedaf9c
Author: Alexander Gavrilov
Date:   Sun Nov 22 14:17:21 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB7dee1a8789fc3aa864b3edb7ce4fd19f0bedaf9c

Limit Rotation: add an Euler Order option and orthogonalize the matrix.

Since Limit Rotation is based on Euler decomposition, it should allow
specifying the order to use for the same reasons as Copy Rotation does,
namely, if the bone uses Quaternion rotation for its animation channels,
there is no way to choose the order for the constraint.

In addition, add a call to orthogonalize the matrix before processing
for the same reasons as D8915, and an early exit in case no limits are
enabled for a bit of extra efficiency.

Since the constraint goes through Euler decomposition, it would remove
shear even before the change, but the rotation won't make much sense.

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

===

M   release/scripts/startup/bl_ui/properties_constraint.py
M   source/blender/blenkernel/intern/constraint.c
M   source/blender/makesdna/DNA_constraint_types.h
M   source/blender/makesrna/intern/rna_constraint.c

===

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py 
b/release/scripts/startup/bl_ui/properties_constraint.py
index 71a7b056d07..a7ac96508f4 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -245,6 +245,7 @@ class ConstraintButtonsPanel(Panel):
 sub.prop(con, "max_z", text="Max")
 row.label(icon="BLANK1")
 
+layout.prop(con, "euler_order", text="Order")
 layout.prop(con, "use_transform_limit")
 self.space_template(layout, con, target=False, owner=True)
 
diff --git a/source/blender/blenkernel/intern/constraint.c 
b/source/blender/blenkernel/intern/constraint.c
index 9b3c6e3c955..5bd8a2bc576 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -1647,10 +1647,28 @@ static void rotlimit_evaluate(bConstraint *con, 
bConstraintOb *cob, ListBase *UN
   float eul[3];
   float size[3];
 
+  /* This constraint is based on euler rotation math, which doesn't work well 
with shear.
+   * The Y axis is chosen as the main one because constraints are most 
commonly used on bones.
+   * This also allows using the constraint to simply remove shear. */
+  orthogonalize_m4_stable(cob->matrix, 1, false);
+
+  /* Only do the complex processing if some limits are actually enabled. */
+  if (!(data->flag & (LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT))) {
+return;
+  }
+
+  /* Select the Euler rotation order, defaulting to the owner value. */
+  short rot_order = cob->rotOrder;
+
+  if (data->euler_order != CONSTRAINT_EULER_AUTO) {
+rot_order = data->euler_order;
+  }
+
+  /* Decompose the matrix using the specified order. */
   copy_v3_v3(loc, cob->matrix[3]);
   mat4_to_size(size, cob->matrix);
 
-  mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
+  mat4_to_eulO(eul, rot_order, cob->matrix);
 
   /* constraint data uses radians internally */
 
@@ -1683,7 +1701,7 @@ static void rotlimit_evaluate(bConstraint *con, 
bConstraintOb *cob, ListBase *UN
 }
   }
 
-  loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder);
+  loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, rot_order);
 }
 
 static bConstraintTypeInfo CTI_ROTLIMIT = {
diff --git a/source/blender/makesdna/DNA_constraint_types.h 
b/source/blender/makesdna/DNA_constraint_types.h
index d3f0809204b..20b60a52077 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -536,6 +536,8 @@ typedef struct bRotLimitConstraint {
   float zmin, zmax;
   short flag;
   short flag2;
+  char euler_order;
+  char _pad[3];
 } bRotLimitConstraint;
 
 /* Limit Scale Constraint */
diff --git a/source/blender/makesrna/intern/rna_constraint.c 
b/source/blender/makesrna/intern/rna_constraint.c
index 343318726c7..eeed8d2f9b3 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -2602,6 +2602,12 @@ static void rna_def_constraint_rotation_limit(BlenderRNA 
*brna)
   RNA_def_property_ui_text(prop, "Maximum Z", "Highest Z value to allow");
   RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, 
"rna_Constraint_update");
 
+  prop = RNA_def_property(srna, "euler_order", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "euler_order");
+  RNA_def_property_enum_items(prop, euler_order_items);
+  RNA_def_property_ui_text(prop, "Euler Order", "Explicitly specify the euler 
rotation order");
+  RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, 
"rna_Constraint_update");
+
   prop = RNA_def_property(srna, "use_transform_limit", PROP_BOOLEAN, 
PROP_NONE

[Bf-blender-cvs] [7e4b1eb61de] temp-angavrilov-constraints: Constraints: refactor the D7437 patch adding Custom Space for constraints.

2021-01-07 Thread Alexander Gavrilov
Commit: 7e4b1eb61de28e847303e3bc7dc0b0056ed96b7a
Author: Alexander Gavrilov
Date:   Mon Nov 23 23:42:05 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB7e4b1eb61de28e847303e3bc7dc0b0056ed96b7a

Constraints: refactor the D7437 patch adding Custom Space for constraints.

As mentioned in the comments to that patch, I had an idea for
a different way to do some technical aspects, but it was too
complicated to force changes in the original patch. Thus I submit
this follow up patch.

First, instead of modifying all the get_constraint_targets and
flush_constraint_targets callbacks, introduce wrapper functions
for accessing constraint targets, convert all code to use them,
and handle the new reference there uniformly for all constraints.

This incidentally revealed a place in the Collada exporter that
didn't clean up after retrieving the targets.

Also, tag the special target with a flag so other code can
handle it appropriately where necessary. This for instance
allows dependency graph to know that the Use B-Bone Shape
option doesn't affect this specific target.

Finally, rename and simplify the function for initializing the
custom space, and make sure it is called everywhere necessary.

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

===

M   source/blender/blenkernel/BKE_constraint.h
M   source/blender/blenkernel/intern/action.c
M   source/blender/blenkernel/intern/armature.c
M   source/blender/blenkernel/intern/constraint.c
M   source/blender/blenkernel/intern/object.c
M   source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M   source/blender/draw/engines/overlay/overlay_extra.c
M   source/blender/editors/armature/armature_add.c
M   source/blender/editors/armature/armature_naming.c
M   source/blender/editors/armature/armature_relations.c
M   source/blender/editors/armature/pose_select.c
M   source/blender/editors/object/object_constraint.c
M   source/blender/editors/transform/transform_mode.c
M   source/blender/io/collada/BCAnimationSampler.cpp
M   source/blender/io/collada/SceneExporter.cpp
M   source/blender/makesdna/DNA_constraint_types.h
M   source/blender/makesrna/intern/rna_constraint.c

===

diff --git a/source/blender/blenkernel/BKE_constraint.h 
b/source/blender/blenkernel/BKE_constraint.h
index afad1e26159..c4f6f855a5a 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -214,6 +214,8 @@ void BKE_constraint_mat_convertspace(struct Object *ob,
  short to,
  const bool keep_scale);
 
+int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *list);
+void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase 
*list, bool no_copy);
 void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph,
   struct Scene *scene,
   struct bConstraint *con,
@@ -227,7 +229,7 @@ void BKE_constraint_targets_for_solving_get(struct 
Depsgraph *depsgraph,
 struct bConstraintOb *ob,
 struct ListBase *targets,
 float ctime);
-void BKE_constraint_custom_object_space_get(float r_mat[4][4], struct 
bConstraint *con);
+void BKE_constraint_custom_object_space_init(struct bConstraintOb *cob, struct 
bConstraint *con);
 void BKE_constraints_solve(struct Depsgraph *depsgraph,
struct ListBase *conlist,
struct bConstraintOb *cob,
diff --git a/source/blender/blenkernel/intern/action.c 
b/source/blender/blenkernel/intern/action.c
index ccb077d6b82..499f81f3669 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -992,13 +992,10 @@ void BKE_pose_channels_remove(Object *ob,
   else {
 /* Maybe something the bone references is being removed instead? */
 for (con = pchan->constraints.first; con; con = con->next) {
-  const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
   ListBase targets = {NULL, NULL};
   bConstraintTarget *ct;
 
-  if (cti && cti->get_constraint_targets) {
-cti->get_constraint_targets(con, &targets);
-
+  if (BKE_constraint_targets_get(con, &targets)) {
 for (ct = targets.first; ct; ct = ct->next) {
   if (ct->tar == ob) {
 if (ct->subtarget[0]) {
@@ -1010,9 +1007,7 @@ void BKE_pose_channels_remove(Object *ob,
   }
 }
 
-if (cti->flush_constraint_targets) {
-  cti->flush_constraint_targets(con, &targets, 0);
-}
+   

[Bf-blender-cvs] [e547bcf5443] temp-angavrilov-constraints: Cloth: completely exclude fully pinned triangles from collision.

2021-01-07 Thread Alexander Gavrilov
Commit: e547bcf5443d4bc0a5af8e1b2f40cefc246de1d0
Author: Alexander Gavrilov
Date:   Wed Jan 6 14:48:42 2021 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBe547bcf5443d4bc0a5af8e1b2f40cefc246de1d0

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

===

M   source/blender/blenkernel/intern/collision.c

===

diff --git a/source/blender/blenkernel/intern/collision.c 
b/source/blender/blenkernel/intern/collision.c
index 72525272254..268523fa2ab 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -1002,6 +1002,23 @@ static int 
cloth_selfcollision_response_static(ClothModifierData *clmd,
 #  pragma GCC diagnostic pop
 #endif
 
+static bool cloth_bvh_collision_is_active(const ClothModifierData 
*UNUSED(clmd),
+  const Cloth *cloth,
+  const MVertTri *tri_a)
+{
+  const ClothVertex *verts = cloth->verts;
+
+  /* Fully pinned triangles don't need collision processing. */
+  const int flags_a = verts[tri_a->tri[0]].flags & verts[tri_a->tri[1]].flags &
+  verts[tri_a->tri[2]].flags;
+
+  if (flags_a & CLOTH_VERT_FLAG_PINNED) {
+return false;
+  }
+
+  return true;
+}
+
 static void cloth_collision(void *__restrict userdata,
 const int index,
 const TaskParallelTLS *__restrict UNUSED(tls))
@@ -1059,13 +1076,31 @@ static void cloth_collision(void *__restrict userdata,
   }
 }
 
-static bool cloth_bvh_selfcollision_is_active(const Cloth *cloth,
+static bool cloth_bvh_selfcollision_is_active(const ClothModifierData *clmd,
+  const Cloth *cloth,
   const MVertTri *tri_a,
-  const MVertTri *tri_b,
-  bool sewing_active)
+  const MVertTri *tri_b)
 {
   const ClothVertex *verts = cloth->verts;
+
+  /* Skip when either triangle is excluded. */
+  const int flags_a = verts[tri_a->tri[0]].flags & verts[tri_a->tri[1]].flags &
+  verts[tri_a->tri[2]].flags;
+  const int flags_b = verts[tri_b->tri[0]].flags & verts[tri_b->tri[1]].flags &
+  verts[tri_b->tri[2]].flags;
+
+  if ((flags_a | flags_b) & CLOTH_VERT_FLAG_NOSELFCOLL) {
+return false;
+  }
+
+  /* Skip when both triangles are pinned. */
+  if ((flags_a & flags_b) & CLOTH_VERT_FLAG_PINNED) {
+return false;
+  }
+
   /* Ignore overlap of neighboring triangles and triangles connected by a 
sewing edge. */
+  bool sewing_active = (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW);
+
   for (uint i = 0; i < 3; i++) {
 for (uint j = 0; j < 3; j++) {
   if (tri_a->tri[i] == tri_b->tri[j]) {
@@ -1080,12 +1115,6 @@ static bool cloth_bvh_selfcollision_is_active(const 
Cloth *cloth,
 }
   }
 
-  if (((verts[tri_a->tri[0]].flags & verts[tri_a->tri[1]].flags & 
verts[tri_a->tri[2]].flags) |
-   (verts[tri_b->tri[0]].flags & verts[tri_b->tri[1]].flags & 
verts[tri_b->tri[2]].flags)) &
-  CLOTH_VERT_FLAG_NOSELFCOLL) {
-return false;
-  }
-
   return true;
 }
 
@@ -1107,8 +1136,7 @@ static void cloth_selfcollision(void *__restrict userdata,
   tri_b = &clmd->clothObject->tri[data->overlap[index].indexB];
 
 #ifdef DEBUG
-  bool sewing_active = (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW);
-  BLI_assert(cloth_bvh_selfcollision_is_active(clmd->clothObject, tri_a, 
tri_b, sewing_active));
+  BLI_assert(cloth_bvh_selfcollision_is_active(clmd, clmd->clothObject, tri_a, 
tri_b));
 #endif
 
   /* Compute distance and normal. */
@@ -1508,6 +1536,18 @@ static int 
cloth_bvh_selfcollisions_resolve(ClothModifierData *clmd,
   return ret;
 }
 
+static bool cloth_bvh_obj_overlap_cb(void *userdata,
+ int index_a,
+ int UNUSED(index_b),
+ int UNUSED(thread))
+{
+  ClothModifierData *clmd = (ClothModifierData *)userdata;
+  struct Cloth *clothObject = clmd->clothObject;
+  const MVertTri *tri_a

[Bf-blender-cvs] [743aa693270] temp-angavrilov-constraints: Surface Deform: optimize memory allocation in the evaluation code.

2021-01-07 Thread Alexander Gavrilov
Commit: 743aa693270f87dfe007d138291f332f49c2c726
Author: Alexander Gavrilov
Date:   Thu Jan 7 20:31:06 2021 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB743aa693270f87dfe007d138291f332f49c2c726

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.

Finally, a one line UI fix: the strength option is not bind specific.

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

===

M   source/blender/modifiers/intern/MOD_surfacedeform.c

===

diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c 
b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 64fad1b370b..0fad78683eb 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -20,6 +20,7 @@
  * \ingroup modifiers
  */
 
+#include "BLI_alloca.h"
 #include "BLI_math.h"
 #include "BLI_math_geom.h"
 #include "BLI_task.h"
@@ -1218,7 +1219,16 @@ static void deformVert(void *__restrict userdata,
   for (int j = 0; j < num_binds; j++) {
 max_verts = MAX2(max_verts, sdbind[j].numverts);
   }
-  float(*coords_buffer)[3] = MEM_malloc_arrayN(max_verts, 
sizeof(*coords_buffer), __func__);
+
+  const bool big_buffer = max_verts > 256;
+  float(*coords_buffer)[3];
+
+  if (UNLIKELY(big_buffer)) {
+coords_buffer = MEM_malloc_arrayN(max_verts, sizeof(*coords_buffer), 
__func__);
+  }
+  else {
+coords_buffer = BLI_array_alloca(coords_buffer, max_verts);
+  }
 
   for (int j = 0; j < num_binds; j++, sdbind++) {
 for (int k = 0; k < sdbind->numverts; k++) {
@@ -1228,28 +1238,32 @@ static void deformVert(void *__restrict userdata,
 normal_poly_v3(norm, coords_buffer, sdbind->numverts);
 zero_v3(temp);
 
-/* -- looptri mode -- */
-if (sdbind->mode == MOD_SDEF_MODE_LOOPTRI) {
-  madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], 
sdbind->vert_weights[0]);
-  madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], 
sdbind->vert_weights[1]);
-  madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[2]], 
sdbind->vert_weights[2]);
-}
-else {
+switch (sdbind->mode) {
+  /* -- looptri mode -- */
+  case MOD_SDEF_MODE_LOOPTRI: {
+madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], 
sdbind->vert_weights[0]);
+madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], 
sdbind->vert_weights[1]);
+madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[2]], 
sdbind->vert_weights[2]);
+break;
+  }
+
   /* -- ngon mode -- */
-  if (sdbind->mode == MOD_SDEF_MODE_NGON) {
+  case MOD_SDEF_MODE_NGON: {
 for (int k = 0; k < sdbind->numverts; k++) {
   madd_v3_v3fl(temp, coords_buffer[k], sdbind->vert_weights[k]);
 }
+break;
   }
 
   /* -- centroid mode -- */
-  else if (sdbind->mode == MOD_SDEF_MODE_CENTROID) {
+  case MOD_SDEF_MODE_CENTROID: {
 float cent[3];
 mid_v3_v3_array(cent, coords_buffer, sdbind->numverts);
 
 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[0]], 
sdbind->vert_weights[0]);
 madd_v3_v3fl(temp, data->targetCos[sdbind->vert_inds[1]], 
sdbind->vert_weights[1]);
 madd_v3_v3fl(temp, cent, sdbind->vert_weights[2]);
+break;
   }
 }
 
@@ -1263,7 +1277,10 @@ static void deformVert(void *__restrict userdata,
 
   /* Add the offset to start coord multiplied by the strength and weight 
values. */
   madd_v3_v3fl(vertexCos, offset, data->strength * weight);
-  MEM_freeN(coords_buffer);
+
+  if (UNLIKELY(big_buffer)) {
+MEM_freeN(coords_buffer);
+  }
 }
 
 static void surfacedeformModifier_do(ModifierData *md,
@@ -1442,9 +1459,9 @@ static void panel_draw(const bContext *UNUSED(C), Panel 
*panel)
   col = uiLayoutColumn(layout, false);
   uiLayoutSetActive(col, !is_bound);
   uiItemR(col, ptr, "target", 0, NULL, ICON_NONE);
-
   uiItemR(col, ptr, "falloff", 0, NULL, ICON_NONE);
-  uiItemR(col, ptr, "strength", 0, NULL, ICON_NONE);
+
+  uiItemR(layout, ptr, "strength", 0, NULL, ICON_NONE);
 
   modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", 
"invert_vertex_group", NULL);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [95c63babbb0] master: Cleanup: Declare variables where initialized

2021-01-07 Thread Hans Goudey
Commit: 95c63babbb0d1423e3a8f5d7ca5328c3cd6f8173
Author: Hans Goudey
Date:   Thu Jan 7 12:30:18 2021 -0600
Branches: master
https://developer.blender.org/rB95c63babbb0d1423e3a8f5d7ca5328c3cd6f8173

Cleanup: Declare variables where initialized

===

M   source/blender/editors/interface/interface_region_tooltip.c
M   source/blender/editors/interface/interface_regions.c

===

diff --git a/source/blender/editors/interface/interface_region_tooltip.c 
b/source/blender/editors/interface/interface_region_tooltip.c
index 89515608c5b..d88e4283553 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -165,7 +165,6 @@ static void ui_tooltip_region_draw_cb(const bContext 
*UNUSED(C), ARegion *region
   float *alert_color = tip_colors[UI_TIP_LC_ALERT];
 
   float background_color[3];
-  float tone_bg;
 
   wmOrtho2_region_pixelspace(region);
 
@@ -185,7 +184,7 @@ static void ui_tooltip_region_draw_cb(const bContext 
*UNUSED(C), ARegion *region
 
   /* find the brightness difference between background and text colors */
 
-  tone_bg = rgb_to_grayscale(background_color);
+  const float tone_bg = rgb_to_grayscale(background_color);
   /* tone_fg = rgb_to_grayscale(main_color); */
 
   /* mix the colors */
@@ -272,9 +271,7 @@ static void ui_tooltip_region_draw_cb(const bContext 
*UNUSED(C), ARegion *region
 
 static void ui_tooltip_region_free_cb(ARegion *region)
 {
-  uiTooltipData *data;
-
-  data = region->regiondata;
+  uiTooltipData *data = region->regiondata;
 
   for (int i = 0; i < data->fields_len; i++) {
 const uiTooltipField *field = &data->fields[i];
@@ -1164,16 +1161,13 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
   const int winx = WM_window_pixels_x(win);
   const int winy = WM_window_pixels_y(win);
   const uiStyle *style = UI_style_get();
-  static ARegionType type;
-  ARegion *region;
-  int fonth, fontw;
-  int h, i;
   rcti rect_i;
   int font_flag = 0;
 
   /* create area region */
-  region = ui_region_temp_add(CTX_wm_screen(C));
+  ARegion *region = ui_region_temp_add(CTX_wm_screen(C));
 
+  static ARegionType type;
   memset(&type, 0, sizeof(ARegionType));
   type.draw = ui_tooltip_region_draw_cb;
   type.free = ui_tooltip_region_free_cb;
@@ -1201,8 +1195,9 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
 #define TIP_BORDER_X (16.0f / aspect)
 #define TIP_BORDER_Y (6.0f / aspect)
 
-  h = BLF_height_max(data->fstyle.uifont_id);
+  int h = BLF_height_max(data->fstyle.uifont_id);
 
+  int i, fonth, fontw;
   for (i = 0, fontw = 0, fonth = 0; i < data->fields_len; i++) {
 uiTooltipField *field = &data->fields[i];
 uiTooltipField *field_next = (i + 1) != data->fields_len ? &data->fields[i 
+ 1] : NULL;
diff --git a/source/blender/editors/interface/interface_regions.c 
b/source/blender/editors/interface/interface_regions.c
index 9ff58ddd24f..51b4e82d679 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -41,9 +41,7 @@
 
 ARegion *ui_region_temp_add(bScreen *screen)
 {
-  ARegion *region;
-
-  region = MEM_callocN(sizeof(ARegion), "area region");
+  ARegion *region = MEM_callocN(sizeof(ARegion), __func__);
   BLI_addtail(&screen->regionbase, region);
 
   region->regiontype = RGN_TYPE_TEMPORARY;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d259e7dcfbb] master: Cycles: Increase instance limit for OptiX acceleration structure building

2021-01-07 Thread Patrick Mours
Commit: d259e7dcfbbd37cec5a45fdfb554f24de10d0268
Author: Patrick Mours
Date:   Thu Jan 7 18:54:29 2021 +0100
Branches: master
https://developer.blender.org/rBd259e7dcfbbd37cec5a45fdfb554f24de10d0268

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

===

M   intern/cycles/device/device_optix.cpp
M   intern/cycles/kernel/kernels/optix/kernel_optix.cu

===

diff --git a/intern/cycles/device/device_optix.cpp 
b/intern/cycles/device/device_optix.cpp
index 673fc1752bb..de98e3f3594 100644
--- a/intern/cycles/device/device_optix.cpp
+++ b/intern/cycles/device/device_optix.cpp
@@ -1519,6 +1519,16 @@ class OptiXDevice : public CUDADevice {
   bvh_optix->traversable_handle = 0;
   bvh_optix->motion_transform_data.free();
 
+#  if OPTIX_ABI_VERSION < 23
+  if (bvh->objects.size() > 0x7F) {
+#  else
+  if (bvh->objects.size() > 0x7FF) {
+#  endif
+progress.set_error(
+"Failed to build OptiX acceleration structure because there are 
too many instances");
+return;
+  }
+
   // Fill instance descriptions
 #  if OPTIX_ABI_VERSION < 41
   device_vector aabbs(this, "optix tlas aabbs", MEM_READ_ONLY);
@@ -1681,7 +1691,11 @@ class OptiXDevice : public CUDADevice {
 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
+#  if OPTIX_ABI_VERSION < 23
 instance.instanceId |= 0x80;
+#  else
+instance.instanceId |= 0x800;
+#  endif
   }
 }
   }
diff --git a/intern/cycles/kernel/kernels/optix/kernel_optix.cu 
b/intern/cycles/kernel/kernels/optix/kernel_optix.cu
index 8ccd2555091..0c2c84fdbdf 100644
--- a/intern/cycles/kernel/kernels/optix/kernel_optix.cu
+++ b/intern/cycles/kernel/kernels/optix/kernel_optix.cu
@@ -47,9 +47,9 @@ template ccl_device_forceinline uint 
get_object_id()
   // 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 & 0x7F;
+return object & 0x7FF;  // OPTIX_ABI_VERSION >= 23 ? 0x7FF : 
0x7F
   // Set to OBJECT_NONE if this is not an instanced object
-  else if (object & 0x80)
+  else if (object & 0x800)  // OPTIX_ABI_VERSION >= 23 ? 0x800 : 
0x80
 object = OBJECT_NONE;
   return object;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3db2bc82aa5] master: Surface Deform: optimize handling of the vertex group weight.

2021-01-07 Thread Alexander Gavrilov
Commit: 3db2bc82aa59725a9cc0c1184465ef4accd85aac
Author: Alexander Gavrilov
Date:   Wed Jan 6 12:47:01 2021 +0300
Branches: master
https://developer.blender.org/rB3db2bc82aa59725a9cc0c1184465ef4accd85aac

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

===

M   source/blender/modifiers/intern/MOD_surfacedeform.c

===

diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c 
b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 4dde1645ab7..64fad1b370b 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -160,7 +160,9 @@ typedef struct SDefDeformData {
   const SDefVert *const bind_verts;
   float (*const targetCos)[3];
   float (*const vertexCos)[3];
-  float *const weights;
+  const MDeformVert *const dvert;
+  int const defgrp_index;
+  bool const invert_vgroup;
   float const strength;
 } SDefDeformData;
 
@@ -1191,7 +1193,17 @@ static void deformVert(void *__restrict userdata,
   const int num_binds = data->bind_verts[index].numbinds;
   float *const vertexCos = data->vertexCos[index];
   float norm[3], temp[3], offset[3];
-  const float weight = (data->weights != NULL) ? data->weights[index] : 1.0f;
+
+  /* Retrieve the value of the weight vertex group if specified. */
+  float weight = 1.0f;
+
+  if (data->dvert && data->defgrp_index != -1) {
+weight = BKE_defvert_find_weight(&data->dvert[index], data->defgrp_index);
+
+if (data->invert_vgroup) {
+  weight = 1.0f - weight;
+}
+  }
 
   /* Check if this vertex will be deformed. If it is not deformed we return 
and avoid
* unnecessary calculations. */
@@ -1332,33 +1344,16 @@ static void surfacedeformModifier_do(ModifierData *md,
   int defgrp_index;
   MDeformVert *dvert;
   MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index);
-  float *weights = NULL;
-  const bool invert_group = (smd->flags & MOD_SDEF_INVERT_VGROUP) != 0;
-
-  if (defgrp_index != -1) {
-dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, 
CD_MDEFORMVERT, mesh->totvert);
-/* If no vertices were ever added to an object's vgroup, dvert might be 
NULL. */
-if (dvert == NULL) {
-  /* Add a valid data layer! */
-  dvert = CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, 
NULL, mesh->totvert);
-}
-
-if (dvert) {
-  weights = MEM_calloc_arrayN((size_t)numverts, sizeof(*weights), 
__func__);
-  MDeformVert *dv = dvert;
-  for (uint i = 0; i < numverts; i++, dv++) {
-weights[i] = invert_group ? (1.0f - BKE_defvert_find_weight(dv, 
defgrp_index)) :
-BKE_defvert_find_weight(dv, defgrp_index);
-  }
-}
-  }
+  const bool invert_vgroup = (smd->flags & MOD_SDEF_INVERT_VGROUP) != 0;
 
   /* Actual vertex location update starts here */
   SDefDeformData data = {
   .bind_verts = smd->verts,
   .targetCos = MEM_malloc_arrayN(tnumverts, sizeof(float[3]), 
"SDefTargetVertArray"),
   .vertexCos = vertexCos,
-  .weights = weights,
+  .dvert = dvert,
+  .defgrp_index = defgrp_index,
+  .invert_vgroup = invert_vgroup,
   .strength = smd->strength,
   };
 
@@ -1372,8 +1367,6 @@ static void surfacedeformModifier_do(ModifierData *md,
 
 MEM_freeN(data.targetCos);
   }
-
-  MEM_SAFE_FREE(weights);
 }
 
 static void deformVerts(ModifierData *md,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [64277e8f3a7] master: UI: Use Eyedropper Cursor with Sample Weight Tool

2021-01-07 Thread Juanfran Matheu
Commit: 64277e8f3a7e0bdcece91d9b09f219a79531bdd1
Author: Juanfran Matheu
Date:   Thu Jan 7 09:44:48 2021 -0800
Branches: master
https://developer.blender.org/rB64277e8f3a7e0bdcece91d9b09f219a79531bdd1

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

===

M   release/scripts/startup/bl_ui/space_toolsystem_toolbar.py

===

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py 
b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 30d614f87c9..aa90e364ef9 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1526,6 +1526,7 @@ class _defs_weight_paint:
 idname="builtin.sample_weight",
 label="Sample Weight",
 icon="ops.paint.weight_sample",
+cursor='EYEDROPPER',
 widget=None,
 keymap=(),
 draw_settings=draw_settings
@@ -1537,6 +1538,7 @@ class _defs_weight_paint:
 idname="builtin.sample_vertex_group",
 label="Sample Vertex Group",
 icon="ops.paint.weight_sample_group",
+cursor='EYEDROPPER',
 widget=None,
 keymap=(),
 )

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e3d9241a053] master: UI: Show Weight Value with Sample Weight Tool

2021-01-07 Thread Juanfran Matheu
Commit: e3d9241a0532e8d4c76def38184f432aa271f3a0
Author: Juanfran Matheu
Date:   Thu Jan 7 09:29:36 2021 -0800
Branches: master
https://developer.blender.org/rBe3d9241a0532e8d4c76def38184f432aa271f3a0

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

===

M   release/scripts/startup/bl_ui/space_toolsystem_toolbar.py

===

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py 
b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index a5354ca6bbe..30d614f87c9 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1514,12 +1514,21 @@ class _defs_weight_paint:
 
 @ToolDef.from_fn
 def sample_weight():
+def draw_settings(context, layout, tool):
+if context.tool_settings.unified_paint_settings.use_unified_weight:
+weight = context.tool_settings.unified_paint_settings.weight
+elif context.tool_settings.weight_paint.brush:
+weight = context.tool_settings.weight_paint.brush.weight
+else:
+return
+layout.label(text="Weight: %.3f" % weight)
 return dict(
 idname="builtin.sample_weight",
 label="Sample Weight",
 icon="ops.paint.weight_sample",
 widget=None,
 keymap=(),
+draw_settings=draw_settings
 )
 
 @ToolDef.from_fn

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3db975f30dd] master: Fix T84326: No ID for geometry nodes instances after scattering

2021-01-07 Thread Hans Goudey
Commit: 3db975f30dd327381dc1a0e08305460a1a12eba4
Author: Hans Goudey
Date:   Thu Jan 7 09:27:42 2021 -0600
Branches: master
https://developer.blender.org/rB3db975f30dd327381dc1a0e08305460a1a12eba4

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

===

M   source/blender/blenkernel/BKE_geometry_set.h
M   source/blender/blenkernel/BKE_geometry_set.hh
M   source/blender/blenkernel/intern/geometry_set.cc
M   source/blender/blenkernel/intern/object_dupli.c
M   source/blender/nodes/geometry/nodes/node_geo_point_instance.cc

===

diff --git a/source/blender/blenkernel/BKE_geometry_set.h 
b/source/blender/blenkernel/BKE_geometry_set.h
index 37a3ed82bb8..5b8273def66 100644
--- a/source/blender/blenkernel/BKE_geometry_set.h
+++ b/source/blender/blenkernel/BKE_geometry_set.h
@@ -49,6 +49,7 @@ int BKE_geometry_set_instances(const struct GeometrySet 
*geometry_set,
float (**r_positions)[3],
float (**r_rotations)[3],
float (**r_scales)[3],
+   int **r_ids,
struct InstancedData **r_instanced_data);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh 
b/source/blender/blenkernel/BKE_geometry_set.hh
index e4232a84a00..9dc2b80d4d4 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -364,6 +364,7 @@ class InstancesComponent : public GeometryComponent {
   blender::Vector positions_;
   blender::Vector rotations_;
   blender::Vector scales_;
+  blender::Vector ids_;
   blender::Vector instanced_data_;
 
  public:
@@ -375,20 +376,24 @@ class InstancesComponent : public GeometryComponent {
   void add_instance(Object *object,
 blender::float3 position,
 blender::float3 rotation = {0, 0, 0},
-blender::float3 scale = {1, 1, 1});
+blender::float3 scale = {1, 1, 1},
+const int id = -1);
   void add_instance(Collection *collection,
 blender::float3 position,
 blender::float3 rotation = {0, 0, 0},
-blender::float3 scale = {1, 1, 1});
+blender::float3 scale = {1, 1, 1},
+const int id = -1);
   void add_instance(InstancedData data,
 blender::float3 position,
 blender::float3 rotation,
-blender::float3 scale);
+blender::float3 scale,
+const int id = -1);
 
   blender::Span instanced_data() const;
   blender::Span positions() const;
   blender::Span rotations() const;
   blender::Span scales() const;
+  blender::Span ids() const;
   blender::MutableSpan positions();
   int instances_amount() const;
 
diff --git a/source/blender/blenkernel/intern/geometry_set.cc 
b/source/blender/blenkernel/intern/geometry_set.cc
index 2a21a60ccc6..5d2b82dcc5f 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -476,34 +476,38 @@ void InstancesComponent::clear()
 void InstancesComponent::add_instance(Object *object,
   blender::float3 position,
   blender::float3 rotation,
-  blender::float3 scale)
+  blender::float3 scale,
+  const int id)
 {
   InstancedData data;
   data.type = INSTANCE_DATA_TYPE_OBJECT;
   data.data.object = object;
-  this->add_instance(data, position, rotation, scale);
+  this->add_instance(data, position, rotation, scale, id);
 }
 
 void InstancesComponent::add_instance(Collection *collection,
   blender::float3 position,
   blender::float3 rotation,
-  blender::float3 scale)
+  blender::float3 scale,
+  const int id)
 {
   Instanced

[Bf-blender-cvs] [4c0fc60105d] master: UndoSystem: Early out from core undo/redo handlers when undo step is NULL.

2021-01-07 Thread Bastien Montagne
Commit: 4c0fc60105d7b7ff3f5c926510d77bb261e71977
Author: Bastien Montagne
Date:   Thu Jan 7 12:15:22 2021 +0100
Branches: master
https://developer.blender.org/rB4c0fc60105d7b7ff3f5c926510d77bb261e71977

UndoSystem: Early out from core undo/redo handlers when undo step is NULL.

Also added `undosys_stack_validate` debug check to redo case.

===

M   source/blender/blenkernel/intern/undo_system.c

===

diff --git a/source/blender/blenkernel/intern/undo_system.c 
b/source/blender/blenkernel/intern/undo_system.c
index 9c7e226007a..e5d2d4a9f0b 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -675,9 +675,11 @@ bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack,
 bool use_skip)
 {
   UNDO_NESTED_ASSERT(false);
-  if (us) {
-undosys_stack_validate(ustack, true);
+  if (us == NULL) {
+return false;
   }
+  undosys_stack_validate(ustack, true);
+
   UndoStep *us_prev = us ? us->prev : NULL;
   if (us) {
 /* The current state is a copy, we need to load the previous state. */
@@ -753,6 +755,11 @@ bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack,
 bool use_skip)
 {
   UNDO_NESTED_ASSERT(false);
+  if (us == NULL) {
+return false;
+  }
+  undosys_stack_validate(ustack, true);
+
   UndoStep *us_next = us ? us->next : NULL;
   /* Unlike undo accumulate, we always use the next. */
   us = us_next;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [044dd42a051] master: Cleanup: Undo system: minor simplification in non-debug code.

2021-01-07 Thread Bastien Montagne
Commit: 044dd42a0515e86ac768d4ad3d8aef4d7eda70f4
Author: Bastien Montagne
Date:   Thu Jan 7 12:06:55 2021 +0100
Branches: master
https://developer.blender.org/rB044dd42a0515e86ac768d4ad3d8aef4d7eda70f4

Cleanup: Undo system: minor simplification in non-debug code.

===

M   source/blender/blenkernel/intern/undo_system.c

===

diff --git a/source/blender/blenkernel/intern/undo_system.c 
b/source/blender/blenkernel/intern/undo_system.c
index 5544e151ddb..9c7e226007a 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -252,9 +252,8 @@ static void undosys_stack_validate(UndoStack *ustack, bool 
expect_non_empty)
   }
 }
 #else
-static void undosys_stack_validate(UndoStack *ustack, bool expect_non_empty)
+static void undosys_stack_validate(UndoStack *UNUSED(ustack), bool 
UNUSED(expect_non_empty))
 {
-  UNUSED_VARS(ustack, expect_non_empty);
 }
 #endif

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [987e9e2145f] master: Fix T84469: Online manual raises an exception with key-map options

2021-01-07 Thread Campbell Barton
Commit: 987e9e2145fd31e9a3f763819b0e942ccd93bb65
Author: Campbell Barton
Date:   Thu Jan 7 23:24:23 2021 +1100
Branches: master
https://developer.blender.org/rB987e9e2145fd31e9a3f763819b0e942ccd93bb65

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.

===

M   release/scripts/startup/bl_operators/wm.py

===

diff --git a/release/scripts/startup/bl_operators/wm.py 
b/release/scripts/startup/bl_operators/wm.py
index 350d9391acf..bef3e5d4384 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -974,7 +974,7 @@ class WM_OT_path_open(Operator):
 return {'FINISHED'}
 
 
-def _wm_doc_get_id(doc_id, do_url=True, url_prefix=""):
+def _wm_doc_get_id(doc_id, do_url=True, url_prefix="", report=None):
 
 def operator_exists_pair(a, b):
 # Not fast, this is only for docs.
@@ -1025,6 +1025,11 @@ def _wm_doc_get_id(doc_id, do_url=True, url_prefix=""):
 # Check class for dynamically registered types.
 rna_class = 
bpy.types.PropertyGroup.bl_rna_get_subclass_py(class_name)
 
+if rna_class is None:
+if report is not None:
+report({'ERROR'}, iface_("Type \"%s\" can not be found") % 
class_name)
+return None
+
 # Detect if this is a inherited member and use that name instead.
 rna_parent = rna_class.bl_rna
 rna_prop = rna_parent.properties.get(class_prop)
@@ -1084,9 +1089,9 @@ class WM_OT_doc_view_manual(Operator):
 return url
 
 def execute(self, _context):
-rna_id = _wm_doc_get_id(self.doc_id, do_url=False)
+rna_id = _wm_doc_get_id(self.doc_id, do_url=False, report=self.report)
 if rna_id is None:
-return {'PASS_THROUGH'}
+return {'CANCELLED'}
 
 url = self._lookup_rna_url(rna_id)
 
@@ -1118,9 +1123,9 @@ class WM_OT_doc_view(Operator):
 _prefix = ("https://docs.blender.org/api/master";)
 
 def execute(self, _context):
-url = _wm_doc_get_id(self.doc_id, do_url=True, url_prefix=self._prefix)
+url = _wm_doc_get_id(self.doc_id, do_url=True, 
url_prefix=self._prefix, report=self.report)
 if url is None:
-return {'PASS_THROUGH'}
+return {'CANCELLED'}
 
 import webbrowser
 webbrowser.open(url)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c55b578c9e1] master: Fix T84142: crash when mirroring hair emitted from vertices

2021-01-07 Thread Jacques Lucke
Commit: c55b578c9e1f4f5d03fbac01c7efa070e1d6970d
Author: Jacques Lucke
Date:   Thu Jan 7 13:32:36 2021 +0100
Branches: master
https://developer.blender.org/rBc55b578c9e1f4f5d03fbac01c7efa070e1d6970d

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

===

M   source/blender/editors/physics/particle_edit.c

===

diff --git a/source/blender/editors/physics/particle_edit.c 
b/source/blender/editors/physics/particle_edit.c
index ff36197c61e..8ab25fa74b8 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -3496,6 +3496,21 @@ static int mirror_exec(bContext *C, wmOperator 
*UNUSED(op))
   return OPERATOR_FINISHED;
 }
 
+static bool mirror_poll(bContext *C)
+{
+  if (!PE_hair_poll(C)) {
+return false;
+  }
+
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+  Scene *scene = CTX_data_scene(C);
+  Object *ob = CTX_data_active_object(C);
+  PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
+
+  /* The operator only works for hairs emitted from faces. */
+  return edit->psys->part->from == PART_FROM_FACE;
+}
+
 void PARTICLE_OT_mirror(wmOperatorType *ot)
 {
   /* identifiers */
@@ -3505,7 +3520,7 @@ void PARTICLE_OT_mirror(wmOperatorType *ot)
 
   /* api callbacks */
   ot->exec = mirror_exec;
-  ot->poll = PE_hair_poll;
+  ot->poll = mirror_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c26f46cb952] master: Fix T83497: missing relations update when group node changes

2021-01-07 Thread Jacques Lucke
Commit: c26f46cb9521c4d3603a5502dce0fd8444fbe408
Author: Jacques Lucke
Date:   Thu Jan 7 13:31:17 2021 +0100
Branches: master
https://developer.blender.org/rBc26f46cb9521c4d3603a5502dce0fd8444fbe408

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

===

M   source/blender/makesrna/intern/rna_nodetree.c

===

diff --git a/source/blender/makesrna/intern/rna_nodetree.c 
b/source/blender/makesrna/intern/rna_nodetree.c
index b1ecce23732..8072d77059a 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3245,6 +3245,7 @@ static void rna_NodeGroup_update(Main *bmain, Scene 
*UNUSED(scene), PointerRNA *
   }
 
   ED_node_tag_update_nodetree(bmain, ntree, node);
+  DEG_relations_tag_update(bmain);
 }
 
 static void rna_NodeGroup_node_tree_set(PointerRNA *ptr,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0d042c8cca1] master: RNA: document Python instancing for ID's and RNA types

2021-01-07 Thread Campbell Barton
Commit: 0d042c8cca13823c976440db37cb9e1e072d5dd5
Author: Campbell Barton
Date:   Thu Jan 7 21:32:43 2021 +1100
Branches: master
https://developer.blender.org/rB0d042c8cca13823c976440db37cb9e1e072d5dd5

RNA: document Python instancing for ID's and RNA types

Document some of the less obvious implications for
re-using Python instances.

===

M   source/blender/makesdna/DNA_ID.h
M   source/blender/makesrna/intern/rna_internal_types.h

===

diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 265baa16cc5..51c47e917f1 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -314,6 +314,20 @@ typedef struct ID {
*/
   struct ID *orig_id;
 
+  /**
+   * Holds the #PyObject reference to the ID (initialized on demand).
+   *
+   * This isn't essential, it could be removed however it gives some 
advantages:
+   *
+   * - Every time the #ID is accessed a #BPy_StructRNA doesn't have to be 
created & destroyed
+   *   (consider all the polling and drawing functions that access ID's).
+   *
+   * - When this #ID is deleted, the #BPy_StructRNA can be invalidated
+   *   so accessing it from Python raises an exception instead of crashing.
+   *
+   *   This is of limited benefit though, as it doesn't apply to non #ID data
+   *   that references this ID (the bones of an armature or the modifiers of 
an object for e.g.).
+   */
   void *py_instance;
   void *_pad1;
 } ID;
diff --git a/source/blender/makesrna/intern/rna_internal_types.h 
b/source/blender/makesrna/intern/rna_internal_types.h
index 01c406104d7..e6ed0f69300 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -545,6 +545,17 @@ struct StructRNA {
   /* function to register/unregister subclasses */
   StructRegisterFunc reg;
   StructUnregisterFunc unreg;
+  /**
+   * Optionally support reusing Python instances for this type.
+   *
+   * Without this, an operator class created for #wmOperatorType.invoke (for 
example)
+   * would have a different instance passed to the #wmOperatorType.modal 
callback.
+   * So any variables assigned to `self` from Python would not be available to 
other callbacks.
+   *
+   * Being able to access the instance also has the advantage that we can 
invalidate
+   * the Python instance when the data has been removed, see: 
#BPY_DECREF_RNA_INVALIDATE
+   * so accessing the variables from Python raises an exception instead of 
crashing.
+   */
   StructInstanceFunc instance;
 
   /* callback to get id properties */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs