def testTargetScene(self): cube = GafferScene.Cube() sphere1 = GafferScene.Sphere() sphere1["transform"]["translate"]["x"].setValue(1) parent = GafferScene.Parent() parent["parent"].setValue("/") parent["in"].setInput(cube["out"]) parent["child"][0].setInput(sphere1["out"]) sphere2 = GafferScene.Sphere() sphere2["transform"]["translate"]["y"].setValue(1) cubeFilter = GafferScene.PathFilter() cubeFilter["paths"].setValue(IECore.StringVectorData(["/cube"])) constraint = GafferScene.ParentConstraint() constraint["in"].setInput(parent["out"]) constraint["filter"].setInput(cubeFilter["out"]) constraint["target"].setValue("/sphere") self.assertEqual(constraint["out"].fullTransform("/cube"), parent["out"].fullTransform("/sphere")) constraint["targetScene"].setInput(sphere2["out"]) self.assertEqual(constraint["out"].fullTransform("/cube"), sphere2["out"].fullTransform("/sphere")) sphere2["name"].setValue("ball") constraint["ignoreMissingTarget"].setValue(True) self.assertEqual(constraint["out"].fullTransform("/cube"), constraint["in"].fullTransform("/cube"))
def testFilter( self ) : sphere = GafferScene.Sphere() group = GafferScene.Group() for i in range( 0, 6 ) : group["in"][i].setInput( sphere["out"] ) cube = GafferScene.Cube() cube["sets"].setValue( "setA" ) filter = GafferScene.PathFilter() filter["paths"].setValue( IECore.StringVectorData( [ "/group/sphere[1-4]" ] ) ) parent = GafferScene.Parent() parent["in"].setInput( group["out"] ) parent["children"][0].setInput( cube["out"] ) parent["filter"].setInput( filter["out"] ) self.assertSceneValid( parent["out"] ) self.assertEqual( parent["out"].childNames( "/group/sphere" ), IECore.InternedStringVectorData() ) for i in range( 1, 5 ) : self.assertEqual( parent["out"].childNames( "/group/sphere{0}".format( i ) ), IECore.InternedStringVectorData( [ "cube" ] ) ) self.assertIn( "setA", parent["out"]["setNames"].getValue() ) self.assertEqual( parent["out"].set( "setA" ).value, IECore.PathMatcher( [ "/group/sphere1/cube", "/group/sphere2/cube", "/group/sphere3/cube", "/group/sphere4/cube", ] ) )
def testScenePathAsSelector(self): sphere = GafferScene.Sphere() cube = GafferScene.Cube() group = GafferScene.Group() group["in"][0].setInput(sphere["out"]) group["in"][1].setInput(cube["out"]) pathFilter = GafferScene.PathFilter() pathFilter["paths"].setValue( IECore.StringVectorData(["/group/sphere", "/group/cube"])) attributes = GafferScene.StandardAttributes() attributes["in"].setInput(group["out"]) attributes["filter"].setInput(pathFilter["out"]) attributes["attributes"]["deformationBlur"]["enabled"].setValue(True) spreadsheet = Gaffer.Spreadsheet() spreadsheet["selector"].setValue("${scene:path}") spreadsheet["rows"].addColumn( attributes["attributes"]["deformationBlur"]["value"]) attributes["attributes"]["deformationBlur"]["value"].setInput( spreadsheet["out"][0]) row = spreadsheet["rows"].addRow() row["name"].setValue("/group/cube") row["cells"][0]["value"].setValue(False) self.assertEqual( attributes["out"].attributes("/group/sphere") ["gaffer:deformationBlur"].value, True) self.assertEqual( attributes["out"].attributes("/group/cube") ["gaffer:deformationBlur"].value, False)
def __init__(self, name="SphereOrCube"): GafferScene.SceneNode.__init__(self, name) self["type"] = Gaffer.IntPlug( defaultValue=int(self.Type.Sphere), minValue=int(self.Type.Sphere), maxValue=int(self.Type.Cube), ) self["__sphere"] = GafferScene.Sphere() self["__sphere"]["enabled"].setInput(self["enabled"]) self["__cube"] = GafferScene.Cube() self["__cube"]["enabled"].setInput(self["enabled"]) self["__primitiveSwitch"] = Gaffer.Switch() self["__primitiveSwitch"].setup(GafferScene.ScenePlug()) self["__primitiveSwitch"]["index"].setInput(self["type"]) self["__primitiveSwitch"]["in"][0].setInput( self["__sphere"]["out"]) self["__primitiveSwitch"]["in"][1].setInput( self["__cube"]["out"]) self["out"].setInput(self["__primitiveSwitch"]["out"])
def testClosure( self ) : s = Gaffer.ScriptNode() c = GafferScene.Cube() s.addChild( c ) o = GafferOSL.OSLObject() s.addChild( o ) f = GafferScene.PathFilter( "PathFilter" ) s.addChild( f ) f["paths"].setValue( IECore.StringVectorData( [ '/cube' ] ) ) o["filter"].setInput( f["out"] ) o['in'].setInput( c["out"] ) o["primitiveVariables"].addChild( Gaffer.NameValuePlug( "testClosure", GafferOSL.ClosurePlug() ) ) code = GafferOSL.OSLCode( "OSLCode" ) code["out"].addChild( GafferOSL.ClosurePlug( "output1", direction = Gaffer.Plug.Direction.Out ) ) code["code"].setValue( 'output1 = debug( "testString", "type", "string", "stringValue", "foo" )\n + debug( "testPoint", "type", "point", "value", vector( 1, 10, 100 ) );' ) o["primitiveVariables"][0]["value"].setInput( code["out"]["output1"] ) cubeObject = s['OSLObject']['out'].object( "/cube" ) self.assertEqual( cubeObject["testString"].data, IECore.StringVectorData( ["foo"]*8 ) ) self.assertEqual( cubeObject["testPoint"].data, IECore.V3fVectorData( [ imath.V3f(1,10,100)] * 8, IECore.GeometricData.Interpretation.Point ) )
def testPruneReadOnlyReason( self ) : s = Gaffer.ScriptNode() s["cube"] = GafferScene.Cube() s["scope"] = Gaffer.EditScope() s["scope"].setup( s["cube"]["out"] ) s["scope"]["in"].setInput( s["cube"]["out"] ) s["box"] = Gaffer.Box.create( s, Gaffer.StandardSet( [ s["cube"], s["scope"] ] ) ) self.assertIsNone( GafferScene.EditScopeAlgo.prunedReadOnlyReason( s["box"]["scope"] ) ) for component in ( s["box"], s["box"]["scope"] ): Gaffer.MetadataAlgo.setReadOnly( component, True ) self.assertEqual( GafferScene.EditScopeAlgo.prunedReadOnlyReason( s["box"]["scope"] ), s["box"] ) Gaffer.MetadataAlgo.setReadOnly( s["box"], False ) self.assertEqual( GafferScene.EditScopeAlgo.prunedReadOnlyReason( s["box"]["scope"] ), s["box"]["scope"] ) Gaffer.MetadataAlgo.setReadOnly( s["box"]["scope"], False ) GafferScene.EditScopeAlgo.setPruned( s["box"]["scope"], "/cube", True ) self.assertIsNone( GafferScene.EditScopeAlgo.prunedReadOnlyReason( s["box"]["scope"] ) ) for component in ( s["box"]["scope"]["PruningEdits"]["paths"], s["box"]["scope"]["PruningEdits"], s["box"]["scope"], s["box"] ) : Gaffer.MetadataAlgo.setReadOnly( component, True ) self.assertEqual( GafferScene.EditScopeAlgo.prunedReadOnlyReason( s["box"]["scope"] ), component )
def testUpdateWhenInputSetChanges(self): p = GafferScene.Plane() c = GafferScene.Cube() g1 = GafferScene.Group() g1["in"][0].setInput(p["out"]) g1["in"][1].setInput(c["out"]) s = GafferScene.Set() s["in"].setInput(g1["out"]) s["paths"].setValue(IECore.StringVectorData(["/group/plane"])) g2 = GafferScene.Group() g2["in"][0].setInput(s["out"]) h = g2["out"].setHash("set") self.assertEqual(g2["out"].set("set").value.paths(), ["/group/group/plane"]) s["paths"].setValue(IECore.StringVectorData(["/group/cube"])) self.assertNotEqual(g2["out"].setHash("set"), h) self.assertEqual(g2["out"].set("set").value.paths(), ["/group/group/cube"])
def testChildSmallerThanExistingChildren(self): c = GafferScene.Cube() cSmall = GafferScene.Cube() cSmall["dimensions"].setValue(IECore.V3f(0.1)) g = GafferScene.Group() g["in"].setInput(c["out"]) p = GafferScene.Parent() p["in"].setInput(g["out"]) p["parent"].setValue("/group") p["child"].setInput(cSmall["out"]) self.assertSceneValid(p["out"])
def testRegisterReferenceScene(self): s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["shader"] = GafferScene.ShaderPlug( flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["b"]["out"] = GafferScene.ScenePlug( direction=Gaffer.Plug.Direction.Out, flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["b"]["cube"] = GafferScene.Cube() s["b"]["assignment"] = GafferScene.ShaderAssignment() s["b"]["assignment"]["in"].setInput(s["b"]["cube"]["out"]) s["b"]["assignment"]["shader"].setInput(s["b"]["shader"]) s["b"]["out"].setInput(s["b"]["assignment"]["out"]) s["b"].exportForReference(self.temporaryDirectory() + "/test.grf") GafferSceneUI.ShaderView.registerScene( "test", "Default", self.temporaryDirectory() + "/test.grf") shader = GafferSceneTest.TestShader() shader["type"].setValue("test:surface") shader["name"].setValue("test") view = GafferUI.View.create(shader["out"]) self.assertTrue(isinstance(view.scene(), Gaffer.Reference)) self.assertEqual(view.scene().fileName(), self.temporaryDirectory() + "/test.grf") self.assertEqual(view.scene()["out"].childNames("/"), IECore.InternedStringVectorData(["cube"]))
def testSource( self ) : # - group1 # - group2 # - plane # - sphere # - plane # - cube plane = GafferScene.Plane() sphere = GafferScene.Sphere() cube = GafferScene.Cube() group2 = GafferScene.Group() group2["in"][0].setInput( plane["out"] ) group2["in"][1].setInput( sphere["out"] ) group2["name"].setValue( "group2" ) group1 = GafferScene.Group() group1["in"][0].setInput( group2["out"] ) group1["in"][1].setInput( plane["out"] ) group1["name"].setValue( "group1" ) parent = GafferScene.Parent() parent["in"].setInput( group1["out"] ) parent["child"].setInput( cube["out"] ) parent["parent"].setValue( "/" ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/group1" ), group1["out"] ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/group1/group2" ), group2["out"] ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/group1/group2/plane" ), plane["out"] ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/group1/group2/sphere" ), sphere["out"] ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/group1/plane" ), plane["out"] ) self.assertEqual( GafferScene.SceneAlgo.source( parent["out"], "/cube" ), cube["out"] )
def testTimeContext(self): s = Gaffer.ScriptNode() s["cube"] = GafferScene.Cube() s["e"] = Gaffer.Expression() s["e"].setExpression( 'parent["cube"]["dimensions"] = IECore.V3f( context["frame"] )') s["n"] = GafferScene.SceneTimeWarp() s["n"]["in"].setInput(s["cube"]["out"]) s["n"]["speed"].setValue(0) s["n"]["offset"].setValue(3) self.assertEqual(s["n"]["out"].bound("/cube"), IECore.Box3f(IECore.V3f(-1.5), IECore.V3f(1.5))) s["e2"] = Gaffer.Expression() s["e2"].setExpression( inspect.cleandoc(""" assert( context.get( "scene:path", None ) is None ) parent["n"]["offset"] = 5 """)) self.assertEqual(s["n"]["out"].bound("/cube"), IECore.Box3f(IECore.V3f(-2.5), IECore.V3f(2.5)))
def testChildArray(self): cube = GafferScene.Cube() cube["sets"].setValue("A B") sphere = GafferScene.Sphere() sphere["sets"].setValue("B C") parent = GafferScene.Parent() parent["children"][0].setInput(cube["out"]) parent["children"][1].setInput(sphere["out"]) parent["children"][2].setInput(sphere["out"]) parent["parent"].setValue("/") self.assertSceneValid(parent["out"]) self.assertEqual( parent["out"].childNames("/"), IECore.InternedStringVectorData(["cube", "sphere", "sphere1"])) self.assertEqual(parent["out"].setNames(), IECore.InternedStringVectorData(["A", "B", "C"])) self.assertEqual(parent["out"].set("A").value, IECore.PathMatcher(["/cube"])) self.assertEqual(parent["out"].set("B").value, IECore.PathMatcher(["/cube", "/sphere", "/sphere1"])) self.assertEqual(parent["out"].set("C").value, IECore.PathMatcher(["/sphere", "/sphere1"]))
def testExistsInternals( self ) : cube = GafferScene.Cube() with Gaffer.Context() as c : c["scene:path"] = IECore.InternedStringVectorData() # When there's only one child, the sorted child names refer # to exactly the same object as the regular child names. self.assertTrue( cube["out"]["__sortedChildNames"].getValue( _copy = False ).isSame( cube["out"]["childNames"].getValue( _copy = False ) ) ) # Likewise when there's none c["scene:path"] = IECore.InternedStringVectorData( [ "cube" ] ) self.assertTrue( cube["out"]["__sortedChildNames"].getValue( _copy = False ).isSame( cube["out"]["childNames"].getValue( _copy = False ) ) ) cs = GafferTest.CapturingSlot( cube.plugDirtiedSignal() ) cube["name"].setValue( "box" ) self.assertGreaterEqual( { x[0] for x in cs }, { cube["out"]["childNames"], cube["out"]["__sortedChildNames"], cube["out"]["exists"] } )
def testChildLargerThanExistingChildren(self): c = GafferScene.Cube() cLarge = GafferScene.Cube() cLarge["dimensions"].setValue(imath.V3f(10)) g = GafferScene.Group() g["in"][0].setInput(c["out"]) p = GafferScene.Parent() p["in"].setInput(g["out"]) p["parent"].setValue("/group") p["children"][0].setInput(cLarge["out"]) self.assertSceneValid(p["out"])
def testMultipleAncestorMatches(self): innerGroup = GafferScene.Group() innerGroup["name"].setValue("inner") outerGroup = GafferScene.Group() outerGroup["in"][0].setInput(innerGroup["out"]) outerGroup["name"].setValue("outer") filter = GafferScene.PathFilter() filter["paths"].setValue( IECore.StringVectorData(["/outer", "/outer/inner"])) cube = GafferScene.Cube() cube["sets"].setValue("setA") parent = GafferScene.Parent() parent["in"].setInput(outerGroup["out"]) parent["children"][0].setInput(cube["out"]) parent["filter"].setInput(filter["out"]) self.assertSceneValid(parent["out"]) self.assertEqual(parent["out"].childNames("/outer"), IECore.InternedStringVectorData(["inner", "cube"])) self.assertEqual(parent["out"].childNames("/outer/inner"), IECore.InternedStringVectorData(["cube"]))
def test(self): cube = GafferScene.Cube() camera = GafferScene.Camera() camera["transform"]["translate"]["z"].setValue(2) group = GafferScene.Group() group["in"][0].setInput(cube["out"]) group["in"][1].setInput(camera["out"]) map = GafferScene.MapProjection() map["in"].setInput(group["out"]) map["camera"].setValue("/group/camera") oIn = group["out"].object("/group/cube") self.assertTrue("s" not in oIn) self.assertTrue("t" not in oIn) oOut = map["out"].object("/group/cube") self.assertTrue("s" in oOut) self.assertTrue("t" in oOut) self.assertTrue(oOut.arePrimitiveVariablesValid()) oIn["s"] = oOut["s"] oIn["t"] = oOut["t"] self.assertEqual(oIn, oOut) camera["transform"]["translate"]["z"].setValue(3) oOut2 = map["out"].object("/group/cube") self.assertNotEqual(oOut, oOut2)
def testAffects(self): cube = GafferScene.Cube() camera = GafferScene.Camera() group = GafferScene.Group() group["in"][0].setInput(cube["out"]) group["in"][1].setInput(camera["out"]) map = GafferScene.MapProjection() map["in"].setInput(group["out"]) cs = GafferTest.CapturingSlot(map.plugDirtiedSignal()) camera["transform"]["translate"]["z"].setValue(2) self.assertTrue( "out.object" in [x[0].relativeName(x[0].node()) for x in cs]) del cs[:] camera["fieldOfView"].setValue(10) self.assertTrue( "out.object" in [x[0].relativeName(x[0].node()) for x in cs]) del cs[:] cube["transform"]["translate"]["z"].setValue(2) self.assertTrue( "out.object" in [x[0].relativeName(x[0].node()) for x in cs])
def testMatch( self ) : p = GafferScene.FilterPlug() with self.assertRaises( Exception ) : p.match( None ) c = GafferScene.Cube() c["sets"].setValue( "cubeSet" ) ctx = Gaffer.Context() ctx[ "scene:path" ] = IECore.InternedStringVectorData( [ "cube" ] ) with ctx : f = GafferScene.SetFilter() p.setInput( f["out"] ) f["setExpression"].setValue( "cubeSet" ) self.assertEqual( p.match( c["out"] ), IECore.PathMatcher.Result.ExactMatch ) f["setExpression"].setValue( "otherSet" ) self.assertEqual( p.match( c["out"] ), IECore.PathMatcher.Result.NoMatch ) f = GafferScene.PathFilter() p.setInput( f["out"] ) f["paths"].setValue( IECore.StringVectorData( [ "/cube" ] ) ) self.assertEqual( p.match( c["out"] ), IECore.PathMatcher.Result.ExactMatch ) f["paths"].setValue( IECore.StringVectorData( [ "/other" ] ) ) self.assertEqual( p.match( c["out"] ), IECore.PathMatcher.Result.NoMatch )
def testPivotAffectsHandlesTransform(self): script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() view = GafferSceneUI.SceneView() view["in"].setInput(script["cube"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/cube"])) tool = GafferSceneUI.RotateTool(view) tool["active"].setValue(True) self.assertEqual(tool.handlesTransform(), imath.M44f()) script["cube"]["transform"]["pivot"].setValue(imath.V3f(1, 0, 0)) self.assertEqual( tool.handlesTransform(), imath.M44f().translate( script["cube"]["transform"]["pivot"].getValue())) script["cube"]["transform"]["translate"].setValue(imath.V3f(1, 2, -1)) self.assertEqual( tool.handlesTransform(), imath.M44f().translate( script["cube"]["transform"]["pivot"].getValue() + script["cube"]["transform"]["translate"].getValue()))
def testChildBounds( self ) : cube = GafferScene.Cube() sphere = GafferScene.Sphere() group = GafferScene.Group() group["in"][0].setInput( cube["out"] ) group["in"][1].setInput( sphere["out"] ) with Gaffer.Context() as c : c["scene:path"] = IECore.InternedStringVectorData( [ "group" ] ) h = group["out"]["childBounds"].hash() b = group["out"]["childBounds"].getValue() self.assertEqual( h, group["out"].childBoundsHash( "/group" ) ) self.assertEqual( b, group["out"].childBounds( "/group" ) ) b2 = cube["out"].bound( "/" ) b2.extendBy( sphere["out"].bound( "/" ) ) self.assertEqual( b, b2 ) cube["transform"]["translate"]["x"].setValue( 10 ) self.assertNotEqual( group["out"].childBoundsHash( "/group"), h ) b = group["out"].childBounds( "/group" ) b2 = cube["out"].bound( "/" ) b2.extendBy( sphere["out"].bound( "/" ) ) self.assertEqual( b, b2 )
def testCanWriteSets( self ): script = Gaffer.ScriptNode() s = GafferScene.Sphere() script.addChild( s ) c = GafferScene.Cube() script.addChild( c ) sphereGroup = GafferScene.Group() script.addChild( sphereGroup ) sphereGroup["in"][0].setInput( s["out"] ) sphereGroup["name"].setValue( 'sphereGroup' ) sn = GafferScene.Set( "Set" ) script.addChild( sn ) sn["paths"].setValue( IECore.StringVectorData( [ '/sphereGroup' ] ) ) sn["name"].setValue( 'foo' ) sn["in"].setInput( sphereGroup["out"] ) sn2 = GafferScene.Set( "Set" ) script.addChild( sn2 ) sn2["mode"].setValue( 1 ) # add to the existing set sn2["paths"].setValue( IECore.StringVectorData( [ '/sphereGroup/sphere' ] ) ) sn2["name"].setValue( 'foo' ) sn2["in"].setInput( sn["out"] ) g = GafferScene.Group() script.addChild( g ) g["name"].setValue( 'group' ) g["in"][0].setInput( sn2["out"] ) g["in"][1].setInput( c["out"] ) writer = GafferScene.SceneWriter() script.addChild( writer ) script["writer"] = writer writer["in"].setInput( g["out"] ) writer["fileName"].setValue( self.temporaryDirectory() + "/setTest.scc" ) writer.execute() sc = IECoreScene.SceneCache( self.temporaryDirectory() + "/setTest.scc", IECore.IndexedIO.OpenMode.Read ) scGroup = sc.child("group") scSphereGroup = scGroup.child("sphereGroup") scSphere = scSphereGroup.child("sphere") self.assertEqual( scGroup.readTags(), [] ) self.assertEqual( scSphereGroup.readTags(), [ IECore.InternedString("foo") ] ) self.assertEqual( set (scSphere.readTags() ), set([IECore.InternedString("foo"), IECore.InternedString("ObjectType:MeshPrimitive")])) scCube = scGroup.child("cube") self.assertEqual( scCube.readTags() , [ IECore.InternedString("ObjectType:MeshPrimitive") ] )
def testHandleOriginsRespectPointConstraint(self): script = Gaffer.ScriptNode() script["sphere"] = GafferScene.Sphere() cubeTranslate = imath.V3f(5, 5, 0) script["cube"] = GafferScene.Cube() script["cube"]["transform"]["translate"].setValue(cubeTranslate) script["parent"] = GafferScene.Parent() script["parent"]["in"].setInput(script["sphere"]["out"]) script["parent"]["children"][0].setInput(script["cube"]["out"]) script["parent"]["parent"].setValue("/") script["sphereFilter"] = GafferScene.PathFilter() script["sphereFilter"]["paths"].setValue( IECore.StringVectorData(["/sphere"])) script["constraint"] = GafferScene.PointConstraint() script["constraint"]["in"].setInput(script["parent"]["out"]) script["constraint"]["filter"].setInput(script["sphereFilter"]["out"]) script["constraint"]["target"].setValue("/cube") view = GafferSceneUI.SceneView() view["in"].setInput(script["constraint"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/sphere"])) tool = GafferSceneUI.ScaleTool(view) tool["active"].setValue(True) self.assertEqual(tool.handlesTransform(), imath.M44f().translate(cubeTranslate))
def testChangingInputSet( self ) : c1 = GafferScene.Cube() c2 = GafferScene.Cube() p = GafferScene.Parent() p["in"].setInput( c1["out"] ) p["parent"].setValue( "/" ) p["child"].setInput( c2["out"] ) h = p["out"].setHash( "test" ) self.assertEqual( p["out"].set( "test" ).value, GafferScene.PathMatcher() ) c1["sets"].setValue( "test" ) self.assertNotEqual( p["out"].setHash( "test" ), h ) self.assertEqual( p["out"].set( "test" ).value, GafferScene.PathMatcher( [ "/cube" ] ) )
def testInteractionWithParentConstraints(self): script = Gaffer.ScriptNode() # Cube with identity transform, parent constrained to sphere # rotated 90 around X and translated to ( 5, 5, 0 ). script["sphere"] = GafferScene.Sphere() script["sphere"]["transform"]["rotate"]["x"].setValue(90) script["sphere"]["transform"]["translate"].setValue(imath.V3f(5, 5, 0)) script["cube"] = GafferScene.Cube() script["parent"] = GafferScene.Parent() script["parent"]["parent"].setValue("/") script["parent"]["in"].setInput(script["sphere"]["out"]) script["parent"]["children"][0].setInput(script["cube"]["out"]) script["cubeFilter"] = GafferScene.PathFilter() script["cubeFilter"]["paths"].setValue( IECore.StringVectorData(["/cube"])) script["constraint"] = GafferScene.ParentConstraint() script["constraint"]["in"].setInput(script["parent"]["out"]) script["constraint"]["filter"].setInput(script["cubeFilter"]["out"]) script["constraint"]["target"].setValue("/sphere") self.assertEqual(script["constraint"]["out"].fullTransform("/cube"), script["constraint"]["out"].fullTransform("/sphere")) # View and Tool view = GafferSceneUI.SceneView() view["in"].setInput(script["constraint"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/cube"])) tool = GafferSceneUI.TranslateTool(view) tool["active"].setValue(True) # Check handle orientation tool["orientation"].setValue(tool.Orientation.Local) self.assertEqual(tool.handlesTransform(), script["constraint"]["out"].fullTransform("/cube")) tool["orientation"].setValue(tool.Orientation.Parent) self.assertEqual( tool.handlesTransform(), imath.M44f().translate(script["constraint"]["out"].fullTransform( "/cube").translation())) # Check translation operation tool["orientation"].setValue(tool.Orientation.Local) tool.translate(imath.V3f(1, 2, 3)) self.assertEqual(script["cube"]["transform"]["translate"].getValue(), imath.V3f(1, 2, 3))
def testPassThroughWhenNoChild(self): c = GafferScene.Cube() p = GafferScene.Parent() p["parent"].setValue("/") p["in"].setInput(c["out"]) self.assertScenesEqual(p["out"], c["out"])
def testHashPassThrough( self ) : cube = GafferScene.Cube() cube["sets"].setValue( "test" ) deleteSets = GafferScene.DeleteSets() deleteSets["in"].setInput( cube["out"] ) self.assertEqual( deleteSets["out"].setHash( "test" ), cube["out"].setHash( "test" ) )
def testNegativeIdsAndIndices(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 2)])) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-10, -5]), ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-1, -2]), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() cube = GafferScene.Cube() instances = GafferScene.Parent() instances["in"].setInput(sphere["out"]) instances["child"].setInput(cube["out"]) instances["parent"].setValue("/") instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(instances["out"]) instancer["parent"].setValue("/object") instancer["index"].setValue("index") instancer["id"].setValue("id") self.assertEqual(instancer["out"].childNames("/object/instances"), IECore.InternedStringVectorData(["sphere", "cube"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere"), IECore.InternedStringVectorData(["-5"])) self.assertEqual(instancer["out"].childNames("/object/instances/cube"), IECore.InternedStringVectorData(["-10"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere/-5"), IECore.InternedStringVectorData()) self.assertEqual( instancer["out"].childNames("/object/instances/cube/-10"), IECore.InternedStringVectorData()) self.assertEqual(instancer["out"].object("/object/instances"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/sphere"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/cube"), IECore.NullObject.defaultNullObject()) self.assertEqual( instancer["out"].object("/object/instances/sphere/-5"), sphere["out"].object("/sphere")) self.assertEqual(instancer["out"].object("/object/instances/cube/-10"), cube["out"].object("/cube")) self.assertSceneValid(instancer["out"])
def testEditSubdivisionAttributes( self ) : script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() script["cube"]["dimensions"].setValue( IECore.V3f( 2 ) ) script["meshType"] = GafferScene.MeshType() script["meshType"]["in"].setInput( script["cube"]["out"] ) script["meshType"]["meshType"].setValue( "catmullClark" ) script["attributes"] = GafferArnold.ArnoldAttributes() script["attributes"]["in"].setInput( script["meshType"]["out"] ) script["attributes"]["attributes"]["subdivIterations"]["enabled"].setValue( True ) script["outputs"] = GafferScene.Outputs() script["outputs"].addOutput( "beauty", IECoreScene.Display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "subdivisionTest", } ) ) script["outputs"]["in"].setInput( script["attributes"]["out"] ) script["objectToImage"] = GafferImage.ObjectToImage() script["imageStats"] = GafferImage.ImageStats() script["imageStats"]["in"].setInput( script["objectToImage"]["out"] ) script["imageStats"]["channels"].setValue( IECore.StringVectorData( [ "R", "G", "B", "A" ] ) ) script["imageStats"]["area"].setValue( IECore.Box2i( IECore.V2i( 0 ), IECore.V2i( 640, 480 ) ) ) script["render"] = self._createInteractiveRender() script["render"]["in"].setInput( script["outputs"]["out"] ) # Render the cube with one level of subdivision. Check we get roughly the # alpha coverage we expect. script["render"]["state"].setValue( script["render"].State.Running ) time.sleep( 1 ) script["objectToImage"]["object"].setValue( IECoreImage.ImageDisplayDriver.storedImage( "subdivisionTest" ) ) self.assertAlmostEqual( script["imageStats"]["average"][3].getValue(), 0.381, delta = 0.001 ) # Now up the number of subdivision levels. The alpha coverage should # increase as the shape tends towards the limit surface. script["attributes"]["attributes"]["subdivIterations"]["value"].setValue( 4 ) time.sleep( 1 ) script["objectToImage"]["object"].setValue( IECoreImage.ImageDisplayDriver.storedImage( "subdivisionTest" ) ) self.assertAlmostEqual( script["imageStats"]["average"][3].getValue(), 0.424, delta = 0.001 )
def testCanShadeVertexInterpolatedPrimitiveVariablesAsUniform( self ) : s = Gaffer.ScriptNode() c = GafferScene.Cube() s.addChild( c ) o = GafferOSL.OSLObject() s.addChild( o ) f = GafferScene.PathFilter( "PathFilter" ) s.addChild( f ) f["paths"].setValue( IECore.StringVectorData( [ '/cube' ] ) ) o["filter"].setInput( f["out"] ) # ensure the source position primitive variable interpolation is set to Vertex self.assertEqual(c["out"].object("/cube")['P'].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex ) o['in'].setInput( c["out"] ) o['interpolation'].setValue( IECoreScene.PrimitiveVariable.Interpolation.Uniform ) inPoint = GafferOSL.OSLShader( "InPoint" ) s.addChild( inPoint ) inPoint.loadShader( "ObjectProcessing/InPoint" ) addVector = GafferOSL.OSLShader( "AddVector" ) s.addChild( addVector ) addVector.loadShader( "Maths/AddVector" ) addVector["parameters"]["b"].setValue( imath.V3f( 1, 2, 3 ) ) addVector["parameters"]["a"].setInput( inPoint["out"]["value"] ) outPoint = GafferOSL.OSLShader( "OutPoint" ) s.addChild( outPoint ) outPoint.loadShader( "ObjectProcessing/OutPoint" ) outPoint['parameters']['name'].setValue("P_copy") outPoint["parameters"]["value"].setInput( addVector["out"]["out"] ) outObject = GafferOSL.OSLShader( "OutObject" ) s.addChild( outObject ) outObject.loadShader( "ObjectProcessing/OutObject" ) outObject["parameters"]["in0"].setInput( outPoint["out"]["primitiveVariable"] ) o["shader"].setInput( outObject["out"] ) cubeObject = s['OSLObject']['out'].object( "/cube" ) self.assertTrue( "P_copy" in cubeObject.keys() ) self.assertEqual( cubeObject["P_copy"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Uniform) self.assertEqual( cubeObject["P_copy"].data[0], imath.V3f( 0.0, 0.0, -0.5 ) + imath.V3f( 1, 2, 3 )) self.assertEqual( cubeObject["P_copy"].data[1], imath.V3f( 0.5, 0.0, 0.0 ) + imath.V3f( 1, 2, 3 )) self.assertEqual( cubeObject["P_copy"].data[2], imath.V3f( 0.0, 0.0, 0.5 ) + imath.V3f( 1, 2, 3 )) self.assertEqual( cubeObject["P_copy"].data[3], imath.V3f( -0.5, 0.0, 0.0 ) + imath.V3f( 1, 2, 3 )) self.assertEqual( cubeObject["P_copy"].data[4], imath.V3f( 0.0, 0.5, 0.0 ) + imath.V3f( 1, 2, 3 )) self.assertEqual( cubeObject["P_copy"].data[5], imath.V3f( 0.0, -0.5, 0.0 ) + imath.V3f( 1, 2, 3 ))
def testOrientation(self): script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() script["cube"]["transform"]["rotate"]["y"].setValue(90) script["group"] = GafferScene.Group() script["group"]["in"][0].setInput(script["cube"]["out"]) script["group"]["transform"]["rotate"]["y"].setValue(90) view = GafferSceneUI.SceneView() view["in"].setInput(script["group"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/group/cube"])) tool = GafferSceneUI.RotateTool(view) tool["active"].setValue(True) # Local tool["orientation"].setValue(tool.Orientation.Local) with Gaffer.UndoScope(script): tool.rotate(imath.Eulerf(0, 0, 90)) self.assertTrue( imath.V3f(0, 1, 0).equalWithAbsError( imath.V3f(1, 0, 0) * script["group"]["out"].fullTransform("/group/cube"), 0.000001)) script.undo() # Parent tool["orientation"].setValue(tool.Orientation.Parent) with Gaffer.UndoScope(script): tool.rotate(imath.Eulerf(90, 0, 0)) self.assertTrue( imath.V3f(0, 1, 0).equalWithAbsError( imath.V3f(1, 0, 0) * script["group"]["out"].fullTransform("/group/cube"), 0.000001)) script.undo() # World tool["orientation"].setValue(tool.Orientation.World) with Gaffer.UndoScope(script): tool.rotate(imath.Eulerf(0, 0, 90)) self.assertTrue( imath.V3f(0, -1, 0).equalWithAbsError( imath.V3f(1, 0, 0) * script["group"]["out"].fullTransform("/group/cube"), 0.000001))