-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add audio support to the GLTF module #88204
base: master
Are you sure you want to change the base?
Conversation
modules/gltf/SCsub
Outdated
# For MP3 support in the audio GLTFDocumentExtension. | ||
if env["module_minimp3_enabled"]: | ||
thirdparty_dir = "#thirdparty/minimp3/" | ||
if not env.msvc: | ||
env_modules.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path]) | ||
else: | ||
env_modules.Prepend(CPPPATH=[thirdparty_dir]) | ||
if not env["minimp3_extra_formats"]: | ||
env_modules.Append(CPPDEFINES=["MINIMP3_ONLY_MP3"]) | ||
|
||
# For OGG Vorbis support in the audio GLTFDocumentExtension. | ||
if env["module_vorbis_enabled"]: | ||
thirdparty_dir = "#thirdparty/libvorbis/" | ||
env_modules.Prepend(CPPPATH=[thirdparty_dir]) | ||
if env["builtin_libogg"]: | ||
env_modules.Prepend(CPPPATH=["#thirdparty/libogg"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use some assistance from buildsystem gurus here. Right now this code adds these path includes into the whole of the modules environment, which seems wrong. If I move env_gltf = env_modules.Clone()
above these lines, and change env_modules
here to env_gltf
, it does not compile.
[ 28%] In file included from modules/gltf/extensions/audio/gltf_document_extension_audio.cpp:40:
./modules/minimp3/audio_stream_mp3.h:37:10: fatal error: 'minimp3_ex.h' file not found
#include <minimp3_ex.h>
^~~~~~~~~~~~~~
[ 28%] 1 error generated.
[ 93%] scons: *** [modules/gltf/extensions/audio/gltf_document_extension_audio.macos.editor.arm64.o] Error 1
} else if (uri.ends_with(".mp3")) { | ||
return "audio/mpeg"; | ||
} else if (uri.ends_with(".wav")) { | ||
return "audio/wav"; | ||
} else if (uri.ends_with(".ogg")) { | ||
return "audio/ogg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decision, at least for now, is that the spec only requires support for the MP3 and WAV audio MIME types. Supporting Ogg Vorbis here is a superset of the spec. There is no harm in having this here, but I wanted to mention it. Additionally, with this PR, Ogg Vorbis cannot be exported, so Godot will only ever export valid to-spec files.
void _copy_audio_stream_properties_to_audio_source(const Ref<AudioStream> p_audio_stream, Dictionary &p_audio_source) { | ||
Ref<AudioStreamWAV> audio_stream_wav = p_audio_stream; | ||
#ifdef MODULE_MINIMP3_ENABLED | ||
Ref<AudioStreamMP3> audio_stream_mp3 = p_audio_stream; | ||
#endif // MODULE_MINIMP3_ENABLED | ||
#ifdef MODULE_VORBIS_ENABLED | ||
Ref<AudioStreamOggVorbis> audio_stream_ogg = p_audio_stream; | ||
#endif // MODULE_VORBIS_ENABLED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The audio formats are conditionally compiled, so you can compile the glTF module without MiniMP3, without Vorbis, or without both if you want to. I tested that this works.
b75f5e4
to
22aa3ad
Compare
We are waiting for the ratification of the various gltf extension standards. |
Marking as draft to prevent accidental merging before ratification. However, the code is complete and ready for review. |
22aa3ad
to
7e5871c
Compare
Implements this proposal godotengine/godot-proposals#8814
This PR adds support for audio import and export in the GLTF module using the not-yet-finalized KHR_audio_emitter GLTF extension (KhronosGroup/glTF#2137). This allows you to save audio inside of GLTF scenes, and load them back later. In the future this will also allow you to use GLTF as an interchange format between game engines.
Some example use cases: a fountain that makes water noises, a gun that makes custom sounds when fired, the radio from Portal that plays music on a loop, or a tree that includes bird chirping noises or rustling leaves or something. For more details about the intended use cases, see the proposal.
Freely licensed example file: https://github.com/omigroup/gltf-extensions/tree/main/extensions/2.0/KHR_audio_emitter/examples/boom_box This file contains a boom box, a short looping music clip, OMI physics, and licensing information via
KHR_xmp_json_ld
. The model is CC0, created by The Khronos Group, and the music is CC-BY 3.0, created by Kevin MacLeod.The code in this PR is ready for review, but note that the extension is not yet finalized. Usually my approach is for us to be pioneers with Godot and implement extensions that may not be finalized, like with OMI physics. However, for this extension, since it is using the
KHR_
namespace, we must tread carefully and avoid shipping features in Khronos's namespace into production without Khronos's approval. Don't put words in their mouth, so to speak.Production edit: closes godotengine/internal-team-priorities#44