-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Best practices for .gltf / .glb #1117
Comments
Thanks for starting this thread. Lately I've started to think that end users should generally always prefer That said, a few apps still prefer It's too late to change now, but Anyway, regardless of the name, I think the self-contained binary form of glTF is going to win over the ecosystem in the long run. |
For desktop use and if you are concerned about editing and versioning, .gltf is a must. In fact, we found it to be bext used with one binary blog per mesh, so meshes are like textures. Obviously other apps will likely do it differently. |
Yes, exactly: During creation, editing (and possibly debugging) of the glTF, the Once the final, deliverable asset is finished though, the self-contained Certainly we need an easy path for users to convert one to the other. |
For 3D Tiles is also a must in my opinion. And in general where bandwith is a priority. |
I think .gltf more like for web and development stage. And .glb for final model which is for use in desktop and mobile apps. Basically the same as above. |
I think the |
Although I cannot speak for real users, there are several aspect that might be relevant for dicussing the "best practices", and maybe even affect of further development or recommendations. One of them is the "JSON refer other JSON?" issue, #37 , which has occasionally brought up. Somewhat related to that: I think there also was a discussion about the guidelines for external references in GLB in general, although the question is only relevant for images and buffers now, and not for other assets. The main point is: A GLB file is not necessarily self-contained. From just having a GLB, you never know whether it contains references to external data or not. Or should one of the "best practices" be exactly this recommendation - namely, to not have external references in GLB? (That would sound like a considerable restriction of use-cases for me...) |
It seems easiest and perhaps most important to suggest a best practice on what should be the default output of consumer applications, e.g. future tools like Sketchfab, Substance Painter, and Minecraft's exporter. For this case, I think a self-contained file is the essential thing, whether it's As a recommendation for developer workflows and final delivery, we should probably do some real-world tests before proposing something here. |
Servers could use transport-level compression on pure JSON We may also evaluate extending GLB with LZ (brotli?) compression of JSON chunk. |
@donmccurdy Valid points there. For developer/artist sanity a single Wondering how does texture re-usability works 🤔 If i have two models using the same texture, exporting the models as a separate |
Yes, unless common texture is stored separately (as an image file or as a part of shared binary buffer). |
In Substance Painter, as said, we are currently only exporting a Even if we are only exporting static objects, I think being able to directly export an 'engine ready' asset as a We should soon expose full control as |
Pardon the partial digression, but it seems to me that the importance of exporting on just the right format would diminish significantly if there were a dependable, free, swiss-army-knife type utility that could convert omnidirectionally between format variations. It could be npm-installed locally for lightning fast execution, or in the cloud (for tiny amounts of money) for convenience. The most obvious candidate would seem to be https://github.com/AnalyticalGraphicsInc/gltf-pipeline, but I'm not sure a web-based GUI is on their roadmap? Anyone else? |
A big +1 @zellski . Af course, such a tool should definitely exist. But still, the questions about file sizes, number of requests etc. are still relevant, and the answers not obvious. There should probably be an overview about the pros/cons of each representation for each application case. Somehow off-topic, regarding the conversion tool: One important question regarding this conversion utility is the one that you already referred to, namely the form of delivery and availability. I think some sort of standalone executable would be nice, to be used in at the command line or for batch processing. But it could also expose the command-line functionality via a trivial interface so that it could be used as a library. A broader question would be about the form or feature set of this tool. I think that there may be different levels of granularity to answer the question of what should be exported how:
(just examples, different combinations may be possible). Some of these conversion options are already covered in the gltf-pipeline, but others are not yet direclty supported (by any tool, as far as I know). The most fine-grained export options might look a bit complicated, though... I already considered to wrap a small GUI like this around some of the https://github.com/javagl/JglTF libraries, and will probably give it a try when I have some more time. But the gltf-pipeline would be the better candidate for an official solution, due to its broader community support. |
Once glTF-pipeline fully supports glTF 2.0 (progress), it should be very possible to make a drag-and-drop web-based tool, or an Electron desktop GUI, for doing the conversions. Could be very handy. :) |
Just a short cross-reference that I just stumbled over - the Best Practices section of the pbrSpecularGlossiness Extension :
We should be careful to not make toooo contradicting statements here: Including both in a GLB may cause it to become prohibitively large. |
🎉 UPDATE 🎉 The VSCode extension got an external contribution in AnalyticalGraphicsInc/gltf-vscode#35, and now includes a command to export the glTF file you're editing to GLB format. Currently, this export includes an implicit bundling of all external references to embedded GLB chunks, which I think is not unreasonable for most use cases. I'm exited about this one if you can't tell. 😃 |
I wanted to give a big +1 to @emackey 's comment on “end users” (not developers or technical artists) only seeing a self-contained .glb file especially when interacting with it as a file on disk. I would strongly encourage any tool or service exporting .gltf also provide a self-contained .glb export option. It will be lot easier for end users to learn to view and share a single .glb file. If your tool is already writing out a .gltf it should be quite straightforward to package that out into a self- contained glb. The .glb export by @najadojo for VSCode extension is a very good starting point if you are looking for examples on how this can be done- https://github.com/AnalyticalGraphicsInc/gltf-vscode/blob/master/src/exportProvider.ts |
On our side, it will obviously make sense to export |
@AurL That animated Swiss Army Knife from your second link is amazing. |
Good point we need more debugging tools around glb :). The recent vscode extension update is quite useful in breaking apart a glb for editing/debugging. Curious to know if there are any other requirements? |
Nice! Update: I hope the VS Code 5MB size limitation will be configurable soon, since it's not possible to inspect most of the |
Back to the gltf fun after few months client work. I've started work on the .glb exports. Now, next is to embed the images... on the doc I could find, for images embed, its a bit unclear how I need to define the pointer that replaces the previous "uri" to the alternative that points to the images chunks... Me naive, I was expecting something logic and simple like {chunk:2, mimeType:"image/jpeg"} Short story, as its not the expected to me, could someone tell me how do I replace the uri to point to the chunk and/or a ref where this is described? thx! |
@Fabrice3D BIN chunk from GLB is represented by |
(Cont.) For one-file delivery, all bufferViews (both with geometry and with image data) must point to the same |
Also, its not necessary to add padding per image then no? |
I think you're confusing some interrelated concepts (while criticising them, which is a weird). You can use one or more buffers, although if you are building a GLB you are best off sticking with the "freebie" one you get from there. I would stop talking about 'chunks' entirely, as that's specific to GLB creation and you will almost always just have two: JSON and the binary one. For GLB creation you typically just slam everything into your one buffer. It's a complete jumble of data. That's why there are BufferViews. They are just views into the Buffer jumble that start at a given offset and have a certain length. Once you've copied your binary image data into the main Buffer one, and configured your new BufferView to point at the right position, you're good to go -- just reference the view it much as you yourself suggested above, except not with chunks -- more something like All BufferViews need to be 4-byte aligned within the Buffer, yes. |
Not necessarily. If one puts all images after vertex buffers then each image don't have to be aligned. |
Really! Huh. My apologies. (Though I think I'll continue to do it in my own code.) |
Its not a critic, as said, I see the wish to be consistent. As I followed the doc to add each images, I was expecting the strategy to first isolate the json, bin and "images"/rest, as they are stored in logical order, when I load a glb, I have these "images" already separated, simply because you must first extract the json and the bin, so continuing to isolate each parts is logic to me. From this logic, I do no need again to look at buffer views, to get the offset and extract the data, I have them already. In fact, while the exporter will define this, my parser would totally skip that part. |
Ok, followed @zellski advise, and added the images to the bin vs add a new buffer. As I've added the "injection" of the images bytes to the exporter routine. I wonder if need to keep the type and componenType. |
@Fabrice3D |
Also, you don't need to create accessors for images, since |
As usual thx for the fast reply @lexaknyazev ! |
Validation report above shows that an asset refers to |
you mean this? where uri should be something else? |
ah ok... now validator gives me this: now the "image.bufferView refers to bufferViews directly." part... |
Just to be sure, when parsing the glb, the bufferViews.byteOffset are expected to be counted from 0 as in external .bin case or from 12 bytes header + (0x4E4F534A ) json.length? |
From |
ok thank you, so encoding both gltf and glb at same time, I do not need to offset their values for the glb version. I have a ACCESSOR_NON_UNIT error that I try figure out... all fine in regular gltf export. |
Probably, that's because you didn't validate |
if I drop the gltf , no errors. The glb file only gives the errors. |
Are you dropping both |
ah a secret feature! :) I do get the same error now. I can load the gltf file in my app and just tried loading it with threejs, no prob either. All displays fine. What can it be?? |
If it's helpful, here is a glTF chatroom: https://gitter.im/KhronosGroup/glTF 😅 |
thx @donmccurdy. joined. |
@lexaknyazev, was caused by length != 1 of normals. Added a routine to check them, all fine now. thx! |
we in the company use gltf + assets + webpack loader to CDN. webpack parse gltf and get links to assets. upload it to CDN and add hash to name. then we add presistent cache for this assets. if we change one small thing in our scene. all assets load from browser cache, cuz name change in only in one asset. we also use http2, and loading multiple files in parallel speeds up overall scene loading. 2020 year =) |
I haven't been able to come up with any concrete recommendation here except that "glTF Embedded" (with Data URIs) should be avoided. Both "glTF Separate" and GLB work well, and different users seem to have fairly different preferences about the performance and ergonomics of each, e.g. for sharing textures across multiple files. I'd like to see us more aggressively trying to discourage "glTF Embedded" (e.g. remove its output from Blender and glTF-Pipeline?), but other than that I don't think there's a clear need for more messaging. |
Documentation for when to export/import .gltf / .glb for different types of apps, e.g., desktop vs. web, consumer vs. developer, etc.
Not 100% sure where this should live but it should be easily discoverable. Perhaps an implementation section in the spec. Or maybe also a glTF Tutorial.
CC @sbtron
The text was updated successfully, but these errors were encountered: