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

		s = Gaffer.ScriptNode()

		s["plane"] = GafferScene.Plane()
		s["sphere"] = GafferScene.Sphere()
		s["group"] = GafferScene.Group()
		s["group"]["in"][0].setInput( s["plane"]["out"] )
		s["group"]["in"][1].setInput( s["sphere"]["out"] )

		s["expression"] = Gaffer.Expression()
		s["expression"].setExpression(
			inspect.cleandoc(
				"""
				parent["plane"]["transform"]["translate"]["x"] = context.getFrame()
				parent["sphere"]["transform"]["translate"]["y"] = context.getFrame() * 2
				parent["group"]["transform"]["translate"]["z"] = context.getFrame() - 1
				"""
			)
		)

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

		s["attributes"] = GafferScene.StandardAttributes()
		s["attributes"]["in"].setInput( s["group"]["out"] )
		s["attributes"]["filter"].setInput( s["planeFilter"]["out"] )
		s["attributes"]["attributes"]["transformBlur"]["enabled"].setValue( True )
		s["attributes"]["attributes"]["transformBlur"]["value"].setValue( False )

		s["options"] = GafferScene.StandardOptions()
		s["options"]["in"].setInput( s["attributes"]["out"] )
		s["options"]["options"]["shutter"]["enabled"].setValue( True )
		s["options"]["options"]["transformBlur"]["enabled"].setValue( True )

		s["render"] = GafferArnold.ArnoldRender()
		s["render"]["in"].setInput( s["options"]["out"] )
		s["render"]["mode"].setValue( s["render"].Mode.SceneDescriptionMode )
		s["render"]["fileName"].setValue( self.temporaryDirectory() + "/test.ass" )

		# No motion blur

		s["options"]["options"]["transformBlur"]["value"].setValue( False )
		s["render"]["task"].execute()

		with IECoreArnold.UniverseBlock( writable = True ) :

			arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

			camera = arnold.AiNodeLookUpByName( "gaffer:defaultCamera" )
			sphere = arnold.AiNodeLookUpByName( "/group/sphere" )
			sphereMotionStart = arnold.AiNodeGetFlt( sphere, "motion_start" )
			sphereMotionEnd = arnold.AiNodeGetFlt( sphere, "motion_end" )
			sphereMatrix = arnold.AiNodeGetMatrix( sphere, "matrix" )

			plane = arnold.AiNodeLookUpByName( "/group/plane" )
			planeMotionStart = arnold.AiNodeGetFlt( plane, "motion_start" )
			planeMotionEnd = arnold.AiNodeGetFlt( plane, "motion_end" )
			planeMatrix = arnold.AiNodeGetMatrix( plane, "matrix" )

			# Motion parameters should be left at default
			self.assertEqual( sphereMotionStart, 0 )
			self.assertEqual( sphereMotionEnd, 1 )
			self.assertEqual( planeMotionStart, 0 )
			self.assertEqual( planeMotionEnd, 1 )

			expectedSphereMatrix = arnold.AiM4Translation( arnold.AtVector( 0, 2, 0 ) )

			expectedPlaneMatrix = arnold.AiM4Translation( arnold.AtVector( 1, 0, 0 ) )

			self.assertEqual( self.__m44f( sphereMatrix ), self.__m44f( expectedSphereMatrix ) )
			self.assertEqual( self.__m44f( planeMatrix ), self.__m44f( expectedPlaneMatrix ) )

			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_start" ), 1 )
			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_end" ), 1 )

		# Motion blur

		s["options"]["options"]["transformBlur"]["value"].setValue( True )
		s["render"]["task"].execute()

		with IECoreArnold.UniverseBlock( writable = True ) :

			arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

			camera = arnold.AiNodeLookUpByName( "gaffer:defaultCamera" )
			sphere = arnold.AiNodeLookUpByName( "/group/sphere" )
			sphereMotionStart = arnold.AiNodeGetFlt( sphere, "motion_start" )
			sphereMotionEnd = arnold.AiNodeGetFlt( sphere, "motion_end" )
			sphereMatrices = arnold.AiNodeGetArray( sphere, "matrix" )

			plane = arnold.AiNodeLookUpByName( "/group/plane" )
			planeMotionStart = arnold.AiNodeGetFlt( plane, "motion_start" )
			planeMotionEnd = arnold.AiNodeGetFlt( plane, "motion_end" )
			planeMatrices = arnold.AiNodeGetArray( plane, "matrix" )

			self.assertEqual( sphereMotionStart, 0.75 )
			self.assertEqual( sphereMotionEnd, 1.25 )
			self.assertEqual( arnold.AiArrayGetNumElements( sphereMatrices.contents ), 1 )
			self.assertEqual( arnold.AiArrayGetNumKeys( sphereMatrices.contents ), 2 )

			self.assertEqual( planeMotionStart, 0.75 )
			self.assertEqual( planeMotionEnd, 1.25 )
			self.assertEqual( arnold.AiArrayGetNumElements( planeMatrices.contents ), 1 )
			self.assertEqual( arnold.AiArrayGetNumKeys( planeMatrices.contents ), 2 )

			for i in range( 0, 2 ) :

				frame = 0.75 + 0.5 * i
				sphereMatrix = arnold.AiArrayGetMtx( sphereMatrices, i )

				expectedSphereMatrix = arnold.AiM4Translation( arnold.AtVector( 0, frame * 2, frame - 1 ) )

				planeMatrix = arnold.AiArrayGetMtx( planeMatrices, i )

				expectedPlaneMatrix = arnold.AiM4Translation( arnold.AtVector( 1, 0, frame - 1 ) )

				self.assertEqual( self.__m44f( sphereMatrix ), self.__m44f( expectedSphereMatrix ) )
				self.assertEqual( self.__m44f( planeMatrix ), self.__m44f( expectedPlaneMatrix ) )

			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_start" ), 0.75 )
			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_end" ), 1.25 )

		# Motion blur on, but sampleMotion off

		s["options"]["options"]["sampleMotion"]["enabled"].setValue( True )
		s["options"]["options"]["sampleMotion"]["value"].setValue( False )
		s["render"]["task"].execute()

		with IECoreArnold.UniverseBlock( writable = True ) :

			arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

			camera = arnold.AiNodeLookUpByName( "gaffer:defaultCamera" )
			sphere = arnold.AiNodeLookUpByName( "/group/sphere" )
			sphereMotionStart = arnold.AiNodeGetFlt( sphere, "motion_start" )
			sphereMotionEnd = arnold.AiNodeGetFlt( sphere, "motion_end" )
			sphereMatrices = arnold.AiNodeGetArray( sphere, "matrix" )

			plane = arnold.AiNodeLookUpByName( "/group/plane" )
			planeMotionStart = arnold.AiNodeGetFlt( plane, "motion_start" )
			planeMotionEnd = arnold.AiNodeGetFlt( plane, "motion_end" )
			planeMatrices = arnold.AiNodeGetArray( plane, "matrix" )

			self.assertEqual( sphereMotionStart, 0.75 )
			self.assertEqual( sphereMotionEnd, 1.25 )
			self.assertEqual( arnold.AiArrayGetNumElements( sphereMatrices.contents ), 1 )
			self.assertEqual( arnold.AiArrayGetNumKeys( sphereMatrices.contents ), 2 )

			self.assertEqual( planeMotionStart, 0.75 )
			self.assertEqual( planeMotionEnd, 1.25 )
			self.assertEqual( arnold.AiArrayGetNumElements( planeMatrices.contents ), 1 )
			self.assertEqual( arnold.AiArrayGetNumKeys( planeMatrices.contents ), 2 )

			for i in range( 0, 2 ) :

				frame = 0.75 + 0.5 * i

				sphereMatrix = arnold.AiArrayGetMtx( sphereMatrices, i )

				expectedSphereMatrix = arnold.AiM4Translation( arnold.AtVector( 0, frame * 2, frame - 1 ) )

				planeMatrix = arnold.AiArrayGetMtx( planeMatrices, i )

				expectedPlaneMatrix = arnold.AiM4Translation( arnold.AtVector( 1, 0, frame - 1 ) )

				self.assertEqual( self.__m44f( sphereMatrix ), self.__m44f( expectedSphereMatrix ) )
				self.assertEqual( self.__m44f( planeMatrix ), self.__m44f( expectedPlaneMatrix ) )

			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_start" ), 0.75 )
			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_end" ), 0.75 )
Exemplo n.º 2
0
    def testTransformMotion(self):

        s = Gaffer.ScriptNode()

        s["plane"] = GafferScene.Plane()
        s["sphere"] = GafferScene.Sphere()
        s["group"] = GafferScene.Group()
        s["group"]["in"][0].setInput(s["plane"]["out"])
        s["group"]["in"][1].setInput(s["sphere"]["out"])

        s["expression"] = Gaffer.Expression()
        s["expression"].setExpression(
            inspect.cleandoc("""
				parent["plane"]["transform"]["translate"]["x"] = context.getFrame()
				parent["sphere"]["transform"]["translate"]["y"] = context.getFrame() * 2
				parent["group"]["transform"]["translate"]["z"] = context.getFrame() - 1
				"""))

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

        s["attributes"] = GafferScene.StandardAttributes()
        s["attributes"]["in"].setInput(s["group"]["out"])
        s["attributes"]["filter"].setInput(s["planeFilter"]["out"])
        s["attributes"]["attributes"]["transformBlur"]["enabled"].setValue(
            True)
        s["attributes"]["attributes"]["transformBlur"]["value"].setValue(False)

        s["options"] = GafferScene.StandardOptions()
        s["options"]["in"].setInput(s["attributes"]["out"])
        s["options"]["options"]["transformBlur"]["enabled"].setValue(True)

        s["render"] = GafferArnold.ArnoldRender()
        s["render"]["in"].setInput(s["options"]["out"])
        s["render"]["mode"].setValue(s["render"].Mode.SceneDescriptionMode)
        s["render"]["fileName"].setValue(self.temporaryDirectory() +
                                         "/test.ass")

        # No motion blur

        s["options"]["options"]["transformBlur"]["value"].setValue(False)
        s["render"]["task"].execute()

        with IECoreArnold.UniverseBlock(writable=True):

            arnold.AiASSLoad(self.temporaryDirectory() + "/test.ass")

            sphere = arnold.AiNodeLookUpByName("/group/sphere")
            sphereTimes = arnold.AiNodeGetArray(sphere,
                                                "transform_time_samples")
            sphereMatrix = arnold.AtMatrix()
            arnold.AiNodeGetMatrix(sphere, "matrix", sphereMatrix)

            plane = arnold.AiNodeLookUpByName("/group/plane")
            planeTimes = arnold.AiNodeGetArray(plane, "transform_time_samples")
            planeMatrix = arnold.AtMatrix()
            arnold.AiNodeGetMatrix(plane, "matrix", planeMatrix)

            expectedSphereMatrix = arnold.AtMatrix()
            arnold.AiM4Translation(expectedSphereMatrix,
                                   arnold.AtVector(0, 2, 0))

            expectedPlaneMatrix = arnold.AtMatrix()
            arnold.AiM4Translation(expectedPlaneMatrix,
                                   arnold.AtVector(1, 0, 0))

            self.__assertStructsEqual(sphereMatrix, expectedSphereMatrix)
            self.__assertStructsEqual(planeMatrix, expectedPlaneMatrix)

        # Motion blur

        s["options"]["options"]["transformBlur"]["value"].setValue(True)
        s["render"]["task"].execute()

        with IECoreArnold.UniverseBlock(writable=True):

            arnold.AiASSLoad(self.temporaryDirectory() + "/test.ass")

            sphere = arnold.AiNodeLookUpByName("/group/sphere")
            sphereTimes = arnold.AiNodeGetArray(sphere,
                                                "transform_time_samples")
            sphereMatrices = arnold.AiNodeGetArray(sphere, "matrix")

            plane = arnold.AiNodeLookUpByName("/group/plane")
            planeTimes = arnold.AiNodeGetArray(plane, "transform_time_samples")
            planeMatrices = arnold.AiNodeGetArray(plane, "matrix")

            self.assertEqual(sphereTimes.contents.nelements, 2)
            self.assertEqual(sphereTimes.contents.nkeys, 1)
            self.assertEqual(sphereMatrices.contents.nelements, 1)
            self.assertEqual(sphereMatrices.contents.nkeys, 2)

            self.assertEqual(planeTimes.contents.nelements, 2)
            self.assertEqual(planeTimes.contents.nkeys, 1)
            self.assertEqual(planeMatrices.contents.nelements, 1)
            self.assertEqual(planeMatrices.contents.nkeys, 2)

            for i in range(0, 2):

                frame = 0.75 + 0.5 * i
                self.assertEqual(arnold.AiArrayGetFlt(sphereTimes, i), frame)
                self.assertEqual(arnold.AiArrayGetFlt(planeTimes, i), frame)

                sphereMatrix = arnold.AtMatrix()
                arnold.AiArrayGetMtx(sphereMatrices, i, sphereMatrix)

                expectedSphereMatrix = arnold.AtMatrix()
                arnold.AiM4Translation(
                    expectedSphereMatrix,
                    arnold.AtVector(0, frame * 2, frame - 1))

                planeMatrix = arnold.AtMatrix()
                arnold.AiArrayGetMtx(planeMatrices, i, planeMatrix)

                expectedPlaneMatrix = arnold.AtMatrix()
                arnold.AiM4Translation(expectedPlaneMatrix,
                                       arnold.AtVector(1, 0, frame - 1))

                self.__assertStructsEqual(sphereMatrix, expectedSphereMatrix)
                self.__assertStructsEqual(planeMatrix, expectedPlaneMatrix)