[Bf-blender-cvs] [f2911ecc075] gpencil-new-data-proposal: Add radius in conversion and test in comparison

Falk David noreply at git.blender.org
Fri Dec 16 15:23:42 CET 2022


Commit: f2911ecc07574255a774ea3c0ad2f113b50c1f23
Author: Falk David
Date:   Fri Dec 16 15:23:38 2022 +0100
Branches: gpencil-new-data-proposal
https://developer.blender.org/rBf2911ecc07574255a774ea3c0ad2f113b50c1f23

Add radius in conversion and test in comparison

===================================================================

M	source/blender/blenkernel/intern/gpencil_new_proposal.hh
M	source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
M	source/blender/blenkernel/intern/gpencil_new_proposal_test.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal.hh b/source/blender/blenkernel/intern/gpencil_new_proposal.hh
index 526a1783f3b..461de5c8041 100644
--- a/source/blender/blenkernel/intern/gpencil_new_proposal.hh
+++ b/source/blender/blenkernel/intern/gpencil_new_proposal.hh
@@ -165,6 +165,8 @@ typedef struct GreasePencil {
 
 namespace blender::bke {
 
+static const std::string ATTR_RADIUS = "radius";
+
 class GPLayerGroup : ::GPLayerGroup { /* Unused for now. Placeholder class. */
  public:
   GPLayerGroup();
diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc b/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
index 14ce1de9d04..7e155b57f72 100644
--- a/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
+++ b/source/blender/blenkernel/intern/gpencil_new_proposal_conversion.cc
@@ -35,7 +35,7 @@ GPData convert_old_to_new_gpencil_data(bGPdata *old_gpd)
 
       MutableSpan<float3> new_gps_positions{new_gps.positions_for_write()};
       SpanAttributeWriter<float> radii = attributes.lookup_or_add_for_write_only_span<float>(
-          "radius", ATTR_DOMAIN_POINT);
+          ATTR_RADIUS, ATTR_DOMAIN_POINT);
       int stroke_index;
       LISTBASE_FOREACH_INDEX (const bGPDstroke *, old_gps, &old_gpf->strokes, stroke_index) {
         const IndexRange point_index_in_curve{new_gps.points_for_curve(stroke_index)};
@@ -82,6 +82,11 @@ bGPdata *convert_new_to_old_gpencil_data(const GPData &new_gpd)
 
       BLI_listbase_clear(&old_gpf->strokes);
       const CurvesGeometry &new_gps{new_gpf.strokes_as_curves()};
+      AttributeAccessor attributes = new_gps.attributes();
+
+      Span<float3> new_gps_positions = new_gps.positions();
+      VArray<float> new_gps_radii = attributes.lookup_or_default<float>(ATTR_RADIUS, ATTR_DOMAIN_POINT, 0);
+
       for (int stroke_index = 0; stroke_index < new_gpf.strokes_num(); stroke_index++) {
         bGPDstroke *old_gps = reinterpret_cast<bGPDstroke *>(
             MEM_mallocN(sizeof(bGPDstroke), __func__));
@@ -94,12 +99,11 @@ bGPdata *convert_new_to_old_gpencil_data(const GPData &new_gpd)
         old_gps->editcurve = nullptr;
         old_gps->dvert = nullptr;
 
-        Span<float3> new_gps_positions = new_gps.positions();
-
         int point_index{0};
         for (int new_gps_point_index : new_gps.points_for_curve(stroke_index)) {
           bGPDspoint *pt = &old_gps->points[point_index];
           copy_v3_v3(&pt->x, new_gps_positions[new_gps_point_index]);
+          pt->pressure = new_gps_radii[new_gps_point_index];
           ++point_index;
         }
 
diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc b/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
index 6c5e1802e0e..ce35caecf8b 100644
--- a/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
+++ b/source/blender/blenkernel/intern/gpencil_new_proposal_test.cc
@@ -158,43 +158,56 @@ static void insert_new_stroke_new_gpencil_data(GPFrame &gpf,
   int stroke_index{gpf.strokes_num()};
   gpf.add_new_stroke(point_num);
   CurvesGeometry &curves = gpf.strokes_as_curves();
+  MutableAttributeAccessor attributes = curves.attributes_for_write();
 
   int point_index{0};
   MutableSpan<float3> pos = curves.positions_for_write();
+  SpanAttributeWriter<float> radii = attributes.lookup_or_add_for_write_only_span<float>(
+      ATTR_RADIUS, ATTR_DOMAIN_POINT);
   for (int point_index_in_curve : curves.points_for_curve(stroke_index)) {
     pos[point_index_in_curve].x = position[3 * point_index];
     pos[point_index_in_curve].y = position[3 * point_index + 1];
     pos[point_index_in_curve].z = position[3 * point_index + 2];
+    radii.span[point_index_in_curve] = pressure[point_index];
     ++point_index;
   }
+
+  radii.finish();
 }
 
 static void compare_gpencil_stroke_data(const CurvesGeometry &curves,
                                         int curve_index,
-                                        const bGPDstroke *stk)
+                                        const bGPDstroke *gps)
 {
   // Stroke/Curve length
   int curve_point_num{curves.points_num_for_curve(curve_index)};
-  EXPECT_EQ(curve_point_num, stk->totpoints);
-  if (curve_point_num != stk->totpoints) {
+  EXPECT_EQ(curve_point_num, gps->totpoints);
+  if (curve_point_num != gps->totpoints) {
     return;
   }
 
+  AttributeAccessor attributes = curves.attributes();
+
   // Get curve attributes
   Span<float3> curve_positions{curves.positions()};
+  VArray<float> radii = attributes.lookup_or_default<float>(ATTR_RADIUS, ATTR_DOMAIN_POINT, 0);
 
   IndexRange curve_id{curves.points_for_curve(curve_index)};
-  int stk_point_id{0};
+  int point_index{0};
   for (int curve_point_id : curve_id) {
-    const bGPDspoint *stk_point{stk->points + stk_point_id};
-    const float3 &curve_pos{curve_positions[curve_point_id]};
+    const bGPDspoint *gps_point{gps->points + point_index};
+    const float3 &position{curve_positions[curve_point_id]};
+    const float radius = radii[curve_point_id];
 
     // Point positions
-    EXPECT_EQ(curve_pos.x, stk_point->x);
-    EXPECT_EQ(curve_pos.y, stk_point->y);
-    EXPECT_EQ(curve_pos.z, stk_point->z);
+    EXPECT_EQ(position.x, gps_point->x);
+    EXPECT_EQ(position.y, gps_point->y);
+    EXPECT_EQ(position.z, gps_point->z);
 
-    ++stk_point_id;
+    // Point radius
+    EXPECT_EQ(radius, gps_point->pressure);
+
+    ++point_index;
   }
 }



More information about the Bf-blender-cvs mailing list