# Simplify, Reorder, Quantize and Compress: Meshoptimizer + Babylon Sandbox

**URL:** <https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034>\
**Category:** Demos and projects\
**Created:** [July 12, 2024, 10:07pm UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034 "2024-07-12T22:07:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 12, 2024, 10:07pm UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/1 "2024-07-12T22:07:11Z")

</div>

The GLB Optimizer now supports Meshopt Compression! - [https://glb.babylonpress.org/](https://glb.babylonpress.org/)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/9/89097c9ced43e2b47975c0c8b730db3c113bb625.jpeg)

Open Settings after uploading a model.  
The [Meshoptimizer](https://www.npmjs.com/package/meshoptimizer) part is here

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/5/b57d1d0efcc780c5ab793c1cf2465e09cc97545c.png)

**Simplify** - MeshoptSimplifier implements mesh simplification, producing a mesh with fewer triangles/points that resembles the original mesh in its appearance. The simplification algorithms are lossy and may result in significant change in appearance, but can often be used without visible visual degradation on high poly input meshes or for level of detail variants far away.  
The algorithm aims to reach the target ‘ratio’, while minimizing error. If error exceeds the specified ‘error’ threshold, the algorithm will quit before reaching the target ratio. Examples:

- ratio=0.0, error=0.0001: Aims for maximum simplification, constrained to 0.01% error.
- ratio=0.5, error=0.0001: Aims for 50% simplification, constrained to 0.01% error.
- ratio=0.5, error=1: Aims for 50% simplification, unconstrained by error.

The last option parameter, _lockBorder_, defines whether to lock topological borders of the mesh. May be necessary when adjacent ‘chunks’ of a large mesh (e.g. terrain) share a border, helping to ensure no seams appear and individual levels of detail can be stitched together later without gaps.

**Reorder** - Pre-processes GLB model to improve index and vertex locality which increases compression ratio before quantization and compression.

**Quantize** - Quantizes vertex attributes with `KHR_mesh_quantization`, reducing the size and memory footprint of the file. [KHR\_mesh\_quantization](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_mesh_quantization) extension will be added to the resulting GLB file.

If you want to apply **Meshopt Compression** there is no need to check reorder and quantize checkboxes (in order to avoid double quantization which may be too lossy). Reorder and quantize are already included into the Meshopt function (but one may use them separately as well, without Meshopt Compression).  
One may choose from 2 available Meshopt Compression levels: “high” and “medium”. [EXT\_meshopt\_compression](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_meshopt_compression) extension will be added to the resulting GLB file.

Both extensions, `KHR_mesh_quantization` and `EXT_meshopt_compression`, are supported by Babylon GLTF Loader.

More info about the [GLB Optimizer](https://glb.babylonpress.org/) and how to use it - [GLB Optimizer for Geometry and Texture Conversion (WEBP and KTX2)](https://forum.babylonjs.com/t/glb-optimizer-for-geometry-and-texture-conversion-webp-and-ktx2/47416)

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 13, 2024, 7:05am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/2 "2024-07-13T07:05:44Z")

</div>

I didn’t even know about this utility 🙂 Helpful one!

thanks!

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 13, 2024, 10:59am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/3 "2024-07-13T10:59:38Z")

</div>

Meshopt decoding is considerably faster than Draco decoding.  
It is also included into GLTF-Transform - [EXTMeshoptCompression | glTF Transform](https://gltf-transform.dev/modules/extensions/classes/EXTMeshoptCompression)

---

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [July 13, 2024, 4:26pm UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/4 "2024-07-13T16:26:25Z")

</div>

Does this implement ISimplifier and thus integrate into mesh.simpify() side-by-side with BABYLON.QuadraticErrorSimplification?

(I’m not intending to highjack your thread. I’m happy to split this into another thread if you prefer.)

Maybe I misunderstand mesh.simplify, but have observed that it (and the associated ISimplificationSettings) don’t seem abstracted enough to capture parameters likely needed with different simplify routines. In particular, a single “quality” number is passed and an optional “optimizeMesh” boolean is used to run (or not) a separate optimize function. I think there’s an opportunity to iterate on that abstraction if MeshoptSimplifier were integrated. In addition, ISimplifier does not seem conducive to being used outside of LOD given that LOD levels and distance are integrated/implied instead of attached after an abstracted simplification/optimization run. I had to go through some extra steps when using QuadraticErrorSimplification to clean up an imported mesh: instead of calling and reurning a mesh, I extracted the new optimized mesh from the existing meshes LOD (then disposed the original).

For reference: when QuadraticErrorSimplification is used separately, the following properties can be assigned after instantiating

- aggressiveness
- boundingBoxEpsilon
- decimationIterations
- syncIterations (number of parallel threads)

I don’t see a way to assign those through mesh.simplify, and the defaults don’t seem to work super well.

Edit: a good discussion, including extracting a simplified mesh from LOD is [here](https://forum.babylonjs.com/t/simplify-mesh-via-approximation-algorithm/27814).

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 13, 2024, 7:27pm UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/5 "2024-07-13T19:27:21Z")

</div>

> [@HiGreg](#):
>
> Does this implement ISimplifier and thus integrate into mesh.simpify() side-by-side with BABYLON.QuadraticErrorSimplification?

No, this algorithm uses WebAssembly module - [meshoptimizer/js/meshopt\_simplifier.js at master · zeux/meshoptimizer · GitHub](https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_simplifier.js) - and works much faster.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 14, 2024, 2:07am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/6 "2024-07-14T02:07:36Z")

</div>

@labris you should definitely put an “Apply optimizations” button somewhere (or the press R key info). 😛

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 14, 2024, 5:03am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/7 "2024-07-14T05:03:21Z")

</div>

@roland Yes, I think I’ll add some info about the ‘R’ key to the main screen in addition to the Help info.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/f/1fb815c751b82b53210e3195d628639a3a4514df.jpeg)

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [July 14, 2024, 8:21am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/8 "2024-07-14T08:21:43Z")

</div>

That’s great. Means we can now just do shit modelling, disregarding everything, and just run the tool 😂 I’d rather think some have already ‘anticipated’ this new feature 🤣

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 14, 2024, 9:47am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/9 "2024-07-14T09:47:41Z")

</div>

> [@labris](#):
>
> in addition to the Help info.

That’s where I found after a while of searching how to apply the changes 😛

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 18, 2024, 4:18am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/10 "2024-07-18T04:18:50Z")

</div>

@roland Here we are 🙂 - [https://glb.babylonpress.org/](https://glb.babylonpress.org/)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/f/6f1d5a3183c02dd973cfc9298fc644610fcf9500.png)

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [July 18, 2024, 4:20am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/11 "2024-07-18T04:20:28Z")

</div>

> [@mawa](#):
>
> we can now just do shit modelling, disregarding everything

Most of free 3D models are done according this principle 🙂

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [July 23, 2024, 10:49am UTC](https://forum.babylonjs.com/t/simplify-reorder-quantize-and-compress-meshoptimizer-babylon-sandbox/52034/12 "2024-07-23T10:49:46Z")

</div>

Last time I said this, I got bullied 🐂 😅 🤣  
I had to rectify: "

_Not all free models are (a piece of cr\*p). I believe - as in everything - 15 to 20% of them are at least “acceptable”; 5% are “good” and about 1 to 2% are “great”._

Essentially, I think when downloading a model or template - being free OR paid - one should not admit that this will save him/her from doing anything more 😁 As per my experience, 95% of the external sources I get/gather, require at least a level of ‘adaptation’, be it just ‘normalizing’ or making it ‘consistent’ for the use in my project.
