Webgl_modifier_simplifier error

hi,

i am trying to use webgl_modifier_simplifier but i am receiving the error

Cannot read properties of undefined (reading 'hasVertex') at collapse (SimplifyModifier.js:362:21)

the model i am trying to simplify does not have uv’s but the geometry seems to have been indexed ( .glb exported from blender ) i have also tried with other models which have been uv’d and the modifier works great.

would anyone happen to know why i’d be getting this error with certain .glb models and would it be related to the uv’s?

thanks for your time.

Do you mind sharing the glb file that produces the issue?

yes, here’s some parts of the model
test_06.glb (2.6 MB)

EDIT:

i have tried exporting the meshes outside of their parent null objects and it seems to work but i need to keep the entire tree heirarchy before hand,

the issue arrises when i import the file i shared, traversing the imported scene, extracting only a clone of child.isMesh, applying the parent matrices to preserve orientation and position, this process is somehow causing the above error when then trying to use { SimplifyModifier }

Hi @Mugen87

also i’ve found that even without the use of { SimplifyModifier } this model does not respect the binary encoding option when using GLTFExporter it’s likely a bug with the original exporter which i think was possibly a primitive cad to gltf type thing…

would you happen to have any other suggestions than using a 3rd party program to manually un-nest these parts of the glb?

Hey @Mugen87 did you happen to get an insight as to why this may be happening with the model in question?

I got same problem with you… did you handle it?

code:

if (mesh instanceof THREE.Group) {. //mesh from gltf.scene
    mesh.traverse((child) => {
      if (child instanceof THREE.Mesh) {
        const modifier = new SimplifyModifier();

        const simplified = child.clone();
        simplified.material = simplified.material.clone();
        simplified.material.flatShading = true;
        const count = Math.floor(simplified.geometry.attributes.position.count * 0.875); // number of vertices to remove
        simplified.geometry = modifier.modify(simplified.geometry, count);

        simplified.position.x = 3;
        simplified.rotation.y = -Math.PI / 2;
        scene.add(simplified);

error :

SimplifyModifier.js:255 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'hasVertex')
    at collapse (SimplifyModifier.js:255:1)
    at SimplifyModifier.modify (SimplifyModifier.js:86:1)
    at lod.ts:17:1
    at Mesh.traverse (three.module.js:5469:1)
    at Group.traverse (three.module.js:5473:1)
    at Group.traverse (three.module.js:5473:1)
    at meshToLod (lod.ts:9:1)
    at noInstancing (importgltf.ts:59:1)
    at importgltf.ts:36:1
    at GLTFLoader.js:78:1

Hi, no no one helped with this, was awaiting some reply from @Mugen87 but alas, I found a hack work around by removing that line from the modifier code

Copied post from @aswwwcom

Hi

Now I’m making code for web 3d world viewer. I want to make lod system for my world and for that, I have to use simplify modifier for this.

Anyway, when I use simplify modifier to simplify gltf model it shows error with this

SimplifyModifier.js:293 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'hasVertex')
    at collapse (SimplifyModifier.js:293:1)
    at SimplifyModifier.modify (SimplifyModifier.js:99:1)

I spend lot of time to search about it, but I can’t find the hint

So I console log it to find out what happen to simplify modifier and I think this might be reason.

I console log this loop

  for (let i = u.faces.length - 1; i >= 0; i--) {
    console.log(u, i);
    if (u.faces[i].hasVertex(v)) {
      removeFace(u.faces[i], faces);
    }
  }

I found that when removeFace function run, it sometimes remove two faces at one loop. As you can see in picture above, first length of u.faces.length = 8, and value i = 7, at second loop u.faces.length = 6, and value i = 6 this cause error.

Is it okay with just add if (!u.faces[i]) continue; in for loop?
it seems running but I think it work not propery.

Sorry, it took a while to have a look at this issue.

However, I can confirm this is a bug in SimplifyModifier. @aswwwcom’s hotfix seems to work as expected. However, a separate if statement is not necessary. It can be written like so:

if ( u.faces[ i ] && u.faces[ i ].hasVertex( v ) ) {

Of course it would be better to figure out why the modifier runs into this exception and avoid it in the first place. However, the additional check u.faces[ i ] seems appropriate to me.

@aswwwcom Are you interested in making a PR at GitHub with your fix?

4 Likes

Okay! I’ll put it and I’ll PR for it!

But some how the meshdeleted with message THREE.SimplifyModifier: No next vertex

What do you mean with “meshdeleted”? Does it not appear on screen after the simplification?

I think the no next vertex error is when the threshold value is too high, try 0.1

1 Like

yep It was. threshold is too high and some mesh are deleted

@Mugen87 It was just about the threshold :slight_smile:

Anyway I make the PR for that Thanks for your advise!

1 Like

I came across with same error the hot fix worked for me as well but did not get the threshold part could you explain more this part @forerunrun @Mugen87 @aswwwcom
advanced thank you