[Bf-blender-cvs] [928ad8e5b8c] temp-gpencil-bezier-stroke-type: GPencil: Add flags for polyline regeneration
Falk David
noreply at git.blender.org
Fri Apr 16 18:47:18 CEST 2021
Commit: 928ad8e5b8cf618748a1b4e0cadf0e7fc715daf0
Author: Falk David
Date: Fri Apr 16 18:45:38 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB928ad8e5b8cf618748a1b4e0cadf0e7fc715daf0
GPencil: Add flags for polyline regeneration
===================================================================
M source/blender/blenkernel/BKE_gpencil_geom.h
M source/blender/blenkernel/intern/gpencil_geom.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index 82a6283a20c..22eea69477c 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -40,8 +40,15 @@ struct bGPdata;
typedef enum eGPStrokeGeoUpdateFlag {
/* Default geometry update. Triangulate the stroke, update UVs and bounding box. If the stroke
- type is bezier, regenerate the polyline first. */
+ type is bezier, regenerate the polyline first (GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL). */
GP_GEO_UPDATE_DEFAULT = 0,
+
+ /* == Curve refitting flags == */
+ /* On a stroke geometry update, if the stroke is of type bézier, there is the option to use the
+ points in the polyline to do a curve fitting. This is useful when an operation writes to the
+ polyline and the shape of the curve is out of sync and needs to be refitted. These flags
+ control what attributes the curve should be fitted to. */
+
/* Refit the curve point positions. */
GP_GEO_UPDATE_CURVE_REFIT_POSITION = (1 << 1),
/* Refit the curve point pressures. */
@@ -53,11 +60,27 @@ typedef enum eGPStrokeGeoUpdateFlag {
/* Refit the curve point weights. */
GP_GEO_UPDATE_CURVE_REFIT_WEIGHT = (1 << 5),
/* Do a partial refit. Uses the `GP_SPOINT_TAG` point flag to determin what curve segments need
- to be refitted. */
+ to be refitted. Only affected curve segments will be updated. */
GP_GEO_UPDATE_CURVE_PARTIAL_REFIT = (1 << 6),
- /* Add additional flags here: (1 << 7), (2 << 7), ... */
- /* GP_GEO_UPDATE_XXX = (1 << 7), */
+ /* == Polyline regeneration flags == */
+ /* The polyline is regenerated when the curve geometry is updated. This is because the polyline
+ is used for rendering instead of the actual curve data. These flag control what attributes
+ should be regenerated when the curve was updated. */
+
+ /* Regenerate the polyline positions from the curve data. */
+ GP_GEO_UPDATE_POLYLINE_POSITION = (1 << 7),
+ /* Regenerate the polyline point pressure from the curve data. */
+ GP_GEO_UPDATE_POLYLINE_PRESSURE = (1 << 8),
+ /* Regenerate the polyline point strength from the curve data. */
+ GP_GEO_UPDATE_POLYLINE_STRENGTH = (1 << 9),
+ /* Regenerate the polyline vertex colors from the curve data. */
+ GP_GEO_UPDATE_POLYLINE_COLOR = (1 << 10),
+ /* Regenerate the polyline weights from the curve data. */
+ GP_GEO_UPDATE_POLYLINE_WEIGHT = (1 << 11),
+
+ /* Add additional flags here: (1 << 12), (2 << 12), ... */
+ /* GP_GEO_UPDATE_XXX = (1 << 12), */
} eGPStrokeGeoUpdateFlag;
/* Refit all attributes. */
@@ -69,6 +92,17 @@ typedef enum eGPStrokeGeoUpdateFlag {
/* Check if any curve refitting is done. */
#define GP_GEO_UPDATE_CURVE_REFIT_ANY(flag) (flag & GP_GEO_UPDATE_CURVE_REFIT_ALL)
+/* Regenerate all attributes of the polyline from the curve data. */
+#define GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL \
+ (GP_GEO_UPDATE_POLYLINE_POSITION | GP_GEO_UPDATE_POLYLINE_PRESSURE | \
+ GP_GEO_UPDATE_POLYLINE_STRENGTH | GP_GEO_UPDATE_POLYLINE_COLOR | \
+ GP_GEO_UPDATE_POLYLINE_WEIGHT)
+
+/* Check if any atttributes of the polyline need to be regenerated. Note that we update all
+ * attributes by default (GP_GEO_UPDATE_DEFAULT). */
+#define GP_GEO_UPDATE_POLYLINE_REGENERATE_ANY(flag) \
+ ((flag & GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL) || flag == GP_GEO_UPDATE_DEFAULT)
+
/* Object boundbox. */
bool BKE_gpencil_data_minmax(const struct bGPdata *gpd, float r_min[3], float r_max[3]);
bool BKE_gpencil_stroke_minmax(const struct bGPDstroke *gps,
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 58b62afdfdb..26d1f0bb6f1 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1297,17 +1297,19 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *gpd,
/* Update curve points first if it's a bezier stroke. */
if (GPENCIL_STROKE_TYPE_BEZIER(gps)) {
+ /* Refit the curve to the polyline points. */
if (GP_GEO_UPDATE_CURVE_REFIT_ANY(flag)) {
- /* TODO: Make do-partial-update variable */
const float threshold = gpd->curve_edit_threshold;
const float corner_angle = gpd->curve_edit_corner_angle;
BKE_gpencil_stroke_editcurve_update(gps, threshold, corner_angle, flag);
}
- /* If curve geometry was updated, stroke points need recalculation. */
- const uint resolution = gpd->curve_edit_resolution;
- const bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
- BKE_gpencil_stroke_update_geometry_from_editcurve(gps, resolution, is_adaptive, flag);
+ /* Regenerate the polyline points from the curve data. */
+ if (GP_GEO_UPDATE_POLYLINE_REGENERATE_ANY(flag)) {
+ const uint resolution = gpd->curve_edit_resolution;
+ const bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
+ BKE_gpencil_stroke_update_geometry_from_editcurve(gps, resolution, is_adaptive, flag);
+ }
}
/* Triangulate the stroke. */
More information about the Bf-blender-cvs
mailing list