-
Notifications
You must be signed in to change notification settings - Fork 13
/
plugin.gd
138 lines (119 loc) · 4.52 KB
/
plugin.gd
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
@tool
extends EditorPlugin
# The new node type to be added
const humanizer_node = preload('res://addons/humanizer/scripts/utils/humanizer_editor_tool.gd')
# Its icon in the scene tree
const node_icon = preload('res://addons/humanizer/icon.png')
# Editor inspectors
var humanizer_inspector = HumanizerEditorInspectorPlugin.new()
var asset_import_inspector = AssetImporterInspectorPlugin.new()
var human_randomizer_inspector = HumanRandomizerInspectorPlugin.new()
var humanizer_material_inspector = HumanizerMeshInstanceInspectorPlugin.new()
# For mapping tool menu signals
const menu_ids := {
'generate_base_mesh': 1,
'read_shapekeys': 2,
'rig_config': 4,
'image_import_settings': 5,
'process_raw_data': 10,
'reload_registry': 20,
'purge_generated_assets': 29,
'asset_importer': 30,
'test': 999,
}
# Thread for background tasks
var thread := Thread.new()
func _enter_tree():
# Load global config singleton
add_autoload_singleton('HumanizerGlobal', "res://addons/humanizer/scenes/humanizer_global.tscn")
# Add editor inspector plugins
add_inspector_plugin(humanizer_inspector)
add_inspector_plugin(asset_import_inspector)
add_inspector_plugin(human_randomizer_inspector)
add_inspector_plugin(humanizer_material_inspector)
# Add custom humanizer node
add_custom_type('Humanizer', 'Node3D', humanizer_node, node_icon)
# Add a submenu to the Project/Tools menu
_add_tool_submenu()
func _exit_tree():
remove_custom_type('Humanizer')
remove_tool_menu_item('Humanizer')
remove_inspector_plugin(humanizer_inspector)
remove_inspector_plugin(asset_import_inspector)
remove_inspector_plugin(human_randomizer_inspector)
remove_inspector_plugin(humanizer_material_inspector)
remove_autoload_singleton('HumanizerGlobal')
if thread.is_started():
thread.wait_to_finish()
func _add_tool_submenu() -> void:
# Should we cache this to clean up signals in _exit_tree?
var popup_menu = PopupMenu.new()
var preprocessing_popup = PopupMenu.new()
var import_assets_popup = PopupMenu.new()
preprocessing_popup.name = 'preprocessing_popup'
preprocessing_popup.add_item('Generate Base Meshes', menu_ids.generate_base_mesh)
preprocessing_popup.add_item('Read ShapeKey files', menu_ids.read_shapekeys)
preprocessing_popup.add_item('Set Up Skeleton Configs', menu_ids.rig_config)
preprocessing_popup.add_item('Import Images as Uncompressed', menu_ids.image_import_settings)
popup_menu.add_child(preprocessing_popup)
popup_menu.add_submenu_item('Preprocessing Tasks', 'preprocessing_popup')
popup_menu.add_item('Run All Preprocessing', menu_ids.process_raw_data)
popup_menu.add_item('Purge Generated Asset Resources', menu_ids.purge_generated_assets)
popup_menu.add_item('Import All Assets', menu_ids.asset_importer)
popup_menu.add_item('Reload Registry', menu_ids.reload_registry)
popup_menu.add_item('Run Test Function', menu_ids.test)
add_tool_submenu_item('Humanizer', popup_menu)
popup_menu.id_pressed.connect(_handle_menu_event)
preprocessing_popup.id_pressed.connect(_handle_menu_event)
func _handle_menu_event(id) -> void:
if thread.is_alive():
printerr('Thread busy... Try again after current task completes')
return
if thread.is_started():
thread.wait_to_finish()
if id == menu_ids.generate_base_mesh:
thread.start(_generate_base_meshes)
elif id == menu_ids.read_shapekeys:
thread.start(_read_shapekeys)
elif id == menu_ids.rig_config:
thread.start(_rig_config)
elif id == menu_ids.image_import_settings:
thread.start(_image_import_settings)
elif id == menu_ids.process_raw_data:
_process_raw_data()
elif id == menu_ids.asset_importer:
thread.start(_import_assets)
elif id == menu_ids.purge_generated_assets:
thread.start(_purge_assets)
elif id == menu_ids.reload_registry:
HumanizerRegistry.load_all()
elif id == menu_ids.test:
thread.start(_test)
#region Thread Tasks
func _process_raw_data() -> void:
print_debug('Running all preprocessing')
for task in [
_generate_base_meshes,
_read_shapekeys,
_rig_config,
_image_import_settings
]:
thread.start(task)
while thread.is_alive():
await get_tree().create_timer(1).timeout
thread.wait_to_finish()
func _generate_base_meshes() -> void:
ReadBaseMesh.new().run()
func _read_shapekeys() -> void:
ShapeKeyReader.new().run()
func _rig_config() -> void:
HumanizerSkeletonConfig.new().run()
func _image_import_settings() -> void:
HumanizerImageImportSettings.new().run()
func _import_assets() -> void:
HumanizerAssetImporter.new().run(false)
func _purge_assets() -> void:
HumanizerAssetImporter.new().run(true)
func _test() -> void:
print(typeof('test'))
#endregion