Exemplo n.º 1
0
    def testShaderConnections(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            r.shader("shader", "flat", {
                "color": IECore.Color3f(1, 0, 0),
                "__handle": "myInputShader"
            })
            r.shader("surface", "standard", {
                "emission": 1.0,
                "emission_color": "link:myInputShader"
            })

            mesh = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
            mesh.render(r)

        image = IECore.ImageDisplayDriver.removeStoredImage("test")
        e = IECore.PrimitiveEvaluator.create(image)
        result = e.createResult()

        e.pointAtUV(IECore.V2f(0.5), result)
        self.assertAlmostEqual(result.floatPrimVar(e.R()), 1, 5)
        self.assertEqual(result.floatPrimVar(e.G()), 0)
        self.assertEqual(result.floatPrimVar(e.B()), 0)
Exemplo n.º 2
0
	def testNormals( self ) :

		r = IECoreArnold.Renderer()
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "testHandle" } )
		with IECore.WorldBlock( r ) :
			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) )
			r.shader( "surface", "utility", { "shade_mode" : "flat", "color_mode" : "n" } )
			m = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -0.9 ), IECore.V2f( 0.9 ) ) )
			m["N"] = IECore.PrimitiveVariable(
					IECore.PrimitiveVariable.Interpolation.Vertex,
					IECore.V3fVectorData( [ IECore.V3f( 1, 0, 0 ), IECore.V3f( 1, 0, 0 ), IECore.V3f( 1, 0, 0 ), IECore.V3f( 1, 0, 0 ) ] )
			)
			m.render( r )

		del r

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

		# the utility shader encodes the normals in the range 0-1 rather than -1-1,
		# which is why we're checking G and B against .5 rather than 0.
		dimensions = image.dataWindow.size() + IECore.V2i( 1 )
		index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5)
		self.assertAlmostEqual( image["R"][index], 1, 4 )
		self.assertAlmostEqual( image["G"][index], 0.5, 4 )
		self.assertAlmostEqual( image["B"][index], 0.5, 4 )
Exemplo n.º 3
0
    def testLight(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.light("point_light", "handle", {
                "intensity": 1,
                "color": IECore.Color3f(1, 0.5, 0.25)
            })

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -1)))

            r.shader("surface", "standard", {})

            mesh = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
            mesh.render(r)

        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.assertTrue(image["R"][index] > 0.2)
        self.assertAlmostEqual(image["R"][index] * 0.5, image["G"][index])
        self.assertAlmostEqual(image["R"][index] * 0.25, image["B"][index])
Exemplo n.º 4
0
    def testEnumAttributes(self):

        for source, result in [(IECore.StringData("catclark"), 1),
                               (IECore.StringData("linear"), 2),
                               (IECore.IntData(1), 1), (IECore.IntData(2), 2)]:

            r = IECoreArnold.Renderer()

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

            with IECore.WorldBlock(r):

                r.concatTransform(
                    IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

                r.setAttribute("ai:polymesh:subdiv_type", source)

                mesh = IECore.MeshPrimitive.createPlane(
                    IECore.Box2f(IECore.V2f(-2), IECore.V2f(2)))
                mesh.render(r)

                shapes = self.__allNodes(type=arnold.AI_NODE_SHAPE)

                self.assertEqual(len(shapes), 1)
                self.assertEqual(arnold.AiNodeGetInt(shapes[0], "subdiv_type"),
                                 result)

            del r
Exemplo n.º 5
0
    def testShaderConnections(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            r.shader("shader", "flat", {
                "color": IECore.Color3f(1, 0, 0),
                "__handle": "myInputShader"
            })
            r.shader("surface", "standard", {
                "emission": 1.0,
                "emission_color": "link:myInputShader"
            })

            mesh = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
            mesh.render(r)

        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["R"][index], 1, 5)
        self.assertEqual(image["G"][index], 0)
        self.assertEqual(image["B"][index], 0)
Exemplo n.º 6
0
    def testShader(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.shader("surface", "standard", {
                "emission": 1.0,
                "emission_color": IECore.Color3f(1, 0, 0)
            })
            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)
Exemplo n.º 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 = 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)
Exemplo n.º 8
0
	def testDiskRendering( self ) :

		numPoints = 10
		p = IECore.V3fVectorData( numPoints )
		random.seed( 0 )
		for i in range( 0, numPoints ) :
			p[i] = IECore.V3f( random.random() * 4, random.random() * 4, random.random() * 4 )
		p = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Vertex, p )

		r = IECoreArnold.Renderer()
		r.setOption( "ai:AA_samples", IECore.IntData( 9 ) )

		r.camera( "main", {
				"projection" : IECore.StringData( "orthographic" ),
				"resolution" : IECore.V2iData( IECore.V2i( 256 ) ),
				"clippingPlanes" : IECore.V2fData( IECore.V2f( 1, 1000 ) ),
				"screenWindow" : IECore.Box2fData( IECore.Box2f( IECore.V2f( -3 ), IECore.V2f( 3 ) ) )
			}
		)
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "testHandle" } )

		with IECore.WorldBlock( r ) :

			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( -2, -2, -10 ) ) )
			r.points( numPoints, { "P" : p } )

		image = IECoreImage.ImageDisplayDriver.removeStoredImage( "testHandle" )
		del image["A"]

		expectedImage = IECore.Reader.create( os.path.dirname( __file__ ) + "/data/pointsImages/points.tif" ).read()

		self.assertEqual( IECoreImage.ImageDiffOp()( imageA=image, imageB=expectedImage, maxError=0.01 ), IECore.BoolData( False ) )
Exemplo n.º 9
0
	def testNonUniformMotionBlur( self ) :

		r = IECoreArnold.Renderer()

		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )
		r.setOption( "ai:AA_samples", IECore.IntData( 20 ) )

		r.camera( "main", { "resolution" : IECore.V2i( 128, 128 ), "shutter" : IECore.V2f( 0, 1 ) } )

		with IECore.WorldBlock( r ) :

			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) )

			# A motion block that has slightly non-uniform sampling, but not enough to notice
			# We should allow it, since the user won't notice that Arnold is ignoring the non-uniformity
			with IECore.MotionBlock( r, [ 0, 0.3333, 0.6666, 1 ] ) :
				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( -1, 0, 0 ) ) )
				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( -0.3333333333, 0, 0 ) ) )
				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0.33333333333, 0, 0 ) ) )
				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 1, 0, 0 ) ) )

			with self.assertRaises( RuntimeError ):
				# This block is actually non-uniform, and won't render correctly, so we should fail
				with IECore.MotionBlock( r, [ 0, 0.333, 0.666, 2 ] ):
					pass

			mesh = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -0.5 ), IECore.V2f( 0.5 ) ) )
			mesh.render( r )


		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], 0.5, 2 )
Exemplo n.º 10
0
	def testTransformationMotionBlur( self ) :

		r = IECoreArnold.Renderer()

		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )
		r.setOption( "ai:AA_samples", IECore.IntData( 20 ) )

		r.camera( "main", { "resolution" : IECore.V2i( 128, 128 ), "shutter" : IECore.V2f( 0, 1 ) } )

		with IECore.WorldBlock( r ) :

			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) )

			with IECore.MotionBlock( r, [ 0, 1 ] ) :

				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( -1, 0, 0 ) ) )
				r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 1, 0, 0 ) ) )

			mesh = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -0.5 ), IECore.V2f( 0.5 ) ) )
			mesh.render( r )


		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], 0.5, 2 )
Exemplo n.º 11
0
    def testShader(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.shader("surface", "standard", {
                "emission": 1.0,
                "emission_color": IECore.Color3f(1, 0, 0)
            })
            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)
Exemplo n.º 12
0
    def __displacementRender(self, doDisplacement):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            r.setAttribute("ai:polymesh:subdiv_iterations", IECore.IntData(5))

            r.shader(
                "surface", "utility", {
                    "color_mode": IECore.StringData("ng"),
                    "shade_mode": IECore.StringData("flat")
                })
            if doDisplacement:
                r.shader("displacement", "noise", {})

            mesh = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2), IECore.V2f(2)))
            mesh.interpolation = "catmullClark"
            mesh.render(r)

        return IECore.ImageDisplayDriver.removeStoredImage("test")
Exemplo n.º 13
0
	def performCurvesTest( self, curvesPrimitive, expectedImage ) :
	
		r = IECoreArnold.Renderer()
				
		r.setOption( "ai:AA_samples", IECore.IntData( 3 ) )
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )
		
		with IECore.TransformBlock( r ) :
			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, 2 ) ) )
			r.camera(
				"main",
				{
					"resolution" : IECore.V2i( 512 ),
					"projectin" : "orthographic",
					"screenWindow" : IECore.Box2f( IECore.V2f( 0 ), IECore.V2f( 1 ) ),
				}
			)

		with IECore.WorldBlock( r ) :			
			curvesPrimitive.render( r )

		image = IECore.ImageDisplayDriver.removeStoredImage( "test" )
		del image["A"]
		
		# raise blackPoint massively to remove possible watermark
		IECore.Grade()( input = image, copyInput = False, blackPoint = IECore.Color3f( 0.9 ) )
				
		expectedImage = IECore.Reader.create( expectedImage ).read()
		
		self.assertEqual( IECore.ImageDiffOp()( imageA=image, imageB=expectedImage, maxError=0.01 ), IECore.BoolData( False ) )
Exemplo n.º 14
0
    def testMissingShaderConnectionWarnings(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            m = IECore.CapturingMessageHandler()
            with m:
                r.shader("shader", "flat", {
                    "color": IECore.Color3f(1, 0, 0),
                    "__handle": "myInputShader"
                })
                r.shader("surface", "standard", {
                    "emission": 1.0,
                    "emission_color": "link:oopsWrongOne"
                })

        self.assertEqual(len(m.messages), 1)
        self.assertEqual(m.messages[0].level, IECore.Msg.Level.Warning)
        self.failUnless("oopsWrongOne" in m.messages[0].message)
Exemplo n.º 15
0
	def testOptions( self ) :
	
		r = IECoreArnold.Renderer()
		
		# check we can set an already existing int
		self.assertEqual( r.getOption( "ai:AA_samples" ), IECore.IntData( 1 ) )
		r.setOption( "ai:AA_samples", IECore.IntData( 11 ) )
		self.assertEqual( r.getOption( "ai:AA_samples" ), IECore.IntData( 11 ) )
		
		# check we can set an already existing float
		self.assertEqual( r.getOption( "ai:auto_transparency_threshold" ), IECore.FloatData( .99 ) )
		r.setOption( "ai:auto_transparency_threshold", IECore.FloatData( .9 ) )
		self.assertEqual( r.getOption( "ai:auto_transparency_threshold" ), IECore.FloatData( .9 ) )
		
		# check tbat trying to set nonexistent options yields a message
		m = IECore.CapturingMessageHandler()
		with m :
		
			r.setOption( "ai:thisIsNotAnArnoldOption", IECore.IntData( 10 ) )
			self.assertEqual( len( m.messages ), 1 )
			self.assertEqual( m.messages[-1].level, IECore.Msg.Level.Warning )
			self.assertEqual( m.messages[-1].message, "Unknown option \"ai:thisIsNotAnArnoldOption\"." )
			
		# check that setting user options works
		r.setOption( "user:myLovelyUserOption", IECore.StringData( "oooh!" ) )
		self.assertEqual( r.getOption( "user:myLovelyUserOption" ), IECore.StringData( "oooh!" ) )
		
		# check that set/get for other renderers is ignored
		r.setOption( "ri:pixelSamples", IECore.V2iData( IECore.V2i( 1, 1 ) ) )
		self.assertEqual( r.getOption( "ri:pixelSamples" ), None )
Exemplo n.º 16
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 )	
Exemplo n.º 17
0
    def testUVs(self):

        r = IECoreArnold.Renderer()
        r.display("test", "ieDisplay", "rgba", {
            "driverType": "ImageDisplayDriver",
            "handle": "testHandle"
        })
        with IECore.WorldBlock(r):
            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))
            r.shader("surface", "utility", {
                "shade_mode": "flat",
                "color_mode": "uv"
            })
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))).render(r)

        del r

        image = IECore.ImageDisplayDriver.removeStoredImage("testHandle")
        expectedImage = IECore.EXRImageReader(
            os.path.dirname(__file__) +
            "/data/meshImages/expectedMeshUVs.exr").read()

        self.failIf(IECore.ImageDiffOp()(imageA=image,
                                         imageB=expectedImage,
                                         maxError=0.003).value)
Exemplo n.º 18
0
	def testLight( self ) :
	
		r = IECoreArnold.Renderer()
		
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )

		with IECore.WorldBlock( r ) :
		
			r.light( "point_light", "handle", { "intensity" : 1, "color" : IECore.Color3f( 1, 0.5, 0.25 ) } )
		
			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -1 ) ) )
			
			r.shader( "surface", "standard", {} )	
			
			mesh = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) )
			mesh.render( r )

		image = IECore.ImageDisplayDriver.removeStoredImage( "test" )
		e = IECore.PrimitiveEvaluator.create( image )
 		result = e.createResult()
				
		e.pointAtUV( IECore.V2f( 0.5 ), result )
		self.assertTrue( result.floatPrimVar( e.R() ) > 0.2 )
		self.assertAlmostEqual( result.floatPrimVar( e.R() ) * 0.5, result.floatPrimVar( e.G() ) )
		self.assertAlmostEqual( result.floatPrimVar( e.R() ) * 0.25, result.floatPrimVar( e.B() ) )
Exemplo n.º 19
0
    def testProcedural(self):

        r = IECoreArnold.Renderer("/tmp/test.ass")

        with IECore.WorldBlock(r):

            r.procedural(
                r.ExternalProcedural(
                    "someVolumeThing.so",
                    IECore.Box3f(IECore.V3f(-1, -2, -3), IECore.V3f(4, 5, 6)),
                    {
                        "ai:nodeType": "volume",
                        "testFloat": 0.5
                    }))

            volume = self.__allNodes(type=arnold.AI_NODE_SHAPE)[-1]
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(volume)),
                "volume")

            self.assertEqual(arnold.AiNodeGetPnt(volume, "min"),
                             arnold.AtPoint(-1, -2, -3))
            self.assertEqual(arnold.AiNodeGetPnt(volume, "max"),
                             arnold.AtPoint(4, 5, 6))
            self.assertEqual(arnold.AiNodeGetStr(volume, "dso"),
                             "someVolumeThing.so")
            self.assertEqual(arnold.AiNodeGetFlt(volume, "testFloat"), 0.5)
Exemplo n.º 20
0
    def testEmptyProceduralIsIgnored(self):
        class EmptyProcedural(IECore.Renderer.Procedural):
            def __init__(self):

                IECore.Renderer.Procedural.__init__(self)

            def bound(self):

                return IECore.Box3f()

            def render(self, renderer):

                pass

            def hash(self):

                h = IECore.MurmurHash()
                return h

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

        messageCallback = arnold.AtMsgCallBack(self.arnoldMessageCallback)
        arnold.AiMsgSetCallback(messageCallback)
        self.__arnoldMessages = ""

        with IECore.WorldBlock(r):

            r.procedural(EmptyProcedural())

        self.failIf("ignoring parameter max" in self.__arnoldMessages)
Exemplo n.º 21
0
    def testExternalProcedural(self):

        r = IECoreArnold.Renderer(self.__assFileName)

        with IECore.WorldBlock(r):

            r.procedural(
                r.ExternalProcedural(
                    "test.so",
                    IECore.Box3f(IECore.V3f(1, 2, 3), IECore.V3f(4, 5, 6)), {
                        "colorParm": IECore.Color3f(1, 2, 3),
                        "stringParm": "test",
                        "floatParm": 1.5,
                        "intParm": 2,
                    }))

        ass = "".join(file(self.__assFileName).readlines())

        self.assertTrue("procedural" in ass)
        self.assertTrue("min 1 2 3" in ass)
        self.assertTrue("max 4 5 6" in ass)
        self.assertTrue("dso \"test.so\"" in ass)
        self.assertTrue("declare stringParm constant STRING" in ass)
        self.assertTrue("declare floatParm constant FLOAT" in ass)
        self.assertTrue("declare intParm constant INT" in ass)
        self.assertTrue("declare colorParm constant RGB" in ass)
        self.assertTrue("stringParm \"test\"" in ass)
        self.assertTrue("floatParm 1.5" in ass)
        self.assertTrue("intParm 2" in ass)
        self.assertTrue("colorParm 1 2 3" in ass)
Exemplo n.º 22
0
    def testEnabling(self):

        r = IECoreArnold.Renderer()

        with IECore.WorldBlock(r):

            r.setAttribute("ai:automaticInstancing", IECore.BoolData(True))

            m = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))

            m.render(r)
            m.render(r)

            nodes = self.__allNodes(type=arnold.AI_NODE_SHAPE)
            self.assertEqual(len(nodes), 2)

            nodeTypes = [
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n))
                for n in nodes
            ]
            mesh = nodes[nodeTypes.index("polymesh")]
            instance = nodes[nodeTypes.index("ginstance")]

            self.assertEqual(arnold.AiNodeGetPtr(instance, "node"),
                             ctypes.addressof(mesh.contents))
Exemplo n.º 23
0
	def testShaderNetworkRender( self ) :

		f = GafferArnold.ArnoldShader()
		f.loadShader( "flat" )
		f["parameters"]["color"].setValue( IECore.Color3f( 1, 1, 0 ) )

		s = GafferArnold.ArnoldShader()
		s.loadShader( "utility" )
		s["parameters"]["color"].setInput( f["parameters"]["color"] )

		r = IECoreArnold.Renderer()

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

		with IECore.WorldBlock( r ) :

			for ss in s.state() :
				ss.render( r )

			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) )
			mesh = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) )
			mesh.render( r )

		image = IECore.ImageDisplayDriver.removeStoredImage( "test" )
		e = IECore.PrimitiveEvaluator.create( image )
 		result = e.createResult()

		e.pointAtUV( IECore.V2f( 0.5 ), result )
		self.assertAlmostEqual( result.floatPrimVar( e.R() ), 1, 5 )
		self.assertAlmostEqual( result.floatPrimVar( e.G() ), 1, 5 )
		self.assertEqual( result.floatPrimVar( e.B() ), 0 )
Exemplo n.º 24
0
    def testShapeAttributes(self):

        r = IECoreArnold.Renderer()

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

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            r.setAttribute("ai:polymesh:subdiv_iterations", IECore.IntData(10))

            mesh = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2), IECore.V2f(2)))
            mesh.render(r)

            shapes = self.__allNodes(type=arnold.AI_NODE_SHAPE)

            self.assertEqual(len(shapes), 1)
            self.assertEqual(
                arnold.AiNodeGetInt(shapes[0], "subdiv_iterations"), 10)
Exemplo n.º 25
0
	def testCameraAspectRatio( self ) :
	
		r = IECoreArnold.Renderer()
		
		r.camera( "main", { "resolution" : IECore.V2i( 640, 480 ), "screenWindow" : IECore.Box2f( IECore.V2f( 0 ), IECore.V2f( 640, 480 ) ) } )	
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "test" } )
					
		with IECore.WorldBlock( r ) :
		
			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) )
			r.shader( "surface", "utility", { "shading_mode" : "flat", "color" : IECore.Color3f( 1, 0, 0 ) } )
			IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( 2 ), IECore.V2f( 638, 478 ) ) ).render( r )
			
			r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -1 ) ) )
			r.shader( "surface", "utility", { "shade_mode" : "flat", "color" : IECore.Color3f( 0, 1, 0 ) } )
			IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( 0 ), IECore.V2f( 640, 480 ) ) ).render( r )
	
		image = IECore.ImageDisplayDriver.removeStoredImage( "test" )
		self.failUnless( image is not None )

		e = IECore.PrimitiveEvaluator.create( image )
		result = e.createResult()
		r = e.R()
		g = e.G()
		
		edges = [
			IECore.V2i( 0 ),
			IECore.V2i( 320, 0 ),
			IECore.V2i( 639, 0 ),			 
			IECore.V2i( 639, 240 ),			 
			IECore.V2i( 639, 479 ),
			IECore.V2i( 320, 479 ),
			IECore.V2i( 0, 479 ),
			IECore.V2i( 0, 240 ),
		]
		
		for point in edges :							
			self.failUnless( e.pointAtPixel( point, result ) )
			self.failUnless( result.floatPrimVar( r ) < 0.1 )
			self.failUnless( result.floatPrimVar( g ) > 0.8 )
		
		innerEdges = [
			IECore.V2i( 3, 3 ),
			IECore.V2i( 320, 3 ),
			IECore.V2i( 637, 3 ),			 
			IECore.V2i( 636, 240 ),			 
			IECore.V2i( 636, 477 ),
			IECore.V2i( 320, 477 ),
			IECore.V2i( 3, 477 ),
			IECore.V2i( 3, 240 ),
		]
		
		for point in innerEdges :
			self.failUnless( e.pointAtPixel( point, result ) )
			self.failUnless( result.floatPrimVar( r ) > 0.8 )
			self.failUnless( result.floatPrimVar( g ) < 0.1 )
Exemplo n.º 26
0
    def testProceduralsShareInstances(self):
        class PlaneProcedural(IECore.Renderer.Procedural):
            def __init__(self):

                IECore.Renderer.Procedural.__init__(self)

            def bound(self):

                return IECore.Box3f(IECore.V3f(-10, -10, -0.01),
                                    IECore.V3f(10, 10, 0.01))

            def render(self, renderer):

                IECore.MeshPrimitive.createPlane(
                    IECore.Box2f(IECore.V2f(-10),
                                 IECore.V2f(10))).render(renderer)

            def hash(self):

                h = IECore.MurmurHash()
                return h

        def arnoldMessageCallback(logMask, severity, msg, tabs):

            self.__arnoldMessages.append(msg)

        r = IECoreArnold.Renderer()
        r.display("test", "driver_null", "rgba", {})

        messageCallback = arnold.AtMsgCallBack(arnoldMessageCallback)
        arnold.AiMsgSetCallback(messageCallback)
        self.__arnoldMessages = []

        with IECore.WorldBlock(r):

            r.concatTransform(
                IECore.M44f.createTranslated(IECore.V3f(0, 0, -5)))

            for i in range(0, 100):
                r.procedural(PlaneProcedural())

        # we can't check for the existence of ginstances by examining the nodes after rendering,
        # because it seems that after rendering, arnold reports the type of ginstances
        # as being the type of the thing they point to, rather than "ginstance". so instead we
        # check for evidence in the log.

        polyMeshStats = [
            m for m in self.__arnoldMessages if m.startswith("polymeshes")
        ][0]
        self.failUnless("99" in polyMeshStats)

        # check that there are no bounding box warnings
        boundingBoxWarnings = [
            m for m in self.__arnoldMessages if "bounding box" in m
        ]
        self.assertEqual(len(boundingBoxWarnings), 0)
Exemplo n.º 27
0
	def testASSOutput( self ) :
	
		r = IECoreArnold.Renderer( self.__assFileName )

		self.failIf( os.path.exists( self.__assFileName ) )
		with IECore.WorldBlock( r ) :
		
			r.sphere( 1, -1, 1, 360, {} )
			
		self.failUnless( os.path.exists( self.__assFileName ) )
Exemplo n.º 28
0
	def testDisplayDriverIntegration( self ) :
	
		r = IECoreArnold.Renderer()
		r.display( "test", "ieDisplay", "rgba", { "driverType" : "ImageDisplayDriver", "handle" : "testHandle" } )
		
		with IECore.WorldBlock( r ) :
			
			r.sphere( 1, -1, 1, 360, {} )
			
		self.failUnless( IECore.ImageDisplayDriver.removeStoredImage( "testHandle" ) )
Exemplo n.º 29
0
	def testPixelAspectRatio( self ) :

		r = IECoreArnold.Renderer( self.__assFileName )

		r.camera( "main", { "resolution" : IECore.V2i( 640, 480 ), "pixelAspectRatio" : 2.0 } )

		with IECore.WorldBlock( r ) :
			pass

		ass = "".join( file( self.__assFileName ).readlines() )
		self.assertTrue( "aspect_ratio 0.5" in ass )
Exemplo n.º 30
0
	def testOtherRendererShaderType( self ) :
	
		r = IECoreArnold.Renderer()
		
		with IECore.WorldBlock( r ) :
		
			m = IECore.CapturingMessageHandler()
			with m :
				r.shader( "ri:surface", "something", {} )
				
			self.assertEqual( len( m.messages ), 0 )