import/export of .obj file
-
Hello, I'm adding a catalog to my website and I would like to use jscad to show 3d models and was thinking that users could simply export the model to .OBJ to download it, but the it seems that jscad adds faces and holes to the exported model.
on the middle is the original model with 400 triangles and no holes
on the left is the model that JSCAD exported with 416 triangles and 16 holes.I will simply only use JSCAD to view the model and add a link for users to download the obj file, but as I'm planning to use JSCAD to dynamically decimate a 3d model, I will certainly export to STL.
-
@platypii Thank you for this investigation. I remember that I tried to get JSCAD to union those groups but then it loses colors. I use Wings 3d to colorize my models, and it does not split them into separate objects (on my screenshot I have only one geometry), only materials are separated into groups.
I splitted the model into 3 geometries and then exported it to .obj and the difference is that it contains 3 lines starting with "o " that defines start of an object. Maybe for the moment JSCAD translate lines starting with "g " like "o ".
-
@gilboonet I think I understand the issue here.
The original file
st_s001.obj
has 3 grouped objects within the obj file:g Girafe_412_blue ... g Girafe_412_lime ... g Girafe_412_orange
This results in generating 3 different objects being produced:
const obj = require("./st_s001.obj") console.log("number of geometries:", obj.length) "number of geometries: 3"
Since these are not closed objects, but rather 3 seperate objects, one for each color, there are seams at the boundaries. Red lines are non-manifold edges:
However, if you remove the "group" lines from the original .obj file, everything works. Including colors, because you can have colored faces in the same object. And since it's one seamless object, the export doesn't introduce gaps.
Can you give that a try?
-
@platypii for sure, you can try this one that has exactly the same problem https://openjscad.xyz/#https://raw.githubusercontent.com/gilboonet/gilboonet.github.io/master/creations/source/st_s001.obj and if you need more examples, I started creating links to models on this page : https://gilboonet.github.io/creations/index.html (the models links are numbers followed by a triangle at the beginning of each item)
Direct link to the obj file : https://github.com/gilboonet/gilboonet.github.io/blob/master/creations/source/st_s001.obj
-
@gilboonet I suspect that the additional faces and holes might be introduced by either
snap
ortriangulate
that is applied when serializing to .obj format.There is a serializer option for whether to triangulate or not. We might want to add an option for whether to snap or not. But it would be easy enough to test locally.
Can you share the obj file?
-
@z3dev JSCAD exported obj with holes breaks my automatic unfolder, I could add code to make it handle holes (edges without neighbor) as I do for the previous version. The aim of my catalog is to allow users to use the models I already unfold for customized needs (typically change size, crop thtm, and as soon as possible decimate them), and I was willing to to those customization with JSCAD. OBJ is the format I use because it can store color information for each triangle. Apparently for the moment this color information is lost when you import a colored OBJ and export it to OBJ.
-
@gilboonet let us know if you think any of the designs seem 'incorrect'. I'd be glad to help out. And of course, fix any bugs.
-
@gilboonet super! Please let us know how the catalogs are published. I'm sure many will want to do the same.
OBJ... it's a good format for exchanging designs, but not very popular. I think most users will want to download STL.