Esempio n. 1
0
def __plugPresetValues(nodeEntry, paramName, paramType):

    # options STRING "name:value|..."

    options = __aiMetadataGetStr(nodeEntry, paramName, "options")
    if not options:
        return None

    values = [o.rpartition(":")[2] for o in options.split("|") if o]

    if paramType == arnold.AI_TYPE_STRING:
        return IECore.StringVectorData(values)
    elif paramType in (arnold.AI_TYPE_INT, arnold.AI_TYPE_BYTE):
        return IECore.IntVectorData([int(v) for v in values])
    elif paramType == arnold.AI_TYPE_UINT:
        return IECore.UIntVectorData([int(v) for v in values])
    elif paramType == arnold.AI_TYPE_FLOAT:
        return IECore.FloatVectorData([float(v) for v in values])
    elif paramType == arnold.AI_TYPE_BOOLEAN:
        falseVals = ("false", "no", "0")
        return IECore.BoolVectorData(
            [False if v.lower() in falseVals else True for v in values])
    elif paramType == arnold.AI_TYPE_RGB:
        return IECore.Color3fVectorData(
            [imath.Color3f(*[float(x) for x in v.split(",")]) for v in values])
    elif paramType == arnold.AI_TYPE_RGBA:
        return IECore.Color4fVectorData(
            [imath.Color4f(*[float(x) for x in v.split(",")]) for v in values])
    elif paramType in (arnold.AI_TYPE_VECTOR, arnold.AI_TYPE_POINT):
        return IECore.V3fVectorData(
            [imath.V3f(*[float(x) for x in v.split(",")]) for v in values])
    elif paramType == arnold.AI_TYPE_POINT2:
        return IECore.V2fVectorData(
            [imath.V2f(*[float(x) for x in v.split(",")]) for v in values])

    return None
Esempio n. 2
0
    def testNestedTransform(self):

        script = Gaffer.ScriptNode()
        script["camera"] = GafferScene.Camera()
        script["group"] = GafferScene.Group()
        script["group"]["in"][0].setInput(script["camera"]["out"])
        script["group"]["transform"]["rotate"]["y"].setValue(90)

        view = GafferSceneUI.SceneView()
        view["in"].setInput(script["group"]["out"])

        view["camera"]["lookThroughEnabled"].setValue(True)
        view["camera"]["lookThroughCamera"].setValue("/group/camera")

        tool = GafferSceneUI.CameraTool(view)
        tool["active"].setValue(True)

        cameraTransform = imath.M44f().translate(imath.V3f(1, 2, 3))
        view.viewportGadget().setCameraTransform(cameraTransform)

        self.assertTrue(
            cameraTransform.equalWithAbsError(
                script["group"]["out"].fullTransform("/group/camera"),
                0.00001))
Esempio n. 3
0
    def testHandlesTransform(self):

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()
        script["plane"]["transform"]["rotate"]["y"].setValue(90)

        view = GafferSceneUI.SceneView()
        view["in"].setInput(script["plane"]["out"])
        GafferSceneUI.ContextAlgo.setSelectedPaths(
            view.getContext(), IECore.PathMatcher(["/plane"]))

        tool = GafferSceneUI.TranslateTool(view)
        tool["active"].setValue(True)

        tool["orientation"].setValue(tool.Orientation.Local)
        self.assertTrue(tool.handlesTransform().equalWithAbsError(
            imath.M44f().rotate(imath.V3f(0, math.pi / 2, 0)), 0.000001))

        tool["orientation"].setValue(tool.Orientation.Parent)
        self.assertEqual(tool.handlesTransform(), imath.M44f())

        tool["orientation"].setValue(tool.Orientation.World)
        self.assertEqual(tool.handlesTransform(), imath.M44f())
Esempio n. 4
0
	def testRead( self ) :

		sc = IECoreScene.SceneCache( self.__testFile, IECore.IndexedIO.OpenMode.Write )

		t = sc.createChild( "transform" )
		t.writeTransform( IECore.M44dData( imath.M44d().translate( imath.V3d( 1, 0, 0 ) ) ), 0.0 )

		s = t.createChild( "shape" )
		s.writeObject( IECoreScene.SpherePrimitive( 10 ), 0.0 )

		del sc, t, s

		reader = GafferScene.SceneReader()
		reader["fileName"].setValue( self.__testFile )

		# we have to remember to set the refresh counts to different values in different tests, otherwise
		# it thinks it's reading an old file...
		reader["refreshCount"].setValue( self.uniqueInt( self.__testFile ) )

		scene = reader["out"]
		self.assertSceneValid( scene )

		self.assertEqual( scene.transform( "transform" ), imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) )
		self.assertEqual( scene.object( "transform/shape" ), IECoreScene.SpherePrimitive( 10 ) )
Esempio n. 5
0
    def renderImage(self, group):

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

        r.camera(
            "main", {
                "projection": "orthographic",
                "resolution": imath.V2i(256),
                "clippingPlanes": imath.V2f(1, 1000),
                "screenWindow": imath.Box2f(imath.V2f(-0.5), imath.V2f(0.5))
            })
        r.display(self.__imageFileName, "tif", "rgba", {})
        r.setOption("gl:searchPath:texture", IECore.StringData("./"))
        r.setOption("gl:searchPath:shader",
                    IECore.StringData("./test/IECoreGL/shaders"))

        with IECoreScene.WorldBlock(r):

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

            group.render(r)

        return IECore.Reader.create(self.__imageFileName).read()
Esempio n. 6
0
    def testSelectionMask(self):

        plane = GafferScene.Plane()
        plane["dimensions"].setValue(imath.V2f(10))
        plane["transform"]["translate"]["z"].setValue(4)

        camera = GafferScene.Camera()
        group = GafferScene.Group()
        group["in"][0].setInput(plane["out"])
        group["in"][1].setInput(camera["out"])

        sg = GafferSceneUI.SceneGadget()
        sg.setScene(group["out"])
        sg.setMinimumExpansionDepth(100)

        with GafferUI.Window() as w:
            gw = GafferUI.GadgetWidget(sg)
        w.setVisible(True)
        self.waitForIdle(10000)

        sg.waitForCompletion()
        gw.getViewportGadget().frame(sg.bound(), imath.V3f(0, 0, -1))
        self.waitForIdle(10000)

        self.assertObjectsAt(sg, imath.Box2f(imath.V2f(0), imath.V2f(1)),
                             ["/group/plane", "/group/camera"])

        sg.setSelectionMask(IECore.StringVectorData(["MeshPrimitive"]))

        self.assertObjectsAt(sg, imath.Box2f(imath.V2f(0), imath.V2f(1)),
                             ["/group/plane"])

        sg.setSelectionMask(IECore.StringVectorData(["Camera"]))

        self.assertObjectsAt(sg, imath.Box2f(imath.V2f(0), imath.V2f(1)),
                             ["/group/camera"])
Esempio n. 7
0
    def points(self):

        testObject = IECoreScene.PointsPrimitive(
            IECore.V3fVectorData([imath.V3f(x) for x in range(0, 10)]))

        testObject["a"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Constant,
            IECore.FloatData(0.5))
        testObject["b"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.FloatVectorData(range(0, 10)))
        testObject["c"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.FloatVectorData([0]))
        testObject["d"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Varying,
            IECore.FloatVectorData(range(0, 10)))
        testObject["e"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            IECore.FloatVectorData(range(0, 10)))

        self.assertTrue(testObject.arePrimitiveVariablesValid())

        return testObject
	def testNoVisualisation( self ) :

		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, -5 ) ) )
			r.coordinateSystem( "myCoordSys" )

		i = IECore.Reader.create( self.__outputFileName ).read()

		a = i["A"]
		for i in range( a.size() ) :
			self.assertEqual( a[i], 0 )
Esempio n. 9
0
	def testMode( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			p = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( i ) for i in range( 0, 10 ) ] ) )

			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "disk" )

			p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, "particle" )
			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "disk" )

			p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, "disk" )
			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "disk" )

			p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, "sphere" )
			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "sphere" )

			p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, "patch" )
			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "quad" )
Esempio n. 10
0
	def testCanWriteAnimatedPrimitiveVariable ( self ):

		fileName = self.getOutputPath("usd_animated_primvar.usda")

		sceneWrite = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
		root = sceneWrite.createChild( "root" )

		for t in range(32):
			positionData = []
			primvarData = []
			for i in range( 16 ) :
				for j in range( 16 ) :
					positionData.append( imath.V3f( [i, j, 0] ) )
					primvarData.append ( i * 16 + j + t )

			positions = IECore.V3fVectorData( positionData )
			primvar = IECore.IntVectorData( primvarData)

			pointsPrimitive = IECoreScene.PointsPrimitive( positions )
			pointsPrimitive["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, primvar )
			root.writeObject( pointsPrimitive, t )

		del root
		del sceneWrite

		sceneRead = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
		self.assertEqual( sceneRead.childNames(), ["root"] )
		readRoot = sceneRead.child( "root" )

		self.assertTrue( readRoot.hasObject() )

		readPoints = readRoot.readObject( 0.0 )
		self.assertIsInstance( readPoints, IECoreScene.PointsPrimitive )

		roundTripPositions = readPoints["P"].data
		self.assertEqual( roundTripPositions, positions )
Esempio n. 11
0
	def testMinMax( self ) :

		b = Gaffer.Box3fPlug( "p", Gaffer.Plug.Direction.In, imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ) )
		v = Gaffer.V3fPlug()

		self.assertEqual( b.minValue(), v.minValue() )
		self.assertEqual( b.maxValue(), v.maxValue() )
		self.assertFalse( b.hasMinValue() )
		self.assertFalse( b.hasMaxValue() )
		self.assertEqual( b.minValue(), v.minValue() )
		self.assertEqual( b.maxValue(), v.maxValue() )

		b = Gaffer.Box3fPlug( "p", minValue = imath.V3f( -1, -2, -3 ), maxValue = imath.V3f( 1, 2, 3 ) )
		self.assertTrue( b.hasMinValue() )
		self.assertTrue( b.hasMaxValue() )
		self.assertEqual( b.minValue(), imath.V3f( -1, -2, -3 ) )
		self.assertEqual( b.maxValue(), imath.V3f( 1, 2, 3 ) )

		c = b.createCounterpart( "c", Gaffer.Plug.Direction.In )
		self.assertTrue( c.hasMinValue() )
		self.assertTrue( c.hasMaxValue() )
		self.assertEqual( c.minValue(), imath.V3f( -1, -2, -3 ) )
		self.assertEqual( c.maxValue(), imath.V3f( 1, 2, 3 ) )
    def testDuplicateDeserialise(self):

        s = Gaffer.ScriptNode()

        s["source"] = Gaffer.Node()
        s["source"]["p"] = Gaffer.V3fPlug(flags=Gaffer.Plug.Flags.Default
                                          | Gaffer.Plug.Flags.Dynamic)
        s["source"]["p"].setValue(imath.V3f(0.1, 0.2, 0.3))

        s["dest"] = Gaffer.Node()
        s["dest"]["p"] = Gaffer.V3fPlug(flags=Gaffer.Plug.Flags.Default
                                        | Gaffer.Plug.Flags.Dynamic)

        s["e"] = Gaffer.Expression()
        s["e"].setExpression(
            "parent.dest.p.x = parent.source.p.x + 1;\n" +
            "parent.dest.p.y = parent.source.p.y + 2;\n" +
            "parent.dest.p.z = parent.source.p.z + 3;\n",
            "OSL",
        )

        ss = s.serialise()

        s.execute(ss)
        s.execute(ss)

        self.assertEqual(s["dest"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))
        self.assertEqual(s["dest1"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))
        self.assertEqual(s["dest2"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))

        # Working well so far, but we've had a bug that could be hidden by the caching.  Lets
        # try evaluating the plugs again, but flushing the cache each time

        Gaffer.ValuePlug.clearCache()
        self.assertEqual(s["dest"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))
        self.assertEqual(s["dest1"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))
        self.assertEqual(s["dest2"]["p"].getValue(), imath.V3f(1.1, 2.2, 3.3))
Esempio n. 13
0
    def testEditScopes(self):

        script = Gaffer.ScriptNode()

        script["sphere"] = GafferScene.Sphere()
        script["sphere"]["transform"]["translate"].setValue(imath.V3f(1, 0, 0))

        script["editScope"] = Gaffer.EditScope()
        script["editScope"].setup(script["sphere"]["out"])
        script["editScope"]["in"].setInput(script["sphere"]["out"])

        view = GafferSceneUI.SceneView()
        view["in"].setInput(script["editScope"]["out"])
        view["editScope"].setInput(script["editScope"]["out"])

        GafferSceneUI.ContextAlgo.setSelectedPaths(
            view.getContext(), IECore.PathMatcher(["/sphere"]))

        tool = GafferSceneUI.TranslateTool(view)
        tool["active"].setValue(True)

        self.assertEqual(tool.handlesTransform(),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))
        self.assertEqual(len(tool.selection()), 1)
        self.assertTrue(tool.selection()[0].editable())
        self.assertFalse(
            GafferScene.EditScopeAlgo.hasTransformEdit(script["editScope"],
                                                       "/sphere"))
        self.assertEqual(script["editScope"]["out"].transform("/sphere"),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))

        tool.translate(imath.V3f(0, 1, 0))
        self.assertEqual(tool.handlesTransform(),
                         imath.M44f().translate(imath.V3f(1, 1, 0)))
        self.assertEqual(len(tool.selection()), 1)
        self.assertTrue(tool.selection()[0].editable())
        self.assertTrue(
            GafferScene.EditScopeAlgo.hasTransformEdit(script["editScope"],
                                                       "/sphere"))
        self.assertEqual(script["editScope"]["out"].transform("/sphere"),
                         imath.M44f().translate(imath.V3f(1, 1, 0)))
Esempio n. 14
0
    def testTypedValueFns(self):

        p = IECore.StringParameter(name="n",
                                   description="d",
                                   defaultValue="10")
        self.assertEqual(p.getTypedValue(), "10")
        p.setTypedValue("20")
        self.assertEqual(p.getTypedValue(), "20")

        self.assertEqual(p.typedDefaultValue, "10")
        self.assertRaises(AttributeError, setattr, p, "typedDefaultValue",
                          "20")

        p = IECore.V3fParameter(name="n",
                                description="d",
                                defaultValue=imath.V3f(1, 2, 3))
        self.assertEqual(p.getTypedValue(), imath.V3f(1, 2, 3))
        p.setTypedValue(imath.V3f(12, 13, 14))
        self.assertEqual(p.getTypedValue(), imath.V3f(12, 13, 14))
        self.assertEqual(p.getValue(), IECore.V3fData(imath.V3f(12, 13, 14)))

        self.assertEqual(p.typedDefaultValue, imath.V3f(1, 2, 3))
        self.assertRaises(AttributeError, setattr, p, "typedDefaultValue",
                          imath.V3f(4, 5, 6))
Esempio n. 15
0
	def testParameterMinMaxMetadata( self ) :

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

		self.assertAlmostEqual( n["parameters"]["b"].minValue(), 2.3, delta = 0.00001 )
		self.assertAlmostEqual( n["parameters"]["b"].maxValue(), 4.7, delta = 0.00001 )
		self.assertEqual( n["parameters"]["c"].minValue(), 23 )
		self.assertEqual( n["parameters"]["c"].maxValue(), 47 )
		self.assertEqual( n["parameters"]["d"].minValue(), imath.Color3f( 1, 2, 3 ) )
		self.assertEqual( n["parameters"]["d"].maxValue(), imath.Color3f( 4, 5, 6 ) )
		self.assertEqual( n["parameters"]["e"].minValue(), imath.V3f( 1, 2, 3 ) )
		self.assertEqual( n["parameters"]["e"].maxValue(), imath.V3f( 4, 5, 6 ) )
		self.assertEqual( n["parameters"]["f"].minValue(), imath.V3f( 1, 2, 3 ) )
		self.assertEqual( n["parameters"]["f"].maxValue(), imath.V3f( 4, 5, 6 ) )
		self.assertEqual( n["parameters"]["g"].minValue(), imath.V3f( 1, 2, 3 ) )
		self.assertEqual( n["parameters"]["g"].maxValue(), imath.V3f( 4, 5, 6 ) )

		# Check default min/max if not specified
		self.assertFalse( n["parameters"]["h"].hasMinValue() )
		self.assertFalse( n["parameters"]["h"].hasMaxValue() )
Esempio n. 16
0
    def testCompute(self):

        c = GafferScene.Cube()

        self.assertEqual(c["out"].object("/"), IECore.NullObject())
        self.assertEqual(c["out"].transform("/"), imath.M44f())
        self.assertEqual(
            c["out"].bound("/"),
            imath.Box3f(imath.V3f(-0.5, -0.5, -0.5), imath.V3f(0.5, 0.5, 0.5)))
        self.assertEqual(c["out"].childNames("/"),
                         IECore.InternedStringVectorData(["cube"]))

        self.assertEqual(
            c["out"].object("/cube"),
            IECoreScene.MeshPrimitive.createBox(
                imath.Box3f(imath.V3f(-0.5), imath.V3f(0.5))))
        self.assertEqual(c["out"].transform("/cube"), imath.M44f())
        self.assertEqual(
            c["out"].bound("/cube"),
            imath.Box3f(imath.V3f(-0.5, -0.5, -0.5), imath.V3f(0.5, 0.5, 0.5)))
        self.assertEqual(c["out"].childNames("/cube"),
                         IECore.InternedStringVectorData())
Esempio n. 17
0
    def testMotion(self):

        m1 = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        IECoreScene.MeshNormalsOp()(input=m1, copyInput=False)

        m2 = m1.copy()
        m2["P"].data[0] -= imath.V3f(0, 0, 1)
        m2["P"].data[1] -= imath.V3f(0, 0, 1)
        IECoreScene.MeshNormalsOp()(input=m2, copyInput=False)

        with IECoreArnold.UniverseBlock(writable=True) as universe:

            node = IECoreArnold.NodeAlgo.convert([m1, m2], -0.25, 0.25,
                                                 universe, "testMesh")

            vList = arnold.AiNodeGetArray(node, "vlist")
            self.assertEqual(arnold.AiArrayGetNumElements(vList.contents), 4)
            self.assertEqual(arnold.AiArrayGetNumKeys(vList.contents), 2)

            nList = arnold.AiNodeGetArray(node, "nlist")
            self.assertEqual(arnold.AiArrayGetNumElements(nList.contents), 4)
            self.assertEqual(arnold.AiArrayGetNumKeys(nList.contents), 2)

            for i in range(0, 4):
                p = arnold.AiArrayGetVec(vList, i)
                self.assertEqual(imath.V3f(p.x, p.y, p.z), m1["P"].data[i])
                n = arnold.AiArrayGetVec(nList, i)
                self.assertEqual(imath.V3f(n.x, n.y, n.z), m1["N"].data[i])

            for i in range(4, 8):
                p = arnold.AiArrayGetVec(vList, i)
                self.assertEqual(imath.V3f(p.x, p.y, p.z), m2["P"].data[i - 4])
                n = arnold.AiArrayGetVec(nList, i)
                self.assertEqual(imath.V3f(n.x, n.y, n.z), m2["N"].data[i - 4])

            self.assertEqual(arnold.AiNodeGetFlt(node, "motion_start"), -0.25)
            self.assertEqual(arnold.AiNodeGetFlt(node, "motion_end"), 0.25)
Esempio n. 18
0
    def makeTriangleScene(self):

        verticesPerFace = IECore.IntVectorData([3])
        vertexIds = IECore.IntVectorData([0, 1, 2])
        p = IECore.V3fVectorData(
            [imath.V3f(0, 0, 0),
             imath.V3f(1, 0, 0),
             imath.V3f(0, 1, 0)])
        prefData = IECore.V3fVectorData(
            [imath.V3f(0, 0, 0),
             imath.V3f(0, -1, 0),
             imath.V3f(1, 0, 0)])

        mesh = IECoreScene.MeshPrimitive(verticesPerFace, vertexIds, "linear",
                                         p)

        mesh["uv"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            IECore.V2fVectorData(
                [imath.V2f(0, 0),
                 imath.V2f(1, 0),
                 imath.V2f(0, 1)], IECore.GeometricData.Interpretation.UV))

        mesh["foo"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            IECore.V2fVectorData(
                [imath.V2f(0, 0),
                 imath.V2f(0, 1),
                 imath.V2f(1, 0)], IECore.GeometricData.Interpretation.UV))

        mesh["Pref"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, prefData)

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

        return objectToScene
Esempio n. 19
0
	def testGeometricInterpretation( self ) :

		s = GafferScene.Sphere()
		p = GafferScene.PrimitiveVariables()
		p["in"].setInput( s["out"] )

		p["primitiveVariables"].addMember( "myFirstData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Vector ) )
		p["primitiveVariables"].addMember( "mySecondData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Normal ) )
		p["primitiveVariables"].addMember( "myThirdData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Point ) )

		o = p["out"].object( "/sphere" )

		# test if the geometric interpretation makes it into the primitive variable
		self.assertEqual( o["myFirstData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Vector )
		self.assertEqual( o["mySecondData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Normal )
		self.assertEqual( o["myThirdData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Point )

		del o["myFirstData"]
		del o["mySecondData"]
		del o["myThirdData"]

		self.assertFalse( 'myFirstData' in o )
		self.assertFalse( 'mySecondData' in o )
		self.assertFalse( 'myThirdData' in o )

		p["primitiveVariables"].addMember( "myFirstData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Point ) )
		p["primitiveVariables"].addMember( "mySecondData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Vector ) )
		p["primitiveVariables"].addMember( "myThirdData", IECore.V3fData( imath.V3f( 0 ), IECore.GeometricData.Interpretation.Normal ) )

		o = p["out"].object( "/sphere" )

		# test if the new geometric interpretation makes it into the primitive variable
		# this tests the hashing on the respective plugs
		self.assertEqual( o["myFirstData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Point )
		self.assertEqual( o["mySecondData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Vector )
		self.assertEqual( o["myThirdData"].data.getInterpretation(), IECore.GeometricData.Interpretation.Normal )
Esempio n. 20
0
    def testSpaces(self):

        sphere = maya.cmds.polySphere(subdivisionsX=10,
                                      subdivisionsY=5,
                                      constructionHistory=False)
        maya.cmds.move(1, 2, 3, sphere)
        sphere = maya.cmds.listRelatives(sphere, shapes=True)[0]

        converter = IECoreMaya.FromMayaShapeConverter.create(sphere)

        self.assertEqual(converter["space"].getNumericValue(),
                         IECoreMaya.FromMayaCurveConverter.Space.Object)
        m = converter.convert()
        self.assertTrue(
            IECore.BoxAlgo.contains(
                imath.Box3f(imath.V3f(-1.0001), imath.V3f(1.0001)), m.bound()))

        converter["space"].setNumericValue(
            IECoreMaya.FromMayaShapeConverter.Space.World)
        m = converter.convert()
        self.assertTrue(
            imath.Box3f(
                imath.V3f(-1.0001) + imath.V3f(1, 2, 3),
                imath.V3f(1.0001) + imath.V3f(1, 2, 3)), m.bound())
Esempio n. 21
0
	def testSphere( self ) :

		m = IECoreScene.MeshPrimitive.createSphere( radius = 1, divisions = imath.V2i( 30, 40 ) )
		self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )
		me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
		mer = me.createResult()
		s = IECoreScene.SpherePrimitive( 1 )
		se = IECoreScene.PrimitiveEvaluator.create( s )
		ser = se.createResult()
		for s in range( 0, 100 ) :
			for t in range( 0, 100 ) :
				uv = imath.V2f( s / 100.0, t / 100.0 )
				if not me.pointAtUV( uv, mer ) :
					# Not all UV coordinates are covered,
					# due to the row of triangles at the
					# poles.
					continue
				self.assertTrue( se.pointAtUV( uv, ser ) )
				self.assertTrue( mer.point().equalWithAbsError( ser.point(), 1e-2 ) )

		# test divisions
		m = IECoreScene.MeshPrimitive.createSphere( radius = 1, divisions = imath.V2i( 300, 300 ) )
		self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )
		me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
		mer = me.createResult()
		for s in range( 0, 100 ) :
			for t in range( 0, 100 ) :
				uv = imath.V2f( s / 100.0, t / 100.0 )
				if not me.pointAtUV( uv, mer ) :
					# Not all UV coordinates are covered,
					# due to the row of triangles at the
					# poles.
					continue
				self.assertTrue( se.pointAtUV( uv, ser ) )
				# more divisions means points are closer to ground truth
				self.assertTrue( mer.point().equalWithAbsError( ser.point(), 1e-4 ) )

		# test radius
		m = IECoreScene.MeshPrimitive.createSphere( radius = 2, divisions = imath.V2i( 30, 40 ) )
		self.assertFalse( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
		self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -2 ), imath.V3f( 2 ) ), m.bound() ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )
		me = IECoreScene.PrimitiveEvaluator.create( IECoreScene.MeshAlgo.triangulate( m ) )
		mer = me.createResult()
		s = IECoreScene.SpherePrimitive( 2 )
		se = IECoreScene.PrimitiveEvaluator.create( s )
		ser = se.createResult()
		for s in range( 0, 100 ) :
			for t in range( 0, 100 ) :
				uv = imath.V2f( s / 100.0, t / 100.0 )
				if not me.pointAtUV( uv, mer ) :
					# Not all UV coordinates are covered,
					# due to the row of triangles at the
					# poles.
					continue
				self.assertTrue( se.pointAtUV( uv, ser ) )
				self.assertTrue( mer.point().equalWithAbsError( ser.point(), 1e-2 ) )

		# test zMin/zMax
		m = IECoreScene.MeshPrimitive.createSphere( radius = 1, zMin = -0.75, zMax = 0.75 )
		self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1, -1, -0.75 ), imath.V3f( 1, 1, 0.75 ) ), m.bound() ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )

		# test thetaMax
		m = IECoreScene.MeshPrimitive.createSphere( radius = 1, thetaMax = 300 )
		self.assertTrue( IECore.BoxAlgo.contains( imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ), m.bound() ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )
		m2 = IECoreScene.MeshPrimitive.createSphere( radius = 1 )
		self.assertTrue( m.numFaces() < m2.numFaces() )
Esempio n. 22
0
	def testPlane( self ) :

		m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Constant ), 1 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Uniform ), 1 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ), 4 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Varying ), 4 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying ), 4 )
		self.assertEqual( m.numFaces(), 1 )
		self.assertEqual( m.verticesPerFace, IECore.IntVectorData( [ 4 ] ) )
		self.assertEqual( m.vertexIds, IECore.IntVectorData( [ 0, 1, 3, 2 ] ) )
		self.assertEqual( m.bound(), imath.Box3f( imath.V3f( 0 ), imath.V3f( 1, 1, 0 ) ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )

		# verify uvs
		self.assertEqual( m["uv"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.FaceVarying )
		self.assertEqual( len( m["uv"].data ), len( m["P"].data ) )
		self.assertEqual( m["uv"].indices, m.vertexIds )

		# verify uvs
		self.assertEqual( m["N"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Vertex )
		self.assertEqual( len( m["N"].data ), len( m["P"].data ) )
		self.assertEqual( m["N"].data, IECore.V3fVectorData( [ imath.V3f( 0, 0, 1 ) ] * len( m["P"].data ), IECore.GeometricData.Interpretation.Normal ) )

		e = IECoreScene.MeshPrimitiveEvaluator( IECoreScene.MeshAlgo.triangulate( m ) )

		r = e.createResult()
		self.assertTrue( e.pointAtUV( imath.V2f( 0, 0 ), r ) )
		self.assertEqual( r.point(), m["P"].data[0] )
		self.assertEqual( r.point(), imath.V3f( 0, 0, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 1, 0 ), r ) )
		self.assertEqual( r.point(), m["P"].data[1] )
		self.assertEqual( r.point(), imath.V3f( 1, 0, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 1, 1 ), r ) )
		self.assertEqual( r.point(), m["P"].data[3] )
		self.assertEqual( r.point(), imath.V3f( 1, 1, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 0, 1 ), r ) )
		self.assertEqual( r.point(), m["P"].data[2] )
		self.assertEqual( r.point(), imath.V3f( 0, 1, 0 ) )

		# test divisions
		m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ), divisions = imath.V2i( 2, 3 ) )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Constant ), 1 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Uniform ), 6 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Vertex ), 12 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.Varying ), 12 )
		self.assertEqual( m.variableSize( IECoreScene.PrimitiveVariable.Interpolation.FaceVarying ), 24 )
		self.assertEqual( m.numFaces(), 6 )
		self.assertEqual( m.verticesPerFace, IECore.IntVectorData( [ 4 ] * 6 ) )
		self.assertEqual( m.vertexIds, IECore.IntVectorData( [ 0, 1, 4, 3, 1, 2, 5, 4, 3, 4, 7, 6, 4, 5, 8, 7, 6, 7, 10, 9, 7, 8, 11, 10 ] ) )
		self.assertEqual( m.bound(), imath.Box3f( imath.V3f( 0 ), imath.V3f( 1, 1, 0 ) ) )
		self.assertTrue( m.arePrimitiveVariablesValid() )

		# corners still have correct uvs
		e = IECoreScene.MeshPrimitiveEvaluator( IECoreScene.MeshAlgo.triangulate( m ) )
		r = e.createResult()
		self.assertTrue( e.pointAtUV( imath.V2f( 0, 0 ), r ) )
		self.assertEqual( r.point(), m["P"].data[0] )
		self.assertEqual( r.point(), imath.V3f( 0, 0, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 1, 0 ), r ) )
		self.assertEqual( r.point(), m["P"].data[2] )
		self.assertEqual( r.point(), imath.V3f( 1, 0, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 1, 1 ), r ) )
		self.assertEqual( r.point(), m["P"].data[11] )
		self.assertEqual( r.point(), imath.V3f( 1, 1, 0 ) )
		self.assertTrue( e.pointAtUV( imath.V2f( 0, 1 ), r ) )
		self.assertEqual( r.point(), m["P"].data[9] )
		self.assertEqual( r.point(), imath.V3f( 0, 1, 0 ) )
Esempio n. 23
0
    def testDetailAttributes(self):
        attr = self.testSetupAttributes()
        attr.parm("class").set(0)  # detail attribute

        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        attr.parm("value1").set(123.456)
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.FloatData)
        self.assert_(result["test_attribute"].data > IECore.FloatData(123.0))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # integer
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.IntData)
        self.assertEqual(result["test_attribute"].data, IECore.IntData(123))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(2)  # 2 elementS
        attr.parm("value2").set(456.789)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2fData)
        self.assertEqual(result["test_attribute"].data.value,
                         imath.V2f(123.456, 456.789))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2iData)
        self.assertEqual(result["test_attribute"].data.value,
                         imath.V2i(123, 456))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(3)  # 3 elements
        attr.parm("value3").set(999.999)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3fData)
        self.assertEqual(result["test_attribute"].data.value,
                         imath.V3f(123.456, 456.789, 999.999))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3iData)
        self.assertEqual(result["test_attribute"].data.value,
                         imath.V3i(123, 456, 999))
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(3)  # string
        attr.parm("string").set("string!")
        result = IECoreHoudini.FromHoudiniPointsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.StringData)
        self.assertEqual(result["test_attribute"].data.value, "string!")
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Constant)
        self.assert_(result.arePrimitiveVariablesValid())
Esempio n. 24
0
    def testPointAttributes(self):
        attr = self.testSetupAttributes()

        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        attr.parm("value1").set(123.456)
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.FloatVectorData)
        self.assert_(result["test_attribute"].data[0] > 123.0)
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # integer
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.IntVectorData)
        self.assertEqual(result["test_attribute"].data[0], 123)
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(2)  # 2 elementS
        attr.parm("value2").set(456.789)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2fVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V2f(123.456, 456.789))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2iVectorData)
        self.assertEqual(result["test_attribute"].data[0], imath.V2i(123, 456))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(3)  # 3 elements
        attr.parm("value3").set(999.999)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3fVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V3f(123.456, 456.789, 999.999))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3iVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V3i(123, 456, 999))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(3)  # string
        attr.parm("string").setExpression(
            "'string %06d!' % pwd().curPoint().number()",
            hou.exprLanguage.Python)
        result = IECoreHoudini.FromHoudiniPointsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.StringVectorData)
        self.assertEqual(result["test_attribute"].data[10], "string 000010!")
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assertEqual(result["test_attribute"].indices[10], 10)
        self.assertEqual(result["test_attribute"].indices.size(), 100)
        self.assert_(result.arePrimitiveVariablesValid())
Esempio n. 25
0
    def testFilter(self):

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

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

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

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

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

        self.assertSceneValid(t["out"])

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

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

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

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

        self.assertSceneValid(t["out"])

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

        self.assertEqual(
            t["out"].bound("/group/plane"),
            imath.Box3f(imath.V3f(1.5, 1.5, 3), imath.V3f(2.5, 2.5, 3)))
        self.assertEqual(
            t["out"].bound("/group/plane1"),
            imath.Box3f(imath.V3f(0.5, -0.5, 0), imath.V3f(1.5, 0.5, 0)))
Esempio n. 26
0
    def __frame(self, nodes, extend=False, at=None):

        graphGadget = self.graphGadget()

        # get the bounds of the nodes
        bound = imath.Box3f()
        for node in nodes:
            nodeGadget = graphGadget.nodeGadget(node)
            if nodeGadget:
                bound.extendBy(nodeGadget.transformedBound(graphGadget))

        # if there were no nodes then use the bound of the whole
        # graph.
        if bound.isEmpty():
            bound = graphGadget.bound()

        # if there's still nothing then an arbitrary area in the centre of the world
        if bound.isEmpty():
            bound = imath.Box3f(imath.V3f(-10, -10, 0), imath.V3f(10, 10, 0))

        # pad it a little bit so
        # it sits nicer in the frame
        bound.setMin(bound.min() - imath.V3f(1, 1, 0))
        bound.setMax(bound.max() + imath.V3f(1, 1, 0))

        if extend:
            # we're extending the existing framing, which we assume the
            # user was happy with other than it not showing the nodes in question.
            # so we just take the union of the existing frame and the one for the nodes.
            cb = self.__currentFrame()
            bound.extendBy(
                imath.Box3f(imath.V3f(cb.min().x,
                                      cb.min().y, 0),
                            imath.V3f(cb.max().x,
                                      cb.max().y, 0)))
        else:
            # we're reframing from scratch, so the frame for the nodes is all we need.
            # we do however want to make sure that we don't zoom in too far if the node
            # bounds are small, as having a single node filling the screen is of little use -
            # it's better to see some context around it.
            boundSize = bound.size()
            widgetSize = imath.V3f(self._qtWidget().width(),
                                   self._qtWidget().height(), 0)

            pixelsPerUnit = min(widgetSize.x / boundSize.x,
                                widgetSize.y / boundSize.y)
            adjustedPixelsPerUnit = min(pixelsPerUnit, 10)

            newBoundSize = widgetSize / adjustedPixelsPerUnit
            boundCenter = bound.center()
            bound.setMin(boundCenter - newBoundSize / 2.0)
            bound.setMax(boundCenter + newBoundSize / 2.0)

        if at is not None:
            viewport = self.graphGadgetWidget().getViewportGadget()
            offset = viewport.rasterToGadgetSpace(
                imath.V2f(self.bound().size() / 2),
                graphGadget).p0 - viewport.rasterToGadgetSpace(
                    at, graphGadget).p0
            bound.setMin(bound.min() + offset)
            bound.setMax(bound.max() + offset)

        self.__gadgetWidget.getViewportGadget().frame(bound)
Esempio n. 27
0
    def test(self):

        targetTranslate = imath.V3f(1, 2, 3)
        constrainedTranslate = imath.V3f(10, 11, 12)
        constrainedScale = imath.V3f(1, 2, 3)
        constrainedRotate = imath.V3f(15, 45, 19)

        plane1 = GafferScene.Plane()
        plane1["transform"]["translate"].setValue(targetTranslate)
        plane1["transform"]["scale"].setValue(imath.V3f(1, 2, 3))
        plane1["transform"]["rotate"].setValue(imath.V3f(
            1000, 20, 39))  # shouldn't affect the result
        plane1["name"].setValue("target")

        plane2 = GafferScene.Plane()
        plane2["transform"]["translate"].setValue(constrainedTranslate)
        plane2["transform"]["scale"].setValue(constrainedScale)
        plane2["transform"]["rotate"].setValue(constrainedRotate)
        plane2["name"].setValue("constrained")

        group = GafferScene.Group()
        group["in"][0].setInput(plane1["out"])
        group["in"][1].setInput(plane2["out"])

        self.assertSceneValid(group["out"])

        constraint = GafferScene.PointConstraint()
        constraint["target"].setValue("/group/target")
        constraint["in"].setInput(group["out"])

        filter = GafferScene.PathFilter()
        filter["paths"].setValue(
            IECore.StringVectorData(["/group/constrained"]))
        constraint["filter"].setInput(filter["out"])

        self.assertSceneValid(constraint["out"])

        self.assertEqual(
            group["out"].fullTransform("/group/target").translation(),
            targetTranslate)
        self.assertEqual(
            group["out"].fullTransform("/group/constrained").translation(),
            constrainedTranslate)

        self.assertEqual(
            constraint["out"].fullTransform("/group/target").translation(),
            targetTranslate)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation(), targetTranslate)

        beforeS, beforeH, beforeR, beforeT = imath.V3f(), imath.V3f(
        ), imath.V3f(), imath.V3f()
        group["out"].fullTransform("/group/constrained").extractSHRT(
            beforeS, beforeH, beforeR, beforeT)

        afterS, afterH, afterR, afterT = imath.V3f(), imath.V3f(), imath.V3f(
        ), imath.V3f()
        constraint["out"].fullTransform("/group/constrained").extractSHRT(
            afterS, afterH, afterR, afterT)

        self.assertEqual(beforeS, afterS)
        self.assertEqual(beforeH, afterH)
        self.assertEqual(beforeR, afterR)

        constraint["xEnabled"].setValue(False)

        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().x, constrainedTranslate.x)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().y, targetTranslate.y)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().z, targetTranslate.z)

        constraint["yEnabled"].setValue(False)

        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().x, constrainedTranslate.x)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().y, constrainedTranslate.y)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().z, targetTranslate.z)

        constraint["zEnabled"].setValue(False)

        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().x, constrainedTranslate.x)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().y, constrainedTranslate.y)
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation().z, constrainedTranslate.z)

        # Test behaviour for missing target
        plane1["name"].setValue("targetX")
        constraint["xEnabled"].setValue(True)
        constraint["yEnabled"].setValue(True)
        constraint["zEnabled"].setValue(True)
        with six.assertRaisesRegex(
                self, RuntimeError,
                'PointConstraint.out.transform : Constraint target does not exist: "/group/target"'
        ):
            constraint["out"].fullTransform("/group/constrained")

        constraint["ignoreMissingTarget"].setValue(True)
        self.assertEqual(constraint["out"].fullTransform("/group/constrained"),
                         constraint["in"].fullTransform("/group/constrained"))

        # Constrain to root
        constraint["target"].setValue("/")
        self.assertEqual(
            constraint["out"].fullTransform(
                "/group/constrained").translation(), imath.V3f(0))

        # No op
        constraint["target"].setValue("")
        self.assertEqual(constraint["out"].fullTransform("/group/constrained"),
                         constraint["in"].fullTransform("/group/constrained"))
Esempio n. 28
0
	def testLength( self ) :

		l = IECore.LineSegment3f( imath.V3f( 1 ), imath.V3f( 2 ) )

		self.assertEqual( l.length(), imath.V3f( 1 ).length() )
		self.assertEqual( l.length2(), imath.V3f( 1 ).length2() )
Esempio n. 29
0
	def testClosestPoints( self ) :

		r = imath.Rand32( 100 )
		for i in range( 0, 1000 ) :

			x = r.nextf( -10, 10 )
			y = r.nextf( -10, 10 )
			z1 = r.nextf( -10, 10 )
			z2 = r.nextf( -10, 10 )

			l1 = IECore.LineSegment3f( imath.V3f( -10, y, z1 ), imath.V3f( 10, y, z1 ) )
			l2 = IECore.LineSegment3f( imath.V3f( x, -10, z2 ), imath.V3f( x, 10, z2 ) )

			p1, p2 = l1.closestPoints( l2 )
			p3, p4 = l2.closestPoints( l1 )

			self.assert_( p1.equalWithAbsError( p4, 0.00001 ) )
			self.assert_( p2.equalWithAbsError( p3, 0.00001 ) )

		# |
		# |
		# |  ------
		# |
		# |
		l1 = IECore.LineSegment3f( imath.V3f( 0, 0, 0 ), imath.V3f( 0, 2, 0 ) )
		l2 = IECore.LineSegment3f( imath.V3f( 1, 1, 0 ), imath.V3f( 3, 1, 0 ) )

		p1, p2 = l1.closestPoints( l2 )
		p3, p4 = l2.closestPoints( l1 )
		self.assertEqual( p1, p4 )
		self.assertEqual( p2, p3 )

		self.assertEqual( p1, imath.V3f( 0, 1, 0 ) )
		self.assertEqual( p2, imath.V3f( 1, 1, 0 ) )

		# \
		#  \
		#
		#  /
		# /

		l1 = IECore.LineSegment3f( imath.V3f( 0, 0, 0 ), imath.V3f( 2, 2, 0 ) )
		l2 = IECore.LineSegment3f( imath.V3f( 0, 5, 0 ), imath.V3f( 2, 3, 0 ) )

		p1, p2 = l1.closestPoints( l2 )
		p3, p4 = l2.closestPoints( l1 )
		self.assertEqual( p1, p4 )
		self.assertEqual( p2, p3 )

		self.assertEqual( p1, imath.V3f( 2, 2, 0 ) )
		self.assertEqual( p2, imath.V3f( 2, 3, 0 ) )
    def testEditSubdivisionAttributes(self):

        script = Gaffer.ScriptNode()

        script["cube"] = GafferScene.Cube()
        script["cube"]["dimensions"].setValue(imath.V3f(2))

        script["meshType"] = GafferScene.MeshType()
        script["meshType"]["in"].setInput(script["cube"]["out"])
        script["meshType"]["meshType"].setValue("catmullClark")

        script["attributes"] = GafferArnold.ArnoldAttributes()
        script["attributes"]["in"].setInput(script["meshType"]["out"])
        script["attributes"]["attributes"]["subdivIterations"][
            "enabled"].setValue(True)

        script["catalogue"] = GafferImage.Catalogue()

        script["outputs"] = GafferScene.Outputs()
        script["outputs"].addOutput(
            "beauty",
            IECoreScene.Output(
                "test", "ieDisplay", "rgba", {
                    "driverType":
                    "ClientDisplayDriver",
                    "displayHost":
                    "localhost",
                    "displayPort":
                    str(script['catalogue'].displayDriverServer().portNumber()
                        ),
                    "remoteDisplayType":
                    "GafferImage::GafferDisplayDriver",
                }))
        script["outputs"]["in"].setInput(script["attributes"]["out"])

        script["imageStats"] = GafferImage.ImageStats()
        script["imageStats"]["in"].setInput(script["catalogue"]["out"])
        script["imageStats"]["channels"].setValue(
            IECore.StringVectorData(["R", "G", "B", "A"]))
        script["imageStats"]["area"].setValue(
            imath.Box2i(imath.V2i(0), imath.V2i(640, 480)))

        script["options"] = GafferScene.StandardOptions()
        script["options"]["in"].setInput(script["outputs"]["out"])
        script["options"]["options"]["filmFit"]["enabled"].setValue(True)
        script["options"]["options"]["filmFit"]["value"].setValue(
            IECoreScene.Camera.FilmFit.Fit)

        script["render"] = self._createInteractiveRender()
        script["render"]["in"].setInput(script["options"]["out"])

        # Render the cube with one level of subdivision. Check we get roughly the
        # alpha coverage we expect.

        script["render"]["state"].setValue(script["render"].State.Running)

        self.uiThreadCallHandler.waitFor(1)

        self.assertAlmostEqual(script["imageStats"]["average"][3].getValue(),
                               0.381,
                               delta=0.001)

        # Now up the number of subdivision levels. The alpha coverage should
        # increase as the shape tends towards the limit surface.

        script["attributes"]["attributes"]["subdivIterations"][
            "value"].setValue(4)
        self.uiThreadCallHandler.waitFor(1)

        self.assertAlmostEqual(script["imageStats"]["average"][3].getValue(),
                               0.424,
                               delta=0.001)

        script["render"]["state"].setValue(script["render"].State.Stopped)