script["Camera"]["renderSettingOverrides"]["overscanBottom"]["value"].setValue( 0.05) script["Camera"]["renderSettingOverrides"]["overscanBottom"][ "enabled"].setValue(True) script.selection().add(script["Camera"]) __path = "/camera" __paths = IECore.PathMatcher([__path]) GafferSceneUI.ContextAlgo.expand(script.context(), __paths) from GafferSceneUI.SceneInspector import __TransformSection, __BoundSection, __ObjectSection, __AttributesSection, __SetMembershipSection for imageName, sectionClass in [("Parameters.png", __ObjectSection), ("Sets.png", __SetMembershipSection)]: section = sectionClass() section._Section__collapsible.setCollapsed(False) with GafferUI.Window("Property") as window: sceneInspector = GafferSceneUI.SceneInspector(script, sections=[section]) sceneInspector.setNodeSet(Gaffer.StandardSet([script["Camera"]])) sceneInspector.setTargetPaths([__path]) window.resizeToFitChild() window.setVisible(True) GafferUI.WidgetAlgo.grab(widget=sceneInspector, imagePath="images/interfaceCamera" + imageName)
def testSceneViewStatus(self): camera = GafferScene.Camera() view = GafferUI.View.create(camera["out"]) tool = GafferSceneUI.CropWindowTool(view) tool["active"].setValue(True) # Presently, crop window tool updates are coupled to `preRender`, so we # need to actually show the View before we can verify our behaviour. with GafferUI.Window() as window: GafferUI.GadgetWidget(view.viewportGadget()) window.setVisible(True) # View camera isn't a real camera self.waitForIdle(1) self.assertEqual(tool.status(), "Error: No applicable crop window for this view") # Working camera, no node to edit view["camera"]["lookThroughCamera"].setValue("/camera") view["camera"]["lookThroughEnabled"].setValue(True) self.waitForIdle(1) self.assertEqual( tool.status(), "Error: No crop window found. Insert a <b>StandardOptions</b> node." ) # Editable options = GafferScene.StandardOptions() options["in"].setInput(camera["out"]) view["in"].setInput(options["out"]) self.waitForIdle(1) self.assertEqual( tool.status(), "Info: Editing <b>StandardOptions.options.renderCropWindow.value</b>" ) # Locked value plug Gaffer.MetadataAlgo.setReadOnly( options["options"]["renderCropWindow"]["value"], True) self.waitForIdle(1) self.assertEqual( tool.status(), "Warning: <b>StandardOptions.options.renderCropWindow.value</b> is locked" ) # Locked/off enabled plug Gaffer.MetadataAlgo.setReadOnly( options["options"]["renderCropWindow"]["value"], False) options["options"]["renderCropWindow"]["enabled"].setValue(False) Gaffer.MetadataAlgo.setReadOnly( options["options"]["renderCropWindow"]["enabled"], True) self.waitForIdle(1) self.assertEqual( tool.status(), "Warning: <b>StandardOptions.options.renderCropWindow.value</b> isn't editable" ) # Check status across visible/invisible overlay transitions (this is # really testing one of the gnarly parts of the status implementation # that has caused trouble before, until we can properly refactor the tool). view["camera"]["lookThroughEnabled"].setValue(False) self.waitForIdle(1) self.assertEqual(tool.status(), "Error: No applicable crop window for this view") view["camera"]["lookThroughEnabled"].setValue(True) self.waitForIdle(1) self.assertEqual( tool.status(), "Warning: <b>StandardOptions.options.renderCropWindow.value</b> isn't editable" )
def testExceptionsDuringCompute(self): # Make this scene # # - bigSphere # - littleSphere (with exception in attributes expression) s = Gaffer.ScriptNode() s["s1"] = GafferScene.Sphere() s["s1"]["name"].setValue("bigSphere") s["s2"] = GafferScene.Sphere() s["s2"]["name"].setValue("littleSphere") s["s2"]["radius"].setValue(0.1) s["p"] = GafferScene.Parent() s["p"]["in"].setInput(s["s1"]["out"]) s["p"]["child"].setInput(s["s2"]["out"]) s["p"]["parent"].setValue("/bigSphere") s["a"] = GafferScene.StandardAttributes() s["a"]["in"].setInput(s["p"]["out"]) s["a"]["attributes"]["doubleSided"]["enabled"].setValue(True) s["e"] = Gaffer.Expression() s["e"].setExpression( 'parent["a"]["attributes"]["doubleSided"]["value"] = context["nonexistent"]' ) s["f"] = GafferScene.PathFilter() s["f"]["paths"].setValue( IECore.StringVectorData(["/bigSphere/littleSphere"])) s["a"]["filter"].setInput(s["f"]["out"]) # Try to view it sg = GafferSceneUI.SceneGadget() sg.setScene(s["a"]["out"]) sg.setMinimumExpansionDepth(4) with GafferUI.Window() as w: gw = GafferUI.GadgetWidget(sg) gw.getViewportGadget().setPlanarMovement(False) gw.getViewportGadget().setCamera( IECoreScene.Camera(parameters={ "projection": "perspective", })) originalMessageHandler = IECore.MessageHandler.getDefaultHandler() mh = IECore.CapturingMessageHandler() IECore.MessageHandler.setDefaultHandler( IECore.LevelFilteredMessageHandler( mh, IECore.LevelFilteredMessageHandler.defaultLevel())) try: w.setVisible(True) self.waitForIdle(1000) sg.waitForCompletion() # Check we were told about the problem self.assertEqual(len(mh.messages), 1) self.assertEqual(mh.messages[0].level, mh.Level.Error) self.assertTrue("nonexistent" in mh.messages[0].message) # And that there isn't some half-assed partial scene # being displayed. self.assertTrue(sg.bound().isEmpty()) gw.getViewportGadget().frame( imath.Box3f(imath.V3f(-1), imath.V3f(1))) self.assertObjectAt(sg, imath.V2f(0.5), None) # And that redraws don't cause more fruitless attempts # to compute the scene. gw.getViewportGadget().frame( imath.Box3f(imath.V3f(-1.1), imath.V3f(1.1))) self.waitForIdle(1000) self.assertEqual(len(mh.messages), 1) self.assertObjectAt(sg, imath.V2f(0.5), None) self.assertTrue(sg.bound().isEmpty()) # Fix the problem with the scene, and check that we can see something now s["f"]["enabled"].setValue(False) sg.waitForCompletion() self.assertEqual(len(mh.messages), 1) self.assertFalse(sg.bound().isEmpty()) self.assertObjectAt(sg, imath.V2f(0.5), IECore.InternedStringVectorData(["bigSphere"])) finally: IECore.MessageHandler.setDefaultHandler(originalMessageHandler)
def testOrientation( self ) : script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["plane"]["transform"]["rotate"]["y"].setValue( 90 ) script["group"] = GafferScene.Group() script["group"]["in"][0].setInput( script["plane"]["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/plane" ] ) ) tool = GafferSceneUI.TranslateTool( view ) tool["active"].setValue( True ) # Local tool["orientation"].setValue( tool.Orientation.Local ) with Gaffer.UndoScope( script ) : tool.translate( imath.V3f( 1, 0, 0 ) ) self.assertTrue( imath.V3f( -1, 0, 0 ).equalWithAbsError( script["group"]["out"].fullTransform( "/group/plane" ).translation(), 0.000001 ) ) script.undo() # Parent tool["orientation"].setValue( tool.Orientation.Parent ) with Gaffer.UndoScope( script ) : tool.translate( imath.V3f( 1, 0, 0 ) ) self.assertTrue( imath.V3f( 0, 0, -1 ).equalWithAbsError( script["group"]["out"].fullTransform( "/group/plane" ).translation(), 0.0000001 ) ) script.undo() # World tool["orientation"].setValue( tool.Orientation.World ) with Gaffer.UndoScope( script ) : tool.translate( imath.V3f( 1, 0, 0 ) ) self.assertTrue( imath.V3f( 1, 0, 0 ).equalWithAbsError( script["group"]["out"].fullTransform( "/group/plane" ).translation(), 0.0000001 ) )
def testSelection( self ) : script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["group"] = GafferScene.Group() script["group"]["in"][0].setInput( script["plane"]["out"] ) script["transformFilter"] = GafferScene.PathFilter() script["transform"] = GafferScene.Transform() script["transform"]["in"].setInput( script["group"]["out"] ) script["transform"]["filter"].setInput( script["transformFilter"]["out"] ) view = GafferSceneUI.SceneView() view["in"].setInput( script["transform"]["out"] ) tool = GafferSceneUI.TranslateTool( view ) tool["active"].setValue( True ) self.assertEqual( len( tool.selection() ), 0 ) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher( [ "/group/plane" ] ) ) self.assertEqual( len( tool.selection() ), 1 ) self.assertEqual( tool.selection()[0].path(), "/group/plane" ) self.assertEqual( tool.selection()[0].context(), view.getContext() ) self.assertTrue( tool.selection()[0].upstreamScene().isSame( script["plane"]["out"] ) ) self.assertEqual( tool.selection()[0].upstreamPath(), "/plane" ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["plane"]["transform"] ) ) self.assertEqual( tool.selection()[0].transformSpace(), imath.M44f() ) self.assertEqual( tool.selection()[0].warning(), "" ) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher( [ "/group" ] ) ) self.assertEqual( tool.selection()[0].path(), "/group" ) self.assertEqual( tool.selection()[0].context(), view.getContext() ) self.assertTrue( tool.selection()[0].upstreamScene().isSame( script["group"]["out"] ) ) self.assertEqual( tool.selection()[0].upstreamPath(), "/group" ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["group"]["transform"] ) ) self.assertEqual( tool.selection()[0].transformSpace(), imath.M44f() ) self.assertEqual( tool.selection()[0].warning(), "" ) script["transformFilter"]["paths"].setValue( IECore.StringVectorData( [ "/group" ] ) ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["transform"]["transform"] ) ) self.assertEqual( tool.selection()[0].warning(), "" ) script["transformFilter"]["enabled"].setValue( False ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["group"]["transform"] ) ) self.assertEqual( tool.selection()[0].warning(), "" ) script["transformFilter"]["enabled"].setValue( True ) self.assertEqual( tool.selection()[0].path(), "/group" ) self.assertEqual( tool.selection()[0].context(), view.getContext() ) self.assertTrue( tool.selection()[0].upstreamScene().isSame( script["transform"]["out"] ) ) self.assertEqual( tool.selection()[0].upstreamPath(), "/group" ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["transform"]["transform"] ) ) self.assertEqual( tool.selection()[0].transformSpace(), imath.M44f() ) self.assertEqual( tool.selection()[0].warning(), "" ) script["transform"]["enabled"].setValue( False ) self.assertTrue( tool.selection()[0].editTarget().isSame( script["group"]["transform"] ) ) self.assertEqual( tool.selection()[0].warning(), "" )
def testSelection(self): script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["group"] = GafferScene.Group() script["group"]["in"][0].setInput(script["plane"]["out"]) script["transformFilter"] = GafferScene.PathFilter() script["transform"] = GafferScene.Transform() script["transform"]["in"].setInput(script["group"]["out"]) script["transform"]["filter"].setInput( script["transformFilter"]["out"]) view = GafferSceneUI.SceneView() view["in"].setInput(script["transform"]["out"]) tool = GafferSceneUI.TranslateTool(view) tool["active"].setValue(True) self.assertTrue(tool.selection().transformPlug is None) view.getContext()["ui:scene:selectedPaths"] = IECore.StringVectorData( ["/group/plane"]) self.assertEqual(tool.selection().path, "/group/plane") self.assertEqual(tool.selection().context, view.getContext()) self.assertTrue(tool.selection().upstreamScene.isSame( script["plane"]["out"])) self.assertEqual(tool.selection().upstreamPath, "/plane") self.assertTrue(tool.selection().transformPlug.isSame( script["plane"]["transform"])) self.assertEqual(tool.selection().transformSpace, IECore.M44f()) view.getContext()["ui:scene:selectedPaths"] = IECore.StringVectorData( ["/group"]) self.assertEqual(tool.selection().path, "/group") self.assertEqual(tool.selection().context, view.getContext()) self.assertTrue(tool.selection().upstreamScene.isSame( script["group"]["out"])) self.assertEqual(tool.selection().upstreamPath, "/group") self.assertTrue(tool.selection().transformPlug.isSame( script["group"]["transform"])) self.assertEqual(tool.selection().transformSpace, IECore.M44f()) script["transformFilter"]["paths"].setValue( IECore.StringVectorData(["/group"])) self.assertTrue(tool.selection().transformPlug.isSame( script["transform"]["transform"])) script["transformFilter"]["enabled"].setValue(False) self.assertTrue(tool.selection().transformPlug.isSame( script["group"]["transform"])) script["transformFilter"]["enabled"].setValue(True) self.assertEqual(tool.selection().path, "/group") self.assertEqual(tool.selection().context, view.getContext()) self.assertTrue(tool.selection().upstreamScene.isSame( script["transform"]["out"])) self.assertEqual(tool.selection().upstreamPath, "/group") self.assertTrue(tool.selection().transformPlug.isSame( script["transform"]["transform"])) self.assertEqual(tool.selection().transformSpace, IECore.M44f()) script["transform"]["enabled"].setValue(False) self.assertTrue(tool.selection().transformPlug.isSame( script["group"]["transform"]))
def testPivotAndExistingTransform(self): script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() script["transformFilter"] = GafferScene.PathFilter() script["transformFilter"]["paths"].setValue( IECore.StringVectorData(["/cube"])) script["transform"] = GafferScene.Transform() script["transform"]["in"].setInput(script["cube"]["out"]) script["transform"]["filter"].setInput( script["transformFilter"]["out"]) view = GafferSceneUI.SceneView() view["in"].setInput(script["transform"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/cube"])) tool = GafferSceneUI.RotateTool(view) tool["active"].setValue(True) # Start with default pivot self.assertEqual( imath.V3f(0) * tool.handlesTransform(), imath.V3f(0, 0, 0), ) # Offset it script["transform"]["transform"]["pivot"].setValue(imath.V3f(1, 0, 0)) self.assertEqual( imath.V3f(0) * tool.handlesTransform(), imath.V3f(1, 0, 0), ) # Now add an existing transform on the cube, prior # to it entering the transform node we're editing. # The pivot's world space position should be affected # because the Transform node is operating in Local space. script["cube"]["transform"]["rotate"]["y"].setValue(90) self.assertTrue( imath.V3f(0, 0, -1).equalWithAbsError( imath.V3f(0) * tool.handlesTransform(), 0.0000001, )) # But if we edit in World space, then the existing transform # should have no relevance. script["transform"]["space"].setValue(script["transform"].Space.World) self.assertEqual( imath.V3f(0) * tool.handlesTransform(), imath.V3f(1, 0, 0), )
def testImageViewStatus(self): script = Gaffer.ScriptNode() script["image"] = GafferImage.ImageReader() view = GafferUI.View.create(script["image"]["out"]) tool = GafferSceneUI.CropWindowTool(view) tool["active"].setValue(True) # Presently, crop window tool updates are coupled to `preRender`, so we # need to actually show the View before we can verify our behaviour. with GafferUI.Window() as window: GafferUI.GadgetWidget(view.viewportGadget()) window.setVisible(True) # Check process exceptions script["image"]["fileName"].setValue("/i/do/not/exist.exr") self.waitForIdle(1000) self.assertEqual( tool.status(), "Error: image.__oiioReader.out.format : OpenImageIOReader : Could not create ImageInput : Could not open file \"/i/do/not/exist.exr\"" ) # Missing metadata script["image"]["fileName"].setValue( "${GAFFER_ROOT}/resources/images/macaw.exr") with IECore.CapturingMessageHandler() as mh: self.waitForIdle(1000) # Don't fail due to running on computer that can't do GPU color transforms well if len(mh.messages): self.assertEqual(len(mh.messages), 1) self.assertEqual(mh.messages[0].context, "ImageGadget") self.assertTrue(mh.messages[0].message.startswith( "Could not find supported floating point texture format in OpenGL" )) self.assertEqual( tool.status(), "Error: No <b>gaffer:sourceScene</b> metadata in image") script["meta"] = GafferImage.ImageMetadata() script["meta"]["metadata"].addChild( Gaffer.NameValuePlug("gaffer:sourceScene", "options.out", True, "member1")) script["meta"]["in"].setInput(script["image"]["out"]) script["options"] = GafferScene.StandardOptions() view["in"].setInput(script["meta"]["out"]) # Valid options path self.waitForIdle(1000) self.assertEqual( tool.status(), "Info: Editing <b>options.options.renderCropWindow.value</b>")
tempPythonEditor.outputWidget().setText("") text = 'context = Gaffer.Context( root.context() )\ncontext["scene:path"] = IECore.InternedStringVectorData( ["cube2"] )\nwith context:\n print root["Transform"]["transform"]["translate"]["y"].getValue()' tempPythonEditor.inputWidget().setText(text) tempPythonEditor.execute() tempPythonEditor.inputWidget().setText(text) GafferUI.WidgetAlgo.grab( widget=tempPythonEditor.outputWidget(), imagePath="images/conceptContextsQueryingResultsFixedPythonEditor.png") tempWindow.close() del tempWindow del tempPythonEditor __delay(0.1) # Concept: Querying results (Scene Inspector) with GafferUI.Window() as tempWindow: tempSceneInspector = GafferSceneUI.SceneInspector(script) tempSceneInspector._SceneInspector__sections[ 2]._Section__collapsible.setCollapsed(False) tempWindow._qtWidget().resize(512, 400) tempWindow.setVisible(True) GafferUI.WidgetAlgo.grab( widget=tempSceneInspector, imagePath="images/conceptContextsQueryingResultsSceneInspector.png") tempWindow.close() del tempWindow del tempSceneInspector __delay(0.1) # Concept: Contexts in parallel branches (Node Editor) script["fileName"].setValue( os.path.abspath("scripts/conceptContextsInParallelBranches.gfr"))
def testSource( self ) : s = Gaffer.ScriptNode() s["pA"] = GafferScene.Plane() s["pA"]["name"].setValue( "planeA" ) s["pB"] = GafferScene.Plane() s["pB"]["name"].setValue( "planeB" ) s["g"] = GafferScene.Group() s["g"]["in"][0].setInput( s["pA"]["out"] ) s["g"]["in"][1].setInput( s["pB"]["out"] ) s["s"] = GafferSceneTest.TestShader() s["a"] = GafferScene.ShaderAssignment() s["a"]["in"].setInput( s["g"]["out"] ) s["a"]["shader"].setInput( s["s"]["out"] ) s["s2"] = GafferSceneTest.TestShader() s["a2"] = GafferScene.ShaderAssignment() s["a2"]["in"].setInput( s["a"]["out"] ) s["a2"]["shader"].setInput( s["s2"]["out"] ) s["g2"] = GafferScene.Group() s["g2"]["in"][0].setInput( s["a2"]["out"] ) s["o"] = GafferScene.SceneWriter() s["o"]["in"].setInput( s["g2"]["out"] ) n = Gaffer.StandardSet() c = Gaffer.Context() self.assertEqual( len(GafferSceneUI.ContextAlgo.getSelectedPaths( c ).paths()), 0 ) h = GafferSceneUI.SourceSet( c, n ) self.assertEqual( h.size(), 0 ) a = "/group/group/planeA" b = "/group/group/planeB" n.add( s["o"] ) # Test scene selection changed GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ a ] ) ) self.assertEqual( set(h), { s["pA"] } ) GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ a, b ] ) ) self.assertEqual( set(h), { s["pA"] } ) # Test defaulting to last input node if no valid plug or path GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher() ) self.assertEqual( set(h), { s["o"] } ) # Test nodes changed n.clear() self.assertEqual( h.size(), 0 ) n.add( s["g2" ] ) GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ a ] ) ) self.assertEqual( set(h), { s["pA"] } ) n.remove( s["g2"] ) n.add( s["g"] ) self.assertEqual( set(h), { s["g"] } ) GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ "/group/planeA" ] ) ) self.assertEqual( set(h), { s["pA"] } ) GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ "/group" ] ) ) n.clear() n.add( s["g2"] ) self.assertEqual( set(h), { s["g2"] } ) # Test incoming scene dirtied GafferSceneUI.ContextAlgo.setSelectedPaths( c, IECore.PathMatcher( [ b ] ) ) self.assertEqual( set(h), { s["pB"] } ) s["pB"]["name"].setValue( "notPlaneB" ) self.assertEqual( set(h), { s["g2"] } ) # Test multiple non-scene nodes n.clear() n.add( s["s"] ) self.assertEqual( set(h), { s["s"] } ) n.add( s["s2"] ) self.assertEqual( set(h), { s["s2"] } ) n.remove( s["s2"] ) self.assertEqual( set(h), { s["s"] } )
def testCannotViewCatalogue(self): view = GafferSceneUI.ShaderView() catalogue = GafferImage.Catalogue() self.assertFalse(view["in"].acceptsInput(catalogue["out"]))
def testInteractionWithAimConstraints(self): script = Gaffer.ScriptNode() # Cube at ( 0, 10, 0 ), aimed at a sphere at the origin. script["sphere"] = GafferScene.Sphere() script["cube"] = GafferScene.Cube() script["cube"]["transform"]["translate"]["y"].setValue(10) 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["aim"] = GafferScene.AimConstraint() script["aim"]["in"].setInput(script["parent"]["out"]) script["aim"]["filter"].setInput(script["cubeFilter"]["out"]) script["aim"]["target"].setValue("/sphere") # Translate in Z (parent space) and check that we moved to # where we expected. self.assertEqual(script["aim"]["out"].transform("/cube").translation(), imath.V3f(0, 10, 0)) view = GafferSceneUI.SceneView() view["in"].setInput(script["aim"]["out"]) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/cube"])) tool = GafferSceneUI.TranslateTool(view) tool["active"].setValue(True) self.assertEqual(len(tool.selection()), 1) self.assertEqual(tool.selection()[0].path(), "/cube") self.assertEqual(tool.selection()[0].upstreamPath(), "/cube") self.assertEqual(tool.selection()[0].editTarget(), script["cube"]["transform"]) tool.translate(imath.V3f(0, 0, 10)) self.assertEqual(script["aim"]["out"].transform("/cube").translation(), imath.V3f(0, 10, 10)) # Reset back to ( 0, 10, 0 ) and check the same thing works with # an EditScope. script["cube"]["transform"]["translate"].setValue(imath.V3f(0, 10, 0)) script["editScope"] = Gaffer.EditScope() script["editScope"].setup(script["parent"]["out"]) script["editScope"]["in"].setInput(script["parent"]["out"]) script["aim"]["in"].setInput(script["editScope"]["out"]) view["editScope"].setInput(script["editScope"]["out"]) self.assertEqual(len(tool.selection()), 1) self.assertTrue(tool.selectionEditable()) self.assertEqual(tool.selection()[0].path(), "/cube") self.assertEqual(tool.selection()[0].upstreamPath(), "/cube") self.assertEqual(tool.selection()[0].editTarget(), script["editScope"]) tool.translate(imath.V3f(0, 0, 10)) self.assertEqual(script["aim"]["out"].transform("/cube").translation(), imath.V3f(0, 10, 10))
def __driveFromSceneSelectionSourceChangeCallback(editor, targetEditor): sourceSet = targetEditor.getNodeSet() context = targetEditor.getContext() return GafferSceneUI.SourceSet(context, sourceSet)
def testObjectAtLine(self): cubes = [] names = ("left", "center", "right") for i in range(3): cube = GafferScene.Cube() cube["transform"]["translate"].setValue( imath.V3f((i - 1) * 2.0, 0.0, -2.5)) cube["name"].setValue(names[i]) cubes.append(cube) group = GafferScene.Group() for i, cube in enumerate(cubes): group["in"][i].setInput(cube["out"]) sg = GafferSceneUI.SceneGadget() sg.setScene(group["out"]) sg.setMinimumExpansionDepth(100) with GafferUI.Window() as w: gw = GafferUI.GadgetWidget(sg) w.setVisible(True) self.waitForIdle(10000) vp = gw.getViewportGadget() # This is the single most important line in this test. If you don't set # this to false, you get an orthographic camera, even if you set a # perspective projection. vp.setPlanarMovement(False) c = IECoreScene.Camera() c.setProjection("perspective") c.setFocalLength(35) c.setAperture(imath.V2f(36, 24)) vp.setCamera(c) cameraTransform = imath.M44f() cameraTransform.translate(imath.V3f(0, 0, 2)) vp.setCameraTransform(cameraTransform) self.waitForIdle(10000) # We assume in this case, that gadget space is world space leftCubeDir = IECore.LineSegment3f(imath.V3f(0, 0, 2), imath.V3f(-2, 0, -2)) pathA = sg.objectAt(leftCubeDir) pathB, hitPoint = sg.objectAndIntersectionAt(leftCubeDir) self.assertIsNotNone(pathA) self.assertEqual(pathA, IECore.InternedStringVectorData(["group", "left"])) self.assertEqual(pathA, pathB) self.assertAlmostEqual(hitPoint.x, -2, delta=0.01) self.assertAlmostEqual(hitPoint.y, 0, delta=0.01) self.assertAlmostEqual(hitPoint.z, -2, delta=0.01) centerCubeDir = IECore.LineSegment3f(imath.V3f(0, 0, 1), imath.V3f(0, 0, -1)) pathA = sg.objectAt(centerCubeDir) pathB, hitPoint = sg.objectAndIntersectionAt(centerCubeDir) self.assertIsNotNone(pathA) self.assertEqual(pathA, IECore.InternedStringVectorData(["group", "center"])) self.assertEqual(pathA, pathB) self.assertAlmostEqual(hitPoint.x, 0, delta=0.01) self.assertAlmostEqual(hitPoint.y, 0, delta=0.01) self.assertAlmostEqual(hitPoint.z, -2, delta=0.01) rightCubeDir = IECore.LineSegment3f(imath.V3f(0, 0, 2), imath.V3f(2, 0, -2)) pathA = sg.objectAt(rightCubeDir) pathB, hitPoint = sg.objectAndIntersectionAt(rightCubeDir) self.assertIsNotNone(pathA) self.assertEqual(pathA, IECore.InternedStringVectorData(["group", "right"])) self.assertEqual(pathA, pathB) self.assertAlmostEqual(hitPoint.x, 2, delta=0.01) self.assertAlmostEqual(hitPoint.y, 0, delta=0.01) self.assertAlmostEqual(hitPoint.z, -2, delta=0.01) missDir = IECore.LineSegment3f(imath.V3f(0, 0, 2), imath.V3f(0, 10, -2)) pathA = sg.objectAt(missDir) pathB, hitPoint = sg.objectAndIntersectionAt(missDir) self.assertIsNone(pathA) self.assertIsNone(pathB)