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 gltf.openGlbFile #222

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ousttrue
Copy link

This pull request implement #218.

I was able to implement a glb preview by manipulating the offset so that the buffer view references the glb's bin chunk.

context_menu
context_menu

open_glb_directly

@ousttrue
Copy link
Author

ousttrue commented Jun 4, 2021

inspect_image

Implement inspect image in glb !

@emackey
Copy link
Member

emackey commented Jun 16, 2021

Oh wow, this got buried in my GitHub notifications overload, but it looks impressive, thank you! I'll try to get this reviewed soon.

@bghgary if you or a coworker would be willing to take a look, feedback welcome. Thanks!

@emackey
Copy link
Member

emackey commented Jun 17, 2021

@ousttrue This is pretty amazing, thank you. I do have a concern about one aspect of the new behavior here: "Save As."

When you load a GLB file, it shows the JSON portion of the file in a read-only editor. But if you click "Save As..." on that read-only editor, it will save the JSON only to a new file. The new file is likely to have a .GLB extension with JSON-only contents, which is not good, and the new file will be missing all of the mesh, textures, and other binary data from the original GLB file, which means it's invalid regardless of which file extension it uses.

Is there any way to control the behavior of the "Save As" function here? Or could we somehow avoid opening the text editor at all, and just show the 3D preview window, or show an option to run the GLB to glTF importer on it? I'll think about all this more too, but if you have any ideas on this I'd be eager to hear.

@ousttrue
Copy link
Author

@emackey Since GlbProvider supplies json chunk of glb, I added ".json" to path to make it clear that the content is json.
And rename GlbProvider to GlbTextDocumentContentProvider.

@ousttrue
Copy link
Author

Add .json suffix to real source glb path.
The virtual text document uri is glb:_path_to_glb_.json

glb json

Being able to view json chunks without importing gltf from glb is useful when looking at the contents of glb.

@bghgary
Copy link
Contributor

bghgary commented Jun 21, 2021

@bghgary if you or a coworker would be willing to take a look, feedback welcome.

I probably can't review this any time soon, but I will put it on my list :-)

@johschmitz
Copy link

johschmitz commented Oct 5, 2022

@emackey Since there is no recent activity I am going to ask this: Is there any chance of this ever being merged so that we can easily look at .glb files exported from Blender?
Also "open GLB" sounds a bit confusing, maybe it should be called "preview GLB".

@emackey
Copy link
Member

emackey commented Oct 6, 2022

While I love the ease of GLB previews here, I'm very concerned about giving users a writable (after Save-As...) copy of the raw JSON from within the GLB itself.

Most users don't know or realize that the JSON in a *.glb is subtly different from the JSON in the corresponding *.gltf that one might get from the "Import from GLB..." function. For example, all of the texture images (PNG, JPG, etc.) are embedded in the binary chunk of the GLB, and the JSON references their bufferViews and byteOffsets and such that are only meaningful for that one instance of the bin chunk, instead of referencing external URIs. There are other changes too, and the glTF Validator can't make any meaningful evaluation of raw JSON that has been separated from its corresponding GLB bin chunk.

If users really want to examine and possibly edit the JSON document, they should really use the "Import from GLB..." option instead of this, so they receive a valid glTF as an editable file, that the glTF Validator can confirm. They can then use "Export to GLB..." when done hand-editing, which will will produce a new valid GLB file, unlike what might come from hand-editing the JSON directly in a GLB.

Maybe there could be a read-only GLB 3D preview that doesn't show the JSON, but offered the "Import" button as a way to get the valid JSON? That preview is really great, but users are going to shoot themselves in the foot if we give them raw GLB contents that haven't been properly imported.

@johschmitz
Copy link

@emackey how about you just combine the two steps you suggest (1. Import, 2. Preview) in a single convenience command. Also when doing so you can just open the resulting. gltf file in the editor without storing it (if that is possible). So the user does not have to deal with deleting that temporary copy or having another file with the same name accidentally overwriten. Then if he DOES decide he wants to save it he can still press Ctrl+S on it.

@emackey
Copy link
Member

emackey commented Oct 6, 2022

It's a good thought, but the process of importing writes multiple files to disk. The JSON alone could be an unsaved preview, but it needs to have a relative path to a saved .bin file and relative paths to PNG / JPG / KTX2 texture files that were extracted from the GLB's bin chunk.

There's actually a way to base64-encode all that into the temporary unsaved JSON, but for real-world models the resulting hunk of text is too large for VSCode to offer in its text editor window. Saving those data files to disk, and referencing them using relative URI paths in the imported JSON, is the only reliable way to import a GLB into an editable window.

@johschmitz
Copy link

Can't you write all or some of the files to tmp maybe?

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.

4 participants