Code Monkey home page Code Monkey logo

Comments (2)

mikedh avatar mikedh commented on May 24, 2024

Oh interesting, I think what is happening here is:

  1. Mesh in question has some degenerate faces which are still 3 unique vertices (so not caught by the remove_degenerate_faces which just checks for 3 unique indices per face on load), but those vertices are colinear (up to way more than tol.zero, 1e-12)
  2. The face normals are from the STL file input
  3. Face normals are stored in the cache, which is cleared when vertices or faces are altered
  4. When mesh.rezero is called it alters vertices, triggering a cache clear
  5. is_watertight asks for faces, which checks to make sure face_normals are populated to ensure consistency in the shape of mesh.faces and mesh.face_normals
  6. the generation of face_normals via cross products detects and removes the degenerate face
  7. mesh is no longer topologically watertight

So it is totally a little janky to be inconsistent like this. A quick hack to ensure consistency is:

m = trimesh.load('rezero-test.stl')
m.face_normals = None #force the Trimesh object to regenerate/validate face normals
m.is_watertight

I also just added a bit to mesh.rezero that maintains face normals, as they're not going to be changed by a translation.

I'm not sure what the right way to deal with this is globally however. If we just threw out face normals from input files it would keep everything consistent, but in a lot of meshes generating the face normal from cross products is pretty expensive (though I just checked and it looked like it was ~15% of total load/process time). Another option is to add a strict flag:

m = trimesh.load('rezero-test.stl', strict=True)

Which would just throw away input normals, or at least validate them. I'm not in love with adding another esoteric boolean flag though, I'm definitely open to suggestions.

I've found trimesh.repair.broken_faces to be pretty useful for seeing whats happening for stuff like this btw.

from trimesh.

mikedh avatar mikedh commented on May 24, 2024

Upon reflection, those faces should really have been removed in initial processing. There is already a remove_degenerate_faces function called in there, however it was only covering the case where a face has two of the same vertex (aka [0,1,0]), not the case where there were three unique vertices that all happened to be colinear. I pushed a fix in d0685ac which is slower than the old function, but its like .015 -> .023s on my machine, which is probably worth it for being more robust.

from trimesh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.