[Bf-blender-cvs] [46276c71103] usd-importer-T81257: USDReaderCamera implementation.

Michael A. Kowalski noreply at git.blender.org
Fri Nov 13 23:51:30 CET 2020


Commit: 46276c711033bc1c270ed36e296cc61a7166bd9d
Author: Michael A. Kowalski
Date:   Fri Nov 13 17:48:54 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rB46276c711033bc1c270ed36e296cc61a7166bd9d

USDReaderCamera implementation.

Finished first pass of camera import.  Added
support for orthographic cameras.  Adjusting
camera rotation when converting from y-up
to z-up. USDXformableReader::read_matrix()
is now virtual.

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

M	source/blender/io/usd/import/usd_reader_camera.cc
M	source/blender/io/usd/import/usd_reader_camera.h
M	source/blender/io/usd/import/usd_reader_xformable.cc
M	source/blender/io/usd/import/usd_reader_xformable.h

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

diff --git a/source/blender/io/usd/import/usd_reader_camera.cc b/source/blender/io/usd/import/usd_reader_camera.cc
index 092021137e7..6ad2b55dcb0 100644
--- a/source/blender/io/usd/import/usd_reader_camera.cc
+++ b/source/blender/io/usd/import/usd_reader_camera.cc
@@ -25,6 +25,10 @@
 #include "BKE_camera.h"
 #include "BKE_object.h"
 
+#include "BLI_math_base.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math_rotation.h"
+
 #include <iostream>
 
 namespace blender::io::usd {
@@ -84,6 +88,8 @@ void USDCameraReader::create_object(Main *bmain, double time)
   const float v_film_offset = usd_cam.GetVerticalApertureOffset();
   const float film_aspect = apperture_x / apperture_y;
 
+  bcam->type = usd_cam.GetProjection() == pxr::GfCamera::Perspective ? CAM_PERSP : CAM_ORTHO;
+
   bcam->lens = usd_cam.GetFocalLength();
 
   bcam->sensor_x = apperture_x;
@@ -102,4 +108,19 @@ void USDCameraReader::create_object(Main *bmain, double time)
   this->object_->data = bcam;
 }
 
+void USDCameraReader::read_matrix(float r_mat[4][4] /* local matrix */,
+                                  const double time,
+                                  const float scale) const
+{
+  USDXformableReader::read_matrix(r_mat, time, scale);
+
+  /* Conveting from y-up to z-up requires adjusting
+   * the camera rotation. */
+  if (this->context_.stage_up_axis == pxr::UsdGeomTokens->y) {
+    float camera_rotation[4][4];
+    axis_angle_to_mat4_single(camera_rotation, 'X', M_PI_2);
+    mul_m4_m4m4(r_mat, r_mat, camera_rotation);
+  }
+}
+
 }  // namespace blender::io::usd
diff --git a/source/blender/io/usd/import/usd_reader_camera.h b/source/blender/io/usd/import/usd_reader_camera.h
index 194fd5909d3..26614f86d28 100644
--- a/source/blender/io/usd/import/usd_reader_camera.h
+++ b/source/blender/io/usd/import/usd_reader_camera.h
@@ -36,6 +36,8 @@ class USDCameraReader : public USDXformableReader {
   bool valid() const override;
 
   void create_object(Main *bmain, double time) override;
+
+  void read_matrix(float r_mat[4][4], const double time, const float scale) const override;
 };
 
 }  // namespace blender::io::usd
diff --git a/source/blender/io/usd/import/usd_reader_xformable.cc b/source/blender/io/usd/import/usd_reader_xformable.cc
index af5cb3558e3..f39abf802d4 100644
--- a/source/blender/io/usd/import/usd_reader_xformable.cc
+++ b/source/blender/io/usd/import/usd_reader_xformable.cc
@@ -57,10 +57,9 @@ void USDXformableReader::set_object_transform(const double time)
     return;
   }
 
-  bool is_constant = false;
   float transform_from_usd[4][4];
 
-  this->read_matrix(transform_from_usd, time, this->context_.import_params.scale, is_constant);
+  this->read_matrix(transform_from_usd, time, this->context_.import_params.scale);
 
   /* Apply the matrix to the object. */
   BKE_object_apply_mat4(object_, transform_from_usd, true, false);
@@ -71,19 +70,15 @@ void USDXformableReader::set_object_transform(const double time)
 
 void USDXformableReader::read_matrix(float r_mat[4][4] /* local matrix */,
                                      const double time,
-                                     const float scale,
-                                     bool &is_constant)
+                                     const float scale) const
 {
   pxr::UsdGeomXformable xformable(prim_);
 
   if (!xformable) {
     unit_m4(r_mat);
-    is_constant = true;
     return;
   }
 
-  /* TODO(makowalski):  Check for constant transform. */
-
   pxr::GfMatrix4d usd_local_xf;
   bool reset_xform_stack;
   xformable.GetLocalTransformation(&usd_local_xf, &reset_xform_stack, time);
diff --git a/source/blender/io/usd/import/usd_reader_xformable.h b/source/blender/io/usd/import/usd_reader_xformable.h
index 8e8cecacc0e..3f3503dcfda 100644
--- a/source/blender/io/usd/import/usd_reader_xformable.h
+++ b/source/blender/io/usd/import/usd_reader_xformable.h
@@ -91,7 +91,7 @@ class USDXformableReader : public USDPrimReader {
 
   void set_object_transform(const double time);
 
-  void read_matrix(float r_mat[4][4], const double time, const float scale, bool &is_constant);
+  virtual void read_matrix(float r_mat[4][4], const double time, const float scale) const;
 };
 
 } /* namespace blender::io::usd */



More information about the Bf-blender-cvs mailing list