diff --git a/XModdingtools-015/XModdingtools-015.py b/XModdingtools-015/XModdingtools-015.py new file mode 100644 index 0000000..66930d8 --- /dev/null +++ b/XModdingtools-015/XModdingtools-015.py @@ -0,0 +1,333 @@ +bl_info = { + "name": "XModdingtools", + "author": "haunetal1990", + "version": (0, 1, 5), + "blender": (2, 80, 0), + "location": "View3D > UI > XModdingtools", + "description": "Add some modding tools", + "doc_url": "#", + "category": "3D View", +} +import bpy +import os + +def set_object_name(obj, new_name): + obj.name = new_name + +def transfer_object_name(obj): + obj.data.name = obj.name + +class View3DPanel: + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = "XModdingtools" + + @classmethod + def poll(cls, context): + return (context.object is not None) + +# Panel rename mesh(s) -------------------------------------------------------------------------------- +class RenameMesh(View3DPanel, bpy.types.Panel): + bl_idname = "VIEW3D_PT_Rename" + bl_label = "Rename Mesh(s)" + + def draw(self, context): + layout = self.layout + obj = context.object + row = layout.row() + + wm = bpy.data.window_managers["WinMan"] + row.prop(wm, "object_name", text="Name") + + row = layout.row() + row.operator("object.transfer_name_operator", text="Rename Mesh(s)") + + row = layout.row() + row.operator("object.rename_selected_objects", text="Rename Mesh Data Only") + +class TransferObjectNameOperator(bpy.types.Operator): + bl_idname = "object.transfer_name_operator" + bl_label = "rename mesh(s)" + + def execute(self, context): + selected_objs = context.selected_objects + obj_name = bpy.data.window_managers["WinMan"].object_name + + for i, obj in enumerate(selected_objs): + set_object_name(obj, f"{obj_name}_{str(i+1).zfill(2)}") + transfer_object_name(obj) + + return {'FINISHED'} + +class RenameSelectedObjectsOperator(bpy.types.Operator): + bl_idname = "object.rename_selected_objects" + bl_label = "rename mesh data only" + + def execute(self, context): + for obj in context.selected_objects: + transfer_object_name(obj) + return {'FINISHED'} + +classes = ( + TransferObjectNameOperator, + RenameSelectedObjectsOperator +) +# Panel texture checker -------------------------------------------------------------------------------- +class Texturechecker(View3DPanel, bpy.types.Panel): + bl_idname = "VIEW3D_PT_Texturechecker" + bl_label = "Texture Checker" + + def draw(self, context): + objects = bpy.context.selected_objects + + textures_missing = [] + for obj in objects: + if obj.type == 'MESH': + if obj.material_slots: + for mat_slot in obj.material_slots: + mat = mat_slot.material + if mat is not None: + if mat.use_nodes: + nodes = mat.node_tree.nodes + for node in nodes: + if node.type == 'BSDF_PRINCIPLED' and node.inputs["Base Color"].is_linked: + linked_node = node.inputs["Base Color"].links[0].from_node + if linked_node.type == 'TEX_IMAGE': + image = linked_node.image + if image is not None: + if image.name not in bpy.data.images: + if obj.name not in textures_missing: + textures_missing.append(obj.name) + break + if node.type == 'TEX_IMAGE': + image = node.image + if image is not None: + if image.name not in bpy.data.images: + if obj.name not in textures_missing: + textures_missing.append(obj.name) + break + elif node.type == 'BSDF_PRINCIPLED': + if not node.inputs["Base Color"].is_linked: + if obj.name not in textures_missing: + textures_missing.append(obj.name) + else: + if obj.name not in textures_missing: + textures_missing.append(obj.name) + + if textures_missing: + self.layout.label(text="Missing Textures:") + box = self.layout.box() + for missing_texture in textures_missing: + obj = bpy.data.objects[missing_texture] + if obj.material_slots: + for mat_slot in obj.material_slots: + mat = mat_slot.material + if mat is not None: + has_missing_texture = False + if mat.use_nodes: + nodes = mat.node_tree.nodes + for node in nodes: + if node.type == 'BSDF_PRINCIPLED' and node.inputs["Base Color"].is_linked: + linked_node = node.inputs["Base Color"].links[0].from_node + if linked_node.type == 'TEX_IMAGE': + image = linked_node.image + if image is not None: + if image.name not in bpy.data.images: + has_missing_texture = True + if node.type == 'TEX_IMAGE': + image = node.image + if image is not None: + if image.name not in bpy.data.images: + has_missing_texture = True + elif node.type == 'BSDF_PRINCIPLED': + if not node.inputs["Base Color"].is_linked: + has_missing_texture = True + if has_missing_texture: + row = box.row() + row.label(text=missing_texture) + row.label(icon='MATERIAL') + row.label(text=mat.name) + else: + row = box.row() + row.label(text=missing_texture) + row.label(icon='MATERIAL') + row.label(text="No Material") + else: + self.layout.label(text="All objects have textures.") + +# Panel track object(s) -------------------------------------------------------------------------------- +class AddMesh(View3DPanel, bpy.types.Panel): + bl_idname = "VIEW3D_PT_Mesh" + bl_label = "Track Object(s)" + + def draw(self, context): + row = self.layout.row() + row.label(text="Array Number:") + row.prop(context.scene, "array_num", text="") + row = self.layout.row() + row.label(text="Origin Type:") + self.layout.prop(context.scene, "origin_type") + + + self.layout.operator("mesh.add_mesh_1", text="Add Tirewall") + self.layout.operator("mesh.add_mesh_2", text="Add Cone") + +#tirewall +class AddMeshOperator1(bpy.types.Operator): + bl_idname = "mesh.add_mesh_1" + bl_label = "Add Tirewall" + origin_type: bpy.props.EnumProperty(items=[("View", "View", "Set origin to view location"), ("Cursor", "3D Cursor", "Set origin to 3D Cursor location")], name="Origin Type") + + def execute(self, context): + + for obj in bpy.data.objects: + obj.select_set(False) + + scene = context.scene + verts = [(0.0, 0.3100000023841858, 0.0), (0.0, 0.18000000715255737, 1.0499999523162842), (0.2199999988079071, 0.2199999988079071, 0.0), (0.12999999523162842, 0.12999999523162842, 1.0499999523162842), (0.3100000023841858, 0.0, 0.0), (0.18000000715255737, 0.0, 1.0499999523162842), (0.2199999988079071, -0.2199999988079071, 0.0), (0.12999999523162842, -0.12999999523162842, 1.0499999523162842), (4.529709940470639e-14, -0.3100000023841858, 0.0), (4.618527782440651e-14, -0.18000000715255737, 1.0499999523162842), (-0.2199999988079071, -0.2199999988079071, 0.0), (-0.12999999523162842, -0.12999999523162842, 1.0499999523162842), (-0.3100000023841858, 0.0, 0.0), (-0.18000000715255737, 0.0, 1.0499999523162842), (-0.2199999988079071, 0.2199999988079071, 0.0), (-0.12999999523162842, 0.12999999523162842, 1.0499999523162842), (0.2199999988079071, 0.2199999988079071, 1.0599998235702515), (0.0, 0.3100000023841858, 1.0599998235702515), (0.3100000023841858, 0.0, 1.0599998235702515), (0.2199999988079071, -0.2199999988079071, 1.0599998235702515), (4.5474745930668137e-14, -0.3100000023841858, 1.0599998235702515), (-0.2199999988079071, -0.2199999988079071, 1.0599998235702515), (-0.3100000023841858, 0.0, 1.0599998235702515), (-0.2199999988079071, 0.2199999988079071, 1.0599998235702515), (0.1899999976158142, 0.1899999976158142, 1.090000033378601), (0.0, 0.27000001072883606, 1.090000033378601), (0.27000001072883606, 0.0, 1.090000033378601), (0.1899999976158142, -0.1899999976158142, 1.090000033378601), (-1.8185453143360064e-13, -0.27000001072883606, 1.090000033378601), (-0.1899999976158142, -0.1899999976158142, 1.090000033378601), (-0.27000001072883606, 0.0, 1.090000033378601), (-0.1899999976158142, 0.1899999976158142, 1.090000033378601), (0.0, 0.23000000417232513, 1.0800000429153442), (0.1599999964237213, 0.1599999964237213, 1.0800000429153442), (0.23000000417232513, 0.0, 1.0800000429153442), (0.1599999964237213, -0.1599999964237213, 1.0800000429153442), (4.529709940470639e-14, -0.23000000417232513, 1.0800000429153442), (-0.1599999964237213, -0.1599999964237213, 1.0800000429153442), (-0.23000000417232513, 0.0, 1.0800000429153442), (-0.1599999964237213, 0.1599999964237213, 1.0800000429153442)] + faces = [(0, 17, 16, 2), (2, 16, 18, 4), (4, 18, 19, 6), (6, 19, 20, 8), (8, 20, 21, 10), (10, 21, 22, 12), (12, 22, 23, 14), (14, 23, 17, 0), (25, 24, 16, 17), (24, 26, 18, 16), (26, 27, 19, 18), (27, 28, 20, 19), (28, 29, 21, 20), (29, 30, 22, 21), (30, 31, 23, 22), (31, 25, 17, 23), (32, 33, 24, 25), (33, 34, 26, 24), (34, 35, 27, 26), (35, 36, 28, 27), (36, 37, 29, 28), (37, 38, 30, 29), (38, 39, 31, 30), (39, 32, 25, 31), (15, 1, 32, 39), (13, 15, 39, 38), (11, 13, 38, 37), (9, 11, 37, 36), (7, 9, 36, 35), (5, 7, 35, 34), (3, 5, 34, 33), (1, 3, 33, 32)] + uv_coords = [(0.9998231530189514, 0.00012504123151302338), (0.9998231530189514, 0.3175739347934723), (0.8748231530189514, 0.3175739347934723), (0.8748231530189514, 0.00012504123151302338), (0.8748231530189514, 0.00012504123151302338), (0.8748231530189514, 0.3175739347934723), (0.7498231530189514, 0.3175739347934723), (0.7498231530189514, 0.00012504123151302338), (0.7498231530189514, 0.00012504123151302338), (0.7498231530189514, 0.3175739347934723), (0.6248231530189514, 0.3175739347934723), (0.6248231530189514, 0.00012504123151302338), (0.6248231530189514, 0.00012504123151302338), (0.6248231530189514, 0.3175739347934723), (0.49982312321662903, 0.3175739347934723), (0.49982312321662903, 0.00012504123151302338), (0.49982312321662903, 0.00012504123151302338), (0.49982312321662903, 0.3175739347934723), (0.37482312321662903, 0.3175739347934723), (0.37482312321662903, 0.00012504123151302338), (0.37482312321662903, 0.00012504123151302338), (0.37482312321662903, 0.3175739347934723), (0.24982312321662903, 0.3175739347934723), (0.24982312321662903, 0.00012504123151302338), (0.24982312321662903, 0.00012504123151302338), (0.24982312321662903, 0.3175739347934723), (0.12482313066720963, 0.3175739347934723), (0.12482313066720963, 0.00012504123151302338), (0.12482313066720963, 0.00012504123151302338), (0.12482313066720963, 0.3175739347934723), (-0.000176871195435524, 0.3175739347934723), (-0.000176871195435524, 0.00012504123151302338), (0.7474998831748962, 0.9813597798347473), (0.9019638299942017, 0.9505533576011658), (0.9249303340911865, 0.9616115093231201), (0.7474998831748962, 0.9969983100891113), (0.9019638299942017, 0.9505533576011658), (0.9659450054168701, 0.8761800527572632), (0.9984245300292969, 0.8761800527572632), (0.9249303340911865, 0.9616115093231201), (0.9659450054168701, 0.8761800527572632), (0.9019638299942017, 0.8018068075180054), (0.9249303340911865, 0.7907484769821167), (0.9984245300292969, 0.8761800527572632), (0.9019638299942017, 0.8018068075180054), (0.7474998831748962, 0.7710002064704895), (0.7474998831748962, 0.7553616762161255), (0.9249303340911865, 0.7907484769821167), (0.7474998831748962, 0.7710002064704895), (0.5930357575416565, 0.8018068075180054), (0.5700693130493164, 0.7907484769821167), (0.7474998831748962, 0.7553616762161255), (0.5930357575416565, 0.8018068075180054), (0.5290547609329224, 0.8761800527572632), (0.4965752065181732, 0.8761800527572632), (0.5700693130493164, 0.7907484769821167), (0.5290547609329224, 0.8761800527572632), (0.5930357575416565, 0.9505533576011658), (0.5700693130493164, 0.9616115093231201), (0.4965752065181732, 0.8761800527572632), (0.5930357575416565, 0.9505533576011658), (0.7474998831748962, 0.9813597798347473), (0.7474998831748962, 0.9969983100891113), (0.5700693130493164, 0.9616115093231201), (0.7474998235702515, 0.9640305042266846), (0.8765144348144531, 0.9382996559143066), (0.9019638299942017, 0.9505533576011658), (0.7474998831748962, 0.9813597798347473), (0.8765144348144531, 0.9382996559143066), (0.9299541115760803, 0.8761800527572632), (0.9659450054168701, 0.8761800527572632), (0.9019638299942017, 0.9505533576011658), (0.9299541115760803, 0.8761800527572632), (0.8765144348144531, 0.814060389995575), (0.9019638299942017, 0.8018068075180054), (0.9659450054168701, 0.8761800527572632), (0.8765144348144531, 0.814060389995575), (0.7474998831748962, 0.788329541683197), (0.7474998831748962, 0.7710002064704895), (0.9019638299942017, 0.8018068075180054), (0.7474998831748962, 0.788329541683197), (0.6184850335121155, 0.814060389995575), (0.5930357575416565, 0.8018068075180054), (0.7474998831748962, 0.7710002064704895), (0.6184850335121155, 0.814060389995575), (0.5650454759597778, 0.8761800527572632), (0.5290547609329224, 0.8761800527572632), (0.5930357575416565, 0.8018068075180054), (0.5650454759597778, 0.8761800527572632), (0.6184850335121155, 0.9382996559143066), (0.5930357575416565, 0.9505533576011658), (0.5290547609329224, 0.8761800527572632), (0.6184850335121155, 0.9382996559143066), (0.7474998235702515, 0.9640305042266846), (0.7474998831748962, 0.9813597798347473), (0.5930357575416565, 0.9505533576011658), (0.6439344882965088, 0.9260458946228027), (0.7474998831748962, 0.946701169013977), (0.7474998235702515, 0.9640305042266846), (0.6184850335121155, 0.9382996559143066), (0.6010362505912781, 0.8761800527572632), (0.6439344882965088, 0.9260458946228027), (0.6184850335121155, 0.9382996559143066), (0.5650454759597778, 0.8761800527572632), (0.6439344882965088, 0.8263140916824341), (0.6010362505912781, 0.8761800527572632), (0.5650454759597778, 0.8761800527572632), (0.6184850335121155, 0.814060389995575), (0.7474998831748962, 0.8056588768959045), (0.6439344882965088, 0.8263140916824341), (0.6184850335121155, 0.814060389995575), (0.7474998831748962, 0.788329541683197), (0.8510652780532837, 0.8263140916824341), (0.7474998831748962, 0.8056588768959045), (0.7474998831748962, 0.788329541683197), (0.8765144348144531, 0.814060389995575), (0.8939633965492249, 0.8761800527572632), (0.8510652780532837, 0.8263140916824341), (0.8765144348144531, 0.814060389995575), (0.9299541115760803, 0.8761800527572632), (0.8510652780532837, 0.9260459542274475), (0.8939633965492249, 0.8761800527572632), (0.9299541115760803, 0.8761800527572632), (0.8765144348144531, 0.9382996559143066), (0.7474998831748962, 0.946701169013977), (0.8510652780532837, 0.9260459542274475), (0.8765144348144531, 0.9382996559143066), (0.7474998235702515, 0.9640305042266846)] + mesh = bpy.data.meshes.new("Mesh") + mesh.from_pydata(verts, [], faces) + mesh.uv_layers.new().data.foreach_set("uv", [uv for pair in uv_coords for uv in pair]) + obj_name = "Tirewall_00" + i = 0 + while obj_name in bpy.data.objects: + i += 1 + obj_name = f"Tirewall_{str(i).zfill(2)}" + obj = bpy.data.objects.new(obj_name, mesh) + mesh = transfer_object_name(obj) + scene.collection.objects.link(obj) + + # Set the origin to the current cursor position + set_origin_to_cursor(obj, context.scene.origin_type) + + if int(scene.array_num) > 1: + obj.modifiers.new("Array", type='ARRAY') + obj.modifiers["Array"].count = int(scene.array_num) + obj.data.polygons.foreach_set("use_smooth", [True] * len(obj.data.polygons)) + mat = bpy.data.materials.new(name="TWAL_STACKS") + mat.use_nodes = True + principled = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled') + mat.node_tree.links.new(principled.outputs[0], mat.node_tree.nodes['Material Output'].inputs[0]) + obj.data.materials.append(mat) + + # Select the active object + obj.select_set(state=True) + return {'FINISHED'} +#cone +class AddMeshOperator2(bpy.types.Operator): + bl_idname = "mesh.add_mesh_2" + bl_label = "Add Cone" + origin_type: bpy.props.EnumProperty(items=[("View", "View", "Set origin to view location"), ("Cursor", "3D Cursor", "Set origin to 3D Cursor location")], name="Origin Type") + + def execute(self, context): + + for obj in bpy.data.objects: + obj.select_set(False) + + scene = context.scene + verts = [(0.18982315063476562, 0.24969765543937683, 0.0), (0.11319868266582489, 0.13308238983154297, 0.03705911710858345), (0.2530466914176941, 0.18546941876411438, 0.0), (0.17594993114471436, 0.013836667872965336, 0.03705911710858345), (0.2530466914176941, -0.18781375885009766, 0.0), (0.13911063969135284, -0.1137293353676796, 0.03705911710858345), (0.18982315063476562, -0.24969767034053802, 0.0), (0.021677548065781593, -0.17594993114471436, 0.03705911710858345), (-0.1834600269794464, -0.24969767034053802, 0.0), (-0.10545281320810318, -0.14045025408267975, 0.03705911710858345), (-0.24768824875354767, -0.18781375885009766, 0.0), (-0.17126129567623138, -0.022246655076742172, 0.03705911710858345), (-0.24768824875354767, 0.18546941876411438, 0.0), (-0.13241256773471832, 0.10722310841083527, 0.03705911710858345), (-0.1834600269794464, 0.24969765543937683, 0.0), (-0.01612960733473301, 0.16992168128490448, 0.03705911710858345), (0.2530466914176941, 0.18546941876411438, 0.03705911710858345), (0.18982315063476562, 0.24969765543937683, 0.03705911710858345), (0.2530466914176941, -0.18781375885009766, 0.03705911710858345), (0.18982315063476562, -0.24969767034053802, 0.03705911710858345), (-0.1834600269794464, -0.24969767034053802, 0.03705911710858345), (-0.24768824875354767, -0.18781375885009766, 0.03705911710858345), (-0.24768824875354767, 0.18546941876411438, 0.03705911710858345), (-0.1834600269794464, 0.24969765543937683, 0.03705911710858345), (0.002258277265354991, -0.003913794178515673, 0.6927124261856079), (0.03811424598097801, -0.000318568927468732, 0.6927125453948975), (0.02510072849690914, 0.024410918354988098, 0.6927125453948975), (0.03047441504895687, -0.026773536577820778, 0.6927125453948975), (0.006120840087532997, -0.039677008986473083, 0.6927125453948975), (-0.02024378813803196, -0.03231498971581459, 0.6927125453948975), (-0.03389131650328636, -0.007801621686667204, 0.6927125453948975), (-0.025834763422608376, 0.019048156216740608, 0.6927125453948975), (-0.0017197055276483297, 0.03205075114965439, 0.6927125453948975)] + faces = [(0, 17, 16, 2), (2, 16, 18, 4), (4, 18, 19, 6), (6, 19, 20, 8), (8, 20, 21, 10), (10, 21, 22, 12), (7, 5, 27, 28), (12, 22, 23, 14), (14, 23, 17, 0), (0, 2, 4, 6, 8, 10, 12, 14), (1, 3, 16, 17), (3, 5, 18, 16), (5, 7, 19, 18), (7, 9, 20, 19), (9, 11, 21, 20), (11, 13, 22, 21), (13, 15, 23, 22), (15, 1, 17, 23), (3, 1, 26, 25), (1, 15, 32, 26), (13, 11, 30, 31), (9, 7, 28, 29), (5, 3, 25, 27), (15, 13, 31, 32), (11, 9, 29, 30), (24, 25, 26), (24, 27, 25), (24, 28, 27), (24, 29, 28), (24, 30, 29), (24, 31, 30), (24, 32, 31), (24, 26, 32)] + uv_coords = [(0.5003069043159485, 2.2351741790771484e-08), (0.5003068447113037, 0.03385297954082489), (0.4516381621360779, 0.03385297954082489), (0.4516381621360779, 2.2351741790771484e-08), (0.4516381621360779, 2.2351741790771484e-08), (0.4516381621360779, 0.03385297954082489), (0.2500595450401306, 0.033853039145469666), (0.25005966424942017, -3.725290298461914e-08), (0.25005966424942017, -3.725290298461914e-08), (0.2500595450401306, 0.033853039145469666), (0.2022848129272461, 0.03385297954082489), (0.20228475332260132, 2.2351741790771484e-08), (0.20228475332260132, 2.2351741790771484e-08), (0.2022848129272461, 0.03385297954082489), (0.0, 0.03385297954082489), (0.0, 2.2351741790771484e-08), (0.9842510223388672, 8.195638656616211e-08), (0.9842510223388672, 0.03385300934314728), (0.9236400127410889, 0.033853039145469666), (0.9236400127410889, 8.195638656616211e-08), (0.9236400127410889, 8.195638656616211e-08), (0.9236400127410889, 0.033853039145469666), (0.750935971736908, 0.03385297954082489), (0.750935971736908, 2.2351741790771484e-08), (0.5657868981361389, 0.07081586122512817), (0.6078783273696899, 0.07081586122512817), (0.6089836955070496, 0.856522262096405), (0.5671202540397644, 0.856522262096405), (0.750935971736908, 2.2351741790771484e-08), (0.750935971736908, 0.03385297954082489), (0.7018851637840271, 0.033853039145469666), (0.7018851637840271, 2.2351741790771484e-08), (0.7018851637840271, 2.2351741790771484e-08), (0.7018851637840271, 0.033853039145469666), (0.5003068447113037, 0.03385297954082489), (0.5003069043159485, 2.2351741790771484e-08), (0.4920065999031067, 0.42378926277160645), (0.43773341178894043, 0.47721362113952637), (0.12230871617794037, 0.4772133231163025), (0.07001680135726929, 0.42378926277160645), (0.07001693546772003, 0.10836496949195862), (0.12230885028839111, 0.05409204959869385), (0.43773341178894043, 0.05409204959869385), (0.4920065999031067, 0.10836496949195862), (0.12891720235347748, 0.6240667104721069), (0.07489333301782608, 0.7453943490982056), (0.0065416269935667515, 0.5667588710784912), (0.06792120635509491, 0.5044038891792297), (0.07489333301782608, 0.7453943490982056), (0.12306053936481476, 0.8719959855079651), (0.0065416269935667515, 0.9350606799125671), (0.0065416269935667515, 0.5667588710784912), (0.12306053936481476, 0.8719959855079651), (0.24415554106235504, 0.9243306517601013), (0.06792120635509491, 0.9951397776603699), (0.0065416269935667515, 0.9350606799125671), (0.24415554106235504, 0.9243306517601013), (0.371318519115448, 0.871164083480835), (0.43031731247901917, 0.9951397776603699), (0.06792120635509491, 0.9951397776603699), (0.371318519115448, 0.871164083480835), (0.4200493097305298, 0.7479429841041565), (0.49267229437828064, 0.935060977935791), (0.43031731247901917, 0.9951397776603699), (0.4200493097305298, 0.7479429841041565), (0.3703414797782898, 0.6275931596755981), (0.49267229437828064, 0.5667588710784912), (0.49267229437828064, 0.935060977935791), (0.3703414797782898, 0.6275931596755981), (0.2487689107656479, 0.5766444206237793), (0.43031731247901917, 0.5044038891792297), (0.49267229437828064, 0.5667588710784912), (0.2487689107656479, 0.5766444206237793), (0.12891720235347748, 0.6240667104721069), (0.06792120635509491, 0.5044038891792297), (0.43031731247901917, 0.5044038891792297), (0.6541111469268799, 0.07081586122512817), (0.7039234042167664, 0.07081586122512817), (0.7045067548751831, 0.856522262096405), (0.6549658179283142, 0.856522262096405), (0.7039234042167664, 0.07081586122512817), (0.755402147769928, 0.07081586122512817), (0.7557051777839661, 0.856522262096405), (0.7045067548751831, 0.856522262096405), (0.806364119052887, 0.07081586122512817), (0.8576191067695618, 0.07081586122512817), (0.8573682904243469, 0.856522262096405), (0.8063898682594299, 0.856522262096405), (0.9067041277885437, 0.07081586122512817), (0.9512556195259094, 0.07081586122512817), (0.9504984021186829, 0.856522262096405), (0.9061867594718933, 0.856522262096405), (0.6078783273696899, 0.07081586122512817), (0.6541111469268799, 0.07081586122512817), (0.6549658179283142, 0.856522262096405), (0.6089836955070496, 0.856522262096405), (0.755402147769928, 0.07081586122512817), (0.806364119052887, 0.07081586122512817), (0.8063898682594299, 0.856522262096405), (0.7557051777839661, 0.856522262096405), (0.8576191067695618, 0.07081586122512817), (0.9067041277885437, 0.07081586122512817), (0.9061867594718933, 0.856522262096405), (0.8573682904243469, 0.856522262096405), (0.7446589469909668, 0.911551833152771), (0.7619311809539795, 0.867983877658844), (0.7882263660430908, 0.893072247505188), (0.7446589469909668, 0.911551833152771), (0.7261190414428711, 0.8681141138076782), (0.7619311809539795, 0.867983877658844), (0.7446589469909668, 0.911551833152771), (0.7013023495674133, 0.8939784169197083), (0.7261190414428711, 0.8681141138076782), (0.7446589469909668, 0.911551833152771), (0.7011171579360962, 0.929578423500061), (0.7013023495674133, 0.8939782977104187), (0.7446589469909668, 0.911551833152771), (0.7269161343574524, 0.9553828835487366), (0.7011171579360962, 0.929578423500061), (0.7446589469909668, 0.911551833152771), (0.7633705735206604, 0.9548720717430115), (0.7269161343574524, 0.9553828835487366), (0.7446589469909668, 0.911551833152771), (0.7882263660430908, 0.9293414950370789), (0.7633705735206604, 0.9548720717430115), (0.7446589469909668, 0.911551833152771), (0.7882263660430908, 0.893072247505188), (0.7882263660430908, 0.9293414950370789)] + mesh = bpy.data.meshes.new("Mesh") + mesh.from_pydata(verts, [], faces) + mesh.uv_layers.new().data.foreach_set("uv", [uv for pair in uv_coords for uv in pair]) + obj_name = "Cone_00" + i = 0 + while obj_name in bpy.data.objects: + i += 1 + obj_name = f"Cone_{str(i).zfill(2)}" + obj = bpy.data.objects.new(obj_name, mesh) + mesh = transfer_object_name(obj) + scene.collection.objects.link(obj) + + # Set the origin to the current cursor position + set_origin_to_cursor(obj, context.scene.origin_type) + + if int(scene.array_num) > 1: + obj.modifiers.new("Array", type='ARRAY') + obj.modifiers["Array"].count = int(scene.array_num) + + # Set edge sharpness + edge_sharp_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 31, 33, 35, 37, 39, 44, 46, 48, 50, 53, 59, 63, 21, 20] + for edge_index in edge_sharp_indices: + obj.data.edges[edge_index].use_edge_sharp = True + + # Add smooth shading + obj.data.polygons.foreach_set("use_smooth", [True] * len(obj.data.polygons)) + + # Add material + mat = bpy.data.materials.new(name="CONE") + mat.use_nodes = True + principled = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled') + mat.node_tree.links.new(principled.outputs[0], mat.node_tree.nodes['Material Output'].inputs[0]) + obj.data.materials.append(mat) + + # Select the active object + obj.select_set(state=True) + return {'FINISHED'} + +def set_origin_to_cursor(obj, origin_type): + if origin_type == "View": + obj.location = bpy.context.space_data.region_3d.view_location + obj.location.z = 0 + else: + obj.location = bpy.context.scene.cursor.location + +# Panel Refresh -------------------------------------------------------------------------------- +class Refresh(View3DPanel, bpy.types.Panel): + bl_idname = "VIEW3D_PT_Refresh" + bl_label = "Refresh" + + def draw(self, context): + # Hinzufügen des Refresh Icon Buttons + self.layout.operator("image.reload", text="", icon='FILE_REFRESH') + +class ReloadTextures(bpy.types.Operator): + bl_idname = "image.reload" + bl_label = "Reload Textures" + + def execute(self, context): + # Funktion zum Neuladen der Texturen + for img in bpy.data.images: + img.reload() + return {'FINISHED'} + +def register(): + bpy.utils.register_class(RenameMesh) + bpy.utils.register_class(Texturechecker) + bpy.utils.register_class(TransferObjectNameOperator) + bpy.utils.register_class(RenameSelectedObjectsOperator) + bpy.utils.register_class(AddMesh) + bpy.types.WindowManager.object_name = bpy.props.StringProperty(name="Object Name") + bpy.utils.register_class(AddMeshOperator1) + bpy.utils.register_class(AddMeshOperator2) + bpy.types.Scene.array_num = bpy.props.IntProperty(name="array", default=1, min=1, max=100, description="Enter number of arrays") + bpy.utils.register_class(Refresh) + bpy.utils.register_class(ReloadTextures) + bpy.types.Object.pivot_point = bpy.props.BoolProperty( + name="Checkbox", + description="Checkbox", + default=False + ) + bpy.types.Scene.origin_type = bpy.props.EnumProperty(items=[("View", "View", "Set origin to view location"), ("Cursor", "3D Cursor", "Set origin to 3D Cursor location")], name="") + + +def unregister(): + del bpy.types.WindowManager.object_name + del bpy.types.Scene.array_num + del bpy.types.Scene.pivot_point + del bpy.types.Scene.origin_type + bpy.utils.unregister_class(RenameMesh) + bpy.utils.unregister_class(Texturechecker) + bpy.utils.unregister_class(TransferObjectNameOperator) + bpy.utils.unregister_class(RenameSelectedObjectsOperator) + bpy.utils.register_class(AddMesh) + bpy.utils.register_class(AddMeshOperator1) + bpy.utils.register_class(AddMeshOperator2) + bpy.utils.unregister_class(Refresh) + bpy.utils.unregister_class(ReloadTextures) + +if __name__ == "__main__": + register() \ No newline at end of file