[Bf-blender-cvs] [921d0851b50] master: Fix T86942: GPencil does not export SVG or PDF in orthographic camera

Antonio Vazquez noreply at git.blender.org
Fri Mar 26 16:07:05 CET 2021


Commit: 921d0851b50d621930e7ecee5f79af0dc259dc98
Author: Antonio Vazquez
Date:   Fri Mar 26 15:52:49 2021 +0100
Branches: master
https://developer.blender.org/rB921d0851b50d621930e7ecee5f79af0dc259dc98

Fix T86942: GPencil does not export SVG or PDF in orthographic camera

The calculation of the 2D point was wrong when using orthographic mode.

Also small cleanup in float3 variable.

Differential Revision: https://developer.blender.org/D10828

===================================================================

M	source/blender/io/gpencil/intern/gpencil_io_base.cc
M	source/blender/io/gpencil/intern/gpencil_io_base.h

===================================================================

diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 855252e648c..e41209811f5 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -85,9 +85,11 @@ GpencilIO::GpencilIO(const GpencilIOParams *iparams)
     invert_m4_m4(viewmat, cam_ob->obmat);
 
     mul_m4_m4m4(persmat_, params.winmat, viewmat);
+    is_ortho_ = params.is_ortho;
   }
   else {
     unit_m4(persmat_);
+    is_ortho_ = false;
   }
 
   winx_ = params_.region->winx;
@@ -112,6 +114,7 @@ GpencilIO::GpencilIO(const GpencilIOParams *iparams)
   }
   else {
     is_camera_ = false;
+    is_ortho_ = false;
     /* Calc selected object boundbox. Need set initial value to some variables. */
     camera_ratio_ = 1.0f;
     offset_.x = 0.0f;
@@ -228,13 +231,15 @@ bool GpencilIO::gpencil_3D_point_to_screen_space(const float3 co, float2 &r_co)
 }
 
 /** 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;
   mul_m4_v3(persmat_, parent_co);
 
-  parent_co.x = parent_co.x / max_ff(FLT_MIN, parent_co[2]);
-  parent_co.y = parent_co.y / max_ff(FLT_MIN, parent_co[2]);
+  if (!is_ortho) {
+    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;
   r_co.x = (parent_co.x + 1.0f) / 2.0f * (float)render_x_;
@@ -257,7 +262,7 @@ float2 GpencilIO::gpencil_3D_point_to_2D(const float3 co)
 {
   const bool is_camera = (bool)(rv3d_->persp == RV3D_CAMOB);
   if (is_camera) {
-    return gpencil_3D_point_to_render_space(co);
+    return gpencil_3D_point_to_render_space(co, is_orthographic());
   }
   float2 result;
   gpencil_3D_point_to_screen_space(co, result);
@@ -324,6 +329,11 @@ bool GpencilIO::is_camera_mode()
   return is_camera_;
 }
 
+bool GpencilIO::is_orthographic()
+{
+  return is_ortho_;
+}
+
 /* Calculate selected strokes boundbox. */
 void GpencilIO::selected_objects_boundbox_calc()
 {
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 986221618b7..cbcd35e470d 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -87,13 +87,14 @@ class GpencilIO {
 
   /* Geometry functions. */
   bool gpencil_3D_point_to_screen_space(const float3 co, float2 &r_co);
-  float2 gpencil_3D_point_to_render_space(const float3 co);
+  float2 gpencil_3D_point_to_render_space(const float3 co, const bool is_ortho);
   float2 gpencil_3D_point_to_2D(const float3 co);
 
   float stroke_point_radius_get(struct bGPDlayer *gpl, struct bGPDstroke *gps);
   void create_object_list();
 
   bool is_camera_mode();
+  bool is_orthographic();
 
   float stroke_average_opacity_get();
 
@@ -107,6 +108,7 @@ class GpencilIO {
  private:
   float avg_opacity_;
   bool is_camera_;
+  bool is_ortho_;
   rctf select_boundbox_;
 
   /* Camera matrix. */



More information about the Bf-blender-cvs mailing list