BufferGeometry mesh simplification in Three.js

Hi

I am trying to simplify the geometry of child objects when loading a .glb file using the reference link below.

The example using TorusKnotGeometry from the link works fine. However, it doesn’t work with the .glb file I’m using.

The link suggests using ‘gltf-transform weld input.glb output.glb’ to index the shape, but I used ‘npx gltfjsx [Model.glb] -T -S --weld’ to create the model.

Is it correct?

여기

여기

this.scene.add(this.loadedModel);


            this.loadedModel.traverse((child) => {

                if (child.isMesh) {

                    let geometry = child.geometry;
                    let dstGeometry = geometry.clone();

                    const srcIndexArray = geometry.index.array;
                    const srcPositionArray = geometry.attributes.position.array;

                    const targetCount = 3 * Math.floor(0.1 * srcIndexArray.length / 3);

                    const [dstIndexArray, error] = MeshoptSimplifier.simplify(
                        srcIndexArray,
                        srcPositionArray,
                        3,
                        targetCount,
                        0.25,
                        ['LockBorder'],
                    );

                    dstGeometry.index.array.set(dstIndexArray);
                    dstGeometry.index.needsUpdate = true;

                    dstGeometry.setDrawRange(0, dstIndexArray.length);
                }
            })

Welding / decimation simplification works by distance - these algorithms take no context into account and just combine nearby vertices- which doesn’t reduce the mesh size significantly most of the time. It’s really only useful for cleaning up meshes - not optimising them.

If you’d like to create simplified geometries of complex models, the most reliable way of doing so would be manually simplifying it in Blender.