1
1

GPencil: Simplify Perimeter functions to not use RegionView3D

This makes the api more portable and not depend on 
any visual area for background tasks like future modifiers.
This commit is contained in:
2022-09-02 16:05:36 +02:00
parent 633117669b
commit 426d6b4baa
7 changed files with 32 additions and 36 deletions

View File

@@ -466,7 +466,7 @@ void BKE_gpencil_stroke_uniform_subdivide(struct bGPdata *gpd,
* This allows for manipulations in 2D but also easy conversion back to 3D.
* \note also takes care of parent space transform.
*/
void BKE_gpencil_stroke_to_view_space(struct RegionView3D *rv3d,
void BKE_gpencil_stroke_to_view_space(float viewmat[4][4],
struct bGPDstroke *gps,
const float diff_mat[4][4]);
/**
@@ -475,7 +475,7 @@ void BKE_gpencil_stroke_to_view_space(struct RegionView3D *rv3d,
* Inverse of #BKE_gpencil_stroke_to_view_space
* \note also takes care of parent space transform.
*/
void BKE_gpencil_stroke_from_view_space(struct RegionView3D *rv3d,
void BKE_gpencil_stroke_from_view_space(float viewinv[4][4],
struct bGPDstroke *gps,
const float diff_mat[4][4]);
/**
@@ -483,7 +483,7 @@ void BKE_gpencil_stroke_from_view_space(struct RegionView3D *rv3d,
* \param subdivisions: Number of subdivisions for the start and end caps.
* \return: bGPDstroke pointer to stroke perimeter.
*/
struct bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
struct bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(float viewmat[4][4],
struct bGPdata *gpd,
const struct bGPDlayer *gpl,
struct bGPDstroke *gps,

View File

@@ -3767,7 +3767,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
BKE_gpencil_stroke_geometry_update(gpd, gps);
}
void BKE_gpencil_stroke_to_view_space(RegionView3D *rv3d,
void BKE_gpencil_stroke_to_view_space(float viewmat[4][4],
bGPDstroke *gps,
const float diff_mat[4][4])
{
@@ -3776,11 +3776,11 @@ void BKE_gpencil_stroke_to_view_space(RegionView3D *rv3d,
/* Point to parent space. */
mul_v3_m4v3(&pt->x, diff_mat, &pt->x);
/* point to view space */
mul_m4_v3(rv3d->viewmat, &pt->x);
mul_m4_v3(viewmat, &pt->x);
}
}
void BKE_gpencil_stroke_from_view_space(RegionView3D *rv3d,
void BKE_gpencil_stroke_from_view_space(float viewinv[4][4],
bGPDstroke *gps,
const float diff_mat[4][4])
{
@@ -3789,7 +3789,7 @@ void BKE_gpencil_stroke_from_view_space(RegionView3D *rv3d,
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
mul_v3_m4v3(&pt->x, rv3d->viewinv, &pt->x);
mul_v3_m4v3(&pt->x, viewinv, &pt->x);
mul_m4_v3(inverse_diff_mat, &pt->x);
}
}
@@ -4206,7 +4206,7 @@ static ListBase *gpencil_stroke_perimeter_ex(const bGPdata *gpd,
return perimeter_list;
}
bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(float viewmat[4][4],
bGPdata *gpd,
const bGPDlayer *gpl,
bGPDstroke *gps,
@@ -4217,6 +4217,10 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
if (gps->totpoints == 0) {
return nullptr;
}
float viewinv[4][4];
invert_m4_m4(viewinv, viewmat);
/* Duplicate only points and fill data. Weight and Curve are not needed. */
bGPDstroke *gps_temp = (bGPDstroke *)MEM_dupallocN(gps);
gps_temp->prev = gps_temp->next = nullptr;
@@ -4241,7 +4245,7 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
pt_dst->uv_rot = 0;
}
BKE_gpencil_stroke_to_view_space(rv3d, gps_temp, diff_mat);
BKE_gpencil_stroke_to_view_space(viewmat, gps_temp, diff_mat);
int num_perimeter_points = 0;
ListBase *perimeter_points = gpencil_stroke_perimeter_ex(
gpd, gpl, gps_temp, subdivisions, thickness_chg, &num_perimeter_points);
@@ -4264,7 +4268,7 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
pt->flag |= GP_SPOINT_SELECT;
}
BKE_gpencil_stroke_from_view_space(rv3d, perimeter_stroke, diff_mat);
BKE_gpencil_stroke_from_view_space(viewinv, perimeter_stroke, diff_mat);
/* Free temp data. */
BLI_freelistN(perimeter_points);

View File

@@ -4001,40 +4001,35 @@ static int gpencil_stroke_outline_exec(bContext *C, wmOperator *op)
bool changed = false;
float viewmat[4][4], viewinv[4][4];
float viewmat[4][4];
copy_m4_m4(viewmat, rv3d->viewmat);
copy_m4_m4(viewinv, rv3d->viewinv);
switch (view_mode) {
case GP_PERIMETER_FRONT:
unit_m4(rv3d->viewmat);
rv3d->viewmat[1][1] = 0.0f;
rv3d->viewmat[1][2] = -1.0f;
viewmat[1][1] = 0.0f;
viewmat[1][2] = -1.0f;
rv3d->viewmat[2][1] = 1.0f;
rv3d->viewmat[2][2] = 0.0f;
viewmat[2][1] = 1.0f;
viewmat[2][2] = 0.0f;
rv3d->viewmat[3][2] = -10.0f;
invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
viewmat[3][2] = -10.0f;
break;
case GP_PERIMETER_SIDE:
zero_m4(rv3d->viewmat);
rv3d->viewmat[0][2] = 1.0f;
rv3d->viewmat[1][0] = 1.0f;
rv3d->viewmat[2][1] = 1.0f;
rv3d->viewmat[3][3] = 1.0f;
invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
zero_m4(viewmat);
viewmat[0][2] = 1.0f;
viewmat[1][0] = 1.0f;
viewmat[2][1] = 1.0f;
viewmat[3][3] = 1.0f;
break;
case GP_PERIMETER_TOP:
unit_m4(rv3d->viewmat);
unit_m4(rv3d->viewinv);
unit_m4(viewmat);
break;
case GP_PERIMETER_CAMERA: {
Scene *scene = CTX_data_scene(C);
Object *cam_ob = scene->camera;
if (cam_ob != NULL) {
invert_m4_m4(rv3d->viewmat, cam_ob->obmat);
copy_m4_m4(rv3d->viewinv, cam_ob->obmat);
invert_m4_m4(viewmat, cam_ob->obmat);
}
break;
}
@@ -4107,7 +4102,7 @@ static int gpencil_stroke_outline_exec(bContext *C, wmOperator *op)
/* Stroke. */
const float ovr_thickness = keep ? thickness : 0.0f;
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d, gpd, gpl, gps_duplicate, subdivisions, diff_mat, ovr_thickness);
viewmat, gpd, gpl, gps_duplicate, subdivisions, diff_mat, ovr_thickness);
gps_perimeter->flag &= ~GP_STROKE_SELECT;
/* Assign material. */
switch (material_mode) {
@@ -4174,9 +4169,6 @@ static int gpencil_stroke_outline_exec(bContext *C, wmOperator *op)
}
}
/* Back to view matrix. */
copy_m4_m4(rv3d->viewmat, viewmat);
copy_m4_m4(rv3d->viewinv, viewinv);
if (changed) {
/* notifiers */

View File

@@ -945,7 +945,7 @@ static bGPDstroke *gpencil_stroke_to_outline(tGPsdata *p, bGPDstroke *gps)
unit_m4(diff_mat);
const float outline_thickness = (float)brush->size * gpencil_settings->outline_fac * 0.5f;
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d, p->gpd, gpl, gps_duplicate, 3, diff_mat, outline_thickness);
rv3d->viewmat, p->gpd, gpl, gps_duplicate, 3, diff_mat, outline_thickness);
/* Assign material. */
if (gpencil_settings->material_alt == NULL) {
gps_perimeter->mat_nr = gps->mat_nr;

View File

@@ -257,7 +257,7 @@ float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps)
/* Radius. */
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d_, gpd_, gpl, gps, 3, diff_mat_.values, 0.0f);
rv3d_->viewmat, gpd_, gpl, gps, 3, diff_mat_.values, 0.0f);
pt = &gps_perimeter->points[0];
const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x);

View File

@@ -192,7 +192,7 @@ void GpencilExporterPDF::export_gpencil_layers()
}
else {
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d_, gpd_, gpl, gps_duplicate, 3, diff_mat_.values, 0.0f);
rv3d_->viewmat, gpd_, gpl, gps_duplicate, 3, diff_mat_.values, 0.0f);
/* Sample stroke. */
if (params_.stroke_sample > 0.0f) {

View File

@@ -217,7 +217,7 @@ void GpencilExporterSVG::export_gpencil_layers()
}
else {
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d_, gpd_, gpl, gps_duplicate, 3, diff_mat_.values, 0.0f);
rv3d_->viewmat, gpd_, gpl, gps_duplicate, 3, diff_mat_.values, 0.0f);
/* Sample stroke. */
if (params_.stroke_sample > 0.0f) {