Skip to content

Commit

Permalink
LDTSurfacingSets
Browse files Browse the repository at this point in the history
  • Loading branch information
ireneh committed Mar 22, 2020
1 parent 5198b19 commit a9b5707
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
60 changes: 60 additions & 0 deletions plugins/gaffer/python/GafferSceneLDT/LDTSurfacingSets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import IECore
import Gaffer
import GafferArnold
import GafferScene
import imath
import ldtgaffer


class LDTSurfacingSets(GafferScene.SceneNode):
def __init__(self, name="LDTSurfacingSets"):
super(LDTSurfacingSets, self).__init__(name)
self.setName("LDTSurfacingSets")
self["in"] = GafferScene.ScenePlug(direction = Gaffer.Plug.Direction.In)
self["path"] = Gaffer.StringPlug( "path", defaultValue = '/')
self["prefix"] = Gaffer.StringPlug( "prefix", defaultValue = 'surf:')
self["attribute"] = Gaffer.StringPlug( "attribute", defaultValue = 'surfacing_object')
self["enabled"] = Gaffer.BoolPlug( "enabled", defaultValue = True)
self["out"] = GafferScene.ScenePlug(direction = Gaffer.Plug.Direction.Out)
self["out"].setFlags(Gaffer.Plug.Flags.Serialisable, False)
self["out"].setInput(self["in"])

self.__plugInputChanged = self.plugInputChangedSignal().connect(self.buildSets)
self.__plugValueChanged = self.plugSetSignal().connect(self.buildSets)

def buildSets(self, plug):
if plug.getName() in ("in", "prefix", "attribute", "path"):
nodeIn = self['in']
nodeOut = self['out']
prefix = self["prefix"].getValue()
hio = ldtgaffer.AttributesSearch(
nodeIn, self["path"].getValue(), self["attribute"].getValue())
setNodes = {}
numAttrs = len(hio.attributes.keys())
for idx, attr in enumerate(list(hio.attributes.keys())):
setNodes[idx] = GafferScene.Set(attr)
setNodes[idx]["name"].setValue(prefix + attr)
self.addChild(setNodes[idx])
filterNode = GafferScene.PathFilter(attr)
self.addChild(filterNode)
setNodes[idx]["filter"].setInput(filterNode["out"])
filterNode["paths"].setValue(IECore.StringVectorData(hio.attributes[attr]))
if idx == 0:
print("Setting up first set {}".format(prefix + attr))
setNodes[idx]["in"].setInput(nodeIn)
elif idx == numAttrs-1:
print("Finalising last set {}".format(prefix + attr))
setNodes[idx]["in"].setInput(setNodes[idx-1]["out"])
nodeOut.setInput(setNodes[idx]["out"])
else:
print("Connecting {} to {}".format(setNodes[idx-1]["name"].getValue(),
setNodes[idx]["name"].getValue()))
setNodes[idx]["in"].setInput(setNodes[idx-1]["out"])


IECore.registerRunTimeTyped(
LDTSurfacingSets, typeName="GafferScene::LDTSurfacingSets"
)



8 changes: 8 additions & 0 deletions plugins/gaffer/startup/gui/LDTNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from GafferSceneLDT import LDTShaderBall
from GafferSceneLDT import LDTAtttributeRead
from GafferSceneLDT import LDTGetBoundingBox
from GafferSceneLDT import LDTSurfacingSets

nodeMenu = GafferUI.NodeMenu.acquire(application)
nodeMenu.append(
Expand All @@ -27,6 +28,13 @@
searchText="LDTGetBoundingBox",
)

nodeMenu.append(
path="/LDT/LDTSurfacingSets",
nodeCreator=LDTSurfacingSets.LDTSurfacingSets,
searchText="LDTSurfacingSets",
)


print "LDT: nodes added to menu"


Expand Down

0 comments on commit a9b5707

Please sign in to comment.