def testSourceLocation(self): sphere1 = GafferScene.Sphere() sphere2 = GafferScene.Sphere() sphere2["radius"].setValue(2) sphere3 = GafferScene.Sphere() sphere3["radius"].setValue(3) group = GafferScene.Group() group["in"][0].setInput(sphere2["out"]) group["in"][1].setInput(sphere3["out"]) sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue(IECore.StringVectorData(["/sphere"])) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(sphere1["out"]) copy["source"].setInput(group["out"]) copy["filter"].setInput(sphereFilter["out"]) copy["primitiveVariables"].setValue("P") copy["sourceLocation"].setValue("/group/sphere") self.assertEqual(copy["out"].object("/sphere")["P"], group["out"].object("/group/sphere")["P"]) copy["sourceLocation"].setValue("/group/sphere1") self.assertEqual(copy["out"].object("/sphere")["P"], group["out"].object("/group/sphere1")["P"]) # Copying from a non-existing location should be a no-op copy["sourceLocation"].setValue("/road/to/nowhere") self.assertScenesEqual(copy["out"], sphere1["out"])
def testInterpolatedVariables(self): littleSphere = GafferScene.Sphere() bigSphere = GafferScene.Sphere() bigSphere["radius"].setValue(10) sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue(IECore.StringVectorData(["/sphere"])) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(littleSphere["out"]) copy["source"].setInput(bigSphere["out"]) copy["filter"].setInput(sphereFilter["out"]) self.assertScenesEqual(copy["out"], littleSphere["out"]) copy["primitiveVariables"].setValue("*") self.assertScenesEqual(copy["out"], bigSphere["out"]) # If the spheres have differing topologies, then we can't copy # and should get an error. bigSphere["divisions"][0].setValue(100) with six.assertRaisesRegex( self, RuntimeError, 'Cannot copy .* from "/sphere" to "/sphere" because source and destination primitives have different topology' ): copy["out"].object("/sphere")
def testBoundUpdate(self): sphere1 = GafferScene.Sphere() sphere2 = GafferScene.Sphere() sphere2["radius"].setValue(2) group = GafferScene.Group() group["in"][0].setInput(sphere1["out"]) sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue( IECore.StringVectorData(["/group/sphere"])) stashP = GafferScene.ShufflePrimitiveVariables() stashP["in"].setInput(group["out"]) stashP["filter"].setInput(sphereFilter["out"]) stashP["shuffles"].addChild(Gaffer.ShufflePlug("P", "Pref")) # P is unchanged, we want a perfect pass through of the input bounds. self.assertScenesEqual(stashP["out"], group["out"], checks={"bound"}) self.assertSceneHashesEqual(stashP["out"], group["out"], checks={"bound"}) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(stashP["out"]) copy["source"].setInput(sphere2["out"]) copy["filter"].setInput(sphereFilter["out"]) copy["sourceLocation"].setValue("/sphere") copy["primitiveVariables"].setValue("P") restoreP = GafferScene.ShufflePrimitiveVariables() restoreP["in"].setInput(copy["out"]) restoreP["filter"].setInput(sphereFilter["out"]) restoreP["shuffles"].addChild(Gaffer.ShufflePlug("Pref", "P")) # P is changed, we need to update bounds self.assertSceneValid(restoreP["out"]) self.assertNotEqual(restoreP["out"].bound("/"), copy["out"].bound("/")) self.assertNotEqual(restoreP["out"].bound("/group"), copy["out"].bound("/")) self.assertNotEqual(restoreP["out"].bound("/group/sphere"), copy["out"].bound("/")) # If we turn off "adjustBounds", we want a perfect pass through of the input bounds. restoreP["adjustBounds"].setValue(False) self.assertScenesEqual(restoreP["out"], copy["out"], checks={"bound"}) self.assertSceneHashesEqual(restoreP["out"], copy["out"], checks={"bound"}) # If "adjustBounds" is on, but the shuffle is disabled, we also want # a perfect pass through of the input bounds. restoreP["adjustBounds"].setValue(True) restoreP["shuffles"][0]["enabled"].setValue(False) self.assertScenesEqual(restoreP["out"], copy["out"], checks={"bound"}) self.assertSceneHashesEqual(restoreP["out"], copy["out"], checks={"bound"})
def testBoundUpdate(self): sphere1 = GafferScene.Sphere() sphere2 = GafferScene.Sphere() sphere2["radius"].setValue(2) group = GafferScene.Group() group["in"][0].setInput(sphere1["out"]) sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue( IECore.StringVectorData(["/group/sphere"])) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(group["out"]) copy["source"].setInput(sphere2["out"]) copy["filter"].setInput(sphereFilter["out"]) copy["sourceLocation"].setValue("/sphere") copy["primitiveVariables"].setValue("P") # We're copying "P", so the bounds need updating. self.assertEqual(copy["out"].object("/group/sphere")["P"], sphere2["out"].object("/sphere")["P"]) self.assertSceneValid(copy["out"]) self.assertEqual(copy["out"].bound("/"), sphere2["out"].bound("/")) self.assertEqual(copy["out"].bound("/group"), sphere2["out"].bound("/")) self.assertEqual(copy["out"].bound("/group/sphere"), sphere2["out"].bound("/")) # If we turn off "adjustBounds", we want a perfect pass through of the input # bounds. copy["adjustBounds"].setValue(False) self.assertScenesEqual(copy["out"], group["out"], checks={"bound"}) self.assertSceneHashesEqual(copy["out"], group["out"], checks={"bound"}) # If "adjustBounds" is on, but "P" isn't being copied, we also want # a perfect pass through of the input bounds. We don't want to pay for # unnecessary bounds propagation. copy["adjustBounds"].setValue(True) copy["primitiveVariables"].setValue("uv") self.assertScenesEqual(copy["out"], group["out"], checks={"bound"}) self.assertSceneHashesEqual(copy["out"], group["out"], checks={"bound"})
def testMismatchedHierarchy(self): sphere = GafferScene.Sphere() cube = GafferScene.Cube() sphereFilter = GafferScene.PathFilter() sphereFilter["paths"].setValue(IECore.StringVectorData(["/sphere"])) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(sphere["out"]) copy["source"].setInput(cube["out"]) copy["filter"].setInput(sphereFilter["out"]) copy["primitiveVariables"].setValue("*") self.assertEqual(copy["out"].object("/sphere"), copy["in"].object("/sphere"))
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, )
def testConstantVariables(self): sphere = GafferScene.Sphere() sphere["name"].setValue("object") cube = GafferScene.Cube() cube["name"].setValue("object") cubeVariables = GafferScene.PrimitiveVariables() cubeVariables["in"].setInput(cube["out"]) cubeVariables["primitiveVariables"].addChild( Gaffer.NameValuePlug("ten", IECore.IntData(10))) cubeVariables["primitiveVariables"].addChild( Gaffer.NameValuePlug("twenty", IECore.IntData(20))) copy = GafferScene.CopyPrimitiveVariables() copy["in"].setInput(sphere["out"]) copy["source"].setInput(cubeVariables["out"]) # Not filtered to anything, so should be a perfect pass through. self.assertScenesEqual(sphere["out"], copy["out"]) self.assertSceneHashesEqual(sphere["out"], copy["out"]) # Add a filter, should still be a pass through because we haven't # asked for any variables to be copied. objectFilter = GafferScene.PathFilter() objectFilter["paths"].setValue(IECore.StringVectorData(["/object"])) copy["filter"].setInput(objectFilter["out"]) self.assertScenesEqual(sphere["out"], copy["out"]) # Copy something that doesn't exist. This isn't an error, because the # variables are treated as match patterns. copy["primitiveVariables"].setValue("these don't exist") self.assertScenesEqual(sphere["out"], copy["out"]) # Copy things that do exist, and check that it has worked. copy["primitiveVariables"].setValue("ten twenty") self.assertEqual( set(copy["out"].object("/object").keys()), set(sphere["out"].object("/object").keys()) | {"ten", "twenty"}, ) self.assertEqual( copy["out"].object("/object")["ten"], cubeVariables["out"].object("/object")["ten"], ) self.assertEqual( copy["out"].object("/object")["twenty"], cubeVariables["out"].object("/object")["twenty"], ) # Check that wildcards work copy["primitiveVariables"].setValue("twen*") self.assertEqual( set(copy["out"].object("/object").keys()), set(sphere["out"].object("/object").keys()) | {"twenty"}, )