How to Convert .OBJ file to .JS file

I am getting problem with the convertion of the 3D object to the Javascript file, I have tried convert 3D object to the json, but there is getting problem with my three.js project. I have also surf the web about convert json to js file but same it is not working.

I want to have the data of Geomatrics, Faces, Vertices, UV shell count/UVs, Material, Edges. I got improper data in the json file, like i got Geomatrices, Vertices, UVs, Materials, but i can’t find get the arrays of the edges, Faces.

So if anyone have any idea or any converter for the same which is usefull for me.

How do you convert from OBJ to JSON? Besides, can you please share the resulting JSON file?

I guess you are referring to the JSON Object/Scene format, right?

The mentioned three.js JSON format does not support any kind of edge data structure. Even the deprecated JSON model 3 did not support edges. Similar, faces are only represented implicitly by the order of vertices (position attribute) or by separate index buffer data.

bathtub-1.zip (818.1 KB)

I am converting objrct from Obj to Three.js converter which is included in three.js package file. Here is the file which i get from the converter. And i don’t have get the whole data which required, Like Counts of Geomatrics, Faces, Vertices, UV shell count/UVs, Material, Edges etc.

Your JSON is based on three.js JSON Object/Scene format. Your statement is unfortunately wrong since vertices (position attribute) and materials are defined in your JSON file. As I said before faces, edges or count properties are not explicitly defined. You have to derive these data by yourself.

I suggest you study how BufferGeometry works. This should makes things hopefully more clear:

https://threejs.org/docs/index.html#api/en/core/BufferGeometry

OK well thanks, I will try to fix by myself. But have you any idea that how i can get the Faces, edges or count properties from Obj file?

I gave a try on looeee converter and it worked with your file.

The only problem i see is that his version seems to use an older version of three, but it worked on your file as well :slight_smile:

1 Like

You can also import the file in the editor and then use one of the export options. In this way, you always work with the latest version of three.js.