-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWeekendMeshJoinScript.py
More file actions
60 lines (48 loc) · 2.25 KB
/
WeekendMeshJoinScript.py
File metadata and controls
60 lines (48 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import bpy
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
def GameReadyMeshJoin():
bpy.ops.object.make_single_user(object=True, obdata=True, material=False, animation=False, obdata_animation=False)
bpy.ops.object.convert(target='MESH')
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
bpy.ops.object.join()
bpy.ops.object.modifier_add(type='TRIANGULATE')
bpy.context.object.modifiers["Triangulate"].min_vertices = 5
def CleanUp():
# Getting rid of stuff with no faces
bpy.ops.object.convert(target='MESH')
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.reveal()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.delete_loose()
bpy.ops.object.editmode_toggle()
def AllQuads():
# Getting all quads
bpy.ops.object.convert(target='MESH')
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.reveal()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.tris_convert_to_quads(uvs=True, seam=True, sharp=True, materials=True)
bpy.ops.object.editmode_toggle()
bpy.ops.object.modifier_add(type='TRIANGULATE')
bpy.context.object.modifiers["Triangulate"].min_vertices = 5
def FixNormals():
# Fixing normals
bpy.ops.object.modifier_add(type='WEIGHTED_NORMAL')
bpy.context.object.modifiers["WeightedNormal"].keep_sharp = True
bpy.context.object.modifiers["WeightedNormal"].weight = 64
bpy.ops.mesh.customdata_custom_splitnormals_clear()
bpy.ops.object.shade_smooth(use_auto_smooth=True, auto_smooth_angle=1.0472) #This is for 60 degree
if (len(bpy.context.selected_objects) <= 0):
ShowMessageBox("You must select at least one object in the scene.", "Mesh Joining - Script", 'ERROR')
else:
# Cache a reference to all selected objects.
objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
# Switch to Object Mode, as this script will only work in that context.
bpy.ops.object.mode_set(mode='OBJECT')
GameReadyMeshJoin()
CleanUp()
AllQuads() #This one is Heavy! comment it out for +1M tris or more
FixNormals()