Dos Posted April 25, 2018 Share Posted April 25, 2018 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 ! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 25, 2018 Share Posted April 25, 2018 If you used the text version of of glTF, then you could take advantage of gzip on the web server (may need to register extension). I might want to create a text version, then zip it to see if there is any gain. GameMonetize and Dos 2 Quote Link to comment Share on other sites More sharing options...
Dos Posted April 26, 2018 Author Share Posted April 26, 2018 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 ?) Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted April 26, 2018 Share Posted April 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Dos Posted May 3, 2018 Author Share Posted May 3, 2018 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 : zip the .gltf .bin and anything else you'd need like texture assets. 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) then extract the .gltf as a string and replace references to the assets by the extracted blobs 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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted May 3, 2018 Share Posted May 3, 2018 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. Dos 1 Quote Link to comment Share on other sites More sharing options...
Dos Posted May 3, 2018 Author Share Posted May 3, 2018 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 GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.