brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
822 stars 105 forks source link

feat : ✨ resolve [TODO] - provide file size of imported mesh #219

Open slash9494 opened 2 years ago

slash9494 commented 2 years ago

Hi @brianzinn while I use model's onProgress or sceneLoader.Context's progress, I found an unresolved TODO feature that loads a correct file size

So, I resolve this in a simple way let me show you the before and after video

before it was modified, GUI progress had not correct length and not the total length ( written as 10000) when importing asset file

https://user-images.githubusercontent.com/70849655/164709710-99a56d35-32d2-4ff9-9565-04349cfb3e99.mp4

and after modified, GUI progress run correctly

https://user-images.githubusercontent.com/70849655/164709833-ccb4d7e5-22d8-4316-a941-0d1e517b723a.mp4

if there is any issue, please let know me

brianzinn commented 2 years ago

hi @slash9494 It's definitely a pain when the file size isn't known and you want to show the progress. Are you downloading the entire file (await fetch ...) to get the file size? Can you perhaps share the calling code as it's not quite clear how this works - thanks!

slash9494 commented 2 years ago

yes, what i tried to do was to get entire file size from local asset path

I thought it was unusual to import large files from a local environment But, I tried to test with a file that has size as big as possible

So,I tested with two files one of them is from gltf-sample-models https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/MosquitoInAmber/glTF-Binary

and another is from sketchfab https://skfb.ly/o6vrn

on storybook, i just change baseUrl of ScaledModelWithProgress with localUrl

스크린샷 2022-04-25 오후 1 47 55 스크린샷 2022-04-25 오후 1 48 28

so, in useSceneLoader ,the below code is executed

스크린샷 2022-04-25 오후 2 06 16

and I figure out if sceneFilename of ScaleModelWithProgress is not declared, the above code does not execute so, i commit one more for this with catching error

brianzinn commented 2 years ago

Sorry @slash9494 I still do not follow. Are you not downloading the asset twice by fetching again in the callback?

slash9494 commented 2 years ago

yes, you're right. the previous way was not good enough. so I fix a little bit more

I change cache control of fetching for getting file data from disk memory So after requesting a file in sceneLoader.importMesh, if that is a static asset file, load from disk-memory inonProgress without any request

스크린샷 2022-04-28 오후 5 51 49 스크린샷 2022-04-28 오후 5 52 03

I feel that this way would be better

brianzinn commented 2 years ago

Ok - I’ll need to check how it runs after my vacation - May 16. I just need to see if on the first try it will load twice. Otherwise it would need to be an opt-in mechanism - also Babylon.js has built-in caching if you are continuously loading same mesh.