-
Notifications
You must be signed in to change notification settings - Fork 2
/
__init__.py
115 lines (95 loc) · 3.58 KB
/
__init__.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
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
bl_info = {
"name": "Texture Compactor",
"author": "Mike Pan",
"description": "Optimize textures to reduce memory usage during render",
"blender": (4, 0, 0),
"version": (0, 0, 1),
"location": "Properties Panel > Render > Texture Compactor",
"warning": "",
"category": "Render",
}
import bpy
from . import ui
from . import core
classes = (
ui.TEXCOMPACTOR_PT_main_panel,
ui.TEXCOMPACTOR_OT_scan_textures,
ui.TEXCOMPACTOR_OT_optimize_textures,
ui.TEXCOMPACTOR_OT_show_report,
)
@bpy.app.handlers.persistent
def clear_addon_data(dummy):
# Clear or reset your addon data here
try:
bpy.context.scene.TC_texture_metadata.clear()
bpy.context.scene.TC_texture_metadata = []
except:
pass
def register():
bpy.app.handlers.load_post.append(clear_addon_data)
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.TC_convert_greyscale = bpy.props.EnumProperty(
items=[
("0", "Off", "Do nothing"),
("1", "Safe", "Optimize when there is no visible difference"),
("2", "Aggressive", "Use a higher tolerance, might make less colorful textures completely grey"),
],
name="Convert to Greyscale",
default="1",
options=set(),
update=core.update_memory_usage,
)
bpy.types.Scene.TC_smart_resize = bpy.props.EnumProperty(
items=[
("0", "Off", "Do nothing"),
("1", "Safe", "Optimize when there is no visible difference"),
("2", "Aggressive", "Use a higher tolerance to find more textures that can be resized"),
],
name="Smart Resize",
default="1",
options=set(),
update=core.update_memory_usage,
)
bpy.types.Scene.TC_optimize_float = bpy.props.EnumProperty(
items=[
("0", "Off", "Do nothing"),
("1", "Safe", "Set all float texture to be read at half-precision (16-bit)"),
("2", "Aggressive", "Not Implemented Yet"),
],
name="Float Textures",
default="1",
options=set(),
update=core.update_memory_usage,
)
bpy.types.Scene.TC_texture_swap = bpy.props.EnumProperty(
items=[("0", "Original", "Use original textures"), ("1", "Optimized", "Use optimized textures")],
name="Swap Textures",
options=set(),
default="0",
update=core.update_texture_swap,
)
bpy.types.Scene.TC_texture_metadata = []
def unregister():
bpy.app.handlers.load_post.remove(clear_addon_data)
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
del bpy.types.Scene.TC_convert_greyscale
del bpy.types.Scene.TC_smart_resize
del bpy.types.Scene.TC_optimize_float
del bpy.types.Scene.TC_texture_swap
del bpy.types.Scene.TC_texture_metadata
if __name__ == "__main__":
register()