window_to_3d() wasn't working at all (only used by grease pencil/path conversion), now works in ortho and perspective view, initgrabz() is no longer needs to be called first.
This commit is contained in:
@@ -377,7 +377,6 @@ static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoi
|
||||
}
|
||||
else {
|
||||
float *fp= give_cursor(scene, v3d);
|
||||
float dvec[3];
|
||||
int mval[2];
|
||||
int mx, my;
|
||||
|
||||
@@ -396,9 +395,7 @@ static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoi
|
||||
/* convert screen coordinate to 3d coordinates
|
||||
* - method taken from editview.c - mouse_cursor()
|
||||
*/
|
||||
project_int_noclip(ar, fp, mval);
|
||||
window_to_3d(ar, dvec, mval[0]-mx, mval[1]-my);
|
||||
sub_v3_v3v3(p3d, fp, dvec);
|
||||
window_to_3d(ar, p3d, fp, mval[0], mval[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,8 +561,6 @@ static int gp_convert_layer_exec (bContext *C, wmOperator *op)
|
||||
bGPdata *gpd= gpencil_data_get_active(C);
|
||||
bGPDlayer *gpl= gpencil_layer_getactive(gpd);
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
View3D *v3d= CTX_wm_view3d(C);
|
||||
float *fp= give_cursor(scene, v3d);
|
||||
int mode= RNA_enum_get(op->ptr, "type");
|
||||
|
||||
/* check if there's data to work with */
|
||||
@@ -574,9 +569,6 @@ static int gp_convert_layer_exec (bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* initialise 3d-cursor correction globals */
|
||||
initgrabz(CTX_wm_region_view3d(C), fp[0], fp[1], fp[2]);
|
||||
|
||||
/* handle conversion modes */
|
||||
switch (mode) {
|
||||
case GP_STROKECONVERT_PATH:
|
||||
|
||||
@@ -80,7 +80,7 @@ typedef struct ViewDepths {
|
||||
float *give_cursor(struct Scene *scene, struct View3D *v3d);
|
||||
|
||||
int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
|
||||
void window_to_3d(struct ARegion *ar, float out[3], const int mx, const int my);
|
||||
void window_to_3d(struct ARegion *ar, float out[3], const float depth_pt[3], const int mx, const int my);
|
||||
void window_to_3d_delta(struct ARegion *ar, float out[3], const int mx, const int my);
|
||||
void window_to_3d_vector(struct ARegion *ar, float out[3], const int mx, const int my);
|
||||
void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
|
||||
|
||||
@@ -598,21 +598,37 @@ int initgrabz(RegionView3D *rv3d, float x, float y, float z)
|
||||
return flip;
|
||||
}
|
||||
|
||||
/* always call initgrabz */
|
||||
void window_to_3d(ARegion *ar, float out[3], const int mx, const int my)
|
||||
void window_to_3d(ARegion *ar, float out[3], const float depth_pt[3], const int mx, const int my)
|
||||
{
|
||||
RegionView3D *rv3d= ar->regiondata;
|
||||
|
||||
float dx= ((float)(mx-(ar->winx/2)))*rv3d->zfac/(ar->winx/2);
|
||||
float dy= ((float)(my-(ar->winy/2)))*rv3d->zfac/(ar->winy/2);
|
||||
|
||||
float fz= rv3d->persmat[0][3]*out[0]+ rv3d->persmat[1][3]*out[1]+ rv3d->persmat[2][3]*out[2]+ rv3d->persmat[3][3];
|
||||
fz= fz/rv3d->zfac;
|
||||
|
||||
out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
|
||||
out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
|
||||
out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
|
||||
|
||||
float line_sta[3];
|
||||
float line_end[3];
|
||||
|
||||
if(rv3d->is_persp) {
|
||||
float mousevec[3];
|
||||
float view_z[3];
|
||||
float pt_mid[3];
|
||||
|
||||
window_to_3d_vector(ar, mousevec, mx, my);
|
||||
|
||||
copy_v3_v3(line_sta, rv3d->viewinv[3]);
|
||||
normalize_v3_v3(view_z, rv3d->viewinv[2]);
|
||||
add_v3_v3v3(line_end, line_sta, view_z);
|
||||
closest_to_line_v3(pt_mid, depth_pt, line_sta, line_end);
|
||||
mul_v3_fl(mousevec, shell_angle_to_dist(angle_normalized_v3v3(view_z, mousevec)) * len_v3v3(line_sta, pt_mid));
|
||||
add_v3_v3v3(out, line_sta, mousevec);
|
||||
}
|
||||
else {
|
||||
const float dx= (2.0f * (float)mx / (float)ar->winx) - 1.0f;
|
||||
const float dy= (2.0f * (float)my / (float)ar->winy) - 1.0f;
|
||||
line_sta[0]= (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0];
|
||||
line_sta[1]= (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1];
|
||||
line_sta[2]= (rv3d->persinv[0][2] * dx) + (rv3d->persinv[1][2] * dy) + rv3d->viewinv[3][2];
|
||||
|
||||
add_v3_v3v3(line_end, line_sta, rv3d->viewinv[2]);
|
||||
closest_to_line_v3(out, depth_pt, line_sta, line_end);
|
||||
}
|
||||
}
|
||||
|
||||
/* always call initgrabz */
|
||||
|
||||
Reference in New Issue
Block a user