def testBooleanPrimitiveVariable( self ) : p = IECore.PointsPrimitive( IECore.V3fVectorData( 10 ) ) p["truePrimVar"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.BoolData( True ) ) p["falsePrimVar"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.BoolData( False ) ) with IECoreArnold.UniverseBlock( writable = True ) : n = IECoreArnold.NodeAlgo.convert( p ) self.assertEqual( arnold.AiNodeGetBool( n, "truePrimVar" ), True ) self.assertEqual( arnold.AiNodeGetBool( n, "falsePrimVar" ), False )
def testAdaptors( self ) : sphere = GafferScene.Sphere() def a() : result = GafferArnold.ArnoldAttributes() result["attributes"]["matte"]["enabled"].setValue( True ) result["attributes"]["matte"]["value"].setValue( True ) return result GafferScene.RendererAlgo.registerAdaptor( "Test", a ) sphere = GafferScene.Sphere() render = GafferArnold.ArnoldRender() render["in"].setInput( sphere["out"] ) render["mode"].setValue( render.Mode.SceneDescriptionMode ) render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" ) render["task"].execute() with IECoreArnold.UniverseBlock( writable = True ) : arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" ) node = arnold.AiNodeLookUpByName( "/sphere" ) self.assertEqual( arnold.AiNodeGetBool( node, "matte" ), True )
def testPrimitiveVariables( self ) : s = IECore.SpherePrimitive() s["v"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.V3f( 1, 2, 3 ) ) s["c"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.Color3f( 1, 2, 3 ) ) s["s"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, "test" ) s["i"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, 11 ) s["b"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, True ) s["f"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, 2.5 ) s["m"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.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] ], )
def testNoLinkedLightsOnLights(self): sphere = GafferScene.Sphere() meshLightShader = GafferArnold.ArnoldShader() meshLightShader.loadShader("flat") meshLightFilter = GafferScene.PathFilter() meshLightFilter["paths"].setValue(IECore.StringVectorData(["/sphere"])) meshLight = GafferArnold.ArnoldMeshLight() meshLight["in"].setInput(sphere["out"]) meshLight["filter"].setInput(meshLightFilter["out"]) meshLight["parameters"]["color"].setInput(meshLightShader["out"]) light1 = GafferArnold.ArnoldLight() light1.loadShader("point_light") light2 = GafferArnold.ArnoldLight() light2.loadShader("point_light") # Trigger light linking by unlinking a light light2["defaultLight"].setValue(False) group = GafferScene.Group() group["in"][0].setInput(meshLight["out"]) group["in"][1].setInput(light1["out"]) group["in"][2].setInput(light2["out"]) render = GafferArnold.ArnoldRender() render["in"].setInput(group["out"]) render["mode"].setValue(render.Mode.SceneDescriptionMode) render["fileName"].setValue(self.temporaryDirectory() + "/test.ass") render["task"].execute() with IECoreArnold.UniverseBlock(writable=True): arnold.AiASSLoad(self.temporaryDirectory() + "/test.ass") sphere = arnold.AiNodeLookUpByName("/group/sphere") self.assertIsNotNone(sphere) self.assertEqual( arnold.AiArrayGetNumElements( arnold.AiNodeGetArray(sphere, "light_group")), 0) self.assertFalse(arnold.AiNodeGetBool(sphere, "use_light_group"))
def Init(procName): proc = arnold.AiNodeLookUpByName(procName) if not proc: print("No such procedural: %s" % procName) return (0, None) attrs = {} it = arnold.AiNodeGetUserParamIterator(proc) while not arnold.AiUserParamIteratorFinished(it): param = arnold.AiUserParamIteratorGetNext(it) pname = arnold.AiUserParamGetName(param) pcat = arnold.AiUserParamGetCategory(param) if pcat == arnold.AI_USERDEF_CONSTANT: ptype = arnold.AiUserParamGetType(param) pval = None if ptype == arnold.AI_TYPE_BOOLEAN: pval = arnold.AiNodeGetBool(proc, pname) elif ptype == arnold.AI_TYPE_INT: pval = arnold.AiNodeGetInt(proc, pname) elif ptype == arnold.AI_TYPE_UINT: pval = arnold.AiNodeGetUInt(proc, pname) elif ptype == arnold.AI_TYPE_FLOAT: pval = arnold.AiNodeGetFlt(proc, pname) elif ptype == arnold.AI_TYPE_POINT: pval = arnold.AiNodeGetPnt(proc, pname) elif ptype == arnold.AI_TYPE_POINT2: pval = arnold.AiNodeGetPnt2(proc, pname) elif ptype == arnold.AI_TYPE_VECTOR: pval = arnold.AiNodeGetVec(proc, pname) elif ptype == arnold.AI_TYPE_RGB: pval = arnold.AiNodeGetRGB(proc, pname) elif ptype == arnold.AI_TYPE_RGBA: pval = arnold.AiNodeGetRGBA(proc, pname) elif ptype == arnold.AI_TYPE_STRING: pval = arnold.AiNodeGetStr(proc, pname) if pval != None: attrs[pname] = (ptype, pval) else: print("Unsupported type (%d) for parameter \"%s\"" % (ptype, pname)) else: print("Ignore non constant parameter \"%s\"" % pname) arnold.AiUserParamIteratorFinished(it) return (1, attrs)
def testDefaultLightsMistakesDontForceLinking(self): light = GafferArnold.ArnoldLight() light.loadShader("point_light") sphere = GafferScene.Sphere() # It doesn't make sense to add a non-light to the "defaultLights" # set like this, but in the event of user error, we don't want to # emit light links unnecessarily. sphereSet = GafferScene.Set() sphereSet["in"].setInput(sphere["out"]) sphereSet["name"].setValue("defaultLights") sphereSet["paths"].setValue(IECore.StringVectorData(["/sphere"])) group = GafferScene.Group() group["in"][0].setInput(light["out"]) group["in"][1].setInput(sphereSet["out"]) render = GafferArnold.ArnoldRender() render["in"].setInput(group["out"]) render["mode"].setValue(render.Mode.SceneDescriptionMode) render["fileName"].setValue(self.temporaryDirectory() + "/test.ass") render["task"].execute() with IECoreArnold.UniverseBlock(writable=True): arnold.AiASSLoad(self.temporaryDirectory() + "/test.ass") sphere = arnold.AiNodeLookUpByName("/group/sphere") self.assertIsNotNone(sphere) self.assertEqual( arnold.AiArrayGetNumElements( arnold.AiNodeGetArray(sphere, "light_group")), 0) self.assertFalse(arnold.AiNodeGetBool(sphere, "use_light_group"))
def testLightAndShadowLinking( self ) : sphere1 = GafferScene.Sphere() sphere2 = GafferScene.Sphere() attributes = GafferScene.StandardAttributes() arnoldAttributes = GafferArnold.ArnoldAttributes() light1 = GafferArnold.ArnoldLight() light1.loadShader( "point_light" ) light2 = GafferArnold.ArnoldLight() light2.loadShader( "point_light" ) group = GafferScene.Group() render = GafferArnold.ArnoldRender() attributes["in"].setInput( sphere1["out"] ) arnoldAttributes["in"].setInput( attributes["out"] ) group["in"][0].setInput( arnoldAttributes["out"] ) group["in"][1].setInput( light1["out"] ) group["in"][2].setInput( light2["out"] ) group["in"][3].setInput( sphere2["out"] ) render["in"].setInput( group["out"] ) # Illumination attributes["attributes"]["linkedLights"]["enabled"].setValue( True ) attributes["attributes"]["linkedLights"]["value"].setValue( "/group/light" ) # Shadows arnoldAttributes["attributes"]["shadowGroup"]["enabled"].setValue( True ) arnoldAttributes["attributes"]["shadowGroup"]["value"].setValue( "/group/light1" ) render["mode"].setValue( render.Mode.SceneDescriptionMode ) render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" ) render["task"].execute() with IECoreArnold.UniverseBlock( writable = True ) : arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" ) # the first sphere had linked lights sphere = arnold.AiNodeLookUpByName( "/group/sphere" ) # check illumination self.assertTrue( arnold.AiNodeGetBool( sphere, "use_light_group" ) ) lights = arnold.AiNodeGetArray( sphere, "light_group" ) self.assertEqual( arnold.AiArrayGetNumElements( lights ), 1 ) self.assertEqual( arnold.AiNodeGetName( arnold.AiArrayGetPtr( lights, 0 ) ), "light:/group/light" ) # check shadows self.assertTrue( arnold.AiNodeGetBool( sphere, "use_shadow_group" ) ) shadows = arnold.AiNodeGetArray( sphere, "shadow_group" ) self.assertEqual( arnold.AiArrayGetNumElements( shadows ), 1 ) self.assertEqual( arnold.AiNodeGetName( arnold.AiArrayGetPtr( shadows, 0 ) ), "light:/group/light1" ) # the second sphere does not have any light linking enabled sphere1 = arnold.AiNodeLookUpByName( "/group/sphere1" ) # check illumination self.assertFalse( arnold.AiNodeGetBool( sphere1, "use_light_group" ) ) lights = arnold.AiNodeGetArray( sphere1, "light_group" ) self.assertEqual( arnold.AiArrayGetNumElements( lights ), 0 ) # check shadows self.assertFalse( arnold.AiNodeGetBool( sphere1, "use_shadow_group" ) ) shadows = arnold.AiNodeGetArray( sphere1, "shadow_group" ) self.assertEqual( arnold.AiArrayGetNumElements( shadows ), 0 )
def get_bool(self, param): if not self.is_valid(): return None return arnold.AiNodeGetBool(self.data, param)
def testLightAndShadowLinking( self ) : sphere1 = GafferScene.Sphere() sphere2 = GafferScene.Sphere() attributes = GafferScene.StandardAttributes() arnoldAttributes = GafferArnold.ArnoldAttributes() light1 = GafferArnold.ArnoldLight() light1.loadShader( "point_light" ) light2 = GafferArnold.ArnoldLight() light2.loadShader( "point_light" ) group = GafferScene.Group() group["in"].addChild( GafferScene.ScenePlug( "in1" ) ) group["in"].addChild( GafferScene.ScenePlug( "in2" ) ) group["in"].addChild( GafferScene.ScenePlug( "in3" ) ) group["in"].addChild( GafferScene.ScenePlug( "in4" ) ) evaluate = GafferScene.EvaluateLightLinks() render = GafferArnold.ArnoldRender() attributes["in"].setInput( sphere1["out"] ) arnoldAttributes["in"].setInput( attributes["out"] ) group["in"]["in1"].setInput( arnoldAttributes["out"] ) group["in"]["in2"].setInput( light1["out"] ) group["in"]["in3"].setInput( light2["out"] ) group["in"]["in4"].setInput( sphere2["out"] ) evaluate["in"].setInput( group["out"] ) render["in"].setInput( evaluate["out"] ) # Illumination attributes["attributes"]["linkedLights"]["enabled"].setValue( True ) attributes["attributes"]["linkedLights"]["value"].setValue( "/group/light /group/light1" ) # Shadows arnoldAttributes["attributes"]["shadowGroup"]["enabled"].setValue( True ) arnoldAttributes["attributes"]["shadowGroup"]["value"].setValue( "/group/light /group/light1" ) # make sure we pass correct data into the renderer self.assertEqual( set( render["in"].attributes( "/group/sphere" )["linkedLights"] ), set( IECore.StringVectorData( ["/group/light", "/group/light1"] ) ) ) self.assertEqual( set( render["in"].attributes( "/group/sphere" )["ai:visibility:shadow_group"] ), set( IECore.StringVectorData( ["/group/light", "/group/light1"] ) ) ) render["mode"].setValue( render.Mode.SceneDescriptionMode ) render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" ) render["task"].execute() with IECoreArnold.UniverseBlock( writable = True ) : arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" ) # the first sphere had linked lights sphere = arnold.AiNodeLookUpByName( "/group/sphere" ) # check illumination lights = arnold.AiNodeGetArray( sphere, "light_group" ) lightNames = [] for i in range( arnold.AiArrayGetNumElements( lights.contents ) ): light = arnold.cast(arnold.AiArrayGetPtr(lights, i), arnold.POINTER(arnold.AtNode)) lightNames.append( arnold.AiNodeGetName(light.contents) ) doLinking = arnold.AiNodeGetBool( sphere, "use_light_group" ) self.assertEqual( set( lightNames ), { "light:/group/light", "light:/group/light1" } ) self.assertEqual( doLinking, True ) # check shadows shadows = arnold.AiNodeGetArray( sphere, "shadow_group" ) lightNames = [] for i in range( arnold.AiArrayGetNumElements( shadows.contents ) ): light = arnold.cast(arnold.AiArrayGetPtr(shadows, i), arnold.POINTER(arnold.AtNode)) lightNames.append( arnold.AiNodeGetName(light.contents) ) doLinking = arnold.AiNodeGetBool( sphere, "use_shadow_group" ) self.assertEqual( set( lightNames ), { "light:/group/light", "light:/group/light1" } ) self.assertEqual( doLinking, True ) # the second sphere does not have any light linking enabled sphere1 = arnold.AiNodeLookUpByName( "/group/sphere1" ) # check illumination lights = arnold.AiNodeGetArray( sphere1, "light_group" ) lightNames = [] for i in range( arnold.AiArrayGetNumElements( lights.contents ) ): light = arnold.cast(arnold.AiArrayGetPtr(lights, i), arnold.POINTER(arnold.AtNode)) lightNames.append( arnold.AiNodeGetName(light.contents) ) doLinking = arnold.AiNodeGetBool( sphere1, "use_light_group" ) self.assertEqual( lightNames, [] ) self.assertEqual( doLinking, False ) # check shadows shadows = arnold.AiNodeGetArray( sphere1, "shadow_group" ) lightNames = [] for i in range( arnold.AiArrayGetNumElements( shadows.contents ) ): light = arnold.cast(arnold.AiArrayGetPtr(shadows, i), arnold.POINTER(arnold.AtNode)) lightNames.append( arnold.AiNodeGetName(light.contents) ) doLinking = arnold.AiNodeGetBool( sphere1, "use_shadow_group" ) self.assertEqual( lightNames, [] ) self.assertEqual( doLinking, False )