-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
functions.py
151 lines (122 loc) · 4.77 KB
/
functions.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
import bpy
import os
import time
from .addon_prefs import get_addon_preferences
from .global_variables import preview_texture
# absolute path
def absolute_path(relpath):
return os.path.abspath(bpy.path.abspath(relpath))
# get addon path
def get_current_dir():
""" get current file parent directory absolute path """
script = os.path.realpath(__file__)
return os.path.dirname(script)
# check libraries
def check_libraries():
modified = []
missing = []
for item in bpy.data.libraries:
path = absolute_path(item.filepath)
if os.path.isfile(path):
if item.autoreload_modification_time != str(os.path.getmtime(path)) \
and not item.autoreload_modified:
item.autoreload_modified=True
modified.append(item)
else:
if item.autoreload_modification_time!="missing":
item.autoreload_modification_time = "missing"
item.autoreload_modified = True
missing.append(item)
return modified, missing
# reload library
def reload_library(lib):
lib.reload()
lib.autoreload_modified=False
lib.autoreload_modification_time = str(os.path.getmtime(absolute_path(lib.filepath)))
# reload modified images
def reload_modified_images():
modified = []
missing = []
# reload images
for item in bpy.data.images:
if not item.library and not item.packed_file and item.source not in {'VIEWER','GENERATED'}:
path = absolute_path(item.filepath)
if os.path.isfile(path):
if item.autoreload_modification_time!=str(os.path.getmtime(path)):
item.reload()
item.autoreload_modification_time=str(os.path.getmtime(path))
modified.append(item.name)
else:
if item.autoreload_modification_time!="missing":
item.autoreload_modification_time="missing"
missing.append(item.name)
return modified, missing
# reload modified images from strip
# def reload_modified_strips_images():
# modified = []
# missing = []
# for scn in bpy.data.scenes:
# for s in scn.sequence_editor.sequences_all:
# if s.type == "IMAGE":
# for e in s.elements:
# update 3d view if in rendered mode and not EEVEE or WORKBENCH
def update_viewers(context):
if context.scene.render.engine not in ['BLENDER_EEVEE','BLENDER_WORKBENCH']:
wman = bpy.data.window_managers['WinMan']
for win in wman.windows :
for area in win.screen.areas :
if area.type=='VIEW_3D' :
for space in area.spaces :
if space.type == 'VIEW_3D' and space.shading.type == 'RENDERED' :
space.shading.type = 'SOLID'
space.shading.type = 'RENDERED'
# update textures
def update_textures(modified_image_list):
for tex in bpy.data.textures:
if tex.type == "IMAGE":
if tex.image:
if modified_image_list:
if tex.image.name in modified_image_list:
tex.image = bpy.data.images[tex.image.name]
else:
tex.image = bpy.data.images[tex.image.name]
# update textures with no images
def update_textures_no_images():
for tex in bpy.data.textures:
if tex.type == "IMAGE":
if not tex.image:
tex.use_alpha = tex.use_alpha
# update strips
# def update_strips(modified_image_list):
# for s in bpy.context.scene.sequence_editor.sequences_all:
# if s.type == "IMAGE":
# for e in s.elements:
# if modified_image_list:
# if e.filename in modified_image_list:
# e.filename = e.filename
# else:
# e.filename = e.filename
# check all images at startup
def check_images_startup():
is_missing = False
for item in bpy.data.images:
if not item.library and not item.packed_file:
try:
path=absolute_path(item.filepath)
item.autoreload_modification_time=str(os.path.getmtime(path))
except FileNotFoundError:
item.autoreload_modification_time="missing"
is_missing = True
return is_missing
# check all libraries at startup
def check_libraries_startup():
is_missing = False
for item in bpy.data.libraries:
try:
path=absolute_path(item.filepath)
item.autoreload_modification_time=str(os.path.getmtime(path))
item.autoreload_modified = False
except FileNotFoundError:
item.autoreload_modification_time="missing"
is_missing = True
return is_missing