Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify breaks due to assertion failed #1263

Closed
wayne-wu opened this issue Feb 12, 2024 · 6 comments · Fixed by #1268
Closed

Simplify breaks due to assertion failed #1263

wayne-wu opened this issue Feb 12, 2024 · 6 comments · Fixed by #1268
Milestone

Comments

@wayne-wu
Copy link

Describe the bug

I'm running into a bug where gltf-transform simplify from the command line breaks with an assertion failed error.

Upon closer examination, it looks like this error is coming from this line here (from the meshopt simplify function):
https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_simplifier.js#L178 , where targetCount > indices.Length after one iteration therefore failing the assertion.

One thing I did notice from the example of simplify here: https://github.com/zeux/meshoptimizer/blob/master/demo/simplify.html -- it looks like the targetCount is calculated based on index count and not the vertex position count as used by gltf-transform. I'm wondering if this is intended, and whether that relates to the bug?

To Reproduce
I'm unable to share the model I was testing with, but I'll see if I can recreate the bug with another model.

Versions:

  • Version: cli.js 4.0.0-alpha.5 — Command-line interface (CLI) for the glTF Transform SDK.
  • Environment: Command line

Thanks!

@wayne-wu wayne-wu added the bug Something isn't working label Feb 12, 2024
@wayne-wu wayne-wu changed the title simplify breaks due to assertion failed Simplify breaks due to assertion failed Feb 12, 2024
@donmccurdy donmccurdy added this to the v4.0 milestone Feb 12, 2024
@donmccurdy
Copy link
Owner

Thanks @wayne-wu! Index count vs. vertex count sounds like a good guess on the cause. Perhaps happening when the source vertex attributes have many vertices, but the indices only use a smaller subset of those. The relevant code is here:

const targetCount = Math.floor((options.ratio * srcVertexCount) / 3) * 3;
const [dstIndicesArray, error] = simplifier.simplify(
indicesArray as Uint32Array,
positionArray as Float32Array,
3,
targetCount,
options.error,
options.lockBorder ? ['LockBorder'] : [],
);

I'll look into reproducing the issue without the model, but if you'd like to try making the change and then testing on the model yourself, it would look something like:

yarn install
yarn dist
node packages/cli/bin/cli.js simplify in.glb out.glb

Or yarn watch will continuously watch and rebuild the code as you're making changes.

@donmccurdy
Copy link
Owner

Fixed and published to 4.0.0-alpha.6. If you'd like to test that fix, you can use the @next tag, like npm install @gltf-transform/cli@next.

@harrycollin
Copy link
Contributor

I encountered this using @gltf-transform/functions@4.0.0-alpha.15 package in node.js.

@donmccurdy
Copy link
Owner

donmccurdy commented Apr 29, 2024

@harrycollin possible to share a reproduction? The tests I have are passing. Meshoptimizer may have assertions for any number of things.

@harrycollin
Copy link
Contributor

My mistake! It looks like I was passing undefined values to the ratio, error and lockBorder options.

@donmccurdy
Copy link
Owner

Ah, well that's a footgun! Should be fixed with:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants