コード例 #1
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],
            )
コード例 #2
0
    def testPrimitiveVariables(self):

        s = IECore.SpherePrimitive()
        s["v"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant,
            IECore.V3f(1, 2, 3))
        s["c"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant,
            IECore.Color3f(1, 2, 3))
        s["s"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant, "test")
        s["i"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant, 11)
        s["b"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant, True)
        s["f"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant, 2.5)
        s["m"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.Constant,
            IECore.M44f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))

        with IECoreArnold.UniverseBlock(writable=True):

            n = IECoreArnold.NodeAlgo.convert(s)
            self.assertEqual(arnold.AiNodeGetVec(n, "v"),
                             arnold.AtVector(1, 2, 3))
            self.assertEqual(arnold.AiNodeGetRGB(n, "c"),
                             arnold.AtColor(1, 2, 3))
            self.assertEqual(arnold.AiNodeGetStr(n, "s"), "test")
            self.assertEqual(arnold.AiNodeGetInt(n, "i"), 11)
            self.assertEqual(arnold.AiNodeGetBool(n, "b"), True)
            self.assertEqual(arnold.AiNodeGetFlt(n, "f"), 2.5)

            m = arnold.AtMatrix()
            arnold.AiNodeGetMatrix(n, "m", 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],
            )
コード例 #3
0
ファイル: ipr.py プロジェクト: lvxejay/barnold
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")
コード例 #4
0
 def set_matrix(self, param, val):
     if self.is_valid():
         if isinstance(val, ArnoldMatrix):
             arnold.AiNodeSetMatrix(self.data, param, val.data)
         else:
             arnold.AiNodeSetMatrix(self.data, param, arnold.AtMatrix(*val))
コード例 #5
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" )
			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 )

			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" )
			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 )

			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" )
			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 )

			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_start" ), 0.75 )
			self.assertEqual( arnold.AiNodeGetFlt( camera, "shutter_end" ), 0.75 )
コード例 #6
0
ファイル: array.py プロジェクト: lunadigital/btoa
 def set_matrix(self, i, val):
     if self.is_valid():
         arnold.AiArraySetMtx(self.data, i, arnold.AtMatrix(*val))
コード例 #7
0
 def convert_from_buffer(self, data):
     self.data = arnold.AtMatrix(*data)