예제 #1
0
    def testConvenienceConstructors(self):
        """ Test IECoreImage.ImagePrimitive convenience constructors """

        window1Min = imath.V2i(0, 0)
        window1Max = imath.V2i(15, 15)
        w1 = imath.Box2i(window1Min, window1Max)

        window2Min = imath.V2i(4, 4)
        window2Max = imath.V2i(11, 11)
        w2 = imath.Box2i(window2Min, window2Max)

        fill = imath.Color3f(0.49, 0.50, 0.51)
        i = IECoreImage.ImagePrimitive.createRGBFloat(fill, w1, w2)

        self.assertTrue(
            i.isInstanceOf(IECoreImage.ImagePrimitive.staticTypeId()))

        self.assertTrue("R" in i)
        self.assertTrue("G" in i)
        self.assertTrue("B" in i)
        self.assertTrue("Y" not in i)

        self.assertEqual(i.dataWindow, w1)
        self.assertEqual(i.displayWindow, w2)

        self.assertTrue(i["R"].isInstanceOf(
            IECore.FloatVectorData.staticTypeId()))
        self.assertTrue(i["G"].isInstanceOf(
            IECore.FloatVectorData.staticTypeId()))
        self.assertTrue(i["B"].isInstanceOf(
            IECore.FloatVectorData.staticTypeId()))

        self.assertEqual(i["R"].size(), 256)
        self.assertEqual(i["G"].size(), 256)
        self.assertEqual(i["B"].size(), 256)

        for p in (0, 63, 127, 255):
            self.assertEqual(i["R"][p], fill[0])
            self.assertEqual(i["G"][p], fill[1])
            self.assertEqual(i["B"][p], fill[2])

        fill = 0.5
        i = IECoreImage.ImagePrimitive.createGreyscaleFloat(fill, w1, w2)

        self.assertTrue(
            i.isInstanceOf(IECoreImage.ImagePrimitive.staticTypeId()))

        self.assertTrue("R" not in i)
        self.assertTrue("G" not in i)
        self.assertTrue("B" not in i)
        self.assertTrue("Y" in i)

        self.assertEqual(i.dataWindow, w1)
        self.assertEqual(i.displayWindow, w2)

        self.assertTrue(i["Y"].isInstanceOf(
            IECore.FloatVectorData.staticTypeId()))
        self.assertEqual(i["Y"].size(), 256)

        for p in (0, 63, 127, 255):
            self.assertEqual(i["Y"][p], fill)
예제 #2
0
    def testDefaultPrimVars(self):
        fileName = "{}/testUSDDefaultPrimVars.scc".format(
            self.temporaryDirectory())
        self._writeScene(fileName, writeCs=True)

        # root
        stage = pxr.Usd.Stage.Open(fileName)
        root = stage.GetPseudoRoot()
        prim = root.GetPrimAtPath("{}/t/s".format(
            IECoreUSD.SceneCacheDataAlgo.internalRootName()))

        # orientation
        orientation = prim.GetAttribute("orientation")
        self.assertEqual(orientation.Get(24.0), "rightHanded")

        # normal
        normals = prim.GetAttribute("normals")
        normalsData = normals.Get(24.0)
        self.assertEqual(normalsData[0], pxr.Gf.Vec3f(0.0, 0.0, -1.0))

        self.assertEqual(normalsData[8], pxr.Gf.Vec3f(0.0, 0.0, 1.0))

        self.assertEqual(normalsData[16], pxr.Gf.Vec3f(0.0, 1.0, 0.0))

        self.assertEqual(normalsData[23], pxr.Gf.Vec3f(0.0, -1.0, 0.0))

        # uv
        uvs = prim.GetAttribute("primvars:st")
        uvsData = uvs.Get(24.0)
        self.assertEqual(uvsData[0], pxr.Gf.Vec2f(0.375, 0.0))

        self.assertEqual(uvsData[8], pxr.Gf.Vec2f(0.375, 1.0))

        self.assertEqual(uvsData[12], pxr.Gf.Vec2f(0.125, .25))

        # uv are indexed
        self.assertTrue(prim.GetAttribute("primvars:st:indices"))

        # cs
        displayColor = prim.GetAttribute("primvars:displayColor")
        displayColorData = displayColor.Get(24.0)
        self.assertEqual(displayColorData[0], pxr.Gf.Vec3f(0.0, 0.0, 0.0))

        self.assertEqual(displayColorData[5], pxr.Gf.Vec3f(0.5, 0.5, 0.5))

        self.assertEqual(displayColorData[7], pxr.Gf.Vec3f(0.0, 0.5, 0.5))

        # round trip
        exportPath = "{}/testUSDExportDefaultPrimVars.scc".format(
            self.temporaryDirectory())
        stage.Export(exportPath)

        scene = IECoreScene.SharedSceneInterfaces.get(exportPath)
        location = scene.scene(["t", "s"])
        mesh = location.readObject(1.0)

        # normals
        normalsData = mesh["N"].data
        self.assertEqual(normalsData[0], imath.V3f(0, 0, -1))
        self.assertEqual(normalsData[8], imath.V3f(0, 0, 1))
        self.assertEqual(normalsData[16], imath.V3f(0, 1.0, 0))
        self.assertEqual(normalsData[23], imath.V3f(0, -1.0, 0))

        # uv
        uvsData = mesh["uv"].data
        self.assertEqual(uvsData[0], imath.V2f(0.375, 0))
        self.assertEqual(uvsData[8], imath.V2f(0.375, 1.0))
        self.assertEqual(uvsData[12], imath.V2f(0.125, 0.25))

        # uv are indexed
        self.assertTrue(mesh["uv"].indices)

        # Cs
        csData = mesh["Cs"].data
        self.assertEqual(csData[0], imath.Color3f(0, 0, 0))
        self.assertEqual(csData[5], imath.Color3f(0.5, 0.5, 0.5))
        self.assertEqual(csData[7], imath.Color3f(0, 0.5, 0.5))
예제 #3
0
	def testPrimVarTypes ( self ) :

		root = IECoreScene.SceneInterface.create( os.path.dirname( __file__ ) + "/data/primVars.usda", IECore.IndexedIO.OpenMode.Read )

		object = root.child("root").child("sphere").readObject(0.0)

		expected = {
			'test_Bool_Scalar_constant' : IECore.BoolData( 0 ),
			'test_Double2_Array_constant' : IECore.V2dVectorData( [imath.V2d( 1.1, 1.2 ), imath.V2d( 2.1, 2.2 ), imath.V2d( 3.1, 3.2 )] ),
			'test_Double2_Scalar_constant' : IECore.V2dData( imath.V2d( 0.1, 0.2 ) ),
			'test_Double3_Array_constant' : IECore.V3dVectorData( [imath.V3d( 1.1, 1.2, 1.3 ), imath.V3d( 2.1, 2.2, 2.3 ), imath.V3d( 3.1, 3.2, 3.3 )] ),
			'test_Double3_Scalar_constant' : IECore.V3dData( imath.V3d( 0.1, 0.2, 0.3 ) ),
			'test_Double_Array_constant' : IECore.DoubleVectorData([1.2, 1.3, 1.4]),
			'test_Double_Scalar_constant' : IECore.DoubleData( 1.1 ),
			'test_Float2_Array_constant' : IECore.V2fVectorData( [imath.V2f( 1.1, 1.2 ), imath.V2f( 2.1, 2.2 ), imath.V2f( 3.1, 3.2 )] ),
			'test_Float2_Scalar_constant' : IECore.V2fData( imath.V2f( 0.1, 0.2 ) ),
			'test_Float3_Array_constant' : IECore.V3fVectorData( [imath.V3f( 1.1, 1.2, 1.3 ), imath.V3f( 2.1, 2.2, 2.3 ), imath.V3f( 3.1, 3.2, 3.3 )] ),
			'test_Float3_Scalar_constant' : IECore.V3fData( imath.V3f( 0.1, 0.2, 0.3 ) ),
			'test_Float_Array_constant' : IECore.FloatVectorData( [0.7, 0.8, 0.9] ),
			'test_Float_Scalar_constant' : IECore.FloatData( 0.6 ),
			'test_Half_Array_constant' : IECore.HalfVectorData( [0.0999756, 0.199951, 0.300049] ),
			'test_Half_Scalar_constant' : IECore.HalfData( 0.5 ),
			'test_Int2_Array_constant' : IECore.V2iVectorData( [imath.V2i( 3, 4 ), imath.V2i( 5, 6 ), imath.V2i( 7, 8 )] ),
			'test_Int2_Scalar_constant' : IECore.V2iData( imath.V2i( 1, 2 ) ),
			'test_Int3_Array_constant' : IECore.V3iVectorData([imath.V3i(3, 4, 5), imath.V3i(5, 6, 7), imath.V3i(7, 8, 9)]),
			'test_Int3_Scalar_constant' : IECore.V3iData(imath.V3i(1, 2, 3)),
			'test_Int64_Array_constant' : IECore.Int64VectorData([9223372036854775805, 9223372036854775806, 9223372036854775807]),
			'test_Int64_Scalar_constant' : IECore.Int64Data(-9223372036854775808),
			'test_Int_Array_constant' : IECore.IntVectorData([0, -1, -2]),
			'test_Int_Scalar_constant' : IECore.IntData(-1),
			'test_String_Array_constant' : IECore.StringVectorData(["is", "a", "test"]),
			'test_String_Scalar_constant': IECore.StringData('this'),
			'test_Token_Array_constant' : IECore.InternedStringVectorData([IECore.InternedString("t-is"), IECore.InternedString("t-a"), IECore.InternedString("t-test")]),
			'test_Token_Scalar_constant' : IECore.InternedStringData(IECore.InternedString("t-this")),
			'test_UChar_Array_constant' : IECore.UCharVectorData([0,1,2]),
			'test_UChar_Scalar_constant' : IECore.UCharData(0),
			'test_UInt64_Array_constant' : IECore.UInt64VectorData([18446744073709551613, 18446744073709551614, 18446744073709551615]),
			'test_UInt64_Scalar_constant' : IECore.UInt64Data(18446744073709551615),
			'test_UInt_Array_constant' : IECore.UIntVectorData([4294967293, 4294967294, 4294967295]),
			'test_UInt_Scalar_constant' : IECore.UIntData(4294967295),
			#'test_color3d_Array_constant' : IECore.Color3dVectorData([IECore.Color3d(1.1, 1.2, 1.3), IECore.Color3d(2.1, 2.2, 2.3), IECore.Color3d(3.1, 3.2, 3.3)]),
			#'test_color3d_Scalar_constant' : IECore.Color3dData(IECore.Color3d(0.1, 0.2, 0.3)),
			'test_color3f_Array_constant' : IECore.Color3fVectorData([imath.Color3f(1.1, 1.2, 1.3), imath.Color3f(2.1, 2.2, 2.3), imath.Color3f(3.1, 3.2, 3.3)]),
			'test_color3f_Scalar_constant' :  IECore.Color3fData(imath.Color3f(0.1, 0.2, 0.3)),
			#'test_color4d_Array_constant' : IECore.Color4dVectorData([IECore.Color4d(1.1, 1.2, 1.3, 1.4), IECore.Color4d(2.1, 2.2, 2.3, 2.4), IECore.Color4d(3.1, 3.2, 3.3, 3.4)]),
			#'test_color4d_Scalar_constant' : IECore.Color4dData(IECore.Color4d(0.1, 0.2, 0.3, 0.4)),
			'test_color4f_Array_constant' : IECore.Color4fVectorData([imath.Color4f(1.1, 1.2, 1.3, 1.4), imath.Color4f(2.1, 2.2, 2.3, 2.4), imath.Color4f(3.1, 3.2, 3.3, 3.4)]),
			'test_color4f_Scalar_constant' : IECore.Color4fData(imath.Color4f(0.1, 0.2, 0.3, 0.4)),
			'test_matrix3d_Array_constant' : IECore.M33dVectorData(
				[
					imath.M33d(0, 0, 0, 0, 1, 0,0, 0, 0),
					imath.M33d(0, 0, 0, 0, 0, 0,0, 0, 2),
					imath.M33d(0, 0, 4, 0, 0, 0,0, 0, 0)
				]
			),
			'test_matrix3d_Scalar_constant' : IECore.M33dData(imath.M33d(0, 0, 0, 0, 0, 0, 0, 0, 0)),
			'test_matrix4d_Array_constant' : IECore.M44dVectorData(
				[
					imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0),
					imath.M44d(1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
					imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0)
				]
			),
			'test_matrix4d_Scalar_constant' : IECore.M44dData(imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
			'test_normal3d_Array_constant' : IECore.V3dVectorData([imath.V3d( 1.1, 1.2, 1.3 ), imath.V3d( 2.1, 2.2, 2.3 ), imath.V3d( 3.1, 3.2, 3.3 )]),
			'test_normal3d_Scalar_constant' : IECore.V3dData (imath.V3d( 0.1, 0.2, 0.3 )),
			'test_normal3f_Array_constant': IECore.V3fVectorData([imath.V3f( 1.1, 1.2, 1.3 ), imath.V3f( 2.1, 2.2, 2.3 ), imath.V3f( 3.1, 3.2, 3.3 )]),
			'test_normal3f_Scalar_constant' : IECore.V3fData (imath.V3f( 0.1, 0.2, 0.3 )),
			'test_point3d_Array_constant' : IECore.V3dVectorData([imath.V3d( 1.1, 1.2, 1.3 ), imath.V3d( 2.1, 2.2, 2.3 ), imath.V3d( 3.1, 3.2, 3.3 )]),
			'test_point3d_Scalar_constant' : IECore.V3dData (imath.V3d( 0.1, 0.2, 0.3 )),
			'test_point3f_Array_constant' : IECore.V3fVectorData([imath.V3f( 1.1, 1.2, 1.3 ), imath.V3f( 2.1, 2.2, 2.3 ), imath.V3f( 3.1, 3.2, 3.3 )]),
			'test_point3f_Scalar_constant' : IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
			'test_quatd_Array_constant' : IECore.QuatdVectorData([imath.Quatd(1, 0, 0, 0), imath.Quatd(0, 1, 0, 0), imath.Quatd(0, 0, 1, 0)]),
			'test_quatd_Scalar_constant' : IECore.QuatdData(imath.Quatd(0, 0, 0, 1)),
			'test_quatf_Array_constant' : IECore.QuatfVectorData([imath.Quatf(1, 0, 0, 0), imath.Quatf(0, 1, 0, 0), imath.Quatf(0, 0, 1, 0)]),
			'test_quatf_Scalar_constant' : IECore.QuatfData(imath.Quatf(0, 0, 0, 1)),
			'test_vector3d_Array_constant' : IECore.V3dVectorData([imath.V3d( 1.1, 1.2, 1.3 ), imath.V3d( 2.1, 2.2, 2.3 ), imath.V3d( 3.1, 3.2, 3.3 )]),
			'test_vector3d_Scalar_constant' : IECore.V3dData (imath.V3d( 0.1, 0.2, 0.3 )),
			'test_vector3f_Array_constant' : IECore.V3fVectorData([imath.V3f( 1.1, 1.2, 1.3 ), imath.V3f( 2.1, 2.2, 2.3 ), imath.V3f( 3.1, 3.2, 3.3 )]),
			'test_vector3f_Scalar_constant' : IECore.V3fData (imath.V3f( 0.1, 0.2, 0.3 )),
		}


		for primVarName, primVarExpectedValue in expected.items():
			self.assertTrue(primVarName in object.keys())
			p = object[primVarName]
			self.assertEqual(p.data, primVarExpectedValue)
예제 #4
0
파일: testCask.py 프로젝트: tanant/cask
    def test_pod_extent(self):
        filename = os.path.join(TEMPDIR, "cask_pod_extent.abc")

        extent = 5
        v = imath.UnsignedCharArray(extent)
        for i in range(0, extent):
            v[i] = i

        a = cask.Archive()

        # create test properties
        foo = a.top.children["foo"] = cask.Xform()
        bar = foo.properties["bar"] = cask.Property()
        baz = foo.properties["baz"] = cask.Property()
        qux = foo.properties["qux"] = cask.Property()
        quux = foo.properties["quux"] = cask.Property()
        garply = foo.properties["garply"] = cask.Property()
        waldo = foo.properties["waldo"] = cask.Property()
        fred = foo.properties["fred"] = cask.Property()
        color = foo.properties["color"] = cask.Property()
        color.metadata["interpretation"] = "rgb"
        
        # set test values
        v = imath.UnsignedCharArray(5)
        for i in range(0, 5):
            v[i] = i
        bar.set_value(v)
        baz.set_value(["a", "b", "c"])
        qux.set_value(imath.Box3d())
        quux.set_value(imath.M33d())
        garply.set_value(imath.M44d())
        waldo.set_value(1)
        fred.set_value([1, 2, 3, 4])
        color.set_value(imath.Color3f(1, 2, 3))
       
        # export
        a.write_to_file(filename)
        a.close()

        # reimport the test file
        a = cask.Archive(filename)

        # recover the test properties
        foo = a.top.children["foo"]
        bar = foo.properties["bar"]
        baz = foo.properties["baz"]
        qux = foo.properties["qux"]
        quux = foo.properties["quux"]
        garply = foo.properties["garply"]
        waldo = foo.properties["waldo"]
        fred = foo.properties["fred"]
        color = foo.properties["color"]
        
        # assert pod, extent values
        self.assertEqual(bar.extent(), 5)
        self.assertEqual(bar.pod(), alembic.Util.POD.kUint8POD)
        self.assertEqual(bar.values[0], v)
        self.assertEqual(baz.extent(), 1)
        self.assertEqual(baz.pod(), alembic.Util.POD.kStringPOD)
        self.assertEqual(list(baz.values[0]), ["a", "b", "c"])
        self.assertEqual(qux.extent(), 6)
        self.assertEqual(qux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(qux.values[0], imath.Box3d())
        self.assertEqual(quux.extent(), 9)
        self.assertEqual(quux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(quux.values[0], imath.M33d())
        self.assertEqual(garply.extent(), 16)
        self.assertEqual(garply.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(garply.values[0], imath.M44d())
        self.assertEqual(waldo.extent(), 1)
        self.assertEqual(waldo.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(waldo.values[0], 1)
        self.assertEqual(fred.extent(), 1)
        self.assertEqual(fred.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(list(fred.values[0]), [1, 2, 3, 4])
        self.assertEqual(color.extent(), 3)
        self.assertEqual(color.pod(), alembic.Util.POD.kFloat32POD)
        self.assertEqual(color.metadata["interpretation"], "rgb")
        self.assertEqual(color.values[0], imath.Color3f(1, 2, 3))
예제 #5
0
    def testSplineParameters(self):

        s = self.compileShader(
            os.path.dirname(__file__) + "/shaders/splineParameters.osl")
        n = GafferOSL.OSLShader()
        n.loadShader(s)

        self.assertEqual(n["parameters"].keys(),
                         ["floatSpline", "colorSpline"])

        self.assertTrue(
            isinstance(n["parameters"]["floatSpline"], Gaffer.SplineffPlug))
        self.assertEqual(
            n["parameters"]["floatSpline"].getValue().spline(),
            IECore.Splineff(IECore.CubicBasisf.catmullRom(), [
                (0, 0),
                (0, 0),
                (1, 1),
                (1, 1),
            ]))

        self.assertTrue(
            isinstance(n["parameters"]["colorSpline"],
                       Gaffer.SplinefColor3fPlug))
        self.assertEqual(
            n["parameters"]["colorSpline"].getValue().spline(),
            IECore.SplinefColor3f(IECore.CubicBasisf.bSpline(), [
                (0, imath.Color3f(0)),
                (0, imath.Color3f(0)),
                (0, imath.Color3f(0)),
                (1, imath.Color3f(1)),
                (1, imath.Color3f(1)),
                (1, imath.Color3f(1)),
            ]))

        shader = n.attributes()["osl:surface"].outputShader()

        self.assertEqual(
            shader.parameters["floatSpline"].value,
            IECore.Splineff(IECore.CubicBasisf.catmullRom(), [
                (0, 0),
                (0, 0),
                (1, 1),
                (1, 1),
            ]))

        self.assertEqual(
            shader.parameters["colorSpline"].value,
            IECore.SplinefColor3f(IECore.CubicBasisf.bSpline(), [
                (0, imath.Color3f(0)),
                (0, imath.Color3f(0)),
                (0, imath.Color3f(0)),
                (1, imath.Color3f(1)),
                (1, imath.Color3f(1)),
                (1, imath.Color3f(1)),
            ]))
예제 #6
0
    def testContextVariable(self):

        s = self.compileShader(
            os.path.dirname(__file__) + "/shaders/contextVariable.osl")

        # A shader which doesn't read a context variable should
        # have a hash which is constant with respect to that variable.

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(s, "osl:surface", {"name": ""}),
            },
                                      output="output"))

        def hashWithVariable(e, name, value):

            with Gaffer.Context() as c:
                c[name] = value
                h = IECore.MurmurHash()
                e.hash(h)
                return h

        self.assertEqual(hashWithVariable(e, "unused", 0),
                         hashWithVariable(e, "unused", 1))

        # And a shader which does read a context variable needs to reflect
        # that in the hash.

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(s, "osl:surface", {
                    "name": "myVariable",
                    "type": "int"
                }),
            },
                                      output="output"))

        self.assertEqual(hashWithVariable(e, "unrelated", 0),
                         hashWithVariable(e, "unrelated", 1))
        self.assertNotEqual(hashWithVariable(e, "myVariable", 0),
                            hashWithVariable(e, "myVariable", 1))
        self.assertNotEqual(hashWithVariable(e, "myVariable", 1),
                            hashWithVariable(e, "myVariable", 2))
        self.assertEqual(hashWithVariable(e, "myVariable", 0),
                         hashWithVariable(e, "myVariable", 0))

        # And should be able to read the variable from the current context.

        def assertCanReadVariable(e, name, value):

            with Gaffer.Context() as c:
                c[name] = value
                r = e.shade(self.rectanglePoints())
                for c in r["Ci"]:
                    self.assertEqual(c, imath.Color3f(value))

        assertCanReadVariable(e, "myVariable", 0)
        assertCanReadVariable(e, "myVariable", 1)

        # Same goes for variables of other types

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(s, "osl:surface", {
                    "name": "myVariable",
                    "type": "color"
                }),
            },
                                      output="output"))

        assertCanReadVariable(e, "myVariable", imath.Color3f(0, 0.5, 1))
        assertCanReadVariable(e, "myVariable", imath.Color3f(1, 0.5, 0))
예제 #7
0
import Gaffer
import GafferOSL

import GafferUI

scriptWindow = GafferUI.ScriptWindow.acquire(script)

script["OSLCode"] = GafferOSL.OSLCode()
script.selection().add(script["OSLCode"])
oslEditor = GafferUI.NodeEditor.acquire(script["OSLCode"], floating=True)
GafferUI.WidgetAlgo.grab(widget=oslEditor, imagePath="images/blank.png")

script["OSLCode"]["parameters"]["width"] = Gaffer.FloatPlug(defaultValue=0.0)
script["OSLCode"]["parameters"]["width"].setValue(0.025)
script["OSLCode"]["out"]["stripes"] = Gaffer.Color3fPlug(
    direction=Gaffer.Plug.Direction.Out, defaultValue=imath.Color3f(0, 0, 0))
GafferUI.WidgetAlgo.grab(widget=oslEditor, imagePath="images/parameters.png")
oslEditor.parent().setVisible(False)

script["OSLCode"]["code"].setValue(
    "stripes = aastep( 0, sin( v * M_PI / width ) )")
viewer = scriptWindow.getLayout().editors(GafferUI.Viewer)[0]
# delay so it can render
t = time.time() + 3
while time.time() < t:
    GafferUI.EventLoop.waitForIdle(1)
GafferUI.WidgetAlgo.grab(widget=viewer,
                         imagePath="images/shaderBallStripes.png")

script["OSLCode"]["parameters"]["color1"] = Gaffer.Color3fPlug(
    defaultValue=imath.Color3f(0, 0, 0))
예제 #8
0
    def testUniformCs(self):

        fragmentSource = """
		#include "IECoreGL/FragmentShader.h"

		IECOREGL_FRAGMENTSHADER_IN vec3 fragmentCs;

		void main()
		{
			gl_FragColor = vec4( fragmentCs, 1.0 );
		}
		"""

        r = IECoreGL.Renderer()
        r.setOption("gl:mode", IECore.StringData("immediate"))

        r.camera(
            "main", {
                "projection":
                IECore.StringData("orthographic"),
                "resolution":
                IECore.V2iData(imath.V2i(256)),
                "clippingPlanes":
                IECore.V2fData(imath.V2f(1, 1000)),
                "screenWindow":
                IECore.Box2fData(imath.Box2f(imath.V2f(-1), imath.V2f(1)))
            })
        r.display(self.outputFileName, "tif", "rgba", {})

        with IECoreScene.WorldBlock(r):

            r.concatTransform(imath.M44f().translate(imath.V3f(0, 0, -15)))

            r.shader("surface", "test",
                     {"gl:fragmentSource": IECore.StringData(fragmentSource)})

            m = IECoreScene.MeshPrimitive.createPlane(
                imath.Box2f(imath.V2f(-1), imath.V2f(1)), imath.V2i(2))
            m["Cs"] = IECoreScene.PrimitiveVariable(
                IECoreScene.PrimitiveVariable.Interpolation.Uniform,
                IECore.Color3fVectorData([
                    imath.Color3f(1, 0, 0),
                    imath.Color3f(0, 1, 0),
                    imath.Color3f(0, 0, 1),
                    imath.Color3f(
                        1,
                        1,
                        1,
                    ),
                ]))

            m.render(r)

        image = IECore.Reader.create(self.outputFileName).read()
        dimensions = image.dataWindow.size() + imath.V2i(1)
        index = dimensions.x * int(dimensions.y * 0.75) + int(
            dimensions.x * 0.25)
        self.assertEqual(image["R"][index], 1)
        self.assertEqual(image["G"][index], 0)
        self.assertEqual(image["B"][index], 0)

        index = dimensions.x * int(dimensions.y * 0.75) + int(
            dimensions.x * 0.75)
        self.assertEqual(image["R"][index], 0)
        self.assertEqual(image["G"][index], 1)
        self.assertEqual(image["B"][index], 0)

        index = dimensions.x * int(dimensions.y * 0.25) + int(
            dimensions.x * 0.75)
        self.assertEqual(image["R"][index], 1)
        self.assertEqual(image["G"][index], 1)
        self.assertEqual(image["B"][index], 1)

        index = dimensions.x * int(dimensions.y * 0.25) + int(
            dimensions.x * 0.25)
        self.assertEqual(image["R"][index], 0)
        self.assertEqual(image["G"][index], 0)
        self.assertEqual(image["B"][index], 1)
예제 #9
0
    def points(self):
        pData = IECore.V3fVectorData([
            imath.V3f(0, 1, 2),
            imath.V3f(1),
            imath.V3f(2),
            imath.V3f(3),
            imath.V3f(4),
            imath.V3f(5),
            imath.V3f(6),
            imath.V3f(7),
            imath.V3f(8),
            imath.V3f(9),
            imath.V3f(10),
            imath.V3f(11),
        ])

        points = IECoreScene.PointsPrimitive(pData)

        floatData = IECore.FloatData(1.5)
        v2fData = IECore.V2fData(imath.V2f(1.5, 2.5))
        v3fData = IECore.V3fData(imath.V3f(1.5, 2.5, 3.5))
        v3fData = IECore.V3fData(imath.V3f(1.5, 2.5, 3.5))
        color3fData = IECore.Color3fData(imath.Color3f(1.5, 2.5, 3.5))
        intData = IECore.IntData(1)
        v2iData = IECore.V2iData(imath.V2i(1, 2))
        v3iData = IECore.V3iData(imath.V3i(1, 2, 3))
        stringData = IECore.StringData("this is a string")
        m33fData = IECore.M33fData(
            imath.M33f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
        m44fData = IECore.M44fData(
            imath.M44f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
                       12.0, 13.0, 14.0, 15.0, 16.0))

        intRange = range(1, 13)
        floatVectorData = IECore.FloatVectorData([x + 0.5 for x in intRange])
        v2fVectorData = IECore.V2fVectorData(
            [imath.V2f(x, x + 0.5) for x in intRange])
        v3fVectorData = IECore.V3fVectorData(
            [imath.V3f(x, x + 0.5, x + 0.75) for x in intRange])
        color3fVectorData = IECore.Color3fVectorData(
            [imath.Color3f(x, x + 0.5, x + 0.75) for x in intRange])
        quatVectorData = IECore.QuatfVectorData(
            [imath.Quatf(x, x + 0.25, x + 0.5, x + 0.75) for x in intRange])
        intVectorData = IECore.IntVectorData(intRange)
        v2iVectorData = IECore.V2iVectorData(
            [imath.V2i(x, -x) for x in intRange])
        v3iVectorData = IECore.V3iVectorData(
            [imath.V3i(x, -x, x * 2) for x in intRange])
        stringVectorData = IECore.StringVectorData(
            ["string number %06d!" % x for x in intRange])
        m33fVectorData = IECore.M33fVectorData([
            imath.M33f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
            for x in intRange
        ])
        m44fVectorData = IECore.M44fVectorData([
            imath.M44f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
                       12.0, 13.0, 14.0, 15.0, 16.0) for x in intRange
        ])

        detailInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Constant
        uniformInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Uniform
        pointInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Vertex

        # add all valid detail attrib types
        points["floatDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, floatData)
        points["v2fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v2fData)
        points["v3fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v3fData)
        points["color3fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, color3fData)
        points["intDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, intData)
        points["v2iDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v2iData)
        points["v3iDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v3iData)
        points["stringDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, stringData)
        points["m33fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, m33fData)
        points["m44fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, m44fData)

        # add all valid prim attrib types
        points["floatPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, floatVectorData[:1])
        points["v2fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v2fVectorData[:1])
        points["v3fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v3fVectorData[:1])
        points["color3fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, color3fVectorData[:1])
        points["quatPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, quatVectorData[:1])
        points["intPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, intVectorData[:1])
        points["v2iPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v2iVectorData[:1])
        points["v3iPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v3iVectorData[:1])
        points["stringPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, stringVectorData[:1],
            IECore.IntVectorData([0]))
        points["m33fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, m33fVectorData[:1])
        points["m44fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, m44fVectorData[:1])

        # add all valid point attrib types
        points["floatPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, floatVectorData)
        points["v2fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v2fVectorData)
        points["v3fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v3fVectorData)
        points["color3fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, color3fVectorData)
        points["quatPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, quatVectorData)
        points["intPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, intVectorData)
        points["v2iPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v2iVectorData)
        points["v3iPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v3iVectorData)
        points["stringPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, stringVectorData,
            IECore.IntVectorData(range(0, 12)))
        points["m33fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, m33fVectorData)
        points["m44fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, m44fVectorData)

        return points
예제 #10
0
	def testPrimitiveVariableTypes( self ) :

		pointsPrimitive = IECoreScene.PointsPrimitive(
			IECore.V3fVectorData( [ imath.V3f( 0 ) ] )
		)
		pointsPrimitive["vector"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData(
				[ imath.V3f( 1, 2, 3 ) ],
				IECore.GeometricData.Interpretation.Vector
			),
		)
		pointsPrimitive["normal"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData(
				[ imath.V3f( 4, 5, 6 ) ],
				IECore.GeometricData.Interpretation.Normal
			),
		)
		pointsPrimitive["point"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData(
				[ imath.V3f( 4, 5, 6 ) ],
				IECore.GeometricData.Interpretation.Point
			),
		)
		pointsPrimitive["uv"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.V2fVectorData(
				[ imath.V2f( 0, 1 ) ],
				IECore.GeometricData.Interpretation.UV
			),
		)
		pointsPrimitive["Cs"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.Color3fVectorData( [ imath.Color3f( 0, 0, 1 ) ] ),
		)
		pointsPrimitive["float"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.FloatVectorData( [ 0.5 ] ),
		)
		pointsPrimitive["int"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.IntVectorData( [ 10 ] ),
		)

		points = GafferScene.ObjectToScene()
		points["object"].setValue( pointsPrimitive )

		plane = GafferScene.Plane()
		plane["transform"]["translate"]["x"].setValue( 1 )

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

		sampler = GafferScene.ClosestPointSampler()
		sampler["in"].setInput( plane["out"] )
		sampler["source"].setInput( points["out"] )
		sampler["filter"].setInput( planeFilter["out"] )
		sampler["sourceLocation"].setValue( "/object" )
		sampler["primitiveVariables"].setValue( "*" )
		sampler["prefix"].setValue( "sampled:" )

		p = sampler["out"].object( "/plane" )
		for name in pointsPrimitive.keys() :
			primVar = pointsPrimitive[name]
			sampledName = "sampled:" + name
			self.assertIn( sampledName, p )
			sampledPrimVar = p[sampledName]
			self.assertIsInstance( sampledPrimVar.data, primVar.data.__class__ )
			if hasattr( primVar.data, "getInterpretation" ) :
				self.assertEqual( sampledPrimVar.data.getInterpretation(), primVar.data.getInterpretation() )

		self.assertEqual( p["sampled:vector"].data[0], imath.V3f( 1, 2, 3 ) )
		self.assertEqual( p["sampled:normal"].data[0], imath.V3f( 4, 5, 6 ) )
		self.assertEqual( p["sampled:point"].data[0], imath.V3f( 3, 5, 6 ) )
		self.assertEqual( p["sampled:uv"].data[0], imath.V2f( 0, 1 ) )
		self.assertEqual( p["sampled:Cs"].data[0], imath.Color3f( 0, 0, 1 ) )
		self.assertEqual( p["sampled:float"].data[0], 0.5 )
		self.assertEqual( p["sampled:int"].data[0], 10 )
예제 #11
0
	def testDefaultValues( self ) :

		s = Gaffer.ScriptNode()
		s["b"] = Gaffer.Box()
		s["b"]["p"] = Gaffer.IntPlug( defaultValue = 1, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
		s["b"]["p"].setValue( 2 )
		s["b"]["c"] = Gaffer.Color3fPlug( defaultValue = imath.Color3f( 1 ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
		s["b"]["c"].setValue( imath.Color3f( 0.5 ) )
		s["b"].exportForReference( self.temporaryDirectory() + "/test.grf" )

		s["r"] = Gaffer.Reference()
		s["r"].load( self.temporaryDirectory() + "/test.grf" )

		# The value at the time of box export should become
		# the default value on the reference node. But the
		# default value on the box itself should remain the
		# same.

		self.assertEqual( s["r"]["p"].getValue(), 2 )
		self.assertEqual( s["r"]["p"].defaultValue(), 2 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 0.5 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.5 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And we should be able to save and reload the script
		# and have that still be the case.

		s["fileName"].setValue( self.temporaryDirectory() + "/test.gfr" )
		s.save()
		s.load()

		self.assertEqual( s["r"]["p"].getValue(), 2 )
		self.assertEqual( s["r"]["p"].defaultValue(), 2 )
		self.assertEqual( s["b"]["p"].getValue(), 2 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 0.5 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.5 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 0.5 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# If we change the value on the box and reexport,
		# then the reference should pick up both the new value
		# and the new default.

		s["b"]["p"].setValue( 3 )
		s["b"]["c"].setValue( imath.Color3f( 0.25 ) )
		s["b"].exportForReference( self.temporaryDirectory() + "/test.grf" )
		s["r"].load( self.temporaryDirectory() + "/test.grf" )

		self.assertEqual( s["r"]["p"].getValue(), 3 )
		self.assertEqual( s["r"]["p"].defaultValue(), 3 )
		self.assertEqual( s["b"]["p"].getValue(), 3 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And that should still hold after saving and reloading the script.

		s.save()
		s.load()
		self.assertEqual( s["r"]["p"].getValue(), 3 )
		self.assertEqual( s["r"]["p"].defaultValue(), 3 )
		self.assertEqual( s["b"]["p"].getValue(), 3 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# But if the user changes the value on the reference node,
		# it should be kept.

		s["r"]["p"].setValue( 100 )
		s["r"]["c"].setValue( imath.Color3f( 100 ) )

		self.assertEqual( s["r"]["p"].getValue(), 100 )
		self.assertEqual( s["r"]["p"].defaultValue(), 3 )
		self.assertEqual( s["b"]["p"].getValue(), 3 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 100 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And a save and load shouldn't change that.

		s.save()
		s.load()

		self.assertEqual( s["r"]["p"].getValue(), 100 )
		self.assertEqual( s["r"]["p"].defaultValue(), 3 )
		self.assertEqual( s["b"]["p"].getValue(), 3 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 100 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 0.25 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And now the user has changed a value, only the
		# default value should be updated if we load a new
		# reference.

		s["b"]["p"].setValue( 4 )
		s["b"]["c"].setValue( imath.Color3f( 4 ) )
		s["b"].exportForReference( self.temporaryDirectory() + "/test.grf" )
		s["r"].load( self.temporaryDirectory() + "/test.grf" )

		self.assertEqual( s["r"]["p"].getValue(), 100 )
		self.assertEqual( s["r"]["p"].defaultValue(), 4 )
		self.assertEqual( s["b"]["p"].getValue(), 4 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 100 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 4 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 4 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And a save and load shouldn't change anything.

		s.save()
		s.load()

		self.assertEqual( s["r"]["p"].getValue(), 100 )
		self.assertEqual( s["r"]["p"].defaultValue(), 4 )
		self.assertEqual( s["b"]["p"].getValue(), 4 )
		self.assertEqual( s["b"]["p"].defaultValue(), 1 )

		self.assertEqual( s["r"]["c"].getValue(), imath.Color3f( 100 ) )
		self.assertEqual( s["r"]["c"].defaultValue(), imath.Color3f( 4 ) )
		self.assertEqual( s["b"]["c"].getValue(), imath.Color3f( 4 ) )
		self.assertEqual( s["b"]["c"].defaultValue(), imath.Color3f( 1 ) )

		# And since we know that all plugs in box exports
		# have had their default values set to the current
		# value, there shouldn't be any need for a single
		# setValue() call in the exported file.

		e = "".join( file( self.temporaryDirectory() + "/test.grf" ).readlines() )
		self.assertTrue( "setValue" not in e )
예제 #12
0
	def testPrimitiveVariables( self ) :

		s = IECoreScene.SpherePrimitive()
		s["v"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, imath.V3f( 1, 2, 3 ) )
		s["c"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, imath.Color3f( 1, 2, 3 ) )
		s["s"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, "test" )
		s["i"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, 11 )
		s["b"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, True )
		s["f"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, 2.5 )
		s["m"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, imath.M44f( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) )

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = IECoreArnold.NodeAlgo.convert( s, "testSphere" )
			self.assertEqual( arnold.AiNodeGetVec( n, "v" ), arnold.AtVector( 1, 2, 3 ) )
			self.assertEqual( arnold.AiNodeGetRGB( n, "c" ), arnold.AtRGB( 1, 2, 3 ) )
			self.assertEqual( arnold.AiNodeGetStr( n, "s" ), "test" )
			self.assertEqual( arnold.AiNodeGetInt( n, "i" ), 11 )
			self.assertEqual( arnold.AiNodeGetBool( n, "b" ), True )
			self.assertEqual( arnold.AiNodeGetFlt( n, "f" ), 2.5 )

			m = arnold.AiNodeGetMatrix( n, "m" )
			self.assertEqual(
				[ list( i ) for i in m.data ],
				[ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ],
			)
예제 #13
0
파일: ocio.py 프로젝트: wubugui/gaffer
    def f(c):

        cc = processor.applyRGB([c.r, c.g, c.b])
        return imath.Color3f(*cc)
예제 #14
0
    def testAttributes(self):

        points = IECoreScene.PointsPrimitive(
            IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 2)]))
        points["testFloat"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.FloatVectorData([0, 1]),
        )
        points["testColor"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.Color3fVectorData(
                [imath.Color3f(1, 0, 0),
                 imath.Color3f(0, 1, 0)]),
        )
        points["testPoint"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData(
                [imath.V3f(0, 0, 0), imath.V3f(1, 1, 1)],
                IECore.GeometricData.Interpretation.Point),
        )

        objectToScene = GafferScene.ObjectToScene()
        objectToScene["object"].setValue(points)

        sphere = GafferScene.Sphere()

        instancer = GafferScene.Instancer()
        instancer["in"].setInput(objectToScene["out"])
        instancer["prototypes"].setInput(sphere["out"])
        instancer["parent"].setValue("/object")

        self.assertEqual(instancer["out"].attributes("/object/instances"),
                         IECore.CompoundObject())

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere"),
            IECore.CompoundObject())

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/0"),
            IECore.CompoundObject())

        instancer["attributes"].setValue("testFloat testColor testPoint")

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/0"),
            IECore.CompoundObject({
                "testFloat":
                IECore.FloatData(0.0),
                "testColor":
                IECore.Color3fData(imath.Color3f(1, 0, 0)),
                "testPoint":
                IECore.V3fData(imath.V3f(0),
                               IECore.GeometricData.Interpretation.Point)
            }))

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/1"),
            IECore.CompoundObject({
                "testFloat":
                IECore.FloatData(1.0),
                "testColor":
                IECore.Color3fData(imath.Color3f(0, 1, 0)),
                "testPoint":
                IECore.V3fData(imath.V3f(1),
                               IECore.GeometricData.Interpretation.Point)
            }))

        instancer["attributePrefix"].setValue("user:"******"out"].attributes("/object/instances/sphere/0"),
            IECore.CompoundObject({
                "user:testFloat":
                IECore.FloatData(0.0),
                "user:testColor":
                IECore.Color3fData(imath.Color3f(1, 0, 0)),
                "user:testPoint":
                IECore.V3fData(imath.V3f(0),
                               IECore.GeometricData.Interpretation.Point)
            }))

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/1"),
            IECore.CompoundObject({
                "user:testFloat":
                IECore.FloatData(1.0),
                "user:testColor":
                IECore.Color3fData(imath.Color3f(0, 1, 0)),
                "user:testPoint":
                IECore.V3fData(imath.V3f(1),
                               IECore.GeometricData.Interpretation.Point)
            }))

        instancer["attributePrefix"].setValue("foo:")

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/0"),
            IECore.CompoundObject({
                "foo:testFloat":
                IECore.FloatData(0.0),
                "foo:testColor":
                IECore.Color3fData(imath.Color3f(1, 0, 0)),
                "foo:testPoint":
                IECore.V3fData(imath.V3f(0),
                               IECore.GeometricData.Interpretation.Point)
            }))

        self.assertEqual(
            instancer["out"].attributes("/object/instances/sphere/1"),
            IECore.CompoundObject({
                "foo:testFloat":
                IECore.FloatData(1.0),
                "foo:testColor":
                IECore.Color3fData(imath.Color3f(0, 1, 0)),
                "foo:testPoint":
                IECore.V3fData(imath.V3f(1),
                               IECore.GeometricData.Interpretation.Point)
            }))
예제 #15
0
			def assertIndex( index ) :

				network = l.attributes()["ai:surface"]
				self.assertEqual( len( network ), 2 )
				self.assertEqual( network[0].parameters["color"].value, imath.Color3f( index ) )
예제 #16
0
	def curves( self, basis=IECore.CubicBasisf.linear(), periodic=False, numCurves=4 ) :
		vertsPerCurve = IECore.IntVectorData()
		pData = IECore.V3fVectorData()
		pData.setInterpretation( IECore.GeometricData.Interpretation.Point )

		for i in range( 0, numCurves ) :
			p = TestToHoudiniCurvesConverter.__curveCoordinates[i%4]

			if not periodic and basis == IECore.CubicBasisf.bSpline() :
				vertsPerCurve.append( len(p) + 4 )
			else :
				vertsPerCurve.append( len(p) )

			pData.extend( p )

		curves = IECoreScene.CurvesPrimitive( vertsPerCurve, basis, periodic )

		floatData = IECore.FloatData( 1.5 )
		v2fData = IECore.V2fData( imath.V2f( 1.5, 2.5 ) )
		v3fData = IECore.V3fData( imath.V3f( 1.5, 2.5, 3.5 ) )
		color3fData = IECore.Color3fData( imath.Color3f( 1.5, 2.5, 3.5 ) )
		intData = IECore.IntData( 1 )
		v2iData = IECore.V2iData( imath.V2i( 1, 2 ) )
		v3iData = IECore.V3iData( imath.V3i( 1, 2, 3 ) )
		stringData = IECore.StringData( "this is a string" )

		intRange = range( 1, pData.size()+1 )
		floatVectorData = IECore.FloatVectorData( [ x+0.5 for x in intRange ] )
		v2fVectorData = IECore.V2fVectorData( [ imath.V2f( x, x+0.5 ) for x in intRange ] )
		v3fVectorData = IECore.V3fVectorData( [ imath.V3f( x, x+0.5, x+0.75 ) for x in intRange ] )
		color3fVectorData = IECore.Color3fVectorData( [ imath.Color3f( x, x+0.5, x+0.75 ) for x in intRange ] )
		intVectorData = IECore.IntVectorData( intRange )
		v2iVectorData = IECore.V2iVectorData( [ imath.V2i( x, -x ) for x in intRange ] )
		v3iVectorData = IECore.V3iVectorData( [ imath.V3i( x, -x, x*2 ) for x in intRange ] )
		stringVectorData = IECore.StringVectorData( [ "string number %06d!" % x for x in intRange ] )

		detailInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Constant
		pointInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Vertex
		primitiveInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Uniform

		# add all valid detail attrib types
		curves["floatDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, floatData )
		curves["v2fDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, v2fData )
		curves["v3fDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, v3fData )
		curves["color3fDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, color3fData )
		curves["intDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, intData )
		curves["v2iDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, v2iData )
		curves["v3iDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, v3iData )
		curves["stringDetail"] = IECoreScene.PrimitiveVariable( detailInterpolation, stringData )

		# add all valid point attrib types
		if not periodic and basis == IECore.CubicBasisf.bSpline() :

			modPData = IECore.V3fVectorData()
			modPData.setInterpretation( IECore.GeometricData.Interpretation.Point )
			floatPointData = IECore.FloatVectorData()
			v2fPointData = IECore.V2fVectorData()
			v3fPointData = IECore.V3fVectorData()
			color3fPointData = IECore.Color3fVectorData()
			intPointData = IECore.IntVectorData()
			v2iPointData = IECore.V2iVectorData()
			v3iPointData = IECore.V3iVectorData()
			stringPointData = IECore.StringVectorData()

			datas = [ modPData, floatPointData, v2fPointData, v3fPointData, color3fPointData, intPointData, v2iPointData, v3iPointData, stringPointData ]
			rawDatas = [ pData, floatVectorData, v2fVectorData, v3fVectorData, color3fVectorData, intVectorData, v2iVectorData, v3iVectorData, stringVectorData ]

			pIndex = 0
			for i in range( 0, numCurves ) :
				for j in range( 0, len(datas) ) :
					index = 8*i
					datas[j].extend( [ rawDatas[j][index], rawDatas[j][index] ] )
					datas[j].extend( rawDatas[j][index:index+8] )
					datas[j].extend( [ rawDatas[j][index+7], rawDatas[j][index+7] ] )

			curves["P"] = IECoreScene.PrimitiveVariable( pointInterpolation, modPData )
			curves["floatPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, floatPointData )
			curves["v2fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation,v2fPointData )
			curves["v3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3fPointData )
			curves["color3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, color3fPointData )
			curves["intPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, intPointData )
			curves["v2iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2iPointData )
			curves["v3iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3iPointData )
		else :
			curves["P"] = IECoreScene.PrimitiveVariable( pointInterpolation, pData )
			curves["floatPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, floatVectorData[:8*numCurves] )
			curves["v2fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2fVectorData[:8*numCurves] )
			curves["v3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3fVectorData[:8*numCurves] )
			curves["color3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, color3fVectorData[:8*numCurves] )
			curves["intPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, intVectorData[:8*numCurves] )
			curves["v2iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2iVectorData[:8*numCurves] )
			curves["v3iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3iVectorData[:8*numCurves] )
			curves["stringPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, stringVectorData[:8*numCurves], IECore.IntVectorData( range( 0, 8*numCurves ) ) )

		# add all valid primitive attrib types
		curves["floatPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, floatVectorData[:numCurves] )
		curves["v2fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2fVectorData[:numCurves] )
		curves["v3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3fVectorData[:numCurves] )
		curves["color3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, color3fVectorData[:numCurves] )
		curves["intPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, intVectorData[:numCurves] )
		curves["v2iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2iVectorData[:numCurves] )
		curves["v3iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3iVectorData[:numCurves] )
		curves["stringPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, stringVectorData[:numCurves], IECore.IntVectorData( range( 0, numCurves ) ) )

		self.assertTrue( curves.arePrimitiveVariablesValid() )

		return curves
예제 #17
0
    def testUserDataViaGetAttribute(self):

        shader = self.compileShader(
            os.path.dirname(__file__) + "/shaders/attribute.osl")

        rp = self.rectanglePoints()

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(shader, "osl:surface",
                                   {"name": "floatUserData"}),
            },
                                      output="output"))

        self.assertEqual(e.needsAttribute("floatUserData"), True)
        self.assertEqual(e.needsAttribute("doubleUserData"), False)
        self.assertEqual(e.needsAttribute("colorUserData"), False)
        self.assertEqual(e.needsAttribute("shading:index"), False)

        p = e.shade(rp)

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(shader, "osl:surface",
                                   {"name": "doubleUserData"}),
            },
                                      output="output"))

        self.assertEqual(e.needsAttribute("floatUserData"), False)
        self.assertEqual(e.needsAttribute("doubleUserData"), True)
        self.assertEqual(e.needsAttribute("colorUserData"), False)
        self.assertEqual(e.needsAttribute("shading:index"), False)

        p = e.shade(rp)

        for i, c in enumerate(p["Ci"]):
            self.assertEqual(c[0], float(i))

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(shader, "osl:surface",
                                   {"name": "colorUserData"}),
            },
                                      output="output"))

        self.assertEqual(e.needsAttribute("floatUserData"), False)
        self.assertEqual(e.needsAttribute("doubleUserData"), False)
        self.assertEqual(e.needsAttribute("colorUserData"), True)
        self.assertEqual(e.needsAttribute("shading:index"), False)

        p = e.shade(rp)

        for i, c in enumerate(p["Ci"]):
            self.assertEqual(c, rp["colorUserData"][i])

        e = GafferOSL.ShadingEngine(
            IECoreScene.ShaderNetwork(shaders={
                "output":
                IECoreScene.Shader(shader, "osl:surface",
                                   {"name": "shading:index"}),
            },
                                      output="output"))

        self.assertEqual(e.needsAttribute("floatUserData"), False)
        self.assertEqual(e.needsAttribute("doubleUserData"), False)
        self.assertEqual(e.needsAttribute("colorUserData"), False)
        self.assertEqual(e.needsAttribute("shading:index"), True)

        p = e.shade(rp)

        for i, c in enumerate(p["Ci"]):
            self.assertEqual(c, imath.Color3f(i))
예제 #18
0
import imath

import Gaffer
import GafferArnold

print("LDTGAFFER:startup:Gaffer:defaults")

# Nodes Defaults Values
Gaffer.Metadata.registerValue("gl:surface:Phong:Cs", "userDefault",
                              imath.Color3f(1.0, 1.0, 1.0))
# Nodes Defaults Values
Gaffer.Metadata.registerValue("gl:surface:Phong:transparency", "userDefault",
                              1.0)
예제 #19
0
    def testRegionSelect(self):

        r = IECoreGL.Renderer()
        r.setOption("gl:mode", IECore.StringData("deferred"))
        r.setOption("gl:searchPath:shader",
                    IECore.StringData(os.path.dirname(__file__) + "/shaders"))

        with IECoreScene.WorldBlock(r):

            r.concatTransform(imath.M44f().translate(imath.V3f(0, 0, -5)))

            r.shader(
                "surface", "color",
                {"colorValue": IECore.Color3fData(imath.Color3f(1, 0, 0))})
            r.concatTransform(imath.M44f().translate(imath.V3f(-2, -2, 0)))
            r.setAttribute("name", IECore.StringData("red"))
            r.sphere(1, -1, 1, 360, {})

            r.shader(
                "surface", "color",
                {"colorValue": IECore.Color3fData(imath.Color3f(0, 1, 0))})
            r.concatTransform(imath.M44f().translate(imath.V3f(0, 4, 0)))
            r.setAttribute("name", IECore.StringData("green"))
            r.sphere(1, -1, 1, 360, {})

            r.shader(
                "surface", "color",
                {"colorValue": IECore.Color3fData(imath.Color3f(0, 0, 1))})
            r.concatTransform(imath.M44f().translate(imath.V3f(4, 0, 0)))
            r.setAttribute("name", IECore.StringData("blue"))
            r.sphere(1, -1, 1, 360, {})

            r.shader(
                "surface", "color",
                {"colorValue": IECore.Color3fData(imath.Color3f(1, 1, 1))})
            r.concatTransform(imath.M44f().translate(imath.V3f(0, -4, 0)))
            r.setAttribute("name", IECore.StringData("white"))
            r.sphere(1, -1, 1, 360, {})

        s = r.scene()
        s.setCamera(IECoreGL.Camera(imath.M44f(), False))

        ss = s.select(IECoreGL.Selector.Mode.GLSelect,
                      imath.Box2f(imath.V2f(0, 0.5), imath.V2f(0.5, 1)))
        self.assertEqual(len(ss), 1)
        self.assertEqual(
            IECoreGL.NameStateComponent.nameFromGLName(ss[0].name), "red")

        ss = s.select(IECoreGL.Selector.Mode.GLSelect,
                      imath.Box2f(imath.V2f(0), imath.V2f(0.5)))
        self.assertEqual(len(ss), 1)
        self.assertEqual(
            IECoreGL.NameStateComponent.nameFromGLName(ss[0].name), "green")

        ss = s.select(IECoreGL.Selector.Mode.GLSelect,
                      imath.Box2f(imath.V2f(0.5, 0), imath.V2f(1, 0.5)))
        self.assertEqual(len(ss), 1)
        self.assertEqual(
            IECoreGL.NameStateComponent.nameFromGLName(ss[0].name), "blue")

        ss = s.select(IECoreGL.Selector.Mode.GLSelect,
                      imath.Box2f(imath.V2f(0.5), imath.V2f(1)))
        self.assertEqual(len(ss), 1)
        self.assertEqual(
            IECoreGL.NameStateComponent.nameFromGLName(ss[0].name), "white")
예제 #20
0
    def testContextChangedAndGIL(self):

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()
        script["plane"]["divisions"].setValue(imath.V2i(20))

        script["sphere"] = GafferScene.Sphere()

        script["expression"] = Gaffer.Expression()
        script["expression"].setExpression(
            "parent['sphere']['radius'] = context.get( 'minRadius', 0.1 ) + context.getFrame() + float( context['instancer:id'] )"
        )

        script["instancer"] = GafferScene.Instancer()
        script["instancer"]["in"].setInput(script["plane"]["out"])
        script["instancer"]["instance"].setInput(script["sphere"]["out"])
        script["instancer"]["parent"].setValue("/plane")

        context = Gaffer.Context()
        traverseConnection = Gaffer.ScopedConnection(
            GafferSceneTest.connectTraverseSceneToContextChangedSignal(
                script["instancer"]["out"], context))
        with context:

            context.setFrame(10)
            context.setFramesPerSecond(50)
            context.setTime(1)

            context.set("a", 1)
            context.set("a", 2.0)
            context.set("a", "a")
            context.set("a", imath.V2i())
            context.set("a", imath.V3i())
            context.set("a", imath.V2f())
            context.set("a", imath.V3f())
            context.set("a", imath.Color3f())
            context.set("a", IECore.BoolData(True))

            context["b"] = 1
            context["b"] = 2.0
            context["b"] = "b"
            context["b"] = imath.V2i()
            context["b"] = imath.V3i()
            context["b"] = imath.V2f()
            context["b"] = imath.V3f()
            context["b"] = imath.Color3f()
            context["b"] = IECore.BoolData(True)

            with Gaffer.BlockedConnection(traverseConnection):
                # Must add it with the connection disabled, otherwise
                # the addition causes a traversal, and then remove() gets
                # all its results from the cache.
                context["minRadius"] = 0.2

            context.remove("minRadius")

            with Gaffer.BlockedConnection(traverseConnection):
                context["minRadius"] = 0.3

            del context["minRadius"]
예제 #21
0
	def __addMenuDefinition( self ) :

		result = IECore.MenuDefinition()
		result.append( "/Add/Bool", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.BoolData( False ) ) } )
		result.append( "/Add/Float", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.FloatData( 0 ) ) } )
		result.append( "/Add/Int", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.IntData( 0 ) ) } )
		result.append( "/Add/NumericDivider", { "divider" : True } )

		result.append( "/Add/String", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.StringData( "" ) ) } )
		result.append( "/Add/StringDivider", { "divider" : True } )

		result.append( "/Add/V2i/Vector", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2iData( imath.V2i( 0 ), IECore.GeometricData.Interpretation.Vector ) ) } )
		result.append( "/Add/V2i/Normal", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2iData( imath.V2i( 0 ), IECore.GeometricData.Interpretation.Normal ) ) } )
		result.append( "/Add/V2i/Point", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2iData( imath.V2i( 0 ), IECore.GeometricData.Interpretation.Point ) ) } )

		result.append( "/Add/V3i/Vector", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3iData( imath.V3i( 0 ), IECore.GeometricData.Interpretation.Vector ) ) } )
		result.append( "/Add/V3i/Normal", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3iData( imath.V3i( 0 ), IECore.GeometricData.Interpretation.Normal ) ) } )
		result.append( "/Add/V3i/Point", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3iData( imath.V3i( 0 ), IECore.GeometricData.Interpretation.Point ) ) } )

		result.append( "/Add/V2f/Vector", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2fData( imath.V2f( 0 ), IECore.GeometricData.Interpretation.Vector ) ) } )
		result.append( "/Add/V2f/Normal", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2fData( imath.V2f( 0 ), IECore.GeometricData.Interpretation.Normal ) ) } )
		result.append( "/Add/V2f/Point", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V2fData( imath.V2f( 0 ), IECore.GeometricData.Interpretation.Point ) ) } )

		result.append( "/Add/V3f/Vector", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Vector ) ) } )
		result.append( "/Add/V3f/Normal", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Normal ) ) } )
		result.append( "/Add/V3f/Point", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Point ) ) } )

		result.append( "/Add/VectorDivider", { "divider" : True } )

		result.append( "/Add/Color3f", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Color3fData( imath.Color3f( 0 ) ) ) } )
		result.append( "/Add/Color4f", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Color4fData( imath.Color4f( 0, 0, 0, 1 ) ) ) } )

		result.append( "/Add/BoxDivider", { "divider" : True } )

		result.append( "/Add/Box2i", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Box2iData( imath.Box2i( imath.V2i( 0 ), imath.V2i( 1 ) ) ) ) } )
		result.append( "/Add/Box2f", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Box2fData( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) ) } )
		result.append( "/Add/Box3i", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Box3iData( imath.Box3i( imath.V3i( 0 ), imath.V3i( 1 ) ) ) ) } )
		result.append( "/Add/Box3f", { "command" : functools.partial( Gaffer.WeakMethod( self.__addItem ), "", IECore.Box3fData( imath.Box3f( imath.V3f( 0 ), imath.V3f( 1 ) ) ) ) } )

		result.append( "/Add/BoxDivider", { "divider" : True } )

		for label, plugType in [
			( "Float", Gaffer.FloatVectorDataPlug ),
			( "Int", Gaffer.IntVectorDataPlug),
			( "NumericDivider", None ),
			( "String", Gaffer.StringVectorDataPlug ),
		] :
			if plugType is not None :
				result.append( "/Add/Array/" + label, {"command" : IECore.curry( Gaffer.WeakMethod( self.__addItem ), "", plugType.ValueType() ) } )
			else :
				result.append( "/Add/Array/" + label, { "divider" : True } )

		return result
예제 #22
0
#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import IECore
import Gaffer
import GafferUI

import GafferOSL

import imath
import functools

_channelNamesOptions = {
    "RGB": IECore.Color3fData(imath.Color3f(1)),
    "RGBA": IECore.Color4fData(imath.Color4f(1)),
    "R": IECore.FloatData(1),
    "G": IECore.FloatData(1),
    "B": IECore.FloatData(1),
    "A": IECore.FloatData(1),
    "customChannel": IECore.FloatData(1),
    "customLayer": IECore.Color3fData(imath.Color3f(1)),
    "customLayerRGBA": IECore.Color4fData(imath.Color4f(1)),
    "closure": None,
}

##########################################################################
# _ChannelsFooter
##########################################################################
예제 #23
0
    def testReload(self):

        s1 = self.compileShader(
            os.path.dirname(__file__) + "/shaders/version1.osl")
        s2 = self.compileShader(
            os.path.dirname(__file__) + "/shaders/version2.osl")

        n = GafferOSL.OSLShader()
        n.loadShader(s1)

        self.assertEqual(n["parameters"].keys(), [
            "commonI",
            "commonF",
            "commonColor",
            "commonString",
            "commonStruct",
            "commonArray",
            "removedI",
            "removedF",
            "removedColor",
            "removedString",
            "removedStruct",
            "typeChanged1",
            "typeChanged2",
            "typeChanged3",
            "typeChanged4",
            "typeChanged5",
            "defaultChangedArray",
        ])

        self.assertEqual(n["parameters"]["commonStruct"].keys(), [
            "commonI",
            "commonF",
            "commonColor",
            "commonString",
            "removedI",
            "removedF",
            "removedColor",
            "removedString",
            "typeChanged1",
            "typeChanged2",
            "typeChanged3",
            "typeChanged4",
        ])

        values = {
            "commonI": 10,
            "commonF": 25,
            "commonColor": imath.Color3f(1),
            "commonString": "test",
            "commonStruct.commonI": 11,
            "commonStruct.commonF": 2.5,
            "commonStruct.commonColor": imath.Color3f(0.5),
            "commonStruct.commonString": "test2",
            "commonArray": IECore.FloatVectorData([0, 1, 2])
        }

        for key, value in values.items():
            n["parameters"].descendant(key).setValue(value)

        arrayToNotGetReloaded = n["parameters"]["commonArray"]
        arrayToGetReloaded = n["parameters"]["defaultChangedArray"]

        self.assertTrue(
            isinstance(n["parameters"]["typeChanged1"], Gaffer.IntPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged2"], Gaffer.FloatPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged3"], Gaffer.Color3fPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged4"], Gaffer.StringPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged5"], Gaffer.V3fPlug))
        self.assertTrue(n["parameters"]["typeChanged5"].interpretation(),
                        IECore.GeometricData.Interpretation.Vector)

        n.loadShader(s2, keepExistingValues=True)

        self.assertEqual(n["parameters"].keys(), [
            "commonI",
            "commonF",
            "commonColor",
            "commonString",
            "commonStruct",
            "commonArray",
            "typeChanged1",
            "typeChanged2",
            "typeChanged3",
            "typeChanged4",
            "typeChanged5",
            "addedI",
            "addedF",
            "addedColor",
            "addedString",
            "addedStruct",
            "defaultChangedArray",
        ])

        self.assertEqual(n["parameters"]["commonStruct"].keys(), [
            "commonI",
            "commonF",
            "commonColor",
            "commonString",
            "typeChanged1",
            "typeChanged2",
            "typeChanged3",
            "typeChanged4",
            "addedI",
            "addedF",
            "addedColor",
            "addedString",
        ])

        self.assertEqual(arrayToNotGetReloaded, n["parameters"]["commonArray"])
        self.assertNotEqual(arrayToGetReloaded,
                            n["parameters"]["defaultChangedArray"])

        for key, value in values.items():
            self.assertEqual(n["parameters"].descendant(key).getValue(), value)

        self.assertTrue(
            isinstance(n["parameters"]["typeChanged1"], Gaffer.StringPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged2"], Gaffer.Color3fPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged3"], Gaffer.FloatPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged4"], Gaffer.IntPlug))
        self.assertTrue(
            isinstance(n["parameters"]["typeChanged5"], Gaffer.V3fPlug))
        self.assertEqual(n["parameters"]["typeChanged5"].interpretation(),
                         IECore.GeometricData.Interpretation.Normal)

        n.loadShader(s2, keepExistingValues=False)
        for plug in n["parameters"]:
            if isinstance(plug, Gaffer.ValuePlug):
                self.assertTrue(plug.isSetToDefault())
예제 #24
0
    def testTransform(self):

        p = GafferScene.Plane()
        p["transform"]["translate"].setValue(imath.V3f(2, 0, 0))

        o = GafferOSL.OSLObject()
        o["in"].setInput(p["out"])

        # shading network to swap x and y

        inPoint = GafferOSL.OSLShader()
        inPoint.loadShader("ObjectProcessing/InPoint")

        code = GafferOSL.OSLCode()
        code["parameters"].addChild(Gaffer.V3fPlug("in"))
        code["out"].addChild(
            Gaffer.Color3fPlug("transformed",
                               direction=Gaffer.Plug.Direction.Out))
        code["out"].addChild(
            Gaffer.Color3fPlug("transformedBack",
                               direction=Gaffer.Plug.Direction.Out))
        code["code"].setValue(
            'transformed = transform( "world", point( in ) );\ntransformedBack = transform( "world", "object", point( transformed ) );'
        )

        code["parameters"]["in"].setInput(inPoint["out"]["value"])

        outTransformed = GafferOSL.OSLShader()
        outTransformed.loadShader("ObjectProcessing/OutColor")
        outTransformed["parameters"]["name"].setValue('transformed')
        outTransformed["parameters"]["value"].setInput(
            code["out"]["transformed"])

        outTransformedBack = GafferOSL.OSLShader()
        outTransformedBack.loadShader("ObjectProcessing/OutColor")
        outTransformedBack["parameters"]["name"].setValue('transformedBack')
        outTransformedBack["parameters"]["value"].setInput(
            code["out"]["transformedBack"])

        primVarShader = GafferOSL.OSLShader()
        primVarShader.loadShader("ObjectProcessing/OutObject")
        primVarShader["parameters"]["in0"].setInput(
            outTransformed["out"]["primitiveVariable"])
        primVarShader["parameters"]["in1"].setInput(
            outTransformedBack["out"]["primitiveVariable"])

        o["shader"].setInput(primVarShader["out"])

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

        o["filter"].setInput(filter["out"])

        self.assertEqual(
            o["out"].object("/plane")["transformed"].data,
            IECore.Color3fVectorData([
                imath.Color3f(1.5, -0.5, 0),
                imath.Color3f(2.5, -0.5, 0),
                imath.Color3f(1.5, 0.5, 0),
                imath.Color3f(2.5, 0.5, 0)
            ]))
        self.assertEqual(
            o["out"].object("/plane")["transformedBack"].data,
            IECore.Color3fVectorData([
                imath.Color3f(-0.5, -0.5, 0),
                imath.Color3f(0.5, -0.5, 0),
                imath.Color3f(-0.5, 0.5, 0),
                imath.Color3f(0.5, 0.5, 0)
            ]))
예제 #25
0
    def testArrays(self):

        s = self.compileShader(
            os.path.dirname(__file__) + "/shaders/arrays.osl")

        n = GafferOSL.OSLShader()
        n.loadShader(s)

        self.assertEqual(n["parameters"].keys(),
                         ["i", "f", "c", "p", "q", "s", "m"])

        self.assertTrue(
            isinstance(n["parameters"]["i"], Gaffer.IntVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["f"], Gaffer.FloatVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["c"], Gaffer.Color3fVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["p"], Gaffer.V3fVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["q"], Gaffer.V3fVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["s"], Gaffer.StringVectorDataPlug))
        self.assertTrue(
            isinstance(n["parameters"]["m"], Gaffer.M44fVectorDataPlug))

        self.assertEqual(n["parameters"]["i"].defaultValue(),
                         IECore.IntVectorData([10, 11, 12]))
        self.assertEqual(n["parameters"]["f"].defaultValue(),
                         IECore.FloatVectorData([1, 2]))
        self.assertEqual(
            n["parameters"]["c"].defaultValue(),
            IECore.Color3fVectorData(
                [imath.Color3f(1, 2, 3),
                 imath.Color3f(4, 5, 6)]))
        self.assertEqual(
            n["parameters"]["p"].defaultValue(),
            IECore.V3fVectorData([imath.V3f(1, 2, 3),
                                  imath.V3f(4, 5, 6)]))
        self.assertEqual(
            n["parameters"]["q"].defaultValue(),
            IECore.V3fVectorData([imath.V3f(1, 2, 3),
                                  imath.V3f(4, 5, 6)]))
        self.assertEqual(n["parameters"]["s"].defaultValue(),
                         IECore.StringVectorData(["s", "t", "u", "v", "word"]))
        self.assertEqual(
            n["parameters"]["m"].defaultValue(),
            IECore.M44fVectorData(
                [imath.M44f() * 1,
                 imath.M44f() * 0,
                 imath.M44f() * 1]))

        self.assertEqual(n["out"].typeId(), Gaffer.Plug.staticTypeId())

        network = n.attributes()["osl:surface"]
        self.assertEqual(len(network), 1)
        self.assertEqual(network.outputShader().name, s)
        self.assertEqual(network.outputShader().type, "osl:surface")
        self.assertEqual(network.outputShader().parameters["i"],
                         IECore.IntVectorData([10, 11, 12]))
        self.assertEqual(network.outputShader().parameters["f"],
                         IECore.FloatVectorData([1, 2]))
        self.assertEqual(
            network.outputShader().parameters["c"],
            IECore.Color3fVectorData(
                [imath.Color3f(1, 2, 3),
                 imath.Color3f(4, 5, 6)]))
        self.assertEqual(
            network.outputShader().parameters["p"],
            IECore.V3fVectorData([imath.V3f(1, 2, 3),
                                  imath.V3f(4, 5, 6)]))
        self.assertEqual(
            network.outputShader().parameters["q"],
            IECore.V3fVectorData([imath.V3f(1, 2, 3),
                                  imath.V3f(4, 5, 6)]))
        self.assertEqual(network.outputShader().parameters["s"],
                         IECore.StringVectorData(["s", "t", "u", "v", "word"]))
        self.assertEqual(
            network.outputShader().parameters["m"],
            IECore.M44fVectorData(
                [imath.M44f() * 1,
                 imath.M44f() * 0,
                 imath.M44f() * 1]))
예제 #26
0
    def testCanShadeFaceVaryingInterpolatedPrimitiveVariablesAsVertex(self):

        s = Gaffer.ScriptNode()

        p = GafferScene.Plane()
        p["divisions"].setValue(imath.V2i(
            2, 2))  #  2x2 plane = 4 quads & 9 vertices
        s.addChild(p)

        o = GafferOSL.OSLObject()
        s.addChild(o)

        f = GafferScene.PathFilter("PathFilter")
        s.addChild(f)
        f["paths"].setValue(IECore.StringVectorData(['/plane']))
        o["filter"].setInput(f["out"])

        # We're going to copy the FaceVarying UV primvar
        # into a Vertex Color3f primvar. Assert that the source
        # is indeed FaceVarying.
        self.assertEqual(
            p["out"].object("/plane")["uv"].interpolation,
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying)

        o['in'].setInput(p["out"])
        o['interpolation'].setValue(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex)

        s["inUV"] = GafferOSL.OSLShader()
        s["inUV"].loadShader("ObjectProcessing/InVector")
        s["inUV"]["parameters"]["name"].setValue("uv")

        s["outColor"] = GafferOSL.OSLShader()
        s["outColor"].loadShader("ObjectProcessing/OutColor")
        s["outColor"]["parameters"]["value"].setInput(
            s["inUV"]["out"]["value"])
        s["outColor"]["parameters"]["name"].setValue("c")

        s["outObject"] = GafferOSL.OSLShader()
        s["outObject"].loadShader("ObjectProcessing/OutObject")
        s["outObject"]["parameters"]["in0"].setInput(
            s["outColor"]["out"]["primitiveVariable"])

        o["shader"].setInput(s["outObject"]["out"])

        planeObject = s['OSLObject']['out'].object("/plane")

        self.assertIn("c", planeObject)
        self.assertEqual(planeObject["c"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)

        self.assertEqual(planeObject["c"].data[0],
                         imath.Color3f(0.0, 0.0, 0.0))
        self.assertEqual(planeObject["c"].data[1],
                         imath.Color3f(0.5, 0.0, 0.0))
        self.assertEqual(planeObject["c"].data[2],
                         imath.Color3f(1.0, 0.0, 0.0))
        self.assertEqual(planeObject["c"].data[3],
                         imath.Color3f(0.0, 0.5, 0.0))
        self.assertEqual(planeObject["c"].data[4],
                         imath.Color3f(0.5, 0.5, 0.0))
        self.assertEqual(planeObject["c"].data[5],
                         imath.Color3f(1.0, 0.5, 0.0))
        self.assertEqual(planeObject["c"].data[6],
                         imath.Color3f(0.0, 1.0, 0.0))
        self.assertEqual(planeObject["c"].data[7],
                         imath.Color3f(0.5, 1.0, 0.0))
        self.assertEqual(planeObject["c"].data[8],
                         imath.Color3f(1.0, 1.0, 0.0))
예제 #27
0
    def testCustomPrimvars(self):
        fileName = "{}/testUSDCustomPrimVar.scc".format(
            self.temporaryDirectory())
        m = IECoreScene.SceneCache(fileName, IECore.IndexedIO.OpenMode.Write)
        box = m.createChild("box")
        mesh = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(0), imath.V3f(1)))
        vertexSize = mesh.variableSize(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex)

        v = IECore.V3fVectorData([imath.Color3f(12, 12, 12)],
                                 IECore.GeometricData.Interpretation.Point)
        mesh["customPoint"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, v)
        mesh["customIndexedInt"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.IntVectorData([12]), IECore.IntVectorData([0] * vertexSize))

        box.writeObject(mesh, 1.0)
        del m, box

        # root
        stage = pxr.Usd.Stage.Open(fileName)
        root = stage.GetPseudoRoot()
        prim = root.GetPrimAtPath("{}/box".format(
            IECoreUSD.SceneCacheDataAlgo.internalRootName()))

        customPoint = prim.GetAttribute("primvars:customPoint")
        # custom
        self.assertTrue(customPoint.GetMetadata("custom"))

        # type
        self.assertEqual(customPoint.GetMetadata("typeName"),
                         pxr.Sdf.ValueTypeNames.Point3fArray)

        # interpolation
        self.assertEqual(customPoint.GetMetadata("interpolation"), "vertex")

        # value
        self.assertEqual(customPoint.Get(24.0),
                         pxr.Vt.Vec3fArray(1, [pxr.Gf.Vec3f(12)]))

        # indices
        indices = prim.GetAttribute("primvars:customIndexedInt:indices")
        self.assertTrue(indices)
        self.assertEqual(indices.Get(24.0),
                         pxr.Vt.IntArray(vertexSize, [0] * vertexSize))

        # uniform interpolation
        customIndexedInt = prim.GetAttribute("primvars:customIndexedInt")
        self.assertEqual(customIndexedInt.GetMetadata("interpolation"),
                         pxr.UsdGeom.Tokens.uniform)

        # round trip
        exportPath = "{}/testUSDExportCustomPrimVar.scc".format(
            self.temporaryDirectory())
        stage.Export(exportPath)

        scene = IECoreScene.SharedSceneInterfaces.get(exportPath)
        box = scene.child("box")

        mesh = box.readObject(1.0)

        customPoint = mesh["customPoint"]
        self.assertTrue(customPoint)

        # type
        self.assertEqual(customPoint.data.typeName(),
                         IECore.V3fVectorData.staticTypeName())

        # interpolation
        self.assertEqual(customPoint.interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)

        # value
        self.assertEqual(
            customPoint.data,
            IECore.V3fVectorData([imath.V3f(12.0)],
                                 IECore.GeometricData.Interpretation.Point))

        # indices
        self.assertEqual(mesh["customIndexedInt"].indices,
                         IECore.IntVectorData([0] * vertexSize))
예제 #28
0
import IECore

import Gaffer
import GafferUI
import GafferScene
import GafferSceneUI
import GafferDispatch
import GafferDispatchUI

##########################################################################
# Colour
##########################################################################

Gaffer.Metadata.registerValue(GafferDispatch.TaskNode, "nodeGadget:color",
                              imath.Color3f(0.61, 0.1525, 0.1525))
Gaffer.Metadata.registerValue(GafferDispatch.TaskNode.TaskPlug, "nodule:color",
                              imath.Color3f(0.645, 0.2483, 0.2483))
Gaffer.Metadata.registerValue(GafferDispatch.TaskNode.TaskPlug,
                              "connectionGadget:color",
                              imath.Color3f(0.315, 0.0787, 0.0787))

Gaffer.Metadata.registerValue(Gaffer.SubGraph, "nodeGadget:color",
                              imath.Color3f(0.225))
Gaffer.Metadata.registerValue(Gaffer.BoxIO, "nodeGadget:color",
                              imath.Color3f(0.225))
Gaffer.Metadata.registerValue(Gaffer.EditScope, "nodeGadget:color",
                              imath.Color3f(0.1876, 0.3908, 0.6))

Gaffer.Metadata.registerValue(Gaffer.Random, "nodeGadget:color",
                              imath.Color3f(0.45, 0.3, 0.3))
예제 #29
0
    def testUserDefaultMetadata(self):

        cacheFile = os.path.join(self.temporaryDirectory(),
                                 "testShaderUserDefaults.scc")
        script = """
import Gaffer
import GafferScene
import GafferArnold
import GafferArnoldUI
root = Gaffer.ScriptNode()
root["image"] = GafferArnold.ArnoldShader( "image" )
root["image"].loadShader( "image" )
Gaffer.NodeAlgo.applyUserDefaults( root["image"] )
root["Sphere"] = GafferScene.Sphere( "Sphere" )
root["ShaderAssignment"] = GafferScene.ShaderAssignment( "ShaderAssignment" )
root["SceneWriter"] = GafferScene.SceneWriter( "SceneWriter" )
root["ShaderAssignment"]["in"].setInput( root["Sphere"]["out"] )
root["ShaderAssignment"]["shader"].setInput( root["image"]["out"] )
root["SceneWriter"]["in"].setInput( root["ShaderAssignment"]["out"] )
root["SceneWriter"]["fileName"].setValue( "%s" )
root["SceneWriter"].execute()
		""" % cacheFile

        env = os.environ.copy()
        subprocess.check_call(["gaffer", "env", "python", "-c", script],
                              env=env)
        scene = IECoreScene.SceneCache(cacheFile,
                                       IECore.IndexedIO.OpenMode.Read)
        sphere = scene.child("sphere")
        parms = sphere.readAttributeAtSample("ai:surface",
                                             0).outputShader().parameters

        self.assertEqual(parms["single_channel"].value, False)
        self.assertEqual(parms["mipmap_bias"].value, 0)
        self.assertEqual(parms["start_channel"].value, 0)
        self.assertEqual(parms["sscale"].value, 1.0)
        self.assertEqual(parms["multiply"].value, imath.Color3f(1.0))
        self.assertEqual(parms["missing_texture_color"].value,
                         imath.Color4f(0.0))
        self.assertEqual(parms["uvcoords"].value, imath.V2f(0.0))
        self.assertEqual(parms["filename"].value, "")
        self.assertEqual(parms["filter"].value, "smart_bicubic")

        env["ARNOLD_PLUGIN_PATH"] = os.path.join(os.path.dirname(__file__),
                                                 "metadata")
        subprocess.check_call(["gaffer", "env", "python", "-c", script],
                              env=env)
        scene = IECoreScene.SceneCache(cacheFile,
                                       IECore.IndexedIO.OpenMode.Read)
        sphere = scene.child("sphere")
        parms = sphere.readAttributeAtSample("ai:surface",
                                             0).outputShader().parameters

        self.assertEqual(parms["single_channel"].value, True)
        self.assertEqual(parms["mipmap_bias"].value, 84)
        self.assertEqual(parms["start_channel"].value, 84)
        self.assertAlmostEqual(parms["sscale"].value, 6.7, places=5)
        self.assertEqual(parms["multiply"].value, imath.Color3f(12, 13, 14))

        # SolidAngle does not appear to have wrapped AiMetaDataGetRGBA in Python, so we don't
        # support the RGBA case
        #self.assertEqual( parms["missing_texture_color"].value, imath.Color4f( 12, 13, 14, 15 ) )

        self.assertEqual(parms["uvcoords"].value, imath.V2f(12, 13))
        self.assertEqual(parms["filename"].value, "overrideUserDefault")
        self.assertEqual(parms["filter"].value, "bilinear")
예제 #30
0
    def testColorMode(self):

        sphere = GafferScene.Sphere()
        group = GafferScene.Group()
        group["in"][0].setInput(sphere["out"])
        group["in"][1].setInput(sphere["out"])
        group["in"][2].setInput(sphere["out"])

        filter1 = GafferScene.PathFilter()
        filter1["paths"].setValue(IECore.StringVectorData(["/group/sphere1"]))

        attributes1 = GafferScene.StandardAttributes()
        attributes1["in"].setInput(group["out"])
        attributes1["attributes"]["transformBlurSegments"]["enabled"].setValue(
            1)
        attributes1["attributes"]["transformBlurSegments"]["value"].setValue(4)
        attributes1["filter"].setInput(filter1["out"])

        filter2 = GafferScene.PathFilter()
        filter2["paths"].setValue(IECore.StringVectorData(["/group/sphere2"]))

        attributes2 = GafferScene.StandardAttributes()
        attributes2["in"].setInput(attributes1["out"])
        attributes2["attributes"]["transformBlurSegments"]["enabled"].setValue(
            1)
        attributes2["attributes"]["transformBlurSegments"]["value"].setValue(2)
        attributes2["filter"].setInput(filter2["out"])

        self.assertTrue(
            "gl:surface" not in attributes2["out"].attributes("/group/sphere"))
        self.assertTrue("gl:surface" not in attributes2["out"].attributes(
            "/group/sphere1"))
        self.assertTrue("gl:surface" not in attributes2["out"].attributes(
            "/group/sphere2"))

        visualiser = GafferScene.AttributeVisualiser()
        visualiser["in"].setInput(attributes2["out"])
        self.assertSceneValid(visualiser["out"])

        self.assertTrue(
            "gl:surface" not in visualiser["out"].attributes("/group/sphere"))
        self.assertTrue(
            "gl:surface" not in visualiser["out"].attributes("/group/sphere1"))
        self.assertTrue(
            "gl:surface" not in visualiser["out"].attributes("/group/sphere2"))

        visualiser["attributeName"].setValue("gaffer:transformBlurSegments")
        visualiser["mode"].setValue(visualiser.Mode.Color)
        visualiser["max"].setValue(4)

        self.assertTrue(
            "gl:surface" not in visualiser["out"].attributes("/group/sphere"))
        self.assertTrue(
            "gl:surface" in visualiser["out"].attributes("/group/sphere1"))
        self.assertTrue(
            "gl:surface" in visualiser["out"].attributes("/group/sphere2"))
        self.assertEqual(
            visualiser["out"].attributes("/group/sphere1")
            ["gl:surface"].outputShader().parameters["Cs"].value,
            imath.Color3f(1),
        )
        self.assertEqual(
            visualiser["out"].attributes("/group/sphere2")
            ["gl:surface"].outputShader().parameters["Cs"].value,
            imath.Color3f(.5),
        )