Compare commits
22 Commits
temp-ui-cp
...
temp-gpenc
Author | SHA1 | Date | |
---|---|---|---|
8c1090f22d | |||
38cf699ff7 | |||
88762806bb | |||
57a5885769 | |||
34c8a7accc | |||
ff3a592c59 | |||
1be4c9b865 | |||
b7d84fc310 | |||
0186bed90a | |||
7127bf45a6 | |||
3356f1f82e | |||
c8c0be35c8 | |||
ab6513f964 | |||
f327a61f9e | |||
3a95141ff3 | |||
63254baad6 | |||
9ec977dcad | |||
bfd7fe37da | |||
d9373cce36 | |||
3c2e5f5215 | |||
74315997ba | |||
9b2676c881 |
@@ -71,6 +71,7 @@ const EnumPropertyItem rna_gpencil_reproject_type_items[] = {
|
||||
"Reproject the strokes to end up on the same plane, as if drawn from the current "
|
||||
"viewpoint "
|
||||
"using 'Cursor' Stroke Placement"},
|
||||
{GP_REPROJECT_CAMERA, "CAMERA", 0, "Camera", "Reproject the strokes using the camera view"},
|
||||
{GP_REPROJECT_CURSOR,
|
||||
"CURSOR",
|
||||
0,
|
||||
@@ -283,6 +284,8 @@ static int gpencil_bake_grease_pencil_animation_exec(bContext *C, wmOperator *op
|
||||
/* Move scene to new frame. */
|
||||
CFRA = i;
|
||||
BKE_scene_graph_update_for_newframe(depsgraph);
|
||||
/* Ensure camera switch is applied. */
|
||||
BKE_scene_camera_switch_update(scene);
|
||||
|
||||
/* Loop all objects in the list. */
|
||||
LISTBASE_FOREACH (GpBakeOb *, elem, &ob_selected_list) {
|
||||
|
@@ -3845,29 +3845,6 @@ static int gpencil_strokes_reproject_exec(bContext *C, wmOperator *op)
|
||||
|
||||
void GPENCIL_OT_reproject(wmOperatorType *ot)
|
||||
{
|
||||
static const EnumPropertyItem reproject_type[] = {
|
||||
{GP_REPROJECT_FRONT, "FRONT", 0, "Front", "Reproject the strokes using the X-Z plane"},
|
||||
{GP_REPROJECT_SIDE, "SIDE", 0, "Side", "Reproject the strokes using the Y-Z plane"},
|
||||
{GP_REPROJECT_TOP, "TOP", 0, "Top", "Reproject the strokes using the X-Y plane"},
|
||||
{GP_REPROJECT_VIEW,
|
||||
"VIEW",
|
||||
0,
|
||||
"View",
|
||||
"Reproject the strokes to end up on the same plane, as if drawn from the current "
|
||||
"viewpoint "
|
||||
"using 'Cursor' Stroke Placement"},
|
||||
{GP_REPROJECT_SURFACE,
|
||||
"SURFACE",
|
||||
0,
|
||||
"Surface",
|
||||
"Reproject the strokes on to the scene geometry, as if drawn using 'Surface' placement"},
|
||||
{GP_REPROJECT_CURSOR,
|
||||
"CURSOR",
|
||||
0,
|
||||
"Cursor",
|
||||
"Reproject the strokes using the orientation of 3D cursor"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Reproject Strokes";
|
||||
@@ -3887,8 +3864,12 @@ void GPENCIL_OT_reproject(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
ot->prop = RNA_def_enum(
|
||||
ot->srna, "type", reproject_type, GP_REPROJECT_VIEW, "Projection Type", "");
|
||||
ot->prop = RNA_def_enum(ot->srna,
|
||||
"type",
|
||||
rna_gpencil_reproject_type_items,
|
||||
GP_REPROJECT_VIEW,
|
||||
"Projection Type",
|
||||
"");
|
||||
|
||||
RNA_def_boolean(
|
||||
ot->srna,
|
||||
|
@@ -271,6 +271,12 @@ bool gpencil_point_xy_to_3d(const GP_SpaceConversion *gsc,
|
||||
const float screen_co[2],
|
||||
float r_out[3]);
|
||||
|
||||
bool gpencil_point_render_xy_to_3d(const GP_SpaceConversion *gsc,
|
||||
float persmat[4][4],
|
||||
float persinv[4][4],
|
||||
const float render_co[2],
|
||||
float r_out[3]);
|
||||
|
||||
/* helper to convert 2d to 3d */
|
||||
void gpencil_stroke_convertcoords_tpoint(struct Scene *scene,
|
||||
struct ARegion *region,
|
||||
|
@@ -52,6 +52,7 @@
|
||||
|
||||
#include "BKE_action.h"
|
||||
#include "BKE_brush.h"
|
||||
#include "BKE_camera.h"
|
||||
#include "BKE_collection.h"
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_context.h"
|
||||
@@ -974,6 +975,63 @@ bool gpencil_point_xy_to_3d(const GP_SpaceConversion *gsc,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool gpencil_point_render_xy_to_3d(const GP_SpaceConversion *gsc,
|
||||
float persmat[4][4],
|
||||
float persinv[4][4],
|
||||
const float render_co[2],
|
||||
float r_out[3])
|
||||
{
|
||||
float rvec[3];
|
||||
Scene *scene = gsc->scene;
|
||||
|
||||
/* use object location */
|
||||
copy_v3_v3(rvec, gsc->ob->obmat[3]);
|
||||
|
||||
/* Apply layer offset. */
|
||||
bGPdata *gpd = gsc->ob->data;
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
|
||||
if (gpl != NULL) {
|
||||
add_v3_v3(rvec, gpl->layer_mat[3]);
|
||||
}
|
||||
|
||||
float zfac = mul_project_m4_v3_zfac(persmat, rvec);
|
||||
|
||||
/* if x,y,z is exactly the viewport offset, zfac is 0 and we don't want that
|
||||
* (accounting for near zero values) */
|
||||
if (zfac < 1.e-6f && zfac > -1.e-6f) {
|
||||
zfac = 1.0f;
|
||||
}
|
||||
|
||||
/* Negative zfac means x, y, z was behind the camera (in perspective).
|
||||
* This gives flipped directions, so revert back to ok default case. */
|
||||
if (zfac < 0.0f) {
|
||||
zfac = -zfac;
|
||||
}
|
||||
|
||||
float mval_f[2], mval_prj[2];
|
||||
float dvec[3];
|
||||
|
||||
copy_v2_v2(mval_f, render_co);
|
||||
|
||||
if (ED_view3d_project_float_ex(gsc->region, persmat, false, rvec, mval_prj, V3D_PROJ_TEST_NOP) ==
|
||||
V3D_PROJ_RET_OK) {
|
||||
sub_v2_v2v2(mval_f, mval_prj, mval_f);
|
||||
|
||||
float dx = 2.0f * mval_f[0] * zfac / (scene->r.xsch * scene->r.size / 100.0f);
|
||||
float dy = 2.0f * mval_f[1] * zfac / (scene->r.ysch * scene->r.size / 100.0f);
|
||||
dvec[0] = (persinv[0][0] * dx + persinv[1][0] * dy);
|
||||
dvec[1] = (persinv[0][1] * dx + persinv[1][1] * dy);
|
||||
dvec[2] = (persinv[0][2] * dx + persinv[1][2] * dy);
|
||||
|
||||
sub_v3_v3v3(r_out, rvec, dvec);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
zero_v3(r_out);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tGPspoint (temporary 2D/screenspace point data used by GP modal operators)
|
||||
* to 3D coordinates.
|
||||
@@ -1175,6 +1233,52 @@ void ED_gpencil_project_stroke_to_plane(const Scene *scene,
|
||||
}
|
||||
}
|
||||
|
||||
/* Retun if is_ortho and the perspective matrix.*/
|
||||
static bool gpencil_calculate_camera_matrix(Scene *scene, float persmat[4][4], float persinv[4][4])
|
||||
{
|
||||
Object *cam_ob = scene->camera;
|
||||
bool is_ortho = false;
|
||||
if (cam_ob != NULL) {
|
||||
/* Set up parameters. */
|
||||
CameraParams params;
|
||||
BKE_camera_params_init(¶ms);
|
||||
BKE_camera_params_from_object(¶ms, cam_ob);
|
||||
|
||||
/* Compute matrix, viewplane, .. */
|
||||
RenderData *rd = &scene->r;
|
||||
BKE_camera_params_compute_viewplane(¶ms, rd->xsch, rd->ysch, rd->xasp, rd->yasp);
|
||||
BKE_camera_params_compute_matrix(¶ms);
|
||||
|
||||
float viewmat[4][4];
|
||||
invert_m4_m4(viewmat, cam_ob->obmat);
|
||||
|
||||
mul_m4_m4m4(persmat, params.winmat, viewmat);
|
||||
invert_m4_m4_safe(persinv, persmat);
|
||||
|
||||
is_ortho = params.is_ortho;
|
||||
}
|
||||
else {
|
||||
unit_m4(persmat);
|
||||
}
|
||||
|
||||
return is_ortho;
|
||||
}
|
||||
|
||||
void ED_gpencil_project_point_to_render_space(const struct Scene *scene,
|
||||
struct bGPDspoint *pt,
|
||||
const float persmat[4][4],
|
||||
float r_co[2])
|
||||
{
|
||||
float render_x = (scene->r.xsch * scene->r.size) / 100;
|
||||
float render_y = (scene->r.ysch * scene->r.size) / 100;
|
||||
|
||||
float parent_co[2];
|
||||
mul_v2_project_m4_v3(parent_co, persmat, &pt->x);
|
||||
|
||||
r_co[0] = (parent_co[0] + 1.0f) / 2.0f * (float)render_x;
|
||||
r_co[1] = (parent_co[1] + 1.0f) / 2.0f * (float)render_y;
|
||||
}
|
||||
|
||||
/* Reproject selected strokes */
|
||||
void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
|
||||
const GP_SpaceConversion *gsc,
|
||||
@@ -1197,6 +1301,9 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
|
||||
BKE_gpencil_layer_transform_matrix_get(depsgraph, gsc->ob, gpl, diff_mat);
|
||||
invert_m4_m4(inverse_diff_mat, diff_mat);
|
||||
|
||||
float persmat[4][4], persinv[4][4];
|
||||
gpencil_calculate_camera_matrix(gsc->scene, persmat, persinv);
|
||||
|
||||
float origin[3];
|
||||
if (mode != GP_REPROJECT_CURSOR) {
|
||||
ED_gpencil_drawing_reference_get(gsc->scene, gsc->ob, ts->gpencil_v3d_align, origin);
|
||||
@@ -1233,10 +1340,10 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
|
||||
|
||||
bGPDspoint pt2;
|
||||
gpencil_point_to_parent_space(pt, diff_mat, &pt2);
|
||||
gpencil_point_to_xy_fl(gsc, gps_active, &pt2, &xy[0], &xy[1]);
|
||||
|
||||
/* Project stroke in one axis */
|
||||
if (ELEM(mode, GP_REPROJECT_FRONT, GP_REPROJECT_SIDE, GP_REPROJECT_TOP, GP_REPROJECT_CURSOR)) {
|
||||
gpencil_point_to_xy_fl(gsc, gps_active, &pt2, &xy[0], &xy[1]);
|
||||
int axis = 0;
|
||||
switch (mode) {
|
||||
case GP_REPROJECT_FRONT: {
|
||||
@@ -1271,9 +1378,16 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
|
||||
/* Project screen-space back to 3D space (from current perspective)
|
||||
* so that all points have been treated the same way. */
|
||||
else if (mode == GP_REPROJECT_VIEW) {
|
||||
gpencil_point_to_xy_fl(gsc, gps_active, &pt2, &xy[0], &xy[1]);
|
||||
/* Planar - All on same plane parallel to the view-plane. */
|
||||
gpencil_point_xy_to_3d(gsc, gsc->scene, xy, &pt->x);
|
||||
}
|
||||
else if (mode == GP_REPROJECT_CAMERA) {
|
||||
/* Convert to Render 2D space. */
|
||||
ED_gpencil_project_point_to_render_space(gsc->scene, &pt2, persmat, xy);
|
||||
/* Convert to Global Camera 3D space. */
|
||||
gpencil_point_render_xy_to_3d(gsc, persmat, persinv, xy, &pt->x);
|
||||
}
|
||||
else {
|
||||
/* Geometry - Snap to surfaces of visible geometry */
|
||||
float ray_start[3];
|
||||
@@ -1288,6 +1402,7 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
|
||||
BLI_assert(gps->flag & GP_STROKE_3DSPACE);
|
||||
BLI_assert(gsc->area && gsc->area->spacetype == SPACE_VIEW3D);
|
||||
const View3D *v3d = gsc->area->spacedata.first;
|
||||
gpencil_point_to_xy_fl(gsc, gps_active, &pt2, &xy[0], &xy[1]);
|
||||
ED_view3d_win_to_ray_clipped(
|
||||
depsgraph, region, v3d, xy, &ray_start[0], &ray_normal[0], true);
|
||||
if (ED_transform_snap_object_project_ray(sctx,
|
||||
|
@@ -76,6 +76,8 @@ typedef enum eGP_ReprojectModes {
|
||||
GP_REPROJECT_SURFACE,
|
||||
/* Reprojected on 3D cursor orientation */
|
||||
GP_REPROJECT_CURSOR,
|
||||
/* Reprojected on Camera View */
|
||||
GP_REPROJECT_CAMERA,
|
||||
/* Keep equals (used in some operators) */
|
||||
GP_REPROJECT_KEEP,
|
||||
} eGP_ReprojectModes;
|
||||
@@ -279,6 +281,10 @@ void ED_gpencil_project_point_to_plane(const struct Scene *scene,
|
||||
const float origin[3],
|
||||
const int axis,
|
||||
struct bGPDspoint *pt);
|
||||
void ED_gpencil_project_point_to_render_space(const struct Scene *scene,
|
||||
struct bGPDspoint *pt,
|
||||
const float persmat[4][4],
|
||||
float r_co[2]);
|
||||
void ED_gpencil_drawing_reference_get(const struct Scene *scene,
|
||||
const struct Object *ob,
|
||||
char align_flag,
|
||||
|
Reference in New Issue
Block a user