Skip to content

Commit 3a69e4f

Browse files
committed
Added AO, reduced repetitive code
Added the AO pass, and reduced the repetitive code, to use a function instead. issue: Seen does not work
1 parent d6dea04 commit 3a69e4f

3 files changed

Lines changed: 32 additions & 44 deletions

File tree

SFR_Panel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def draw(self, context):
191191
layout.label(text="Texture Optimization Factor")
192192
col = layout.column(align=True)
193193
col.prop(settings, "diffuse_resize", slider=True)
194+
col.prop(settings, "ao_resize", slider=True)
194195
col.prop(settings, "specular_resize", slider=True)
195196
col.prop(settings, "roughness_resize", slider=True)
196197
col.prop(settings, "normal_resize", slider=True)

SFR_Settings.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@ class SFR_Settings(PropertyGroup):
109109
default=0,
110110
max=7,
111111
min=0,
112-
description="the factor by which the diffuse or albedo textures will be scaled down, 0 = unaffected \nrecomended: 0",
112+
description="the factor by which the ambient occlusion textures will be scaled down, 0 = unaffected \nrecomended: 0",
113+
options=set(), # Not animatable!
114+
)
115+
ao_resize: IntProperty(
116+
name="Ambient Occlusion",
117+
default=2,
118+
max=7,
119+
min=0,
120+
description="the factor by which the roughness or glossiness textures will be scaled down, 0 = unaffected \nrecomended: 2",
113121
options=set(), # Not animatable!
114122
)
115123
specular_resize: IntProperty(

Utils/SFR_TextureOptimizer.py

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def execute(self, context: Context):
4545
Opacity = ["opacity","alpha","presence"]
4646
Normal = ["normal","norm","nor","nrm","bump","bmp","height"]
4747
Translucency = ["translucency","transmission","translucent"]
48+
AO = ["ao","ambient occlusion","occlusion"]
4849

4950
#make skimage not give warning
5051
import imageio.core.util
@@ -67,49 +68,27 @@ def add_to_seen(file, type):
6768

6869
return False
6970

70-
71-
for file in os.listdir(path):
72-
if not os.path.isfile(os.path.join(path, file)):
73-
continue
74-
# lowercase file name for comparisons
75-
nc_file = nc(file)
76-
77-
if settings.diffuse_resize > 0:
78-
if [name for name in Diffuse if name in nc_file]:
79-
if add_to_seen(file, 'Diffuse'):
80-
continue
81-
resize_image(file, settings.diffuse_resize, path)
82-
83-
if settings.specular_resize > 0:
84-
if [name for name in Specular if name in nc_file]:
85-
if add_to_seen(file, 'Specular'):
86-
continue
87-
resize_image(file, settings.specular_resize, path)
88-
89-
if settings.roughness_resize > 0:
90-
if [name for name in Roughness if name in nc_file]:
91-
if add_to_seen(file, 'Roughness'):
92-
continue
93-
resize_image(file, settings.roughness_resize, path)
94-
95-
if settings.opacity_resize > 0:
96-
if [name for name in Opacity if name in nc_file]:
97-
if add_to_seen(file, 'Opacity'):
98-
continue
99-
resize_image(file, settings.opacity_resize, path)
100-
101-
if settings.normal_resize > 0:
102-
if [name for name in Normal if name in nc_file]:
103-
if add_to_seen(file, 'Normal'):
104-
continue
105-
resize_image(file, settings.normal_resize, path)
106-
107-
if settings.translucency_resize > 0:
108-
if [name for name in Translucency if name in nc_file]:
109-
if add_to_seen(file, 'Translucency'):
110-
continue
111-
resize_image(file, settings.translucency_resize, path)
112-
71+
def do_resize(path, setting, prop, type):
72+
for file in os.listdir(path):
73+
if not os.path.isfile(os.path.join(path, file)):
74+
continue
75+
# lowercase file name for comparisons
76+
nc_file = nc(file)
77+
78+
if setting > 0:
79+
if [name for name in prop if name in nc_file]:
80+
if add_to_seen(file, type):
81+
continue
82+
resize_image(file, setting, path)
83+
84+
do_resize(path, settings.diffuse_resize, Diffuse, 'Diffuse')
85+
do_resize(path, settings.ao_resize, AO, 'AO')
86+
do_resize(path, settings.specular_resize, Specular, 'Specular')
87+
do_resize(path, settings.roughness_resize, Roughness, 'Roughness')
88+
do_resize(path, settings.opacity_resize, Opacity, 'Opacity')
89+
do_resize(path, settings.normal_resize, Normal, 'Normal')
90+
do_resize(path, settings.translucency_resize, Translucency, 'Translucency')
91+
11392
print("TEXTURE OPTIMIZATION: COMPLETED")
11493

11594
return {'FINISHED'}

0 commit comments

Comments
 (0)