示例#1
0
    def testFilter(self):

        p1 = GafferScene.Plane()
        p1["transform"]["translate"].setValue(imath.V3f(1, 2, 3))

        p2 = GafferScene.Plane()
        p2["transform"]["translate"].setValue(imath.V3f(1, 2, 3))

        g = GafferScene.Group()
        g["transform"]["translate"].setValue(imath.V3f(1, 0, 0))
        g["in"][0].setInput(p1["out"])
        g["in"][1].setInput(p2["out"])

        f = GafferScene.PathFilter()
        f["paths"].setValue(IECore.StringVectorData(["/group/plane"]))

        t = GafferScene.FreezeTransform()
        t["in"].setInput(g["out"])
        t["filter"].setInput(f["out"])

        self.assertSceneValid(t["out"])

        self.assertEqual(t["out"].transform("/group"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))
        self.assertEqual(t["out"].transform("/group/plane"), imath.M44f())
        self.assertEqual(t["out"].transform("/group/plane1"),
                         imath.M44f().translate(imath.V3f(1, 2, 3)))

        self.assertEqual(
            t["out"].bound("/group/plane"),
            imath.Box3f(imath.V3f(0.5, 1.5, 3), imath.V3f(1.5, 2.5, 3)))
        self.assertEqual(
            t["out"].bound("/group/plane1"),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))

        self.assertEqual(
            t["out"].object("/group/plane").bound(),
            imath.Box3f(imath.V3f(0.5, 1.5, 3), imath.V3f(1.5, 2.5, 3)))
        self.assertEqual(
            t["out"].object("/group/plane1").bound(),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))

        f["paths"].setValue(IECore.StringVectorData(["/group",
                                                     "/group/plane"]))

        self.assertSceneValid(t["out"])

        self.assertEqual(t["out"].transform("/group"), imath.M44f())
        self.assertEqual(t["out"].transform("/group/plane"), imath.M44f())
        self.assertEqual(t["out"].transform("/group/plane1"),
                         imath.M44f().translate(imath.V3f(1, 2, 3)))

        self.assertEqual(
            t["out"].bound("/group/plane"),
            imath.Box3f(imath.V3f(1.5, 1.5, 3), imath.V3f(2.5, 2.5, 3)))
        self.assertEqual(
            t["out"].bound("/group/plane1"),
            imath.Box3f(imath.V3f(0.5, -0.5, 0), imath.V3f(1.5, 0.5, 0)))
	def test( self ) :

		p = GafferScene.Plane()
		p["transform"]["translate"].setValue( IECore.V3f( 1, 2, 3 ) )

		t = GafferScene.FreezeTransform()
		t["in"].setInput( p["out"] )

		self.assertSceneValid( t["out"] )

		self.assertEqual( t["out"].transform( "/plane" ), IECore.M44f() )
		self.assertEqual( t["out"].bound( "/plane" ), IECore.Box3f( IECore.V3f( 0.5, 1.5, 3 ), IECore.V3f( 1.5, 2.5, 3 ) ) )
		self.assertEqual( t["out"].object( "/plane" ).bound(), IECore.Box3f( IECore.V3f( 0.5, 1.5, 3 ), IECore.V3f( 1.5, 2.5, 3 ) ) )
示例#3
0
    def testSetFilter(self):

        plane = GafferScene.Plane()
        plane["transform"]["translate"].setValue(imath.V3f(1, 2, 3))
        plane["sets"].setValue("A")

        planeFilter = GafferScene.SetFilter()
        planeFilter["setExpression"].setValue("A")

        freezeTransform = GafferScene.FreezeTransform()
        freezeTransform["in"].setInput(plane["out"])
        freezeTransform["filter"].setInput(planeFilter["out"])

        self.assertSceneValid(freezeTransform["out"])
        self.assertEqual(freezeTransform["out"].transform("/plane"),
                         imath.M44f())
    def testSelectionRefersToCorrectPlug(self):

        script = Gaffer.ScriptNode()

        script["sphere"] = GafferScene.Sphere()
        script["cube"] = GafferScene.Cube()
        script["freeze"] = GafferScene.FreezeTransform()
        script["freezeFilter"] = GafferScene.PathFilter()
        script["freezeFilter"]["paths"].setValue(
            IECore.StringVectorData(["/sphere"]))
        script["freeze"]["in"].setInput(script["sphere"]["out"])
        script["freeze"]["filter"].setInput(script["freezeFilter"]["out"])
        script["instancer"] = GafferScene.Instancer()
        script["instancerFilter"] = GafferScene.PathFilter()
        script["instancerFilter"]["paths"].setValue(
            IECore.StringVectorData(["/sphere"]))
        script["instancer"]["in"].setInput(script["freeze"]["out"])
        script["instancer"]["prototypes"].setInput(script["cube"]["out"])
        script["instancer"]["filter"].setInput(
            script["instancerFilter"]["out"])
        script["subTree"] = GafferScene.SubTree()
        script["subTree"]["root"].setValue("/sphere/instances")
        script["subTree"]["in"].setInput(script["instancer"]["out"])
        script["plane"] = GafferScene.Plane()
        script["group"] = GafferScene.Group()
        script["group"]["in"][0].setInput(script["subTree"]["out"])
        script["group"]["in"][1].setInput(script["plane"]["out"])

        view = GafferSceneUI.SceneView()

        tool = GafferSceneUI.TranslateTool(view)
        tool["active"].setValue(True)
        self.assertEqual(tool.selection(), [])

        view["in"].setInput(script["group"]["out"])
        self.assertEqual(tool.selection(), [])

        GafferSceneUI.ContextAlgo.setSelectedPaths(
            view.getContext(), IECore.PathMatcher(["/group/plane"]))
        self.assertEqual(len(tool.selection()), 1)
        self.assertEqual(tool.selection()[0].editTarget(),
                         script["plane"]["transform"])
示例#5
0
    def testAffects(self):

        t = GafferScene.FreezeTransform()
        self.assertEqual(set(t.affects(t["in"]["object"])),
                         set([t["out"]["object"]]))
    def test(self):

        # Make a few input scenes

        script = Gaffer.ScriptNode()

        script["Cube"] = GafferScene.Cube("Cube")
        script["PathFilter"] = GafferScene.PathFilter("PathFilter")
        script["PathFilter"]["paths"].setValue(
            IECore.StringVectorData(['/cube']))
        script["Transform"] = GafferScene.Transform("Transform")
        script["Transform"]["in"].setInput(script["Cube"]["out"])
        script["Transform"]["filter"].setInput(script["PathFilter"]["out"])
        script["FreezeTransform"] = GafferScene.FreezeTransform(
            "FreezeTransform")
        script["FreezeTransform"]["in"].setInput(script["Transform"]["out"])
        script["FreezeTransform"]["filter"].setInput(
            script["PathFilter"]["out"])
        script["PrimitiveVariables"] = GafferScene.PrimitiveVariables(
            "PrimitiveVariables")
        script["PrimitiveVariables"]["primitiveVariables"].addChild(
            Gaffer.CompoundDataPlug.MemberPlug("member1"))
        script["PrimitiveVariables"]["primitiveVariables"]["member1"].addChild(
            Gaffer.StringPlug("name"))
        script["PrimitiveVariables"]["primitiveVariables"]["member1"].addChild(
            Gaffer.Color3fPlug("value"))
        script["PrimitiveVariables"]["primitiveVariables"]["member1"].addChild(
            Gaffer.BoolPlug("enabled", defaultValue=True))
        script["PrimitiveVariables"]["in"].setInput(
            script["FreezeTransform"]["out"])
        script["PrimitiveVariables"]["filter"].setInput(
            script["PathFilter"]["out"])
        script["PrimitiveVariables"]["primitiveVariables"]["member1"][
            "name"].setValue('Cs')
        script[
            "CollectPrimitiveVariables"] = GafferScene.CollectPrimitiveVariables(
                "CollectPrimitiveVariables")
        script["CollectPrimitiveVariables"]["in"].setInput(
            script["PrimitiveVariables"]["out"])
        script["CollectPrimitiveVariables"]["filter"].setInput(
            script["PathFilter"]["out"])
        script["Expression1"] = Gaffer.Expression("Expression1")
        script["Expression1"].setExpression(
            """
s =  context.get( "collect:primitiveVariableSuffix", "_suffix0" )
i = int( s[7] )
parent["Transform"]["transform"]["translate"] = imath.V3f( i )
parent["PrimitiveVariables"]["primitiveVariables"]["member1"]["value"] = imath.V3f( i )""",
            "python")

        defaultCube = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(-0.5), imath.V3f(0.5)))
        defaultCubeOff1 = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0.5), imath.V3f(1.5)))
        defaultCubeOff2 = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(1.5), imath.V3f(2.5)))

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()), set(["P", "N", "uv", "Cs"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["N"],
            defaultCube["N"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["uv"],
            defaultCube["uv"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))

        script["CollectPrimitiveVariables"]["suffixes"].setValue(
            IECore.StringVectorData(['_suffix1', '_suffix2']))

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()),
            set(["P", "N", "uv", "P_suffix1", "P_suffix2", "Cs"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["P_suffix1"], defaultCubeOff1["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["P_suffix2"], defaultCubeOff2["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))

        script["CollectPrimitiveVariables"]["primitiveVariables"].setValue(
            "P Cs")

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()),
            set([
                "P", "N", "uv", "P_suffix1", "P_suffix2", "Cs", "Cs_suffix1",
                "Cs_suffix2"
            ]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["P_suffix1"], defaultCubeOff1["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["P_suffix2"], defaultCubeOff2["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix1"].data.value, imath.Color3f(1))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix2"].data.value, imath.Color3f(2))

        script["CollectPrimitiveVariables"]["primitiveVariables"].setValue(
            "Cs")

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()),
            set(["P", "N", "uv", "Cs", "Cs_suffix1", "Cs_suffix2"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix1"].data.value, imath.Color3f(1))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix2"].data.value, imath.Color3f(2))

        script["CollectPrimitiveVariables"]["suffixContextVariable"].setValue(
            "collect:customVar")

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()),
            set(["P", "N", "uv", "Cs", "Cs_suffix1", "Cs_suffix2"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix1"].data.value, imath.Color3f(0))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix2"].data.value, imath.Color3f(0))

        script["CollectPrimitiveVariables"]["requireVariation"].setValue(True)

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()), set(["P", "N", "uv", "Cs"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))

        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].objectHash("/cube"),
            script["PrimitiveVariables"]["out"].objectHash("/cube"))

        script["Expression1"].setExpression(
            """
s =  context.get( "collect:customVar", "_suffix0" )
i = int( s[7] )
parent["Transform"]["transform"]["translate"] = imath.V3f( i )
parent["PrimitiveVariables"]["primitiveVariables"]["member1"]["value"] = imath.V3f( i )""",
            "python")

        self.assertEqual(
            set(script["CollectPrimitiveVariables"]["out"].object(
                "/cube").keys()),
            set(["P", "N", "uv", "Cs", "Cs_suffix1", "Cs_suffix2"]))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")["P"],
            defaultCube["P"])
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs"].data.value, imath.Color3f(0))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix1"].data.value, imath.Color3f(1))
        self.assertEqual(
            script["CollectPrimitiveVariables"]["out"].object("/cube")
            ["Cs_suffix2"].data.value, imath.Color3f(2))