コード例 #1
0
def ConvertNodeMaterial(scene, ob, ma):
    debug.PrintInfo("Converting node material: %s" % ma.name)

    materialNode = None

    maNtree = ma.node_tree
    nt = _createVRayTree(ma.name, 'Material')

    ntOutput = _createVRayNode(nt, 'OutputMaterial')
    ntMaterial = _createVRayNode(nt, 'MtlSingleBRDF')
    _connectNodes(nt, ntMaterial, 'Material', ntOutput, 'Material')

    maNtreeOutput = NodesUtils.GetNodeByType(maNtree,
                                             'ShaderNodeOutputMaterial')
    maShader = NodesUtils.GetConnectedNode(maNtree,
                                           maNtreeOutput.inputs['Surface'])

    vrayNode = ConvertNode(maNtree, maShader, nt)
    if vrayNode:
        _connectNodes(nt, vrayNode, 'BRDF', ntMaterial, 'BRDF')

    NodesTools.rearrangeTree(nt, ntOutput)
    NodesTools.deselectNodes(nt)

    ma.vray.ntree = nt

    return ntMaterial
コード例 #2
0
ファイル: convert.py プロジェクト: ISRAELAVLIS33/vb30
def ConvertNodeMaterial(scene, ob, ma):
    debug.PrintInfo("Converting node material: %s" % ma.name)

    materialNode = None

    maNtree = ma.node_tree
    nt      = _createVRayTree(ma.name, 'Material')

    ntOutput   = _createVRayNode(nt, 'OutputMaterial')
    ntMaterial = _createVRayNode(nt, 'MtlSingleBRDF')
    _connectNodes(nt, ntMaterial, 'Material', ntOutput, 'Material')

    maNtreeOutput = NodesUtils.GetNodeByType(maNtree, 'ShaderNodeOutputMaterial')
    maShader      = NodesUtils.GetConnectedNode(maNtree, maNtreeOutput.inputs['Surface'])

    vrayNode = ConvertNode(maNtree, maShader, nt)
    if vrayNode:
        _connectNodes(nt, vrayNode, 'BRDF', ntMaterial, 'BRDF')

    NodesTools.rearrangeTree(nt, ntOutput)
    NodesTools.deselectNodes(nt)

    ma.vray.ntree = nt

    return ntMaterial
コード例 #3
0
ファイル: preset.py プロジェクト: JuhaW/vb30
    def _execute(self, context, vrsceneDict):
        space = context.space_data
        ntree = space.edit_tree

        # Deselect before import
        NodesTools.deselectNodes(ntree)

        # Get fake asset node
        assetDesc = NodesImport.getPluginByType(vrsceneDict, "Asset")
        assetType = assetDesc['Name']

        # Import template
        lastNode = None

        if assetType == 'Material':
            maName = assetDesc['Attributes']['material']
            maDesc = NodesImport.getPluginByName(vrsceneDict, maName)

            maNode = NodesImport.createNode(ntree, None, vrsceneDict, maDesc)

            # NOTE: Depends on how user saves the preset
            if 'Material' not in maNode.outputs:
                lastNode = maNode

            else:
                outputNode = ntree.nodes.new('VRayNodeOutputMaterial')
                ntree.links.new(maNode.outputs['Material'], outputNode.inputs['Material'])
                lastNode = outputNode

        elif assetType == 'Texture':
            texName = assetDesc['Attributes']['texture']
            texDesc = NodesImport.getPluginByName(vrsceneDict, texName)

            lastNode = NodesImport.createNode(ntree, None, vrsceneDict, texDesc)

        elif assetType == 'Channel':
            chanNames = assetDesc['Attributes']['channel']
            if len(chanNames):
                channContainer = ntree.nodes.new('VRayNodeRenderChannels')

                for i,chanName in enumerate(reversed(chanNames)):
                    chanSockName = "Channel %i" % i
                    NodesSockets.AddInput(channContainer, 'VRaySocketRenderChannel', chanSockName)

                    chanDesc = NodesImport.getPluginByName(vrsceneDict, chanName)
                    chanNode = NodesImport.createNode(ntree, None, vrsceneDict, chanDesc)

                    ntree.links.new(chanNode.outputs['Channel'], channContainer.inputs[chanSockName])

                lastNode = channContainer

        if lastNode:
            NodesTools.rearrangeTree(ntree, lastNode)

        return {'FINISHED'}
コード例 #4
0
    def _execute(self, context, vrsceneDict):
        space = context.space_data
        ntree = space.edit_tree

        # Deselect before import
        NodesTools.deselectNodes(ntree)

        # Get fake asset node
        assetDesc = NodesImport.getPluginByType(vrsceneDict, "Asset")
        assetType = assetDesc['Name']

        # Import template
        lastNode = None

        if assetType == 'Material':
            maName = assetDesc['Attributes']['material']
            maDesc = NodesImport.getPluginByName(vrsceneDict, maName)

            maNode = NodesImport.createNode(ntree, None, vrsceneDict, maDesc)

            # NOTE: Depends on how user saves the preset
            if 'Material' not in maNode.outputs:
                lastNode = maNode

            else:
                outputNode = ntree.nodes.new('VRayNodeOutputMaterial')
                ntree.links.new(maNode.outputs['Material'], outputNode.inputs['Material'])
                lastNode = outputNode

        elif assetType == 'Texture':
            texName = assetDesc['Attributes']['texture']
            texDesc = NodesImport.getPluginByName(vrsceneDict, texName)

            lastNode = NodesImport.createNode(ntree, None, vrsceneDict, texDesc)

        elif assetType == 'Channel':
            chanNames = assetDesc['Attributes']['channel']
            if len(chanNames):
                channContainer = ntree.nodes.new('VRayNodeRenderChannels')

                for i,chanName in enumerate(reversed(chanNames)):
                    chanSockName = "Channel %i" % i
                    NodesSockets.AddInput(channContainer, 'VRaySocketRenderChannel', chanSockName)

                    chanDesc = NodesImport.getPluginByName(vrsceneDict, chanName)
                    chanNode = NodesImport.createNode(ntree, None, vrsceneDict, chanDesc)

                    ntree.links.new(chanNode.outputs['Channel'], channContainer.inputs[chanSockName])

                lastNode = channContainer

        if lastNode:
            NodesTools.rearrangeTree(ntree, lastNode)

        return {'FINISHED'}
コード例 #5
0
ファイル: preset.py プロジェクト: ISRAELAVLIS33/vb30
    def _execute(self, context, vrsceneDict):
        space = context.space_data
        ntree = space.edit_tree

        # Deselect before import
        NodesTools.deselectNodes(ntree)

        # Get fake asset node
        assetDesc = NodesImport.getPluginByType(vrsceneDict, "Asset")
        assetType = assetDesc['Name']

        # Import template
        lastNode = None

        if assetType == 'Material':
            maName = assetDesc['Attributes']['material']
            maDesc = NodesImport.getPluginByName(vrsceneDict, maName)

            maNode = NodesImport.createNode(ntree, None, vrsceneDict, maDesc)

            # NOTE: Depends on how user saves the preset
            if 'Material' not in maNode.outputs:
                lastNode = maNode

            else:
                outputNode = ntree.nodes.new('VRayNodeOutputMaterial')
                ntree.links.new(maNode.outputs['Material'], outputNode.inputs['Material'])
                lastNode = outputNode

        elif assetType == 'Texture':
            texName = assetDesc['Attributes']['texture']
            texDesc = NodesImport.getPluginByName(vrsceneDict, texName)

            lastNode = NodesImport.createNode(ntree, None, vrsceneDict, texDesc)

        if lastNode:
            NodesTools.rearrangeTree(ntree, lastNode)

        return {'FINISHED'}
コード例 #6
0
ファイル: MtlVRmat.py プロジェクト: Zaurio/vb30
    def execute(self, context):
        node = context.node
        if not node:
            Debug.PrintError("No active node!")
            return {"CANCELLED"}
        if node.bl_idname != "VRayNodeMtlVRmat":
            Debug.PrintError("Selected node is not of type VRayNodeMtlVRmat!")
            return {"CANCELLED"}

        MtlVRmat = node.MtlVRmat
        if not MtlVRmat.filename:
            Debug.PrintError("Filepath is not set!")
            return {"CANCELLED"}

        if not MtlVRmat.mtlname:
            Debug.PrintError("Material is not chosen!")
            return {"CANCELLED"}

        filePath = os.path.normpath(bpy.path.abspath(MtlVRmat.filename))
        if not os.path.exists(filePath):
            Debug.PrintError("File doesn't exist!")
            return {"CANCELLED"}

        namePrefix = ""
        vrsceneDict = []
        if filePath.endswith(".vrscene"):
            vrsceneDict = ParseVrscene(filePath)
        else:
            vrsceneDict = ParseVrmat(filePath)
            namePrefix = "/"

        # Preview data from the file
        #
        # for pluginDesc in vrsceneDict:
        #     pluginID    = pluginDesc['ID']
        #     pluginName  = pluginDesc['Name']
        #     pluginAttrs = pluginDesc['Attributes']
        #
        #     print("Plugin:")
        #     print("  Type: %s" % pluginID)
        #     print("  Name: %s" % pluginName)
        #     print("  Attributes:")
        #     for attrName in pluginAttrs:
        #         print("    %s = %s" % (attrName, pluginAttrs[attrName]))

        # Find requested material plugin
        #
        mtlName = namePrefix + MtlVRmat.mtlname
        mtlPlugDesc = NodesImport.getPluginByName(vrsceneDict, mtlName)

        if not mtlPlugDesc:
            print("Requested material is not found!")
            return {"CANCELLED"}

        ntree = context.space_data.edit_tree

        # Now lets start creating nodes
        #
        mtlNode = NodesImport.createNode(ntree, node, vrsceneDict, mtlPlugDesc)

        # Connect material output to our node
        #
        ntree.links.new(mtlNode.outputs["Material"], node.inputs["Material"])

        NodesTools.rearrangeTree(ntree, node)

        return {"FINISHED"}
コード例 #7
0
def ImportMaterialWithDisplacement(context, filePath, use_fake_user=True):
    debug.PrintInfo('Importing materials from "%s"' % filePath)

    vrsceneDict = {}

    if filePath.endswith(".vrscene"):
        vrsceneDict = ParseVrscene(filePath)
    else:
        vrsceneDict = ParseVrmat(filePath)

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

        if pluginID == 'Node':
            nodeNames.append(pluginName)

    for nodeName in nodeNames:
        debug.PrintInfo("Importing material from Node: %s" % nodeName)

        nodePluginDesc = NodesImport.getPluginByName(vrsceneDict, nodeName)

        # Import material
        #
        maName = nodePluginDesc['Attributes']['material']
        if maName in bpy.data.node_groups:
            continue

        maPluginDesc = NodesImport.getPluginByName(vrsceneDict, maName)
        if not maPluginDesc:
            continue

        maNtree = bpy.data.node_groups.new(maName, type='VRayNodeTreeMaterial')
        maNtree.use_fake_user = True

        maOutputNode = maNtree.nodes.new('VRayNodeOutputMaterial')

        maNode = NodesImport.createNode(maNtree, maOutputNode, vrsceneDict,
                                        maPluginDesc)

        maNtree.links.new(maNode.outputs['Material'],
                          maOutputNode.inputs['Material'])

        NodesTools.rearrangeTree(maNtree, maOutputNode)

        # Check geometry for displacement
        #
        geomName = nodePluginDesc['Attributes']['geometry']

        geomPluginDesc = NodesImport.getPluginByName(vrsceneDict, geomName)

        if geomPluginDesc and geomPluginDesc['ID'] == 'GeomDisplacedMesh':
            colorTexName = geomPluginDesc['Attributes'].get(
                "displacement_tex_color")
            floatTexName = geomPluginDesc['Attributes'].get(
                "displacement_tex_float")

            if colorTexName or floatTexName:
                # Create node tree with displace name
                dispNtree = bpy.data.node_groups.new(
                    geomPluginDesc['Name'], type='VRayNodeTreeMaterial')
                dispNtree.use_fake_user = True

                # Add group output to displace tree
                dispGroupOutput = dispNtree.nodes.new('NodeGroupOutput')

                # Import texture nodes
                colorTexNode = NodesImport.FindAndCreateNode(
                    vrsceneDict, colorTexName, dispNtree, dispGroupOutput)
                floatTexNode = NodesImport.FindAndCreateNode(
                    vrsceneDict, floatTexName, dispNtree, dispGroupOutput)

                # Add/connect output sockets
                if colorTexName:
                    dispNtree.outputs.new('VRaySocketColor', 'Color')
                    dispNtree.links.new(colorTexNode.outputs['Output'],
                                        dispGroupOutput.inputs['Color'])
                if floatTexName:
                    dispNtree.outputs.new('VRaySocketFloat', 'Float')
                    dispNtree.links.new(floatTexNode.outputs['Output'],
                                        dispGroupOutput.inputs['Float'])

                NodesTools.rearrangeTree(dispNtree, dispGroupOutput)
                NodesTools.deselectNodes(dispNtree)

                # Create a group node in current material tree
                # to show user that we have displacement
                dispGroupNode = maNtree.nodes.new('ShaderNodeGroup')
                dispGroupNode.node_tree = dispNtree
                dispGroupNode.location.x = 0
                dispGroupNode.location.y = 100

        # Finally create a material
        CreateMaterial(maName, maNtree, use_fake_user)
        NodesTools.deselectNodes(maNtree)

    return {'FINISHED'}
コード例 #8
0
def ImportMaterials(context, filePath, baseMaterial, use_fake_user=True):
    debug.PrintInfo('Importing materials from "%s"' % filePath)

    vrsceneDict = {}

    if filePath.endswith(".vrscene"):
        vrsceneDict = ParseVrscene(filePath)
    else:
        vrsceneDict = ParseVrmat(filePath)

    MaterialTypeFilter = {
        'STANDARD': {
            'MtlSingleBRDF',
            'MtlVRmat',
            'MtlDoubleSided',
            'MtlGLSL',
            'MtlLayeredBRDF',
            'MtlDiffuse',
            'MtlBump',
            'Mtl2Sided',
        },
        'MULTI': {'MtlMulti'},
        'WRAPPED': {
            'MtlWrapper',
            'MtlWrapperMaya',
            'MayaMtlMatte',
            'MtlMaterialID',
            'MtlMayaRamp',
            'MtlObjBBox',
            'MtlOverride',
            'MtlRenderStats',
            'MtlRoundEdges',
            'MtlStreakFade',
        },
    }

    # Collect material names based on selected
    # base material type
    #
    materialNames = []
    for pluginDesc in vrsceneDict:
        pluginID = pluginDesc['ID']
        pluginName = pluginDesc['Name']

        if pluginID in MaterialTypeFilter[baseMaterial]:
            materialNames.append(pluginName)

    for maName in materialNames:
        debug.PrintInfo("Importing material: %s" % maName)

        pluginDesc = NodesImport.getPluginByName(vrsceneDict, maName)

        ntree = bpy.data.node_groups.new(maName, type='VRayNodeTreeMaterial')
        ntree.use_fake_user = True

        outputNode = ntree.nodes.new('VRayNodeOutputMaterial')

        maNode = NodesImport.createNode(ntree, outputNode, vrsceneDict,
                                        pluginDesc)

        ntree.links.new(maNode.outputs['Material'],
                        outputNode.inputs['Material'])

        NodesTools.rearrangeTree(ntree, outputNode)
        NodesTools.deselectNodes(ntree)

        # Finally create a material
        CreateMaterial(maName, ntree, use_fake_user)

    return {'FINISHED'}
コード例 #9
0
    def execute(self, context):
        node = context.node
        if not node:
            Debug.PrintError("No active node!")
            return {'CANCELLED'}
        if node.bl_idname != "VRayNodeMtlVRmat":
            Debug.PrintError("Selected node is not of type VRayNodeMtlVRmat!")
            return {'CANCELLED'}

        MtlVRmat = node.MtlVRmat
        if not MtlVRmat.filename:
            Debug.PrintError("Filepath is not set!")
            return {'CANCELLED'}

        if not MtlVRmat.mtlname:
            Debug.PrintError("Material is not chosen!")
            return {'CANCELLED'}

        filePath = os.path.normpath(bpy.path.abspath(MtlVRmat.filename))
        if not os.path.exists(filePath):
            Debug.PrintError("File doesn't exist!")
            return {'CANCELLED'}

        namePrefix = ""
        vrsceneDict = []
        if filePath.endswith(".vrscene"):
            vrsceneDict = ParseVrscene(filePath)
        else:
            vrsceneDict = ParseVrmat(filePath)
            namePrefix = "/"

        # Preview data from the file
        #
        # for pluginDesc in vrsceneDict:
        #     pluginID    = pluginDesc['ID']
        #     pluginName  = pluginDesc['Name']
        #     pluginAttrs = pluginDesc['Attributes']
        #
        #     print("Plugin:")
        #     print("  Type: %s" % pluginID)
        #     print("  Name: %s" % pluginName)
        #     print("  Attributes:")
        #     for attrName in pluginAttrs:
        #         print("    %s = %s" % (attrName, pluginAttrs[attrName]))

        # Find requested material plugin
        #
        mtlName = namePrefix + MtlVRmat.mtlname
        mtlPlugDesc = NodesImport.getPluginByName(vrsceneDict, mtlName)

        if not mtlPlugDesc:
            print("Requested material is not found!")
            return {'CANCELLED'}

        ntree = context.space_data.edit_tree

        # Now lets start creating nodes
        #
        mtlNode = NodesImport.createNode(ntree, node, vrsceneDict, mtlPlugDesc)

        # Connect material output to our node
        #
        ntree.links.new(mtlNode.outputs['Material'], node.inputs['Material'])

        NodesTools.rearrangeTree(ntree, node)

        return {'FINISHED'}
コード例 #10
0
ファイル: convert.py プロジェクト: ISRAELAVLIS33/vb30
def ConvertObject(scene, ob):
    debug.PrintInfo("Converting object: %s" % ob.name)

    VRayObject = ob.vray
    VRayData   = ob.data.vray

    needNodeTree    = False
    hasDisplacement = None

    for ms in ob.material_slots:
        if not (ms and ms.material):
            continue

        ma = ms.material

        textures = ProcessTextures(ma)

        ConvertMaterial(scene, ob, ma, textures)

        if 'displacement' in textures:
            debug.PrintInfo("  Found displacement")
            hasDisplacement = textures['displacement']

    # Check if we need node tree from override materials
    for ovrName in ObjectMaterialOverrides:
        ovrPropGroup = getattr(VRayObject, ovrName)
        ovrUse = getattr(ovrPropGroup, 'use')
        if ovrUse:
            debug.PrintInfo("  Found override: %s" % ovrName)
            needNodeTree = True
            break

    needNodeTree = needNodeTree or hasDisplacement or VRayData.override

    if not VRayObject.ntree and needNodeTree:
        nt = _createVRayTree(ob.name, 'Object')

        outputNode = _createVRayNode(nt, 'ObjectOutput')

        # MATERIAL
        #
        blenderMaterial = _createVRayNode(nt, 'BlenderOutputMaterial')

        for ovrName in ObjectMaterialOverrides:
            ovrPropGroup = getattr(VRayObject, ovrName)
            ovrUse = getattr(ovrPropGroup, 'use')

            # NOTE: MtlWrapper and MtlOverride could be left on node
            # as is
            if not ovrUse:
                continue
            pass

        _connectNodes(nt,
            blenderMaterial, 'Material',
            outputNode,      'Material'
        )

        # GEOMETRY
        #

        # Infinite plane or VRayProxy
        if VRayData.override:
            debug.PrintInfo("  Found geometry override '%s'" % VRayData.override_type)

            if VRayData.override_type == 'VRAYPLANE':
                blenderGeometry = _createVRayNode(nt, 'GeomPlane')
            else:
                blenderGeometry = _createVRayNode(nt, 'GeomMeshFile')
                blenderGeometry.GeomMeshFile.file = VRayData.GeomMeshFile.file

        # Displacemnt and / or subdivision
        else:
            blenderGeometry = _createVRayNode(nt, 'BlenderOutputGeometry')

            if hasDisplacement:
                displaceNodeType = 'GeomDisplacedMesh'
                if VRayObject.GeomStaticSmoothedMesh.use:
                    displaceNodeType = 'GeomStaticSmoothedMesh'

                dispTex    = hasDisplacement
                dispAmount = _getDisplacementAmount(ob)

                displaceNode = _createVRayNode(nt, displaceNodeType)

                displacePropGroup = getattr(displaceNode, displaceNodeType)
                setattr(displacePropGroup, 'displacement_amount', dispAmount)

                dispTexNode = dispTex.createNode(nt)

                # Connect textures
                _connectNodes(nt,
                    dispTexNode,  'Color',
                    displaceNode, 'Color'
                )
                _connectNodes(nt,
                    dispTexNode,  'Out Intensity',
                    displaceNode, 'Float'
                )

                # Connect geometry
                _connectNodes(nt,
                    blenderGeometry,  'Geometry',
                    displaceNode,     'Mesh'
                )

                # Set displace as last geometry node
                blenderGeometry = displaceNode

            else:
                if VRayObject.GeomStaticSmoothedMesh.use:
                    pass

        if blenderGeometry:
            _connectNodes(nt,
                blenderGeometry, 'Geometry',
                outputNode,      'Geometry'
            )

        NodesTools.rearrangeTree(nt, outputNode)

        VRayObject.ntree = nt
コード例 #11
0
ファイル: convert.py プロジェクト: ISRAELAVLIS33/vb30
def ConvertMaterial(scene, ob, ma, textures):
    VRayMaterial = ma.vray
    VRayConverter = scene.vray.VRayConverter

    # This is the last node of the material
    # NOT the output, but the last Mtl node
    materialNode = None

    if VRayMaterial.ntree:
        outputNode = NodesUtils.GetNodeByType(VRayMaterial.ntree, 'VRayNodeOutputMaterial')
        materialNode = NodesUtils.GetConnectedNode(VRayMaterial.ntree, outputNode.inputs['Material'])

    else:
        if ma.node_tree:
            if VRayConverter.convert_from == 'CYCLES':
                return ConvertNodeMaterial(scene, ob, ma)
            return None

        debug.PrintInfo("Converting material: %s" % ma.name)

        nt = _createVRayTree(ma.name, 'Material')

        outputNode = _createVRayNode(nt, 'OutputMaterial')

        materialTop = _createVRayNode(nt, 'MtlSingleBRDF')
        brdfTo      = materialTop
        mainBRDF    = None

        if VRayMaterial.round_edges:
            mtlRoundEdges = _createVRayNode(nt, 'MtlRoundEdges')
            mtlRoundEdges.inputs['Radius'].value = VRayMaterial.radius

            _connectNodes(nt,
                materialTop,   'Material',
                mtlRoundEdges, 'Base Mtl')

            materialTop = mtlRoundEdges

        if VRayMaterial.material_id_number:
            mtlMaterialID = _createVRayNode(nt, 'MtlMaterialID')
            mtlMaterialID.MtlMaterialID.material_id_number  = VRayMaterial.material_id_number
            mtlMaterialID.inputs['Material Id Color'].value = VRayMaterial.material_id_color

            _connectNodes(nt,
                materialTop,   'Material',
                mtlMaterialID, 'Base Mtl')

            materialTop = mtlMaterialID

        if VRayMaterial.Mtl2Sided.use:
            mtl2Sided = _createVRayNode(nt, 'Mtl2Sided')
            mtl2Sided.Mtl2Sided.force_1sided = VRayMaterial.Mtl2Sided.force_1sided
            mtl2Sided.inputs['Translucency'].value = [VRayMaterial.Mtl2Sided.translucency_slider]*3

            backMat = None
            if VRayMaterial.Mtl2Sided.back:
                backMaName = VRayMaterial.Mtl2Sided.back
                if backMaName in bpy.data.materials:
                    backMa  = bpy.data.materials[backMaName]
                    backTex = ProcessTextures(backMa)

                    ConvertMaterial(scene, ob, backMa, backTex)

                    backMat = _createGroupMaterial(nt, backMa)

            _connectNodes(nt,
                materialTop, 'Material',
                mtl2Sided,   'Front')

            if backMat:
                _connectNodes(nt,
                    backMat,   'Material',
                    mtl2Sided, 'Back')
            else:
                _connectNodes(nt,
                    materialTop, 'Material',
                    mtl2Sided,   'Back')

            materialTop = mtl2Sided

        if VRayMaterial.MtlOverride.use:
            pass

        for ovrName in {'MtlWrapper', 'MtlRenderStats'}:
            ovrPropGroup = getattr(VRayMaterial, ovrName)
            ovrUse = getattr(ovrPropGroup, 'use')
            if not ovrUse:
                continue
            debug.PrintInfo("  Found override: %s" % ovrName)

            ovrNode = _createVRayNode(nt, ovrName)

            _connectNodes(nt,
                materialTop, 'Material',
                ovrNode,     OverrideInputSocket[ovrName])

            materialTop = ovrNode

        # Connect last material to the output
        materialNode = materialTop
        _connectNodes(nt,
            materialTop, 'Material',
            outputNode,  'Material')

        # BRDFs
        #
        if 'normal' in textures:
            norTex = _getTextureFromTextures(textures, 'normal')

            mainBRDF = _createVRayNode(nt, 'BRDFBump')
            mainBRDF.inputs['Bump Amount Texture'].value = _getBumpAmount(ma)

            bumpTexNode = norTex.createNode(nt)

            _connectNodes(nt,
                bumpTexNode, 'Color',
                mainBRDF,    'Color Texture'
            )
            _connectNodes(nt,
                bumpTexNode, 'Out Intensity',
                mainBRDF,    'Float Texture'
            )

        # Finally generate main BRDF node and connect top brdf
        # if needed
        brdfType = VRayMaterial.type

        baseBRDF = _createVRayNode(nt, brdfType)

        oldPropGroup = getattr(VRayMaterial, brdfType)

        TransferProperties(baseBRDF, brdfType, oldPropGroup)

        # Manual tweaks
        if brdfType == 'BRDFVRayMtl':
            baseBRDF.inputs['Fog Color'].value = VRayMaterial.BRDFVRayMtl.fog_color

        CreateTextureNodes(nt, baseBRDF, textures)

        if brdfType == 'BRDFVRayMtl':
            if 'reflect' not in textures:
                baseBRDF.inputs['Reflect'].value = oldPropGroup.reflect_color
            if 'refract' not in textures:
                baseBRDF.inputs['Refract'].value = oldPropGroup.refract_color
            baseBRDF.inputs['Fog Color'].value = oldPropGroup.fog_color

        if not mainBRDF:
            mainBRDF = baseBRDF
        else:
            _connectNodes(nt,
                baseBRDF, 'BRDF',
                mainBRDF, 'Base Brdf')

        # Connect last BRDF to the last material
        _connectNodes(nt,
            mainBRDF, 'BRDF',
            brdfTo,   'BRDF')

        NodesTools.rearrangeTree(nt, outputNode)
        NodesTools.deselectNodes(nt)

        VRayMaterial.ntree = nt

    return materialNode
コード例 #12
0
ファイル: import_file.py プロジェクト: JuhaW/vb30
def ImportMaterialWithDisplacement(context, filePath, use_fake_user=True):
    debug.PrintInfo('Importing materials from "%s"' % filePath)

    vrsceneDict = {}

    if filePath.endswith(".vrscene"):
        vrsceneDict = ParseVrscene(filePath)
    else:
        vrsceneDict = ParseVrmat(filePath)

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

        if pluginID == 'Node':
            nodeNames.append(pluginName)

    for nodeName in nodeNames:
        debug.PrintInfo("Importing material from Node: %s" % nodeName)

        nodePluginDesc = NodesImport.getPluginByName(vrsceneDict, nodeName)

        # Import material
        #
        maName = nodePluginDesc['Attributes']['material']
        if maName in bpy.data.node_groups:
            continue

        maPluginDesc = NodesImport.getPluginByName(vrsceneDict, maName)
        if not maPluginDesc:
            continue

        maNtree = bpy.data.node_groups.new(maName, type='VRayNodeTreeMaterial')
        maNtree.use_fake_user = True

        maOutputNode = maNtree.nodes.new('VRayNodeOutputMaterial')

        maNode = NodesImport.createNode(maNtree, maOutputNode, vrsceneDict, maPluginDesc)

        maNtree.links.new(
            maNode.outputs['Material'],
            maOutputNode.inputs['Material']
        )

        NodesTools.rearrangeTree(maNtree, maOutputNode)

        # Check geometry for displacement
        #
        geomName = nodePluginDesc['Attributes']['geometry']

        geomPluginDesc = NodesImport.getPluginByName(vrsceneDict, geomName)

        if geomPluginDesc and geomPluginDesc['ID'] == 'GeomDisplacedMesh':
            colorTexName = geomPluginDesc['Attributes'].get("displacement_tex_color")
            floatTexName = geomPluginDesc['Attributes'].get("displacement_tex_float")

            if colorTexName or floatTexName:
                # Create node tree with displace name
                dispNtree = bpy.data.node_groups.new(geomPluginDesc['Name'], type='VRayNodeTreeMaterial')
                dispNtree.use_fake_user = True

                # Add group output to displace tree
                dispGroupOutput = dispNtree.nodes.new('NodeGroupOutput')

                # Import texture nodes
                colorTexNode = NodesImport.FindAndCreateNode(vrsceneDict, colorTexName, dispNtree, dispGroupOutput)
                floatTexNode = NodesImport.FindAndCreateNode(vrsceneDict, floatTexName, dispNtree, dispGroupOutput)

                # Add/connect output sockets
                if colorTexName:
                    dispNtree.outputs.new('VRaySocketColor', 'Color')
                    dispNtree.links.new(
                        colorTexNode.outputs['Output'],
                        dispGroupOutput.inputs['Color']
                    )
                if floatTexName:
                    dispNtree.outputs.new('VRaySocketFloat', 'Float')
                    dispNtree.links.new(
                        floatTexNode.outputs['Output'],
                        dispGroupOutput.inputs['Float']
                    )

                NodesTools.rearrangeTree(dispNtree, dispGroupOutput)
                NodesTools.deselectNodes(dispNtree)

                # Create a group node in current material tree
                # to show user that we have displacement
                dispGroupNode = maNtree.nodes.new('ShaderNodeGroup')
                dispGroupNode.node_tree = dispNtree
                dispGroupNode.location.x = 0
                dispGroupNode.location.y = 100

        # Finally create a material
        CreateMaterial(maName, maNtree, use_fake_user)
        NodesTools.deselectNodes(maNtree)

    return {'FINISHED'}
コード例 #13
0
ファイル: import_file.py プロジェクト: JuhaW/vb30
def ImportMaterials(context, filePath, baseMaterial, use_fake_user=True):
    debug.PrintInfo('Importing materials from "%s"' % filePath)

    vrsceneDict = {}

    if filePath.endswith(".vrscene"):
        vrsceneDict = ParseVrscene(filePath)
    else:
        vrsceneDict = ParseVrmat(filePath)

    MaterialTypeFilter = {
        'STANDARD' : {
            'MtlSingleBRDF',
            'MtlVRmat',
            'MtlDoubleSided',
            'MtlGLSL',
            'MtlLayeredBRDF',
            'MtlDiffuse',
            'MtlBump',
            'Mtl2Sided',
        },
        'MULTI' : {
            'MtlMulti'
        },
        'WRAPPED' : {
            'MtlWrapper',
            'MtlWrapperMaya',
            'MayaMtlMatte',
            'MtlMaterialID',
            'MtlMayaRamp',
            'MtlObjBBox',
            'MtlOverride',
            'MtlRenderStats',
            'MtlRoundEdges',
            'MtlStreakFade',
        },
    }

    # Collect material names based on selected
    # base material type
    #
    materialNames = []
    for pluginDesc in vrsceneDict:
        pluginID    = pluginDesc['ID']
        pluginName  = pluginDesc['Name']

        if pluginID in MaterialTypeFilter[baseMaterial]:
            materialNames.append(pluginName)

    for maName in materialNames:
        debug.PrintInfo("Importing material: %s" % maName)

        pluginDesc = NodesImport.getPluginByName(vrsceneDict, maName)

        ntree = bpy.data.node_groups.new(maName, type='VRayNodeTreeMaterial')
        ntree.use_fake_user = True

        outputNode = ntree.nodes.new('VRayNodeOutputMaterial')

        maNode = NodesImport.createNode(ntree, outputNode, vrsceneDict, pluginDesc)

        ntree.links.new(maNode.outputs['Material'], outputNode.inputs['Material'])

        NodesTools.rearrangeTree(ntree, outputNode)
        NodesTools.deselectNodes(ntree)

        # Finally create a material
        CreateMaterial(maName, ntree, use_fake_user)

    return {'FINISHED'}
コード例 #14
0
def ConvertObject(scene, ob):
    debug.PrintInfo("Converting object: %s" % ob.name)

    VRayConverter = scene.vray.VRayConverter

    VRayObject = ob.vray
    VRayData = ob.data.vray

    needNodeTree = False
    hasDisplacement = None

    for ms in ob.material_slots:
        if not (ms and ms.material):
            continue

        ma = ms.material

        textures = ProcessTextures(ma)

        if VRayConverter.convert_materials:
            ConvertMaterial(scene, ob, ma, textures)

        if 'displacement' in textures:
            debug.PrintInfo("  Found displacement")
            hasDisplacement = textures['displacement']

    if not VRayConverter.convert_objects:
        return

    # Check if we need node tree from override materials
    for ovrName in ObjectMaterialOverrides:
        ovrPropGroup = getattr(VRayObject, ovrName)
        ovrUse = getattr(ovrPropGroup, 'use')
        if ovrUse:
            debug.PrintInfo("  Found override: %s" % ovrName)
            needNodeTree = True
            break

    needNodeTree = needNodeTree or hasDisplacement or VRayData.override

    if not VRayObject.ntree and needNodeTree:
        nt = _createVRayTree(ob.name, 'Object')

        outputNode = _createVRayNode(nt, 'ObjectOutput')

        # MATERIAL
        #
        blenderMaterial = _createVRayNode(nt, 'BlenderOutputMaterial')

        for ovrName in ObjectMaterialOverrides:
            ovrPropGroup = getattr(VRayObject, ovrName)
            ovrUse = getattr(ovrPropGroup, 'use')

            # NOTE: MtlWrapper and MtlOverride could be left on node
            # as is
            if not ovrUse:
                continue
            pass

        _connectNodes(nt, blenderMaterial, 'Material', outputNode, 'Material')

        # GEOMETRY
        #

        # Infinite plane or VRayProxy
        if VRayData.override:
            debug.PrintInfo("  Found geometry override '%s'" %
                            VRayData.override_type)

            if VRayData.override_type == 'VRAYPLANE':
                blenderGeometry = _createVRayNode(nt, 'GeomPlane')
            else:
                blenderGeometry = _createVRayNode(nt, 'GeomMeshFile')
                blenderGeometry.GeomMeshFile.file = VRayData.GeomMeshFile.file

        # Displacemnt and / or subdivision
        else:
            blenderGeometry = _createVRayNode(nt, 'BlenderOutputGeometry')

            if hasDisplacement:
                displaceNodeType = 'GeomDisplacedMesh'
                if VRayObject.GeomStaticSmoothedMesh.use:
                    displaceNodeType = 'GeomStaticSmoothedMesh'

                dispTex = hasDisplacement
                dispAmount = _getDisplacementAmount(ob)

                displaceNode = _createVRayNode(nt, displaceNodeType)

                displacePropGroup = getattr(displaceNode, displaceNodeType)
                setattr(displacePropGroup, 'displacement_amount', dispAmount)

                dispTexNode = dispTex.createNode(nt)

                # Connect textures
                _connectNodes(nt, dispTexNode, 'Color', displaceNode, 'Color')
                _connectNodes(nt, dispTexNode, 'Out Intensity', displaceNode,
                              'Float')

                # Connect geometry
                _connectNodes(nt, blenderGeometry, 'Geometry', displaceNode,
                              'Mesh')

                # Set displace as last geometry node
                blenderGeometry = displaceNode

            else:
                if VRayObject.GeomStaticSmoothedMesh.use:
                    pass

        if blenderGeometry:
            _connectNodes(nt, blenderGeometry, 'Geometry', outputNode,
                          'Geometry')

        NodesTools.rearrangeTree(nt, outputNode)

        VRayObject.ntree = nt
コード例 #15
0
def ConvertMaterial(scene, ob, ma, textures):
    VRayMaterial = ma.vray
    VRayConverter = scene.vray.VRayConverter

    # This is the last node of the material
    # NOT the output, but the last Mtl node
    materialNode = None

    if VRayMaterial.ntree:
        outputNode = NodesUtils.GetNodeByType(VRayMaterial.ntree,
                                              'VRayNodeOutputMaterial')
        materialNode = NodesUtils.GetConnectedNode(
            VRayMaterial.ntree, outputNode.inputs['Material'])

    else:
        if ma.node_tree:
            if VRayConverter.convert_from == 'CYCLES':
                return ConvertNodeMaterial(scene, ob, ma)
            return None

        debug.PrintInfo("Converting material: %s" % ma.name)

        nt = _createVRayTree(ma.name, 'Material')

        outputNode = _createVRayNode(nt, 'OutputMaterial')

        materialTop = _createVRayNode(nt, 'MtlSingleBRDF')
        brdfTo = materialTop
        mainBRDF = None

        if VRayMaterial.round_edges:
            mtlRoundEdges = _createVRayNode(nt, 'MtlRoundEdges')
            mtlRoundEdges.inputs['Radius'].value = VRayMaterial.radius

            _connectNodes(nt, materialTop, 'Material', mtlRoundEdges,
                          'Base Mtl')

            materialTop = mtlRoundEdges

        if VRayMaterial.material_id_number:
            mtlMaterialID = _createVRayNode(nt, 'MtlMaterialID')
            mtlMaterialID.MtlMaterialID.material_id_number = VRayMaterial.material_id_number
            mtlMaterialID.inputs[
                'Material Id Color'].value = VRayMaterial.material_id_color

            _connectNodes(nt, materialTop, 'Material', mtlMaterialID,
                          'Base Mtl')

            materialTop = mtlMaterialID

        if VRayMaterial.Mtl2Sided.use:
            mtl2Sided = _createVRayNode(nt, 'Mtl2Sided')
            mtl2Sided.Mtl2Sided.force_1sided = VRayMaterial.Mtl2Sided.force_1sided
            mtl2Sided.inputs['Translucency'].value = [
                VRayMaterial.Mtl2Sided.translucency_slider
            ] * 3

            backMat = None
            if VRayMaterial.Mtl2Sided.back:
                backMaName = VRayMaterial.Mtl2Sided.back
                if backMaName in bpy.data.materials:
                    backMa = bpy.data.materials[backMaName]
                    backTex = ProcessTextures(backMa)

                    ConvertMaterial(scene, ob, backMa, backTex)

                    backMat = _createGroupMaterial(nt, backMa)

            _connectNodes(nt, materialTop, 'Material', mtl2Sided, 'Front')

            if backMat:
                _connectNodes(nt, backMat, 'Material', mtl2Sided, 'Back')
            else:
                _connectNodes(nt, materialTop, 'Material', mtl2Sided, 'Back')

            materialTop = mtl2Sided

        if VRayMaterial.MtlOverride.use:
            pass

        for ovrName in {'MtlWrapper', 'MtlRenderStats'}:
            ovrPropGroup = getattr(VRayMaterial, ovrName)
            ovrUse = getattr(ovrPropGroup, 'use')
            if not ovrUse:
                continue
            debug.PrintInfo("  Found override: %s" % ovrName)

            ovrNode = _createVRayNode(nt, ovrName)

            _connectNodes(nt, materialTop, 'Material', ovrNode,
                          OverrideInputSocket[ovrName])

            materialTop = ovrNode

        # Connect last material to the output
        materialNode = materialTop
        _connectNodes(nt, materialTop, 'Material', outputNode, 'Material')

        # BRDFs
        #
        if 'normal' in textures:
            norTex = _getTextureFromTextures(textures, 'normal')

            mainBRDF = _createVRayNode(nt, 'BRDFBump')
            mainBRDF.inputs['Bump Amount Texture'].value = _getBumpAmount(ma)

            bumpTexNode = norTex.createNode(nt)

            _connectNodes(nt, bumpTexNode, 'Color', mainBRDF, 'Color Texture')
            _connectNodes(nt, bumpTexNode, 'Out Intensity', mainBRDF,
                          'Float Texture')

        # Finally generate main BRDF node and connect top brdf
        # if needed
        brdfType = VRayMaterial.type

        baseBRDF = _createVRayNode(nt, brdfType)

        oldPropGroup = getattr(VRayMaterial, brdfType)

        TransferProperties(baseBRDF, brdfType, oldPropGroup)

        CreateTextureNodes(nt, baseBRDF, textures)

        # Manual tweaks
        if brdfType == 'BRDFVRayMtl':
            if 'reflect' not in textures:
                baseBRDF.inputs['Reflect'].value = oldPropGroup.reflect_color
            if 'refract' not in textures:
                baseBRDF.inputs['Refract'].value = oldPropGroup.refract_color
            baseBRDF.inputs['Fog Color Tex'].value = oldPropGroup.fog_color

        if not mainBRDF:
            mainBRDF = baseBRDF
        else:
            _connectNodes(nt, baseBRDF, 'BRDF', mainBRDF, 'Base Brdf')

        # Connect last BRDF to the last material
        _connectNodes(nt, mainBRDF, 'BRDF', brdfTo, 'BRDF')

        NodesTools.rearrangeTree(nt, outputNode)
        NodesTools.deselectNodes(nt)

        VRayMaterial.ntree = nt

    return materialNode