julienr / meshcut

Python 3D mesh planar cross-section
MIT License
103 stars 27 forks source link

Bad slicing for some planes #7

Closed julienr closed 2 years ago

julienr commented 6 years ago

Follow-up from https://github.com/vlachoudis/bCNC/issues/901

In examples/1_stl_sphere_cut.py, with the settings

plane_orig = (0, 0.75, 0)
plane_norm = (0, 1, 0)

this gives :

screen shot 2018-09-08 at 10 26 43
Harvie commented 6 years ago

I've just tried latest meshcut.py from your git and there are still some artifacts :-/

image

Harvie commented 6 years ago

Any ideas what might cause this? It almost looks like one of the coordinates is ignored...

image

the line goes flat instead of being at angle.

julienr commented 6 years ago

I would need to investigate this, I'm not sure what's wrong. I am currently quite busy, but I'll try to have a look when I have some time.

julienr commented 6 years ago

Trying to reproduce this: is this still with the hemisphere.stl model ? The plane y=14.5 doesn't intersect the sphere, so I guess there is some scaling going on. I guess you are using another model. Could you share it ?

Harvie commented 6 years ago

I am using this model:

https://github.com/vlachoudis/bCNC/files/2358797/sphere.stl.zip

But i've got very similar problems with sphere.stl from your repository. see following: https://github.com/vlachoudis/bCNC/issues/901#issuecomment-419243166

Harvie commented 6 years ago

@julienr note it is Y -14.5 not Y 14.5 update: it probably does not matter, because model is symmetric in this axis...

but there are such problems in lots of slices... 14.5 is just example.

Harvie commented 6 years ago

I've tried increasing close_epsilon and dist_tol magic numbers and it does not seem to help.

julienr commented 6 years ago

I am not able to reproduce this on the 1_stl_sphere_cut.py example of meshcut. Here is an example with the sphere.stl.zip that you gave above and

    plane_orig = (0, -14.5, 0)
    plane_norm = (0, 1, 0)
screen shot 2018-10-24 at 21 57 38

I tried to play a bit with various parameters, but couldn't find some that would reproduce the bug. Are you sure this is not a display problem in bCNC ?

Harvie commented 6 years ago

Well. Maybe there's some problem in how i interpret the resulting contour, but it seems to me that sometimes there's one piece missing. Even in your screenshot:

image

We can close that slice path by returning back to the first coordinates, but not every slice should be closed as some models might not be manifold / solid and in such case the resulting slice should be open path. For example if you slice STL model of plane (eg. single triangle) you should get line (open path), but if you slice sphere, you should get circle (closed path). So i thin we should not always close the path, but rather figure out, why is the last line missing from slice.

Harvie commented 6 years ago

Update: i had problem in bCNC. I had typo in code which automaticaly closes the contour. Now i fixed it:

image

I am quite happy with how it turned out.

Harvie commented 6 years ago

Only issue is the non-manifold case. It's not really critical, as most meshes are manifold, however it would make meshcut more consistent if fixed.

I think that meshcut should close the path itself if needed. Now i close it by returning to original coordinates, but this might not be desirable for non-watertight meshes. See the last line of this code:

first = contour[0]
block.append("g0 x%f y%f z%f"%(first[0],first[1],first[2]))
for segment in contour:
    block.append("g1 x%f y%f z%f"%(segment[0],segment[1],segment[2]))
block.append("g1 x%f y%f z%f"%(first[0],first[1],first[2])) #HERE I CLOSE THE PATH

if i don't include the last line, i get bad slice for manifold mesh. if i include it, i get bad slice for non-manifold mesh.

unre4l commented 4 years ago

any news regarding this issue? 🤔

julienr commented 4 years ago

@unre4l Are you running into this with a non-manifold mesh ? Do you have a repro mesh ?

I've been quite busy, but I think fixing this would involve keeping track of the starting triangle and the ending triangle and if those are the same triangle, then it means the mesh is manifold and we can close the path. If the two triangles are different, then the mesh is non-manifold and the path shouldn't be closed. If you want to work on it, PR welcome. Otherwise, I can have a look, but I don't promise anything :)

julienr commented 2 years ago

Duplicate of #20, closed by #21