-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_scene_export.gd
More file actions
81 lines (68 loc) · 3.68 KB
/
Copy pathtest_scene_export.gd
File metadata and controls
81 lines (68 loc) · 3.68 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
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
## "Bake as Scene" export: dock state -> .scn -> reload, asserting the snapshot is a
## plain scene with no Kickdot dependencies. Run:
## godot --headless -s tests/test_scene_export.gd
extends SceneTree
const OUT_PATH := "user://baked_test.scn"
var _failures := 0
func _init() -> void:
ProjectSettings.set_setting("kickdot/build/combine_meshes", false)
ProjectSettings.set_setting(SKResourceCache.SETTING_CACHE_DIR, "user://test_kickdot_cache")
# The dock needs a running tree for _ready()/_build_ui(); defer past _init.
call_deferred("_run")
func _run() -> void:
print("[scene export]")
var dock: Control = load("res://addons/kickdot/editor/sidekick_dock.gd").new()
root.add_child(dock) # _ready() -> refresh()
# Equip the first preset of every group so the dock state describes a full character.
for group: int in dock._preset_pickers:
var picker: OptionButton = dock._preset_pickers[group]
if picker.item_count > 1:
dock._apply_part_preset(picker.get_item_id(1), group)
DirAccess.remove_absolute(ProjectSettings.globalize_path(OUT_PATH))
dock.export_scene(OUT_PATH)
_check(String(dock._status.text).begins_with("Baked"), "status reports success (got '%s')" % dock._status.text)
_check(FileAccess.file_exists(OUT_PATH), "scene file written")
var no_addon_deps := true
for dep in ResourceLoader.get_dependencies(OUT_PATH):
if String(dep).contains("addons/kickdot"):
no_addon_deps = false
_check(no_addon_deps, "no dependency on addons/kickdot")
var packed: PackedScene = ResourceLoader.load(OUT_PATH, "PackedScene", ResourceLoader.CACHE_MODE_IGNORE)
_check(packed != null, "scene loads back")
if packed != null:
var character := packed.instantiate()
_check(character is Node3D and character.get_script() == null, "root is a plain Node3D without script")
var skeleton: Node = character.find_children("*", "Skeleton3D", true, false).front()
_check(skeleton != null, "skeleton present")
var meshes := character.find_children("*", "MeshInstance3D", true, false)
_check(meshes.size() >= 5, "part meshes present (got %d)" % meshes.size())
var clean := true
for node: Node in [character] + character.find_children("*", "", true, false):
if node.has_meta(SKCharacterBuilder.GENERATED_META) or node.get_script() != null:
clean = false
_check(clean, "no generated-meta or scripts anywhere in the snapshot")
var baked_materials := true
for mesh: MeshInstance3D in meshes:
if not (mesh.material_override is StandardMaterial3D) or mesh.skin == null:
baked_materials = false
_check(baked_materials, "every mesh has a baked StandardMaterial3D and a skin")
character.free()
# Combined mode: the merged ArrayMesh has no resource path, so it embeds in the file.
ProjectSettings.set_setting("kickdot/build/combine_meshes", true)
const COMBINED_PATH := "user://baked_test_combined.scn"
dock.export_scene(COMBINED_PATH)
_check(String(dock._status.text).begins_with("Baked 1 "), "combined bake has a single mesh (got '%s')" % dock._status.text)
var combined: PackedScene = ResourceLoader.load(COMBINED_PATH, "PackedScene", ResourceLoader.CACHE_MODE_IGNORE)
_check(combined != null, "combined scene loads back")
if combined != null:
var character := combined.instantiate()
var mesh: MeshInstance3D = character.find_children("*", "MeshInstance3D", true, false).front()
_check(mesh != null and mesh.mesh != null and mesh.mesh.get_blend_shape_count() > 0,
"combined mesh kept its blend shapes")
character.free()
print("SCENE EXPORT: %s" % ("ALL PASSED" if _failures == 0 else "%d FAILURES" % _failures))
quit(0 if _failures == 0 else 1)
func _check(condition: bool, label: String) -> void:
print(" %s %s" % ["PASS" if condition else "FAIL", label])
if not condition:
_failures += 1