From 7d17f45ea7795312c1c0f0545bc17c4f25bb14e2 Mon Sep 17 00:00:00 2001 From: s473621 Date: Mon, 4 Mar 2024 23:13:45 +0100 Subject: [PATCH] skript --- skript_bl | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 skript_bl diff --git a/skript_bl b/skript_bl new file mode 100644 index 0000000..7e78fdf --- /dev/null +++ b/skript_bl @@ -0,0 +1,87 @@ +import bpy + +from math import radians + +import os +from bpy_extras.io_utils import ExportHelper + +context = bpy.context +scene = context.scene +vl = context.view_layer + +bpy.ops.wm.ply_import(filepath="C:/Users/") + +bpy.ops.object.select_all(action='DESELECT') + +texture_path = "C:/Users/neryt/Grafika2023/PlanetCreator/" +texture = bpy.data.images.load(texture_path) + + +material = bpy.data.materials.new(name="TextureMaterial") +material.use_nodes = True +nodes = material.node_tree.nodes +links = material.node_tree.links + + +for node in nodes: + if node.type == 'BSDF_PRINCIPLED': + nodes.remove(node) + + +shader_node = nodes.new(type='ShaderNodeTexImage') +shader_node.image = texture + + +output_node = nodes.get('Material Output') +links.new(shader_node.outputs['Color'], output_node.inputs['Surface']) + + +for obj in scene.objects: + if (obj.type == 'MESH'): + vl.objects.active = obj + obj.select_set(True) + print(obj.name) + lm = obj.data.uv_layers.get("LightMap") + if not lm: + lm = obj.data.uv_layers.new(name="LightMap") + lm.active = True + bpy.ops.object.editmode_toggle() + bpy.ops.mesh.select_all(action='SELECT') # for all faces + bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.02) + bpy.ops.object.editmode_toggle() + if obj.type == 'MESH': + obj.data.materials.append(material) + + obj.select_set(False) + + + +for obj in bpy.context.selected_objects: + if obj.type == 'MESH': + obj.data.materials.append(material) + + +output_folder = "C:\\Users\\" + +os.makedirs(output_folder, exist_ok=True) + + +for idx, obj in enumerate(bpy.data.objects): + if obj.type == "MESH": + + bpy.context.view_layer.objects.active = obj + obj.select_set(True) + + + obj_name = f"roslina{idx + 1}" + file_path = os.path.join(output_folder, f"{obj_name}.obj") + bpy.ops.wm.obj_export(filepath=file_path, + check_existing=False, + export_selected_objects=True, + apply_modifiers=True, + export_smooth_groups=False, + smooth_group_bitflags=False, + export_normals=True, + export_uv=True) + + obj.select_set(False)