Example #1
0
File: preset.py Project: JuhaW/vb30
    def _execute(self, context, vrsceneDict):
        for pluginDesc in vrsceneDict:
            pluginID    = pluginDesc['ID']
            pluginName  = pluginDesc['Name']
            pluginAttrs = pluginDesc['Attributes']

            pluginModule = PLUGINS_ID.get(pluginID)
            if pluginModule is None:
                continue

            if not hasattr(context.scene.vray, pluginID):
                # TODO: Add warning?
                continue

            propGroup = getattr(context.scene.vray, pluginID)

            for attrName in pluginAttrs:
                attrDesc  = NodesImport.getParamDesc(pluginModule.PluginParams, attrName)
                if attrDesc is None:
                    continue

                attrValue = pluginAttrs[attrName]
                if attrDesc['type'] == 'ENUM':
                    attrValue = str(attrValue)

                setattr(propGroup, attrName, attrValue)

        return {'FINISHED'}
Example #2
0
def createNodeBitmapBuffer(ntree, n, vrsceneDict, pluginDesc):
    pluginModule = PLUGINS_ID.get('BitmapBuffer')

    bitmatBuffer = NodeUtils.CreateNode(ntree, 'VRayNodeBitmapBuffer',
                                        pluginDesc['Name'])
    propGroup = bitmatBuffer.BitmapBuffer

    bitmapTexture = bitmatBuffer.texture

    imageFilepath = pluginDesc['Attributes'].get('file')

    importSettings = getPluginByName(vrsceneDict, "Import Settings")
    if importSettings:
        importDir = importSettings['Attributes']['dirpath']

    LoadImage(imageFilepath, importDir, bitmapTexture)

    for attrName in pluginDesc['Attributes']:
        attrDesc = getParamDesc(pluginModule.PluginParams, attrName)

        attrValue = pluginDesc['Attributes'][attrName]

        if hasattr(propGroup, attrName):
            if attrDesc['type'] == 'ENUM':
                attrValue = str(attrValue)
                if not AttributeUtils.ValueInEnumItems(attrDesc, attrValue):
                    debug.PrintError(
                        "Unsupported ENUM value '%s' for attribute: %s.%s" %
                        (attrValue, 'BitmapBuffer', attrName))
                    continue
            setattr(propGroup, attrName, attrValue)

    return bitmatBuffer
def ImportSettings(context, filePath, pluginFilter=None):
    debug.PrintInfo('Importing settings from "%s"' % filePath)

    vrsceneDict = ParseVrscene(filePath)

    for pluginDesc in vrsceneDict:
        pluginID = pluginDesc['ID']
        pluginName = pluginDesc['Name']
        pluginAttrs = pluginDesc['Attributes']

        if pluginID not in PLUGINS['SETTINGS']:
            continue

        pluginModule = PLUGINS_ID.get(pluginID)
        if pluginModule is None:
            continue

        if not hasattr(context.scene.vray, pluginID):
            continue

        propGroup = getattr(context.scene.vray, pluginID)

        for attrName in pluginAttrs:
            attrDesc = NodesImport.getParamDesc(pluginModule.PluginParams,
                                                attrName)
            if attrDesc is None:
                continue

            attrValue = pluginAttrs[attrName]
            if attrDesc['type'] == 'ENUM':
                attrValue = str(attrValue)

            setattr(propGroup, attrName, attrValue)

    return {'FINISHED'}
Example #4
0
def createNodeBitmapBuffer(ntree, n, vrsceneDict, pluginDesc):
    pluginModule = PLUGINS_ID.get('BitmapBuffer')

    bitmatBuffer = ntree.nodes.new('VRayNodeBitmapBuffer')
    propGroup = bitmatBuffer.BitmapBuffer

    bitmapTexture = bitmatBuffer.texture

    imageFilepath = pluginDesc['Attributes'].get('file')

    importSettings = getPluginByName(vrsceneDict, "Import Settings")
    if importSettings:
        importDir = importSettings['Attributes']['dirpath']

    LoadImage(imageFilepath, importDir, bitmapTexture)

    for attrName in pluginDesc['Attributes']:
        attrDesc  = getParamDesc(pluginModule.PluginParams, attrName)

        attrValue = pluginDesc['Attributes'][attrName]

        if hasattr(propGroup, attrName):
            if attrDesc['type'] == 'ENUM':
                attrValue = str(attrValue)
                if not AttributeUtils.ValueInEnumItems(attrDesc, attrValue):
                    debug.PrintError("Unsupported ENUM value '%s' for attribute: %s.%s" %
                        (attrValue, 'BitmapBuffer', attrName))
                    continue
            setattr(propGroup, attrName, attrValue)

    return bitmatBuffer
Example #5
0
def ImportSettings(context, filePath, pluginFilter=None):
    debug.PrintInfo('Importing settings from "%s"' % filePath)

    vrsceneDict = ParseVrscene(filePath)

    for pluginDesc in vrsceneDict:
        pluginID    = pluginDesc['ID']
        pluginName  = pluginDesc['Name']
        pluginAttrs = pluginDesc['Attributes']

        if pluginID not in PLUGINS['SETTINGS']:
            continue

        pluginModule = PLUGINS_ID.get(pluginID)
        if pluginModule is None:
            continue

        if not hasattr(context.scene.vray, pluginID):
            continue

        propGroup = getattr(context.scene.vray, pluginID)

        for attrName in pluginAttrs:
            attrDesc  = NodesImport.getParamDesc(pluginModule.PluginParams, attrName)
            if attrDesc is None:
                continue

            attrValue = pluginAttrs[attrName]
            if attrDesc['type'] == 'ENUM':
                attrValue = str(attrValue)

            setattr(propGroup, attrName, attrValue)

    return {'FINISHED'}
    def _execute(self, context, vrsceneDict):
        for pluginDesc in vrsceneDict:
            pluginID    = pluginDesc['ID']
            pluginName  = pluginDesc['Name']
            pluginAttrs = pluginDesc['Attributes']

            pluginModule = PLUGINS_ID.get(pluginID)
            if pluginModule is None:
                continue

            if not hasattr(context.scene.vray, pluginID):
                # TODO: Add warning?
                continue

            propGroup = getattr(context.scene.vray, pluginID)

            for attrName in pluginAttrs:
                attrDesc  = NodesImport.getParamDesc(pluginModule.PluginParams, attrName)
                if attrDesc is None:
                    continue

                attrValue = pluginAttrs[attrName]
                if attrDesc['type'] == 'ENUM':
                    attrValue = str(attrValue)

                setattr(propGroup, attrName, attrValue)

        return {'FINISHED'}
    def execute(self, context):
        preset_menu_class = getattr(bpy.types, self.preset_menu)
        preset_type = preset_menu_class.preset_subdir

        presetSubdir = PathUtils.CreateDirectory(os.path.join(SysUtils.GetUserConfigDir(), "presets"))
        exportPath   = PathUtils.CreateDirectory(os.path.join(presetSubdir, preset_type))

        presetName = preset_menu_class.bl_label if self.remove_active else self.name

        fileName = "%s.vrscene" % LibUtils.CleanString(bpy.path.display_name(presetName))

        outputFilepath = os.path.normpath(os.path.join(exportPath, fileName))

        if self.remove_active:
            # NOTE: Remove function is locked to user config directory,
            # so system settings are safe

            debug.PrintInfo('Removing preset file: "%s"' % outputFilepath)
            if not os.path.exists(outputFilepath):
                return {'CANCELLED'}
            try:
                os.remove(outputFilepath)
            except:
                debug.PrintError('Error removing preset file: "%s"!' % outputFilepath)

            # Set default menu name
            preset_menu_class.bl_label = bpy.path.display_name(preset_type)

        else:
            bus = {
                'output' : VRayStream.VRaySimplePluginExporter(outputFilepath),
                'scene'  : context.scene,
                'camera' : context.scene.camera,
                'preview' : False,
            }

            pluginPresetIDs = None
            if preset_type == 'global':
                pluginPresetIDs = (pID for pID in sorted(PLUGINS['SETTINGS']))
            else:
                pluginPresetIDs = PresetTypePlugins[preset_type]

            for pluginID in pluginPresetIDs:
                pluginModule = PLUGINS_ID.get(pluginID)
                if pluginModule is None:
                    continue

                if not hasattr(context.scene.vray, pluginID):
                    continue

                propGroup = getattr(context.scene.vray, pluginID)

                ExportUtils.WritePlugin(bus, pluginModule, pluginID.lower(), propGroup, {})

        return {'FINISHED'}
Example #8
0
def createNodeTexRemap(ntree, prevNode, vrsceneDict, pluginDesc):
    pluginModule = PLUGINS_ID.get('TexRemap')
    texTexRemap = NodeUtils.CreateNode(ntree, 'VRayNodeTexRemap',
                                       pluginDesc['Name'])
    propGroup = texTexRemap.TexRemap

    attributes = pluginDesc['Attributes']

    FillRamp(vrsceneDict, texTexRemap.texture.color_ramp,
             attributes['color_colors'], attributes['color_positions'])

    return texTexRemap
Example #9
0
def createNodeTexRemap(ntree, prevNode, vrsceneDict, pluginDesc):
    pluginModule = PLUGINS_ID.get('TexRemap')
    texTexRemap  = ntree.nodes.new('VRayNodeTexRemap')
    propGroup    = texTexRemap.TexRemap

    attributes   = pluginDesc['Attributes']

    FillRamp(vrsceneDict,
        texTexRemap.texture.color_ramp,
        attributes['color_colors'],
        attributes['color_positions']
    )

    return texTexRemap
Example #10
0
def createNodeTexGradRamp(ntree, prevNode, vrsceneDict, pluginDesc):
    pluginModule = PLUGINS_ID.get('TexGradRamp')
    texGradRamp  = NodeUtils.CreateNode(ntree, 'VRayNodeTexGradRamp', pluginDesc['Name'])
    propGroup    = texGradRamp.TexGradRamp

    attributes   = pluginDesc['Attributes']

    FillRamp(vrsceneDict,
        texGradRamp.texture.color_ramp,
        attributes['colors'],
        attributes['positions']
    )

    return texGradRamp
Example #11
0
def createNode(ntree, prevNode, vrsceneDict, pluginDesc):
    from vb30.plugins import PLUGINS_ID

    pluginID = pluginDesc['ID']
    pluginName = pluginDesc['Name']
    pluginAttrs = pluginDesc['Attributes']

    for n in ntree.nodes:
        if n.name == pluginName:
            return ntree.nodes[pluginName]

    if pluginID == 'TexLayered':
        return createNodeTexLayered(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'BRDFLayered':
        return createNodeBRDFLayered(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'BitmapBuffer':
        return createNodeBitmapBuffer(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'TexGradRamp':
        return createNodeTexGradRamp(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'TexRemap':
        return createNodeTexRemap(ntree, prevNode, vrsceneDict, pluginDesc)

    else:
        pluginModule = PLUGINS_ID.get(pluginID)
        if pluginModule is None:
            debug.PrintError(
                "Plugin '%s' is not yet supported! This shouldn't happen! Please, report this!"
                % pluginID)
            return None

        n = NodeUtils.CreateNode(ntree, 'VRayNode%s' % pluginID, pluginName)

        # This property group holds all plugin settings
        #
        propGroup = getattr(n, pluginID)

        # Now go through all plugin attributes and check
        # if we should create other nodes or simply set the value
        #
        for attrName in pluginAttrs:
            attrValue = pluginAttrs[attrName]

            # NOTE: Fixes vrscene exported from other applications using deprecated 'bump_tex'
            # attribute
            fixBump = False
            if attrName == 'bump_tex':
                fixBump = True
                attrName = 'bump_tex_color'

            attrDesc = getParamDesc(pluginModule.PluginParams, attrName)
            if attrDesc is None:
                # XXX: This could happen when loading VISMATS; error message disabled here...
                # print("Plugin '%s': Attribute '%s' is not yet supported! This is very strange!" % (pluginID, attrName))
                continue

            attrSocketName = getSocketName(pluginModule.PluginParams, attrName)

            # Attribute is a output type - nothing to do
            if attrDesc['type'] in AttributeUtils.OutputTypes:
                continue

            if attrDesc['type'] == 'MATRIX':
                mNode = NodeUtils.CreateNode(ntree, 'VRayNodeMatrix')

                m = mathutils.Matrix()
                m.identity()

                if type(attrValue) in {list, tuple}:
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = attrValue[r][c]

                else:
                    tmArray = struct.unpack(
                        "fffffffff",
                        binascii.unhexlify(bytes(attrValue, 'ascii')))
                    i = 0
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmArray[i]
                            i += 1

                _tmp, rotate, scale = m.decompose()
                rotate = rotate.to_euler('XYZ')

                tmNode.rotate = (rotate[0], rotate[1], rotate[2])
                tmNode.scale = (scale[0], scale[1], scale[2])

                ntree.links.new(mNode.outputs['Matrix'],
                                n.inputs[attrSocketName])

                continue

            if attrDesc['type'] == 'TRANSFORM':
                tmNode = NodeUtils.CreateNode(ntree, 'VRayNodeTransform')

                m = mathutils.Matrix()
                m.identity()

                if type(attrValue) in {list, tuple}:
                    tmM = attrValue[0]
                    tmOffs = attrValue[1]

                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmM[r][c]
                    for c in range(3):
                        m[c][3] = tmOffs[c]

                else:
                    tmArray = struct.unpack(
                        "fffffffffddd",
                        binascii.unhexlify(bytes(attrValue, 'ascii')))
                    i = 0
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmArray[i]
                            i += 1

                offset, rotate, scale = m.decompose()
                rotate = rotate.to_euler('XYZ')

                tmNode.offset = (offset[0], offset[1], offset[2])
                tmNode.rotate = (rotate[0], rotate[1], rotate[2])
                tmNode.scale = (scale[0], scale[1], scale[2])

                ntree.links.new(tmNode.outputs['Transform'],
                                n.inputs[attrSocketName])

                continue

            if attrDesc['type'] not in AttributeUtils.InputTypes:
                # Attribute is not mappable, so simply set it's value
                if attrDesc['type'] == 'ENUM':
                    attrValue = str(attrValue)

                    if not AttributeUtils.ValueInEnumItems(
                            attrDesc, attrValue):
                        debug.PrintError(
                            "Unsupported ENUM value '%s' for attribute: %s.%s"
                            % (attrValue, pluginID, attrName))
                        attrValue = None

                if attrValue is not None:
                    setattr(propGroup, attrName, attrValue)

            else:
                # Attribute could possibly be mapped with other node
                # Check if we could find requested node in a vrsceneDict
                if type(attrValue) is str:
                    inPluginName = attrValue
                    inPluginOutput = None

                    # Check if a specific output is requested (like MyTexture::out_intensity)
                    if inPluginName.find("::") != -1:
                        inPluginName, inPluginOutput = attrValue.split("::")

                    # Set socket value
                    connectedPlugin = getPluginByName(vrsceneDict,
                                                      inPluginName)
                    if connectedPlugin is None:
                        if type(attrValue) is str:
                            # TODO: finish this or check if None is ok here
                            if attrDesc['type'] == 'ENUM':
                                pass
                        else:
                            attrSocket = n.inputs[attrSocketName]
                            attrSocket.value = attrValue

                    # Create connected plugin
                    else:
                        connectedPluginID = connectedPlugin['ID']

                        collapsedValue = CollapseToValue(connectedPlugin)
                        if collapsedValue is not None:
                            attrSocket = n.inputs[attrSocketName]
                            attrSocket.value = FixValue(collapsedValue)

                        else:
                            inPluginOutputSocketName = AttributeUtils.GetNameFromAttr(
                                inPluginOutput
                            ) if inPluginOutput else getOutputSocket(
                                connectedPluginID)

                            connectedNode = createNode(ntree, n, vrsceneDict,
                                                       connectedPlugin)
                            if connectedNode:
                                ntree.links.new(
                                    connectedNode.
                                    outputs[inPluginOutputSocketName],
                                    n.inputs[attrSocketName])

                                if fixBump:
                                    ntree.links.new(
                                        getOutputSocketByAttr(
                                            connectedNode, 'out_intensity'),
                                        n.inputs['Float Texture'])

                # Attr is not linked - set socket default value
                else:
                    attrSocket = n.inputs[attrSocketName]
                    attrValue = FixValue(attrValue)

                    attrSocket.value = attrValue

    return n
Example #12
0
def createNode(ntree, prevNode, vrsceneDict, pluginDesc):
    from vb30.plugins import PLUGINS_ID

    pluginID    = pluginDesc['ID']
    pluginName  = pluginDesc['Name']
    pluginAttrs = pluginDesc['Attributes']

    for n in ntree.nodes:
        if n.name == pluginName:
            return ntree.nodes[pluginName]

    if pluginID == 'TexLayered':
        return createNodeTexLayered(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'BRDFLayered':
        return createNodeBRDFLayered(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'BitmapBuffer':
        return createNodeBitmapBuffer(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'TexGradRamp':
        return createNodeTexGradRamp(ntree, prevNode, vrsceneDict, pluginDesc)

    elif pluginID == 'TexRemap':
        return createNodeTexRemap(ntree, prevNode, vrsceneDict, pluginDesc)

    else:
        pluginModule = PLUGINS_ID.get(pluginID)
        if pluginModule is None:
            debug.PrintError("Plugin '%s' is not yet supported! This shouldn't happen! Please, report this!" % pluginID)
            return None

        n = ntree.nodes.new('VRayNode%s' % pluginID)
        n.name = pluginName

        # This property group holds all plugin settings
        #
        propGroup = getattr(n, pluginID)

        # Now go through all plugin attributes and check
        # if we should create other nodes or simply set the value
        #
        for attrName in pluginAttrs:
            attrValue = pluginAttrs[attrName]

            # NOTE: Fixes vrscene exported from other applications using deprecated 'bump_tex'
            # attribute
            fixBump = False
            if attrName == 'bump_tex':
                fixBump  = True
                attrName = 'bump_tex_color'

            attrDesc  = getParamDesc(pluginModule.PluginParams, attrName)
            if attrDesc is None:
                # XXX: This could happen when loading VISMATS; error message disabled here...
                # print("Plugin '%s': Attribute '%s' is not yet supported! This is very strange!" % (pluginID, attrName))
                continue

            attrSocketName = getSocketName(pluginModule.PluginParams, attrName)

            # Attribute is a output type - nothing to do
            if attrDesc['type'] in AttributeUtils.OutputTypes:
                continue

            if attrDesc['type'] == 'MATRIX':
                mNode = ntree.nodes.new('VRayNodeMatrix')

                m = mathutils.Matrix()
                m.identity()

                if type(attrValue) in {list, tuple}:
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = attrValue[r][c]

                else:
                    tmArray = struct.unpack("fffffffff", binascii.unhexlify(bytes(attrValue, 'ascii')))
                    i = 0
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmArray[i]
                            i += 1

                _tmp, rotate, scale = m.decompose()
                rotate = rotate.to_euler('XYZ')

                tmNode.rotate = (rotate[0], rotate[1], rotate[2])
                tmNode.scale  = (scale[0],  scale[1],  scale[2])

                ntree.links.new(
                    mNode.outputs['Matrix'],
                    n.inputs[attrSocketName]
                )

                continue

            if attrDesc['type'] == 'TRANSFORM':
                tmNode = ntree.nodes.new('VRayNodeTransform')

                m = mathutils.Matrix()
                m.identity()

                if type(attrValue) in {list, tuple}:
                    tmM    = attrValue[0]
                    tmOffs = attrValue[1]

                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmM[r][c]
                    for c in range(3):
                        m[c][3] = tmOffs[c]

                else:
                    tmArray = struct.unpack("fffffffffddd", binascii.unhexlify(bytes(attrValue, 'ascii')))
                    i = 0
                    for c in range(3):
                        for r in range(3):
                            m[c][r] = tmArray[i]
                            i += 1

                offset, rotate, scale = m.decompose()
                rotate = rotate.to_euler('XYZ')

                tmNode.offset = (offset[0], offset[1], offset[2])
                tmNode.rotate = (rotate[0], rotate[1], rotate[2])
                tmNode.scale  = (scale[0],  scale[1],  scale[2])

                ntree.links.new(
                    tmNode.outputs['Transform'],
                    n.inputs[attrSocketName]
                )

                continue

            if attrDesc['type'] not in AttributeUtils.InputTypes:
                # Attribute is not mappable, so simply set it's value
                if attrDesc['type'] == 'ENUM':
                    attrValue = str(attrValue)

                    if not AttributeUtils.ValueInEnumItems(attrDesc, attrValue):
                        debug.PrintError("Unsupported ENUM value '%s' for attribute: %s.%s" %
                            (attrValue, pluginID, attrName))
                        attrValue = None

                if attrValue is not None:
                    setattr(propGroup, attrName, attrValue)

            else:
                # Attribute could possibly be mapped with other node
                # Check if we could find requested node in a vrsceneDict
                if type(attrValue) is str:
                    inPluginName   = attrValue
                    inPluginOutput = None

                    # Check if a specific output is requested (like MyTexture::out_intensity)
                    if inPluginName.find("::") != -1:
                        inPluginName, inPluginOutput = attrValue.split("::")

                    # Set socket value
                    connectedPlugin = getPluginByName(vrsceneDict, inPluginName)
                    if connectedPlugin is None:
                        if type(attrValue) is str:
                            # TODO: finish this or check if None is ok here
                            if attrDesc['type'] == 'ENUM':
                                pass
                        else:
                            attrSocket = n.inputs[attrSocketName]
                            attrSocket.value = attrValue

                    # Create connected plugin
                    else:
                        connectedPluginID = connectedPlugin['ID']

                        collapsedValue = CollapseToValue(connectedPlugin)
                        if collapsedValue is not None:
                            attrSocket.value = FixValue(collapsedValue)

                        else:
                            inPluginOutputSocketName = AttributeUtils.GetNameFromAttr(inPluginOutput) if inPluginOutput else getOutputSocket(connectedPluginID)

                            connectedNode = createNode(ntree, n, vrsceneDict, connectedPlugin)
                            if connectedNode:
                                ntree.links.new(connectedNode.outputs[inPluginOutputSocketName], n.inputs[attrSocketName])

                                if fixBump:
                                    ntree.links.new(
                                        getOutputSocketByAttr(connectedNode, 'out_intensity'),
                                        n.inputs['Float Texture']
                                    )

                # Attr is not linked - set socket default value
                else:
                    attrSocket = n.inputs[attrSocketName]
                    attrValue  = FixValue(attrValue)

                    attrSocket.value = attrValue

    return n