[Bf-blender-cvs] [8fa259604b8] refactor-mesh-position-generic: Merge branch 'master' into refactor-mesh-position-generic

2022-12-18 Thread Hans Goudey
Commit: 8fa259604b8bf32979848dcb7597cd1126730bac
Author: Hans Goudey
Date:   Sun Dec 18 23:24:38 2022 -0600
Branches: refactor-mesh-position-generic
https://developer.blender.org/rB8fa259604b8bf32979848dcb7597cd1126730bac

Merge branch 'master' into refactor-mesh-position-generic

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9cc4f430c93] refactor-mesh-position-generic: Merge branch 'master' into refactor-mesh-position-generic

2022-12-18 Thread Hans Goudey
Commit: 9cc4f430c938d7e69a0605bf4e5662346f3d203e
Author: Hans Goudey
Date:   Sun Dec 18 12:38:09 2022 -0600
Branches: refactor-mesh-position-generic
https://developer.blender.org/rB9cc4f430c938d7e69a0605bf4e5662346f3d203e

Merge branch 'master' into refactor-mesh-position-generic

===



===

diff --cc source/blender/blenkernel/BKE_mesh.h
index b5f3137ba1c,066d302fdd1..548ed122f3e
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@@ -617,15 -620,15 +617,15 @@@ void BKE_mesh_normals_loop_custom_set(c
struct MEdge *medges,
int numEdges,
const struct MLoop *mloops,
-   float (*r_custom_loopnors)[3],
+   float (*r_custom_loop_normals)[3],
int numLoops,
const struct MPoly *mpolys,
-   const float (*polynors)[3],
+   const float (*poly_normals)[3],
int numPolys,
short (*r_clnors_data)[2]);
 -void BKE_mesh_normals_loop_custom_from_verts_set(const struct MVert *mverts,
 +void BKE_mesh_normals_loop_custom_from_verts_set(const float (*positions)[3],
   const float 
(*vert_normals)[3],
-  float 
(*r_custom_vertnors)[3],
+  float 
(*r_custom_vert_normals)[3],
   int numVerts,
   struct MEdge *medges,
   int numEdges,
diff --cc source/blender/blenkernel/intern/mesh_iterators.cc
index 393ce479f8a,bc765c0ddd0..c89e0f41de1
--- a/source/blender/blenkernel/intern/mesh_iterators.cc
+++ b/source/blender/blenkernel/intern/mesh_iterators.cc
@@@ -185,12 -185,12 +185,12 @@@ void BKE_mesh_foreach_mapped_loop(Mesh 
  }
}
else {
- const float(*lnors)[3] = (flag & MESH_FOREACH_USE_NORMAL) ?
-  static_cast(
-  CustomData_get_layer(>ldata, 
CD_NORMAL)) :
-  nullptr;
+ const float(*loop_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ?
+ static_cast(
+ 
CustomData_get_layer(>ldata, CD_NORMAL)) :
+ nullptr;
  
 -const MVert *mv = BKE_mesh_verts(mesh);
 +const float(*positions)[3] = BKE_mesh_positions(mesh);
  const MLoop *ml = BKE_mesh_loops(mesh);
  const MPoly *mp = BKE_mesh_polys(mesh);
  const int *v_index = static_cast(
@@@ -217,8 -217,8 +217,8 @@@
  for (i = 0; i < mp->totloop; i++, ml++) {
const int v_idx = ml->v;
const int f_idx = p_idx;
-   const float *no = lnors ? *lnors++ : nullptr;
+   const float *no = loop_normals ? *loop_normals++ : nullptr;
 -  func(userData, v_idx, f_idx, mv[ml->v].co, no);
 +  func(userData, v_idx, f_idx, positions[ml->v], no);
  }
}
  }
diff --cc source/blender/blenkernel/intern/mesh_normals.cc
index d3f5012454b,3db34786661..99032e4ddf5
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@@ -945,11 -993,11 +945,11 @@@ static void split_loop_nor_single_do(Lo
MLoopNorSpaceArray *lnors_spacearr = common_data->lnors_spacearr;
const Span clnors_data = common_data->clnors_data;
  
 -  const Span verts = common_data->verts;
 +  const Span positions = common_data->positions;
const Span edges = common_data->edges;
const Span loops = common_data->loops;
-   const Span polynors = common_data->polynors;
-   MutableSpan loop_normals = common_data->loopnors;
+   const Span poly_normals = common_data->poly_normals;
+   MutableSpan loop_normals = common_data->loop_normals;
  
MLoopNorSpace *lnor_space = data->lnor_space;
const int ml_curr_index = data->ml_curr_index;
@@@ -1000,10 -1051,10 +1000,10 @@@ static void split_loop_nor_fan_do(LoopS
BLI_Stack *edge_vectors)
  {
MLoopNorSpaceArray *lnors_spacearr = common_data->lnors_spacearr;
-   MutableSpan loopnors = common_data->loopnors;
+   MutableSpan loop_normals = common_data->loop_normals;
MutableSpan clnors_data = common_data->clnors_data;
  
 -  const Span verts = common_data->verts;
 +  const Span positions = common_data->positions;
const Span edges = common_data->edges;
const Span polys = common_data->polys;
const Span loops 

[Bf-blender-cvs] [f0ac5e8aec0] master: Cleanup: Move context.c to C++

2022-12-18 Thread Hans Goudey
Commit: f0ac5e8aec03f7d0ca07d3792e50da929159478b
Author: Hans Goudey
Date:   Sun Dec 18 14:40:30 2022 -0600
Branches: master
https://developer.blender.org/rBf0ac5e8aec03f7d0ca07d3792e50da929159478b

Cleanup: Move context.c to C++

===

M   source/blender/blenkernel/BKE_context.h
M   source/blender/blenkernel/CMakeLists.txt
R075source/blender/blenkernel/intern/context.c  
source/blender/blenkernel/intern/context.cc
M   source/blender/python/BPY_extern.h

===

diff --git a/source/blender/blenkernel/BKE_context.h 
b/source/blender/blenkernel/BKE_context.h
index e1406e63ce1..90597a3e273 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -99,7 +99,7 @@ typedef struct bContextStore {
 } bContextStore;
 
 /* for the context's rna mode enum
- * keep aligned with data_mode_strings in context.c */
+ * keep aligned with data_mode_strings in context.cc */
 typedef enum eContextObjectMode {
   CTX_MODE_EDIT_MESH = 0,
   CTX_MODE_EDIT_CURVE,
diff --git a/source/blender/blenkernel/CMakeLists.txt 
b/source/blender/blenkernel/CMakeLists.txt
index d645408c6e9..c12c0c06ed8 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -97,7 +97,7 @@ set(SRC
   intern/colortools.c
   intern/compute_contexts.cc
   intern/constraint.c
-  intern/context.c
+  intern/context.cc
   intern/cpp_types.cc
   intern/crazyspace.cc
   intern/cryptomatte.cc
diff --git a/source/blender/blenkernel/intern/context.c 
b/source/blender/blenkernel/intern/context.cc
similarity index 75%
rename from source/blender/blenkernel/intern/context.c
rename to source/blender/blenkernel/intern/context.cc
index 0ddd53ccb99..4469f22346a 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.cc
@@ -4,9 +4,9 @@
  * \ingroup bke
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include "MEM_guardedalloc.h"
 
@@ -58,15 +58,15 @@ struct bContext {
 
   /* windowmanager context */
   struct {
-struct wmWindowManager *manager;
-struct wmWindow *window;
-struct WorkSpace *workspace;
-struct bScreen *screen;
-struct ScrArea *area;
-struct ARegion *region;
-struct ARegion *menu;
-struct wmGizmoGroup *gizmo_group;
-struct bContextStore *store;
+wmWindowManager *manager;
+wmWindow *window;
+WorkSpace *workspace;
+bScreen *screen;
+ScrArea *area;
+ARegion *region;
+ARegion *menu;
+wmGizmoGroup *gizmo_group;
+bContextStore *store;
 
 /* Operator poll. */
 /**
@@ -82,8 +82,8 @@ struct bContext {
 
   /* data context */
   struct {
-struct Main *main;
-struct Scene *scene;
+Main *main;
+Scene *scene;
 
 int recursion;
 /** True if python is initialized. */
@@ -101,14 +101,15 @@ struct bContext {
 
 bContext *CTX_create(void)
 {
-  bContext *C = MEM_callocN(sizeof(bContext), "bContext");
+  bContext *C = MEM_cnew(__func__);
 
   return C;
 }
 
 bContext *CTX_copy(const bContext *C)
 {
-  bContext *newC = MEM_dupallocN((void *)C);
+  bContext *newC = MEM_new(__func__);
+  *newC = *C;
 
   memset(>wm.operator_poll_msg_dyn_params, 0, 
sizeof(newC->wm.operator_poll_msg_dyn_params));
 
@@ -129,22 +130,23 @@ bContextStore *CTX_store_add(ListBase *contexts, const 
char *name, const Pointer
 {
   /* ensure we have a context to put the entry in, if it was already used
* we have to copy the context to ensure */
-  bContextStore *ctx = contexts->last;
+  bContextStore *ctx = static_cast(contexts->last);
 
   if (!ctx || ctx->used) {
 if (ctx) {
   bContextStore *lastctx = ctx;
-  ctx = MEM_dupallocN(lastctx);
+  ctx = MEM_new(__func__);
+  *ctx = *lastctx;
   BLI_duplicatelist(>entries, >entries);
 }
 else {
-  ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
+  ctx = MEM_cnew(__func__);
 }
 
 BLI_addtail(contexts, ctx);
   }
 
-  bContextStoreEntry *entry = MEM_callocN(sizeof(bContextStoreEntry), 
"bContextStoreEntry");
+  bContextStoreEntry *entry = MEM_cnew(__func__);
   BLI_strncpy(entry->name, name, sizeof(entry->name));
   entry->ptr = *ptr;
 
@@ -157,23 +159,25 @@ bContextStore *CTX_store_add_all(ListBase *contexts, 
bContextStore *context)
 {
   /* ensure we have a context to put the entries in, if it was already used
* we have to copy the context to ensure */
-  bContextStore *ctx = contexts->last;
+  bContextStore *ctx = static_cast(contexts->last);
 
   if (!ctx || ctx->used) {
 if (ctx) {
   bContextStore *lastctx = ctx;
-  ctx = MEM_dupallocN(lastctx);
+  ctx = MEM_new(__func__);
+  *ctx = *lastctx;
   BLI_duplicatelist(>entries, >entries);
 }
 else {
-  ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
+  ctx = MEM_cnew(__func__);
 }
 
 

[Bf-blender-cvs] [1eb90ee519c] master: UI: Use vector instead of linked list for block button groups

2022-12-18 Thread Hans Goudey
Commit: 1eb90ee519c4537be6ecd86b41cb5e7aa092581a
Author: Hans Goudey
Date:   Sun Dec 18 21:45:32 2022 -0600
Branches: master
https://developer.blender.org/rB1eb90ee519c4537be6ecd86b41cb5e7aa092581a

UI: Use vector instead of linked list for block button groups

This simplifies some memory management, ammortizes some of the many
small allocations when building UI layouts, and simplifies the code
that deals with the groups. `uiBlock` is no longer a trivial type.
In my testing this saved a few ms when drawing a large node tree.

===

M   source/blender/editors/interface/interface.cc
M   source/blender/editors/interface/interface_button_group.cc
M   source/blender/editors/interface/interface_intern.hh
M   source/blender/editors/interface/interface_layout.cc
M   source/blender/editors/interface/interface_panel.cc
M   source/blender/editors/interface/interface_template_search_menu.cc

===

diff --git a/source/blender/editors/interface/interface.cc 
b/source/blender/editors/interface/interface.cc
index c16c3068320..6728b1e3a41 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -3478,10 +3478,9 @@ void UI_block_free(const bContext *C, uiBlock *block)
   BLI_freelistN(>color_pickers.list);
   BLI_freelistN(>dynamic_listeners);
 
-  ui_block_free_button_groups(block);
   ui_block_free_views(block);
 
-  MEM_freeN(block);
+  MEM_delete(block);
 }
 
 void UI_block_listen(const uiBlock *block, const wmRegionListenerParams 
*listener_params)
@@ -3597,13 +3596,11 @@ uiBlock *UI_block_begin(const bContext *C, ARegion 
*region, const char *name, eU
   wmWindow *window = CTX_wm_window(C);
   Scene *scene = CTX_data_scene(C);
 
-  uiBlock *block = MEM_cnew(__func__);
+  uiBlock *block = MEM_new(__func__);
   block->active = true;
   block->emboss = emboss;
   block->evil_C = (void *)C; /* XXX */
 
-  BLI_listbase_clear(>button_groups);
-
   if (scene) {
 /* store display device name, don't lookup for transformations yet
  * block could be used for non-color displays where looking up for 
transformation
@@ -4058,7 +4055,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
   ui_but_alloc_info(new_type, _size, _str, _has_custom_type);
 
   if (new_has_custom_type || old_has_custom_type) {
-const void *old_but_ptr = but;
+const uiBut *old_but_ptr = but;
 /* Button may have pointer to a member within itself, this will have to be 
updated. */
 const bool has_str_ptr_to_self = but->str == but->strdata;
 const bool has_poin_ptr_to_self = but->poin == (char *)but;
@@ -4082,7 +4079,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
 }
 #ifdef WITH_PYTHON
 if (UI_editsource_enable_check()) {
-  UI_editsource_but_replace(static_cast(old_but_ptr), but);
+  UI_editsource_but_replace(old_but_ptr, but);
 }
 #endif
   }
diff --git a/source/blender/editors/interface/interface_button_group.cc 
b/source/blender/editors/interface/interface_button_group.cc
index ed9065423e4..371cfda47df 100644
--- a/source/blender/editors/interface/interface_button_group.cc
+++ b/source/blender/editors/interface/interface_button_group.cc
@@ -17,54 +17,35 @@
 void ui_block_new_button_group(uiBlock *block, uiButtonGroupFlag flag)
 {
   /* Don't create a new group if there is a "lock" on new groups. */
-  if (!BLI_listbase_is_empty(>button_groups)) {
-uiButtonGroup *last_button_group = static_cast(block->button_groups.last);
-if (last_button_group->flag & UI_BUTTON_GROUP_LOCK) {
+  if (!block->button_groups.is_empty()) {
+uiButtonGroup _group = block->button_groups.last();
+if (last_group.flag & UI_BUTTON_GROUP_LOCK) {
   return;
 }
   }
 
-  uiButtonGroup *new_group = MEM_cnew(__func__);
-  new_group->flag = flag;
-  BLI_addtail(>button_groups, new_group);
+  block->button_groups.append({});
+  block->button_groups.last().flag = flag;
 }
 
 void ui_button_group_add_but(uiBlock *block, uiBut *but)
 {
-  if (BLI_listbase_is_empty(>button_groups)) {
+  if (block->button_groups.is_empty()) {
 ui_block_new_button_group(block, uiButtonGroupFlag(0));
   }
 
-  uiButtonGroup *current_button_group = static_cast(block->button_groups.last);
-
-  /* We can't use the button directly because adding it to
-   * this list would mess with its `prev` and `next` pointers. */
-  LinkData *button_link = BLI_genericNodeN(but);
-  BLI_addtail(_button_group->buttons, button_link);
+  uiButtonGroup _group = block->button_groups.last();
+  current_group.buttons.append(but);
 }
 
-static void button_group_free(uiButtonGroup *button_group)
+void ui_button_group_replace_but_ptr(uiBlock *block, const uiBut *old_but_ptr, 
uiBut *new_but)
 {
-  BLI_freelistN(_group->buttons);
-  MEM_freeN(button_group);
-}
-
-void ui_block_free_button_groups(uiBlock *block)
-{
-  LISTBASE_FOREACH_MUTABLE 

[Bf-blender-cvs] [7d7e90ca685] master: UI: Use vector instead of linked lists for context store

2022-12-18 Thread Hans Goudey
Commit: 7d7e90ca685954409ece007d03d2e93860a6cef7
Author: Hans Goudey
Date:   Sun Dec 18 19:13:15 2022 -0600
Branches: master
https://developer.blender.org/rB7d7e90ca685954409ece007d03d2e93860a6cef7

UI: Use vector instead of linked lists for context store

Duplicating context lists took a measurable amount of time when drawing
large node trees in the node editor. Instead of using a linked list of
entries, which results in many small allocations, use a vector. Also,
use std::string and StringRefNull instead of char buffers and pointers.

===

M   source/blender/blenkernel/BKE_context.h
M   source/blender/blenkernel/intern/context.cc
M   source/blender/editors/interface/interface.cc

===

diff --git a/source/blender/blenkernel/BKE_context.h 
b/source/blender/blenkernel/BKE_context.h
index 90597a3e273..f836b98f3b2 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -16,6 +16,11 @@
 #include "DNA_object_enums.h"
 #include "RNA_types.h"
 
+#ifdef __cplusplus
+#  include "BLI_string_ref.hh"
+#  include "BLI_vector.hh"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -84,19 +89,22 @@ typedef int /*eContextResult*/ 
(*bContextDataCallback)(const bContext *C,
const char *member,
bContextDataResult 
*result);
 
-typedef struct bContextStoreEntry {
-  struct bContextStoreEntry *next, *prev;
+#ifdef __cplusplus
 
-  char name[128];
+struct bContextStoreEntry {
+  std::string name;
   PointerRNA ptr;
-} bContextStoreEntry;
+};
+
+struct bContextStore {
+  bContextStore *next = nullptr;
+  bContextStore *prev = nullptr;
 
-typedef struct bContextStore {
-  struct bContextStore *next, *prev;
+  blender::Vector entries;
+  bool used = false;
+};
 
-  ListBase entries;
-  bool used;
-} bContextStore;
+#endif
 
 /* for the context's rna mode enum
  * keep aligned with data_mode_strings in context.cc */
@@ -132,18 +140,23 @@ void CTX_free(bContext *C);
 
 bContext *CTX_copy(const bContext *C);
 
+#ifdef __cplusplus
+
 /* Stored Context */
 
-bContextStore *CTX_store_add(ListBase *contexts, const char *name, const 
PointerRNA *ptr);
+bContextStore *CTX_store_add(ListBase *contexts,
+ blender::StringRefNull name,
+ const PointerRNA *ptr);
 bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context);
 bContextStore *CTX_store_get(bContext *C);
 void CTX_store_set(bContext *C, bContextStore *store);
 const PointerRNA *CTX_store_ptr_lookup(const bContextStore *store,
-   const char *name,
-   const StructRNA *type 
CPP_ARG_DEFAULT(nullptr));
-bContextStore *CTX_store_copy(bContextStore *store);
+   blender::StringRefNull name,
+   const StructRNA *type = nullptr);
+bContextStore *CTX_store_copy(const bContextStore *store);
 void CTX_store_free(bContextStore *store);
-void CTX_store_free_list(ListBase *contexts);
+
+#endif
 
 /* need to store if python is initialized or not */
 bool CTX_py_init_get(bContext *C);
diff --git a/source/blender/blenkernel/intern/context.cc 
b/source/blender/blenkernel/intern/context.cc
index 4469f22346a..8d8e96f26c8 100644
--- a/source/blender/blenkernel/intern/context.cc
+++ b/source/blender/blenkernel/intern/context.cc
@@ -126,7 +126,9 @@ void CTX_free(bContext *C)
 
 /* store */
 
-bContextStore *CTX_store_add(ListBase *contexts, const char *name, const 
PointerRNA *ptr)
+bContextStore *CTX_store_add(ListBase *contexts,
+ const blender::StringRefNull name,
+ const PointerRNA *ptr)
 {
   /* ensure we have a context to put the entry in, if it was already used
* we have to copy the context to ensure */
@@ -134,23 +136,16 @@ bContextStore *CTX_store_add(ListBase *contexts, const 
char *name, const Pointer
 
   if (!ctx || ctx->used) {
 if (ctx) {
-  bContextStore *lastctx = ctx;
-  ctx = MEM_new(__func__);
-  *ctx = *lastctx;
-  BLI_duplicatelist(>entries, >entries);
+  ctx = MEM_new(__func__, *ctx);
 }
 else {
-  ctx = MEM_cnew(__func__);
+  ctx = MEM_new(__func__);
 }
 
 BLI_addtail(contexts, ctx);
   }
 
-  bContextStoreEntry *entry = MEM_cnew(__func__);
-  BLI_strncpy(entry->name, name, sizeof(entry->name));
-  entry->ptr = *ptr;
-
-  BLI_addtail(>entries, entry);
+  ctx->entries.append(bContextStoreEntry{name, *ptr});
 
   return ctx;
 }
@@ -163,22 +158,17 @@ bContextStore *CTX_store_add_all(ListBase *contexts, 
bContextStore *context)
 
   if (!ctx || ctx->used) {
 if (ctx) {
-  bContextStore *lastctx = ctx;
-  ctx = MEM_new(__func__);
-  *ctx = *lastctx;
-

[Bf-blender-cvs] [d59f6ffdcb4] master: Fix: Wrong const iterator type for blender::Vector

2022-12-18 Thread Hans Goudey
Commit: d59f6ffdcb4a008e5d3a8a2638fea40cf19912a0
Author: Hans Goudey
Date:   Sun Dec 18 18:35:40 2022 -0600
Branches: master
https://developer.blender.org/rBd59f6ffdcb4a008e5d3a8a2638fea40cf19912a0

Fix: Wrong const iterator type for blender::Vector

===

M   source/blender/blenlib/BLI_vector.hh

===

diff --git a/source/blender/blenlib/BLI_vector.hh 
b/source/blender/blenlib/BLI_vector.hh
index be594377eb3..8860bb05127 100644
--- a/source/blender/blenlib/BLI_vector.hh
+++ b/source/blender/blenlib/BLI_vector.hh
@@ -902,11 +902,11 @@ class Vector {
 
   std::reverse_iterator rbegin() const
   {
-return std::reverse_iterator(this->end());
+return std::reverse_iterator(this->end());
   }
   std::reverse_iterator rend() const
   {
-return std::reverse_iterator(this->begin());
+return std::reverse_iterator(this->begin());
   }
 
   /**

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [50c7eb14f45] master: Fix T103321: NodeSocket.node is None in Node.copy callback

2022-12-18 Thread Hans Goudey
Commit: 50c7eb14f455de9f932028861899d5d6b6f20527
Author: Hans Goudey
Date:   Sun Dec 18 14:06:43 2022 -0600
Branches: master
https://developer.blender.org/rB50c7eb14f455de9f932028861899d5d6b6f20527

Fix T103321: NodeSocket.node is None in Node.copy callback

Tag the topology cache dirty before Python can do arbitrary things
in the RNA copy callback.

===

M   source/blender/blenkernel/intern/node.cc

===

diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index 9bc42879d78..84bf186367b 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -2326,6 +2326,10 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree,
 node_src.typeinfo->copyfunc(dst_tree, node_dst, _src);
   }
 
+  if (dst_tree) {
+BKE_ntree_update_tag_node_new(dst_tree, node_dst);
+  }
+
   /* Only call copy function when a copy is made for the main database, not
* for cases like the dependency graph and localization. */
   if (node_dst->typeinfo->copyfunc_api && !(flag & LIB_ID_CREATE_NO_MAIN)) {
@@ -2335,10 +2339,6 @@ bNode *node_copy_with_mapping(bNodeTree *dst_tree,
 node_dst->typeinfo->copyfunc_api(, _src);
   }
 
-  if (dst_tree) {
-BKE_ntree_update_tag_node_new(dst_tree, node_dst);
-  }
-
   /* Reset the declaration of the new node. */
   nodeDeclarationEnsure(dst_tree, node_dst);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8666791b2e7] master: Fix T103261: Undo after mask extract doesn't restore active object

2022-12-18 Thread Joseph Eagar
Commit: 8666791b2e7542913e824a34eed2e579381377b0
Author: Joseph Eagar
Date:   Sun Dec 18 07:50:35 2022 -0800
Branches: master
https://developer.blender.org/rB8666791b2e7542913e824a34eed2e579381377b0

Fix T103261: Undo after mask extract doesn't restore active object

===

M   source/blender/editors/mesh/editmesh_mask_extract.c

===

diff --git a/source/blender/editors/mesh/editmesh_mask_extract.c 
b/source/blender/editors/mesh/editmesh_mask_extract.c
index 070f748c78e..bb4d745a677 100644
--- a/source/blender/editors/mesh/editmesh_mask_extract.c
+++ b/source/blender/editors/mesh/editmesh_mask_extract.c
@@ -37,6 +37,7 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_sculpt.h"
+#include "ED_undo.h"
 #include "ED_view3d.h"
 
 #include "bmesh_tools.h"
@@ -287,6 +288,16 @@ static int paint_mask_extract_exec(bContext *C, wmOperator 
*op)
   params.add_boundary_loop = RNA_boolean_get(op->ptr, "add_boundary_loop");
   params.apply_shrinkwrap = RNA_boolean_get(op->ptr, "apply_shrinkwrap");
   params.add_solidify = RNA_boolean_get(op->ptr, "add_solidify");
+
+  /* Push an undo step prior to extraction.
+   * Note: A second push happens after the operator due to
+   * the OPTYPE_UNDO flag; having an initial undo step here
+   * is just needed to preserve the active object pointer.
+   * 
+   * Fixes T103261.
+   */
+  ED_undo_push_op(C, op);
+
   return geometry_extract_apply(C, op, geometry_extract_tag_masked_faces, 
);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [17e266cd55e] master: Cleanup: make paint_init_pivot an api method.

2022-12-18 Thread Joseph Eagar
Commit: 17e266cd55ea58bd82094c3874254748a6d199be
Author: Joseph Eagar
Date:   Sun Dec 18 07:20:12 2022 -0800
Branches: master
https://developer.blender.org/rB17e266cd55ea58bd82094c3874254748a6d199be

Cleanup: make paint_init_pivot an api method.

I had forgotten about curves sculpt mode when I wrote
this function. It just initializes the viewport
pivot point to the evaluated object bounding box.
Should be used inside the mode entry function.

===

M   source/blender/editors/sculpt_paint/paint_image.cc
M   source/blender/editors/sculpt_paint/paint_intern.h

===

diff --git a/source/blender/editors/sculpt_paint/paint_image.cc 
b/source/blender/editors/sculpt_paint/paint_image.cc
index 1ab364c4877..a57287b924b 100644
--- a/source/blender/editors/sculpt_paint/paint_image.cc
+++ b/source/blender/editors/sculpt_paint/paint_image.cc
@@ -759,7 +759,7 @@ void PAINT_OT_sample_color(wmOperatorType *ot)
 
 / texture paint toggle operator /
 
-static void paint_init_pivot(Object *ob, Scene *scene)
+void paint_init_pivot(Object *ob, Scene *scene)
 {
   UnifiedPaintSettings *ups = >toolsettings->unified_paint_settings;
 
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h 
b/source/blender/editors/sculpt_paint/paint_intern.h
index 8a2c6955679..a3449e52225 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -517,6 +517,9 @@ enum eBlurKernelType;
 BlurKernel *paint_new_blur_kernel(struct Brush *br, bool proj);
 void paint_delete_blur_kernel(BlurKernel *);
 
+/* Initialize viewport pivot from evaulated bounding box center of ob. */
+void paint_init_pivot(struct Object *ob, struct Scene *scene);
+
 /* paint curve defines */
 #define PAINT_CURVE_NUM_SEGMENTS 40

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0beb358a69d] master: Fix T103198: Missing bounds check for material_index attr in texpaint

2022-12-18 Thread Joseph Eagar
Commit: 0beb358a69d0c9c5436995c2945eadbae95e8965
Author: Joseph Eagar
Date:   Sun Dec 18 07:08:57 2022 -0800
Branches: master
https://developer.blender.org/rB0beb358a69d0c9c5436995c2945eadbae95e8965

Fix T103198: Missing bounds check for material_index attr in texpaint

Texpaint now bounds checks material indices when looking up
materials, in case the user has corrupted the material_index
attribute somehow.  We may wish to report this to the user
somehow on entering texture paint mode.

===

M   source/blender/editors/sculpt_paint/paint_image_proj.cc

===

diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc 
b/source/blender/editors/sculpt_paint/paint_image_proj.cc
index 4eeeb760b23..7c7e9fc 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc
@@ -545,10 +545,20 @@ static int project_paint_face_paint_tile(Image *ima, 
const float *uv)
   return 1001 + 10 * ty + tx;
 }
 
+static Material *tex_get_material(const ProjPaintState *ps, int poly_i)
+{
+  int mat_nr = ps->material_indices == nullptr ? 0 : 
ps->material_indices[poly_i];
+  if (mat_nr >= 0 && mat_nr <= ps->ob->totcol) {
+return ps->mat_array[mat_nr];
+  }
+
+  return nullptr;
+}
+
 static TexPaintSlot *project_paint_face_paint_slot(const ProjPaintState *ps, 
int tri_index)
 {
   const int poly_i = ps->mlooptri_eval[tri_index].poly;
-  Material *ma = ps->mat_array[ps->material_indices == nullptr ? 0 : 
ps->material_indices[poly_i]];
+  Material *ma = tex_get_material(ps, poly_i);
   return ma ? ma->texpaintslot + ma->paint_active_slot : nullptr;
 }
 
@@ -559,7 +569,7 @@ static Image *project_paint_face_paint_image(const 
ProjPaintState *ps, int tri_i
   }
 
   const int poly_i = ps->mlooptri_eval[tri_index].poly;
-  Material *ma = ps->mat_array[ps->material_indices == nullptr ? 0 : 
ps->material_indices[poly_i]];
+  Material *ma = tex_get_material(ps, poly_i);
   TexPaintSlot *slot = ma ? ma->texpaintslot + ma->paint_active_slot : nullptr;
   return slot ? slot->ima : ps->canvas_ima;
 }
@@ -567,14 +577,14 @@ static Image *project_paint_face_paint_image(const 
ProjPaintState *ps, int tri_i
 static TexPaintSlot *project_paint_face_clone_slot(const ProjPaintState *ps, 
int tri_index)
 {
   const int poly_i = ps->mlooptri_eval[tri_index].poly;
-  Material *ma = ps->mat_array[ps->material_indices == nullptr ? 0 : 
ps->material_indices[poly_i]];
+  Material *ma = tex_get_material(ps, poly_i);
   return ma ? ma->texpaintslot + ma->paint_clone_slot : nullptr;
 }
 
 static Image *project_paint_face_clone_image(const ProjPaintState *ps, int 
tri_index)
 {
   const int poly_i = ps->mlooptri_eval[tri_index].poly;
-  Material *ma = ps->mat_array[ps->material_indices == nullptr ? 0 : 
ps->material_indices[poly_i]];
+  Material *ma = tex_get_material(ps, poly_i);
   TexPaintSlot *slot = ma ? ma->texpaintslot + ma->paint_clone_slot : nullptr;
   return slot ? slot->ima : ps->clone_ima;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d15324f1c38] temp-sculpt-roll-mapping: temp-sculpt-roll-mapping: update more comments

2022-12-18 Thread Joseph Eagar
Commit: d15324f1c38f10945214bdd29d3b3e167ff8a699
Author: Joseph Eagar
Date:   Sun Dec 18 05:45:37 2022 -0800
Branches: temp-sculpt-roll-mapping
https://developer.blender.org/rBd15324f1c38f10945214bdd29d3b3e167ff8a699

temp-sculpt-roll-mapping: update more comments

===

M   source/blender/blenlib/BLI_even_spline.hh
M   source/blender/editors/sculpt_paint/paint_stroke.cc
M   source/tools

===

diff --git a/source/blender/blenlib/BLI_even_spline.hh 
b/source/blender/blenlib/BLI_even_spline.hh
index 5ac4bda019c..dea44756ca4 100644
--- a/source/blender/blenlib/BLI_even_spline.hh
+++ b/source/blender/blenlib/BLI_even_spline.hh
@@ -55,26 +55,6 @@ namespace blender {
 
 /** Cubic curves */
 
-/*
-comment: Reduce algebra script;
-
-comment: Build bernstein polynomials from linear combination;
-procedure bez(a, b);
-  a + (b - a) * t;
-
-lin := bez(k1, k2);
-quad := bez(lin, sub(k2=k3, k1=k2, lin));
-cubic := bez(quad, sub(k3=k4, k2=k3, k1=k2, quad));
-
-dcubic := df(cubic, t);
-
-comment: display final equations in fortran;
-on fort;
-cubic;
-dcubic;
-off fort;
-
-*/
 template class CubicBezier 
{
   using Vector = vec_base;
 
@@ -166,6 +146,7 @@ template class CubicBezier {
 
   Float length;
 
+  /* Update arc length -> parameterization table. */
   void update()
   {
 Float t = 0.0, dt = 1.0 / (Float)table_size;
@@ -272,6 +253,7 @@ template class CubicBezier {
 if (exact) {
   Float len = sqrt(_dot(r, r));
 
+  /* Use FLT_EPSILON here? */
   if (len > 0.1) {
 r = r / len;
   }
@@ -312,6 +294,7 @@ template class CubicBezier {
 comment: arc length second derivative;
 
 comment: build arc length from abstract derivative operators;
+
 operator x, y, z, dx, dy, dz, d2x, d2y, d2z;
 
 forall t let df(x(t), t) = dx(t);
@@ -380,6 +363,7 @@ template class CubicBezier {
 return sqrt(_dot(dv2, dv2));
   }
 
+  /* First derivative of curvature. */
   Float dcurvature(Float s)
   {
 const Float ds = 0.0001;
@@ -404,23 +388,27 @@ template class CubicBezier {
   Float *_arc_to_t;
   bool deleted = false;
 
+  /* Bernstein/bezier polynomial.*/
   Float cubic(Float k1, Float k2, Float k3, Float k4, Float t)
   {
 return -(((3.0 * (t - 1.0) * k3 - k4 * t) * t - 3.0 * (t - 1.0) * (t - 
1.0) * k2) * t +
  (t - 1) * (t - 1) * (t - 1) * k1);
   }
 
+  /* First derivative. */
   Float dcubic(Float k1, Float k2, Float k3, Float k4, Float t)
   {
 return -3.0 * ((t - 1.0) * (t - 1.0) * k1 - k4 * t * t + (3.0 * t - 2.0) * 
k3 * t -
(3.0 * t - 1.0) * (t - 1.0) * k2);
   }
 
+  /* Second derivative. */
   Float d2cubic(Float k1, Float k2, Float k3, Float k4, Float t)
   {
 return -6.0 * (k1 * t - k1 - 3.0 * k2 * t + 2.0 * k2 + 3.0 * k3 * t - k3 - 
k4 * t);
   }
 
+  /* Inlinable dot product. */
   Float _dot(Vector a, Vector b)
   {
 Float sum = 0.0;
@@ -440,6 +428,9 @@ template class CubicBezier {
 return s;
   }
 
+  /* Convert a unit distance along the curve to parameterization t
+   * using a linearly-interpolated lookup table.
+   */
   Float arc_to_t(Float s)
   {
 if (length == 0.0) {
@@ -537,6 +528,9 @@ class EvenSpline {
 update_inflection_points();
   }
 
+  /* Find inflection points, these are used to speed
+   * up closest point test.
+   */
   void update_inflection_points()
   {
 inflection_points.clear();
@@ -562,7 +556,8 @@ class EvenSpline {
 inflection_points.append(1.0);
   }
 
-  int components() noexcept
+  /* Number of control points inside a curve segment. */
+  int order() noexcept
   {
 return sizeof(segments[0].bezier.ps) / sizeof(*segments[0].bezier.ps);
   }
@@ -574,7 +569,7 @@ class EvenSpline {
 }
 
 if (s >= length) {
-  return segments[segments.size() - 1].bezier.ps[components() - 1];
+  return segments[segments.size() - 1].bezier.ps[order() - 1];
 }
 
 Segment *seg = get_segment(s);
@@ -594,6 +589,7 @@ class EvenSpline {
 return seg->bezier.derivative(s - seg->start, exact);
   }
 
+  /* Second derivative. */
   Vector derivative2(Float s)
   {
 if (segments.size() == 0) {
@@ -618,6 +614,7 @@ class EvenSpline {
 return seg->bezier.curvature(s - seg->start);
   }
 
+  /* First derivative of curvature. */
   Float dcurvature(Float s)
   {
 if (segments.size() == 0) {
@@ -630,7 +627,8 @@ class EvenSpline {
 return seg->bezier.dcurvature(s - seg->start);
   }
 
-  /* Find the closest point on the spline.  Uses a bisecting root finding 
approach..
+  /* Find the closest point on the spline.  Uses a bisecting root
+   * finding approach.
*/
   Vector closest_point(const Vector p, Float _s, Vector _tan, Float _dis)
   {
@@ -652,10 +650,10 @@ class EvenSpline {
 
   b = evaluate(s);
 
-  /* The extra false parameter means we don't
-   * need fully normalized derivative.
+  /* The 

[Bf-blender-cvs] [e9b573e11db] temp-sculpt-roll-mapping: temp-sculpt-roll-mapping: Cleanup some comments

2022-12-18 Thread Joseph Eagar
Commit: e9b573e11dbc349bd3b58bd6b800f8b6adaca866
Author: Joseph Eagar
Date:   Sat Dec 17 20:58:10 2022 -0800
Branches: temp-sculpt-roll-mapping
https://developer.blender.org/rBe9b573e11dbc349bd3b58bd6b800f8b6adaca866

temp-sculpt-roll-mapping: Cleanup some comments

===

M   source/blender/blenlib/BLI_even_spline.hh

===

diff --git a/source/blender/blenlib/BLI_even_spline.hh 
b/source/blender/blenlib/BLI_even_spline.hh
index 4b98d51db37..5ac4bda019c 100644
--- a/source/blender/blenlib/BLI_even_spline.hh
+++ b/source/blender/blenlib/BLI_even_spline.hh
@@ -58,9 +58,7 @@ namespace blender {
 /*
 comment: Reduce algebra script;
 
-on factor;
-off period;
-
+comment: Build bernstein polynomials from linear combination;
 procedure bez(a, b);
   a + (b - a) * t;
 
@@ -70,6 +68,7 @@ cubic := bez(quad, sub(k3=k4, k2=k3, k1=k2, quad));
 
 dcubic := df(cubic, t);
 
+comment: display final equations in fortran;
 on fort;
 cubic;
 dcubic;
@@ -140,7 +139,6 @@ template class CubicBezier {
 return *this;
   }
 
-#if 1
   CubicBezier(CubicBezier &)
   {
 *this = b;
@@ -165,7 +163,6 @@ template class CubicBezier {
 
 return *this;
   }
-#endif
 
   Float length;
 
@@ -311,11 +308,12 @@ template class CubicBezier {
 Float dy = dcubic(ps[0][1], ps[1][1], ps[2][1], ps[3][1], t);
 Float d2y = d2cubic(ps[0][1], ps[1][1], ps[2][1], ps[3][1], t);
 
-/*
+/* reduce algebra script
 comment: arc length second derivative;
 
-comment: build arc length version from abstract derivative operators;
+comment: build arc length from abstract derivative operators;
 operator x, y, z, dx, dy, dz, d2x, d2y, d2z;
+
 forall t let df(x(t), t) = dx(t);
 forall t let df(y(t), t) = dy(t);
 forall t let df(z(t), t) = dz(t);
@@ -328,6 +326,7 @@ template class CubicBezier {
 comment: 2d case;
 dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2);
 
+comment: final derivatives;
 df(df(x(t), t) / dlen, t);
 df(df(y(t), t) / dlen, t);
 
@@ -335,15 +334,13 @@ template class CubicBezier {
 dlen := sqrt(df(x(t), t)**2 + df(y(t), t)**2 + df(z(t), t)**2);
 
 comment: final derivatives;
-
 df(df(x(t), t) / dlen, t);
 df(df(y(t), t) / dlen, t);
 df(df(z(t), t) / dlen, t);
-
 */
+
 if constexpr (axes == 2) {
   /* Basically the 2d perpidicular normalized tangent multiplied by the 
curvature. */
-
   Float div = sqrt(dx * dx + dy * dy) * (dx * dx + dy * dy);
 
   r[0] = ((d2x * dy - d2y * dx) * dy) / div;
@@ -633,9 +630,7 @@ class EvenSpline {
 return seg->bezier.dcurvature(s - seg->start);
   }
 
-  /* Find the closest point on the spline.  Uses a bisecting root finding 
approach.
-   * Note: in thoery we could split the spline into quadratic segments and 
solve
-   * for the closest point directy.
+  /* Find the closest point on the spline.  Uses a bisecting root finding 
approach..
*/
   Vector closest_point(const Vector p, Float _s, Vector _tan, Float _dis)
   {
@@ -656,7 +651,11 @@ class EvenSpline {
   Float ds = s - inflection_points[i - 1];
 
   b = evaluate(s);
-  dvb = derivative(s, false); /* False means we don't need fully 
normalized derivative. */
+
+  /* The extra false parameter means we don't
+   * need fully normalized derivative.
+   */
+  dvb = derivative(s, false); 
 
   if (i == 0) {
 continue;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [90b633967b7] temp-sculpt-roll-mapping: Merge remote-tracking branch 'origin' into temp-sculpt-roll-mapping

2022-12-18 Thread Joseph Eagar
Commit: 90b633967b726d940935ea9577299daf1a4882d9
Author: Joseph Eagar
Date:   Sat Dec 17 20:58:31 2022 -0800
Branches: temp-sculpt-roll-mapping
https://developer.blender.org/rB90b633967b726d940935ea9577299daf1a4882d9

Merge remote-tracking branch 'origin' into temp-sculpt-roll-mapping

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a3020fe2c26] gpencil-new-data-proposal: Merge branch 'master' into gpencil-new-data-proposal

2022-12-18 Thread Falk David
Commit: a3020fe2c2618c71eb95f54fc4115b85800aa672
Author: Falk David
Date:   Sun Dec 18 13:17:19 2022 +0100
Branches: gpencil-new-data-proposal
https://developer.blender.org/rBa3020fe2c2618c71eb95f54fc4115b85800aa672

Merge branch 'master' into gpencil-new-data-proposal

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs