I am doing NC Machining simulation. I have successfully generated an offset surface by a specified distance (a STL model). The problem I got in that I want draw lines around any model that fit the shape of model.
Is there any ideal or any similiar example ? please help me
Create a black alpha texture with white lines along the x-direction at regular intervals in the y-direction.
Align the alpha texture to the blue rectangle in your example images.
Enable blending so that your filled mesh values get multiplied with the alpha texture values and you get lines as a result.
You can just draw one white line in the black alpha texture, set the texture coordinate wrapping mode to repeat and play with the texture coordinates to get a more sparse/dense displaying of these virtual lines without having to recompute the actual lines.
PS. You can also do this easily in fragment shaders without the need for an alpha texture.
Nico’s method is much simpler, but you may have artefacts when multiple layers of line overlap, such as between the cylinder an the cube in the top image.
If the machine has 3 axis. A possible solution would be to render the the object from the top into a heightmap. The next step should be to filter the heightmap with a filter kernel that describes the cutter. The kernel is a smaller heightmap from the cutters bottom side. The lowest distance have to be written into the output texture. The result can be used as Z value for the cutter for a given (X,Y) position.
I’ve written a small program for you that uses GLSL shaders to do what you need without having to create/use alpha maps. You can download it here.
Use the f/F and r/R keys to change the fraction and repeat values.
Change vpos.y in toolpath.frag to vpos.x or vpos.z in order to change the orientation of the lines.
This tool requires the original mesh and the offset mesh. I’m assuming that you’re already able to create this offset mesh. If not, you can take a look at implicit surfaces e.g. using radial basis functions. With implicit surfaces it is fairly easy to generate an offset mesh, you only need the mesh vertices end their corresponding normals to create an implicit function.
@ZbuffeR: I’m not sure what you meant with the artefacts. But if it is what I think you meant, that shouldn’t be a problem if you enable alpha testing, right?
There is one artefact however. Each of the lines represent a slice, so if a mesh triangle coincides with a slice it will be colored completely e.g. it’s possible that a cube face will be fully colored instead of just a line.
You are right. I only thought about alpha blending, and overlooked alpha test.
There is one artefact however. Each of the lines represent a slice, so if a mesh triangle coincides with a slice it will be colored completely e.g. it’s possible that a cube face will be fully colored instead of just a line.
That is why I think the best is to reconstruct real lines from the reading the depth of offset surface. But it may be more difficult to program, and slower too.