Jump to content

Load a zip containing a glb file


Dos
 Share

Recommended Posts

Hey,

I'm currently successfully loading glb files through the `BABYLON.SceneLoader.ImportMeshAsync('', rootURL, filename, scene)` method.

I was wondering if (for loading times) it was possible to import meshes from a zip file containing the glb one.
I could unzip and get the GLB file but, all I have is it's content but not its path.

Is there a way to provide ImportMesh or ImportMeshAsync the content to load instead of its path ?

Thanks in advance !

Link to comment
Share on other sites

Thank you for your help. I'll try that too but is there any reason why we can't provide any asset directly instead of its path ?

(BJS seems to obviously doing that under the hood so is there any shortcut to provide the glb content in the first place ?)

Link to comment
Share on other sites

I do not know.  Time to dig into the source, and look for a door, or do a refactoring to serve as one. 

For the JSON (.babylon) text format, there is way to pass the actual data in the file url parameter.  Perhaps you could refactor for the glTF eqivalent, where ever that is.  One problem with that location is there may be code looking at the extension name, and deciding to branch.  If so, follow the trail.  Since reading a file is async, the processing will be in the callback code.  Perhaps the function in the callback can be called directly. 

Have fun, & good hunting.

Link to comment
Share on other sites

Thank you very much for your help. In fact, we switched back to glTF instead of glb and zipped all the assets required by the model.

For people landing here with a similar "issue", here's how I did this :

  1. zip the .gltf .bin and anything else you'd need like texture assets.
  2. I used JSZip to extract all assets. This lib offers a bunch of formats to extract files like 'string' and 'blob' (those were what I wanted)
  3. then extract the .gltf as a string and replace references to the assets by the extracted blobs
  4. and load the modified glTF simply with
BABYLON.SceneLoader.ImportMeshAsync('', '', `data:${glTFasStringifiedJSON}`, scene)

And voilà!

Bonus fact : The zipped glTF with assets turned out to be lighter than the zipped glb

Thanks again for your help :)

Link to comment
Share on other sites

For the .gltf itself, you can also just enable gzip on your server & make sure the .glft file extension is view as text.  The zip-unzip process is then done automatically.  Binaries / texture files do not really zip well.

Not surprised compressed .glft is smaller than .glb.  For Blender, I also let you pick # of significant digits by data type (positions, normals, UV, vertex colors, & matrix weights).  This makes things smaller even before zip.  I do not know why anyone else does not do this.  Seeing the difference of having more than 2 digits for matrix weights, or 3 for normals would require a microscope, but other exporters just spew out 8 decimals for everything cause they need to be "super accurate".  Muggles.

Link to comment
Share on other sites

Thank you for the advice. I like it the way it is now because the zip encapsulates all the assets I need avoiding possible 404 errors if one of these isn't findeable.

Il talk to the 3D artists providing me glTFs about decimals. I really didn't thought about that but seeing how geometry adds weight, this seems like an efficient and easy way to optimize !

Thanks again, this is so enlightening for me :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...