GafferHQ / gaffer

Gaffer is a node-based application for lookdev, lighting and automation
http://www.gafferhq.org
BSD 3-Clause "New" or "Revised" License
950 stars 205 forks source link

LayoutEngine::applyPositions bug #5552

Open JeremyBooks opened 10 months ago

JeremyBooks commented 10 months ago

Version: Gaffer 1.3.0.0-linux Third-party tools: Arnold Third-party modules: N/A

Description

When programmatically creating many nodes and connect them to a GafferScene::Group node, the LayoutEngine::applyPositions will fail to set positions if you have 40 or more nodes...

Steps to reproduce

Run the following snippet to see expected behavior

root["Group"] = GafferScene.Group()
for x in range(39):
     name = "node_{}".format(x)
     root[name] = GafferScene.SceneNode()
     root["Group"]["in"].next().setInput(root[name]["out"])

Run the following snippet to see incorrect behavior

root["Group"] = GafferScene.Group()
for x in range(40):
     name = "node_{}".format(x)
     root[name] = GafferScene.SceneNode()
     root["Group"]["in"].next().setInput(root[name]["out"])
johnhaddon commented 10 months ago

Related to #4255. Jeremy, in the meantime it might be useful to know that you can programmatically set the position of a node using GraphGadget::setNodePosition() so you may be able to work around by defining node positions yourself, knowing the specific arrangement you're wanting.

JeremyBooks commented 10 months ago

thanks John, yeah I was going to do that if needed. However because of some other issues with the logic of the script, I had to restructure it to use multiple group nodes. So hopefully that means we should not be effected by this often or at all.

johnhaddon commented 10 months ago

Are you familiar with CollectScenes at all? It can often do the same thing as a Group but without needing to have an input per child.

JeremyBooks commented 10 months ago

I know of it, but I have not thought of a use case for it though. I am loading in multiple USD stages with the SceneReader Node and using Group nodes to group them by "asset type", namespace etc

johnhaddon commented 10 months ago

That's exactly what CollectScenes is good at. You give it a list of root locations (where you want each subscene to end up in the output scene), and then for each of those it pulls on a single input scene with a context variable saying which root it is being evaluated for. So then you can use an expression to choose the right filename for the SceneReader (or customise the subscene in any other way you want). The nice thing is you don't need to keep adding and removing nodes as the number of assets changes - instead you just change the rootNames the CollectScenes uses, which can also be driven dynamically by an expression. I think I posted a very simple example in this thread :

https://groups.google.com/u/1/g/gaffer-dev/c/jyGXgx-MkL8/m/12AtzcErCAAJ

JeremyBooks commented 10 months ago

wow that is quite interesting!! I am a big fan of that. I might explore other options to creating that "assetDataBase" to better integrate with our "shot manager" UI. Thank you for the info John!