[Bf-blender-cvs] [f546b0800b9] master: GPencil: Add custom normal entry to bGPDspoint.

YimingWu noreply at git.blender.org
Wed Jun 9 16:46:47 CEST 2021


Commit: f546b0800b9121b24b1292f1ec602ed9964d1848
Author: YimingWu
Date:   Wed Jun 9 22:42:55 2021 +0800
Branches: master
https://developer.blender.org/rBf546b0800b9121b24b1292f1ec602ed9964d1848

GPencil: Add custom normal entry to bGPDspoint.

Also modified existing utility functions to take
care of the new surface normal interpolation and so on.

Reviewed By: Antonio Vazquez (antoniov)

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

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

M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 7f839650f33..b0fed35253d 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -218,6 +218,7 @@ static int stroke_march_next_point(const bGPDstroke *gps,
                                    float *pressure,
                                    float *strength,
                                    float *vert_color,
+                                   float *custom_vector,
                                    float *ratio_result,
                                    int *index_from,
                                    int *index_to)
@@ -258,6 +259,7 @@ static int stroke_march_next_point(const bGPDstroke *gps,
     *pressure = gps->points[next_point_index].pressure;
     *strength = gps->points[next_point_index].strength;
     memcpy(vert_color, gps->points[next_point_index].vert_color, sizeof(float[4]));
+    memcpy(custom_vector, gps->points[next_point_index].custom_vector, sizeof(float[3]));
 
     *index_from = next_point_index - 1;
     *index_to = next_point_index;
@@ -276,6 +278,10 @@ static int stroke_march_next_point(const bGPDstroke *gps,
                  gps->points[next_point_index - 1].vert_color,
                  gps->points[next_point_index].vert_color,
                  ratio);
+  interp_v3_v3v3(custom_vector,
+                 gps->points[next_point_index - 1].custom_vector,
+                 gps->points[next_point_index].custom_vector,
+                 ratio);
 
   *index_from = next_point_index - 1;
   *index_to = next_point_index;
@@ -454,6 +460,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
   int i = 0;
   float pressure, strength, ratio_result;
   float vert_color[4];
+  float custom_vector[3];
   int index_from, index_to;
   float last_coord[3];
 
@@ -465,6 +472,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
   new_pt[i].pressure = pt[0].pressure;
   new_pt[i].strength = pt[0].strength;
   memcpy(new_pt[i].vert_color, pt[0].vert_color, sizeof(float[4]));
+  memcpy(new_pt[i].custom_vector, pt[0].custom_vector, sizeof(float[3]));
   if (select) {
     new_pt[i].flag |= GP_SPOINT_SELECT;
   }
@@ -483,6 +491,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
                                                      &pressure,
                                                      &strength,
                                                      vert_color,
+                                                     custom_vector,
                                                      &ratio_result,
                                                      &index_from,
                                                      &index_to)) > -1) {
@@ -491,6 +500,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist,
     new_pt[i].pressure = pressure;
     new_pt[i].strength = strength;
     memcpy(new_pt[i].vert_color, vert_color, sizeof(float[4]));
+    memcpy(new_pt[i].custom_vector, custom_vector, sizeof(float[3]));
     if (select) {
       new_pt[i].flag |= GP_SPOINT_SELECT;
     }
@@ -1568,6 +1578,7 @@ bool BKE_gpencil_stroke_close(bGPDstroke *gps)
     pt->strength = interpf(pt2->strength, pt1->strength, step);
     pt->flag = 0;
     interp_v4_v4v4(pt->vert_color, pt1->vert_color, pt2->vert_color, step);
+    interp_v3_v3v3(pt->custom_vector, pt1->custom_vector, pt2->custom_vector, step);
 
     /* Set weights. */
     if (gps->dvert != NULL) {
@@ -1942,6 +1953,7 @@ void BKE_gpencil_stroke_subdivide(bGPdata *gpd, bGPDstroke *gps, int level, int
       pt_final->runtime.pt_orig = pt->runtime.pt_orig;
       pt_final->runtime.idx_orig = pt->runtime.idx_orig;
       copy_v4_v4(pt_final->vert_color, pt->vert_color);
+      copy_v3_v3(pt_final->custom_vector, pt->custom_vector);
 
       if (gps->dvert != NULL) {
         dvert = &temp_dverts[i];
@@ -1967,6 +1979,7 @@ void BKE_gpencil_stroke_subdivide(bGPdata *gpd, bGPDstroke *gps, int level, int
       pt_final->runtime.pt_orig = NULL;
       pt_final->flag = 0;
       interp_v4_v4v4(pt_final->vert_color, pt->vert_color, next->vert_color, 0.5f);
+      interp_v3_v3v3(pt_final->custom_vector, pt->custom_vector, next->custom_vector, 0.5f);
 
       if (gps->dvert != NULL) {
         dvert = &temp_dverts[i];
@@ -2725,6 +2738,7 @@ void BKE_gpencil_stroke_flip(bGPDstroke *gps)
     pt.strength = point->strength;
     pt.time = point->time;
     copy_v4_v4(pt.vert_color, point->vert_color);
+    copy_v3_v3(pt.custom_vector, point->custom_vector);
 
     /* replace first point with last point */
     point2 = &gps->points[end];
@@ -2736,6 +2750,7 @@ void BKE_gpencil_stroke_flip(bGPDstroke *gps)
     point->strength = point2->strength;
     point->time = point2->time;
     copy_v4_v4(point->vert_color, point2->vert_color);
+    copy_v3_v3(point->custom_vector, point2->custom_vector);
 
     /* replace last point with first saved before */
     point = &gps->points[end];
@@ -2747,6 +2762,7 @@ void BKE_gpencil_stroke_flip(bGPDstroke *gps)
     point->strength = pt.strength;
     point->time = pt.time;
     copy_v4_v4(point->vert_color, pt.vert_color);
+    copy_v3_v3(point->custom_vector, pt.custom_vector);
 
     end--;
   }
@@ -2800,6 +2816,7 @@ static void gpencil_stroke_join_islands(bGPdata *gpd,
     pt_final->time = delta;
     pt_final->flag = pt->flag;
     copy_v4_v4(pt_final->vert_color, pt->vert_color);
+    copy_v3_v3(pt_final->custom_vector, pt->custom_vector);
 
     /* retiming with fixed time interval (we cannot determine real time) */
     delta += 0.01f;
@@ -3153,6 +3170,7 @@ static void gpencil_stroke_copy_point(bGPDstroke *gps,
   newpoint->strength = strength;
   newpoint->time = point->time + deltatime;
   copy_v4_v4(newpoint->vert_color, point->vert_color);
+  copy_v3_v3(newpoint->custom_vector, point->custom_vector);
 
   if (gps->dvert != NULL) {
     MDeformVert *newdvert = &gps->dvert[gps->totpoints - 1];
@@ -3308,6 +3326,7 @@ typedef struct tSamplePoint {
   float x, y, z;
   float pressure, strength, time;
   float vertex_color[4];
+  float custom_vector[3];
   struct MDeformWeight *dw;
   int totweight;
 } tSamplePoint;
@@ -3327,6 +3346,7 @@ static tSamplePoint *new_sample_point_from_gp_point(const bGPDspoint *pt, const
   new_pt->strength = pt->strength;
   new_pt->time = pt->time;
   copy_v4_v4((float *)&new_pt->vertex_color, (float *)&pt->vert_color);
+  copy_v3_v3((float *)&new_pt->custom_vector, (float *)&pt->custom_vector);
   if (dvert != NULL) {
     new_pt->totweight = dvert->totweight;
     new_pt->dw = MEM_callocN(sizeof(MDeformWeight) * new_pt->totweight, __func__);
@@ -3418,6 +3438,10 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
                    (float *)&sp->vertex_color,
                    (float *)&sp_next->vertex_color,
                    0.5f);
+    interp_v3_v3v3((float *)&new_sp->custom_vector,
+                   (float *)&sp->custom_vector,
+                   (float *)&sp_next->custom_vector,
+                   0.5f);
     if (sp->dw && sp_next->dw) {
       new_sp->totweight = MIN2(sp->totweight, sp_next->totweight);
       new_sp->dw = MEM_callocN(sizeof(MDeformWeight) * new_sp->totweight, __func__);
@@ -3460,6 +3484,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
     pt->strength = sp->strength;
     pt->time = sp->time;
     copy_v4_v4((float *)&pt->vert_color, (float *)&sp->vertex_color);
+    copy_v3_v3((float *)&pt->custom_vector, (float *)&sp->custom_vector);
 
     if (sp->dw) {
       dvert->totweight = sp->totweight;
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index ea3c1ff7275..504a44da34b 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -97,9 +97,10 @@ typedef struct bGPDspoint {
   /** Vertex Color RGBA (A=mix factor). */
   float vert_color[4];
 
-  /** Runtime data */
-  char _pad2[4];
+  /** Generic custom vector for various use cases. */
+  float custom_vector[3];
 
+  /** Runtime data */
   bGPDspoint_Runtime runtime;
 } bGPDspoint;
 
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 19ed5f960cf..a2d6bbed70c 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1288,6 +1288,14 @@ static void rna_def_gpencil_stroke_point(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Vertex Color", "Color used to mix with point color to get final color");
   RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
+  /* Surface normal. */
+  prop = RNA_def_property(srna, "custom_vector", PROP_FLOAT, PROP_COLOR);
+  RNA_def_property_array(prop, 3);
+  RNA_def_property_range(prop, 0.0f, 1.0f);
+  RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+  RNA_def_property_ui_text(prop, "Custom Vector", "Generic custom vector for various use cases");
+  RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 }
 
 static void rna_def_gpencil_stroke_points_api(BlenderRNA *brna, PropertyRNA *cprop)



More information about the Bf-blender-cvs mailing list