def setUp(self):
        self.output_file_name = os.path.join(tempfile.gettempdir(),
                                             "result.exr")

        ai.AiBegin()
        ai.AiMsgSetConsoleFlags(ai.AI_LOG_NONE)
        ai.AiMsgSetConsoleFlags(ai.AI_LOG_WARNINGS | ai.AI_LOG_ERRORS)

        options = ai.AiUniverseGetOptions()
        ai.AiNodeSetBool(options, "skip_license_check", True)
        ai.AiNodeSetInt(options, "xres", 16)
        ai.AiNodeSetInt(options, "yres", 16)

        self.my_camera = ai.AiNode("persp_camera", "my_camera", None)
        self.my_filter = ai.AiNode("gaussian_filter", "my_filter", None)
        self.my_driver = ai.AiNode("driver_exr", "my_driver", None)
        self.my_cryptomatte = ai.AiNode("cryptomatte", "my_cryptomatte", None)

        ai.AiNodeSetStr(self.my_driver, "filename", self.output_file_name)
        ai.AiNodeSetPtr(options, "aov_shaders", self.my_cryptomatte)

        self.assertTrue(
            self.my_cryptomatte,
            ("Cryptomatte node could not be created, plugin may not be "
             "loaded in Python. (There may be binary compatibily issues "
             "with Python). "))
Example #2
0
    def testDoubleData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard")

            IECoreArnold.ParameterAlgo.setParameter(n, "Kd",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "Kd"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(n, "customFloat",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "customFloat"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(
                n, "customMatrix",
                IECore.M44dData(
                    IECore.M44d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                                15, 16)))
            m = arnold.AtMatrix()
            arnold.AiNodeGetMatrix(n, "customMatrix", m)
            self.assertEqual(
                [getattr(m, f[0]) for f in m._fields_],
                [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
            )
Example #3
0
    def testIntData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard_surface")
            IECoreArnold.ParameterAlgo.setParameter(n, "customInt",
                                                    IECore.IntData(42))
            IECoreArnold.ParameterAlgo.setParameter(n, "customUInt",
                                                    IECore.UIntData(43))
            IECoreArnold.ParameterAlgo.setParameter(
                n, "customIntVectorData", IECore.IntVectorData([5, 6, 7]))
            IECoreArnold.ParameterAlgo.setParameter(
                n, "customUIntVectorData",
                IECore.UIntVectorData([12, 2147483649]))

            self.assertEqual(arnold.AiNodeGetInt(n, "customInt"), 42)
            self.assertEqual(arnold.AiNodeGetUInt(n, "customUInt"), 43)
            a = arnold.AiNodeGetArray(n, "customIntVectorData")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 3)
            self.assertEqual(arnold.AiArrayGetInt(a, 0), 5)
            self.assertEqual(arnold.AiArrayGetInt(a, 1), 6)
            self.assertEqual(arnold.AiArrayGetInt(a, 2), 7)
            a = arnold.AiNodeGetArray(n, "customUIntVectorData")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 2)
            self.assertEqual(arnold.AiArrayGetUInt(a, 0), 12)
            self.assertEqual(arnold.AiArrayGetUInt(a, 1), 2147483649)
Example #4
0
    def testDoubleData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard_surface")

            IECoreArnold.ParameterAlgo.setParameter(n, "base",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "base"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(n, "customFloat",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "customFloat"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(
                n, "customMatrix",
                IECore.M44dData(
                    imath.M44d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                               15, 16)))
            m = arnold.AiNodeGetMatrix(n, "customMatrix")
            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]
                 ],
            )
Example #5
0
    def testReferenceExistingShader(self):

        r = IECoreArnold.Renderer()

        r.display("test", "ieDisplay", "rgba", {
            "driverType": "ImageDisplayDriver",
            "handle": "test"
        })

        with IECore.WorldBlock(r):

            shader = arnold.AiNode("standard")
            arnold.AiNodeSetStr(shader, "name", "red_shader")
            arnold.AiNodeSetFlt(shader, "emission", 1)
            arnold.AiNodeSetRGB(shader, "emission_color", 1, 0, 0)

            r.shader("surface", "reference:red_shader", {})
            r.sphere(1, -1, 1, 360, {})

        image = IECoreImage.ImageDisplayDriver.removeStoredImage("test")

        dimensions = image.dataWindow.size() + IECore.V2i(1)
        index = dimensions.x * int(dimensions.y * 0.5) + int(
            dimensions.x * 0.5)
        self.assertAlmostEqual(image["A"][index], 1, 5)
        self.assertAlmostEqual(image["R"][index], 1, 5)
        self.assertEqual(image["G"][index], 0)
        self.assertEqual(image["B"][index], 0)
Example #6
0
    def _outputWorldProcedural(self, scenePlug, renderer):

        import arnold

        node = arnold.AiNode("procedural")
        arnold.AiNodeSetStr(node, "dso", "ieProcedural.so")

        arnold.AiNodeSetPnt(node, "min", -1e30, -1e30, -1e30)
        arnold.AiNodeSetPnt(node, "max", 1e30, 1e30, 1e30)

        arnold.AiNodeDeclare(node, "className", "constant STRING")
        arnold.AiNodeDeclare(node, "classVersion", "constant INT")
        arnold.AiNodeDeclare(node, "parameterValues", "constant ARRAY STRING")

        arnold.AiNodeSetStr(node, "className", "gaffer/script")
        arnold.AiNodeSetInt(node, "classVersion", 1)

        scriptNode = scenePlug.node().scriptNode()
        parameterValues = [
            "-fileName",
            scriptNode["fileName"].getValue(),
            "-node",
            scenePlug.node().relativeName(scriptNode),
            "-frame",
            str(Gaffer.Context.current().getFrame()),
        ]
        stringArray = arnold.AiArrayAllocate(len(parameterValues), 1,
                                             arnold.AI_TYPE_STRING)
        for i in range(0, len(parameterValues)):
            arnold.AiArraySetStr(stringArray, i, parameterValues[i])
        arnold.AiNodeSetArray(node, "parameterValues", stringArray)
Example #7
0
	def testReferenceExistingShader( self ) :
	
		r = IECoreArnold.Renderer()
		
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )

		with IECore.WorldBlock( r ) :
		
			shader = arnold.AiNode( "standard" )
			arnold.AiNodeSetStr( shader, "name", "red_shader" )
			arnold.AiNodeSetFlt( shader, "emission", 1 )
			arnold.AiNodeSetRGB( shader, "emission_color", 1, 0, 0 )
			
			r.shader( "surface", "reference:red_shader", {} )
			r.sphere( 1, -1, 1, 360, {} )

		image = IECore.ImageDisplayDriver.removeStoredImage( "test" )

		e = IECore.PrimitiveEvaluator.create( image )
		result = e.createResult()
		e.pointAtUV( IECore.V2f( 0.5, 0.5 ), result )
		self.assertAlmostEqual( result.floatPrimVar( e.A() ), 1, 5 )
		self.assertAlmostEqual( result.floatPrimVar( e.R() ), 1, 5 )
		self.assertEqual( result.floatPrimVar( e.G() ), 0 )
		self.assertEqual( result.floatPrimVar( e.B() ), 0 )	
Example #8
0
	def testConverterResultType( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			p = IECore.PointsPrimitive( IECore.V3fVectorData( [ IECore.V3f( i ) for i in range( 0, 10 ) ] ) )
			n = IECoreArnold.NodeAlgo.convert( p )

			self.failUnless( type( n ) is type( arnold.AiNode( "points" ) ) )
Example #9
0
	def testConverterResultType( 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.assertTrue( type( n ) is type( arnold.AiNode( "points" ) ) )
	def testConverterResultType( self ) :
	
		with IECoreArnold.UniverseBlock() :
		
			p = IECore.PointsPrimitive( IECore.V3fVectorData( [ IECore.V3f( i ) for i in range( 0, 10 ) ] ) )
			c = IECoreArnold.ToArnoldPointsConverter( p )
			n = c.convert()
		
			self.failUnless( type( n ) is type( arnold.AiNode( "points" ) ) )
Example #11
0
    def testReadOnlyUniverseDoesntPreventWritableUniverseCleanup(self):

        with IECoreArnold.UniverseBlock(writable=False):

            with IECoreArnold.UniverseBlock(writable=True):

                node = arnold.AiNode("polymesh")
                arnold.AiNodeSetStr(node, "name", "test")

            self.assertEqual(arnold.AiNodeLookUpByName("test"), None)
Example #12
0
	def testStringArray( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = arnold.AiNode( "polymesh" )
			IECoreArnold.ParameterAlgo.setParameter( n, "trace_sets", IECore.StringVectorData( [ "a", "b" ] ) )

			a = arnold.AiNodeGetArray( n, "trace_sets" )
			self.assertEqual( arnold.AiArrayGetNumElements( a.contents ), 2 )
			self.assertEqual( arnold.AiArrayGetStr( a, 0 ), "a" )
			self.assertEqual( arnold.AiArrayGetStr( a, 1 ), "b" )
Example #13
0
	def testVectorIntData( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = arnold.AiNode( "standard_surface" )

			IECoreArnold.ParameterAlgo.setParameter( n, "customV2i", IECore.V2iData( IECore.V2i( 3, 4 ) ) )
			self.assertEqual( arnold.AiNodeGetVec2( n, "customV2i" ), arnold.AtVector2( 3, 4 ) )

			IECoreArnold.ParameterAlgo.setParameter( n, "customV3i", IECore.V3iData( IECore.V3i( 3, 4, 5 ) ) )
			self.assertEqual( arnold.AiNodeGetVec( n, "customV3i" ), arnold.AtVector( 3, 4, 5 ) )
Example #14
0
	def testSetParameter( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = arnold.AiNode( "standard_surface" )

			IECoreArnold.ParameterAlgo.setParameter( n, "base", IECore.FloatData( 0.25 ) )
			IECoreArnold.ParameterAlgo.setParameter( n, "customString", IECore.StringData( "test" ) )

			self.assertEqual( arnold.AiNodeGetFlt( n, "base" ), 0.25 )
			self.assertEqual( arnold.AiNodeGetStr( n, "customString" ), "test" )
Example #15
0
    def testSetParameter(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard")

            IECoreArnold.ParameterAlgo.setParameter(n, "Kd",
                                                    IECore.FloatData(0.25))
            IECoreArnold.ParameterAlgo.setParameter(n, "aov_emission",
                                                    IECore.StringData("test"))

            self.assertEqual(arnold.AiNodeGetFlt(n, "Kd"), 0.25)
            self.assertEqual(arnold.AiNodeGetStr(n, "aov_emission"), "test")
Example #16
0
    def testGetParameter(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard")

            self.assertEqual(IECoreArnold.ParameterAlgo.getParameter(n, "Kd"),
                             IECore.FloatData(arnold.AiNodeGetFlt(n, "Kd")))

            self.assertEqual(
                IECoreArnold.ParameterAlgo.getParameter(n, "aov_emission"),
                IECore.StringData("emission"),
            )
Example #17
0
    def testGetParameter(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard_surface")

            self.assertEqual(
                IECoreArnold.ParameterAlgo.getParameter(n, "base"),
                IECore.FloatData(arnold.AiNodeGetFlt(n, "base")))

            IECore.FloatData(arnold.AiNodeSetStr(n, "name", "testString"))
            self.assertEqual(
                IECoreArnold.ParameterAlgo.getParameter(n, "name"),
                IECore.StringData("testString"),
            )
def createLight(lightType, name, attributes):
	""" Method to create a light 

		This method takes the type,name,attributes 
		and creates a light

		Args:
			lightType(string): The light type
			name(string): The name of the light
			attributes(dict): The dictionary with attribute name, (type,value)
		Returns:
			light(AiNode): Returns the light created with the attributes set
	"""
	light = arnold.AiNode(lightType)
	arnold.AiNodeSetStr(light, "name", name)
	assignAttributes(light, attributes)
	return light
def createCamera(cameraType, name, attributes):
	""" Method to create a camera 

		This method takes the type,name,attributes 
		and creates a camera

		Args:
			cameraType(string): The camera type
			name(string): The name of the camera
			attributes(dict): The dictionary with attribute name, (type,value)

		Returns:
			camera(AiNode): Returns the camera created with the attributes set
	"""
	camera = arnold.AiNode(cameraType)
	arnold.AiNodeSetStr(camera, "name", name)
	assignAttributes(camera, attributes)
	return camera
def createOutputDriver(driverType, name, attributes):
	""" Method to create an output driver with the specified type

		This method takes the type,name,attributes 
		and creates an output driver

		Args:
			driverType(string): The driver type
			name(string): The name of the driver
			attributes(dict): The dictionary with attribute name, (type,value)

		Returns:
			driver(AiNode): Returns the driver created with the attributes set
	"""
	driver = arnold.AiNode(driverType)
	arnold.AiNodeSetStr(driver, "name", name)
	assignAttributes(driver, attributes)
	return driver
def createFilter(filterType, name, attributes):
	""" Method to create a filter with the specified type

		This method takes the type,name,attributes 
		and creates an image filter

		Args:
			filterType(string): The filter type
			name(string): The name of the filter
			attributes(dict): The dictionary with attribute name, (type,value)

		Returns:
			filter(AiNode): Returns the filter created with the attributes set
	"""
	filter = arnold.AiNode(filterType)
	arnold.AiNodeSetStr(filter, "name", name)
	assignAttributes(filter, attributes)
	return filter
def createGeometry(geo, name, attributes):
	""" Method to create a geometry 

		This method takes the type,name,attributes 
		and creates a geometry

		Args:
			geo(string): The geometry type
			name(string): The name of the geometry
			attributes(dict): The dictionary with attribute name, (type,value)

		Returns:
			geometry(AiNode): Returns the geometry created with the attributes set
	"""
	geometry = arnold.AiNode(geo)
	arnold.AiNodeSetStr(geometry, "name", name)
	assignAttributes(geometry, attributes)
	return geometry
def createSimpleShader(shaderType, name, attributes):
	""" Method to create a shader 

		This method takes the type,name,attributes  
		and creates a shader

		Args:
			shaderType(string): The shader type
			name(string): The name of the geometry
			attributes(dict): The dictionary with attribute name, (type,value)

		Returns:
			shader(AiNode): Returns the shader created with the attributes set
	"""
	shader = arnold.AiNode(shaderType)
	arnold.AiNodeSetStr(shader, "name", name)
	assignAttributes(shader, attributes)
	return shader
Example #24
0
def GetNode(user_data, i):
    ptype, pval = user_data.get("type")
    n = arnold.AiNode(pval)
    if n:
        name = "sample_%s" % pval
        arnold.AiNodeSetStr(n, "name", name)
        ne = arnold.AiNodeGetNodeEntry(n)
        for k, v in user_data.iteritems():
            if k == "type":
                continue
            ptype, pval = v
            pe = arnold.AiNodeEntryLookUpParameter(ne, k)
            if pe:
                if ptype == arnold.AI_TYPE_BOOLEAN:
                    arnold.AiNodeSetBool(n, k, pval)
                elif ptype == arnold.AI_TYPE_INT:
                    arnold.AiNodeSetInt(n, k, pval)
                elif ptype == arnold.AI_TYPE_UINT:
                    arnold.AiNodeSetUInt(n, k, pval)
                elif ptype == arnold.AI_TYPE_FLOAT:
                    arnold.AiNodeSetFlt(n, k, pval)
                elif ptype == arnold.AI_TYPE_POINT:
                    arnold.AiNodeSetPnt(n, k, pval.x, pval.y, pval.z)
                elif ptype == arnold.AI_TYPE_POINT2:
                    arnold.AiNodeSetPnt2(n, k, pval.x, pval.y)
                elif ptype == arnold.AI_TYPE_VECTOR:
                    arnold.AiNodeSetVec(n, k, pval.x, pval.y, pval.z)
                elif ptype == arnold.AI_TYPE_RGB:
                    arnold.AiNodeSetRGB(n, k, pval.r, pval.g, pval.b)
                elif ptype == arnold.AI_TYPE_RGBA:
                    arnold.AiNodeSetRGBA(n, k, pval.r, pval.g, pval.b, pval.a)
                elif ptype == arnold.AI_TYPE_STRING:
                    arnold.AiNodeSetStr(n, k, pval)
        return name
    else:
        return None
Example #25
0
    def __init__(self, node_type=None):
        super().__init__()

        if node_type is not None:
            self.data = arnold.AiNode(node_type)
Example #26
0
    def renderGeo(self):

        arnold.AiBegin()

        arnold.AiMsgSetLogFileName(self._logFile)
        arnold.AiMsgSetConsoleFlags(arnold.AI_LOG_ALL)

        # create a sphere geometric primitive
        sph = arnold.AiNode("sphere")
        arnold.AiNodeSetStr(sph, "name", "mysphere")
        arnold.AiNodeSetVec(sph, "center", 0.0, 4.0, 0.0)
        arnold.AiNodeSetFlt(sph, "radius", 5.0)

        # create a red standard shader
        shader1 = arnold.AiNode("standard")
        arnold.AiNodeSetStr(shader1, "name", "myshader1")
        arnold.AiNodeSetRGB(shader1, "Kd_color", self._color[0],
                            self._color[1], self._color[2])
        arnold.AiNodeSetFlt(shader1, "Ks", 0.05)

        # assign the shaders to the geometric objects
        arnold.AiNodeSetPtr(sph, "shader", shader1)

        # create a perspective camera
        camera = arnold.AiNode("persp_camera")
        arnold.AiNodeSetStr(camera, "name", "mycamera")
        # position the camera (alternatively you can set 'matrix')
        arnold.AiNodeSetVec(camera, "position", 0.0, 10.0, 35.0)
        arnold.AiNodeSetVec(camera, "look_at", 0.0, 3.0, 0.0)
        arnold.AiNodeSetFlt(camera, "fov", 45.0)

        # create a point light source
        light = arnold.AiNode("point_light")
        arnold.AiNodeSetStr(light, "name", "pointLight_A")
        # // position the light (alternatively use 'matrix')
        arnold.AiNodeSetVec(light, "position", 0.0, 30.0, 0.0)
        arnold.AiNodeSetFlt(light, "intensity", 10.0)
        # alternatively, use 'exposure'
        arnold.AiNodeSetFlt(light, "radius", 4.0)
        # for soft shadows

        # create a point light source
        light = arnold.AiNode("point_light")
        arnold.AiNodeSetStr(light, "name", "pointLight_B")
        # // position the light (alternatively use 'matrix')
        arnold.AiNodeSetVec(light, "position", 0.0, -30.0, 0.0)
        arnold.AiNodeSetFlt(light, "intensity", 10.0)
        # alternatively, use 'exposure'
        arnold.AiNodeSetFlt(light, "radius", 4.0)
        # for soft shadows

        # create a point light source
        light = arnold.AiNode("point_light")
        arnold.AiNodeSetStr(light, "name", "pointLight_C")
        # // position the light (alternatively use 'matrix')
        arnold.AiNodeSetVec(light, "position", 0.0, 4.0, 20.0)
        arnold.AiNodeSetFlt(light, "intensity", 5.0)
        # alternatively, use 'exposure'
        arnold.AiNodeSetFlt(light, "radius", 15.0)
        # for soft shadows

        # // get the global options node and set some options
        options = arnold.AiUniverseGetOptions()
        arnold.AiNodeSetInt(options, "AA_samples", 8)
        arnold.AiNodeSetInt(options, "xres", 480)
        arnold.AiNodeSetInt(options, "yres", 360)
        arnold.AiNodeSetInt(options, "GI_diffuse_depth", 4)
        # // set the active camera (optional, since there is only one camera)
        arnold.AiNodeSetPtr(options, "camera", camera)

        # create an output driver node
        driver = arnold.AiNode("driver_jpeg")
        arnold.AiNodeSetStr(driver, "name", "mydriver")
        arnold.AiNodeSetStr(driver, "filename", self._sceneName)
        arnold.AiNodeSetFlt(driver, "gamma", 2.2)

        # create a gaussian filter node
        filter = arnold.AiNode("gaussian_filter")
        arnold.AiNodeSetStr(filter, "name", "myfilter")

        # assign the driver and filter to the main (beauty) AOV,
        # which is called "RGBA" and is of type RGBA
        outputs_array = arnold.AiArrayAllocate(1, 1, arnold.AI_TYPE_STRING)
        arnold.AiArraySetStr(outputs_array, 0, "RGBA RGBA myfilter mydriver")
        arnold.AiNodeSetArray(options, "outputs", outputs_array)

        # finally, render the image!
        arnold.AiRender(arnold.AI_RENDER_MODE_CAMERA)

        # // Arnold session shutdown
        arnold.AiEnd()
Example #27
0
	def renderGeo(self):
		""" This method calls the arnold functions to setup and scene and render the image
		"""

		arnold.AiBegin()

		arnold.AiMsgSetLogFileName(self.log)
		arnold.AiMsgSetConsoleFlags(arnold.AI_LOG_ALL)

		attributes = {
			"Kd_color": ("rgb", (self._color[0], self._color[1], self._color[2])),
			"Ks": ("float", 0.05),
			"Ko": ("float", .5),
		}
		shader = createSimpleShader("standard", "myshader1", attributes)

		attributes = {
			"center": ("vector", (0.0, 4.0, 0.0)),
			"radius": ("float", 5.0),
			"shader": ("pointer", shader)
		}
		sph = createGeometry("sphere", "mysphere", attributes)
		# attributes["center"] = ("vector", (1.0, 2.0, 3.0))
		# sph1 = createGeometry("sphere", "mysphere", attributes)

		# assignAttributes(sph, {"radius": ("float", 0.9)})

		# arnold.AiNodeSetRGB(shader1, "Kd_color", self._color[0], self._color[1], self._color[2])
		# arnold.AiNodeSetFlt(shader1, "Ks", 0.05)
  
		# # assign the shaders to the geometric objects
		# arnold.AiNodeSetPtr(sph, "shader", shader1)
  
		# create a perspective camera
		camera = arnold.AiNode("persp_camera")
		arnold.AiNodeSetStr(camera, "name", "mycamera")
		arnold.AiNodeSetVec(camera, "position", 0.0, 10.0, 35.0)
		arnold.AiNodeSetVec(camera, "look_at", 0.0, 3.0, 0.0)
		arnold.AiNodeSetFlt(camera, "fov", 45.0)
  
		# create a point light source
		light = arnold.AiNode("point_light")
		arnold.AiNodeSetStr(light, "name", "pointLight_A")
		arnold.AiNodeSetVec(light, "position", 0.0, 30.0, 0.0)
		arnold.AiNodeSetFlt(light, "intensity", 10.0) 
		arnold.AiNodeSetFlt(light, "radius", 4.0) 
  
		# create a point light source
		light = arnold.AiNode("point_light")
		arnold.AiNodeSetStr(light, "name", "pointLight_B")
		arnold.AiNodeSetVec(light, "position", 0.0, -30.0, 0.0)
		arnold.AiNodeSetFlt(light, "intensity", 10.0) 
		arnold.AiNodeSetFlt(light, "radius", 4.0) 

		# create a point light source
		light = arnold.AiNode("point_light")
		arnold.AiNodeSetStr(light, "name", "pointLight_C")
		arnold.AiNodeSetVec(light, "position", 0.0, 4.0, 20.0)
		arnold.AiNodeSetFlt(light, "intensity", 5.0)
		arnold.AiNodeSetFlt(light, "radius", 15.0) 


		# get the global options node and set some options
		options = arnold.AiUniverseGetOptions()
		arnold.AiNodeSetInt(options, "AA_samples", 8)
		arnold.AiNodeSetInt(options, "xres", 480)
		arnold.AiNodeSetInt(options, "yres", 360)
		arnold.AiNodeSetInt(options, "GI_diffuse_depth", 4)
		arnold.AiNodeSetPtr(options, "camera", camera)
  
		 # create an output driver node
		driver = arnold.AiNode("driver_jpeg")
		arnold.AiNodeSetStr(driver, "name", "mydriver")
		# arnold.AiNodeSetStr(driver, "filepath", os.path.dirname(self.image))
		arnold.AiNodeSetStr(driver, "filename", os.path.basename(self.image))
		arnold.AiNodeSetFlt(driver, "gamma", 2.2)
  
		# create a gaussian filter node
		filter = arnold.AiNode("gaussian_filter")
		arnold.AiNodeSetStr(filter, "name", "myfilter")
  
		# assign the driver and filter to the main (beauty) AOV,
		# which is called "RGBA" and is of type RGBA
		outputs_array = arnold.AiArrayAllocate(1, 1, arnold.AI_TYPE_STRING)
		arnold.AiArraySetStr(outputs_array, 0, "RGBA RGBA myfilter mydriver")
		arnold.AiNodeSetArray(options, "outputs", outputs_array)
  
		# finally, render the image!
		arnold.AiRender(arnold.AI_RENDER_MODE_CAMERA)
	
		# // Arnold session shutdown
		arnold.AiEnd()
Example #28
0
def createLight(lightType, name, attributes):
	# create a red standard shader
	light = arnold.AiNode(lightType)
	arnold.AiNodeSetStr(light, "name", name)
	assignAttributes(light, attributes)
	return light
Example #29
0
def _worker(data, new_data, redraw_event, mmap_size, mmap_name, state):
    print("+++ _worker: started")

    import os
    import ctypes

    dir = os.path.dirname(__file__)
    if dir not in sys.path:
        sys.path.append(dir)

    import arnold

    nodes = {}
    lights = {}
    nptrs = []  # nodes linked by AiNodeSetPtr
    links = []  # nodes linked by AiNodeLink

    def _AiNodeSetArray(node, param, value):
        t, a = value
        _len = len(a)
        if t == arnold.AI_TYPE_VECTOR:
            _len //= 3
        elif t == arnold.AI_TYPE_UINT:
            pass
        _a = arnold.AiArrayConvert(_len, 1, t, ctypes.c_void_p(a.ctypes.data))
        arnold.AiNodeSetArray(node, param, _a)

    _AiNodeSet = {
        'NodeSocketShader': lambda n, i, v: True,
        'NodeSocketBool': lambda n, i, v: arnold.AiNodeSetBool(n, i, v),
        'NodeSocketInt': lambda n, i, v: arnold.AiNodeSetInt(n, i, v),
        'NodeSocketFloat': lambda n, i, v: arnold.AiNodeSetFlt(n, i, v),
        'NodeSocketColor': lambda n, i, v: arnold.AiNodeSetRGBA(n, i, *v),
        'NodeSocketVector': lambda n, i, v: arnold.AiNodeSetVec(n, i, *v),
        'NodeSocketVectorXYZ':
        lambda n, i, v: arnold.AiNodeSetVector(n, i, *v),
        'NodeSocketString': lambda n, i, v: arnold.AiNodeSetStr(n, i, v),
        'ArnoldNodeSocketColor': lambda n, i, v: arnold.AiNodeSetRGB(n, i, *v),
        'ArnoldNodeSocketByte': lambda n, i, v: arnold.AiNodeSetByte(n, i, v),
        'ArnoldNodeSocketProperty': lambda n, i, v: True,
        'BOOL': lambda n, p, v: arnold.AiNodeSetBool(n, p, v),
        'BYTE': lambda n, p, v: arnold.AiNodeSetByte(n, p, v),
        'INT': lambda n, p, v: arnold.AiNodeSetInt(n, p, v),
        'FLOAT': lambda n, p, v: arnold.AiNodeSetFlt(n, p, v),
        'VECTOR2': lambda n, p, v: arnold.AiNodeSetVec2(n, p, *v),
        'RGB': lambda n, p, v: arnold.AiNodeSetRGB(n, p, *v),
        'RGBA': lambda n, p, v: arnold.AiNodeSetRGBA(n, p, *v),
        'VECTOR': lambda n, p, v: arnold.AiNodeSetVec(n, p, *v),
        'STRING': lambda n, p, v: arnold.AiNodeSetStr(n, p, v),
        'MATRIX':
        lambda n, p, v: arnold.AiNodeSetMatrix(n, p, arnold.AtMatrix(*v)),
        'ARRAY': _AiNodeSetArray,
        'LINK': lambda n, p, v: links.append((n, p, v)),
        'NODE': lambda n, p, v: nptrs.append((n, p, v)),
    }

    arnold.AiBegin()
    try:
        # arnold.AiMsgSetConsoleFlags(arnold.AI_LOG_ALL)
        # arnold.AiMsgSetConsoleFlags(0x000E)
        #
        # from pprint import pprint as pp
        # pp(data)

        ## Nodes
        for node in data['nodes']:
            nt, np = node
            anode = arnold.AiNode(nt)
            for n, (t, v) in np.items():
                _AiNodeSet[t](anode, n, v)
            nodes[id(node)] = anode
        for light in data['lights']:
            nt, np = light
            anode = arnold.AiNode(nt)
            for n, (t, v) in np.items():
                _AiNodeSet[t](anode, n, v)
            lights[id(light)] = anode
        options = arnold.AiUniverseGetOptions()
        for n, (t, v) in data['options'].items():
            _AiNodeSet[t](options, n, v)
        for n, p, v in nptrs:
            arnold.AiNodeSetPtr(n, p, nodes[id(v)])
        for n, p, v in links:
            arnold.AiNodeLink(nodes[id(v)], p, n)

        ## Outputs
        filter = arnold.AiNode("gaussian_filter")
        arnold.AiNodeSetStr(filter, "name", "__filter")
        driver = arnold.AiNode("driver_display_callback")
        arnold.AiNodeSetStr(driver, "name", "__driver")
        #arnold.AiNodeSetBool(driver, "rgba_packing", False)
        outputs_aovs = (b"RGBA RGBA __filter __driver", )
        outputs = arnold.AiArray(len(outputs_aovs), 1, arnold.AI_TYPE_STRING,
                                 *outputs_aovs)
        arnold.AiNodeSetArray(options, "outputs", outputs)

        sl = data['sl']

        del nodes, nptrs, links, data

        if platform.system() == "Darwin" or "Linux":
            _rect = lambda w, h: numpy.frombuffer(mmap.mmap(-1, w * h * 4 * 4),
                                                  dtype=numpy.float32).reshape(
                                                      [h, w, 4])
            rect = _rect(*mmap_size)

        if platform.system() == "Windows":
            _rect = lambda n, w, h: numpy.frombuffer(
                mmap.mmap(-1, w * h * 4 * 4, n), dtype=numpy.float32).reshape(
                    [h, w, 4])
            rect = _rect(mmap_name, *mmap_size)

        def _callback(x, y, width, height, buffer, data):
            #print("+++ _callback:", x, y, width, height, ctypes.cast(buffer, ctypes.c_void_p))
            if buffer:
                try:
                    if new_data.poll():
                        arnold.AiRenderInterrupt()
                    else:
                        #print("+++ _callback: tile", x, y, width, height)
                        _buffer = ctypes.cast(buffer,
                                              ctypes.POINTER(ctypes.c_uint16))
                        a = numpy.ctypeslib.as_array(_buffer,
                                                     shape=(height, width, 4))
                        rect[y:y + height, x:x + width] = a
                        redraw_event.set()
                    return
                finally:
                    arnold.AiFree(buffer)
            elif not new_data.poll():
                return
            arnold.AiRenderAbort()
            print("+++ _callback: abort")

        cb = arnold.AtDisplayCallBack(_callback)
        arnold.AiNodeSetPtr(driver, "callback", cb)

        class _Dict(dict):
            def update(self, u):
                for k, v in u.items():
                    if isinstance(v, dict):
                        self[k] = _Dict.update(self.get(k, {}), v)
                    else:
                        self[k] = u[k]
                return self

        while state.value != ABORT:
            for _sl in range(*sl):
                arnold.AiNodeSetInt(options, "AA_samples", _sl)
                res = arnold.AiRender(arnold.AI_RENDER_MODE_CAMERA)
                if res == arnold.AI_SUCCESS:
                    break
            if state.value == ABORT:
                #print("+++ _worker: abort")
                break

            data = _Dict()
            _data = new_data.recv()
            print(_data)
            while _data is not None:
                # from pprint import pprint as pp
                # print("+++ _worker: data")
                # pp(_data)
                data.update(_data)
                if not new_data.poll():
                    _nodes = data.get('nodes')
                    if _nodes is not None:
                        for name, params in _nodes.items():
                            node = arnold.AiNodeLookUpByName(name)
                            for n, (t, v) in params.items():
                                _AiNodeSet[t](node, n, v)
                    opts = data.get('options')
                    if opts is not None:
                        for n, (t, v) in opts.items():
                            _AiNodeSet[t](options, n, v)
                    size = data.get('mmap_size')
                    if size is not None:
                        rect = _rect(mmap_name, *size)
                    break
                _data = new_data.recv()
    finally:
        arnold.AiEnd()
    print("+++ _worker: finished")
Example #30
0
def createSimpleShader(shaderType, name, attributes):
	# create a red standard shader
	shader = arnold.AiNode(shaderType)
	arnold.AiNodeSetStr(shader, "name", name)
	assignAttributes(shader, attributes)
	return shader