-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support for public assets #14
Comments
Hi @leoncvlt! Not out of scope at all, but I think we'd need to decide whether using the
I am a bit worried that (1) not supporting hashing might create cache invalidation problems for users, and (2) leaving files in |
Ha I gotta confess that I'm definitely in the third point category, I just find it less verbose to write
rather than
especially when it comes down to projects with a lot of models which need to be loaded programatically, as in the former case I'd have to start messing with glob / dynamic imports. I don't really care about cache invalidation or the public files changing in filesize from development to the processed production version (I assume that's something users would be conscious of as they're installing the plugin), but I can see why it would be a concern for other users... |
Where should I place my models? I'm trying out the plugin in a SvelteKit project; I put the models in a subdirectory of the ...
const config: UserConfig = {
plugins: [
gltf({
verbose: true,
transforms: [
// remove unused resources
prune(),
// try to reduce poly count
weld({ tolerance: 0.001 }),
simplify({ simplifier: MeshoptSimplifier, ratio: 0.75, error: 0.001 }),
// combine duplicated resources
dedup(),
// effectively remove textures
textureResize({ size: [1, 1] }),
// center the models in the origin
center({ pivot: 'above' }),
// compress mesh geometry
draco()
]
}),
sveltekit()
],
...
};
... Note: I also tried reversing the order of the plugins, to no avail. |
The idea of static assets is that they're served as-is, without changes at build time. This plugin allows glTF files to be optimized at build time, so I think the result is that .glb/.gltf files will need to go somewhere under the src/ directory instead. In a typical SvelteKit project structure, and based on the asset handling guidelines, I think that location would be something like <script>
import sceneURL from '$lib/assets/scene.glb';
</script> Other frameworks may have different conventions though, I'm not familiar with Next.js for example. In any case, we should add some of this information in README.md. :) |
Thanks for the tip @donmccurdy... I'm trying to follow your suggestion but run into a mysterious error:
It's quite hard to google this sort of thing (I tried) and it point inside the If necessary I am happy to provide a minimal reproduction, but I thought I would first wait to see if you can see an obvious issue. |
It seems SSR was the issue. Here is a minimal reproduction, including the fix: https://github.com/seedling-life/sveltekit-gltf |
@ixxie Thanks for the added information - to echo @donmccurdy I wonder if this is worth a README section with framework specific caveats? and if so, would you be open to contributing a short blurb about Sveltekit? |
@juniorxsound something like this - #17? |
Great plugin! In most of my projects, however, I tend to store the 3D models in the
public
folder, which of course results in the plugin not picking up the files for optimization.I quickly created a proof of concept which works on those public assets - it consists of hookin up the
closeBundle
plugin function to recursively iterate through all files inside theviteConfig.build.outDir
folder, then filtering gltfs/glbs out and running the same transform functions, overwriting the files.It should be pretty easy to generalize the asset processing function in the plugin and have a flag in the plugins config to run that on
load
(for bundled assets) or oncloseBundle
(for public assets).@donmccurdy would such functionality be in the plugin's scope? If so, I'll start working towards a pull request.
The text was updated successfully, but these errors were encountered: