SimplifyModifier not working, breaking the geometry and removing the materials

Hello everyone.

I’m trying to apply A SimplifyModifier to an object, but when I applied the mesh goes crazy and gets all the materials removed.

Plus it does not apply any modifier to the mesh.

Pink avatar = Original
Black avatars = SimplifyModifier applied

This is how I’m trying to do it:

gltfLoader.load("avatar.gltf",(obj)=>{
    const model = obj.scene;
    model.traverse(  ( child )=>{
        if ( child.isMesh ) {
            const modifier = new SimplifyModifier();
            const count = Math.floor(child.geometry.attributes.position.count * 0.7);
            child.geometry = modifier.modify(child.geometry, count);
            child.material.envMap = envTexture;
        }
    });
});

What else have I tried?

  • To create a new THREE.Mesh() with the simplified geometry, instead of replacing it and assigned it to the original structure. But same behaviour happens, it does not get modified and it becomes material-less.
  • I tried to apply this same modifier to a much simpler mesh, because I thought that it could be a problem using a SkinnedMesh. But same behaviour happens, it does not get modified and it becomes material-less.

What could I be doing wrong? Am I missing something?

Thank you in advance.

1 Like

Where are you getting the SimplifyModifier from? My guess is that it’s outdated, and it’s expecting a legacy Geometry object, but GLTFLoader outputs a BufferGeometry object.

Nope. I’m using the SimplifyModifier from the latest release. Which is already using BufferGeometry.

Here is the link: https://threejs.org/examples/jsm/modifiers/SimplifyModifier.js

I added

child.material.flatShading = true;

And now I can tell that the Modifier is working, but it does not keep the Materials, nor weights.

I’m reading how the SimplifyModifier works and it seems it only works for the position attribute of the vertexes?

// this modifier can only process indexed and non-indexed geomtries with a position attribute
for ( const name in attributes ) {
     if ( name !== 'position' ) geometry.deleteAttribute( name );
}

So it basically removes all data information about: normal, uv, color, skinIndex, skinWeight

Is this due a constraint issue? or just lack of time to add full-support to the modifier?

1 Like