Memory calculation before loading the model

Hi Guys,

We have a viewer which loads the large number of meshes in it.
As a solution to that, We are using some mesh reduction algorithm.
But before loading the model to the scene we have to calculate the memory consumption it will cause after loading the model.

We are already using buffergeometryutils.estimateBytesUsed, But this only returns the geometry memory not the whole object.

Is there any way where we can pre-calculate the memory required to load the model?

Akash B

Have a look at THREE’s LoadingManager, what you’re asking is pretty difficult without making some sort of custom XHR request, have a look here

1 Like

This is partially a Three.js question, and partially a Javascript one. While @forerunrun answer is excellent to find the size of things like loaded resources like images, videos, audios, if you attempt to find the entire size you might want to add the values given by the .length of a JS object (see here, here or here, and bear in mind that Three.js objects are basically JSON ones, they can be stringified and accounted for) to the already mentioned geometry and resource values. If you’re talking about GLTF models, here is what such a structure is made of. This matches the stucture and approach for “normal” (i.e. non GLTF) objects, since you have the same 3 components:

That being said, you’d normally get the actual values only after the said object is created. Maybe a better idea would be to not try to precompute things, but add to the scene based on whether the total size of the already existing objects is below a certain threshold… :thinking:

1 Like

@forerunrun @Yin_Cognyto

Thanks for the quick reply guys.
It seems the better idea would be to put the object count or memory below the some certain threshold just like @Yin_Cognyto mentioned.

Well, I don’t like the word impossible, but let’s just say it’s difficult to find out how much memory would use an object that doesn’t yet exist, so, if rough estimations are not enough, then doing it after the object exists via the threshold approach seems more logical.

In case you didn’t yet check them out and they help with either getting the values or verifying if they are the correct ones, take a look here or here, maybe they’re of some use, in addition to inspecting things via Chrome Dev Tools.

1 Like

Yes, I agree with you
I’ll try the dev tools.

Akash B

Keep in mind that the size of textures in GPU memory is much larger than their size as files and on disk. In many mobile devices, GPU and CPU memory are shared. To compute the size of PNG, JPEG, or other non-specialized image formats in GPU memory, you can use the expression:

memoryByteSize = width ⨉ height ⨉ 4 ⨉ 1.333

The 1.333 factor accounts for mipmaps.