Skip to content

USD CameraAlgo : Fix reading and writing of cameras without shutter values #1472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: RB-10.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
10.5.x.x (relative to 10.5.15.0)
========

Fixes
-----

- USDScene :
- Fixed writing of shutter values from cameras without a `shutter` parameter. The `shutter:open` and `shutter:close` attributes are now omitted instead of being written with Cortex's default -0.5, 0.5 shutter values.
- Fixed reading of shutter values from cameras without `shutter:open` and `shutter:close` attributes. The `shutter` parameter is now omitted instead of being created with USD's default 0, 0 shutter values.

10.5.15.0 (relative to 10.5.14.1)
=========
Expand Down
30 changes: 19 additions & 11 deletions contrib/IECoreUSD/src/IECoreUSD/CameraAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ IECore::ObjectPtr readCamera( pxr::UsdGeomCamera &camera, pxr::UsdTimeCode time,
result->setFocusDistance( focusDistance );

Imath::V2d shutter;
camera.GetShutterOpenAttr().Get( &shutter[0], time );
camera.GetShutterCloseAttr().Get( &shutter[1], time );
result->setShutter( shutter );
auto shutterOpenAttr = camera.GetShutterOpenAttr();
auto shutterCloseAttr = camera.GetShutterCloseAttr();
if( shutterOpenAttr.HasAuthoredValue() || shutterCloseAttr.HasAuthoredValue() )
{
shutterOpenAttr.Get( &shutter[0], time );
shutterCloseAttr.Get( &shutter[1], time );
result->setShutter( shutter );
}

return result;
}
Expand Down Expand Up @@ -188,14 +193,17 @@ bool writeCamera( const IECoreScene::Camera *camera, const pxr::UsdStagePtr &sta
usdCamera.GetFStopAttr().Set( camera->getFStop() );
usdCamera.GetFocusDistanceAttr().Set( camera->getFocusDistance() );

/// \todo This is documented as being specified in UsdTimeCode units,
/// in which case I think we should be converting from seconds using
/// `stage->GetTimeCodesPerSecond()`. Having looked at both the Maya
/// and Houdini plugin sources, I've been unable to find evidence for
/// anyone else doing this though, so maybe it's one of those things
/// everyone is just getting wrong?
usdCamera.GetShutterOpenAttr().Set( (double)camera->getShutter()[0] );
usdCamera.GetShutterCloseAttr().Set( (double)camera->getShutter()[1] );
if( camera->hasShutter() )
{
/// \todo This is documented as being specified in UsdTimeCode units,
/// in which case I think we should be converting from seconds using
/// `stage->GetTimeCodesPerSecond()`. Having looked at both the Maya
/// and Houdini plugin sources, I've been unable to find evidence for
/// anyone else doing this though, so maybe it's one of those things
/// everyone is just getting wrong?
usdCamera.GetShutterOpenAttr().Set( (double)camera->getShutter()[0] );
usdCamera.GetShutterCloseAttr().Set( (double)camera->getShutter()[1] );
}

return true;
}
Expand Down
16 changes: 14 additions & 2 deletions contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,13 @@ def formatCameraName( **kw ) :
name = formatCameraName( scale = scale )
testCameras[name] = c

for shutterOpen in [ 0, -0.25, -1.0 ] :
for shutterClose in [ 0, 0.25, 1.0 ] :
c = IECoreScene.Camera()
c.setShutter( imath.V2f( shutterOpen, shutterClose ) )
name = formatCameraName( shutterOpen = shutterOpen, shutterClose = shutterClose )
testCameras[name] = c

root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )

for name, c in testCameras.items() :
Expand Down Expand Up @@ -1321,8 +1328,12 @@ def formatCameraName( **kw ) :
self.assertEqual( c.clippingRange.max, cortexCam.getClippingPlanes()[1] )
self.assertEqual( c.fStop, cortexCam.getFStop() )
self.assertEqual( c.focusDistance, cortexCam.getFocusDistance() )
self.assertEqual( cG.GetShutterOpenAttr().Get(), cortexCam.getShutter()[0] )
self.assertEqual( cG.GetShutterCloseAttr().Get(), cortexCam.getShutter()[1] )
if cortexCam.hasShutter() :
self.assertEqual( cG.GetShutterOpenAttr().Get(), cortexCam.getShutter()[0] )
self.assertEqual( cG.GetShutterCloseAttr().Get(), cortexCam.getShutter()[1] )
else :
self.assertFalse( cG.GetShutterOpenAttr().HasAuthoredValue() )
self.assertFalse( cG.GetShutterCloseAttr().HasAuthoredValue() )

try :
from pxr import CameraUtil
Expand Down Expand Up @@ -1389,6 +1400,7 @@ def assertVectorsAlmostEqual( a, b,**kw ) :
self.assertEqual( c2.getClippingPlanes(), c.getClippingPlanes() )
self.assertEqual( c2.getFStop(), c.getFStop() )
self.assertEqual( c2.getFocusDistance(), c.getFocusDistance() )
self.assertEqual( c2.hasShutter(), c.hasShutter() )
self.assertEqual( c2.getShutter(), c.getShutter() )

assertVectorsAlmostEqual( c2.frustum().min(), c.frustum().min(), places = 6 )
Expand Down