Removing KHR_mesh_quantization #233
-
Asked in the three.js repo, how can you remove the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Should be something like... // remove_quantization.js
const { NodeIO } = require('@gltf-transform/core');
const { KHRONOS_EXTENSIONS } = require('@gltf-transform/extensions');
const io = new NodeIO().registerExtensions(KHRONOS_EXTENSIONS);
const document = io.read('input.glb');
const root = document.getRoot();
const tmpAttr = document.createAccessor('TMP');
// Replace int8/int16/uint8/uint16 attributes with float32.
for (const mesh of root.listMeshes()) {
for (const prim of mesh.listPrimitives()) {
for (const semantic of prim.listSemantics()) {
const attr = prim.getAttribute(semantic);
if (attr.getComponentSize() === 4) continue;
if (semantic.startsWith('JOINTS_')) continue;
// Create identical tmp attribute with float32.
tmpAttr.copy(attr)
.setNormalized(false)
.setArray(new Float32Array(attr.getArray().length));
// Copy data to tmp attribute.
for (let i = 0; i < attr.getCount(); i++) {
tmpAttr.setElement(i, attr.getElement(i, []));
}
// Merge changes back to original attribute.
attr.copy(tmpAttr);
}
}
}
tmpAttr.dispose();
// Remove KHR_mesh_quantization.
root.listExtensionsUsed()
.find((ext) => ext.extensionName === 'KHR_mesh_quantization')
.dispose();
io.write('output.glb', document); And then run the script with If quantization was applied with certain tools, the model might have
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the code. I actually do have The resulting model has some objects at very different scales in comparison to the original. Any idea? |
Beta Was this translation helpful? Give feedback.
Should be something like...