Skip to content

Conversation

wengn
Copy link

@wengn wengn commented Feb 1, 2020

Add functions in USDScene.cpp so that SceneReader node will be able to read usdGeomCamera correctly and convert it to IECoreScene::camera into Gaffer.

Checklist

  • I have read the contribution guidelines.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

wengn and others added 2 commits February 1, 2020 12:31
Merge ImageEngine cortex master to my fork
Add functions to UsdScene.cpp so that usdGeomCamera will be read
correctly and converted to IECoreScene camera.

Tests : Add Unit test for importing UsdGeomCamera
Copy link
Contributor

@dboogert dboogert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR Naiqi ! These are only suggestions on how to improve the PR and hopefully they're uncontentious to the official cortex developers.

Gafffer & Cortex have reasonably strict formatting rules and these stand out to me :

  • Use tabs instead of spaces
  • There is almost always a space after '(' and before ')' unless it's '()'
  • rebase your branch onto origin/master to avoid merge commits to update your topic branch to upstream/master

GetStereoRoleAttr perhaps this should be copied to the Camera somewheere? A Camera is a BlindDataHolder so perhaps the attribute should be serialized there and written back out if it exists?

result->setApertureOffset(Imath::V2f(horizontalOff / 10.0f, verticalOff / 10.0f));

}
else { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently all possible values for projToken are covered. Perhaps we should warn in the else if another camera type is added to USD?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't handle it on the way out, so I'd be happy just leaving out the else {} for now.

self.assertTrue( camera.hasObject() )

cameraObj = camera.readObject( 0.0 )
self.failUnless( isinstance( cameraObj, IECoreScene.Camera ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd test all of the attributes in we expect to be transferred from the camera. In fact it would be great to round trip a camera in testing, i.e. create a camera in cortex, write to USD and read back in again with as little data loss as possible.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely need to test all values for read at minimum. A roundtrip test as well would be ideal, but in addition to a read test - to make sure we test reading data in we haven't authored.

@themissingcow themissingcow self-requested a review February 6, 2020 14:52
@themissingcow
Copy link

Hey Naiqi, thanks for getting this up! Looking promising. I'll get back to you with a proper review soon - sorry we're just in the middle of a big Gaffer release so have been somewhat busy.

These are only suggestions on how to improve the PR and hopefully they're uncontentious to the official cortex developers.

Thanks @dboogert, you are spot on with your comments there.

@wengn
Copy link
Author

wengn commented Feb 7, 2020 via email

@themissingcow
Copy link

@tom, I do have a question for this: I just found out for this camera to be able to work properly inside of Gaffer as a renderable camera, I need to change some of Gaffer's RenderController code as well.

Are you able to explain a little more why you need to change RenderController? I wouldn't expect there to be any changes needed there.

I am wondering in this kind of situation, what's the proper procedure to submit PR for Gaffer
repo?

The procedure for gaffer is pretty much the same as for cortex. ie:

  • Discuss the intended changes on the list first so we can make sure it fits with the Gaffer approach before you spend any time on it.
  • Fork gaffer and make a topic branch from the appropriate GafferHQ branch with your changes (we have maintenance branches for older versions, depending on the nature of the work).
  • Submit a PR.

'best
Tom

@wengn
Copy link
Author

wengn commented Feb 7, 2020 via email

@johnhaddon
Copy link
Member

I suspect the Gaffer crash may be because the camera is not in the cameras set. We should probably look at generating the cameras set automatically in the USD reader as well.

@themissingcow
Copy link

themissingcow commented Feb 10, 2020

Hey Naiqi, Thanks for the extra details.

Hi, Tom This is the reason: if I only convert the output object of SceneReader to be IECore::camera into the scene, when you have the following graph for rendering, Arnold can't recognize this object as known camera, therefore it will crash if you click on the render button on "InterativeArnoldRender" node.

Right, cool. As John alluded to, this is actually a 'known issue we've been meaning to sort for a while. You have the same crash with alembic cameras.

It happens as at the beginning of the render Gaffer translates all of the cameras in the __cameras set (which is also used to populate the Viewer UI camera pickers) to the renderer. If your camera isn't in that set, then it doesn't get converted, and the crash you noted happens. What we need to do is this:

  1. Fix the crash - it should just be an informative error. I'll sort that soon.
  2. Ensure the USD reader (and the Alembic one too) populates the __cameras set with all the cameras in the file that's being read. That's a bigger change though, so probably best to tackle that in another PR.

So don't worry about the IECoreArnoldPreview changes for now, we'll take care of those. If you are able to address Don's comments though that would be fantastic.

Many thanks again for all the time you've spent on this!
'best
Tom

For now, you can also use the Set node to add your cameras to the __cameras set, which should stop the crash.

Copy link

@themissingcow themissingcow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together Naiqi, this is going to be a great addition. Don beat me to commenting on the more general coding standards topics. I've added a few other notes in here too.

Comment on lines +1044 to +1046
result->setFocalLength(focalLengthVal / scale);
result->setAperture(Imath::V2f(horizontalAper / scale, verticalAper / scale));
result->setApertureOffset(Imath::V2f(horizontalOff / scale, verticalOff / scale));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to factor in scale here. I believe it cancels out as long as they're in the same units. The only time the actual dimensions become meaningful is in relation to setFocusDistance and the resulting DoF blur. @danieldresser-ie may be able to confirm.

Comment on lines +1038 to +1040
// We store focalLength and aperture in arbitary units. USD uses tenths
// of scene units
float scale = 10.0f * result->getFocalLengthWorldScale();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think because of the USD assumption, this can just be:

result->setFocalLengthWorldScale( 0.1f );

I think this is working right now as the default for a newly created IECoreScene::Camera is 0.1 so scale will always end up just being 1.0f.

I noticed that USD allows you to specify the linear encoding units in the file. I had a quick chat with @johnhaddon and we can leave supporting this for another time (as it needs some thought on the right way to do it), so just setting the 'assumed' scale is fine for now, unless it's going to cause issues for you.

result->setApertureOffset(Imath::V2f(horizontalOff / 10.0f, verticalOff / 10.0f));

}
else { }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't handle it on the way out, so I'd be happy just leaving out the else {} for now.

@@ -31,7 +31,6 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-instate this line, we try to keep any whitespace changes in their own commits if they're required.

self.assertTrue( camera.hasObject() )

cameraObj = camera.readObject( 0.0 )
self.failUnless( isinstance( cameraObj, IECoreScene.Camera ) )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely need to test all values for read at minimum. A roundtrip test as well would be ideal, but in addition to a read test - to make sure we test reading data in we haven't authored.

@themissingcow themissingcow self-assigned this Feb 10, 2020
@johnhaddon
Copy link
Member

I've implemented camera reading again in #1082, since progress seems to have stalled here and IECoreUSD has changed a lot in the intervening period. Once #1082 is merged we should be able to close this, and then I'll open another PR to make the __cameras set.

@johnhaddon
Copy link
Member

Closing - IECoreUSD now reads cameras and the __cameras set.

@johnhaddon johnhaddon closed this Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants