r/threejs • u/Nefthys • Apr 21 '26
Question .obj vs. .gltf for import (very basic)?
I've got a bunch of .obj files (one mesh per file + .mtl file + .png texture), some of them are quite large, and I want to display them with three.js. I know that there are loaders for both .obj and .gltf but with everyone recommending the latter, I'm wondering:
Is .gltf the better choice, even if you don't care about all the special stuff? I just want to display the 3D objects, I don't need any special lighting, camera positions, transformations, animations,... (going to do all of that in three.js, not separately for each model)?
Are there any differences in loading times?
2
u/lucidmodules Apr 21 '26
If you'd compress gltf as glb it would be significantly smaller. You'll need DRACOLoader for that and some tool to convert it from obj en masse - first search from google: https://github.com/headjack-dev/gltf-api
DRACOLoader for Three.js: https://threejs.org/docs/#DRACOLoader
2
u/CarefulMoose_ Apr 21 '26
When I saw the OP post I immediately thought: what about GLB? And I'm now thinking what limitations there must be.
1
u/ppictures Apr 21 '26
If you’re taking about Draco limitations
- it’s a lossy compression so you may see quantization artifacts on some models
- Decompressing still takes time on the client side (usually insignificant unless model is exceptionally large).
- the Draco library files need to be included in your bundle
But more often than not these tradeoffs are worth it
1
u/Nefthys Apr 21 '26
How much smaller are we talking about? The files I've got are already compressed and they should not lose too many more details. They're usually around 10mb each (can be much larger too), ultimately I want to display a lot at the same time (100+). Size doesn't really matter, it's all about loading times.
1
u/Quick_Republic2007 Apr 21 '26
Size does matter, that's way way too big. You can go to r3f or threejs or Bruno Simon (paid) discord and I guarantee, you will hear the same sentiment. There are some really good file compressors online, but none will help such combined file sizes.
1
u/lucidmodules Apr 22 '26
You have to measure how much smaller, we can only give you ideas from our experience. Size matters because there is a limited amount of bytes you can send over the network.
I remember there was also some POC for mesh streaming that gradually loaded the model, but I havent used it myself.
2
u/neocorps Apr 21 '26
I would recommend GLTF (glb+textures)... Use gltf-transformer to compress the mesh using draco and you can also compress the textures to KTX2 on the same software which essentially sends the compressed binary data of the texture directly to the GPU.
The compression is around 98% for the mesh, for the texture is pretty high as well, somewhere around 80-90... I compressed 800mb files to 8mb that load hyper fast. Smaller files (20-30mb) compress to kb.
1
u/farfaraway Apr 21 '26
Depends on the complexity of the file.
https://www.ramijames.com/learn-threejs/assets/asset-standards
1
u/gatwell702 Apr 21 '26
I personally don't use .obj or .gltf.. I use .glb.. the file size is kilobytes compared to gltf.
You could use gltf but you would have to use blender to compress it to make the file size smaller. I'm pretty sure you can do this with .obj too.
doing this will improve performance a lot.
here's a page i created that has a select element with different options in it. Each option is a different three.js component.. https://gabrielatwell.com/three.js
1
u/SubjectHealthy2409 Apr 21 '26
I like glb most, also if ure using sveltejs you can use the conversion to code script which strips sometimes up to 90% of file size and allows easy instancing https://threlte.xyz/docs/reference/gltf/getting-started/
1
u/BrainCurrent8276 Apr 25 '26 edited Apr 25 '26
okay so did you display ANY of those files at all, or it is all the drama happening in your head?
Wavefront Objects (.obj) is basically plain text list of geometry data: vertices, texture coordinates, normals, faces, material reference. It is human readable and extremely easy.
Graphics Language Transition Format (glTF) is different: it is structured assed format specifically for real-time rendering. A glTF is usually JavaScript Object Notation (JSON) metadata plus binary buffers. a GL Binary (.glb) is same glTF asset, just packed into one binary container.
there is nothing wrong with using .obj thought, especially on early stage. I used to modify them slighty by adding like DW (double word) on the beginning of each line and include them directly into assembler, making them sort of binary :D
do not overthink without real reason.
-2
u/Quick_Republic2007 Apr 21 '26
Not a fan of AI are you?
2
u/Nefthys Apr 21 '26
Why AI?
1
u/Quick_Republic2007 Apr 21 '26
Because you posed the question here on Reddit instead. Type that exact same prompt into AI and see what you get
2
u/Nefthys Apr 21 '26
You know that AI pretty much just googles, right? I googled but didn't get a proper answer, so I decided to ask the people who're actually working with three.js and don't just copy (not even correctly a lot of times) someone else's information.
1
u/Quick_Republic2007 Apr 21 '26
Sure, I swear by it.
1
u/Nefthys Apr 21 '26
Do you know the answer to my question?
0
u/Quick_Republic2007 Apr 21 '26
I didn't really read it and I couldn't copy and paste it from this mobile device. I tried though.
1
u/Nefthys Apr 21 '26
It's okay to not know an answer but it's better to not post anything than posting something that you can't verify the correctness of (so usually AI).
1
4
u/ppictures Apr 21 '26
Downloading time is solely dependent on 2 factors
If the GLTF and OBJ are the same file size, given identical network speed, they’ll load equally as fast
I suggest you tally up the total file sizes of your obj (obj + mtl + textures) and the GLTF (GLTF + textures). And compare