# Script by Fredrik Lindgren - 2023 # studiosapiens.net import bpy for mat in bpy.data.materials: if not mat.use_nodes: continue nodes = mat.node_tree.nodes mix = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeMixShader)), None) while mix is not None: nodes.remove(mix) mix = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeMixShader)), None) emission = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeEmission)), None) while emission is not None: nodes.remove(emission) emission = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeEmission)), None) transparent = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeBsdfTransparent)), None) while transparent is not None: nodes.remove(transparent) transparent = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeBsdfTransparent)), None) light_path = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeLightPath)), None) while light_path is not None: nodes.remove(light_path) light_path = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeLightPath)), None) output = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeOutputMaterial)), None) if output is None: continue principled = nodes.new("ShaderNodeBsdfPrincipled") principled.location = (output.location[0] - 400, output.location[1]+100) mat.node_tree.links.new(principled.outputs[0], output.inputs[0]) texture = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeTexImage)), None) if texture is None: continue mat.node_tree.links.new(texture.outputs['Color'], principled.inputs['Base Color']) # Adds a value node and connects it to Specular with a value of 0.5. Doesn't transfer to Unreal. Thinking about how to set up and transfer other parameters than images. One way is offcourse to import all materials as instaces in unrel so I can have one Main Material in Unreal to set parameters for all instances of the Unreal Material. valueA = nodes.new("ShaderNodeValue") valueA.location = (principled.location[0] - 200, principled.location[1]-200) valueA.outputs[0].default_value = 0.5 mat.node_tree.links.new(valueA.outputs[0], principled.inputs['Metallic']) # Adds a value node and connects it to Roughness with a value of 0.5. Same problem as with Specular above. valueB = nodes.new("ShaderNodeValue") valueB.location = (principled.location[0] - 200, principled.location[1]-300) valueB.outputs[0].default_value = 0.5 mat.node_tree.links.new(valueB.outputs[0], principled.inputs['Roughness']) # Rename the material mat.name = 'A_' + mat.name # Rename the the image image_node = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeTexImage)), None) if image_node is not None: image_node.image.name = 'A_' + image_node.image.name Python script that changes all materials used in the google 3D Tile map to export properly with textures via fbx to be able to import the map in other software as Unreal engine, or others... By Fredrik Lindgren studiosapiens.net Here’s a brief overview of what the script does: The script loops through all the materials in the Blender file. For each material, it checks if it uses nodes. If not, it skips to the next material. If the material uses nodes, it removes Mix Shader Nodes, Emission Nodes, Transparent BSDF Nodes, and Light Path Nodes from the node tree. It then adds a Principled BSDF Node to the node tree and links it to the output node. It links the texture node to the Principled BSDF Node. It renames the material by adding the letter ‘A_’ to the beginning of its current name. It renames the active image in the image texture node so it starts with ‘A_’. import bpy for mat in bpy.data.materials: if not mat.use_nodes: continue nodes = mat.node_tree.nodes mix = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeMixShader)), None) while mix is not None: nodes.remove(mix) mix = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeMixShader)), None) emission = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeEmission)), None) while emission is not None: nodes.remove(emission) emission = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeEmission)), None) transparent = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeBsdfTransparent)), None) while transparent is not None: nodes.remove(transparent) transparent = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeBsdfTransparent)), None) light_path = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeLightPath)), None) while light_path is not None: nodes.remove(light_path) light_path = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeLightPath)), None) output = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeOutputMaterial)), None) if output is None: continue principled = nodes.new("ShaderNodeBsdfPrincipled") principled.location = (output.location[0] - 400, output.location[1]+100) mat.node_tree.links.new(principled.outputs[0], output.inputs[0]) texture = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeTexImage)), None) if texture is None: continue mat.node_tree.links.new(texture.outputs['Color'], principled.inputs['Base Color']) # Rename the material mat.name = "B_" + mat.name # Rename the image image_node = next((n for n in nodes if isinstance(n, bpy.types.ShaderNodeTexImage)), None) if image_node is not None: image_node.image.name = "B_" + image_node.image.name