-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlenderUnrealCollisionScript.txt
84 lines (70 loc) · 3.01 KB
/
BlenderUnrealCollisionScript.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#1 December 2018
#Added functionality to toggle auto-unwrap on or off
#26 December 2017
#Dingo_aus
#Script adds geometry that Unreal Engine interprets to be the collision volumes. Collision data will be added to layer 2 in Blender
#script requires objects to be selected for collision to be added
#0) remove the full stop from previsouly duplicated names
#0.5) Smart Project Unwrap each item (calculate UVs)
#1) Duplicates all selected objects then
#2) runs through a loop and finds the duplicated items with ".001, .002, .003 etc" and renames these
# objects to be collision objects. Will also put the collision volumes on Layer 2.
#GLOBAL VARIABLES
#set the variable below to 1 if you want the script to automatically unwrap the UVs of each selected visible mesh.
SHOULD_AUTO_UNWRAP = 0
import bpy
print("Start---------------- ")
#0)
for obj in bpy.context.selected_objects:
obj.name = obj.name.replace(".","_")
print("---Any fullstops in names successfully replaced with underscores... continuing")
#0.5) - Smart unwrap each object's UVs if GLOBAL variation set to unwrap
if SHOULD_AUTO_UNWRAP == 1:
bpy.ops.object.mode_set(mode = 'OBJECT')
unwrapcount = 0
for obj in bpy.data.objects:
#bpy.ops.object.select_all(action= 'DESELECT')
#if obj.layers[0] == True:
# bpy.context.scene.objects.active = obj
# obj.select = True
#else:
# continue
#Just to be sure that is everything deselected
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
print("---unwrapping: " + obj.name)
bpy.ops.uv.smart_project()
unwrapcount = unwrapcount + 1
print("---Total objects unwrapped:" + str(unwrapcount))
print("---All objects have been unwrapped")
elif SHOULD_AUTO_UNWRAP == 0:
print("---No Objects Unwrapped, original set UV Coords used---")
#1)
#Duplicate selected objects...then rename to be the collision
bpy.ops.object.duplicate()
print("---All objects duplicated")
#3)
#rename objects
n = 1
for obj in bpy.context.selected_objects:
n = n +1
oldname = obj.name
temp_str = oldname[-4:]
temp_str2 = "."
#print(temp_str)
if temp_str[:1] == temp_str2:
print("CANDIDATE TO CONVERT TO PHYSICS VOLUME HAS BEEN FOUND: " + oldname)
#add prefix
obj.name = "UCX_" + obj.name
#remove last four characters
obj.name = obj.name[:-4]
#add postfix
postfix_str = str(n)
obj.name = obj.name + "_" + postfix_str.rjust(2, '0')
#add to separate layer so export can exclude UCX objects and painted in Substance Painter etc
#move to layer 2
obj.layers=(False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
print("Collision volumes assigned to layer 2")
print(obj.name)
print("Success!")