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'}
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'}
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"}
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'}
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'}
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'}
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'}
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'}