Skip to content
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 ability to export files and buffer views #73

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

robertlong
Copy link

This PR supersedes #60.

I'm developing an exporter plugin for Third Room that has support for the KHR_audio extension. This includes exporting mp3 files. Files are either exported to disk and referenced via uri or exported as a buffer view. This PR adds two new methods for exporting arbitrary files and buffer views as well as exposing the shouldUseInternalBuffer flag for determining which method to use.

When exporting as a .glb or if you just want to export arbitrary buffer views, you can now use the exporter.ExportBufferView(byte[] bytes) function.

When exporting as a .gltf and you want to export an external file you can now use the exporter.ExportFile(string path) function which returns the file uri.

Here's an example of this in use:

KHR_AudioData audio;

if (exporter.shouldUseInternalBuffer) {
  var data = File.ReadAllBytes(path);
  var bufferView = exporter.ExportBufferView(data);

  audio = new KHR_AudioData() {
    mimeType = "audio/mpeg",
    bufferView = bufferView,
  };
} else {
  audio = new KHR_AudioData() {
    uri = exporter.ExportFile(path),
  };
}

@hybridherbst
Copy link

hybridherbst commented Feb 4, 2023

Thanks! It feels a bit weird that now I need to handle things different depending on if I want to export a glTF or a glb (exposing these internals, basically).

Just an idea, what do you think about:

  • always passing in streams (could be a FileStream or MemoryStream) with a filename/path
  • keeping shouldUseInternalBuffer private
  • at export time deciding by shouldUseInternalBuffer whether the data should be shoveled into a bufferView or onto disk?
  • returning a struct with both infos (bufferView, uri), either of which can be null, so that the extension can write itself correctly

@robertlong
Copy link
Author

Here's where I'm using it right now: https://github.com/matrix-org/thirdroom-unity-exporter/blob/main/Packages/thirdroom-unity-exporter/Runtime/Scripts/KHR_audio/KHR_AudioExtension.cs#L123

I think that approach would work well 👍 I'll switch over to it and update this PR when I do.

@robertlong
Copy link
Author

A couple months later, but I finally made the change @hybridherbst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants