예제 #1
0
    def testPointTypePrimitiveVariables(self):
        # make sure that we can add prim vars of both vector and point type, and differentiate between the two.
        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))

        points = IECore.V3fVectorData([])
        IECore.setGeometricInterpretation(
            points, IECore.GeometricData.Interpretation.Point)
        m["points"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, points)

        vectors = IECore.V3fVectorData([])
        IECore.setGeometricInterpretation(
            vectors, IECore.GeometricData.Interpretation.Vector)
        m["vectors"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, vectors)

        with IECoreArnold.UniverseBlock(writable=True) as universe:
            node = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            p = arnold.AiNodeGetArray(node, "points")
            self.assertEqual(arnold.AiArrayGetType(p.contents),
                             arnold.AI_TYPE_VECTOR)

            v = arnold.AiNodeGetArray(node, "vectors")
            self.assertEqual(arnold.AiArrayGetType(v.contents),
                             arnold.AI_TYPE_VECTOR)
예제 #2
0
    def testColor4fVectorDataPrimimitiveVariable(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["myColor"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.Color4fVectorData([
                imath.Color4f(1, 0, 0, 1),
                imath.Color4f(0, 2, 0, 0),
                imath.Color4f(0, 0, 3, 0.25),
                imath.Color4f(4, 0, 0, 1),
            ]))

        with IECoreArnold.UniverseBlock(writable=True) as universe:

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            a = arnold.AiNodeGetArray(n, "myColor")

            self.assertEqual(arnold.AiArrayGetType(a.contents),
                             arnold.AI_TYPE_RGBA)
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)

            self.assertEqual(arnold.AiArrayGetRGBA(a, 0),
                             arnold.AtRGBA(1, 0, 0, 1))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 1),
                             arnold.AtRGBA(0, 2, 0, 0))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 2),
                             arnold.AtRGBA(0, 0, 3, 0.25))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 3),
                             arnold.AtRGBA(4, 0, 0, 1))
예제 #3
0
	def __arrayToSet( self, a ) :

		result = set()
		for i in range( 0,  arnold.AiArrayGetNumElements( a.contents ) ) :
			if arnold.AiArrayGetType( a.contents ) == arnold.AI_TYPE_STRING :
				result.add( arnold.AiArrayGetStr( a, i ) )
			else :
				raise TypeError

		return result
예제 #4
0
def arnoldToUsdParamString(paramEntry, scope):
    ret = ''
    paramName = ai.AiParamGetName(paramEntry)
    if paramName == 'name':
        return '' # nothing to return for attribute 'name'

    # Add the arnold scope to the attribute namespace, so that the token can be compiled
    if paramName == 'namespace' and len(scope) == 0:
        scope = 'arnold:'

    optionsStr = "customData = {string apiName = \"arnold_%s\"}" % paramName
    if len(paramName) == 1:
        paramName = paramName.lower()


    '''
    // TODO:
    // AI_TYPE_POINTER
    // AI_TYPE_NODE
    // AI_TYPE_USHORT
    // AI_TYPE_HALF
    // AI_TYPE_UNDEFINED
    // AI_TYPE_NONE
    '''
    paramType = ai.AiParamGetType(paramEntry)
    paramDefault = ai.AiParamGetDefault(paramEntry)
    paramVal = ''
    optionsStr = ''

    if paramType != ai.AI_TYPE_ARRAY:
        typeStr, valueStr, optionsValStr = getParameterStr(paramType, paramDefault, paramEntry)
        if typeStr is None or typeStr == '':
            return ''

        ret += typeStr
        paramVal = valueStr
        optionsStr += optionsValStr
        ret += ' {}{} = {} ({})'.format(scope, paramName, paramVal, optionsStr)

    else:
        # Array parameter
        arrayVal = paramDefault.contents.ARRAY
        if arrayVal is None or arrayVal[0] is None:
            return ''
        arrayVal = arrayVal[0]
        arrayType = ai.AiArrayGetType(arrayVal)
        typeStr, valueStr, optionsValStr = getParameterStr(arrayType)
        if typeStr is None or typeStr == '':
            return ''

        ret += '{}[] {}{}'.format(typeStr, scope, paramName)

    # FIXME do we need to set the API name ?
    # ret += ' (customData = {string apiName = "arnold{}"}\n'.format(GetCamelCase(paramName))
    return ret
예제 #5
0
def arnoldToUsdParamString(paramEntry, scope):
    ret = ''
    paramName = ai.AiParamGetName(paramEntry)
    if paramName == 'name':
        return ''  # nothing to return for attribute 'name'

    # Add the arnold scope to the attribute namespace, so that the token can be compiled
    if (paramName == 'namespace'
            or paramName == 'operator') and len(scope) == 0:
        scope = 'arnold:'

    if len(paramName) == 1:
        paramName = paramName.lower()
    '''
    // TODO:
    // AI_TYPE_POINTER
    // AI_TYPE_USHORT
    // AI_TYPE_HALF
    // AI_TYPE_UNDEFINED
    // AI_TYPE_NONE
    '''
    paramType = ai.AiParamGetType(paramEntry)
    paramDefault = ai.AiParamGetDefault(paramEntry)
    paramVal = ''
    optionsStr = 'customData = {string apiName = "'
    optionsStr += makeCamelCase(paramName)
    optionsStr += '"}'

    if paramType != ai.AI_TYPE_ARRAY:
        typeStr, valueStr, optionsValStr = getParameterStr(
            paramType, paramDefault, paramEntry)
        if typeStr is None or typeStr == '':
            return ''

        ret += typeStr
        paramVal = valueStr
        if len(optionsValStr) > 0:
            if len(optionsStr) > 0:
                optionsStr = '\n        {}{}\n        '.format(
                    optionsStr, optionsValStr)
            else:
                optionsStr = optionsValStr
        ret += ' {}{} = {} ({})'.format(scope, paramName, paramVal, optionsStr)

    else:
        # Array parameter
        arrayVal = paramDefault.contents.ARRAY
        if arrayVal is None or arrayVal[0] is None:
            return ''
        arrayVal = arrayVal[0]
        arrayType = ai.AiArrayGetType(arrayVal)
        typeStr, valueStr, optionsValStr = getParameterStr(arrayType)
        if typeStr is None or typeStr == '':
            return ''

        if len(optionsValStr) > 0:
            if len(optionsStr) > 0:
                optionsStr = '\n        {}{}\n        '.format(
                    optionsStr, optionsValStr)
            else:
                optionsStr = optionsValStr

        ret += '{}[] {}{} ({})'.format(typeStr, scope, paramName, optionsStr)

    return ret