예제 #1
0
    def testNameClashes(self):

        sphere = IECore.SpherePrimitive()
        input1 = GafferSceneTest.CompoundObjectSource()
        input1["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(sphere.bound()),
                "children": {
                    "myLovelyObject": {
                        "bound": IECore.Box3fData(sphere.bound()),
                        "object": sphere,
                    },
                },
            }), )

        plane = IECore.MeshPrimitive.createPlane(
            IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
        input2 = GafferSceneTest.CompoundObjectSource()
        input2["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(plane.bound()),
                "children": {
                    "myLovelyObject": {
                        "bound": IECore.Box3fData(plane.bound()),
                        "object": plane,
                    },
                },
            }), )

        combinedBound = sphere.bound()
        combinedBound.extendBy(plane.bound())

        group = GafferScene.Group()
        group["name"].setValue("topLevel")
        group["in"][0].setInput(input1["out"])
        group["in"][1].setInput(input2["out"])

        self.assertEqual(group["out"].object("/"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/"), IECore.M44f())
        self.assertEqual(group["out"].bound("/"), combinedBound)
        self.assertEqual(group["out"].childNames("/"),
                         IECore.InternedStringVectorData(["topLevel"]))

        self.assertEqual(group["out"].object("/topLevel"), IECore.NullObject())
        self.assertEqual(group["out"].transform("/topLevel"), IECore.M44f())
        self.assertEqual(group["out"].bound("/topLevel"), combinedBound)
        self.assertEqual(
            group["out"].childNames("/topLevel"),
            IECore.InternedStringVectorData(
                ["myLovelyObject", "myLovelyObject1"]))

        self.assertEqual(group["out"].object("/topLevel/myLovelyObject"),
                         sphere)
        self.assertEqual(group["out"].transform("/topLevel/myLovelyObject"),
                         IECore.M44f())
        self.assertEqual(group["out"].bound("/topLevel/myLovelyObject"),
                         sphere.bound())
        self.assertEqual(group["out"].childNames("/topLevel/myLovelyObject"),
                         IECore.InternedStringVectorData())

        self.assertEqual(group["out"].object("/topLevel/myLovelyObject1"),
                         plane)
        self.assertEqual(group["out"].transform("/topLevel/myLovelyObject1"),
                         IECore.M44f())
        self.assertEqual(group["out"].bound("/topLevel/myLovelyObject1"),
                         plane.bound())
        self.assertEqual(group["out"].childNames("/topLevel/myLovelyObject1"),
                         IECore.InternedStringVectorData())
예제 #2
0
    def test(self):

        sphere = IECoreScene.SpherePrimitive()
        instanceInput = GafferSceneTest.CompoundObjectSource()
        instanceInput["in"].setValue(
            IECore.CompoundObject({
                "bound":
                IECore.Box3fData(IECore.Box3f(IECore.V3f(-2), IECore.V3f(2))),
                "children": {
                    "sphere": {
                        "object":
                        sphere,
                        "bound":
                        IECore.Box3fData(sphere.bound()),
                        "transform":
                        IECore.M44fData(IECore.M44f.createScaled(
                            IECore.V3f(2))),
                    },
                }
            }))

        seeds = IECoreScene.PointsPrimitive(
            IECore.V3fVectorData([
                IECore.V3f(1, 0, 0),
                IECore.V3f(1, 1, 0),
                IECore.V3f(0, 1, 0),
                IECore.V3f(0, 0, 0)
            ]))
        seedsInput = GafferSceneTest.CompoundObjectSource()
        seedsInput["in"].setValue(
            IECore.CompoundObject(
                {
                    "bound":
                    IECore.Box3fData(
                        IECore.Box3f(IECore.V3f(1, 0, 0), IECore.V3f(2, 1,
                                                                     0))),
                    "children": {
                        "seeds": {
                            "bound":
                            IECore.Box3fData(seeds.bound()),
                            "transform":
                            IECore.M44fData(
                                IECore.M44f.createTranslated(
                                    IECore.V3f(1, 0, 0))),
                            "object":
                            seeds,
                        },
                    },
                }, ))

        instancer = GafferScene.Instancer()
        instancer["in"].setInput(seedsInput["out"])
        instancer["instance"].setInput(instanceInput["out"])
        instancer["parent"].setValue("/seeds")
        instancer["name"].setValue("instances")

        self.assertEqual(instancer["out"].object("/"), IECore.NullObject())
        self.assertEqual(instancer["out"].transform("/"), IECore.M44f())
        self.assertEqual(
            instancer["out"].bound("/"),
            IECore.Box3f(IECore.V3f(-1, -2, -2), IECore.V3f(4, 3, 2)))
        self.assertEqual(instancer["out"].childNames("/"),
                         IECore.InternedStringVectorData(["seeds"]))

        self.assertEqual(instancer["out"].object("/seeds"), seeds)
        self.assertEqual(instancer["out"].transform("/seeds"),
                         IECore.M44f().createTranslated(IECore.V3f(1, 0, 0)))
        self.assertEqual(
            instancer["out"].bound("/seeds"),
            IECore.Box3f(IECore.V3f(-2, -2, -2), IECore.V3f(3, 3, 2)))
        self.assertEqual(instancer["out"].childNames("/seeds"),
                         IECore.InternedStringVectorData(["instances"]))

        self.assertEqual(instancer["out"].object("/seeds/instances"),
                         IECore.NullObject())
        self.assertEqual(instancer["out"].transform("/seeds/instances"),
                         IECore.M44f())
        self.assertEqual(
            instancer["out"].bound("/seeds/instances"),
            IECore.Box3f(IECore.V3f(-2, -2, -2), IECore.V3f(3, 3, 2)))
        self.assertEqual(instancer["out"].childNames("/seeds/instances"),
                         IECore.InternedStringVectorData(["0", "1", "2", "3"]))

        for i in range(0, 4):

            instancePath = "/seeds/instances/%d" % i

            self.assertEqual(instancer["out"].object(instancePath),
                             IECore.NullObject())
            self.assertEqual(instancer["out"].transform(instancePath),
                             IECore.M44f.createTranslated(seeds["P"].data[i]))
            self.assertEqual(instancer["out"].bound(instancePath),
                             IECore.Box3f(IECore.V3f(-2), IECore.V3f(2)))
            self.assertEqual(instancer["out"].childNames(instancePath),
                             IECore.InternedStringVectorData(["sphere"]))

            self.assertEqual(instancer["out"].object(instancePath + "/sphere"),
                             sphere)
            self.assertEqual(
                instancer["out"].transform(instancePath + "/sphere"),
                IECore.M44f.createScaled(IECore.V3f(2)))
            self.assertEqual(instancer["out"].bound(instancePath + "/sphere"),
                             sphere.bound())
            self.assertEqual(
                instancer["out"].childNames(instancePath + "/sphere"),
                IECore.InternedStringVectorData())
예제 #3
0
	def testFilterCompute( self ) :
		crowd_input = GafferSceneTest.CompoundObjectSource()
		crowd_input["in"].setValue( buildCrowdTest() )

		node = AtomsGaffer.AtomsMetadata()
		node["in"].setInput( crowd_input["out"] )
		node["agentIds"].setValue( "1-2")
		node["metadata"].addMember( "tint", IECore.V3fData( imath.V3f( 1.0, 0.0, 0.0 ) ) )
		node["metadata"].addMember( "variation", IECore.StringData( "Robot3" ) )
		node["metadata"].addMember( "testData", IECore.IntData( 1 ) )

		output = node["out"].object( "/crowd" )
		self.assertEqual( output.typeId(), IECoreScene.PointsPrimitive.staticTypeId() )

		tint_data = output["atoms:tint"].data
		self.assertEqual( len(tint_data), 4 )
		self.assertNotEqual( tint_data[0], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[1], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[2], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertNotEqual( tint_data[3], imath.V3f( 1.0, 0.0, 0.0 ) )

		variation_data = output["atoms:variation"].data
		self.assertEqual( len(variation_data), 4 )
		self.assertNotEqual( variation_data[0], "Robot3" )
		self.assertEqual( variation_data[1], "Robot3" )
		self.assertEqual( variation_data[2], "Robot3" )
		self.assertNotEqual( variation_data[3], "Robot3" )

		test_data = output["atoms:testData"].data
		self.assertEqual( len(test_data), 4 )
		self.assertEqual( test_data[0], 2 )
		self.assertEqual( test_data[1], 1 )
		self.assertEqual( test_data[2], 1 )
		self.assertEqual( test_data[3], 2 )

		node["agentIds"].setValue( "!1-2" )
		output = node["out"].object( "/crowd" )
		self.assertEqual( output.typeId(), IECoreScene.PointsPrimitive.staticTypeId() )

		tint_data = output["atoms:tint"].data
		self.assertEqual( len(tint_data), 4 )
		self.assertEqual( tint_data[0], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertNotEqual( tint_data[1], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertNotEqual( tint_data[2], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[3], imath.V3f( 1.0, 0.0, 0.0 ) )

		variation_data = output["atoms:variation"].data
		self.assertEqual( len(variation_data), 4 )
		self.assertEqual( variation_data[0], "Robot3" )
		self.assertNotEqual( variation_data[1], "Robot3" )
		self.assertNotEqual( variation_data[2], "Robot3" )
		self.assertEqual( variation_data[3], "Robot3" )

		node["invert"].setValue( True )
		output = node["out"].object( "/crowd" )

		tint_data = output["atoms:tint"].data
		self.assertEqual( len(tint_data), 4 )
		self.assertNotEqual( tint_data[0], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[1], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[2], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertNotEqual( tint_data[3], imath.V3f( 1.0, 0.0, 0.0 ) )

		variation_data = output["atoms:variation"].data
		self.assertEqual( len(variation_data), 4 )
		self.assertNotEqual( variation_data[0], "Robot3" )
		self.assertEqual( variation_data[1], "Robot3" )
		self.assertEqual( variation_data[2], "Robot3" )
		self.assertNotEqual( variation_data[3], "Robot3" )
예제 #4
0
	def testPassThrough( self ) :

		sphere = IECore.SpherePrimitive()
		input = GafferSceneTest.CompoundObjectSource()
		input["in"].setValue(
			IECore.CompoundObject( {
				"bound" : IECore.Box3fData( sphere.bound() ),
				"children" : {
					"groupA" : {
						"bound" : IECore.Box3fData( sphere.bound() ),
						"children" : {
							"sphereAA" : {
								"bound" : IECore.Box3fData( sphere.bound() ),
								"object" : sphere,
							},
							"sphereAB" : {
								"bound" : IECore.Box3fData( sphere.bound() ),
								"object" : sphere,
							},
						},
					},
					"groupB" : {
						"bound" : IECore.Box3fData( sphere.bound() ),
						"children" : {
							"sphereBA" : {
								"bound" : IECore.Box3fData( sphere.bound() ),
								"object" : sphere,
							},
							"sphereBB" : {
								"bound" : IECore.Box3fData( sphere.bound() ),
								"object" : sphere,
							},
						},
					},
				},
			} ),
		)

		isolate = GafferScene.Isolate()
		isolate["in"].setInput( input["out"] )

		self.assertSceneValid( input["out"] )
		self.assertSceneValid( isolate["out"] )

		# with no filter applied, nothing should be isolated so we should have a perfect pass through

		self.assertScenesEqual( input["out"], isolate["out"] )
		self.assertSceneHashesEqual( input["out"], isolate["out"] )
		self.assertTrue( input["out"].object( "/groupA/sphereAA", _copy = False ).isSame( isolate["out"].object( "/groupA/sphereAA", _copy = False ) ) )

		# and even with a filter applied, we should have a perfect pass through if the node is disabled.

		filter = GafferScene.PathFilter()
		filter["paths"].setValue( IECore.StringVectorData( [ "/*" ] ) )
		isolate["filter"].setInput( filter["out"] )

		isolate["enabled"].setValue( False )

		self.assertScenesEqual( input["out"], isolate["out"] )
		self.assertSceneHashesEqual( input["out"], isolate["out"] )
		self.assertTrue( input["out"].object( "/groupA/sphereAA", _copy = False ).isSame( isolate["out"].object( "/groupA/sphereAA", _copy = False ) ) )
예제 #5
0
    def testHashPassThrough(self):

        sphere = IECoreScene.SpherePrimitive()
        input = GafferSceneTest.CompoundObjectSource()
        input["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(sphere.bound()),
                "children": {
                    "ball1": {
                        "object": sphere,
                        "bound": IECore.Box3fData(sphere.bound()),
                    },
                    "ball2": {
                        "object": sphere,
                        "bound": IECore.Box3fData(sphere.bound()),
                    },
                },
            }))

        a = GafferScene.CustomAttributes()
        a["in"].setInput(input["out"])

        # when we have no attributes at all, everything should be a pass-through
        self.assertSceneHashesEqual(input["out"], a["out"])

        # when we have some attributes, everything except the attributes plug should
        # be a pass-through.
        a["attributes"].addChild(
            Gaffer.NameValuePlug("ri:shadingRate",
                                 IECore.FloatData(2.0),
                                 flags=Gaffer.Plug.Flags.Default
                                 | Gaffer.Plug.Flags.Dynamic))
        self.assertSceneHashesEqual(input["out"],
                                    a["out"],
                                    checks=self.allSceneChecks -
                                    {"attributes"})
        self.assertSceneHashesNotEqual(input["out"],
                                       a["out"],
                                       checks={"attributes"})

        # when we add a filter, non-matching objects should become pass-throughs
        f = GafferScene.PathFilter()
        f["paths"].setValue(IECore.StringVectorData(["/ball1"]))
        a["filter"].setInput(f["out"])
        self.assertSceneHashesEqual(input["out"],
                                    a["out"],
                                    pathsToIgnore=("/ball1", ))

        c = Gaffer.Context()
        c["scene:path"] = IECore.InternedStringVectorData(["ball1"])
        with c:
            self.assertEqual(a["out"]["childNames"].hash(),
                             input["out"]["childNames"].hash())
            self.assertEqual(a["out"]["transform"].hash(),
                             input["out"]["transform"].hash())
            self.assertEqual(a["out"]["bound"].hash(),
                             input["out"]["bound"].hash())
            self.assertEqual(a["out"]["object"].hash(),
                             input["out"]["object"].hash())
            self.assertNotEqual(a["out"]["attributes"].hash(),
                                input["out"]["attributes"].hash())
예제 #6
0
    def testOverrideAttributes(self):

        sphere = IECoreScene.SpherePrimitive()
        input = GafferSceneTest.CompoundObjectSource()
        input["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(sphere.bound()),
                "children": {
                    "ball1": {
                        "object": sphere,
                        "bound": IECore.Box3fData(sphere.bound()),
                    },
                },
            }))

        a = GafferScene.CustomAttributes()
        a["in"].setInput(input["out"])

        a["attributes"].addChild(
            Gaffer.NameValuePlug("ri:shadingRate",
                                 IECore.FloatData(0.25),
                                 flags=Gaffer.Plug.Flags.Default
                                 | Gaffer.Plug.Flags.Dynamic))
        a["attributes"].addChild(
            Gaffer.NameValuePlug("user:something",
                                 IECore.IntData(1),
                                 flags=Gaffer.Plug.Flags.Default
                                 | Gaffer.Plug.Flags.Dynamic))
        self.assertEqual(
            a["out"].attributes("/ball1"),
            IECore.CompoundObject({
                "ri:shadingRate": IECore.FloatData(0.25),
                "user:something": IECore.IntData(1),
            }))

        a2 = GafferScene.CustomAttributes()
        a2["in"].setInput(a["out"])

        self.assertEqual(
            a2["out"].attributes("/ball1"),
            IECore.CompoundObject({
                "ri:shadingRate": IECore.FloatData(0.25),
                "user:something": IECore.IntData(1),
            }))

        a2["attributes"].addChild(
            Gaffer.NameValuePlug("ri:shadingRate",
                                 IECore.FloatData(.5),
                                 flags=Gaffer.Plug.Flags.Default
                                 | Gaffer.Plug.Flags.Dynamic))
        a2["attributes"].addChild(
            Gaffer.NameValuePlug("user:somethingElse",
                                 IECore.IntData(10),
                                 flags=Gaffer.Plug.Flags.Default
                                 | Gaffer.Plug.Flags.Dynamic))

        self.assertEqual(
            a2["out"].attributes("/ball1"),
            IECore.CompoundObject({
                "ri:shadingRate": IECore.FloatData(0.5),
                "user:something": IECore.IntData(1),
                "user:somethingElse": IECore.IntData(10),
            }))