deadsy / sdfx

A simple CAD package using signed distance functions
MIT License
518 stars 52 forks source link

Render to triangle mesh #67

Closed Megidd closed 1 year ago

Megidd commented 1 year ago

Render a signed distance field - SDF3 - to a raw vertex buffer.

Why

Sometimes the users of this package just intend to render to a triangle mesh. This PR would let them have the vertex buffer of the rendered triangle mesh.

Megidd commented 1 year ago

Test

I have tested a modified version of this code which renders to a custom triangle mesh. It was fine :roll_eyes:

deadsy commented 1 year ago

So the intent is to just to have a point cloud right? ie - the edges between the triangles are being lost, so the result is not a triangle mesh, but just the triangle vertices.

Also - the plural of vertex is vertices, not vertexes.

Megidd commented 1 year ago

...the plural of vertex is vertices, not vertexes.

Done.

...so the result is not a triangle mesh, but just the triangle vertices.

For my use case, I could convert the vertex buffer to any custom mesh I want. Every three consecutive vertices are corresponding to a triangle. I just thought the raw vertex buffer might be the most generic form of a triangle mesh.

deadsy commented 1 year ago

For my use case, I could convert the vertex buffer to any custom mesh I want. Every three consecutive vertices are corresponding to a triangle. I just thought the raw vertex buffer might be the most generic form of a triangle mesh.

Do you seek to maintain the relationship between the vertices (triangles) or just the vertices themselves? As written you are going to have a lot of duplicated vertices, because triangles share vertices and and any shared vertex will be present at least twice. That is: If you were just after the surface point cloud then you could weed out the duplicates and have a much smaller data set.

btw - that's what the 3mf file format does. They remove any duplicated vertices and then use integer indices to reference the vertex list when defining the triangles.

If you are after the triangles then why not store them as such, instead of having an unstated "every three consecutive vertices is a triangle" relationship?

Megidd commented 1 year ago

... If you are after the triangles then why not store them as such, ...

Done.