Convert a 3D Object to a ThreeJS readable format (JSON)

Problem

I have 3D object file (ex:- car.obj) and want to load it with ThreeJS on a browser

Solution

The solution is in the ThreeJS library itself. We can use the utils in the ThreeJS library (three.js/utils/converters/).  In the utils/converters folder you will see the following JS files

JS files

 

Use the obj2three.js file for the conversion as follows

Requirements

  • NodeJs installed
  • A 3D file (.obj)

 

Once we have the required material and software installed, open the command line and use the following command. You need to first be in the folder where your 3D object file resides.

 

 

cd <path to your .obj file>

node <path to the obj2three.js file> <object file>

 

output

 

Once you have the JSON file you can use the " THREE.ObjectLoader() " to load the file on a browser