Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/gpencil/intern/gpencil_io_base.cc
| Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | if (cam_ob != nullptr) { | ||||
| RenderData *rd = &scene_->r; | RenderData *rd = &scene_->r; | ||||
| BKE_camera_params_compute_viewplane(¶ms, rd->xsch, rd->ysch, rd->xasp, rd->yasp); | BKE_camera_params_compute_viewplane(¶ms, rd->xsch, rd->ysch, rd->xasp, rd->yasp); | ||||
| BKE_camera_params_compute_matrix(¶ms); | BKE_camera_params_compute_matrix(¶ms); | ||||
| float viewmat[4][4]; | float viewmat[4][4]; | ||||
| invert_m4_m4(viewmat, cam_ob->obmat); | invert_m4_m4(viewmat, cam_ob->obmat); | ||||
| mul_m4_m4m4(persmat_, params.winmat, viewmat); | mul_m4_m4m4(persmat_, params.winmat, viewmat); | ||||
| is_ortho_ = params.is_ortho; | |||||
| } | } | ||||
| else { | else { | ||||
| unit_m4(persmat_); | unit_m4(persmat_); | ||||
| is_ortho_ = false; | |||||
| } | } | ||||
| winx_ = params_.region->winx; | winx_ = params_.region->winx; | ||||
| winy_ = params_.region->winy; | winy_ = params_.region->winy; | ||||
| /* Camera rectangle. */ | /* Camera rectangle. */ | ||||
| if (rv3d_->persp == RV3D_CAMOB) { | if (rv3d_->persp == RV3D_CAMOB) { | ||||
| render_x_ = (scene_->r.xsch * scene_->r.size) / 100; | render_x_ = (scene_->r.xsch * scene_->r.size) / 100; | ||||
| render_y_ = (scene_->r.ysch * scene_->r.size) / 100; | render_y_ = (scene_->r.ysch * scene_->r.size) / 100; | ||||
| ED_view3d_calc_camera_border(CTX_data_scene(params_.C), | ED_view3d_calc_camera_border(CTX_data_scene(params_.C), | ||||
| depsgraph_, | depsgraph_, | ||||
| params_.region, | params_.region, | ||||
| params_.v3d, | params_.v3d, | ||||
| rv3d_, | rv3d_, | ||||
| &camera_rect_, | &camera_rect_, | ||||
| true); | true); | ||||
| is_camera_ = true; | is_camera_ = true; | ||||
| camera_ratio_ = render_x_ / (camera_rect_.xmax - camera_rect_.xmin); | camera_ratio_ = render_x_ / (camera_rect_.xmax - camera_rect_.xmin); | ||||
| offset_.x = camera_rect_.xmin; | offset_.x = camera_rect_.xmin; | ||||
| offset_.y = camera_rect_.ymin; | offset_.y = camera_rect_.ymin; | ||||
| } | } | ||||
| else { | else { | ||||
| is_camera_ = false; | is_camera_ = false; | ||||
| is_ortho_ = false; | |||||
| /* Calc selected object boundbox. Need set initial value to some variables. */ | /* Calc selected object boundbox. Need set initial value to some variables. */ | ||||
| camera_ratio_ = 1.0f; | camera_ratio_ = 1.0f; | ||||
| offset_.x = 0.0f; | offset_.x = 0.0f; | ||||
| offset_.y = 0.0f; | offset_.y = 0.0f; | ||||
| selected_objects_boundbox_calc(); | selected_objects_boundbox_calc(); | ||||
| rctf boundbox; | rctf boundbox; | ||||
| selected_objects_boundbox_get(&boundbox); | selected_objects_boundbox_get(&boundbox); | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | bool GpencilIO::gpencil_3D_point_to_screen_space(const float3 co, float2 &r_co) | ||||
| if (invert_axis_[1]) { | if (invert_axis_[1]) { | ||||
| r_co[1] = winy_ - r_co[1]; | r_co[1] = winy_ - r_co[1]; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** Convert to render space. */ | /** Convert to render space. */ | ||||
| float2 GpencilIO::gpencil_3D_point_to_render_space(const float3 co) | float2 GpencilIO::gpencil_3D_point_to_render_space(const float3 co, const bool is_ortho) | ||||
| { | { | ||||
| float3 parent_co = diff_mat_ * co; | float3 parent_co = diff_mat_ * co; | ||||
| mul_m4_v3(persmat_, parent_co); | mul_m4_v3(persmat_, parent_co); | ||||
| parent_co.x = parent_co.x / max_ff(FLT_MIN, parent_co[2]); | if (!is_ortho) { | ||||
| parent_co.y = parent_co.y / max_ff(FLT_MIN, parent_co[2]); | parent_co.x = parent_co.x / max_ff(FLT_MIN, parent_co.z); | ||||
| parent_co.y = parent_co.y / max_ff(FLT_MIN, parent_co.z); | |||||
| } | |||||
| float2 r_co; | float2 r_co; | ||||
| r_co.x = (parent_co.x + 1.0f) / 2.0f * (float)render_x_; | r_co.x = (parent_co.x + 1.0f) / 2.0f * (float)render_x_; | ||||
| r_co.y = (parent_co.y + 1.0f) / 2.0f * (float)render_y_; | r_co.y = (parent_co.y + 1.0f) / 2.0f * (float)render_y_; | ||||
| /* Invert X axis. */ | /* Invert X axis. */ | ||||
| if (invert_axis_[0]) { | if (invert_axis_[0]) { | ||||
| r_co.x = (float)render_x_ - r_co.x; | r_co.x = (float)render_x_ - r_co.x; | ||||
| } | } | ||||
| /* Invert Y axis. */ | /* Invert Y axis. */ | ||||
| if (invert_axis_[1]) { | if (invert_axis_[1]) { | ||||
| r_co.y = (float)render_y_ - r_co.y; | r_co.y = (float)render_y_ - r_co.y; | ||||
| } | } | ||||
| return r_co; | return r_co; | ||||
| } | } | ||||
| /** Convert to 2D. */ | /** Convert to 2D. */ | ||||
| float2 GpencilIO::gpencil_3D_point_to_2D(const float3 co) | float2 GpencilIO::gpencil_3D_point_to_2D(const float3 co, const bool is_ortho) | ||||
| { | { | ||||
| const bool is_camera = (bool)(rv3d_->persp == RV3D_CAMOB); | const bool is_camera = (bool)(rv3d_->persp == RV3D_CAMOB); | ||||
| if (is_camera) { | if (is_camera) { | ||||
| return gpencil_3D_point_to_render_space(co); | return gpencil_3D_point_to_render_space(co, is_ortho); | ||||
| } | } | ||||
| float2 result; | float2 result; | ||||
| gpencil_3D_point_to_screen_space(co, result); | gpencil_3D_point_to_screen_space(co, result); | ||||
| return result; | return result; | ||||
| } | } | ||||
| /** Get radius of point. */ | /** Get radius of point. */ | ||||
| float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) | float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, bGPDstroke *gps) | ||||
| { | { | ||||
| bGPDspoint *pt = &gps->points[0]; | bGPDspoint *pt = &gps->points[0]; | ||||
| const float2 screen_co = gpencil_3D_point_to_2D(&pt->x); | const float2 screen_co = gpencil_3D_point_to_2D(&pt->x, is_orthographic()); | ||||
| /* Radius. */ | /* Radius. */ | ||||
| bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view( | bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view( | ||||
| rv3d_, gpd_, gpl, gps, 3, diff_mat_.values); | rv3d_, gpd_, gpl, gps, 3, diff_mat_.values); | ||||
| pt = &gps_perimeter->points[0]; | pt = &gps_perimeter->points[0]; | ||||
| const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x); | const float2 screen_ex = gpencil_3D_point_to_2D(&pt->x, is_orthographic()); | ||||
| const float2 v1 = screen_co - screen_ex; | const float2 v1 = screen_co - screen_ex; | ||||
| float radius = v1.length(); | float radius = v1.length(); | ||||
| BKE_gpencil_free_stroke(gps_perimeter); | BKE_gpencil_free_stroke(gps_perimeter); | ||||
| return MAX2(radius, 1.0f); | return MAX2(radius, 1.0f); | ||||
| } | } | ||||
| Show All 32 Lines | float GpencilIO::stroke_average_opacity_get() | ||||
| return avg_opacity_; | return avg_opacity_; | ||||
| } | } | ||||
| bool GpencilIO::is_camera_mode() | bool GpencilIO::is_camera_mode() | ||||
| { | { | ||||
| return is_camera_; | return is_camera_; | ||||
| } | } | ||||
| bool GpencilIO::is_orthographic() | |||||
| { | |||||
| return is_ortho_; | |||||
| } | |||||
| /* Calculate selected strokes boundbox. */ | /* Calculate selected strokes boundbox. */ | ||||
| void GpencilIO::selected_objects_boundbox_calc() | void GpencilIO::selected_objects_boundbox_calc() | ||||
| { | { | ||||
| const float gap = 10.0f; | const float gap = 10.0f; | ||||
| float2 min, max; | float2 min, max; | ||||
| INIT_MINMAX2(min, max); | INIT_MINMAX2(min, max); | ||||
| Show All 14 Lines | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_eval->layers) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | ||||
| if (gps->totpoints == 0) { | if (gps->totpoints == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (const bGPDspoint &pt : MutableSpan(gps->points, gps->totpoints)) { | for (const bGPDspoint &pt : MutableSpan(gps->points, gps->totpoints)) { | ||||
| const float2 screen_co = gpencil_3D_point_to_2D(&pt.x); | const float2 screen_co = gpencil_3D_point_to_2D(&pt.x, is_orthographic()); | ||||
| minmax_v2v2_v2(min, max, screen_co); | minmax_v2v2_v2(min, max, screen_co); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Add small gap. */ | /* Add small gap. */ | ||||
| add_v2_fl(min, gap * -1.0f); | add_v2_fl(min, gap * -1.0f); | ||||
| add_v2_fl(max, gap); | add_v2_fl(max, gap); | ||||
| Show All 21 Lines | |||||