-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture_checks.py
More file actions
54 lines (46 loc) · 2.08 KB
/
texture_checks.py
File metadata and controls
54 lines (46 loc) · 2.08 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
import os
import cv2
from PIL import Image
SUPPORTED_TEXTURES = ['.png', '.jpg', '.bmp', '.jpeg']
def is_supportedtexture(filename):
filename = filename.lower()
if filename[filename.find("."):] in SUPPORTED_TEXTURES:
return True
return False
def existence_check(texture, normalmap):
if os.path.exists(texture) and os.path.exists(normalmap):
return True
print("One or both texture files don't exist. Please check input paths.")
exit(-1)
def check_sizes(source_texture, normal_map):
f_source_texture = cv2.imread(source_texture)
f_normal_map = cv2.imread(normal_map)
ws, hs, _ = f_source_texture.shape
wn, hn, _ = f_normal_map.shape
if ws==wn and hs == hn:
return True
print("Normal map and source texture sould have same widht and height")
print("Your texture resolution: ", ws,'x',hs)
print("Your normal map resolution: ", wn, 'x', hn)
exit(-1)
def has_nss(path, alphabet=set('абвгдеёжзийклмнопрстуфхцчшщъыьэюяäößü')):
return not alphabet.isdisjoint(path.lower())
def texture_path_check(source_texture, normal_map):
if ' ' not in source_texture and ' ' not in normal_map and not has_nss(source_texture) and not has_nss(normal_map):
return True
print("Your texture/normal map path contains not supported symbols. Please change the path(s).")
exit(-1)
def typo_check(source_texture, normal_map):
if is_supportedtexture(source_texture) and is_supportedtexture(normal_map):
return True
print("Input file types aren't supported by this utility. ")
print("Supported types: ", end=' ')
for i in SUPPORTED_TEXTURES:
print(i, end=" ")
exit(-1)
def texture_validation(source_texture, normal_map):
existence_check(texture=source_texture, normalmap=normal_map)
texture_path_check(source_texture=source_texture, normal_map=normal_map)
typo_check(source_texture=source_texture, normal_map=normal_map)
check_sizes(source_texture=source_texture, normal_map=normal_map)
return True