def a() : result = GafferArnold.ArnoldAttributes() result["attributes"]["matte"]["enabled"].setValue( True ) result["attributes"]["matte"]["value"].setValue( True ) return result
def testEditSubdivisionAttributes( self ) : script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() script["cube"]["dimensions"].setValue( IECore.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["outputs"] = GafferScene.Outputs() script["outputs"].addOutput( "beauty", IECoreScene.Display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "subdivisionTest", } ) ) script["outputs"]["in"].setInput( script["attributes"]["out"] ) script["objectToImage"] = GafferImage.ObjectToImage() script["imageStats"] = GafferImage.ImageStats() script["imageStats"]["in"].setInput( script["objectToImage"]["out"] ) script["imageStats"]["channels"].setValue( IECore.StringVectorData( [ "R", "G", "B", "A" ] ) ) script["imageStats"]["area"].setValue( IECore.Box2i( IECore.V2i( 0 ), IECore.V2i( 640, 480 ) ) ) script["render"] = self._createInteractiveRender() script["render"]["in"].setInput( script["outputs"]["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 ) time.sleep( 1 ) script["objectToImage"]["object"].setValue( IECoreImage.ImageDisplayDriver.storedImage( "subdivisionTest" ) ) 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 ) time.sleep( 1 ) script["objectToImage"]["object"].setValue( IECoreImage.ImageDisplayDriver.storedImage( "subdivisionTest" ) ) self.assertAlmostEqual( script["imageStats"]["average"][3].getValue(), 0.424, delta = 0.001 )
def testSerialisation(self): s = Gaffer.ScriptNode() s["a"] = GafferArnold.ArnoldAttributes() s["a"]["attributes"]["cameraVisibility"]["value"].setValue(False) names = s["a"]["attributes"].keys() s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertEqual(s2["a"]["attributes"].keys(), names) self.assertTrue("attributes1" not in s2["a"]) self.assertEqual( s2["a"]["attributes"]["cameraVisibility"]["value"].getValue(), False)
def test(self): p = GafferScene.Plane() a = GafferArnold.ArnoldAttributes() a["in"].setInput(p["out"]) aa = a["out"].attributes("/plane") self.assertEqual(len(aa), 0) a["attributes"]["cameraVisibility"]["enabled"].setValue(True) a["attributes"]["cameraVisibility"]["value"].setValue(False) aa = a["out"].attributes("/plane") self.assertEqual( aa, IECore.CompoundObject( {"ai:visibility:camera": IECore.BoolData(False)}))
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)
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 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 )
def setup_attributes(self, look_idx=0): x = time.time() attribute_count = 0 self["mtlXLook"].setValue(look_idx) if self.mtlx_doc is None: if not self.valid_mtlx(): return # Sets Attributes for idx, look in enumerate(self.mtlx_doc.getLooks()): if look_idx == idx: material_list = self.material_list() # Assigns Visibility attributes attribute_assignment = None for idx, visibility in enumerate(look.getVisibilities()): attrib_list = self.attribute_list() if idx % 8 == 0: attribute_assignment = GafferArnold.ArnoldAttributes() path_filter = GafferScene.PathFilter() attribute_assignment['filter'].setInput(path_filter["out"]) if attrib_list: attribute_assignment["in"].setInput(attrib_list[-1]["out"]) else: if material_list: attribute_assignment["in"].setInput(material_list[-1]["out"]) else: attribute_assignment["in"].setInput(self["in"]) geom_name = visibility.getGeom() path_filter["paths"].setValue(IECore.StringVectorData([geom_name])) self.addChild(attribute_assignment) self.addChild(path_filter) attribute_count += 1 vis_type = visibility.getVisibilityType() is_visible = visibility.getVisible() attributes = attribute_assignment["attributes"] if vis_type == "camera": attributes["cameraVisibility"]["enabled"].setValue(True) attributes["cameraVisibility"]["value"].setValue(is_visible) elif vis_type == "shadow": attributes["shadowVisibility"]["enabled"].setValue(True) attributes["shadowVisibility"]["value"].setValue(is_visible) elif vis_type == "diffuse_transmit": attributes["diffuseTransmissionVisibility"]["enabled"].setValue(True) attributes["diffuseTransmissionVisibility"]["value"].setValue(is_visible) elif vis_type == "specular_transmit": attributes["specularTransmissionVisibility"]["enabled"].setValue(True) attributes["specularTransmissionVisibility"]["value"].setValue(is_visible) elif vis_type == "volume": attributes["volumeVisibility"]["enabled"].setValue(True) attributes["volumeVisibility"]["value"].setValue(is_visible) elif vis_type == "diffuse_reflect": attributes["diffuseReflectionVisibility"]["enabled"].setValue(True) attributes["diffuseReflectionVisibility"]["value"].setValue(is_visible) elif vis_type == "specular_reflect": attributes["specularReflectionVisibility"]["enabled"].setValue(True) attributes["specularReflectionVisibility"]["value"].setValue(is_visible) elif vis_type == "subsurface": attributes["subsurfaceVisibility"]["enabled"].setValue(True) attributes["subsurfaceVisibility"]["value"].setValue(is_visible) if attribute_assignment is not None: self["out"].setInput(attribute_assignment["out"]) logger.info("%s Loaded %d attributes in %.2f seconds" % (self.getName(), attribute_count, time.time() - x))
def testEditSubdivisionAttributes(self): script = Gaffer.ScriptNode() script["cube"] = GafferScene.Cube() script["cube"]["dimensions"].setValue(IECore.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["outputs"] = GafferScene.Outputs() script["outputs"].addOutput( "beauty", IECore.Display( "test", "ieDisplay", "rgba", { "driverType": "ClientDisplayDriver", "displayType": "IECore::ClientDisplayDriver", "displayHost": "localhost", "displayPort": "2500", "remoteDisplayType": "GafferImage::GafferDisplayDriver", })) script["outputs"]["in"].setInput(script["attributes"]["out"]) # Emulate the connection the UI makes, so the Display knows someone is listening and # it needs to actually make servers. dataReceivedConnection = GafferImage.Display.dataReceivedSignal( ).connect(lambda plug: None) script["display"] = GafferImage.Display() script["display"]["port"].setValue(2500) script["imageStats"] = GafferImage.ImageStats() script["imageStats"]["in"].setInput(script["display"]["out"]) script["imageStats"]["channels"].setValue( IECore.StringVectorData(["R", "G", "B", "A"])) script["imageStats"]["area"].setValue( IECore.Box2i(IECore.V2i(0), IECore.V2i(640, 480))) script["render"] = self._createInteractiveRender() script["render"]["in"].setInput(script["outputs"]["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) time.sleep(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) time.sleep(1) self.assertAlmostEqual(script["imageStats"]["average"][3].getValue(), 0.424, delta=0.001)