Bugfix [#35686] Grease pencil to curve conversion causes NAN weights on vertices
When you convert a grease pencil stroke to a polygon curve and look at the vertices, the first and last vertex have weight = 0, but all others have a -NaN value. This was caused by division by zero issues when minmax_weights[0] == minmax_weights[1].
This commit is contained in:
@@ -1264,9 +1264,15 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2
|
||||
{
|
||||
Nurb *nu;
|
||||
const float delta = minmax_weights[0];
|
||||
const float fac = 1.0f / (minmax_weights[1] - delta);
|
||||
float fac;
|
||||
int i;
|
||||
|
||||
/* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */
|
||||
if (IS_EQ(delta, minmax_weights[1]))
|
||||
fac = 1.0f;
|
||||
else
|
||||
fac = 1.0f / (minmax_weights[1] - delta);
|
||||
|
||||
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
||||
if (nu->bezt) {
|
||||
BezTriple *bezt = nu->bezt;
|
||||
@@ -1361,12 +1367,14 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
|
||||
}
|
||||
|
||||
/* If link_strokes, be sure first and last points have a zero weight/size! */
|
||||
if (link_strokes)
|
||||
if (link_strokes) {
|
||||
gp_stroke_finalize_curve_endpoints(cu);
|
||||
|
||||
}
|
||||
|
||||
/* Update curve's weights, if needed */
|
||||
if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f)))
|
||||
if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f))) {
|
||||
gp_stroke_norm_curve_weights(cu, minmax_weights);
|
||||
}
|
||||
|
||||
/* Create the path animation, if needed */
|
||||
gp_stroke_path_animation(C, reports, cu, gtd);
|
||||
|
||||
Reference in New Issue
Block a user