diff --git a/project/addons/godot-steam-audio/src/post_import.gd b/project/addons/godot-steam-audio/src/post_import.gd new file mode 100644 index 0000000..7dcb4f7 --- /dev/null +++ b/project/addons/godot-steam-audio/src/post_import.gd @@ -0,0 +1,61 @@ +@tool +# Generates SteamAudioGeometry for imported scenes with hints. +class_name SteamAudioPostImport +extends EditorScenePostImport + +var scene_root: Node +var STEAM_AUDIO_GEOM_PREFIX := "-sasg" +var STEAM_AUDIO_DYN_GEOM_PREFIX := "-sadg" + +enum GeomType { + NONE = 0, + STATIC = 1, + DYNAMIC = 2 +} + +func _post_import(scene: Node): + self.scene_root = scene + iterate(scene) + return scene + +func iterate(n: Node): + var typ := steam_audio_geom_type(n) + if typ != GeomType.NONE: + var g: Node + match typ: + GeomType.STATIC: + g = SteamAudioGeometry.new() + g.name = "SteamAudioGeometry" + GeomType.DYNAMIC: + g = SteamAudioDynamicGeometry.new() + g.name = "SteamAudioDynamicGeometry" + g.set_material(preload("res://addons/godot-steam-audio/materials/default_material.tres")) + n.add_child(g) + g.owner = self.scene_root + + + for child in n.get_children(): + iterate(child) + +func steam_audio_geom_type(n: Node) -> GeomType: + if n is MeshInstance3D: + if n.name.ends_with(STEAM_AUDIO_GEOM_PREFIX): + n.name = n.name.substr(0, n.name.length() - 5) + return GeomType.STATIC + elif n.name.ends_with(STEAM_AUDIO_DYN_GEOM_PREFIX): + n.name = n.name.substr(0, n.name.length() - 5) + return GeomType.DYNAMIC + return GeomType.NONE + if n is CollisionShape3D: + # check parent name because -colonly generates plain names + # for the collision shapes. we do not check the grandparents + # (for the -col case) because we've already generated a geometry for the mesh instance. + if n.get_parent().name.ends_with(STEAM_AUDIO_GEOM_PREFIX): + n.get_parent().name = n.get_parent().name.substr(0, n.get_parent().name.length() - 5) + return GeomType.STATIC + elif n.get_parent().name.ends_with(STEAM_AUDIO_DYN_GEOM_PREFIX): + n.get_parent().name = n.get_parent().name.substr(0, n.get_parent().name.length() - 5) + return GeomType.DYNAMIC + return GeomType.NONE + return GeomType.NONE + diff --git a/src/lib/steamaudio b/src/lib/steamaudio index 85db68e..b0bfcd5 160000 --- a/src/lib/steamaudio +++ b/src/lib/steamaudio @@ -1 +1 @@ -Subproject commit 85db68e7d560079d8c5bd685e550d07c21cd32d1 +Subproject commit b0bfcd58189aaddef15cab223b31ed16737eda75