What's the best way to support USD instance in gaffer?

296 views
Skip to first unread message

Naiqi Weng

unread,
Dec 27, 2019, 5:14:47 AM12/27/19
to gaffer-dev
Hi, 
Merry Christmas and Happy holidays everyone!

We are trying to use USD as much as we can in our pipeline. For example we would like to be able to parse usd instance with SceneReader in Gaffer and render it. I asked about UsdGeomPointInstancer before, and understand it is basically the similar workflow, but I still have some questions with regards to the inputs of the "instancer" node. From previous discussion, my understanding is that I need to get the instanced mesh locations using sceneReader and the actual geometry using a second sceneReader and input them to instancer node, but it looks like I don't have any control over the output of "sceneReader" node, then how do I specifically pass those information to "instancer" node.  It looks to me "instancer" node has 2 inputs: "in" (which is a scene plug) and "instances".
Can anyone help me solving this puzzle? 

Thanks a lot!
Naiqi

Don Boogert

unread,
Dec 27, 2019, 2:21:14 PM12/27/19
to gaffe...@googlegroups.com
Here is a an example to start you off.

You'll need to download the `city set` example from here : http://graphics.pixar.com/usd/downloads.html

I'm not sure about the orientation & scale attributes right now and will work on adding more to the example scene, but it does demonstrate how to prepare USD point instancer data for use with gaffer's instancer.

Cheers

- Don


--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/d0e8207f-26c8-43b7-96bb-78a198859124%40googlegroups.com.
usd-instancer.gfr

Naiqi Weng

unread,
Dec 29, 2019, 10:53:01 PM12/29/19
to gaffer-dev
Hi, Don

Thanks for the scene file. For some reason, whenver I clicked on the "OSLObject" node, Gaffer crashed on my end.  And my question to your set-up is: what's the input plug"instances" of instancer node connecting?  

I just wanted to clarify a little bit. I saw example in this thread how to prepare the data and send it to a "instancer" node. 

My question is: if I have multiple prims instanced to a single mesh in a USD file(note, this is not using point instance in USD, just regular instance, but I guess the workflow is very similar),  how do I use "SceneReader" to output information to "instancer" node? A USD instance example could be like this: 


#usda 1.0

over "InstanceSources" (
    prepend references = @/mnt/pubTempData/users/wengn/usdFile/qingtongniao.usda@
)
{
}

def Xform "qingtongniao_000000" (
    kind = "assembly"
    prepend references = </InstanceSources>
    instanceable = true
)
{
    float3 xformOp:rotateXYZ = (0, 167.93382, 0)
    double3 xformOp:translate = (1507.870849609375, 0, -585)
    uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
}

def Xform "qingtongniao_000001" (
    kind = "assembly"
    prepend references = </InstanceSources>
    instanceable = true
)
{
    float3 xformOp:rotateXYZ = (0, 258.27264, 0)
    double3 xformOp:translate = (843.3968505859375, 0, -1417)
    uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]

I see "SceneReader" node is just outputting a scene file, I am trying to figure out how to output correct information to connect this node to "instancer" node. My understanding is that I need to create 2 "SceneReader" node, one outputs the whole scene's transformation information to the "in" plug of "instancer" node, the second "SceneReader" node output the instanced mesh and plug it to the plug "instances" on the "instancer" node. And also I probaby need to change the USDScene code so that it output correct information that "instancer" node needs? 
Hopefully this is making sense....

My experience with Gaffer is pretty limited so far, so I may be asking a very easy question.


Thanks!

Naiqi


在 2019年12月28日星期六 UTC+8上午3:21:14,Don Boogert写道:
Here is a an example to start you off.

You'll need to download the `city set` example from here : http://graphics.pixar.com/usd/downloads.html

I'm not sure about the orientation & scale attributes right now and will work on adding more to the example scene, but it does demonstrate how to prepare USD point instancer data for use with gaffer's instancer.

Cheers

- Don


On Fri, 27 Dec 2019 at 02:14, Naiqi Weng <nik...@gmail.com> wrote:
Hi, 
Merry Christmas and Happy holidays everyone!

We are trying to use USD as much as we can in our pipeline. For example we would like to be able to parse usd instance with SceneReader in Gaffer and render it. I asked about UsdGeomPointInstancer before, and understand it is basically the similar workflow, but I still have some questions with regards to the inputs of the "instancer" node. From previous discussion, my understanding is that I need to get the instanced mesh locations using sceneReader and the actual geometry using a second sceneReader and input them to instancer node, but it looks like I don't have any control over the output of "sceneReader" node, then how do I specifically pass those information to "instancer" node.  It looks to me "instancer" node has 2 inputs: "in" (which is a scene plug) and "instances".
Can anyone help me solving this puzzle? 

Thanks a lot!
Naiqi

--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffe...@googlegroups.com.

Don Boogert

unread,
Dec 31, 2019, 1:57:08 AM12/31/19
to gaffe...@googlegroups.com
Hi Naiqi,

Are you able to attach an example usd file which can be composed please (your example references a file on your local machine)?  I suspect we need to look into Gaffer's support of USD's SceneGraph instancing but a concrete self contained example would help make sure we're talking about the same thing. 

The Gaffer Instancer won't help with dealing with USD's SceneGraph graph instancing, AFAIK as it corresponds only to the USD PointInstancer as we convert the pointInstancer to a points primitive and then we can use the gaffer instancer.

I don't think Gaffer has an analogue of USD's scene graph instancing and I guess the best we can do now is verify that the instances are expanded out into the Gaffer Scene in a somewhat efficient way (the USD SceneInterface should be aware of instances and masters and return a single object / hash in these cases)

I'm including the following as a reference for USD PointInstancer -> Gaffer Instancer but don't think it's going to help you beyond verifying that it's not the thing you need:
  • updated the usd-instancer.gfr by saving from gaffer 0.55.1.0 rather than my development build, which could have been the source of your crash. 
  • animated gif as it demonstrates how the left input is PointsPrimitive and the right contains the prototypes of what you're going to instance at each point.

Cheers 
- Don


To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/71c4e5c1-c926-4c8c-823d-3125d52fcb3a%40googlegroups.com.
gaffer-point-instancer.gif
usd-instancer.gfr

Naiqi Weng

unread,
Jan 6, 2020, 2:05:13 AM1/6/20
to gaffer-dev

Hi, Don

Thanks for the example file. I was able to see it correctly in Gaffer0.55.
Unfortunately the usd file I was instancing cannot be shared, I can use a simpler file to replace this. Actually any usd file can be used, as long as you replace this line
 "prepend references = @/mnt/pubTempData/users/wengn/usdFile/qingtongniao.usda@" with its correct path.  If you want me to attach a simpler usd file, let me know. 

About your comments, "The Gaffer Instancer won't help with dealing with USD's SceneGraph graph instancing, AFAIK as it corresponds only to the USD PointInstancer as we convert the pointInstancer to a points primitive and then we can use the gaffer instancer."  I was not aware of this, I thought the instancer node is more of a general interface, and as long as you pass necessary information to it, it should be able to absorb the information. I mean, I understand Gaffer does not have an analogue of USD's scene graph instancing, but I thought I could organize the output from "SceneReader" node somehow, simliar to what you did in your pointInstancer example: use gaffer nodes to get position information of all the instancing prims from the "SceneReader" and pass it to "instancer" node as its first input, use gaffer nodes to get prototype mesh information (which is the usd instance prim master)  and pass it to "instancer" as second input, and instancer node should be able to understand and resolve the information. Does this make sense?  If what I am saying is possible, then the question becomes: what exactly information "SceneReader" node outputs? And what exactly "instancer" node needs on its "in" and "instances" input plug? And how to connect them together?


Thanks!
Naiqi





在 2019年12月31日星期二 UTC+8下午2:57:08,Don Boogert写道:

John Haddon

unread,
Jan 6, 2020, 6:32:47 AM1/6/20
to gaffe...@googlegroups.com
Hi guys,
This won't help immediately, but our intention is to eventually support UsdGeomPointInstancer directly in the SceneReader, so that what you see in Gaffer matches what you would see in USDView. I'm afraid we don't have a timetable for that yet though...
Cheers...
John

To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/691b5241-5378-4070-9958-f11c53b9333d%40googlegroups.com.


--
John Haddon - R&D Programmer
Image Engine
studio: +1-604-874-5634 | jo...@image-engine.com | www.image-engine.com



15 West 5th Avenue, Vancouver, BC, V5Y 1H4, Canada

If you are not the intended recipient, disclosure, copying, distribution and use of this email is prohibited. Please notify us immediately and delete this email from your systems. You may contact us at in...@image-engine.com if you do not wish to receive further commercial electronic messages. We may still send you messages for which we do not require consent.

Don Boogert

unread,
Jan 6, 2020, 11:28:07 AM1/6/20
to gaffe...@googlegroups.com
Hi Naiqi,



On Sun, 5 Jan 2020 at 23:05, Naiqi Weng <nik...@gmail.com> wrote:

Hi, Don

Thanks for the example file. I was able to see it correctly in Gaffer0.55.
Unfortunately the usd file I was instancing cannot be shared, I can use a simpler file to replace this. Actually any usd file can be used, as long as you replace this line
 "prepend references = @/mnt/pubTempData/users/wengn/usdFile/qingtongniao.usda@" with its correct path.  If you want me to attach a simpler usd file, let me know. 

I quickly tried this and I was unable to get it to work. It would be helpful it you supply a standalone repro case.

About your comments, "The Gaffer Instancer won't help with dealing with USD's SceneGraph graph instancing, AFAIK as it corresponds only to the USD PointInstancer as we convert the pointInstancer to a points primitive and then we can use the gaffer instancer."  I was not aware of this, I thought the instancer node is more of a general interface, and as long as you pass necessary information to it, it should be able to absorb the information. I mean, I understand Gaffer does not have an analogue of USD's scene graph instancing, but I thought I could organize the output from "SceneReader" node somehow, simliar to what you did in your pointInstancer example: use gaffer nodes to get position information of all the instancing prims from the "SceneReader" and pass it to "instancer" node as its first input, use gaffer nodes to get prototype mesh information (which is the usd instance prim master)  and pass it to "instancer" as second input, and instancer node should be able to understand and resolve the information. Does this make sense?

It completely makes sense but it's currently not possible to do without changing the USDSceneReader. My guess is we should change the USD Scene Reader to flatten the instancing. This might not be appropriate for some situations or also have performance penalties but at least the scene will load.
 
  If what I am saying is possible, then the question becomes: what exactly information "SceneReader" node outputs? And what exactly "instancer" node needs on its "in" and "instances" input plug? And how to connect them together?

This is a surprisingly difficult question to answer and I'm going to draft some notes on it as it's flexible, elegant & general but touch difficult to explain without some examples.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/691b5241-5378-4070-9958-f11c53b9333d%40googlegroups.com.

Naiqi Weng

unread,
Jan 13, 2020, 5:13:12 AM1/13/20
to gaffer-dev
Hi, Don

I have some simple instancing examples attached here. Let me know if you need anything else.

I can parse usd instance information inside of USDScene.cpp of IECoreUSD lib and add support for instancing information, as you suggested: flatten all the instanced objects to be real mesh objects, but the part I really miss is how to pass those information as output of "SceneReader" node and compose a graph of nodes for "instancer" node to digest.  

Thanks a lot!

Naiqi
在 2020年1月7日星期二 UTC+8上午12:28:07,Don Boogert写道:
Hi Naiqi,



instance_2.usda
HelloWorld.usda

Naiqi Weng

unread,
Jan 17, 2020, 4:09:38 AM1/17/20
to gaffer-dev
Hi, Don

Did you get a chance to look at my example file?

Thanks!
Naiqi

在 2020年1月13日星期一 UTC+8下午6:13:12,Naiqi Weng写道:

Don Boogert

unread,
Jan 18, 2020, 3:44:09 PM1/18/20
to gaffe...@googlegroups.com
Hi Naiqi,

I've taken another look and it should be simple to get the scene loading inefficiently using : https://graphics.pixar.com/usd/docs/api/prim_flags_8h.html#a0d604565b22c13d66365b04be5a8da12 in USDScene.cpp in cortex.

void USDScene::childNames( SceneInterface::NameList &childNames ) const
{
for( const auto &i : m_location->prim.GetFilteredChildren( pxr::UsdTraverseInstanceProxies() ) )
{
image.png

The problem with this is each instance's geometry will be considered unique by gaffer (and will get de-duplicated when sending to arnold) 

Hey John, would it be worth putting up a PR with just this change  or would you only accept a change with an update to the geometry hashes also along with it? I also tried to convert USD Shphere primitives to IECore::SpherePrimitive which didn't seem to work in gaffer - is there a limitation or did I probably mess it up?

Cheers

- Don

To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/36fa4d8c-8333-4388-881a-69bbb057ff0a%40googlegroups.com.

Don Boogert

unread,
Jan 18, 2020, 6:26:17 PM1/18/20
to gaffe...@googlegroups.com
> I also tried to convert USD Shphere primitives to IECore::SpherePrimitive which didn't seem to work in gaffer - is there a limitation or did I probably mess it up?

And the answer is I messed it up and will put up a UsdGeomSphere <-> IECoreScene::SpherePrimitive PR

Don Boogert

unread,
Jan 18, 2020, 6:41:50 PM1/18/20
to gaffe...@googlegroups.com
> would it be worth putting up a PR with just this change  or would you only accept a change with an update to the geometry hashes also along with it?

It looks like it should be quite simple to use Prim::IsInstance and Prim::GetMaster in the USDScene::objectHash to prevent multiple objects being created on USD scene read.

As for writing I don't think there is anything we can do apart from write the expanded scene back. Perhaps we could consider an automatic instancing write in the distant future?

- D


Naiqi Weng

unread,
Jan 20, 2020, 3:12:50 AM1/20/20
to gaffer-dev
Hi, Don

Thanks for the suggestion, this works on our side,  now we don't need to go through the "connecting SceneReader node to instancer node" pass. 

Thank you!

Naiqi

在 2020年1月19日星期日 UTC+8上午7:41:50,Don Boogert写道:

John Haddon

unread,
Jan 20, 2020, 4:17:51 AM1/20/20
to gaffe...@googlegroups.com
On Sat, Jan 18, 2020 at 8:44 PM Don Boogert <don.b...@gmail.com> wrote:
Hey John, would it be worth putting up a PR with just this change  or would you only accept a change with an update to the geometry hashes also along with it?

I think any support for USDGeomPointInstancer needs to include deduplicated hashes, because of the scale it is likely to be used at, and because of the inevitable performance comparisons to USD itself.

Bruno Pollet

unread,
Jul 15, 2020, 4:59:01 AM7/15/20
to gaffer-dev
Hi everyone. I'm bumping this thread because we're in trouble with our project and usd instancing in Gaffer.

We have to replicate 300 source buildings on 27000 instances. We have a setup in Houdini that does it, and when exporting the usd, we end up with a very small file size (under 1Mb) tha seem to correctly reference our houses. However when loading it in gaffer and rendering it with Arnold it seems to unique every instance. Which according to this discussions is actually what happens.

Then I read this line from Don :
"It looks like it should be quite simple to use Prim::IsInstance and Prim::GetMaster in the USDScene::objectHash to prevent multiple objects being created on USD scene read."

Is this something that can be done without coding ? Because right now the process is really long and memory intensive, we sometimes wait over 45 minutes before the render actually starts, and it seem to totally fail on computers with a lower ram budget.

Cheers,
Bruno

Tom Cowland

unread,
Jul 16, 2020, 1:04:42 PM7/16/20
to gaffe...@googlegroups.com
Hey Bruno,

Is this something that can be done without coding ? Because right now the process is really long and memory intensive, we sometimes wait over 45 minutes before the render actually starts, and it seem to totally fail on computers with a lower ram budget.

Sadly anything in that domain requires low level changes to our USD reader. In short, we don't have efficient instancing from USD at present. To get the best performance, you'd need to recreate the setup using Gaffers native instancer in the Node Graph. We've done a bunch of work in recent Gaffer versions to hopefully make it compatible with USD point-based setups. See: 

   http://www.gafferhq.org/documentation/0.57.0.0/Reference/NodeReference/GafferScene/Instancer.html#prototypemode

We are looking to improve our USD support soon, so this is definitely something we will investigate then.

Sorry not to be any more help,
Tom
Reply all
Reply to author
Forward
0 new messages