I want to compress a GLB file with DRACO compression in React App using KHRONOS_EXTENSIONS
The following error message appears and I don’t know how to fix that. Thanks in advance.
gltf-transform is also a commandline tool. im guessing npxy @gltf-transform/cli optimize file.glb compressing a glb in a react app, hard to imagine what you’re trying to do unless this is a server component running under a node backend like next.
if you’re using react you can also just open your shell and type: npx gltfjsx yourmodel.glb --transform
The problem you will have with this code, though, is that the draco3dgltf package is built for Node.js. I wish they’d ship a browser build to npm, but for now you’ll need to grab the Draco dependency the old fashioned way:
i think with modern day react this is all possible now via rsc. i have yet to try but it should just work. the old limitations should apply no more, everything that runs under node should be available.
@drcmda What is rsc? I think the problem is how they’re compiling and packaging the Draco WASM decoder, last I checked it’s still a nightmare to build WASM for multiple runtimes and publish to npm…
In any case – I wouldn’t necessarily want to process a user’s 3D files on my server if i can do so on their browser. Huge difference in performance and security implications, if you’re just giving them back the output to download.
This is how https://gltf.report/ works – it’s statically hosted. Draco, Meshopt, and anything you put in the script tab will just run in the browser.
I moved above code to server side, there is no bug now, but gave the same size glb file, it seems that Draco compression did not work. I don’t know what happened in above code.
I tried to download the extension files and use them in React, it did not work.
The Draco compression of this website https://gltf.report/ is what I want to do. But I tested https://gltf.report/ to compress my glb file, the website also gave me the same size glb file after I clicked export button.
Could you share the model, or a screenshot of the “metadata” tab from glTF Report?
Draco compresses only mesh geometry – if your model is large for other reasons (textures, animation, morph targets) then you’ll have to optimize it in other ways.
Sure, please see the attached model and metadata. This is the model that I converted from dxf to glb, there is no textures, animation…, just vertex. I just want to convert dxf to glb then use draco compression to reduce the size then upload to S3. Everything is going well except for draco compression . Except for gltf-transform/extensions, what else technique can do draco compression? Thank you so much.
I’m noticing that the file’s UVs have type “VEC3”, which isn’t valid – this should be a “VEC2” attribute. In three.js that’s geometry.attributes.uv.itemSize. It’s possible that’s the cause, but on the CLI (running a more recent glTF Transform version) this does compress anyway, from 3MB to 94.45 KB.
Except for gltf-transform/extensions, what else technique can do draco compression?
I’m not aware of another in-browser implementation of Draco compression for glTF sorry!
Found the issue – Draco requires indexed geometry. The CLI indexes automatically when required, but the glTF Report site (and the code above) do not. I’ll push out a fix soon but in the meantime you can work around the issue like this:
import { weld } from '@gltf-transform/functions';
await document.transform(weld({tolerance: 0}));
That script can be run either in your code, or in the glTF Report ‘script’ tab, before exporting with Draco compression.
The UVs probably should still be VEC2 and not VEC3, but that seems unrelated to the compression question here.
import { weld } from '@gltf-transform/functions';
await document.transform(weld({tolerance: 0}));
I really appreciate all your help. It took me almost 3 days and nights, I tried lots of other methods and other techniques, but none of them works. Thank you soooooo much.
Thanks again for UVs problem. I will try to fix that.
a server component. React Labs: What We've Been Working On – March 2023 – React these blur the lines between client and server, they’re not part of the bundle and can execute tasks that traditionally run on the client, but they can also run on the server and handle rest requests or do anything that a traditional node service did in the past. if i had to set up an application that transforms glb’s i guess i would use rsc, it would be able to run these async gltf-transform functions right in the render function.