[Bf-blender-cvs] [c71027705c3] temp-T96709-painting-target: Show Canvas selector only when experimental flag is enabled.

2022-04-07 Thread Jeroen Bakker
Commit: c71027705c37a31ccb41ae3910008497cd419798
Author: Jeroen Bakker
Date:   Fri Apr 8 08:15:02 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rBc71027705c37a31ccb41ae3910008497cd419798

Show Canvas selector only when experimental flag is enabled.

===

M   release/scripts/startup/bl_ui/space_view3d_toolbar.py
M   source/blender/blenkernel/intern/material.c
M   source/blender/editors/sculpt_paint/paint_canvas.cc
M   source/blender/makesrna/intern/rna_sculpt_paint.c

===

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 6eb85bf76cb..332933be68a 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -570,6 +570,9 @@ class VIEW3D_PT_slots_paint_canvas(SelectPaintSlotHelper, 
View3DPanel, Panel):
 
 @classmethod
 def poll(cls, context):
+if not context.preferences.experimental.use_sculpt_texture_paint:
+return False
+
 from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
 tool = ToolSelectPanelHelper.tool_active_from_context(context)
 if tool is None:
@@ -578,6 +581,7 @@ class VIEW3D_PT_slots_paint_canvas(SelectPaintSlotHelper, 
View3DPanel, Panel):
 
 def get_mode_settings(self, context):
 return context.tool_settings.paint_mode
+
 def draw_image_interpolation(self, **kwargs):
 pass
 
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 07f158d7787..bc569956f66 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1477,13 +1477,9 @@ static void fill_texpaint_slots_recursive(bNodeTree 
*nodetree,
 /** Check which type of paint slots should be filled for the given object. */
 static ePaintSlotFilter material_paint_slot_filter(const struct Object *ob)
 {
-  ePaintSlotFilter slot_filter = 0;
-  if (ob->mode == OB_MODE_SCULPT) {
-slot_filter = PAINT_SLOT_COLOR_ATTRIBUTE;
-SET_FLAG_FROM_TEST(slot_filter, U.experimental.use_sculpt_texture_paint, 
PAINT_SLOT_IMAGE);
-  }
-  else if (ob->mode == OB_MODE_TEXTURE_PAINT) {
-slot_filter = PAINT_SLOT_IMAGE;
+  ePaintSlotFilter slot_filter = PAINT_SLOT_IMAGE;
+  if (ob->mode == OB_MODE_SCULPT && U.experimental.use_sculpt_texture_paint) {
+slot_filter |= PAINT_SLOT_COLOR_ATTRIBUTE;
   }
   return slot_filter;
 }
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc 
b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 25089387b3d..9a1a61cf3ab 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -105,6 +105,9 @@ eV3DShadingColorType 
ED_paint_shading_color_override(bContext *C,
  Object *ob,
  eV3DShadingColorType 
orig_color_type)
 {
+  if (!U.experimental.use_sculpt_texture_paint) {
+return orig_color_type;
+  }
   /* NOTE: This early exit is temporarily, until a paint mode has been added.
* For better integration with the vertex paint in sculpt mode we sticky
* with the last stoke when using tools like masking.
@@ -140,11 +143,6 @@ eV3DShadingColorType 
ED_paint_shading_color_override(bContext *C,
 }
   }
 
-  /* Reset to original color based on enabled experimental features */
-  if (!U.experimental.use_sculpt_texture_paint && color_type == 
V3D_SHADING_TEXTURE_COLOR) {
-return orig_color_type;
-  }
-
   return color_type;
 }
 
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c 
b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 234d21e2ece..37c687ddb2b 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -558,38 +558,6 @@ static bool 
rna_PaintModeSettings_canvas_image_poll(PointerRNA *UNUSED(ptr), Poi
   return !ELEM(image->type, IMA_TYPE_COMPOSITE, IMA_TYPE_R_RESULT);
 }
 
-static int rna_PaintModeSettings_canvas_source_get(PointerRNA *ptr)
-{
-  PaintModeSettings *settings = ptr->data;
-  if (!U.experimental.use_sculpt_texture_paint &&
-  settings->canvas_source == PAINT_CANVAS_SOURCE_IMAGE) {
-return PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE;
-  }
-
-  return settings->canvas_source;
-}
-
-static const EnumPropertyItem 
*rna_PaintModeSettings_canvas_source_itemf(bContext *UNUSED(C),
- 
PointerRNA *UNUSED(ptr),
- 
PropertyRNA *UNUSED(prop),
- bool 
*r_free)
-{
-  EnumPropertyItem *items = NULL;
-  int totitem = 0;
-

[Bf-blender-cvs] [d466b0378a3] temp-T96709-painting-target: Revert removal of force shading color to vertex colors.

2022-04-07 Thread Jeroen Bakker
Commit: d466b0378a3c6deb04955ea286e9a8c245e243b5
Author: Jeroen Bakker
Date:   Fri Apr 8 08:19:15 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rBd466b0378a3c6deb04955ea286e9a8c245e243b5

Revert removal of force shading color to vertex colors.

===

M   source/blender/editors/sculpt_paint/sculpt.c

===

diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index b4f731402cb..24c5a9fce52 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5192,6 +5192,16 @@ static bool sculpt_stroke_test_start(bContext *C, struct 
wmOperator *op, const f
 Object *ob = CTX_data_active_object(C);
 SculptSession *ss = ob->sculpt;
 Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+Brush *brush = BKE_paint_brush(&sd->paint);
+
+/* NOTE: This should be removed when paint mode is available. Paint mode 
can force based on the
+ * canvas it is painting on. (ref. use_sculpt_texture_paint). */
+if (brush && SCULPT_TOOL_NEEDS_COLOR(brush->sculpt_tool)) {
+  View3D *v3d = CTX_wm_view3d(C);
+  if (v3d) {
+v3d->shading.color_type = V3D_SHADING_VERTEX_COLOR;
+  }
+}
 
 ED_view3d_init_mats_rv3d(ob, CTX_wm_region_view3d(C));

___
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] [15aea1bb227] temp-T96709-painting-target: Merge remote-tracking branch 'origin/master' into temp-T96709-painting-target

2022-04-07 Thread Jeroen Bakker
Commit: 15aea1bb22725be7ea450ff25a0245bf87bf7db0
Author: Jeroen Bakker
Date:   Fri Apr 8 07:59:39 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rB15aea1bb22725be7ea450ff25a0245bf87bf7db0

Merge remote-tracking branch 'origin/master' into temp-T96709-painting-target

===



===

diff --cc release/scripts/startup/bl_ui/properties_data_mesh.py
index 4809060fad3,97519e55b48..1bfd82cc790
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@@ -545,35 -544,28 +544,28 @@@ class DATA_PT_mesh_attributes(MeshButto
  ob = context.object
  mesh = ob.data
  
- builtin_attribute = object()
- 
- def add_builtin(name):
- attributes_by_name[name].append(builtin_attribute)
- 
- def add_attributes(layers):
- for layer in layers:
- attributes_by_name[layer.name].append(layer)
- 
- add_builtin("position")
- add_builtin("material_index")
- add_builtin("shade_smooth")
- add_builtin("normal")
- add_builtin("crease")
- 
- add_attributes(mesh.attributes)
- add_attributes(mesh.uv_layers)
- add_attributes(ob.vertex_groups)
+ unique_names = set()
+ colliding_names = []
+ for collection in (
+ # Built-in names.
+ {"position": None, "material_index": None, "shade_smooth": 
None, "normal": None, "crease": None},
+ mesh.attributes,
+ mesh.uv_layers,
+ ob.vertex_groups,
+ ):
+ for name in collection.keys():
+ unique_names_len = len(unique_names)
+ unique_names.add(name)
+ if len(unique_names) == unique_names_len:
+ colliding_names.append(name)
  
- colliding_names = [name for name, layers in 
attributes_by_name.items() if len(layers) >= 2]
- if len(colliding_names) == 0:
+ if not colliding_names:
  return
  
- layout.label(text="Name collisions: {}".format(", 
".join(colliding_names)), icon='ERROR')
+ layout.label(text="Name collisions: " + ", 
".join(set(colliding_names)), icon='ERROR')
  
  
 -class MESH_UL_color_attributes(UIList):
 +class ColorAttributesListBase():
  display_domain_names = {
  'POINT': "Vertex",
  'EDGE': "Edge",

___
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] [ee292a1d66b] master: PyAPI: use keyword only arguments for Text.region_{from/to} string

2022-04-07 Thread Campbell Barton
Commit: ee292a1d66b22d8707a493550138ead91b3c0ccc
Author: Campbell Barton
Date:   Fri Apr 8 12:49:02 2022 +1000
Branches: master
https://developer.blender.org/rBee292a1d66b22d8707a493550138ead91b3c0ccc

PyAPI: use keyword only arguments for Text.region_{from/to} string

This is the convention for most parts of Blender Python API.

===

M   source/blender/python/intern/bpy_rna_text.c
M   tests/python/bl_pyapi_text.py

===

diff --git a/source/blender/python/intern/bpy_rna_text.c 
b/source/blender/python/intern/bpy_rna_text.c
index fedb914256a..7ccc70cc7fa 100644
--- a/source/blender/python/intern/bpy_rna_text.c
+++ b/source/blender/python/intern/bpy_rna_text.c
@@ -36,6 +36,8 @@ typedef struct TextRegion {
   int selc;
 } TextRegion;
 
+/** \} */
+
 /*  */
 /** \name Text Editor Get / Set region text API
  * \{ */
@@ -53,18 +55,27 @@ PyDoc_STRVAR(bpy_rna_region_as_string_doc,
  "   :return: The specified region as a string.\n"
  "   :rtype: str.\n");
 /* Receive a Python Tuple as parameter to represent the region range. */
-static PyObject *bpy_rna_region_as_string(PyObject *self, PyObject *args)
+static PyObject *bpy_rna_region_as_string(PyObject *self, PyObject *args, 
PyObject *kwds)
 {
   BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
   Text *text = pyrna->ptr.data;
   /* Parse the region range. */
   TextRegion region;
-  if (!PyArg_ParseTuple(
-  args, "|((ii)(ii))", ®ion.curl, ®ion.curc, ®ion.sell, 
®ion.selc)) {
+
+  static const char *_keywords[] = {"range", NULL};
+  static _PyArg_Parser _parser = {
+  "|$" /* Optional keyword only arguments. */
+  "((ii)(ii))" /* `range` */
+  ":region_as_string",
+  _keywords,
+  0,
+  };
+  if (!_PyArg_ParseTupleAndKeywordsFast(
+  args, kwds, &_parser, ®ion.curl, ®ion.curc, ®ion.sell, 
®ion.selc)) {
 return NULL;
   }
 
-  if (PyTuple_GET_SIZE(args) > 0) {
+  if (PyDict_GET_SIZE(kwds) > 0) {
 txt_sel_set(text, region.curl, region.curc, region.sell, region.selc);
   }
 
@@ -98,7 +109,7 @@ PyDoc_STRVAR(bpy_rna_region_from_string_doc,
  "  The values match Python's slicing logic "
  "(negative values count backwards from the end, the end value is 
not inclusive).\n"
  "   :type range: Two pairs of ints\n");
-static PyObject *bpy_rna_region_from_string(PyObject *self, PyObject *args)
+static PyObject *bpy_rna_region_from_string(PyObject *self, PyObject *args, 
PyObject *kwds)
 {
   BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
   Text *text = pyrna->ptr.data;
@@ -107,18 +118,29 @@ static PyObject *bpy_rna_region_from_string(PyObject 
*self, PyObject *args)
   const char *buf;
   Py_ssize_t buf_len;
   TextRegion region;
-  if (!PyArg_ParseTuple(args,
-"s#|((ii)(ii))",
-&buf,
-&buf_len,
-®ion.curl,
-®ion.curc,
-®ion.sell,
-®ion.selc)) {
+
+  static const char *_keywords[] = {"", "range", NULL};
+  static _PyArg_Parser _parser = {
+  "s#" /* `buf` (positional). */
+  "|$" /* Optional keyword only arguments. */
+  "((ii)(ii))" /* `range` */
+  ":region_from_string",
+  _keywords,
+  0,
+  };
+  if (!_PyArg_ParseTupleAndKeywordsFast(args,
+kwds,
+&_parser,
+&buf,
+&buf_len,
+®ion.curl,
+®ion.curc,
+®ion.sell,
+®ion.selc)) {
 return NULL;
   }
 
-  if (PyTuple_GET_SIZE(args) > 1) {
+  if (PyDict_GET_SIZE(kwds) > 0) {
 txt_sel_set(text, region.curl, region.curc, region.sell, region.selc);
   }
 
@@ -133,7 +155,7 @@ static PyObject *bpy_rna_region_from_string(PyObject *self, 
PyObject *args)
 PyMethodDef BPY_rna_region_from_string_method_def = {
 "region_from_string",
 (PyCFunction)bpy_rna_region_from_string,
-METH_VARARGS,
+METH_VARARGS | METH_KEYWORDS,
 bpy_rna_region_from_string_doc,
 };
 
diff --git a/tests/python/bl_pyapi_text.py b/tests/python/bl_pyapi_text.py
index 67e07e7d907..0d8987fb69d 100644
--- a/tests/python/bl_pyapi_text.py
+++ b/tests/python/bl_pyapi_text.py
@@ -40,9 +40,9 @@ class TestText(unittest.TestCase):
 )
 self.text.write(tmp_text)
 # Get string in the middle of the text.
-self.assertEqual(self.text.region_as_string(((1, 0), (1, -1))), "Line 
2: test line 2")
+self.assertEqual(self.text.region_as_string(range=((1, 0), (1, -1))), 
"Line 2: test line 2"

[Bf-blender-cvs] [982aea88e0d] master: Cleanup: separate format-units for Python argument parsing

2022-04-07 Thread Campbell Barton
Commit: 982aea88e0d74020c62c2054a45eeafa56c8ca30
Author: Campbell Barton
Date:   Fri Apr 8 09:41:28 2022 +1000
Branches: master
https://developer.blender.org/rB982aea88e0d74020c62c2054a45eeafa56c8ca30

Cleanup: separate format-units for Python argument parsing

With the increased use of multi-character format units and keyword-only
arguments these are increasingly difficult to make sense of.

Split the string onto multiple lines, one per argument.
While verbose it's easier to understand and add new arguments.

===

M   source/blender/python/generic/imbuf_py_api.c
M   source/blender/python/gpu/gpu_py_batch.c
M   source/blender/python/gpu/gpu_py_element.c
M   source/blender/python/gpu/gpu_py_framebuffer.c
M   source/blender/python/gpu/gpu_py_offscreen.c
M   source/blender/python/gpu/gpu_py_shader.c
M   source/blender/python/gpu/gpu_py_texture.c
M   source/blender/python/gpu/gpu_py_uniformbuffer.c
M   source/blender/python/gpu/gpu_py_vertex_buffer.c
M   source/blender/python/gpu/gpu_py_vertex_format.c
M   source/blender/python/intern/bpy.c
M   source/blender/python/intern/bpy_app_icons.c
M   source/blender/python/intern/bpy_app_timers.c
M   source/blender/python/intern/bpy_gizmo_wrap.c
M   source/blender/python/intern/bpy_library_load.c
M   source/blender/python/intern/bpy_library_write.c
M   source/blender/python/intern/bpy_msgbus.c
M   source/blender/python/intern/bpy_props.c
M   source/blender/python/intern/bpy_rna.c
M   source/blender/python/intern/bpy_rna_data.c
M   source/blender/python/intern/bpy_rna_gizmo.c
M   source/blender/python/intern/bpy_rna_id_collection.c
M   source/blender/python/intern/bpy_utils_units.c

===

diff --git a/source/blender/python/generic/imbuf_py_api.c 
b/source/blender/python/generic/imbuf_py_api.c
index bfe25435eab..ef11d1ab32d 100644
--- a/source/blender/python/generic/imbuf_py_api.c
+++ b/source/blender/python/generic/imbuf_py_api.c
@@ -92,7 +92,14 @@ static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject 
*args, PyObject *kw)
   struct PyC_StringEnum method = {method_items, FAST};
 
   static const char *_keywords[] = {"size", "method", NULL};
-  static _PyArg_Parser _parser = {"(ii)|$O&:resize", _keywords, 0};
+  static _PyArg_Parser _parser = {
+  "(ii)" /* `size` */
+  "|$"   /* Optional keyword only arguments. */
+  "O&"   /* `method` */
+  ":resize",
+  _keywords,
+  0,
+  };
   if (!_PyArg_ParseTupleAndKeywordsFast(
   args, kw, &_parser, &size[0], &size[1], PyC_ParseStringEnum, 
&method)) {
 return NULL;
@@ -130,7 +137,13 @@ static PyObject *py_imbuf_crop(Py_ImBuf *self, PyObject 
*args, PyObject *kw)
   rcti crop;
 
   static const char *_keywords[] = {"min", "max", NULL};
-  static _PyArg_Parser _parser = {"(II)(II):crop", _keywords, 0};
+  static _PyArg_Parser _parser = {
+  "(II)" /* `min` */
+  "(II)" /* `max` */
+  ":crop",
+  _keywords,
+  0,
+  };
   if (!_PyArg_ParseTupleAndKeywordsFast(
   args, kw, &_parser, &crop.xmin, &crop.ymin, &crop.xmax, &crop.ymax)) 
{
 return NULL;
@@ -420,7 +433,12 @@ static PyObject *M_imbuf_new(PyObject *UNUSED(self), 
PyObject *args, PyObject *k
 {
   int size[2];
   static const char *_keywords[] = {"size", NULL};
-  static _PyArg_Parser _parser = {"(ii):new", _keywords, 0};
+  static _PyArg_Parser _parser = {
+  "(ii)" /* `size` */
+  ":new",
+  _keywords,
+  0,
+  };
   if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], 
&size[1])) {
 return NULL;
   }
@@ -455,7 +473,12 @@ static PyObject *M_imbuf_load(PyObject *UNUSED(self), 
PyObject *args, PyObject *
   const char *filepath;
 
   static const char *_keywords[] = {"filepath", NULL};
-  static _PyArg_Parser _parser = {"s:load", _keywords, 0};
+  static _PyArg_Parser _parser = {
+  "s" /* `filepath` */
+  ":load",
+  _keywords,
+  0,
+  };
   if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filepath)) {
 return NULL;
   }
@@ -497,7 +520,14 @@ static PyObject *M_imbuf_write(PyObject *UNUSED(self), 
PyObject *args, PyObject
   const char *filepath = NULL;
 
   static const char *_keywords[] = {"image", "filepath", NULL};
-  static _PyArg_Parser _parser = {"O!|$s:write", _keywords, 0};
+  static _PyArg_Parser _parser = {
+  "O!" /* `image` */
+  "|$" /* Optional keyword only arguments. */
+  "s"  /* `filepath` */
+  ":write",
+  _keywords,
+  0,
+  };
   if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, 
&py_imb, &filepath)) {
 return NULL;
   }
diff --git a/source/blender/python/gpu/gpu_py_batch.c 
b/source/blender/python/gpu/gpu_py_batch.c
index 486601f4c86..232d4775746 100644
--- a/source/blender/python/gpu/gpu_py_batch.c
+++ b/source/blender/python/gpu/gpu_py_batch.c
@@ 

[Bf-blender-cvs] [87a3bf33564] master: Cleanup: Define new curves normal mode in DNA

2022-04-07 Thread Hans Goudey
Commit: 87a3bf33564b035e4c2400098ea4932d5dfdba5d
Author: Hans Goudey
Date:   Thu Apr 7 18:10:05 2022 -0500
Branches: master
https://developer.blender.org/rB87a3bf33564b035e4c2400098ea4932d5dfdba5d

Cleanup: Define new curves normal mode in DNA

Don't include the tangent mode for now, since that
was never implemented for geometry nodes curves.

===

M   source/blender/blenkernel/BKE_spline.hh
M   source/blender/blenkernel/intern/curve_eval.cc
M   source/blender/blenkernel/intern/spline_base.cc
M   source/blender/makesdna/DNA_curves_types.h

===

diff --git a/source/blender/blenkernel/BKE_spline.hh 
b/source/blender/blenkernel/BKE_spline.hh
index 32330244c08..6cbb47dc709 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -51,12 +51,7 @@ using SplinePtr = std::unique_ptr;
  */
 class Spline {
  public:
-  enum NormalCalculationMode {
-ZUp,
-Minimum,
-Tangent,
-  };
-  NormalCalculationMode normal_mode = Minimum;
+  NormalMode normal_mode = NORMAL_MODE_MINIMUM_TWIST;
 
   blender::bke::CustomDataAttributes attributes;
 
diff --git a/source/blender/blenkernel/intern/curve_eval.cc 
b/source/blender/blenkernel/intern/curve_eval.cc
index 122df12261c..9b1fd510fa8 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -189,18 +189,17 @@ static HandleType handle_type_from_dna_bezt(const 
eBezTriple_Handle dna_handle_t
   return BEZIER_HANDLE_AUTO;
 }
 
-static Spline::NormalCalculationMode normal_mode_from_dna_curve(const int 
twist_mode)
+static NormalMode normal_mode_from_dna_curve(const int twist_mode)
 {
   switch (twist_mode) {
 case CU_TWIST_Z_UP:
-  return Spline::NormalCalculationMode::ZUp;
-case CU_TWIST_MINIMUM:
-  return Spline::NormalCalculationMode::Minimum;
 case CU_TWIST_TANGENT:
-  return Spline::NormalCalculationMode::Tangent;
+  return NORMAL_MODE_Z_UP;
+case CU_TWIST_MINIMUM:
+  return NORMAL_MODE_MINIMUM_TWIST;
   }
   BLI_assert_unreachable();
-  return Spline::NormalCalculationMode::Minimum;
+  return NORMAL_MODE_MINIMUM_TWIST;
 }
 
 static KnotsMode knots_mode_from_dna_nurb(const short flag)
@@ -333,8 +332,7 @@ std::unique_ptr curve_eval_from_dna_curve(const 
Curve &dna_curve,
 
   /* Normal mode is stored separately in each spline to facilitate combining
* splines from multiple curve objects, where the value may be different. */
-  const Spline::NormalCalculationMode normal_mode = normal_mode_from_dna_curve(
-  dna_curve.twist_mode);
+  const NormalMode normal_mode = 
normal_mode_from_dna_curve(dna_curve.twist_mode);
   for (SplinePtr &spline : curve->splines()) {
 spline->normal_mode = normal_mode;
   }
diff --git a/source/blender/blenkernel/intern/spline_base.cc 
b/source/blender/blenkernel/intern/spline_base.cc
index eecb374cd63..7704a74841a 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -377,19 +377,14 @@ Span Spline::evaluated_normals() const
 
   /* Only Z up normals are supported at the moment. */
   switch (this->normal_mode) {
-case ZUp: {
+case NORMAL_MODE_Z_UP: {
   calculate_normals_z_up(tangents, normals);
   break;
 }
-case Minimum: {
+case NORMAL_MODE_MINIMUM_TWIST: {
   calculate_normals_minimum(tangents, is_cyclic_, normals);
   break;
 }
-case Tangent: {
-  /* Tangent mode is not yet supported. */
-  calculate_normals_z_up(tangents, normals);
-  break;
-}
   }
 
   /* Rotate the generated normals with the interpolated tilt data. */
diff --git a/source/blender/makesdna/DNA_curves_types.h 
b/source/blender/makesdna/DNA_curves_types.h
index a1eefca4ab5..0aa4ebc61d0 100644
--- a/source/blender/makesdna/DNA_curves_types.h
+++ b/source/blender/makesdna/DNA_curves_types.h
@@ -49,6 +49,12 @@ typedef enum KnotsMode {
   NURBS_KNOT_MODE_ENDPOINT_BEZIER = 3,
 } KnotsMode;
 
+/** Method used to calculate the normals of a curve's evaluated points. */
+typedef enum NormalMode {
+  NORMAL_MODE_Z_UP = 0,
+  NORMAL_MODE_MINIMUM_TWIST = 1,
+} NormalMode;
+
 /**
  * A reusable data structure for geometry consisting of many curves. All 
control point data is
  * stored contiguously for better efficiency. Data for each curve is stored as 
a slice of the

___
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] [3214028ae82] master: Cycles: Support adding Lightgroups from the object/world properties

2022-04-07 Thread Lukas Stockner
Commit: 3214028ae822d6b9b1622589d27dd9b9746f2aa8
Author: Lukas Stockner
Date:   Mon Apr 4 03:50:55 2022 +0200
Branches: master
https://developer.blender.org/rB3214028ae822d6b9b1622589d27dd9b9746f2aa8

Cycles: Support adding Lightgroups from the object/world properties

Currently, only Lightgroups that exist in the current view layer can be
selected from object or world properties.

The internal UI code already has support for search fields that accept
unknown input, so I just added that to the API and use it for lightgroups.

When a lightgroup is entered that does not exist in the current view layer
(e.g. because it's completely new, because the view layer was switched or
because it was deleted earlier), a new button next to it becomes active and
adds it to the view layer when pressed.

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

===

M   intern/cycles/blender/addon/ui.py
M   source/blender/blenkernel/BKE_layer.h
M   source/blender/blenkernel/intern/layer.c
M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/interface/interface_intern.h
M   source/blender/editors/interface/interface_layout.c
M   source/blender/editors/interface/interface_utils.cc
M   source/blender/editors/render/render_shading.cc
M   source/blender/makesrna/intern/rna_scene.c
M   source/blender/makesrna/intern/rna_ui_api.c

===

diff --git a/intern/cycles/blender/addon/ui.py 
b/intern/cycles/blender/addon/ui.py
index b7fd3e46669..2c6788b867b 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -1174,8 +1174,15 @@ class CYCLES_OBJECT_PT_lightgroup(CyclesButtonsPanel, 
Panel):
 
 view_layer = context.view_layer
 
-col = layout.column(align=True)
-col.prop_search(ob, "lightgroup", view_layer, "lightgroups", 
text="Light Group")
+row = layout.row(align=True)
+row.use_property_decorate = False
+
+sub = row.column(align=True)
+sub.prop_search(ob, "lightgroup", view_layer, "lightgroups", 
text="Light Group", results_are_suggestions=True)
+
+sub = row.column(align=True)
+sub.active = bool(ob.lightgroup) and not any(lg.name == ob.lightgroup 
for lg in view_layer.lightgroups)
+sub.operator("scene.view_layer_add_lightgroup", icon='ADD', 
text="").name = ob.lightgroup
 
 
 class CYCLES_OBJECT_PT_visibility(CyclesButtonsPanel, Panel):
@@ -1435,8 +1442,15 @@ class CYCLES_WORLD_PT_surface(CyclesButtonsPanel, Panel):
 if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
 layout.prop(world, "color")
 
-col = layout.column(align=True)
-col.prop_search(world, "lightgroup", view_layer, "lightgroups", 
text="Light Group")
+row = layout.row(align=True)
+row.use_property_decorate = False
+
+sub = row.column(align=True)
+sub.prop_search(world, "lightgroup", view_layer, "lightgroups", 
text="Light Group", results_are_suggestions=True)
+
+sub = row.column(align=True)
+sub.active = bool(world.lightgroup) and not any(lg.name == 
world.lightgroup for lg in view_layer.lightgroups)
+sub.operator("scene.view_layer_add_lightgroup", icon='ADD', 
text="").name = world.lightgroup
 
 
 class CYCLES_WORLD_PT_volume(CyclesButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_layer.h 
b/source/blender/blenkernel/BKE_layer.h
index 4a3917dafee..cad6f6d6645 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -582,7 +582,8 @@ bool BKE_view_layer_has_valid_aov(struct ViewLayer 
*view_layer);
 struct ViewLayer *BKE_view_layer_find_with_aov(struct Scene *scene,
struct ViewLayerAOV 
*view_layer_aov);
 
-struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer 
*view_layer);
+struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer 
*view_layer,
+  const char *name);
 void BKE_view_layer_remove_lightgroup(struct ViewLayer *view_layer,
   struct ViewLayerLightgroup *lightgroup);
 void BKE_view_layer_set_active_lightgroup(struct ViewLayer *view_layer,
diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index c99bf885074..1cc1839d2d0 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -2535,11 +2535,17 @@ static void viewlayer_lightgroup_active_set(ViewLayer 
*view_layer, ViewLayerLigh
   }
 }
 
-struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer 
*view_layer)
+struct ViewLayerLightgroup *BKE_view_layer_add_lightgroup(struct ViewLayer 
*view_layer,
+  const char 

[Bf-blender-cvs] [aaa5a80763e] master: Fix Cycles build error after recent changes

2022-04-07 Thread Brecht Van Lommel
Commit: aaa5a80763ee7669d84741f936f24560984f5df3
Author: Brecht Van Lommel
Date:   Thu Apr 7 20:33:34 2022 +0200
Branches: master
https://developer.blender.org/rBaaa5a80763ee7669d84741f936f24560984f5df3

Fix Cycles build error after recent changes

===

M   intern/cycles/cmake/external_libs.cmake

===

diff --git a/intern/cycles/cmake/external_libs.cmake 
b/intern/cycles/cmake/external_libs.cmake
index 0924b83201f..05c0980bdfb 100644
--- a/intern/cycles/cmake/external_libs.cmake
+++ b/intern/cycles/cmake/external_libs.cmake
@@ -534,9 +534,9 @@ endif()
 # GLEW
 ###
 
-if((WITH_CYCLES_STANDALONE AND WITH_CYCLES_STANDALONE_GUI) OR
-   WITH_CYCLES_HYDRA_RENDER_DELEGATE)
-  if(CYCLES_STANDALONE_REPOSITORY)
+if(CYCLES_STANDALONE_REPOSITORY)
+  if((WITH_CYCLES_STANDALONE AND WITH_CYCLES_STANDALONE_GUI) OR
+ WITH_CYCLES_HYDRA_RENDER_DELEGATE)
 if(MSVC AND EXISTS ${_cycles_lib_dir})
   set(GLEW_LIBRARY "${_cycles_lib_dir}/opengl/lib/glew.lib")
   set(GLEW_INCLUDE_DIR "${_cycles_lib_dir}/opengl/include")
@@ -546,11 +546,11 @@ if((WITH_CYCLES_STANDALONE AND 
WITH_CYCLES_STANDALONE_GUI) OR
 endif()
 
 set(CYCLES_GLEW_LIBRARIES ${GLEW_LIBRARY})
-  else()
-# Workaround for unconventional variable name use in Blender.
-set(GLEW_INCLUDE_DIR "${GLEW_INCLUDE_PATH}")
-set(CYCLES_GLEW_LIBRARIES bf_intern_glew_mx ${BLENDER_GLEW_LIBRARIES})
   endif()
+else()
+  # Workaround for unconventional variable name use in Blender.
+  set(GLEW_INCLUDE_DIR "${GLEW_INCLUDE_PATH}")
+  set(CYCLES_GLEW_LIBRARIES bf_intern_glew_mx ${BLENDER_GLEW_LIBRARIES})
 endif()
 
 ###

___
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] [d197e272bb7] master: Fix Clang/Linux build error after line primitive parallelization

2022-04-07 Thread Brecht Van Lommel
Commit: d197e272bb711ce271106c1da01e89b2c431200b
Author: Brecht Van Lommel
Date:   Thu Apr 7 20:36:15 2022 +0200
Branches: master
https://developer.blender.org/rBd197e272bb711ce271106c1da01e89b2c431200b

Fix Clang/Linux build error after line primitive parallelization

===

M   source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc

===

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index 8c1dea90f44..2af86b4b1d2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -3,6 +3,8 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+#include "BLI_task.hh"
+
 #include "BKE_material.h"
 #include "BKE_mesh.h"

___
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] [0de0950ad5d] master: Cycles: various Linux build fixes related to Hydra render delegate

2022-04-07 Thread Brecht Van Lommel
Commit: 0de0950ad5d1de5172cbd2b6b0e67fe319a420c1
Author: Brecht Van Lommel
Date:   Wed Apr 6 22:25:40 2022 +0200
Branches: master
https://developer.blender.org/rB0de0950ad5d1de5172cbd2b6b0e67fe319a420c1

Cycles: various Linux build fixes related to Hydra render delegate

* Add missing GLEW and hgiGL libraries for Hydra
* Fix wrong case sensitive include
* Fix link errors by adding external libs to static Hydra lib
* Work around weird Hydra link error with MAX_SAMPLES
* Use Embree by default for Hydra
* Sync external libs code with standalone
* Update version number to match Blender
* Remove unneeded CLEW/GLEW from test executable

None of this should affect Cycles in Blender.

Ref T96731

===

M   intern/cycles/app/CMakeLists.txt
M   intern/cycles/cmake/external_libs.cmake
M   intern/cycles/cmake/macros.cmake
M   intern/cycles/device/CMakeLists.txt
M   intern/cycles/hydra/CMakeLists.txt
M   intern/cycles/hydra/plugin.cpp
M   intern/cycles/hydra/render_delegate.cpp
M   intern/cycles/scene/scene.h
M   intern/cycles/test/CMakeLists.txt
M   intern/cycles/util/system.cpp
M   intern/cycles/util/version.h

===

diff --git a/intern/cycles/app/CMakeLists.txt b/intern/cycles/app/CMakeLists.txt
index 484d99c5ca7..872a95ed5a6 100644
--- a/intern/cycles/app/CMakeLists.txt
+++ b/intern/cycles/app/CMakeLists.txt
@@ -11,7 +11,7 @@ set(INC
 set(INC_SYS
 )
 
-set(LIBRARIES
+set(LIB
   cycles_device
   cycles_kernel
   cycles_scene
@@ -33,27 +33,23 @@ if(WITH_ALEMBIC)
 endif()
 
 if(WITH_CYCLES_OSL)
-  list(APPEND LIBRARIES cycles_kernel_osl)
+  list(APPEND LIB cycles_kernel_osl)
 endif()
 
 if(CYCLES_STANDALONE_REPOSITORY)
-  list(APPEND LIBRARIES extern_sky)
+  list(APPEND LIB extern_sky)
 else()
-  list(APPEND LIBRARIES bf_intern_sky)
+  list(APPEND LIB bf_intern_sky)
 endif()
 
 if(WITH_CYCLES_STANDALONE AND WITH_CYCLES_STANDALONE_GUI)
   add_definitions(${GL_DEFINITIONS})
-  list(APPEND INC_SYS
-${GLEW_INCLUDE_DIR}
-${SDL2_INCLUDE_DIRS}
-  )
-  list(APPEND LIBRARIES
-${CYCLES_GL_LIBRARIES}
-${SDL2_LIBRARIES}
-  )
+  list(APPEND INC_SYS ${GLEW_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS})
+  list(APPEND LIB ${CYCLES_GL_LIBRARIES} ${CYCLES_GLEW_LIBRARIES} 
${SDL2_LIBRARIES})
 endif()
 
+cycles_external_libraries_append(LIB)
+
 # Common configuration.
 
 include_directories(${INC})
@@ -84,8 +80,7 @@ if(WITH_CYCLES_STANDALONE)
   add_executable(cycles ${SRC} ${INC} ${INC_SYS})
   unset(SRC)
 
-  target_link_libraries(cycles ${LIBRARIES})
-  cycles_target_link_libraries(cycles)
+  target_link_libraries(cycles PRIVATE ${LIB})
 
   if(APPLE)
 if(WITH_OPENCOLORIO)
@@ -128,9 +123,12 @@ if(WITH_CYCLES_CUBIN_COMPILER)
 set(INC
   ../../../extern/cuew/include
 )
+set(LIB
+)
+cycles_external_libraries_append(LIB)
 add_executable(cycles_cubin_cc ${SRC})
 include_directories(${INC})
-cycles_target_link_libraries(cycles_cubin_cc)
+target_link_libraries(cycles_cubin_cc PRIVATE ${LIB})
 unset(SRC)
 unset(INC)
   endif()
diff --git a/intern/cycles/cmake/external_libs.cmake 
b/intern/cycles/cmake/external_libs.cmake
index 3ee92b7be88..0924b83201f 100644
--- a/intern/cycles/cmake/external_libs.cmake
+++ b/intern/cycles/cmake/external_libs.cmake
@@ -19,7 +19,11 @@ endmacro()
 
 if(CYCLES_STANDALONE_REPOSITORY)
   if(APPLE)
-set(_cycles_lib_dir "${CMAKE_SOURCE_DIR}/../lib/darwin")
+if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64")
+  set(_cycles_lib_dir "${CMAKE_SOURCE_DIR}/../lib/darwin")
+else()
+  set(_cycles_lib_dir "${CMAKE_SOURCE_DIR}/../lib/darwin_arm64")
+endif()
   elseif(WIN32)
 if(CMAKE_CL_64)
   set(_cycles_lib_dir "${CMAKE_SOURCE_DIR}/../lib/win64_vc15")
@@ -48,18 +52,24 @@ if(CYCLES_STANDALONE_REPOSITORY)
   endif()
 endif()
 
+if(DEFINED _cycles_lib_dir)
+  message(STATUS "Using precompiled libraries at ${_cycles_lib_dir}")
+endif()
+
 # Avoid namespace pollustion.
 unset(LIBDIR_NATIVE_ABI)
 unset(LIBDIR_CENTOS7_ABI)
   endif()
 
   if(EXISTS ${_cycles_lib_dir})
+_set_default(ALEMBIC_ROOT_DIR "${_cycles_lib_dir}/alembic")
 _set_default(BOOST_ROOT "${_cycles_lib_dir}/boost")
 _set_default(BLOSC_ROOT_DIR "${_cycles_lib_dir}/blosc")
 _set_default(EMBREE_ROOT_DIR "${_cycles_lib_dir}/embree")
 _set_default(GLEW_ROOT_DIR "${_cycles_lib_dir}/glew")
 _set_default(JPEG_ROOT "${_cycles_lib_dir}/jpeg")
 _set_default(LLVM_ROOT_DIR "${_cycles_lib_dir}/llvm")
+_set_default(CLANG_ROOT_DIR "${_cycles_lib_dir}/llvm")
 _set_default(OPENCOLORIO_ROOT_DIR "${_cycles_lib_dir}/opencolorio")
 _set_default(OPENEXR_ROOT_DIR "${_cycles_lib_dir}/openexr")
 _set_default(OPENIMAGEDENOISE_ROOT_DIR 
"${_cycles_lib_dir}/openimagedenoise")
@@ -110,7 +120,7 @@ if(CYCLES_STANDALONE_REPOSITORY)
 set(ZLIB_LIBRARY ${_cycles_lib_di

[Bf-blender-cvs] [be799749dcc] master: Fix T97035: crash transferring face corner data

2022-04-07 Thread Brecht Van Lommel
Commit: be799749dcc886e9e47493cb34eaf0367894d979
Author: Brecht Van Lommel
Date:   Wed Apr 6 20:29:28 2022 +0200
Branches: master
https://developer.blender.org/rBbe799749dcc886e9e47493cb34eaf0367894d979

Fix T97035: crash transferring face corner data

The mechanism to instance meshes when there are no modifiers did not take
into account that modifiers might get re-evaluated from an operator that
requests loop normals. Now check for that case and no longer use the
instance then.

In the future, a better solution may be to compute loop normals on demand
as is already done for poly and vertex normals, but that would be a big
change.

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

===

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

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc 
b/source/blender/blenkernel/intern/DerivedMesh.cc
index 904a43a7c28..604cc3682f0 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -606,6 +606,19 @@ static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh 
*mesh, Mesh *mesh_orc
   }
 }
 
+static bool mesh_has_modifier_final_normals(const Mesh *mesh_input,
+const CustomData_MeshMasks 
*final_datamask,
+Mesh *mesh_final)
+{
+  /* Test if mesh has the required loop normals, in case an additional modifier
+   * evaluation from another instance or from an operator requests it but the
+   * initial normals were not loop normals. */
+  const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 ||
+(final_datamask->lmask & CD_MASK_NORMAL) != 0);
+
+  return (!do_loop_normals || CustomData_has_layer(&mesh_final->ldata, 
CD_NORMAL));
+}
+
 static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
  const CustomData_MeshMasks 
*final_datamask,
  const bool sculpt_dyntopo,
@@ -1190,7 +1203,8 @@ static void mesh_calc_modifiers(struct Depsgraph 
*depsgraph,
   BLI_assert(runtime->eval_mutex != nullptr);
   BLI_mutex_lock((ThreadMutex *)runtime->eval_mutex);
   if (runtime->mesh_eval == nullptr) {
-/* Isolate since computing normals is multithreaded and we are holding 
a lock. */
+/* Not yet finalized by any instance, do it now
+ * Isolate since computing normals is multithreaded and we are holding 
a lock. */
 blender::threading::isolate_task([&] {
   mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
   mesh_calc_modifier_final_normals(
@@ -1199,9 +1213,23 @@ static void mesh_calc_modifiers(struct Depsgraph 
*depsgraph,
   runtime->mesh_eval = mesh_final;
 });
   }
+  else {
+/* Already finalized by another instance, reuse. */
+mesh_final = runtime->mesh_eval;
+  }
   BLI_mutex_unlock((ThreadMutex *)runtime->eval_mutex);
 }
-mesh_final = runtime->mesh_eval;
+else if (!mesh_has_modifier_final_normals(mesh_input, &final_datamask, 
runtime->mesh_eval)) {
+  /* Modifier stack was (re-)evaluated with a request for additional 
normals
+   * different than the instanced mesh, can't instance anymore now. */
+  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
+  mesh_calc_modifier_final_normals(mesh_input, &final_datamask, 
sculpt_dyntopo, mesh_final);
+  mesh_calc_finalize(mesh_input, mesh_final);
+}
+else {
+  /* Already finalized by another instance, reuse. */
+  mesh_final = runtime->mesh_eval;
+}
   }
 
   if (is_own_mesh) {

___
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] [51a7e4b488a] master: Cleanup: remove unused mface tesselation code from modifier stack

2022-04-07 Thread Brecht Van Lommel
Commit: 51a7e4b488a4df1ce6fec93ee599d70efdbf5e03
Author: Brecht Van Lommel
Date:   Wed Apr 6 20:02:04 2022 +0200
Branches: master
https://developer.blender.org/rB51a7e4b488a4df1ce6fec93ee599d70efdbf5e03

Cleanup: remove unused mface tesselation code from modifier stack

This seems to serve no purpose anymore, I don't see anywhere that
CD_MFACE is requested for modifier evaluation, and it's confusing
to have this in this final normals computation function.

Found while looking into D14579.

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

===

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

===

diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc 
b/source/blender/blenkernel/intern/DerivedMesh.cc
index 604cc3682f0..33f0c331e46 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -631,30 +631,23 @@ static void mesh_calc_modifier_final_normals(const Mesh 
*mesh_input,
   if (do_loop_normals) {
 /* Compute loop normals (NOTE: will compute poly and vert normals as well, 
if needed!). */
 BKE_mesh_calc_normals_split(mesh_final);
-BKE_mesh_tessface_clear(mesh_final);
   }
-
-  if (sculpt_dyntopo == false) {
-/* watch this! after 2.75a we move to from tessface to looptri (by 
default) */
-if (final_datamask->fmask & CD_MASK_MFACE) {
-  BKE_mesh_tessface_ensure(mesh_final);
-}
-
-/* without this, drawing ngon tri's faces will show ugly tessellated face
- * normals and will also have to calculate normals on the fly, try avoid
- * this where possible since calculating polygon normals isn't fast,
- * note that this isn't a problem for subsurf (only quads) or editmode
- * which deals with drawing differently. */
-if (!do_loop_normals) {
+  else {
+if (sculpt_dyntopo == false) {
+  /* without this, drawing ngon tri's faces will show ugly tessellated face
+   * normals and will also have to calculate normals on the fly, try avoid
+   * this where possible since calculating polygon normals isn't fast,
+   * note that this isn't a problem for subsurf (only quads) or editmode
+   * which deals with drawing differently. */
   BKE_mesh_ensure_normals_for_display(mesh_final);
 }
-  }
 
-  /* Some modifiers, like data-transfer, may generate those data as temp layer,
-   * we do not want to keep them, as they are used by display code when 
available
-   * (i.e. even if autosmooth is disabled). */
-  if (!do_loop_normals && CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) 
{
-CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop);
+/* Some modifiers, like data-transfer, may generate those data as temp 
layer,
+ * we do not want to keep them, as they are used by display code when 
available
+ * (i.e. even if autosmooth is disabled). */
+if (CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) {
+  CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, 
mesh_final->totloop);
+}
   }
 }
 
@@ -1196,6 +1189,7 @@ static void mesh_calc_modifiers(struct Depsgraph 
*depsgraph,
   /* Compute normals. */
   if (is_own_mesh) {
 mesh_calc_modifier_final_normals(mesh_input, &final_datamask, 
sculpt_dyntopo, mesh_final);
+mesh_calc_finalize(mesh_input, mesh_final);
   }
   else {
 Mesh_Runtime *runtime = &mesh_input->runtime;
@@ -1232,10 +1226,6 @@ static void mesh_calc_modifiers(struct Depsgraph 
*depsgraph,
 }
   }
 
-  if (is_own_mesh) {
-mesh_calc_finalize(mesh_input, mesh_final);
-  }
-
   /* Return final mesh */
   *r_final = mesh_final;
   if (r_deform) {
@@ -1299,21 +1289,9 @@ static void editbmesh_calc_modifier_final_normals(Mesh 
*mesh_final,
   if (do_loop_normals) {
 /* Compute loop normals */
 BKE_mesh_calc_normals_split(mesh_final);
-BKE_mesh_tessface_clear(mesh_final);
   }
-
-  /* BMESH_ONLY, ensure tessface's used for drawing,
-   * but don't recalculate if the last modifier in the stack gives us tessfaces
-   * check if the derived meshes are DM_TYPE_EDITBMESH before calling, this 
isn't essential
-   * but quiets annoying error messages since tessfaces won't be created. */
-  if (final_datamask->fmask & CD_MASK_MFACE) {
-if (mesh_final->edit_mesh == nullptr) {
-  BKE_mesh_tessface_ensure(mesh_final);
-}
-  }
-
-  /* same as mesh_calc_modifiers (if using loop normals, poly nors have 
already been computed). */
-  if (!do_loop_normals) {
+  else {
+/* Same as mesh_calc_modifiers. If using loop normals, poly nors have 
already been computed. */
 BKE_mesh_ensure_normals_for_display(mesh_final);
 
 /* Some modifiers, like data-transfer, may generate those data, we do not 
want to keep them,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription detai

[Bf-blender-cvs] [46c54b12b02] master: Cleanup: Return early in metaball tessellation code

2022-04-07 Thread Hans Goudey
Commit: 46c54b12b02d5b735df326ca9813bf35e94bdcf3
Author: Hans Goudey
Date:   Thu Apr 7 12:33:47 2022 -0500
Branches: master
https://developer.blender.org/rB46c54b12b02d5b735df326ca9813bf35e94bdcf3

Cleanup: Return early in metaball tessellation code

Also declare variables where initialized and use const.

===

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

===

diff --git a/source/blender/blenkernel/intern/mball_tessellate.c 
b/source/blender/blenkernel/intern/mball_tessellate.c
index b3e6a854811..54def0189b1 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.c
+++ b/source/blender/blenkernel/intern/mball_tessellate.c
@@ -1373,13 +1373,10 @@ static void init_meta(Depsgraph *depsgraph, PROCESS 
*process, Scene *scene, Obje
 
 void BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob, 
ListBase *dispbase)
 {
-  MetaBall *mb;
-  DispList *dl;
-  unsigned int a;
   PROCESS process = {0};
-  bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
+  const bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
 
-  mb = ob->data;
+  MetaBall *mb = ob->data;
 
   process.thresh = mb->thresh;
 
@@ -1419,47 +1416,54 @@ void BKE_mball_polygonize(Depsgraph *depsgraph, Scene 
*scene, Object *ob, ListBa
 
   /* initialize all mainb (MetaElems) */
   init_meta(depsgraph, &process, scene, ob);
+  if (process.totelem == 0) {
+freepolygonize(&process);
+return;
+  }
 
-  if (process.totelem > 0) {
-build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, 
&process.allbb);
+  build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, 
&process.allbb);
 
-/* Don't polygonize meta-balls with too high resolution (base mball too 
small)
- * NOTE: Eps was 0.0001f but this was giving problems for blood animation 
for
- * the open movie "Sintel", using 0.1f. */
-if (ob->scale[0] > 0.1f * (process.allbb.max[0] - 
process.allbb.min[0]) ||
-ob->scale[1] > 0.1f * (process.allbb.max[1] - 
process.allbb.min[1]) ||
-ob->scale[2] > 0.1f * (process.allbb.max[2] - 
process.allbb.min[2])) {
-  polygonize(&process);
+  /* Don't polygonize meta-balls with too high resolution (base mball too 
small)
+   * NOTE: Eps was 0.0001f but this was giving problems for blood animation for
+   * the open movie "Sintel", using 0.1f. */
+  if (ob->scale[0] < 0.1f * (process.allbb.max[0] - process.allbb.min[0]) 
||
+  ob->scale[1] < 0.1f * (process.allbb.max[1] - process.allbb.min[1]) 
||
+  ob->scale[2] < 0.1f * (process.allbb.max[2] - process.allbb.min[2])) 
{
+freepolygonize(&process);
+return;
+  }
 
-  /* add resulting surface to displist */
-  if (process.curindex) {
+  polygonize(&process);
+  if (process.curindex == 0) {
+freepolygonize(&process);
+return;
+  }
 
-/* Avoid over-allocation since this is stored in the displist. */
-if (process.curindex != process.totindex) {
-  process.indices = MEM_reallocN(process.indices, sizeof(int[4]) * 
process.curindex);
-}
-if (process.curvertex != process.totvertex) {
-  process.co = MEM_reallocN(process.co, process.curvertex * 
sizeof(float[3]));
-  process.no = MEM_reallocN(process.no, process.curvertex * 
sizeof(float[3]));
-}
+  /* add resulting surface to displist */
 
-dl = MEM_callocN(sizeof(DispList), "mballdisp");
-BLI_addtail(dispbase, dl);
-dl->type = DL_INDEX4;
-dl->nr = (int)process.curvertex;
-dl->parts = (int)process.curindex;
+  /* Avoid over-allocation since this is stored in the displist. */
+  if (process.curindex != process.totindex) {
+process.indices = MEM_reallocN(process.indices, sizeof(int[4]) * 
process.curindex);
+  }
+  if (process.curvertex != process.totvertex) {
+process.co = MEM_reallocN(process.co, process.curvertex * 
sizeof(float[3]));
+process.no = MEM_reallocN(process.no, process.curvertex * 
sizeof(float[3]));
+  }
 
-dl->index = (int *)process.indices;
+  DispList *dl = MEM_callocN(sizeof(DispList), "mballdisp");
+  BLI_addtail(dispbase, dl);
+  dl->type = DL_INDEX4;
+  dl->nr = (int)process.curvertex;
+  dl->parts = (int)process.curindex;
 
-for (a = 0; a < process.curvertex; a++) {
-  normalize_v3(process.no[a]);
-}
+  dl->index = (int *)process.indices;
 
-dl->verts = (float *)process.co;
-dl->nors = (float *)process.no;
-  }
-}
+  for (uint a = 0; a < process.curvertex; a++) {
+normalize_v3(process.no[a]);
   }
 
+  dl->verts = (float *)process.co;
+  dl->nors = (float *)process.no;
+
   freepolygonize(&process);
 }

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

[Bf-blender-cvs] [a5beca7ba0d] master: BLI: inline fast path of IndexRange::as_span

2022-04-07 Thread Jacques Lucke
Commit: a5beca7ba0daaca81805dbbf8857378a5bde6414
Author: Jacques Lucke
Date:   Thu Apr 7 19:28:41 2022 +0200
Branches: master
https://developer.blender.org/rBa5beca7ba0daaca81805dbbf8857378a5bde6414

BLI: inline fast path of IndexRange::as_span

This frequently showed up in profiling but shouldn't.

This also updates the code to use atomics for more correctness and
adds multi-threading for better performance.

===

M   source/blender/blenlib/BLI_index_range.hh
M   source/blender/blenlib/BLI_span.hh
M   source/blender/blenlib/intern/BLI_index_range.cc

===

diff --git a/source/blender/blenlib/BLI_index_range.hh 
b/source/blender/blenlib/BLI_index_range.hh
index 85f2c83364b..7d5c2400bba 100644
--- a/source/blender/blenlib/BLI_index_range.hh
+++ b/source/blender/blenlib/BLI_index_range.hh
@@ -39,6 +39,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -288,6 +289,12 @@ class IndexRange {
 stream << "[" << range.start() << ", " << range.one_after_last() << ")";
 return stream;
   }
+
+ private:
+  static std::atomic s_current_array_size;
+  static std::atomic s_current_array;
+
+  Span as_span_internal() const;
 };
 
 }  // namespace blender
diff --git a/source/blender/blenlib/BLI_span.hh 
b/source/blender/blenlib/BLI_span.hh
index 9ab096094de..0f3fcea1270 100644
--- a/source/blender/blenlib/BLI_span.hh
+++ b/source/blender/blenlib/BLI_span.hh
@@ -722,4 +722,16 @@ template class MutableSpan {
   }
 };
 
+/** This is defined here, because in `BLI_index_range.hh` `Span` is not yet 
defined. */
+inline Span IndexRange::as_span() const
+{
+  const int64_t min_required_size = start_ + size_;
+  const int64_t current_array_size = 
s_current_array_size.load(std::memory_order_acquire);
+  const int64_t *current_array = 
s_current_array.load(std::memory_order_acquire);
+  if (min_required_size <= current_array_size) {
+return Span(current_array + start_, size_);
+  }
+  return this->as_span_internal();
+}
+
 } /* namespace blender */
diff --git a/source/blender/blenlib/intern/BLI_index_range.cc 
b/source/blender/blenlib/intern/BLI_index_range.cc
index 346f55d9405..398228ab461 100644
--- a/source/blender/blenlib/intern/BLI_index_range.cc
+++ b/source/blender/blenlib/intern/BLI_index_range.cc
@@ -1,46 +1,47 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
-#include 
 #include 
 
 #include "BLI_array.hh"
 #include "BLI_index_range.hh"
 #include "BLI_span.hh"
+#include "BLI_task.hh"
 #include "BLI_vector.hh"
 
 namespace blender {
 
 static RawVector> arrays;
-static int64_t current_array_size = 0;
-static int64_t *current_array = nullptr;
 static std::mutex current_array_mutex;
+std::atomic IndexRange::s_current_array_size = 0;
+std::atomic IndexRange::s_current_array = nullptr;
 
-Span IndexRange::as_span() const
+Span IndexRange::as_span_internal() const
 {
   int64_t min_required_size = start_ + size_;
 
-  if (min_required_size <= current_array_size) {
-return Span(current_array + start_, size_);
-  }
-
   std::lock_guard lock(current_array_mutex);
 
-  if (min_required_size <= current_array_size) {
-return Span(current_array + start_, size_);
+  /* Double checked lock. */
+  if (min_required_size <= s_current_array_size) {
+return Span(s_current_array + start_, size_);
   }
 
-  int64_t new_size = std::max(1000, 
power_of_2_max_u(min_required_size));
-  RawArray new_array(new_size);
-  for (int64_t i = 0; i < new_size; i++) {
-new_array[i] = i;
-  }
-  arrays.append(std::move(new_array));
-
-  current_array = arrays.last().data();
-  std::atomic_thread_fence(std::memory_order_seq_cst);
-  current_array_size = new_size;
-
-  return Span(current_array + start_, size_);
+  /* Isolate, because a mutex is locked. */
+  threading::isolate_task([&]() {
+int64_t new_size = std::max(1000, 
power_of_2_max_u(min_required_size));
+RawArray new_array(new_size);
+threading::parallel_for(IndexRange(new_size), 4096, [&](const IndexRange 
range) {
+  for (const int64_t i : range) {
+new_array[i] = i;
+  }
+});
+arrays.append(std::move(new_array));
+
+s_current_array.store(arrays.last().data(), std::memory_order_release);
+s_current_array_size.store(new_size, std::memory_order_release);
+  });
+
+  return Span(s_current_array + start_, size_);
 }
 
 }  // namespace blender

___
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] [ef0e84afc67] asset-greasepencil: Create custom Tooltip for GPencil

2022-04-07 Thread Antonio Vazquez
Commit: ef0e84afc671e6a0bbdee307a60125f122faa87c
Author: Antonio Vazquez
Date:   Thu Apr 7 19:18:07 2022 +0200
Branches: asset-greasepencil
https://developer.blender.org/rBef0e84afc671e6a0bbdee307a60125f122faa87c

Create custom Tooltip for GPencil

===

M   source/blender/editors/space_view3d/space_view3d.c

===

diff --git a/source/blender/editors/space_view3d/space_view3d.c 
b/source/blender/editors/space_view3d/space_view3d.c
index 9b0103030ef..3f0b84721e7 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -629,6 +629,14 @@ static char *view3d_object_data_drop_tooltip(bContext 
*UNUSED(C),
   return BLI_strdup(TIP_("Create object instance from object-data"));
 }
 
+static char *view3d_gpencil_data_drop_tooltip(bContext *UNUSED(C),
+  wmDrag *UNUSED(drag),
+  const int UNUSED(xy[2]),
+  wmDropBox *UNUSED(drop))
+{
+  return BLI_strdup(TIP_("Add strokes to active object"));
+}
+
 static bool view3d_ima_drop_poll(bContext *C, wmDrag *drag, const wmEvent 
*event)
 {
   if (ED_region_overlap_isect_any_xy(CTX_wm_area(C), event->xy)) {
@@ -954,7 +962,7 @@ static void view3d_dropboxes(void)
  view3d_gpencil_drop_poll,
  view3d_id_drop_copy_with_type,
  WM_drag_free_imported_drag_ID,
- view3d_object_data_drop_tooltip);
+ view3d_gpencil_data_drop_tooltip);
 }
 
 static void view3d_widgets(void)

___
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] [67c42e7f034] master: Functions: optimize simple generated multi-functions

2022-04-07 Thread Jacques Lucke
Commit: 67c42e7f034aad2564d8cde1a9901d9629527daa
Author: Jacques Lucke
Date:   Thu Apr 7 18:48:14 2022 +0200
Branches: master
https://developer.blender.org/rB67c42e7f034aad2564d8cde1a9901d9629527daa

Functions: optimize simple generated multi-functions

This implements two optimizations:
* Reduce virtual function call overhead when a non-standard virtual
  array is used as input.
* Use a lambda in `type_conversion.cc`.

In my test setup, which creates a float attribute filled with the index,
the running time drops from `4.0 ms` to `2.0 ms`.

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

===

M   source/blender/blenkernel/intern/type_conversions.cc
M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/blenkernel/intern/type_conversions.cc 
b/source/blender/blenkernel/intern/type_conversions.cc
index d109799..aa79199d668 100644
--- a/source/blender/blenkernel/intern/type_conversions.cc
+++ b/source/blender/blenkernel/intern/type_conversions.cc
@@ -18,7 +18,11 @@ static void add_implicit_conversion(DataTypeConversions 
&conversions)
   static const CPPType &to_type = CPPType::get();
   static const std::string conversion_name = from_type.name() + " to " + 
to_type.name();
 
-  static fn::CustomMF_SI_SO multi_function{conversion_name.c_str(), 
ConversionF};
+  static fn::CustomMF_SI_SO multi_function{
+  conversion_name.c_str(),
+  /* Use lambda instead of passing #ConversionF directly, because 
otherwise the compiler won't
+ inline the function. */
+  [](const From &a) { return ConversionF(a); }};
   static auto convert_single_to_initialized = [](const void *src, void *dst) {
 *(To *)dst = ConversionF(*(const From *)src);
   };
diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index b041e67390c..ed587a87695 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -47,11 +47,46 @@ template class CustomMF_SI_SO 
: public MultiFunctio
   template static FunctionT 
create_function(ElementFuncT element_fn)
   {
 return [=](IndexMask mask, const VArray &in1, MutableSpan out1) 
{
-  /* Devirtualization results in a 2-3x speedup for some simple functions. 
*/
-  devirtualize_varray(in1, [&](const auto &in1) {
+  if (in1.is_single()) {
+/* Only evaluate the function once when the input is a single value. */
+const In1 in1_single = in1.get_internal_single();
+const Out1 out1_single = element_fn(in1_single);
+out1.fill_indices(mask, out1_single);
+return;
+  }
+
+  if (in1.is_span()) {
+const Span in1_span = in1.get_internal_span();
 mask.to_best_mask_type(
-[&](const auto &mask) { execute_SI_SO(element_fn, mask, in1, 
out1.data()); });
-  });
+[&](auto mask) { execute_SI_SO(element_fn, mask, in1_span, 
out1.data()); });
+return;
+  }
+
+  /* The input is an unknown virtual array type. To avoid virtual function 
call overhead for
+   * every element, elements are retrieved and processed in chunks. */
+
+  static constexpr int64_t MaxChunkSize = 32;
+  TypedBuffer in1_buffer_owner;
+  MutableSpan in1_buffer{in1_buffer_owner.ptr(), MaxChunkSize};
+
+  const int64_t mask_size = mask.size();
+  for (int64_t chunk_start = 0; chunk_start < mask_size; chunk_start += 
MaxChunkSize) {
+const int64_t chunk_size = std::min(mask_size - chunk_start, 
MaxChunkSize);
+const IndexMask sliced_mask = mask.slice(chunk_start, chunk_size);
+
+/* Load input from the virtual array. */
+MutableSpan in1_chunk = in1_buffer.take_front(chunk_size);
+in1.materialize_compressed_to_uninitialized(sliced_mask, in1_chunk);
+
+if (sliced_mask.is_range()) {
+  execute_SI_SO(
+  element_fn, IndexRange(chunk_size), in1_chunk, out1.data() + 
sliced_mask[0]);
+}
+else {
+  execute_SI_SO_compressed(element_fn, sliced_mask, in1_chunk, 
out1.data());
+}
+destruct_n(in1_chunk.data(), chunk_size);
+  }
 };
   }
 
@@ -66,6 +101,18 @@ template class CustomMF_SI_SO 
: public MultiFunctio
 }
   }
 
+  /** Expects the input array to be "compressed", i.e. there are no gaps 
between the elements. */
+  template
+  BLI_NOINLINE static void execute_SI_SO_compressed(const ElementFuncT 
&element_fn,
+MaskT mask,
+const In1Array &in1,
+Out1 *__restrict r_out)
+  {
+for (const int64_t i : IndexRange(mask.size())) {
+  new (r_out + mask[i]) Out1(element_fn(in1[i]));
+}
+  }
+
   void call(Inde

[Bf-blender-cvs] [8f344b530a6] master: Geometry Nodes: Parallelize mesh line node

2022-04-07 Thread Hans Goudey
Commit: 8f344b530a6ed8530ceb780110006af68430c9d5
Author: Hans Goudey
Date:   Thu Apr 7 11:44:32 2022 -0500
Branches: master
https://developer.blender.org/rB8f344b530a6ed8530ceb780110006af68430c9d5

Geometry Nodes: Parallelize mesh line node

I observed a 4-5x performance improvement (from 50ms to 12ms)
with five million points, though obviously the change depends on
the hardware.

In the future we may want to disable the parallelization in
`parallel_invoke` when there is a small amount of points.

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

===

M   source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc

===

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index cbad4544860..8c1dea90f44 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -169,15 +169,6 @@ static void node_geo_exec(GeoNodeExecParams params)
 
 namespace blender::nodes {
 
-static void fill_edge_data(MutableSpan edges)
-{
-  for (const int i : edges.index_range()) {
-edges[i].v1 = i;
-edges[i].v2 = i + 1;
-edges[i].flag |= ME_LOOSEEDGE;
-  }
-}
-
 Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
 {
   if (count < 1) {
@@ -189,11 +180,23 @@ Mesh *create_line_mesh(const float3 start, const float3 
delta, const int count)
   MutableSpan verts{mesh->mvert, mesh->totvert};
   MutableSpan edges{mesh->medge, mesh->totedge};
 
-  for (const int i : verts.index_range()) {
-copy_v3_v3(verts[i].co, start + delta * i);
-  }
-
-  fill_edge_data(edges);
+  threading::parallel_invoke(
+  [&]() {
+threading::parallel_for(verts.index_range(), 4096, [&](IndexRange 
range) {
+  for (const int i : range) {
+copy_v3_v3(verts[i].co, start + delta * i);
+  }
+});
+  },
+  [&]() {
+threading::parallel_for(edges.index_range(), 4096, [&](IndexRange 
range) {
+  for (const int i : range) {
+edges[i].v1 = i;
+edges[i].v2 = i + 1;
+edges[i].flag |= ME_LOOSEEDGE;
+  }
+});
+  });
 
   return mesh;
 }

___
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] [4b94d972ac6] asset-greasepencil: Cleanup code

2022-04-07 Thread Antonio Vazquez
Commit: 4b94d972ac632d8eba8bc4f63030b3c195a310a8
Author: Antonio Vazquez
Date:   Thu Apr 7 18:02:57 2022 +0200
Branches: asset-greasepencil
https://developer.blender.org/rB4b94d972ac632d8eba8bc4f63030b3c195a310a8

Cleanup code

===

M   source/blender/editors/gpencil/gpencil_asset.c

===

diff --git a/source/blender/editors/gpencil/gpencil_asset.c 
b/source/blender/editors/gpencil/gpencil_asset.c
index 65ef5e42e94..fc12d70d535 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -1235,12 +1235,33 @@ static void gpencil_asset_import_exit(bContext *C, 
wmOperator *op)
   op->customdata = NULL;
 }
 
-/* Init new temporary data. */
-static bool gpencil_asset_import_set_init_values(bContext *C,
- const wmOperator *op,
- ID *id,
- tGPDasset *tgpa)
+/* Allocate memory and initialize values */
+static tGPDasset *gpencil_session_init_asset_import(bContext *C, wmOperator 
*op)
 {
+  Main *bmain = CTX_data_main(C);
+  ID *id = NULL;
+
+  PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
+  PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
+
+  /* These shouldn't fail when created by outliner dropping as it checks the 
ID is valid. */
+  if (!RNA_property_is_set(op->ptr, prop_name) || 
!RNA_property_is_set(op->ptr, prop_type)) {
+return NULL;
+  }
+  const short id_type = RNA_property_enum_get(op->ptr, prop_type);
+  char name[MAX_ID_NAME - 2];
+  RNA_property_string_get(op->ptr, prop_name, name);
+  id = BKE_libblock_find_name(bmain, id_type, name);
+  if (id == NULL) {
+return NULL;
+  }
+  const int object_type = BKE_object_obdata_to_type(id);
+  if (object_type != OB_GPENCIL) {
+return NULL;
+  }
+
+  tGPDasset *tgpa = MEM_callocN(sizeof(tGPDasset), "GPencil Asset Import 
Data");
+
   /* Save current settings. */
   tgpa->win = CTX_wm_window(C);
   tgpa->bmain = CTX_data_main(C);
@@ -1270,40 +1291,6 @@ static bool 
gpencil_asset_import_set_init_values(bContext *C,
   tgpa->data_len = 0;
   tgpa->data = NULL;
 
-  return true;
-}
-
-/* Allocate memory and initialize values */
-static tGPDasset *gpencil_session_init_asset_import(bContext *C, wmOperator 
*op)
-{
-  Main *bmain = CTX_data_main(C);
-  ID *id = NULL;
-
-  PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
-  PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
-
-  /* These shouldn't fail when created by outliner dropping as it checks the 
ID is valid. */
-  if (!RNA_property_is_set(op->ptr, prop_name) || 
!RNA_property_is_set(op->ptr, prop_type)) {
-return NULL;
-  }
-  const short id_type = RNA_property_enum_get(op->ptr, prop_type);
-  char name[MAX_ID_NAME - 2];
-  RNA_property_string_get(op->ptr, prop_name, name);
-  id = BKE_libblock_find_name(bmain, id_type, name);
-  if (id == NULL) {
-return NULL;
-  }
-  const int object_type = BKE_object_obdata_to_type(id);
-  if (object_type != OB_GPENCIL) {
-return NULL;
-  }
-
-  tGPDasset *tgpa = MEM_callocN(sizeof(tGPDasset), "GPencil Asset Import 
Data");
-
-  /* Save initial values. */
-  gpencil_asset_import_set_init_values(C, op, id, tgpa);
-
-  /* return context data for running operator */
   return tgpa;
 }

___
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] [f8c21937d2b] master: GPencil: Add skip option to envelope modifier

2022-04-07 Thread Henrik Dick
Commit: f8c21937d2ba1140533c5e6f70426099f9680609
Author: Henrik Dick
Date:   Thu Apr 7 17:41:49 2022 +0200
Branches: master
https://developer.blender.org/rBf8c21937d2ba1140533c5e6f70426099f9680609

GPencil: Add skip option to envelope modifier

This patch adds an option to only use every n-th segment of the
envelope result. This can be used to reduce the complexity of the
result.

Differential Revision: http://developer.blender.org/D14503

===

M   source/blender/gpencil_modifiers/intern/MOD_gpencilenvelope.c
M   source/blender/makesdna/DNA_gpencil_modifier_defaults.h
M   source/blender/makesdna/DNA_gpencil_modifier_types.h
M   source/blender/makesrna/intern/rna_gpencil_modifier.c

===

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilenvelope.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencilenvelope.c
index f8ac8d95493..d9881f5b7ae 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilenvelope.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilenvelope.c
@@ -332,18 +332,17 @@ static void add_stroke(Object *ob,
bGPDstroke *gps,
const int point_index,
const int connection_index,
-   const int size,
+   const int size2,
+   const int size1,
const int mat_nr,
const float thickness,
const float strength,
ListBase *results)
 {
+  const int size = size1 + size2;
   bGPdata *gpd = ob->data;
   bGPDstroke *gps_dst = BKE_gpencil_stroke_new(mat_nr, size, gps->thickness);
 
-  const int size1 = size == 4 ? 2 : 1;
-  const int size2 = size - size1;
-
   memcpy(&gps_dst->points[0], &gps->points[connection_index], size1 * 
sizeof(bGPDspoint));
   memcpy(&gps_dst->points[size1], &gps->points[point_index], size2 * 
sizeof(bGPDspoint));
 
@@ -369,35 +368,36 @@ static void add_stroke_cyclic(Object *ob,
   bGPDstroke *gps,
   const int point_index,
   const int connection_index,
+  const int size,
   const int mat_nr,
   const float thickness,
   const float strength,
   ListBase *results)
 {
   bGPdata *gpd = ob->data;
-  bGPDstroke *gps_dst = BKE_gpencil_stroke_new(mat_nr, 4, gps->thickness);
+  bGPDstroke *gps_dst = BKE_gpencil_stroke_new(mat_nr, size * 2, 
gps->thickness);
+  if (gps->dvert != NULL) {
+gps_dst->dvert = MEM_malloc_arrayN(size * 2, sizeof(MDeformVert), 
__func__);
+  }
 
-  int connection_index2 = (connection_index + 1) % gps->totpoints;
-  int point_index2 = (point_index + 1) % gps->totpoints;
+  for (int i = 0; i < size; i++) {
+int a = (connection_index + i) % gps->totpoints;
+int b = (point_index + i) % gps->totpoints;
 
-  gps_dst->points[0] = gps->points[connection_index];
-  gps_dst->points[1] = gps->points[connection_index2];
-  gps_dst->points[2] = gps->points[point_index];
-  gps_dst->points[3] = gps->points[point_index2];
-  for (int i = 0; i < 4; i++) {
+gps_dst->points[i] = gps->points[a];
+gps_dst->points[size + i] = gps->points[b];
+
+if (gps->dvert != NULL) {
+  BKE_defvert_array_copy(&gps_dst->dvert[i], &gps->dvert[a], 1);
+  BKE_defvert_array_copy(&gps_dst->dvert[size + i], &gps->dvert[b], 1);
+}
+  }
+  for (int i = 0; i < size * 2; i++) {
 gps_dst->points[i].pressure *= thickness;
 gps_dst->points[i].strength *= strength;
 memset(&gps_dst->points[i].runtime, 0, sizeof(bGPDspoint_Runtime));
   }
 
-  if (gps->dvert != NULL) {
-gps_dst->dvert = MEM_malloc_arrayN(4, sizeof(MDeformVert), __func__);
-BKE_defvert_array_copy(&gps_dst->dvert[0], &gps->dvert[connection_index], 
1);
-BKE_defvert_array_copy(&gps_dst->dvert[1], &gps->dvert[connection_index2], 
1);
-BKE_defvert_array_copy(&gps_dst->dvert[2], &gps->dvert[point_index], 1);
-BKE_defvert_array_copy(&gps_dst->dvert[3], &gps->dvert[point_index2], 1);
-  }
-
   BLI_addtail(results, gps_dst);
 
   /* Calc geometry data. */
@@ -459,31 +459,41 @@ static void generate_geometry(GpencilModifierData *md, 
Object *ob, bGPDlayer *gp
 
 const int mat_nr = mmd->mat_nr < 0 ? gps->mat_nr : min_ii(mmd->mat_nr, 
ob->totcol - 1);
 if (mmd->mode == GP_ENVELOPE_FILLS) {
+  const int skip = min_ii(mmd->skip, min_ii(mmd->spread / 2, 
gps->totpoints - 2));
   if (gps->flag & GP_STROKE_CYCLIC) {
 for (int i = 0; i < gps->totpoints; i++) {
-  const int connection_index = (i + mmd->spread) % gps->totpoints;
-  add_stroke_cyclic(
-  ob, gps, i, connection_index, mat_nr, mmd->thickness, 
mmd->strength, &duplicates);
+  

[Bf-blender-cvs] [09bb0fffe5b] asset-greasepencil: Fix possible use of NULL pointer

2022-04-07 Thread Antonio Vazquez
Commit: 09bb0fffe5b30c57aca9f9407035774e22c3a5b0
Author: Antonio Vazquez
Date:   Thu Apr 7 17:29:45 2022 +0200
Branches: asset-greasepencil
https://developer.blender.org/rB09bb0fffe5b30c57aca9f9407035774e22c3a5b0

Fix possible use of NULL pointer

===

M   source/blender/editors/gpencil/gpencil_asset.c

===

diff --git a/source/blender/editors/gpencil/gpencil_asset.c 
b/source/blender/editors/gpencil/gpencil_asset.c
index 7f144d4da97..65ef5e42e94 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -1209,9 +1209,10 @@ static void gpencil_asset_import_update(bContext *C, 
const wmOperator *op, tGPDa
 static void gpencil_asset_import_exit(bContext *C, wmOperator *op)
 {
   tGPDasset *tgpa = op->customdata;
-  bGPdata *gpd = tgpa->gpd;
 
   if (tgpa) {
+bGPdata *gpd = tgpa->gpd;
+
 /* Clear status message area. */
 ED_area_status_text(tgpa->area, NULL);
 ED_workspace_status_text(C, NULL);
@@ -1225,8 +1226,9 @@ static void gpencil_asset_import_exit(bContext *C, 
wmOperator *op)
 }
 
 MEM_SAFE_FREE(tgpa);
+DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
   }
-  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+
   WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED | ND_DATA, NULL);
 
   /* Clear pointer. */

___
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] [1a09024eacb] master: Cleanup: Compilation warning about virtual functions

2022-04-07 Thread Sergey Sharybin
Commit: 1a09024eacbdfa52b3ec669f2bdea313a06b82db
Author: Sergey Sharybin
Date:   Thu Apr 7 17:14:47 2022 +0200
Branches: master
https://developer.blender.org/rB1a09024eacbdfa52b3ec669f2bdea313a06b82db

Cleanup: Compilation warning about virtual functions

Method which overrides a base class's virtual methods are expetced to
be marked with `override`. This also gives better idea to the developers
about what is going on.

===

M   source/blender/blenlib/BLI_virtual_array.hh
M   source/blender/blenlib/intern/generic_virtual_array.cc

===

diff --git a/source/blender/blenlib/BLI_virtual_array.hh 
b/source/blender/blenlib/BLI_virtual_array.hh
index 206e0191a54..27bb04f5796 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -295,7 +295,7 @@ template class VArrayImpl_For_Span : public 
VMutableArrayImpl {
 return data_ == other_span.data();
   }
 
-  void materialize_compressed(IndexMask mask, MutableSpan r_span) const
+  void materialize_compressed(IndexMask mask, MutableSpan r_span) const 
override
   {
 mask.to_best_mask_type([&](auto best_mask) {
   for (const int64_t i : IndexRange(best_mask.size())) {
@@ -304,7 +304,8 @@ template class VArrayImpl_For_Span : public 
VMutableArrayImpl {
 });
   }
 
-  void materialize_compressed_to_uninitialized(IndexMask mask, MutableSpan 
r_span) const
+  void materialize_compressed_to_uninitialized(IndexMask mask,
+   MutableSpan r_span) const 
override
   {
 T *dst = r_span.data();
 mask.to_best_mask_type([&](auto best_mask) {
diff --git a/source/blender/blenlib/intern/generic_virtual_array.cc 
b/source/blender/blenlib/intern/generic_virtual_array.cc
index 6cdbbde671a..e1a150c3f08 100644
--- a/source/blender/blenlib/intern/generic_virtual_array.cc
+++ b/source/blender/blenlib/intern/generic_virtual_array.cc
@@ -279,12 +279,12 @@ class GVArrayImpl_For_SingleValueRef : public GVArrayImpl 
{
 type_->fill_construct_indices(value_, dst, mask);
   }
 
-  void materialize_compressed(const IndexMask mask, void *dst) const
+  void materialize_compressed(const IndexMask mask, void *dst) const override
   {
 type_->fill_assign_n(value_, dst, mask.size());
   }
 
-  void materialize_compressed_to_uninitialized(const IndexMask mask, void 
*dst) const
+  void materialize_compressed_to_uninitialized(const IndexMask mask, void 
*dst) const override
   {
 type_->fill_construct_n(value_, dst, mask.size());
   }

___
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] [618e48b657d] asset-greasepencil: Merge branch 'master' into asset-greasepencil

2022-04-07 Thread Antonio Vazquez
Commit: 618e48b657d7049a6191d305c486607510ae23a5
Author: Antonio Vazquez
Date:   Thu Apr 7 17:00:52 2022 +0200
Branches: asset-greasepencil
https://developer.blender.org/rB618e48b657d7049a6191d305c486607510ae23a5

Merge branch 'master' into asset-greasepencil

===



===



___
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] [22e102efae7] temp-collection-assets: Merge branch 'master' into temp-collection-assets

2022-04-07 Thread Julian Eisel
Commit: 22e102efae70cd50f5f49d93c8df22185cb4dc76
Author: Julian Eisel
Date:   Thu Apr 7 15:03:42 2022 +0200
Branches: temp-collection-assets
https://developer.blender.org/rB22e102efae70cd50f5f49d93c8df22185cb4dc76

Merge branch 'master' into temp-collection-assets

===



===

diff --cc source/blender/editors/object/object_add.cc
index 000,b3c5879b4d0..8cad98ab4ae
mode 00,100644..100644
--- a/source/blender/editors/object/object_add.cc
+++ b/source/blender/editors/object/object_add.cc
@@@ -1,0 -1,4089 +1,4089 @@@
+ /* SPDX-License-Identifier: GPL-2.0-or-later
+  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
+ 
+ /** \file
+  * \ingroup edobj
+  */
+ 
+ #include 
+ #include 
+ #include 
+ #include 
+ 
+ #include "MEM_guardedalloc.h"
+ 
+ #include "DNA_anim_types.h"
+ #include "DNA_camera_types.h"
+ #include "DNA_collection_types.h"
+ #include "DNA_curve_types.h"
+ #include "DNA_gpencil_modifier_types.h"
+ #include "DNA_gpencil_types.h"
+ #include "DNA_key_types.h"
+ #include "DNA_light_types.h"
+ #include "DNA_lightprobe_types.h"
+ #include "DNA_material_types.h"
+ #include "DNA_mesh_types.h"
+ #include "DNA_meta_types.h"
+ #include "DNA_object_fluidsim_types.h"
+ #include "DNA_object_force_types.h"
+ #include "DNA_object_types.h"
+ #include "DNA_pointcloud_types.h"
+ #include "DNA_scene_types.h"
+ #include "DNA_vfont_types.h"
+ 
+ #include "BLI_ghash.h"
+ #include "BLI_listbase.h"
+ #include "BLI_math.h"
+ #include "BLI_string.h"
+ #include "BLI_utildefines.h"
+ 
+ #include "BLT_translation.h"
+ 
+ #include "BKE_action.h"
+ #include "BKE_anim_data.h"
+ #include "BKE_armature.h"
+ #include "BKE_camera.h"
+ #include "BKE_collection.h"
+ #include "BKE_constraint.h"
+ #include "BKE_context.h"
+ #include "BKE_curve.h"
+ #include "BKE_curves.h"
+ #include "BKE_displist.h"
+ #include "BKE_duplilist.h"
+ #include "BKE_effect.h"
+ #include "BKE_geometry_set.h"
+ #include "BKE_gpencil_curve.h"
+ #include "BKE_gpencil_geom.h"
+ #include "BKE_gpencil_modifier.h"
+ #include "BKE_key.h"
+ #include "BKE_lattice.h"
+ #include "BKE_layer.h"
+ #include "BKE_lib_id.h"
+ #include "BKE_lib_override.h"
+ #include "BKE_lib_query.h"
+ #include "BKE_lib_remap.h"
+ #include "BKE_light.h"
+ #include "BKE_lightprobe.h"
+ #include "BKE_main.h"
+ #include "BKE_material.h"
+ #include "BKE_mball.h"
+ #include "BKE_mesh.h"
+ #include "BKE_mesh_runtime.h"
+ #include "BKE_nla.h"
+ #include "BKE_object.h"
+ #include "BKE_particle.h"
+ #include "BKE_pointcloud.h"
+ #include "BKE_report.h"
+ #include "BKE_scene.h"
+ #include "BKE_speaker.h"
+ #include "BKE_vfont.h"
+ #include "BKE_volume.h"
+ 
+ #include "DEG_depsgraph.h"
+ #include "DEG_depsgraph_build.h"
+ #include "DEG_depsgraph_query.h"
+ 
+ #include "RNA_access.h"
+ #include "RNA_define.h"
+ #include "RNA_enum_types.h"
+ 
+ #include "UI_interface.h"
+ 
+ #include "WM_api.h"
+ #include "WM_types.h"
+ 
+ #include "ED_armature.h"
+ #include "ED_curve.h"
+ #include "ED_curves.h"
+ #include "ED_gpencil.h"
+ #include "ED_mball.h"
+ #include "ED_mesh.h"
+ #include "ED_node.h"
+ #include "ED_object.h"
+ #include "ED_outliner.h"
+ #include "ED_physics.h"
+ #include "ED_render.h"
+ #include "ED_screen.h"
+ #include "ED_select_utils.h"
+ #include "ED_transform.h"
+ #include "ED_view3d.h"
+ 
+ #include "UI_resources.h"
+ 
+ #include "object_intern.h"
+ 
+ /*  */
+ /** \name Local Enum Declarations
+  * \{ */
+ 
+ /* This is an exact copy of the define in `rna_light.c`
+  * kept here because of linking order.
+  * Icons are only defined here */
+ const EnumPropertyItem rna_enum_light_type_items[] = {
+ {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point 
light source"},
+ {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray 
light source"},
+ {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light 
source"},
+ {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light 
source"},
+ {0, nullptr, 0, nullptr, nullptr},
+ };
+ 
+ /* copy from rna_object_force.c */
+ static const EnumPropertyItem field_type_items[] = {
+ {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""},
+ {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""},
+ {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""},
+ {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""},
+ {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""},
+ {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""},
+ {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", 
""},
+ {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""},
+ {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""},
+ {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""},
+ {PFIELD_TURBULENCE, "TURB

[Bf-blender-cvs] [a6896bda899] temp-collection-assets: Port to new operator with instancing option from master

2022-04-07 Thread Julian Eisel
Commit: a6896bda8999f61816dd8171225486dc3ee160be
Author: Julian Eisel
Date:   Thu Apr 7 16:08:40 2022 +0200
Branches: temp-collection-assets
https://developer.blender.org/rBa6896bda8999f61816dd8171225486dc3ee160be

Port to new operator with instancing option from master

===

M   source/blender/editors/space_view3d/space_view3d.c

===

diff --git a/source/blender/editors/space_view3d/space_view3d.c 
b/source/blender/editors/space_view3d/space_view3d.c
index 4ae39440a12..bbe96ae7b76 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -834,46 +834,6 @@ static void view3d_collection_drop_matrix_get(const 
Collection *collection,
   view3d_drop_matrix_from_snap(snap_state, &boundbox, unit_mat, r_mat_final);
 }
 
-static void view3d_collection_instance_drop_copy_external_asset(wmDrag *drag, 
wmDropBox *drop)
-{
-  wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
-  bContext *C = asset_drag->evil_C;
-  Scene *scene = CTX_data_scene(C);
-  ViewLayer *view_layer = CTX_data_view_layer(C);
-
-  BKE_view_layer_base_deselect_all(view_layer);
-
-  ID *id = WM_drag_asset_id_import_ex(asset_drag, FILE_AUTOSELECT, true);
-  /* `FILE_AUTOSELECT` causes the collection instance to be both selected and 
active. */
-
-  /* TODO(sergey): Only update relations for the current scene. */
-  DEG_relations_tag_update(CTX_data_main(C));
-  DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
-  WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
-  ED_outliner_select_sync_from_object_tag(C);
-
-  float mat[4][4];
-  view3d_collection_drop_matrix_get((Collection *)id, mat);
-  RNA_float_set_array(drop->ptr, "matrix", &mat[0][0]);
-}
-
-static void view3d_collection_drop_copy_local_id(wmDrag *drag, wmDropBox *drop)
-{
-  ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR);
-
-  float mat[4][4];
-  view3d_collection_drop_matrix_get((Collection *)id, mat);
-
-  float loc[3], rot_quat[4], rot_eul[3], scale[3];
-  mat4_decompose(loc, rot_quat, scale, mat);
-  quat_to_eul(rot_eul, rot_quat);
-  RNA_float_set_array(drop->ptr, "location", loc);
-  RNA_float_set_array(drop->ptr, "rotation", rot_eul);
-  RNA_float_set_array(drop->ptr, "scale", scale);
-
-  RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid);
-}
-
 /* Mostly the same logic as #view3d_ob_drop_copy_external_asset(), just 
different enough to make
  * sharing code a bit difficult. */
 static void view3d_collection_drop_copy_external_asset(wmDrag *drag, wmDropBox 
*drop)
@@ -907,11 +867,39 @@ static void 
view3d_collection_drop_copy_external_asset(wmDrag *drag, wmDropBox *
   DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
   ED_outliner_select_sync_from_object_tag(C);
 
+  float mat[4][4];
+  view3d_collection_drop_matrix_get(collection, mat);
+
+  float loc[3], rot_quat[4], rot_eul[3], scale[3];
+  mat4_decompose(loc, rot_quat, scale, mat);
+  add_v3_v3(loc, collection->instance_offset);
+  quat_to_eul(rot_eul, rot_quat);
+  RNA_float_set_array(drop->ptr, "location", loc);
+  RNA_float_set_array(drop->ptr, "rotation", rot_eul);
+  RNA_float_set_array(drop->ptr, "scale", scale);
+
   /* XXX Without an undo push here, there will be a crash when the user 
modifies operator
* properties. The stuff we do in these drop callbacks just isn't safe over 
undo/redo. */
   ED_undo_push(C, "Collection_Drop");
 }
 
+static void view3d_collection_drop_copy_local_id(wmDrag *drag, wmDropBox *drop)
+{
+  ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR);
+
+  float mat[4][4];
+  view3d_collection_drop_matrix_get((Collection *)id, mat);
+
+  float loc[3], rot_quat[4], rot_eul[3], scale[3];
+  mat4_decompose(loc, rot_quat, scale, mat);
+  quat_to_eul(rot_eul, rot_quat);
+  RNA_float_set_array(drop->ptr, "location", loc);
+  RNA_float_set_array(drop->ptr, "rotation", rot_eul);
+  RNA_float_set_array(drop->ptr, "scale", scale);
+
+  RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid);
+}
+
 static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
   ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
@@ -1001,33 +989,16 @@ static void view3d_dropboxes(void)
   drop->draw_activate = view3d_boundbox_drop_draw_activate_collection;
   drop->draw_deactivate = view3d_boundbox_drop_draw_deactivate;
 
-  /* Collection asset from external file (adds collection instance). */
-  drop = WM_dropbox_add(
-  lb,
-  /* Use OBJECT_OT_transform_to_mouse for collection instances as well, to 
transform the
-   * instance empty. Just needs different callbacks than objects. */
-  "OBJECT_OT_transform_to_mouse",
-  view3d_collection_drop_poll_external_asset,
-  view3d_collection_instance_drop_copy_external_asset,
-  WM_drag_free_imported_drag_ID,
-  NULL);
+  drop = WM_dropbox_add(lb,
+

[Bf-blender-cvs] [9db15f502c1] master: Fix T97123: Applying modifier to multi-user: other objects were also converted

2022-04-07 Thread Dalai Felinto
Commit: 9db15f502c105f96f0ec939dd2fc79f4567a4bf7
Author: Dalai Felinto
Date:   Thu Apr 7 14:51:59 2022 +0200
Branches: master
https://developer.blender.org/rB9db15f502c105f96f0ec939dd2fc79f4567a4bf7

Fix T97123: Applying modifier to multi-user: other objects were also converted

The first element of the iterator was not being tested against the flag.
So in some cases it would lead to more objects been made into
single-user than the active (or selected) ones.

===

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

===

diff --git a/source/blender/blenkernel/intern/collection.c 
b/source/blender/blenkernel/intern/collection.c
index c215321bc30..939f7c7b3ff 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1929,6 +1929,26 @@ void BKE_scene_objects_iterator_begin(BLI_Iterator 
*iter, void *data_in)
   scene_objects_iterator_begin(iter, scene, NULL);
 }
 
+static void scene_objects_iterator_skip_invalid_flag(BLI_Iterator *iter)
+{
+  if (!iter->valid) {
+return;
+  }
+
+  /* Unpack the data. */
+  SceneObjectsIteratorExData *data = iter->data;
+  iter->data = data->iter_data;
+
+  Object *ob = iter->current;
+  if (ob && (ob->flag & data->flag) == 0) {
+iter->skip = true;
+  }
+
+  /* Pack the data. */
+  data->iter_data = iter->data;
+  iter->data = data;
+}
+
 void BKE_scene_objects_iterator_begin_ex(BLI_Iterator *iter, void *data_in)
 {
   SceneObjectsIteratorExData *data = data_in;
@@ -1938,6 +1958,8 @@ void BKE_scene_objects_iterator_begin_ex(BLI_Iterator 
*iter, void *data_in)
   /* Pack the data. */
   data->iter_data = iter->data;
   iter->data = data_in;
+
+  scene_objects_iterator_skip_invalid_flag(iter);
 }
 
 void BKE_scene_objects_iterator_next_ex(struct BLI_Iterator *iter)
@@ -1948,14 +1970,11 @@ void BKE_scene_objects_iterator_next_ex(struct 
BLI_Iterator *iter)
 
   BKE_scene_objects_iterator_next(iter);
 
-  Object *ob = iter->current;
-  if (ob && (ob->flag & data->flag) == 0) {
-iter->skip = true;
-  }
-
   /* Pack the data. */
   data->iter_data = iter->data;
   iter->data = data;
+
+  scene_objects_iterator_skip_invalid_flag(iter);
 }
 
 void BKE_scene_objects_iterator_end_ex(struct BLI_Iterator *iter)

___
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] [80b5f27d232] lineart-shadow: LineArt: Adapt new object loading changes.

2022-04-07 Thread YimingWu
Commit: 80b5f27d232e18890156ad79bf8eebab1475b6fc
Author: YimingWu
Date:   Thu Apr 7 20:24:48 2022 +0800
Branches: lineart-shadow
https://developer.blender.org/rB80b5f27d232e18890156ad79bf8eebab1475b6fc

LineArt: Adapt new object loading changes.

===

M   source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c

===

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c 
b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 256bd2ea776..93ba4e238f4 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -482,10 +482,6 @@ static void lineart_occlusion_worker(TaskPool *__restrict 
UNUSED(pool), LineartR
   eip = rti->pending_edges.array[i];
   lineart_occlusion_single_line(rb, eip, rti->thread_id);
 }
-
-for (eip = rti->shadow.first; eip && eip != rti->shadow.last; eip = 
eip->next) {
-  lineart_occlusion_single_line(rb, eip, rti->thread_id);
-}
   }
 }
 
@@ -3894,6 +3890,8 @@ static void 
lineart_destroy_render_data_keep_init(LineartRenderBuffer *rb)
   BLI_listbase_clear(&rb->line_buffer_pointers);
   BLI_listbase_clear(&rb->triangle_buffer_pointers);
 
+  MEM_freeN(rb->pending_edges.array);
+
   lineart_mem_destroy(&rb->render_data_pool);
 }
 
@@ -5950,7 +5948,7 @@ static void 
lineart_transform_and_add_shadow(LineartRenderBuffer *rb,
   }
   LineartEdge *e = eeln->pointer;
   for (int i = 0; i < eeln->element_count; i++) {
-lineart_add_edge_to_list(rb, &e[i]);
+lineart_add_edge_to_list(&rb->pending_edges, &e[i]);
   }
   BLI_addtail(&rb->vertex_buffer_pointers, veln);
   BLI_addtail(&rb->line_buffer_pointers, eeln);

___
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] [27c8f7eeb39] lineart-shadow: LineArt: Separate cast shadow and light contour in shadow edge loading.

2022-04-07 Thread YimingWu
Commit: 27c8f7eeb3936193c69a968d4beed2e5c58599aa
Author: YimingWu
Date:   Thu Apr 7 21:00:06 2022 +0800
Branches: lineart-shadow
https://developer.blender.org/rB27c8f7eeb3936193c69a968d4beed2e5c58599aa

LineArt: Separate cast shadow and light contour in shadow edge loading.

===

M   source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c

===

diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c 
b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 93ba4e238f4..2f24326bbf4 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1835,7 +1835,7 @@ static uint16_t 
lineart_identify_feature_line(LineartRenderBuffer *rb,
 dot_2 = dot_v3v3_db(view_vector, tri2->gn);
 
 if ((result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) {
-  edge_flag_result |= LRT_EDGE_FLAG_LIGHT_CONTOUR;
+  // edge_flag_result |= LRT_EDGE_FLAG_LIGHT_CONTOUR;
 }
   }
 
@@ -3250,7 +3250,7 @@ static bool 
lineart_triangle_edge_image_space_occlusion(SpinLock *UNUSED(spl),
   dot_r = dot_v3v3_db(Rv, tri->gn);
   dot_f = dot_v3v3_db(Cv, tri->gn);
 
-  if ((e->flags & LRT_EDGE_FLAG_PROJECTED_SHADOW) &&
+  if (((e->flags & LRT_EDGE_FLAG_PROJECTED_SHADOW) || (e->flags & 
LRT_EDGE_FLAG_LIGHT_CONTOUR)) &&
   (e->target_reference == tri->target_reference || !e->target_reference) &&
   LRT_SHADOW_CLOSE_ENOUGH(dot_l, 0) && LRT_SHADOW_CLOSE_ENOUGH(dot_r, 0)) {
 /* Currently unable to precisely determine if the edge is really from this 
triangle. */
@@ -5771,7 +5771,7 @@ static bool 
lineart_shadow_cast_generate_edges(LineartRenderBuffer *rb,
 tot_orig_edges++;
   }
 
-  int edge_alloc = tot_orig_edges + tot_edges;
+  int edge_alloc = tot_edges + tot_orig_edges;
 
   if (G.debug_value == 4000) {
 printf("Line art shadow segments total: %d\n", tot_edges);
@@ -5828,7 +5828,7 @@ static bool 
lineart_shadow_cast_generate_edges(LineartRenderBuffer *rb,
 //}
 e->v1 = v1;
 e->v2 = v2;
-e->flags = LRT_EDGE_FLAG_PROJECTED_SHADOW;
+e->flags = LRT_EDGE_FLAG_LIGHT_CONTOUR;
 i++;
   }
   return true;

___
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] [9b3407c1bcd] lineart-shadow: Merge branch 'temp-lineart-contained' into lineart-shadow

2022-04-07 Thread YimingWu
Commit: 9b3407c1bcd6955c117d295560c9ed8e4da75663
Author: YimingWu
Date:   Tue Apr 5 22:20:16 2022 +0800
Branches: lineart-shadow
https://developer.blender.org/rB9b3407c1bcd6955c117d295560c9ed8e4da75663

Merge branch 'temp-lineart-contained' into lineart-shadow

===



===

diff --cc source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 4490bf8b5ab,fc2b9fff709..7549362baf2
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@@ -236,11 -210,12 +244,17 @@@ enum eLineArtTileRecursiveLimit 
  #define LRT_TILE_SPLITTING_TRIANGLE_LIMIT 100
  #define LRT_TILE_EDGE_COUNT_INITIAL 32
  
 +enum eLineartShadowCameraType {
 +  LRT_SHADOW_CAMERA_DIRECTIONAL = 1,
 +  LRT_SHADOW_CAMERA_POINT = 2,
 +};
 +
+ typedef struct LineartPendingEdges {
+   LineartEdge **array;
+   int max;
+   int next;
+ } LineartPendingEdges;
+ 
  typedef struct LineartRenderBuffer {
struct LineartRenderBuffer *prev, *next;
  
@@@ -305,13 -273,13 +319,17 @@@
ListBase edge_mark;
ListBase floating;
ListBase light_contour;
 +  ListBase shadow;
  
+   /* Note: Data here are allocated with MEM_xxx call instead of in pool. */
+   struct LineartPendingEdges pending_edges;
+   int scheduled_count;
+ 
ListBase chains;
  
 +  /* Intermediate shadow results, list of LineartShadowSegmentContainer */
 +  ListBase shadow_containers;
 +
/* For managing calculation tasks for multiple threads. */
SpinLock lock_task;
  
@@@ -433,13 -395,13 +451,17 @@@ typedef struct LineartRenderTaskInfo 
ListBase edge_mark;
ListBase floating;
ListBase light_contour;
 +  ListBase shadow;
  
+   /* Here it doesn't really hold memory, it just stores a refernce to a 
portion in
+* rb->pending_edges. */
+   struct LineartPendingEdges pending_edges;
+ 
  } LineartRenderTaskInfo;
  
 +#define LRT_OBINDEX_SHIFT 20
 +#define LRT_OBINDEX_LOWER 0x0f /* Lower 20 bits. */
 +
  typedef struct LineartObjectInfo {
struct LineartObjectInfo *next;
struct Object *original_ob;
@@@ -466,8 -425,10 +488,11 @@@
ListBase edge_mark;
ListBase floating;
ListBase light_contour;
 +  ListBase shadow;
  
+   /* Note: Data here are allocated with MEM_xxx call instead of in pool. */
+   struct LineartPendingEdges pending_edges;
+ 
  } LineartObjectInfo;
  
  typedef struct LineartObjectLoadTaskInfo {
diff --cc source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index b2a109f9b48,a7153e7abde..0937035ac42
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@@ -487,38 -475,10 +478,14 @@@ static void lineart_occlusion_worker(Ta
LineartEdge *eip;
  
while (lineart_occlusion_make_task_info(rb, rti)) {
- 
- for (eip = rti->contour.first; eip && eip != rti->contour.last; eip = 
eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->crease.first; eip && eip != rti->crease.last; eip = 
eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->intersection.first; eip && eip != rti->intersection.last; 
eip = eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->material.first; eip && eip != rti->material.last; eip = 
eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->edge_mark.first; eip && eip != rti->edge_mark.last; eip = 
eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->floating.first; eip && eip != rti->floating.last; eip = 
eip->next) {
-   lineart_occlusion_single_line(rb, eip, rti->thread_id);
- }
- 
- for (eip = rti->light_contour.first; eip && eip != 
rti->light_contour.last; eip = eip->next) {
+ for (int i = 0; i < rti->pending_edges.max; i++) {
+   eip = rti->pending_edges.array[i];
lineart_occlusion_single_line(rb, eip, rti->thread_id);
  }
 +
 +for (eip = rti->shadow.first; eip && eip != rti->shadow.last; eip = 
eip->next) {
 +  lineart_occlusion_single_line(rb, eip, rti->thread_id);
 +}
}
  }

___
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] [f7081aac316] lineart-shadow: Merge branch 'temp-lineart-contained' into lineart-shadow

2022-04-07 Thread YimingWu
Commit: f7081aac316842b3251ddac5160c8ca162d0c572
Author: YimingWu
Date:   Thu Apr 7 19:33:52 2022 +0800
Branches: lineart-shadow
https://developer.blender.org/rBf7081aac316842b3251ddac5160c8ca162d0c572

Merge branch 'temp-lineart-contained' into lineart-shadow

===



===

diff --cc source/blender/makesdna/DNA_lineart_types.h
index 6c77b567c6f,bf3b62320f6..903748b3aa8
--- a/source/blender/makesdna/DNA_lineart_types.h
+++ b/source/blender/makesdna/DNA_lineart_types.h
@@@ -52,17 -52,15 +52,20 @@@ typedef enum eLineartEdgeFlag 
/* LRT_EDGE_FLAG_FOR_FUTURE = (1 << 7), */
/* Limited to 8 bits for edge type flag, don't add anymore because 
BMEdge->head.eflag only has 8
   bits. So unless we changed this into a non-single-bit flag thing, we 
keep it this way. */
 +
 +  /* Shaow edge type doesn't go into BMEdge->head.eflag so we can make it 
higher than 1<<7. */
 +  LRT_EDGE_FLAG_PROJECTED_SHADOW = (1 << 8),
 +  /* To determine an edge to be occluded from the front or back face it's 
lying on. */
 +  LRT_EDGE_FLAG_SHADOW_FACING_LIGHT = (1 << 9),
/** Also used as discarded line mark. */
 -  LRT_EDGE_FLAG_CHAIN_PICKED = (1 << 8),
 -  LRT_EDGE_FLAG_CLIPPED = (1 << 9),
 +  LRT_EDGE_FLAG_CHAIN_PICKED = (1 << 10),
 +  LRT_EDGE_FLAG_CLIPPED = (1 << 11),
/** Limited to 16 bits for the entire thing. */
+ 
+   /** For object loading code to use only. */
+   LRT_EDGE_FLAG_INHIBIT = (1 << 14),
  } eLineartEdgeFlag;
  
 -#define LRT_EDGE_FLAG_ALL_TYPE 0x7f
 +#define LRT_EDGE_FLAG_ALL_TYPE 0x01ff
  #define LRT_EDGE_FLAG_INIT_TYPE 0x37 /* Without material & light contour */
  #define LRT_EDGE_FLAG_TYPE_MAX_BITS 7

___
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] [434521a9e2c] master: Curves: improve Add menu for new curves object

2022-04-07 Thread Jacques Lucke
Commit: 434521a9e2cc417e932115a3bc40c42b9b77cd92
Author: Jacques Lucke
Date:   Thu Apr 7 13:02:03 2022 +0200
Branches: master
https://developer.blender.org/rB434521a9e2cc417e932115a3bc40c42b9b77cd92

Curves: improve Add menu for new curves object

The goal is to make the Add menu more convenient for the new curves object.
The following changes are done:
* Add `curves` submenu.
* Add an `Empty Hair` operator that also sets the surface object.
* Rename the old operator to `Random`. It's mostly for testing at this point.

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

===

M   release/scripts/startup/bl_ui/space_view3d.py
M   source/blender/editors/object/object_add.cc
M   source/blender/editors/object/object_intern.h
M   source/blender/editors/object/object_ops.c

===

diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index dbb28513a51..b31e3209aea 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2052,6 +2052,19 @@ class VIEW3D_MT_curve_add(Menu):
 layout.operator("curve.primitive_nurbs_path_add", text="Path", 
icon='CURVE_PATH')
 
 
+class VIEW3D_MT_curves_add(Menu):
+bl_idname = "VIEW3D_MT_curves_add"
+bl_label = "Curves"
+
+def draw(self, _context):
+layout = self.layout
+
+layout.operator_context = 'INVOKE_REGION_WIN'
+
+layout.operator("object.curves_empty_hair_add", text="Empty Hair", 
icon='CURVES_DATA')
+layout.operator("object.curves_random_add", text="Random", 
icon='CURVES_DATA')
+
+
 class VIEW3D_MT_surface_add(Menu):
 bl_idname = "VIEW3D_MT_surface_add"
 bl_label = "Surface"
@@ -2204,12 +2217,12 @@ class VIEW3D_MT_add(Menu):
 
 # layout.operator_menu_enum("object.curve_add", "type", text="Curve", 
icon='OUTLINER_OB_CURVE')
 layout.menu("VIEW3D_MT_curve_add", icon='OUTLINER_OB_CURVE')
+if context.preferences.experimental.use_new_curves_type:
+layout.menu("VIEW3D_MT_curves_add", icon='OUTLINER_OB_CURVES')
 # layout.operator_menu_enum("object.surface_add", "type", 
text="Surface", icon='OUTLINER_OB_SURFACE')
 layout.menu("VIEW3D_MT_surface_add", icon='OUTLINER_OB_SURFACE')
 layout.menu("VIEW3D_MT_metaball_add", text="Metaball", 
icon='OUTLINER_OB_META')
 layout.operator("object.text_add", text="Text", 
icon='OUTLINER_OB_FONT')
-if context.preferences.experimental.use_new_curves_type:
-layout.operator("object.hair_curves_add", text="Hair Curves", 
icon='OUTLINER_OB_CURVES')
 if context.preferences.experimental.use_new_point_cloud_type:
 layout.operator("object.pointcloud_add", text="Point Cloud", 
icon='OUTLINER_OB_POINTCLOUD')
 layout.menu("VIEW3D_MT_volume_add", text="Volume", 
icon='OUTLINER_OB_VOLUME')
@@ -7638,6 +7651,7 @@ classes = (
 VIEW3D_MT_angle_control,
 VIEW3D_MT_mesh_add,
 VIEW3D_MT_curve_add,
+VIEW3D_MT_curves_add,
 VIEW3D_MT_surface_add,
 VIEW3D_MT_edit_metaball_context_menu,
 VIEW3D_MT_metaball_add,
diff --git a/source/blender/editors/object/object_add.cc 
b/source/blender/editors/object/object_add.cc
index ba11483722e..b3c5879b4d0 100644
--- a/source/blender/editors/object/object_add.cc
+++ b/source/blender/editors/object/object_add.cc
@@ -2044,10 +2044,10 @@ void OBJECT_OT_speaker_add(wmOperatorType *ot)
 /** \} */
 
 /*  */
-/** \name Add Hair Curves Operator
+/** \name Add Curves Operator
  * \{ */
 
-static bool object_hair_curves_add_poll(bContext *C)
+static bool object_curves_add_poll(bContext *C)
 {
   if (!U.experimental.use_new_curves_type) {
 return false;
@@ -2055,7 +2055,7 @@ static bool object_hair_curves_add_poll(bContext *C)
   return ED_operator_objectmode(C);
 }
 
-static int object_hair_curves_add_exec(bContext *C, wmOperator *op)
+static int object_curves_random_add_exec(bContext *C, wmOperator *op)
 {
   using namespace blender;
 
@@ -2075,16 +2075,16 @@ static int object_hair_curves_add_exec(bContext *C, 
wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_hair_curves_add(wmOperatorType *ot)
+void OBJECT_OT_curves_random_add(wmOperatorType *ot)
 {
   /* identifiers */
-  ot->name = "Add Hair Curves";
-  ot->description = "Add a hair curves object to the scene";
-  ot->idname = "OBJECT_OT_hair_curves_add";
+  ot->name = "Add Random Curves";
+  ot->description = "Add a curves object with random curves to the scene";
+  ot->idname = "OBJECT_OT_curves_random_add";
 
   /* api callbacks */
-  ot->exec = object_hair_curves_add_exec;
-  ot->poll = object_hair_curves_add_poll;
+  ot->exec = object_curves_random_add_exec;
+  ot->poll = object_curves_add_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | 

[Bf-blender-cvs] [50869b408b2] master: Curves: operator to snap curves to surface

2022-04-07 Thread Jacques Lucke
Commit: 50869b408b20f621fe8860e9f3551fb653b4b714
Author: Jacques Lucke
Date:   Thu Apr 7 12:49:13 2022 +0200
Branches: master
https://developer.blender.org/rB50869b408b20f621fe8860e9f3551fb653b4b714

Curves: operator to snap curves to surface

This operator snaps the first point of every curve to the corresponding
surface object. The shape of individual curves or their orientation is
not changed.

There are two different attachment modes:
* `Nearest`: Move each curve so that the first point is on the closest
  point on the surface. This should be used when the topology of the
  surface mesh changed, but the shape generally stayed the same.
* `Deform`: Use the existing attachment information that is stored
  for curves to move curves to their new location when the surface
  mesh was deformed. This generally does not work when the
  topology changed.

The purpose of the operator is to help setup the "ground truth"
for how curves are attached to the surface. When the ground
truth surface changed, the original curves have to be updated
as well. Deforming curves based on an animated surface will be
done with geometry nodes independent of the operator.

In the UI, the operator is currently exposed in curves sculpt mode
in the `Curves > Snap Curves to Surface` menu.

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

===

M   release/scripts/startup/bl_ui/space_view3d.py
M   source/blender/blenkernel/BKE_curves.hh
M   source/blender/editors/curves/intern/curves_ops.cc

===

diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index 41c1f3d0683..dbb28513a51 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -935,6 +935,8 @@ class VIEW3D_MT_editor_menus(Menu):
 if mode_string == 'SCULPT':
 layout.menu("VIEW3D_MT_mask")
 layout.menu("VIEW3D_MT_face_sets")
+if mode_string == 'SCULPT_CURVES':
+layout.menu("VIEW3D_MT_sculpt_curves")
 
 else:
 layout.menu("VIEW3D_MT_object")
@@ -3124,6 +3126,15 @@ class VIEW3D_MT_sculpt(Menu):
 layout.operator("object.transfer_mode", text="Transfer Sculpt Mode")
 
 
+class VIEW3D_MT_sculpt_curves(Menu):
+bl_label = "Curves"
+
+def draw(self, _context):
+layout = self.layout
+
+layout.operator("curves.snap_curves_to_surface")
+
+
 class VIEW3D_MT_mask(Menu):
 bl_label = "Mask"
 
@@ -7759,6 +7770,7 @@ classes = (
 VIEW3D_MT_sculpt_automasking_pie,
 VIEW3D_MT_wpaint_vgroup_lock_pie,
 VIEW3D_MT_sculpt_face_sets_edit_pie,
+VIEW3D_MT_sculpt_curves,
 VIEW3D_PT_active_tool,
 VIEW3D_PT_active_tool_duplicate,
 VIEW3D_PT_view3d_properties,
diff --git a/source/blender/blenkernel/BKE_curves.hh 
b/source/blender/blenkernel/BKE_curves.hh
index 8d24b6136b2..9061bb9fb81 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -368,6 +368,17 @@ inline int curve_segment_size(const int points_num, const 
bool cyclic)
   return cyclic ? points_num : points_num - 1;
 }
 
+inline float2 encode_surface_bary_coord(const float3 &v)
+{
+  BLI_assert(std::abs(v.x + v.y + v.z - 1.0f) < 0.1f);
+  return {v.x, v.y};
+}
+
+inline float3 decode_surface_bary_coord(const float2 &v)
+{
+  return {v.x, v.y, 1.0f - v.x - v.y};
+}
+
 namespace bezier {
 
 /**
diff --git a/source/blender/editors/curves/intern/curves_ops.cc 
b/source/blender/editors/curves/intern/curves_ops.cc
index c6dd4508b5a..3a4dcd4f5f6 100644
--- a/source/blender/editors/curves/intern/curves_ops.cc
+++ b/source/blender/editors/curves/intern/curves_ops.cc
@@ -4,13 +4,17 @@
  * \ingroup edcurves
  */
 
+#include 
+
 #include "BLI_utildefines.h"
 
 #include "ED_curves.h"
 #include "ED_object.h"
+#include "ED_screen.h"
 
 #include "WM_api.h"
 
+#include "BKE_bvhutils.h"
 #include "BKE_context.h"
 #include "BKE_curves.hh"
 #include "BKE_layer.h"
@@ -18,6 +22,7 @@
 #include "BKE_mesh_runtime.h"
 #include "BKE_paint.h"
 #include "BKE_particle.h"
+#include "BKE_report.h"
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -28,6 +33,9 @@
 
 #include "DEG_depsgraph.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 /**
  * The code below uses a suffix naming convention to indicate the coordinate 
space:
  * `cu`: Local space of the curves object that is being edited.
@@ -283,10 +291,204 @@ static void 
CURVES_OT_convert_to_particle_system(wmOperatorType *ot)
   ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
 }
 
+namespace snap_curves_to_surface {
+
+enum class AttachMode {
+  Nearest,
+  Deform,
+};
+
+static bool snap_curves_to_surface_poll(bContext *C)
+{
+  Object *ob = CTX_data_active_object(C);
+  if (ob == nullptr || ob->type != OB_CURVES) {
+return false;
+  }
+  if (!ED_o

[Bf-blender-cvs] [d4efcef5e30] temp-viewport-compositor-compiler: Viewport Compositor: Fix use after free results

2022-04-07 Thread Omar Emara
Commit: d4efcef5e303eae1be9c6d7e1dc17f72a9a71252
Author: Omar Emara
Date:   Thu Apr 7 12:23:25 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBd4efcef5e303eae1be9c6d7e1dc17f72a9a71252

Viewport Compositor: Fix use after free results

===

M   source/blender/nodes/NOD_compositor_execute.hh
M   source/blender/nodes/intern/node_compositor_execute.cc

===

diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index 4463db979cc..5c0591db5bc 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -4,6 +4,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include "BLI_map.hh"
 #include "BLI_math_vec_types.hh"
@@ -567,8 +568,8 @@ class NodeOperation : public Operation {
  private:
   /* The node that this operation represents. */
   DNode node_;
-  /* A vector storing the results mapped to the inputs that are not linked. */
-  Vector unlinked_inputs_results_;
+  /* A vector storing unique pointers to the results mapped to unlinked 
inputs. */
+  Vector> unlinked_inputs_results_;
   /* A mapping between each unlinked input in the node identified by its 
identifier and its
* corresponding input socket. */
   Map unlinked_inputs_sockets_;
diff --git a/source/blender/nodes/intern/node_compositor_execute.cc 
b/source/blender/nodes/intern/node_compositor_execute.cc
index 3d1cb671486..ecd3d807098 100644
--- a/source/blender/nodes/intern/node_compositor_execute.cc
+++ b/source/blender/nodes/intern/node_compositor_execute.cc
@@ -2,6 +2,7 @@
  * Copyright 2022 Blender Foundation. All rights reserved. */
 
 #include 
+#include 
 #include 
 
 #include "BLI_assert.h"
@@ -697,9 +698,8 @@ void NodeOperation::populate_results_for_unlinked_inputs()
 /* Construct a result of an appropriate type, add it to the results 
vector, and map the input
  * to it. */
 const ResultType result_type = 
get_node_socket_result_type(origin.socket_ref());
-const Result result = Result(result_type, texture_pool());
-unlinked_inputs_results_.append(result);
-map_input_to_result(input->identifier(), &unlinked_inputs_results_.last());
+unlinked_inputs_results_.append(std::make_unique(result_type, 
texture_pool()));
+map_input_to_result(input->identifier(), 
unlinked_inputs_results_.last().get());
 
 /* Map the input to the socket to later allocate and initialize its value. 
*/
 const DInputSocket origin_input{origin.context(), &origin->as_input()};

___
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] [e5c7f372237] master: Cleanup: make CustomMF_* implementations more similar

2022-04-07 Thread Jacques Lucke
Commit: e5c7f3722370f3cd70a7a00079820332c5b92de4
Author: Jacques Lucke
Date:   Thu Apr 7 11:51:31 2022 +0200
Branches: master
https://developer.blender.org/rBe5c7f3722370f3cd70a7a00079820332c5b92de4

Cleanup: make CustomMF_* implementations more similar

===

M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index dfdd152e62a..b041e67390c 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -185,12 +185,27 @@ class CustomMF_SI_SI_SI_SO : public MultiFunction {
MutableSpan out1) {
   /* Virtual arrays are not devirtualized yet, to avoid generating lots of 
code without further
* consideration. */
-  for (const int64_t i : mask) {
-new (static_cast(&out1[i])) Out1(element_fn(in1[i], in2[i], 
in3[i]));
-  }
+  execute_SI_SI_SI_SO(element_fn, mask, in1, in2, in3, out1.data());
 };
   }
 
+  template
+  BLI_NOINLINE static void execute_SI_SI_SI_SO(const ElementFuncT &element_fn,
+   MaskT mask,
+   const In1Array &in1,
+   const In2Array &in2,
+   const In3Array &in3,
+   Out1 *__restrict r_out)
+  {
+for (const int64_t i : mask) {
+  new (r_out + i) Out1(element_fn(in1[i], in2[i], in3[i]));
+}
+  }
+
   void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const 
override
   {
 const VArray &in1 = params.readonly_single_input(0);
@@ -250,12 +265,29 @@ class CustomMF_SI_SI_SI_SI_SO : public MultiFunction {
MutableSpan out1) {
   /* Virtual arrays are not devirtualized yet, to avoid generating lots of 
code without further
* consideration. */
-  for (const int64_t i : mask) {
-new (static_cast(&out1[i])) Out1(element_fn(in1[i], in2[i], 
in3[i], in4[i]));
-  }
+  execute_SI_SI_SI_SI_SO(element_fn, mask, in1, in2, in3, in4, 
out1.data());
 };
   }
 
+  template
+  BLI_NOINLINE static void execute_SI_SI_SI_SI_SO(const ElementFuncT 
&element_fn,
+  MaskT mask,
+  const In1Array &in1,
+  const In2Array &in2,
+  const In3Array &in3,
+  const In4Array &in4,
+  Out1 *__restrict r_out)
+  {
+for (const int64_t i : mask) {
+  new (r_out + i) Out1(element_fn(in1[i], in2[i], in3[i], in4[i]));
+}
+  }
+
   void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const 
override
   {
 const VArray &in1 = params.readonly_single_input(0);

___
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] [d9d49d35137] tracking_tools: Merge branch 'master' into tracking_tools

2022-04-07 Thread Sebastian Koenig
Commit: d9d49d35137bc39e2aa76dfbf1293d53203ae015
Author: Sebastian Koenig
Date:   Thu Apr 7 11:21:00 2022 +0200
Branches: tracking_tools
https://developer.blender.org/rBd9d49d35137bc39e2aa76dfbf1293d53203ae015

Merge branch 'master' into tracking_tools

===



===

diff --cc source/blender/blenloader/intern/versioning_300.c
index 19c29bc1e54,dd3412d6c83..1db489e480f
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@@ -2457,23 -2498,172 +2498,190 @@@ void blo_do_versions_300(FileData *fd, 
  }
}
  }
 +
 +{
 +  for (bScreen *screen = bmain->screens.first; screen; screen = 
screen->id.next) {
 +LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
 +  LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
 +ListBase *regionbase = (sl == area->spacedata.first) ? 
&area->regionbase :
 +   
&sl->regionbase;
 +if ((sl->spacetype == SPACE_CLIP) &&
 +(do_versions_find_region_or_null(regionbase, 
RGN_TYPE_TOOL_HEADER) == NULL)) {
 +  ARegion *region = do_versions_add_region_if_not_found(
 +  regionbase, RGN_TYPE_TOOL_HEADER, "tool header", 
RGN_TYPE_HEADER);
 +  region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? 
RGN_ALIGN_BOTTOM :
 +
RGN_ALIGN_TOP;
 +}
 +  }
 +}
 +  }
 +}
}
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 302, 9)) {
+ /* Sequencer channels region. */
+ 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_SEQ) {
+ continue;
+   }
+   if (ELEM(((SpaceSeq *)sl)->view, SEQ_VIEW_PREVIEW, 
SEQ_VIEW_SEQUENCE_PREVIEW)) {
+ continue;
+   }
+ 
+   ListBase *regionbase = (sl == area->spacedata.first) ? 
&area->regionbase :
+  
&sl->regionbase;
+   ARegion *region = BKE_area_find_region_type(area, 
RGN_TYPE_CHANNELS);
+   if (!region) {
+ ARegion *tools_region = BKE_area_find_region_type(area, 
RGN_TYPE_TOOLS);
+ region = do_versions_add_region(RGN_TYPE_CHANNELS, "channels 
region");
+ BLI_insertlinkafter(regionbase, tools_region, region);
+ region->alignment = RGN_ALIGN_LEFT;
+ region->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL;
+   }
+ 
+   ARegion *timeline_region = BKE_area_find_region_type(area, 
RGN_TYPE_WINDOW);
+   if (timeline_region != NULL) {
+ timeline_region->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL;
+   }
+ }
+   }
+ }
+ 
+ /* Initialize channels. */
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+   Editing *ed = SEQ_editing_get(scene);
+   if (ed == NULL) {
+ continue;
+   }
+   SEQ_channels_ensure(&ed->channels);
+   SEQ_for_each_callback(&scene->ed->seqbase, seq_meta_channels_ensure, 
NULL);
+ 
+   ed->displayed_channels = &ed->channels;
+ 
+   ListBase *previous_channels = &ed->channels;
+   LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) {
+ ms->old_channels = previous_channels;
+ previous_channels = &ms->parseq->channels;
+ /* If `MetaStack` exists, active channels must point to last link. */
+ ed->displayed_channels = &ms->parseq->channels;
+   }
+ }
+   }
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 302, 10)) {
+ 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_FILE) {
+ continue;
+   }
+   SpaceFile *sfile = (SpaceFile *)sl;
+   if (sfile->browse_mode != FILE_BROWSE_MODE_ASSETS) {
+ continue;
+   }
+   sfile->asset_params->base_params.filter_id |= FILTER_ID_GR;
+ }
+   }
+ }
+   }
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 302, 10)) {
+ /* While vertex-colors were experimental the smear tool became corrupt due
+  * to bugs in the wm_toolsystem API (auto-creation of sculpt brushes
+  * was broken).  Go through and reset all smear brushes. */
+ LISTBASE_FOREACH (Brush *, br, &bmain->brushes) {
+   if (br->sculpt_tool == SCULPT_TOOL_SMEAR) {
+ br->alpha = 1.0f;
+ br->spacing = 5;
+ br->flag &= ~BRUSH_ALPHA_PRESSURE;
+ br->flag &= ~BRUSH_SPACE_ATTEN;

[Bf-blender-cvs] [1d18c0682fa] master: Fix T96888: data transfer operator crash in certain situation

2022-04-07 Thread Philipp Oeser
Commit: 1d18c0682fa43324193639c16fcee0d22c34d15e
Author: Philipp Oeser
Date:   Tue Apr 5 09:49:55 2022 +0200
Branches: master
https://developer.blender.org/rB1d18c0682fa43324193639c16fcee0d22c34d15e

Fix T96888: data transfer operator crash in certain situation

The operator could crash in case the context "object" was overridden
from python, but the "active_object" wasnt (and the active object was
not a mesh).

Reason for the crash is a mismatch in the operators poll function
`data_transfer_poll` vs. `dt_layers_select_src_itemf` -- in the former,
the overriden "object" was respected (and if this was a mesh, the poll
was permissive), in the later it wasnt and only the "active_object" was
used (if this was not a mesh, a crash would happen trying to get an
evaluated mesh).

Now rectify how the object which is used is being fetched -> use
`ED_object_active_context` everywhere (see also rBe560bbe1d584).

Maniphest Tasks: T96888

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

===

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

===

diff --git a/source/blender/editors/object/object_data_transfer.c 
b/source/blender/editors/object/object_data_transfer.c
index 3447ded5f68..23d2327fe72 100644
--- a/source/blender/editors/object/object_data_transfer.c
+++ b/source/blender/editors/object/object_data_transfer.c
@@ -137,7 +137,7 @@ static const EnumPropertyItem 
*dt_layers_select_src_itemf(bContext *C,
   RNA_enum_items_add_value(
   &item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC);
 
-  Object *ob_src = CTX_data_active_object(C);
+  Object *ob_src = ED_object_active_context(C);
   if (ob_src == NULL) {
 RNA_enum_item_end(&item, &totitem);
 *r_free = true;

___
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] [09d6ce320f4] temp-viewport-compositor-compiler: Viewport Compositor: Add Translate node

2022-04-07 Thread Omar Emara
Commit: 09d6ce320f4fda04bce2baf806a3f8c71677f72e
Author: Omar Emara
Date:   Thu Apr 7 10:28:30 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB09d6ce320f4fda04bce2baf806a3f8c71677f72e

Viewport Compositor: Add Translate node

===

M   source/blender/nodes/composite/nodes/node_composite_translate.cc

===

diff --git a/source/blender/nodes/composite/nodes/node_composite_translate.cc 
b/source/blender/nodes/composite/nodes/node_composite_translate.cc
index d161b4a..f512b5baa1e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_translate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_translate.cc
@@ -21,9 +21,14 @@
  * \ingroup cmpnodes
  */
 
+#include "BLI_math_vec_types.hh"
+#include "BLI_transformation_2d.hh"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+#include "NOD_compositor_execute.hh"
+
 #include "node_composite_util.hh"
 
 /*  Translate  */
@@ -32,9 +37,19 @@ namespace blender::nodes::node_composite_translate_cc {
 
 static void cmp_node_translate_declare(NodeDeclarationBuilder &b)
 {
-  b.add_input(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 
1.0f});
-  
b.add_input(N_("X")).default_value(0.0f).min(-1.0f).max(1.0f);
-  
b.add_input(N_("Y")).default_value(0.0f).min(-1.0f).max(1.0f);
+  b.add_input(N_("Image"))
+  .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+  .compositor_domain_priority(0);
+  b.add_input(N_("X"))
+  .default_value(0.0f)
+  .min(-1.0f)
+  .max(1.0f)
+  .compositor_expects_single_value();
+  b.add_input(N_("Y"))
+  .default_value(0.0f)
+  .min(-1.0f)
+  .max(1.0f)
+  .compositor_expects_single_value();
   b.add_output(N_("Image"));
 }
 
@@ -50,6 +65,59 @@ static void node_composit_buts_translate(uiLayout *layout, 
bContext *UNUSED(C),
   uiItemR(layout, ptr, "wrap_axis", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 
ICON_NONE);
 }
 
+using namespace blender::viewport_compositor;
+
+class TranslateOperation : public NodeOperation {
+ public:
+  using NodeOperation::NodeOperation;
+
+  void execute() override
+  {
+Result &input = get_input("Image");
+Result &result = get_result("Image");
+input.pass_through(result);
+
+float x = get_input("X").get_float_value_default(0.0f);
+float y = get_input("Y").get_float_value_default(0.0f);
+if (get_use_relative()) {
+  x *= input.domain().size.x;
+  y *= input.domain().size.y;
+}
+
+const float2 translation = float2(x, y);
+const Transformation2D transformation = 
Transformation2D::from_translation(translation);
+
+result.transform(transformation);
+result.get_realization_options().repeat_x = get_repeat_x();
+result.get_realization_options().repeat_y = get_repeat_y();
+  }
+
+  NodeTranslateData &get_node_translate()
+  {
+return *static_cast(node().storage);
+  }
+
+  bool get_use_relative()
+  {
+return get_node_translate().relative;
+  }
+
+  bool get_repeat_x()
+  {
+return ELEM(get_node_translate().wrap_axis, CMP_NODE_WRAP_X, 
CMP_NODE_WRAP_XY);
+  }
+
+  bool get_repeat_y()
+  {
+return ELEM(get_node_translate().wrap_axis, CMP_NODE_WRAP_Y, 
CMP_NODE_WRAP_XY);
+  }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+  return new TranslateOperation(context, node);
+}
+
 }  // namespace blender::nodes::node_composite_translate_cc
 
 void register_node_type_cmp_translate()
@@ -64,6 +132,7 @@ void register_node_type_cmp_translate()
   node_type_init(&ntype, file_ns::node_composit_init_translate);
   node_type_storage(
   &ntype, "NodeTranslateData", node_free_standard_storage, 
node_copy_standard_storage);
+  ntype.get_compositor_operation = file_ns::get_compositor_operation;
 
   nodeRegisterType(&ntype);
 }

___
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] [e7d06c0bf22] temp-viewport-compositor-compiler: Viewport Compositor: Implement Rotate node

2022-04-07 Thread Omar Emara
Commit: e7d06c0bf2215b890e345e194a28c62c6ac6e42a
Author: Omar Emara
Date:   Fri Apr 1 19:03:19 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBe7d06c0bf2215b890e345e194a28c62c6ac6e42a

Viewport Compositor: Implement Rotate node

===

M   source/blender/nodes/composite/nodes/node_composite_rotate.cc
M   source/blender/nodes/composite/nodes/node_composite_transform.cc

===

diff --git a/source/blender/nodes/composite/nodes/node_composite_rotate.cc 
b/source/blender/nodes/composite/nodes/node_composite_rotate.cc
index 96ac4f3db5b..efa74b7fe72 100644
--- a/source/blender/nodes/composite/nodes/node_composite_rotate.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_rotate.cc
@@ -21,9 +21,14 @@
  * \ingroup cmpnodes
  */
 
+#include "BLI_assert.h"
+#include "BLI_transformation_2d.hh"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+#include "NOD_compositor_execute.hh"
+
 #include "node_composite_util.hh"
 
 /*  Rotate   */
@@ -32,12 +37,15 @@ namespace blender::nodes::node_composite_rotate_cc {
 
 static void cmp_node_rotate_declare(NodeDeclarationBuilder &b)
 {
-  b.add_input(N_("Image")).default_value({1.0f, 1.0f, 1.0f, 
1.0f});
+  b.add_input(N_("Image"))
+  .default_value({1.0f, 1.0f, 1.0f, 1.0f})
+  .compositor_domain_priority(0);
   b.add_input(N_("Degr"))
   .default_value(0.0f)
   .min(-1.0f)
   .max(1.0f)
-  .subtype(PROP_ANGLE);
+  .subtype(PROP_ANGLE)
+  .compositor_expects_single_value();
   b.add_output(N_("Image"));
 }
 
@@ -51,6 +59,47 @@ static void node_composit_buts_rotate(uiLayout *layout, 
bContext *UNUSED(C), Poi
   uiItemR(layout, ptr, "filter_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", 
ICON_NONE);
 }
 
+using namespace blender::viewport_compositor;
+
+class RotateOperation : public NodeOperation {
+ public:
+  using NodeOperation::NodeOperation;
+
+  void execute() override
+  {
+Result &input = get_input("Image");
+Result &result = get_result("Image");
+input.pass_through(result);
+
+const float rotation = get_input("Degr").get_float_value_default(0.0f);
+
+const Transformation2D transformation = 
Transformation2D::from_rotation(rotation);
+
+result.transform(transformation);
+result.set_realization_interpolation(get_interpolation());
+  }
+
+  Interpolation get_interpolation()
+  {
+switch (node().custom1) {
+  case 0:
+return Interpolation::Nearest;
+  case 1:
+return Interpolation::Bilinear;
+  case 2:
+return Interpolation::Bicubic;
+}
+
+BLI_assert_unreachable();
+return Interpolation::Nearest;
+  }
+};
+
+static NodeOperation *get_compositor_operation(Context &context, DNode node)
+{
+  return new RotateOperation(context, node);
+}
+
 }  // namespace blender::nodes::node_composite_rotate_cc
 
 void register_node_type_cmp_rotate()
@@ -63,6 +112,7 @@ void register_node_type_cmp_rotate()
   ntype.declare = file_ns::cmp_node_rotate_declare;
   ntype.draw_buttons = file_ns::node_composit_buts_rotate;
   node_type_init(&ntype, file_ns::node_composit_init_rotate);
+  ntype.get_compositor_operation = file_ns::get_compositor_operation;
 
   nodeRegisterType(&ntype);
 }
diff --git a/source/blender/nodes/composite/nodes/node_composite_transform.cc 
b/source/blender/nodes/composite/nodes/node_composite_transform.cc
index 0d314a4d20e..001ad932fbc 100644
--- a/source/blender/nodes/composite/nodes/node_composite_transform.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_transform.cc
@@ -23,6 +23,7 @@
 
 #include "BLI_assert.h"
 #include "BLI_math_vector.h"
+#include "BLI_transformation_2d.hh"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -37,7 +38,9 @@ namespace blender::nodes::node_composite_transform_cc {
 
 static void cmp_node_transform_declare(NodeDeclarationBuilder &b)
 {
-  b.add_input(N_("Image")).default_value({0.8f, 0.8f, 0.8f, 
1.0f});
+  b.add_input(N_("Image"))
+  .default_value({0.8f, 0.8f, 0.8f, 1.0f})
+  .compositor_domain_priority(0);
   b.add_input(N_("X"))
   .default_value(0.0f)
   .min(-1.0f)

___
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] [6a22de3927a] temp-viewport-compositor-compiler: Viewport Compositor: Add domain repetition support

2022-04-07 Thread Omar Emara
Commit: 6a22de3927a7596d110eed1b72b377862d0dd92e
Author: Omar Emara
Date:   Thu Apr 7 10:25:43 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB6a22de3927a7596d110eed1b72b377862d0dd92e

Viewport Compositor: Add domain repetition support

===

M   source/blender/nodes/NOD_compositor_execute.hh
M   source/blender/nodes/composite/nodes/node_composite_rotate.cc
M   source/blender/nodes/composite/nodes/node_composite_transform.cc
M   source/blender/nodes/intern/node_compositor_execute.cc

===

diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index 5709dc9b4cf..4463db979cc 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -110,17 +110,41 @@ class Context {
 };
 
 /* 
- * Domain.
+ * Realization Options.
  */
 
-/* Possible interpolations to use when realizing an input of some domain on 
another domain. See the
- * Domain class for more information. */
+/* Possible interpolations to use when realizing an input result of some 
domain on another domain.
+ * See the RealizationOptions class for more information. */
 enum class Interpolation : uint8_t {
   Nearest,
   Bilinear,
   Bicubic,
 };
 
+/* The options that describe how an input result prefer to be realized on some 
other domain. This
+ * is used by the RealizeOnDomainProcessorOperation to identify the 
appropriate method of
+ * realization. See the Domain class for more information. */
+class RealizationOptions {
+ public:
+  /* The interpolation method that should be used when performing realization. 
Since realizing a
+   * result involves projecting it on a different domain, which in turn, 
involves sampling the
+   * result at arbitrary locations, the interpolation identifies the method 
used for computing the
+   * value at those arbitrary locations. */
+  Interpolation interpolation = Interpolation::Nearest;
+  /* If true, the result will be repeated infinitely along the horizontal axis 
when realizing the
+   * result. If false, regions outside of bounds of the result along the 
horizontal axis will be
+   * filled with zeros. */
+  bool repeat_x = false;
+  /* If true, the result will be repeated infinitely along the vertical axis 
when realizing the
+   * result. If false, regions outside of bounds of the result along the 
vertical axis will be
+   * filled with zeros. */
+  bool repeat_y = false;
+};
+
+/* 
+ * Domain.
+ */
+
 /* A domain is a rectangular area of a certain size in pixels that is 
transformed by a certain
  * transformation in pixel space relative to some reference space.
  *
@@ -138,10 +162,11 @@ enum class Interpolation : uint8_t {
  * RealizeOnDomainProcessorOperation, except inputs whose descriptor sets 
skip_realization or
  * expects_single_value, see InputDescriptor for more information. The 
realization process simply
  * projects the input domain on the operation domain, copies the area of input 
that intersects the
- * operation domain, and fill the rest with zeros. The realization happens 
using the interpolation
- * method defined set in the realization_interpolation member. This process is 
illustrated below.
- * It follows that operations should expect all their inputs to have the same 
domain and
- * consequently size, except for inputs that explicitly skip realization.
+ * operation domain, and fill the rest with zeros or repetitions of the input 
domain; depending on
+ * the realization_options, see the RealizationOptions class for more 
information. This process is
+ * illustrated below, assuming no repetition in either directions. It follows 
that operations
+ * should expect all their inputs to have the same domain and consequently 
size, except for inputs
+ * that explicitly skip realization.
  *
  *   Realized Result
  * +-+   +-+
@@ -187,9 +212,9 @@ class Domain {
   /* The 2D transformation of the domain defining its translation in pixels, 
rotation, and scale in
* 2D space. */
   Transformation2D transformation;
-  /* The interpolation method that should be used when realizing the input 
whose domain is this
-   * one. */
-  Interpolation realization_interpolation = Interpolation::Nearest;
+  /* The options that describe how this domain prefer to be realized on some 
other domain. See the
+   * RealizationOptions for more information. */
+  RealizationOptions realization_options;
 
  public:
   /* A size only constructor that sets the transformation to identity. */
@@ -302,8 +327,9 @@ class Result {
* transformation by the current transformation of the domain of the result. 
*/
   void transf

[Bf-blender-cvs] [a87428f5330] temp-viewport-compositor-compiler: Viewport Compositor: Support realization interpolations

2022-04-07 Thread Omar Emara
Commit: a87428f533009dd7045e7134fc2295905b4ba7b0
Author: Omar Emara
Date:   Fri Apr 1 17:09:30 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBa87428f533009dd7045e7134fc2295905b4ba7b0

Viewport Compositor: Support realization interpolations

===

M   source/blender/nodes/NOD_compositor_execute.hh
M   source/blender/nodes/composite/nodes/node_composite_transform.cc
M   source/blender/nodes/intern/node_compositor_execute.cc

===

diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index b61618e6725..5709dc9b4cf 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -113,6 +113,14 @@ class Context {
  * Domain.
  */
 
+/* Possible interpolations to use when realizing an input of some domain on 
another domain. See the
+ * Domain class for more information. */
+enum class Interpolation : uint8_t {
+  Nearest,
+  Bilinear,
+  Bicubic,
+};
+
 /* A domain is a rectangular area of a certain size in pixels that is 
transformed by a certain
  * transformation in pixel space relative to some reference space.
  *
@@ -130,9 +138,10 @@ class Context {
  * RealizeOnDomainProcessorOperation, except inputs whose descriptor sets 
skip_realization or
  * expects_single_value, see InputDescriptor for more information. The 
realization process simply
  * projects the input domain on the operation domain, copies the area of input 
that intersects the
- * operation domain, and fill the rest with zeros. This process is illustrated 
below. It follows
- * that operations should expect all their inputs to have the same domain and 
consequently size,
- * except for inputs that explicitly skip realization.
+ * operation domain, and fill the rest with zeros. The realization happens 
using the interpolation
+ * method defined set in the realization_interpolation member. This process is 
illustrated below.
+ * It follows that operations should expect all their inputs to have the same 
domain and
+ * consequently size, except for inputs that explicitly skip realization.
  *
  *   Realized Result
  * +-+   +-+
@@ -152,7 +161,7 @@ class Context {
  * from it. The domain input is determined to be the non-single value input 
that have the highest
  * domain priority, a zero value being the highest priority. If all inputs are 
single values, then
  * the operation domain is irrelevant and an identity domain is set. See
- * NodeOperation::compute_domain.
+ * NodeOperation::compute_domain for more information.
  *
  * The aforementioned logic for operation domain computation is only a default 
that works for most
  * cases, but an operation can override the compute_domain method to implement 
a different logic.
@@ -178,6 +187,9 @@ class Domain {
   /* The 2D transformation of the domain defining its translation in pixels, 
rotation, and scale in
* 2D space. */
   Transformation2D transformation;
+  /* The interpolation method that should be used when realizing the input 
whose domain is this
+   * one. */
+  Interpolation realization_interpolation = Interpolation::Nearest;
 
  public:
   /* A size only constructor that sets the transformation to identity. */
@@ -290,6 +302,9 @@ class Result {
* transformation by the current transformation of the domain of the result. 
*/
   void transform(const Transformation2D &transformation);
 
+  /* Set the interpolation method that will be used when realizing this result 
if needed. */
+  void set_realization_interpolation(Interpolation interpolation);
+
   /* If the result is a single value result of type float, return its float 
value. Otherwise, an
* uninitialized value is returned. */
   float get_float_value() const;
@@ -350,7 +365,7 @@ class Result {
* reference count of the master result is returned instead. */
   int reference_count() const;
 
-  /* Returns the domain of the result. See the Domain class. */
+  /* Returns a reference to the domain of the result. See the Domain class. */
   const Domain &domain() const;
 };
 
diff --git a/source/blender/nodes/composite/nodes/node_composite_transform.cc 
b/source/blender/nodes/composite/nodes/node_composite_transform.cc
index d6f2734b54d..0d314a4d20e 100644
--- a/source/blender/nodes/composite/nodes/node_composite_transform.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_transform.cc
@@ -21,6 +21,7 @@
  * \ingroup cmpnodes
  */
 
+#include "BLI_assert.h"
 #include "BLI_math_vector.h"
 
 #include "UI_interface.h"
@@ -87,6 +88,22 @@ class TransformOperation : public NodeOperation {
 translation, rotation, scale);
 
 result.transform(transformation);
+result.set_realization_interpolation(get_interpolation());
+  }
+
+  Interpolation get_interpolati

[Bf-blender-cvs] [384a02a214c] master: BLI: add missing materialize methods for virtual arrays

2022-04-07 Thread Jacques Lucke
Commit: 384a02a214cad88f3180deee36b22529c213ddaf
Author: Jacques Lucke
Date:   Thu Apr 7 10:02:34 2022 +0200
Branches: master
https://developer.blender.org/rB384a02a214cad88f3180deee36b22529c213ddaf

BLI: add missing materialize methods for virtual arrays

This does two things:
* Introduce new `materialize_compressed` methods. Those are used
  when the dst array should not have any gaps.
* Add materialize methods in various classes where they were missing
  (and therefore caused overhead, because slower fallbacks had to be used).

===

M   source/blender/blenlib/BLI_generic_virtual_array.hh
M   source/blender/blenlib/BLI_virtual_array.hh
M   source/blender/blenlib/intern/generic_virtual_array.cc
M   source/blender/blenlib/tests/BLI_virtual_array_test.cc

===

diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh 
b/source/blender/blenlib/BLI_generic_virtual_array.hh
index f4c9e745cf9..4aed1caf796 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -51,6 +51,9 @@ class GVArrayImpl {
   virtual void materialize(const IndexMask mask, void *dst) const;
   virtual void materialize_to_uninitialized(const IndexMask mask, void *dst) 
const;
 
+  virtual void materialize_compressed(IndexMask mask, void *dst) const;
+  virtual void materialize_compressed_to_uninitialized(IndexMask mask, void 
*dst) const;
+
   virtual bool try_assign_VArray(void *varray) const;
   virtual bool may_have_ownership() const;
 };
@@ -133,6 +136,9 @@ class GVArrayCommon {
   void materialize_to_uninitialized(void *dst) const;
   void materialize_to_uninitialized(const IndexMask mask, void *dst) const;
 
+  void materialize_compressed(IndexMask mask, void *dst) const;
+  void materialize_compressed_to_uninitialized(IndexMask mask, void *dst) 
const;
+
   /**
* Returns true when the virtual array is stored as a span internally.
*/
@@ -336,6 +342,16 @@ template class GVArrayImpl_For_VArray : public 
GVArrayImpl {
 varray_.materialize_to_uninitialized(mask, MutableSpan((T *)dst, 
mask.min_array_size()));
   }
 
+  void materialize_compressed(const IndexMask mask, void *dst) const override
+  {
+varray_.materialize_compressed(mask, MutableSpan((T *)dst, mask.size()));
+  }
+
+  void materialize_compressed_to_uninitialized(const IndexMask mask, void 
*dst) const override
+  {
+varray_.materialize_compressed_to_uninitialized(mask, MutableSpan((T 
*)dst, mask.size()));
+  }
+
   bool try_assign_VArray(void *varray) const override
   {
 *(VArray *)varray = varray_;
@@ -400,6 +416,27 @@ template class VArrayImpl_For_GVArray : public 
VArrayImpl {
   {
 return varray_.may_have_ownership();
   }
+
+  void materialize(IndexMask mask, MutableSpan r_span) const override
+  {
+varray_.materialize(mask, r_span.data());
+  }
+
+  void materialize_to_uninitialized(IndexMask mask, MutableSpan r_span) 
const override
+  {
+varray_.materialize_to_uninitialized(mask, r_span.data());
+  }
+
+  void materialize_compressed(IndexMask mask, MutableSpan r_span) const 
override
+  {
+varray_.materialize_compressed(mask, r_span.data());
+  }
+
+  void materialize_compressed_to_uninitialized(IndexMask mask,
+   MutableSpan r_span) const 
override
+  {
+varray_.materialize_compressed_to_uninitialized(mask, r_span.data());
+  }
 };
 
 /* Used to convert any typed virtual mutable array into a generic one. */
@@ -479,6 +516,16 @@ template class 
GVMutableArrayImpl_For_VMutableArray : public GVMutab
 varray_.materialize_to_uninitialized(mask, MutableSpan((T *)dst, 
mask.min_array_size()));
   }
 
+  void materialize_compressed(const IndexMask mask, void *dst) const override
+  {
+varray_.materialize_compressed(mask, MutableSpan((T *)dst, mask.size()));
+  }
+
+  void materialize_compressed_to_uninitialized(const IndexMask mask, void 
*dst) const override
+  {
+varray_.materialize_compressed_to_uninitialized(mask, MutableSpan((T 
*)dst, mask.size()));
+  }
+
   bool try_assign_VArray(void *varray) const override
   {
 *(VArray *)varray = varray_;
@@ -561,6 +608,27 @@ template class 
VMutableArrayImpl_For_GVMutableArray : public VMutabl
   {
 return varray_.may_have_ownership();
   }
+
+  void materialize(IndexMask mask, MutableSpan r_span) const override
+  {
+varray_.materialize(mask, r_span.data());
+  }
+
+  void materialize_to_uninitialized(IndexMask mask, MutableSpan r_span) 
const override
+  {
+varray_.materialize_to_uninitialized(mask, r_span.data());
+  }
+
+  void materialize_compressed(IndexMask mask, MutableSpan r_span) const 
override
+  {
+varray_.materialize_compressed(mask, r_span.data());
+  }
+
+  void materialize_compressed_to_uninitialized(IndexMask mask,
+   MutableSpan

[Bf-blender-cvs] [2aff04917f9] master: Functions: parallelize materializing arrays after field evaluation

2022-04-07 Thread Jacques Lucke
Commit: 2aff04917f9e0420174e01dff0936d5237a7bbbd
Author: Jacques Lucke
Date:   Thu Apr 7 09:48:07 2022 +0200
Branches: master
https://developer.blender.org/rB2aff04917f9e0420174e01dff0936d5237a7bbbd

Functions: parallelize materializing arrays after field evaluation

This improves performance e.g. when creating an integer attribute
based on an index field. For 4 million vertices, I measured a speedup
from 3.5 ms to 1.2 ms.

===

M   source/blender/functions/intern/field.cc

===

diff --git a/source/blender/functions/intern/field.cc 
b/source/blender/functions/intern/field.cc
index 986d6ddc19e..944674c23a9 100644
--- a/source/blender/functions/intern/field.cc
+++ b/source/blender/functions/intern/field.cc
@@ -468,16 +468,21 @@ Vector evaluate_fields(ResourceScope &scope,
   /* Still have to copy over the data in the destination provided by the 
caller. */
   if (dst_varray.is_span()) {
 /* Materialize into a span. */
-computed_varray.materialize_to_uninitialized(mask, 
dst_varray.get_internal_span().data());
+threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange 
range) {
+  computed_varray.materialize_to_uninitialized(mask.slice(range),
+   
dst_varray.get_internal_span().data());
+});
   }
   else {
 /* Slower materialize into a different structure. */
 const CPPType &type = computed_varray.type();
-BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
-for (const int i : mask) {
-  computed_varray.get_to_uninitialized(i, buffer);
-  dst_varray.set_by_relocate(i, buffer);
-}
+threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange 
range) {
+  BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
+  for (const int i : mask.slice(range)) {
+computed_varray.get_to_uninitialized(i, buffer);
+dst_varray.set_by_relocate(i, buffer);
+  }
+});
   }
   r_varrays[out_index] = dst_varray;
 }

___
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] [120a17a45a6] master: BLI: add CPPType utility to copy elements to a shorter array

2022-04-07 Thread Jacques Lucke
Commit: 120a17a45a6d6c7f5520c8bfa32a0938f29a46be
Author: Jacques Lucke
Date:   Thu Apr 7 09:34:07 2022 +0200
Branches: master
https://developer.blender.org/rB120a17a45a6d6c7f5520c8bfa32a0938f29a46be

BLI: add CPPType utility to copy elements to a shorter array

===

M   source/blender/blenlib/BLI_cpp_type.hh
M   source/blender/blenlib/BLI_cpp_type_make.hh
M   source/blender/blenlib/tests/BLI_cpp_type_test.cc

===

diff --git a/source/blender/blenlib/BLI_cpp_type.hh 
b/source/blender/blenlib/BLI_cpp_type.hh
index 9453eb89a2e..dd14cca7a0b 100644
--- a/source/blender/blenlib/BLI_cpp_type.hh
+++ b/source/blender/blenlib/BLI_cpp_type.hh
@@ -118,9 +118,11 @@ class CPPType : NonCopyable, NonMovable {
 
   void (*copy_assign_)(const void *src, void *dst) = nullptr;
   void (*copy_assign_indices_)(const void *src, void *dst, IndexMask mask) = 
nullptr;
+  void (*copy_assign_compressed_)(const void *src, void *dst, IndexMask mask) 
= nullptr;
 
   void (*copy_construct_)(const void *src, void *dst) = nullptr;
   void (*copy_construct_indices_)(const void *src, void *dst, IndexMask mask) 
= nullptr;
+  void (*copy_construct_compressed_)(const void *src, void *dst, IndexMask 
mask) = nullptr;
 
   void (*move_assign_)(void *src, void *dst) = nullptr;
   void (*move_assign_indices_)(void *src, void *dst, IndexMask mask) = nullptr;
@@ -408,6 +410,18 @@ class CPPType : NonCopyable, NonMovable {
 copy_assign_indices_(src, dst, mask);
   }
 
+  /**
+   * Similar to #copy_assign_indices, but does not leave gaps in the #dst 
array.
+   */
+  void copy_assign_compressed(const void *src, void *dst, IndexMask mask) const
+  {
+BLI_assert(mask.size() == 0 || src != dst);
+BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
+BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
+
+copy_assign_compressed_(src, dst, mask);
+  }
+
   /**
* Copy an instance of this type from src to dst.
*
@@ -439,6 +453,18 @@ class CPPType : NonCopyable, NonMovable {
 copy_construct_indices_(src, dst, mask);
   }
 
+  /**
+   * Similar to #copy_construct_indices, but does not leave gaps in the #dst 
array.
+   */
+  void copy_construct_compressed(const void *src, void *dst, IndexMask mask) 
const
+  {
+BLI_assert(mask.size() == 0 || src != dst);
+BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
+BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
+
+copy_construct_compressed_(src, dst, mask);
+  }
+
   /**
* Move an instance of this type from src to dst.
*
diff --git a/source/blender/blenlib/BLI_cpp_type_make.hh 
b/source/blender/blenlib/BLI_cpp_type_make.hh
index 2612348075b..b0dbbff7ca8 100644
--- a/source/blender/blenlib/BLI_cpp_type_make.hh
+++ b/source/blender/blenlib/BLI_cpp_type_make.hh
@@ -51,6 +51,17 @@ template void copy_assign_indices_cb(const void 
*src, void *dst, Ind
 
   mask.foreach_index([&](int64_t i) { dst_[i] = src_[i]; });
 }
+template void copy_assign_compressed_cb(const void *src, void 
*dst, IndexMask mask)
+{
+  const T *src_ = static_cast(src);
+  T *dst_ = static_cast(dst);
+
+  mask.to_best_mask_type([&](auto best_mask) {
+for (const int64_t i : IndexRange(best_mask.size())) {
+  dst_[i] = src_[best_mask[i]];
+}
+  });
+}
 
 template void copy_construct_cb(const void *src, void *dst)
 {
@@ -63,6 +74,17 @@ template void copy_construct_indices_cb(const 
void *src, void *dst,
 
   mask.foreach_index([&](int64_t i) { new (dst_ + i) T(src_[i]); });
 }
+template void copy_construct_compressed_cb(const void *src, void 
*dst, IndexMask mask)
+{
+  const T *src_ = static_cast(src);
+  T *dst_ = static_cast(dst);
+
+  mask.to_best_mask_type([&](auto best_mask) {
+for (const int64_t i : IndexRange(best_mask.size())) {
+  new (dst_ + i) T(src_[best_mask[i]]);
+}
+  });
+}
 
 template void move_assign_cb(void *src, void *dst)
 {
@@ -208,10 +230,12 @@ CPPType::CPPType(CPPTypeParam /* unused */, 
StringRef debug_name)
   if constexpr (std::is_copy_assignable_v) {
 copy_assign_ = copy_assign_cb;
 copy_assign_indices_ = copy_assign_indices_cb;
+copy_assign_compressed_ = copy_assign_compressed_cb;
   }
   if constexpr (std::is_copy_constructible_v) {
 copy_construct_ = copy_construct_cb;
 copy_construct_indices_ = copy_construct_indices_cb;
+copy_construct_compressed_ = copy_construct_compressed_cb;
   }
   if constexpr (std::is_move_assignable_v) {
 move_assign_ = move_assign_cb;
diff --git a/source/blender/blenlib/tests/BLI_cpp_type_test.cc 
b/source/blender/blenlib/tests/BLI_cpp_type_test.cc
index f00767eda8c..6a59bedc649 100644
--- a/source/blender/blenlib/tests/BLI_cpp_type_test.cc
+++ b/source/blender/blenlib/tests/BLI_cpp_type_test.cc
@@ -381,4 +381,14 @@ TEST(cpp_type, ToStaticType)
   EXPECT_EQ(types[

[Bf-blender-cvs] [fd5e5dac894] master: Geometry Nodes: avoid data copy in store named attribute node

2022-04-07 Thread Jacques Lucke
Commit: fd5e5dac8946b1359904737f799523682b4ada1e
Author: Jacques Lucke
Date:   Thu Apr 7 09:40:37 2022 +0200
Branches: master
https://developer.blender.org/rBfd5e5dac8946b1359904737f799523682b4ada1e

Geometry Nodes: avoid data copy in store named attribute node

===

M   source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc

===

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc 
b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
index 5b0816fa3e3..1d1446ce1bd 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
@@ -91,18 +91,34 @@ static void try_capture_field_on_geometry(GeometryComponent 
&component,
   const int domain_size = component.attribute_domain_size(domain);
   const IndexMask mask{IndexMask(domain_size)};
 
-  const CustomDataType data_type = 
bke::cpp_type_to_custom_data_type(field.cpp_type());
+  const CPPType &type = field.cpp_type();
+  const CustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
+
+  /* Could avoid allocating a new buffer if:
+   * - We are writing to an attribute that exists already.
+   * - The field does not depend on that attribute (we can't easily check for 
that yet). */
+  void *buffer = MEM_mallocN(type.size() * domain_size, __func__);
 
-  /* Don't use #add_with_destination because the field might depend on an 
attribute
-   * with that name, and changing it as part of evaluation might affect the 
result. */
   fn::FieldEvaluator evaluator{field_context, &mask};
-  evaluator.add(field);
+  evaluator.add_with_destination(field, GMutableSpan{type, buffer, 
domain_size});
   evaluator.evaluate();
-  const GVArray &result = evaluator.get_evaluated(0);
-  OutputAttribute attribute = 
component.attribute_try_get_for_output_only(name, domain, data_type);
-  if (attribute) {
-result.materialize(attribute.as_span().data());
-attribute.save();
+
+  component.attribute_try_delete(name);
+  if (component.attribute_exists(name)) {
+WriteAttributeLookup write_attribute = 
component.attribute_try_get_for_write(name);
+if (write_attribute && write_attribute.domain == domain &&
+write_attribute.varray.type() == type) {
+  write_attribute.varray.set_all(buffer);
+  write_attribute.tag_modified_fn();
+}
+else {
+  /* Cannot change type of built-in attribute. */
+}
+type.destruct_n(buffer, domain_size);
+MEM_freeN(buffer);
+  }
+  else {
+component.attribute_try_create(name, domain, data_type, 
AttributeInitMove{buffer});
   }
 }

___
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