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

Can this plugin bundle assets pointed to by glTF JSON files? #27

Open
krispya opened this issue Nov 30, 2023 · 3 comments
Open

Can this plugin bundle assets pointed to by glTF JSON files? #27

krispya opened this issue Nov 30, 2023 · 3 comments

Comments

@krispya
Copy link

krispya commented Nov 30, 2023

I have been using GLB files in dev mostly, but I recently wanted to start using glTF JSON with separated textures and bin so that I could reuse textures more easily. However, I ran into the Vite bundling problem where the imported glTF file gets bundled but none of the assets it points to. Can this Vite plugin handle that without transforming the file to GLB?

PS: I did not see a discussion tab for this repo or I would have posted this there.

@krispya krispya changed the title Can this plugin bundle assets pointed to by glTF JSON files too? Can this plugin bundle assets pointed to by glTF JSON files? Nov 30, 2023
@donmccurdy
Copy link
Contributor

Defined here ...

const publicAssetPath = publicPath + "/" + `${basename}.glb`;
const outputAssetPath = path.join(outputPath, `${basename}.glb`);
const document = await io.readJSON({ json, resources });
await document.setLogger(logger).transform(...pluginOptions.transforms);
this.emitFile({
type: "asset",
fileName: outputAssetPath,
source: await io.writeBinary(document),
});

... this plugin does always bundle input files to .glb, embedding any binary or image resources they depend on. I don't know of any reason it would have to work that way, but note that to support the 'hash' suffix properly, we'd need to append a hash to these resource filenames and update references from the .gltf.

@krispya
Copy link
Author

krispya commented Nov 30, 2023

I see! I do some pre-processing with gltf-transform but I'd like to do some post-processing with this plugin as well for builds. But the most basic expectation I have is that any .glb, .gltf and its linked assets inside of /src properly make it into a build. Does that align with the vision for this plugin?

@donmccurdy
Copy link
Contributor

donmccurdy commented Nov 30, 2023

Nothing is lost now, but your linked resources (.png, .jpg, .bin, ...) are getting embedded into .glb files in the bundling step. I think changing that so it's possible to output .gltf files — keeping external resources external — in the bundle would be within the vision of this plugin from my perspective, but isn't something I have bandwidth to work on right now. PRs would be welcome though!

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

No branches or pull requests

2 participants