How to detect vertices not visible from Z

I’ve been working on a script to remove overhanging geometry from molds (necessary to be able to remove cast pieces from a solid mold). My original script is finished, but it just doesn’t work. It was intended to work by using the boolean/intersect-boolean functions to remove anything above upwards oriented faces, but they’re too unpredictable to be relied on. It just about does the job on a few simple test meshes, but when I try it on something complex, like Suzanne, it spends half an hour churning away then hands back a corrupted mesh.


So I’m trying a new approach. Instead of removing overhanging geometry from the mold, I’m going to try filling overhanging geometry on the model I’m making the mold from. My current thoughts on how to do this go as follows:

  • Select all upward oriented faces (normal > 0)
  • Split them off into a new object
  • Detect all vertices which are not visible from -Z on the original object and delete them
  • Detect all vertices which are not visible from +Z on the new object and delete them
  • Join the two objects back together
  • Remove doubles (should fuse the mesh again)
  • Fill as many voids as possible automatically with mesh repair tools
  • Fill the remainder myself manually

I can do almost all of that already, I have code for detecting upwards/downwards oriented faces, creating new objects and joining objects as well as some functions for repairing meshes. The part I’m not sure about is selecting occluded (hidden by geometry) vertices. I can very easily do this manually:

  • Enter Edit mode
  • Hit 7 to switch the camera to Z+
  • Hit 5 to enter orthographic projection
  • Ensure selection is limited to visible (the button just to the right of vert/edge/face selection mode)
  • Border select all
  • Invert selection

The thing is, I’m not sure how much of that functionality is exposed to python, if any. I’d prefer not to have to perform a manual task in the middle of my script, but I guess I’ll do it if I have to. Another approach I thought of is to…

  • Iterate through all the verts in the mesh
  • Cast a ray in the z+ / z- direction (depending on whether I’m working on the top or bottom object)
  • If it intersects with any other geometry, remove it

The problem with this approach is that I’m not sure how it will interact with vertical faces, like the sides of a cube. I want to preserve those, but surely any ray they cast would hit the faces above them, because they’re perfectly aligned with them?

Anyhow, I’m new to blender’s API, so I don’t really know what it’s possibilities are. I’m hoping someone more experienced than me reads this and has some ideas about how to approach this problem, either removing occluded geometry specifically or filling/removing overhangs in general. Thoughts on other approaches are also welcome, and if anyone knows of any CAM software that does this automatically it’d be a huge help.

What do the molds need to look like? Images would be helpful. What’s the object and what’s the mold visually? Also how much precision do you need? Can the object only be an approximate one?

If you don’t need a super high precision you can just project rays from up and from down on a 2D grid and then build a object from that data. Bigger 2D grid, more precision. For example 1024x1024 sounds like it should handle most things.

Hi Ambi, thank you very much for your reply. I don’t have the objects I want to mold modeled yet (I want to work out the molding process first) but they’ll be this kind of thing:


Modelling the hard-surface objects shouldn’t be a problem, I can just be careful when I’m modelling not to create any negative surfaces/overhangs. The problem is the organic surfaces and cloth, I’ll have to sculpt those and it’s virtually impossible while sculpting to be absolutely sure you’re not creating any overhangs. I decided that the best approach would be to sculpt then write a modifier that erodes overhanging geometry, but if you happen to know of an option that constrains sculpting to avoid this being necessary then it’d be incredibly useful.

Precision isn’t extremely important, as it’s for an artistic application, not a medical one or anything.

Sorry, I just noticed your edit, that might actually work come to think of it. I threw out that idea in the past because I figured it’d either result in stupidly huge meshes or too little detail, but the smallest end mill I’ll be using is .3mm, so even with a 30cm by 30cm mold that should be enough.

Thanks

Well Blender can handle something like 10 mil quads pretty decently. 2 * x ** 2 = 10 mil, x = sqrt(10 ** 7 / 2) = 2.236. So something like 2048 x 2048 would be fine. Also the raycasts done in Python are really much faster than I expected. It may take just a couple of seconds at most to shoot 10 mil rays.

Also I’ve been thinking of using OpenGL zbuffer to calculate the depth instead of raycasts but that’s a little too much hassle for very little gain as it’s already fast.

Peter_Rabbit I would actually be interessted in you script, for exactly the same, to create molds.

BUT perhaps you want to try the shrinkwrap modifier first. With the projection option and a plane with many, many subdivided surfaces, you normally get something that only needs a few small tweaks by hand to be usable to create a mold! Perhaps you can save a hell lot of time writing your script!

Best regards

Baxerus

Unfortunately my script does not work. It’s dependent on booleans and the boolean library in blender is shaky as hell. It runs perfectly on very very simple, low poly meshes, but I tried it on a more complex one and it just spat out a mess of isolated verts and faces.

I tried a couple of other approaches, including shrink wrap, but they were too memory intensive and tended to crash blender if you used any reasonable degree of resolution.

I’m currently talking to the developer behind blendCAM who thinks he might be able to integrate “remove overhangs” into his script. He quoted me between €800 and €1000, so if you’d like to contribute to funding the feature that’d be great. If not you’ll still be able to get it for free with the next update.