AnalyticalGraphicsInc / gltf-vscode

This is an extension for Visual Studio Code to add support for editing glTF files.
Apache License 2.0
441 stars 61 forks source link

add gltf.openGlbFile #222

Open ousttrue opened 3 years ago

ousttrue commented 3 years ago

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 commented 3 years ago

inspect_image

Implement inspect image in glb !

emackey commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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