Fix T100028: Convert USD camera properties to mm from USD units.
Authored by Sonny Campbell. Currently when importing a USD file, some of the camera properties are ignored, or the units are not converted correctly from USD world units. On import we currently set the focal length, but not the camera sensor size (horizontal and vertical aperture), so the camera field of view is wrong. The sensor size information is in the USD file, but is ignored for perspective cameras. USD uses "tenth of a world unit" scale for some physical camera properties like focal length and aperture. https://graphics.pixar.com/usd/release/api/class_usd_geom_camera.html#UsdGeom_CameraUnits I have added the UsdStage's metersPerUnit parameter to the ImportSettings so the camera can do the required conversion on import. This will convert from the USD file's world units to millimeters for Blender's camera settings. Reviewed by: Sybren and makowalski. Differential Revision: https://developer.blender.org/D16019
This commit is contained in:
@@ -155,6 +155,39 @@ class USDImportTest(AbstractUSDTest):
|
||||
coords = list(filter(lambda x: x[0] > 1.0, coords))
|
||||
self.assertGreater(len(coords), 16)
|
||||
|
||||
def test_import_camera_properties(self):
|
||||
"""Test importing camera to ensure properties set correctly."""
|
||||
|
||||
# This file has metersPerUnit = 1
|
||||
infile = str(self.testdir / "usd_camera_test_1.usda")
|
||||
res = bpy.ops.wm.usd_import(filepath=infile)
|
||||
self.assertEqual({'FINISHED'}, res)
|
||||
|
||||
camera_object = bpy.data.objects["Test_Camera"]
|
||||
test_cam = camera_object.data
|
||||
|
||||
self.assertAlmostEqual(43.12, test_cam.lens, 2)
|
||||
self.assertAlmostEqual(24.89, test_cam.sensor_width, 2)
|
||||
self.assertAlmostEqual(14.00, test_cam.sensor_height, 2)
|
||||
self.assertAlmostEqual(12.34, test_cam.shift_x, 2)
|
||||
self.assertAlmostEqual(56.78, test_cam.shift_y, 2)
|
||||
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
bpy.ops.object.delete()
|
||||
|
||||
# This file has metersPerUnit = 0.1
|
||||
infile = str(self.testdir / "usd_camera_test_2.usda")
|
||||
res = bpy.ops.wm.usd_import(filepath=infile)
|
||||
self.assertEqual({'FINISHED'}, res)
|
||||
|
||||
camera_object = bpy.data.objects["Test_Camera"]
|
||||
test_cam = camera_object.data
|
||||
|
||||
self.assertAlmostEqual(4.312, test_cam.lens, 3)
|
||||
self.assertAlmostEqual(2.489, test_cam.sensor_width, 3)
|
||||
self.assertAlmostEqual(1.400, test_cam.sensor_height, 3)
|
||||
self.assertAlmostEqual(1.234, test_cam.shift_x, 3)
|
||||
self.assertAlmostEqual(5.678, test_cam.shift_y, 3)
|
||||
|
||||
def main():
|
||||
global args
|
||||
|
||||
Reference in New Issue
Block a user