Is it possible to export mesh to .obj without extra lines (triangles)?

I have code which exports mesh to the .obj file and that works fine.
After that I convert the .obj file to .dxf file in C#.
The problem is that the outcome .dxf file contains a lot of lines, since mesh is made of triangles.

I’m wondering is it possible in BabylonJS to export a mesh to .obj without those lines (triangles)?
I’ve seen that BabylonJS has a simplification feature but even with that I still get those lines.

If it is not possible, is it possible that I just get outlines (silhouette) of the mesh?

Welcome aboard!

A mesh is made up of triangles, so it’s not possible to export anything other than triangles.

I’m not sure what you expect from the generated dxf file, given the input .obj file?

You mean ‘visually’? because in that case the answer is ‘yes’. You should be able to find some examples in the forum. Else, let me know and I’ll try find it for you.

I would need only outlines(silhouette) of a mesh, To make it look like as a tehnical drawing (for example top view on the scene but as a a tehnical drawing). In my case I can do that, but I have so many unnecessary lines in the output. I was wondering is it possible to call some method from BabylonJS on the mesh in order to do that before creating an .obj file.

Is it a 3D object? If so, I don’t see how.

Yes, just to get outlines(silhouette) which can be exported to .obj and latter on to .dxf.

yes, it is a 3D object.

I’m sorry, I must be dumb but I still do not fully understand the problem. Are you actually saying that the obj file (which obviously is made from triangles) is fine for your needs BUT when you convert it to .dxf you get ADDITIONAL lines between triangles. Like (assumption) the vertices are converted to triangles, is that what you mean?

That is correct. Reason why they are there in .dxf file is because .obj file contains all the vertices/faces which defines those triangles. I was wondering if Babylon can do something on a mesh level before I do the final conversion.

That makes things a little bit clearer, however the way you state it here is like your obj export has converted all vertices to meshes and that already shouldn’t be. Then why do you need a dfx as final is also unclear to me. The times I faced this kind of issue, I solved it through the export (not at engine level). Clearly, it’s a wrong interpretation of file when exporting. May be check the export settings, use another tool or another format. What’s the native format of the file (you get or create?) and what needs do you have for the final version?

As for your question

I have no faen clue. I suppose the vertices exported to mesh must likely follow some naming convention. You could try select these meshes and dispose of them but next, you would likely have missing parts connecting the faces. As I said, no faen clue. Let’s cc again @Evgeni_Popov

Edit: May be you could also share one of your buggy obj files with us or import in a PG so we could have a look at it. Thx,

A repro in the Playground would be nice, I’m still not sure I understand the problem fully.

1 Like

Here is a playground:

I’ve turned on the material.wireframe = true; so you can see extra triangles.
And when I export the mesh to the .obj file I get all those triangles. Ideally I would like to get only outlines of a mesh (in 2D world that would be a circle).
This is a screenshot from the exported obj file in Belnder (edit mode):

I’m sorry I see nothing wrong with this mesh. There are no extra-lines as far as i can see. I downloaded the obj and opened in c4d and honestly, this looks fine to me. Just to make this clear, obj is triangles (it doesn’t handle things like i.e. quadrangles or ngones). Your expectations here are kind of unclear to me (I’m sorry) but then… I’m not the ultimate expert for it. May be someone else will see this differently?

the mesh is fine, but when I export that OBJ file to DXF I get so many lines (triangles) which is causing that the file to large. So I wondering how to get only outline of the entire mesh without those inner triangles. And my question was related with BabylonJS, if it has some API which can be used in order to resolve my problem.
This is how DXF file looks like:

There’s not really an absolute outline of a mesh. The outline (if you mean the “external borders” of the mesh) depends on the camera view.

For a sphere, it could seem the outline is always the same because of the symetries, but think of it when textured: you won’t see the same thing depending on the camera view.

You can decrease the number of triangles by lowering the number of segments used in the create sphere method (if you created the sphere with this method), but that’s about it…

1 Like

Yes, I was about to say the same. In fact, I still don’t understand your process and use case. Sorry, I must be dumb. Are you trying to make a 2D export for CAD? In which case your sphere would be a circle? But then I suppose, the sphere is just a dummy, is it? So you would want to export an outline for 2D which would depend (as said above) on the camera view (except of course for a sphere, which - if so - might just not be the best example. I’m sorry, I’m afraid that without a complete understanding of the goal and intended process, this thing will just remain a forth and back. Unless, your topic stumbles over someone much smarter than me :grin:

I also join with a bit of confusion on what do you mean by “outline”. But if you don’t want triangles for visual purposes only, there might be a way to cheat it a bit.

What’s going on here is the following.

In 3D software (3dsMax for example), you basically create 3D mesh from the wiremesh of the sphere.
There is a neat button in 3dsMax which allows you to create shape from selection, where selection in this case are the edges of the sphere.

This basicaly creates a spline, to which you can then add thickness that you want, and convert to a poly mesh.

The end result off this process is this

Now you just combine the two. Sphere underneath, and wiremesh mesh on the top.
Here is an example playground, you can check the list of meshes to see what’s going on.

Note that this is only visually working, but as you basically creating and exporting another mesh, and even worse, mesh is created from sphere edges, and then converted to basically a lot of tubes, all of those tubes now have a lot of vertices and edges on their own, which can impact the performance and file size.

So, much less optimized, but visually maybe what you aiming for.

1 Like

“Are you trying to make a 2D export for CAD?” - lets say it should be like that. For example top view of some configuration so it looks like some technical drawing. I understand that the camera view has influence. Also, I have different polygonal shapes (3d models). The sphere is just an example.

Thanks for clarifying the case. I think I understand better where you are heading. Unfortunately, I don’t see a solution in BJS for this. One more question: Is this something the user can do and would download as a ready-to-use file? Obviously, you can forget about the edgeRendering since it is a post-process, it will never export to a spline. Same for renderOutline which offsets the volume and will never make a line/spline. Honestly, I have no faen clue. I don’t even know if you could export greasedLines to mesh/lines? cc @roland ???

If it’s YOU doing it and not the user, and doesn’t have to be a fully automated/dynamic process - I would actually use an external tool for cad to convert the shapes into a vector spline:

  1. Set an emissive material only to all meshes you want to outline and a clear color that works as a mask.
  2. Export the PNG result.
  3. Open image/render in tool (i.e. PSD or AI), select by color, then convert to vector spline.
    This will also give a much cleaner result for a 2D CAD draw. Else, as I said (I’m sorry) I have nothing better to propose. :thinking:

With the additional information you provided above, all I can do is call-in again cc @Evgeni_Popov @nogalo @PatrickRyan (if you have a minute?) May be they will have a different look at this?

@icf, from what I am reading here, it appears you want to take a 3D model and render a 2D technical illustration from it. For example, if you have a 3D mesh of this part, you want to be able to create a technical drawing like this:

While you could do something along the lines of a toon shader on the mesh that gives you an outline of the silhouette and some lines defining where complex shapes overlap, it’s not super accurate and usually is more of an aesthetic approach to a render. The image above contains some very intentional lines to help the user understand the 3D shape such as the radius that transitions between the larger cylinder and the thinner plate in the side view. Rendering that line with a toon shader likely won’t produce the shape accurately.

The other issue with this approach is that the shader will only render the lines on the mesh. There is no object - mesh, spline, or otherwise - that will be generated for those lines, so it can only be used as a render and cannot be used as data to be extracted.

I’m not sure if this is what you are going for, but there isn’t an out of the box shader to do this in Babylon. This would need to be a custom shader or node material.