forked from Hancapo/VichoTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvicho_operators.py
214 lines (167 loc) · 7.9 KB
/
vicho_operators.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import bpy
import os
from .misc.misc_funcs import export_milo_ymap_xml
from bpy.props import StringProperty
from bpy_extras.io_utils import ExportHelper
class ExpSelObjsFile(bpy.types.Operator):
bl_idname = "vicho.selobjsastext"
bl_label = "Save to file"
@classmethod
def poll(cls, context):
return context.selected_objects is not None
def execute(self, context):
objetos = context.selected_objects
nombres = []
for objeto in objetos:
nombres.append(objeto.name)
# filter name with a dot and just get the string before the dot
nombres = [nombre.split(".")[0] for nombre in nombres]
nombres = list(set(nombres))
# get user's desktop path
desktop_path = os.path.expanduser("~/Desktop")
# export list to file with name from scene
with open(desktop_path + "/" + context.scene.file_name_field + ".txt", "w") as f:
for nombre in nombres:
f.write(nombre + "\n")
return {'FINISHED'}
class VichoCreateVC(bpy.types.Operator):
bl_idname = "vicho.vertexcolor"
bl_label = "Create Vertex Color"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
bpy.ops.geometry.color_attribute_add(
name="colour0", domain='CORNER', data_type='BYTE_COLOR')
return {'FINISHED'}
class ResetObjTransRot(bpy.types.Operator):
bl_idname = "vicho.resetobjtransrot"
bl_label = "Reset object(s) transforms"
@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0 and (context.scene.location_checkbox or context.scene.rotation_checkbox or context.scene.scale_checkbox)
def execute(self, context):
check_loc = context.scene.location_checkbox
check_rot = context.scene.rotation_checkbox
check_scale = context.scene.scale_checkbox
objetos = context.selected_objects
for objeto in objetos:
if check_loc:
objeto.location = (0, 0, 0)
if check_rot:
if objeto.rotation_mode == 'QUATERNION':
objeto.rotation_quaternion = (1, 0, 0, 0)
elif objeto.rotation_mode == 'AXIS_ANGLE':
objeto.rotation_axis_angle = (0, 0, 0, 0)
else:
objeto.rotation_euler = (0, 0, 0)
if check_scale:
objeto.scale = (1, 1, 1)
return {'FINISHED'}
class ExportMLOTransFile(bpy.types.Operator):
bl_idname = "vicho.exportmlostransformstofile"
bl_label = "Export MLO transforms to YMAP"
@classmethod
def poll(cls, context):
return context.selected_objects is not None
def execute(self, context):
objetos = context.selected_objects
for objeto in objetos:
if objeto.sollum_type == 'sollumz_bound_composite' or objeto.type == 'MESH':
export_milo_ymap_xml(
'Mi bro', objeto, context.scene.ymap_instance_name_field)
self.report(
{'INFO'}, f"{objeto.name} location and rotation exported to file")
else:
self.report(
{'WARNING'}, f"{objeto.name} is not a Bound Composite or a Mesh")
return {'FINISHED'}
class PasteObjectTransformFromPickedObject(bpy.types.Operator):
bl_idname = "vicho.pasteobjtransfrompickedobject"
bl_label = "Set transforms"
@classmethod
def poll(cls, context):
return context.scene.CopyDataFromObject is not None and (context.scene.locationOb_checkbox or context.scene.rotationOb_checkbox or context.scene.scaleOb_checkbox)
def execute(self, context):
fromobj = context.scene.CopyDataFromObject
toobj = context.scene.PasteDataToObject
if context.scene.locationOb_checkbox:
toobj.location = fromobj.location
if context.scene.rotationOb_checkbox:
toobj.rotation_euler = fromobj.rotation_euler
if context.scene.scaleOb_checkbox:
toobj.scale = fromobj.scale
return {'FINISHED'}
class DeleteEmptyObj(bpy.types.Operator):
bl_idname = "vicho.deleteemptyobj"
bl_label = "Delete empty objects"
@classmethod
def poll(cls, context):
return context.selected_objects is not None
def execute(self, context):
objects = context.selected_objects
for obj in objects:
if obj.type == 'EMPTY':
if obj.sollum_type == 'sollumz_drawable':
if len(obj.children) < 1:
bpy.data.objects.remove(obj)
else:
for ochild in obj.children:
if ochild.sollum_type == 'sollumz_drawable_model':
drawmodelchild = ochild.children
if len(drawmodelchild) < 1:
bpy.data.objects.remove(ochild)
else:
for dchild in drawmodelchild:
if dchild.sollum_type == 'sollumz_drawable_geometry' and dchild.type == 'MESH':
if len(dchild.data.vertices) < 1:
bpy.data.objects.remove(dchild)
if len(ochild.children) < 1:
bpy.data.objects.remove(
ochild)
elif obj.sollum_type == 'sollumz_bound_composite':
if len(obj.children) < 1:
bpy.data.objects.remove(obj)
else:
for ochild in obj.children:
if ochild.sollum_type == 'sollumz_bound_geometrybvh':
drawmodelchild = ochild.children
if len(drawmodelchild) < 1:
bpy.data.objects.remove(ochild)
else:
for dchild in drawmodelchild:
if (dchild.sollum_type == 'sollumz_bound_poly_triangle' or
dchild.sollum_type == 'sollumz_bound_poly_box' or
dchild.sollum_type == 'sollumz_bound_poly_sphere' or
dchild.sollum_type == 'sollumz_bound_poly_cylinder' or
dchild.sollum_type == 'sollumz_bound_poly_capsule') and dchild.type == 'MESH':
if len(dchild.data.vertices) < 1:
bpy.data.objects.remove(dchild)
if len(ochild.children) < 1:
bpy.data.objects.remove(
ochild)
elif obj.sollum_type == 'sollumz_drawable_dictionary':
print('todo')
else:
continue
return {'FINISHED'}
class MloYmapFileBrowser(bpy.types.Operator, ExportHelper):
bl_idname = "vicho.mloyampfilebrowser"
bl_label = "Export MLO transforms to YMAP"
bl_action = "Export a YMAP MLO"
bl_showtime = True
filename_ext = '.ymap'
filter_glob: StringProperty(
default='*.ymap',
options={'HIDDEN'}
)
def execute(self, context):
try:
export_milo_ymap_xml(
self.filepath, context.active_object, context.scene.ymap_instance_name_field)
self.report({'INFO'}, f"{self.filepath} successfully exported")
return {'FINISHED'}
except:
self.report(
{'ERROR'}, f"Error exporting {self.filepath} ")
return {'FINISHED'}