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 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 testCollaboratePerf(self): # Set up a scene with lots of spheres with different UVs uvSphere = GafferScene.Sphere() uvSphere["divisions"].setValue(imath.V2i(2000)) uvSphere["expression"] = Gaffer.Expression() uvSphere["expression"].setExpression( 'parent["transform"]["translate"]["y"] = 2 * int( context["collect:rootName"] )' ) camera = GafferScene.Camera() camera["projection"].setValue('orthographic') parent = GafferScene.Parent() parent["parent"].setValue('/') parent["children"][0].setInput(camera["out"]) parent["in"].setInput(uvSphere["out"]) sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue(IECore.StringVectorData(['/sphere'])) mapProjection = GafferScene.MapProjection() mapProjection["in"].setInput(parent["out"]) mapProjection["filter"].setInput(sphereFilter["out"]) mapProjection["camera"].setValue('/camera') collectScenes = GafferScene.CollectScenes() collectScenes["in"].setInput(mapProjection["out"]) collectScenes["rootNames"].setValue( IECore.StringVectorData([str(i) for i in range(50)])) allFilter = GafferScene.PathFilter() allFilter["paths"].setValue(IECore.StringVectorData(['/...'])) # Set up query query = GafferScene.UDIMQuery() query["in"].setInput(collectScenes["out"]) query["filter"].setInput(allFilter["out"]) query["outInt"] = Gaffer.IntPlug() query["outIntExpression"] = Gaffer.Expression() query["outIntExpression"].setExpression( 'parent["outInt"] = len( parent["out"] ) + context["iteration"]') with GafferTest.TestRunner.PerformanceScope(): GafferTest.parallelGetValue(query["outInt"], 400, "iteration")
def testHash(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"]) h = map["out"].objectHash("/group/cube") self.assertNotEqual(h, group["out"].objectHash("/group/cube")) cube["transform"]["translate"]["y"].setValue(1) h2 = map["out"].objectHash("/group/cube") self.assertNotEqual(h, h2)
def testWrongPositionType(self): cube = GafferScene.Cube() camera = GafferScene.Camera() group = GafferScene.Group() group["in"][0].setInput(cube["out"]) group["in"][1].setInput(camera["out"]) cubeFilter = GafferScene.PathFilter() cubeFilter["paths"].setValue(IECore.StringVectorData(["/group/cube"])) projection = GafferScene.MapProjection() projection["in"].setInput(group["out"]) projection["filter"].setInput(cubeFilter["out"]) projection["position"].setValue("uv") with six.assertRaisesRegex( self, RuntimeError, r'Position primitive variable "uv" on object "/group/cube" should be V3fVectorData \(but is V2fVectorData\)' ): projection["out"].object("/group/cube")
def test(self): allFilter = GafferScene.PathFilter() allFilter["paths"].setValue(IECore.StringVectorData(['/...'])) rootFilter = GafferScene.PathFilter() rootFilter["paths"].setValue(IECore.StringVectorData(['/*'])) plane0 = GafferScene.Plane() plane0["transform"]["translate"].setValue(imath.V3f(2, 1, 0)) plane0["transform"]["scale"].setValue(imath.V3f(2, 2, 1)) plane0["divisions"].setValue(imath.V2i(10, 10)) group = GafferScene.Group() group["in"][0].setInput(plane0["out"]) udimQuery = GafferScene.UDIMQuery() udimQuery["in"].setInput(group["out"]) udimQuery["filter"].setInput(allFilter["out"]) def dictResult(): c = udimQuery["out"].getValue().items() return { key0: {key1: dict(val1.items()) for (key1, val1) in val0.items()} for (key0, val0) in c } # Test a basic single UDIM self.assertEqual(dictResult(), {'1001': {'/group/plane': {}}}) # Add an attribute udimQuery["attributes"].setValue('attributeA attributeB attributeC') customAttributes0 = GafferScene.CustomAttributes() customAttributes0["attributes"].addChild( Gaffer.NameValuePlug("attributeA", "test")) customAttributes0["in"].setInput(plane0["out"]) group["in"][0].setInput(customAttributes0["out"]) self.assertEqual(dictResult(), { '1001': { '/group/plane': { 'attributeA': IECore.StringData('test') } } }) # Add an alternate UV set based on P, using a projection camera projCam = GafferScene.Camera() projCam["transform"]["translate"].setValue(imath.V3f(0.5, 0.5, 0)) projCam["projection"].setValue('orthographic') projCam["orthographicAperture"].setValue(imath.V2f(1)) group["in"][1].setInput(projCam["out"]) mapProjection = GafferScene.MapProjection() mapProjection["camera"].setValue('/group/camera') mapProjection["uvSet"].setValue('uvAlt') mapProjection["filter"].setInput(allFilter["out"]) mapProjection["in"].setInput(group["out"]) udimQuery["in"].setInput(mapProjection["out"]) self.assertEqual(dictResult(), { '1001': { '/group/plane': { 'attributeA': IECore.StringData('test') } } }) udimQuery["uvSet"].setValue('uvAlt') self.assertEqual( dictResult(), { i: { '/group/plane': { 'attributeA': IECore.StringData('test') } } for i in ["1002", "1003", "1012", "1013"] }) # Add two more objects plane1 = GafferScene.Plane() plane1["transform"]["translate"].setValue(imath.V3f(6.5, 2.5, 0)) plane1["divisions"].setValue(imath.V2i(10, 10)) customAttributes1 = GafferScene.CustomAttributes("CustomAttributes1") customAttributes1["in"].setInput(plane1["out"]) customAttributes1["filter"].setInput(allFilter["out"]) customAttributes1["attributes"].addChild( Gaffer.NameValuePlug("attributeA", "baz")) customAttributes1["attributes"].addChild( Gaffer.NameValuePlug("attributeB", 12)) plane2 = GafferScene.Plane() plane2["transform"]["translate"].setValue(imath.V3f(8, 4, 0)) plane2["transform"]["scale"].setValue(imath.V3f(2, 2, 1)) plane2["divisions"].setValue(imath.V2i(10, 10)) group["in"][2].setInput(customAttributes1["out"]) group["in"][3].setInput(plane2["out"]) customAttributes2 = GafferScene.CustomAttributes("CustomAttributes2") customAttributes2["in"].setInput(group["out"]) customAttributes2["filter"].setInput(rootFilter["out"]) customAttributes2["attributes"].addChild( Gaffer.NameValuePlug("attributeC", "inherited")) mapProjection["in"].setInput(customAttributes2["out"]) self.assertEqual( dictResult(), dict([(i, { '/group/plane': { 'attributeA': IECore.StringData('test'), 'attributeC': IECore.StringData('inherited') } }) for i in ["1002", "1003", "1012", "1013"]] + [("1027", { '/group/plane1': { 'attributeA': IECore.StringData('baz'), 'attributeB': IECore.IntData(12), 'attributeC': IECore.StringData('inherited') } })] + [(i, { '/group/plane2': { 'attributeC': IECore.StringData('inherited') } }) for i in ["1038", "1039", "1048", "1049"]])) # Switch back to default uv set so that everything lands on top of each other udimQuery["uvSet"].setValue('uv') self.assertEqual( dictResult(), { "1001": { '/group/plane': { 'attributeA': IECore.StringData('test'), 'attributeC': IECore.StringData('inherited') }, '/group/plane1': { 'attributeA': IECore.StringData('baz'), 'attributeB': IECore.IntData(12), 'attributeC': IECore.StringData('inherited') }, '/group/plane2': { 'attributeC': IECore.StringData('inherited') } } })
def testCustomPosition(self): littleCube = GafferScene.Cube() littleCube["name"].setValue("little") bigCube = GafferScene.Cube() bigCube["dimensions"].setValue(imath.V3f(10, 10, 10)) bigCube["name"].setValue("big") camera = GafferScene.Camera() camera["transform"]["translate"]["z"].setValue(10) group = GafferScene.Group() group["in"][0].setInput(littleCube["out"]) group["in"][1].setInput(bigCube["out"]) group["in"][2].setInput(camera["out"]) self.assertNotEqual( group["out"].object("/group/little")["P"].data, group["out"].object("/group/big")["P"].data, ) bigCubeFilter = GafferScene.PathFilter() bigCubeFilter["paths"].setValue(IECore.StringVectorData(["/group/big" ])) shuffle = GafferScene.ShufflePrimitiveVariables() shuffle["in"].setInput(group["out"]) shuffle["filter"].setInput(bigCubeFilter["out"]) shuffle["shuffles"].addChild(Gaffer.ShufflePlug("P", "Pref")) littleCubeFilter = GafferScene.PathFilter() littleCubeFilter["paths"].setValue( IECore.StringVectorData(["/group/little"])) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(shuffle["out"]) copy["source"].setInput(shuffle["out"]) copy["filter"].setInput(littleCubeFilter["out"]) copy["sourceLocation"].setValue("/group/big") copy["primitiveVariables"].setValue("Pref") self.assertEqual( copy["out"].object("/group/little")["Pref"].data, copy["out"].object("/group/big")["Pref"].data, ) unionFilter = GafferScene.UnionFilter() unionFilter["in"][0].setInput(littleCubeFilter["out"]) unionFilter["in"][1].setInput(bigCubeFilter["out"]) projection = GafferScene.MapProjection() projection["in"].setInput(copy["out"]) projection["filter"].setInput(unionFilter["out"]) projection["camera"].setValue("/group/camera") projection["uvSet"].setValue("projectedUV") self.assertNotEqual( projection["out"].object("/group/little")["projectedUV"].data, projection["out"].object("/group/big")["projectedUV"].data, ) projection["position"].setValue("Pref") self.assertEqual( projection["out"].object("/group/little")["projectedUV"].data[0], projection["out"].object("/group/big")["projectedUV"].data[0], ) self.assertEqual( projection["out"].object("/group/little")["projectedUV"].data, projection["out"].object("/group/big")["projectedUV"].data, )