evanw / csg.js

Constructive solid geometry on meshes using BSP trees in JavaScript
http://evanw.github.com/csg.js/
MIT License
1.79k stars 264 forks source link

Question: Cutting Line #20

Closed ianpaschal closed 5 years ago

ianpaschal commented 6 years ago

Hello,

I'm trying to implement CSG into a Three.js project in which a line on the surface of a mesh is used to slice it into two parts. The line is defined as two arrays, one with the positions of each vertex of the polyline, and one with the normal vectors of the mesh at those points (which can be interpolated to "stick" the line to the surface of the mesh between vertices).

So far I haven't had much luck using distance-from-plane slice methods since these are not planes, more like rectangles certainly with discrete edges at the line segment end points, and also likely "height" above and below the surface of the mesh.

So my idea is to sweep this line into a very very skinny rectangle and then use CSG to cut into the mesh. Then, toss out the new "interior" faces (which would be highlighted in blue in the CSG examples) leaving only two red meshes on either side of the line.

I'll be trying to implement this throughout the day but I thought I would post this first to see if anyone has:

Answering the above could really speed up my experiments.

Thanks in advance!

z3dev commented 6 years ago

Try asking this at OpenJSCAD.org community.

themmes commented 5 years ago

@ianpaschal do you mean creating a cross-section of the mesh? Or are the section lines not planar?

If I understand you correctly I build something similar for a Python version of this code. Let me know if this is what you are looking for, then I'll send you the code.

ianpaschal commented 5 years ago

@themmes Unfortunately it's been about a year so I came up with something else. I dove hardcore into computational geometry and wrote my own boolean methods that used lines in 3D space like a sort of virtual scalpel to slice apart polygons.

PrashantKT commented 2 years ago

@ianpaschal Sir I am also searching cross section - which is like cutting mesh from the centre with plane (box ) and get the centre area - That is working with Substact method

But I need this in border - like subtracted part in border where the mesh is collided

If you could guide me - I am very weak in 3d geometry stuff :(

https://github.com/nicklockwood/Euclid/issues/76