forked from Sollumz/Sollumz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sollumz_helper.py
112 lines (88 loc) · 3.06 KB
/
sollumz_helper.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
import bpy
import traceback
import os
import time
from abc import abstractmethod
from .tools.meshhelper import get_children_recursive
from .sollumz_properties import BOUND_TYPES, SollumType
from .ydr.ydrexport import get_used_materials
class SOLLUMZ_OT_base:
bl_options = {"UNDO"}
bl_action = "do"
bl_showtime = False
bl_update_view = False
def __init__(self):
self.messages = []
@abstractmethod
def run(self, context):
pass
def execute(self, context):
start = time.time()
try:
result = self.run(context)
if self.bl_update_view:
reset_sollumz_view(context.scene)
except:
result = False
self.error(
f"Error occured running operator : {self.bl_idname} \n {traceback.format_exc()}")
end = time.time()
if self.bl_showtime and result == True:
self.message(
f"{self.bl_label} took {round(end - start, 3)} seconds to {self.bl_action}.")
if len(self.messages) > 0:
self.message('\n'.join(self.messages))
if result:
return {"FINISHED"}
else:
return {"CANCELLED"}
def message(self, msg):
self.report({"INFO"}, msg)
def warning(self, msg):
self.report({"WARNING"}, msg)
def error(self, msg):
self.report({"ERROR"}, msg)
def reset_sollumz_view(scene):
scene.hide_collision = not scene.hide_collision
scene.hide_high_lods = not scene.hide_high_lods
scene.hide_medium_lods = not scene.hide_medium_lods
scene.hide_low_lods = not scene.hide_low_lods
scene.hide_very_low_lods = not scene.hide_very_low_lods
scene.hide_collision = not scene.hide_collision
scene.hide_high_lods = not scene.hide_high_lods
scene.hide_medium_lods = not scene.hide_medium_lods
scene.hide_low_lods = not scene.hide_low_lods
scene.hide_very_low_lods = not scene.hide_very_low_lods
def is_sollum_object_in_objects(objs):
for obj in objs:
if obj.sollum_type != SollumType.NONE:
return True
return False
def get_sollumz_objects_from_objects(objs, sollum_type):
robjs = []
for obj in objs:
if obj.sollum_type in sollum_type:
robjs.append(obj)
for child in obj.children:
if child.sollum_type in sollum_type:
robjs.append(child)
return robjs
def find_fragment_file(filepath):
directory = os.path.dirname(filepath)
for file in os.listdir(directory):
if file.endswith(".yft.xml"):
return os.path.join(directory, file)
return None
def has_embedded_textures(obj):
for mat in get_used_materials(obj):
nodes = mat.node_tree.nodes
for node in nodes:
if(isinstance(node, bpy.types.ShaderNodeTexImage)):
if(node.texture_properties.embedded == True):
return True
return False
def has_collision(obj):
for child in get_children_recursive(obj):
if child.sollum_type in BOUND_TYPES:
return True
return False