A lot of memory with GLTF

Hi!

I`m new on three.js I’m working with a GLTF models exported from blender. My model has size of 11MB.
Alfter load the model Chrome use under 80MB of memory, but its loaded Chrome use more than 700MB of memory, I tried diposed render, and model, but doesn’t work. Do you have any idea to reduce the memory ? Thank you!

Try using glTF-Transform CLI to run:

gltf-transform inspect my-model.glb

This will print the memory use of each mesh and texture in the model. The usual cause of this issue is that PNG and JPEG textures become fully uncompressed in GPU memory. The only way to avoid that is to reduce the resolution of the textures (unpack to separated .gltf, resize textures, repack to .glb), or to compress them using KTX2/Basis. glTF-Transform or gltfpack can do the KTX2/Basis compression for you, but it sometimes requires some tuning of the compression parameters to avoid compression artifacts.

5 Likes

Thank you! Now I’m fighting in the installations of the tools. Give me an opportunity to try it

Thank you very much for your tool!

I tried some models and encountered a problem that the SCENES table only show the first object, nothing else is displayed.
MESHS, MATERIALS, TEXTURES and ANIMATIONS works OK.

Simplest file:
a.glb (69.9 KB)

gtlf-transform inspect result:

1 Like

Oh, realised it’s SCENES table, is intended to just list the scenes and it’s first child, not hierarchy?

Yeah, it’s just listing the (top-level) scenes. Usually there will only be one, but there could be more. The name of the first child is included because sometimes that’s more useful than the name of the scene. But listing the entire hierarchy would be pretty long, so I haven’t included that in the printout so far.

1 Like

Hello @donmccurdy, it’s hard to read and sort informations in CLI, and copy-paste to Excel they’ll all in one tab-cell.
Is there a way to export something like Excel or csv file?

Is there a way to export something like Excel or csv file?

Not at the moment, but I like the idea as a feature request. Something like:

gltf-transform inspect house.glb --format csv > house-report.csv

Feel free to open a request on GitHub - donmccurdy/glTF-Transform: glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.. :slight_smile:

2 Likes

Or you could use the JS API to get JSON, already:

import { inspect } from '@gltf-transform/lib';
import { NodeIO } from '@gltf-transform/core';

const io = new NodeIO();
const doc = io.read('house.glb');

fs.writeFileSync('report.json', JSON.stringify( inspect(doc) ));
2 Likes

Hi! Need other advice. Do you know a tools that I can convert my texture from .jpg to .ktx2 ?
When I use GLTF-transform say this :
error: • Texture compression failed.
error: spawnSync toktx ENOENT
Thank you!

Could you report an issue on https://github.com/donmccurdy/glTF-Transform and share the file (or texture) that you can’t convert? gltfpack is another option, but both use the same library to convert JPG to KTX2, so I think the JPG might be using a compression feature that the compressor doesn’t support yet.

Even with .png is the same error. Yes, I’ll report

I try to use Basis Universal I understood that exist encoding for Desktop and Mobile, I use basisu to convert to .basis but just convert file form mobile version, Do you know a tool tu convert to .basis with BC7 encoding of the file?
By the other hand I see the example of basis and I see that just use one file and works fine for mobile and desktop, do you know the encoding? Or maybe the user Mugen87 know something about, I see that is a collaborator in this basis example and I see that is an active user. @Mugen87 can you help us ?
Thank you so much guys!

Do you know a tool tu convert to .basis with BC7 encoding of the file?

I think you’ve misunderstood – there are only two versions of .basis files, ETC1S or UASTC. They have different quality/size tradeoffs, ETC1S is smaller and lower quality. You load the .basis file on the device, and then THREE.BasisTextureLoader transcodes to whatever format the hardware needs, which could be BC7 or many others.

Did you see this example? It should automatically convert to BC7 if that is the most appropriate format for the hardware. Or there are low-level transcoders available specifically for BC7, but they are more advanced to use.

I think you’ve misunderstood

:sweat_smile: Thank you!

THREE.BasisTextureLoader transcodes to whatever format the hardware needs, which could be BC7 or many others.

I see, but do you know why when load textures in desktop load in dark ?

Oh I see, hm. No, I can’t say without looking at the demo and the texture. Can you share a demo?

If you can embed the basis textures in your glTF file it should handle a lot of things for you, but otherwise it can take a bit of understanding of compressed GPU textures to load textures this way yourself and deal with mipmaps correctly, etc.

Can you share a demo?

Yes, can you see the project here ?

If you can embed the basis textures in your glTF file it should handle a lot of things for you

Yes I’m afraid by the textures, I tried to use with blender, but I guess blender don’t support .basis. Do you know how I can embed the textures ? Do I have to do manual in the .gltf?

It’s strange because in the desktop load the skin (most biggest texture) and the hair, but in the mobiles devices just load the eyes and hair

Thank you!

I’d suggest making sure all textures are power-of-two dimensions, no larger than 2048x2048. The skin is an 8K texture, which many mobile devices won’t be able to handle. There are errors like this in the JS console that are important:

RENDER WARNING: texture bound to texture unit 0 is not renderable. It might be non-power-of-2 or have incompatible texture filtering (maybe)?

Blender doesn’t support basis textures, no. The CLI mentioned earlier in this thread can take a glTF file exported from Blender and convert it to a glTF file containing Basis (.ktx2) textures.

The CLI mentioned earlier in this thread can take a glTF file exported from Blender and convert it to a glTF file containing Basis ( .ktx2 ) textures.

But dosen’t work in my computer :frowning: Can you help me please ? Maybe you can help me with convert the gtlf files, I will find a way to reward you

If you’re having trouble installing it could you post details? I’d rather fix that if possible.

You’d need to resize the images either way I’m afraid, there’s no way around that at the moment.

Hi @donmccurdy,

I am working on glTF loader to load multiple files.
However, I am stuck in how to free up memory of the render.

Follow up here (https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects), I tried to dispose all geometry, texture and material whenever I change to load another models, but still have problem in render memory.

According to the first pic (for the 1st model), the render.info.memory.geometries = 15
But when I load the 2nd model (the second pic), the render.info.memory.geometries = 32
Actually the 2nd model only has 17 geometries and the 1st model has 15 geometries.

Thanks,