A C++ parser for Wavefront's .obj 3D files
All OSs:
cmake 3.0 and later
A web browser with WebGL support (All modern Web browsers should work)
Linux:
Clang 5 and later
Windows:
Visual C++ 15.7 (2017) and later
Linux:
git clone https://github.com/dartzon/dotObj-parser
cd dotObj-parser
./build.sh
The build.sh
runs cmake and make automaticaly.
Windows:
git clone https://github.com/dartzon/dotObj-parser
cd dotObj-parser
generateVSProject.bat
The generateVSProject.bat
runs cmake and generates by default a Visual Studio 2017 solution
in the build directory.
Modify the content of build.sh
or generateVSProject.bat
to customize the following build options:
- Build directory.
- Build type (release is the default).
The generated binary is located in build/bin/objparser
. objparser
is the name of the executable.
If you are using Linux, you can just execute run.sh:
Linux:
./run.sh
Windows:
build/bin/objparser
Command line arguments:
The program takes two optional arguments.
The .obj file path:
Linux:
./run.sh ~/MyObjFiles/Spaceship.obj
Windows:
build/bin/objparser c:\Users\Me\Desktop\Spaceship.obj
And a scale factor:
Linux:
./run.sh ~/MyObjFiles/Spaceship.obj 5
Windows:
build/bin/objparser c:\Users\Me\Desktop\Spaceship.obj 5
Running the program with no arguments will do nothing.
After a successful run, go to the folder out3d
in the base of the project and open the html page index.html
in a web browser. You should see the 3D content of your .obj file and you can interact with it by zooming and moving the model using the mouse or the keyboard like you would do on any 3D graphics viewer.
If nothing shows up, try to zoom-out with your mouse wheel or change the scale factor argument when executing the program.
You can see debug messages on the terminal if you compile the program in debug mode and execute it.
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(39): Obj file parsing started...
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(214): Parsing Vertex
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(304): Parsing Group
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(304): Parsing Group
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(304): Parsing Group
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(304): Parsing Group
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(242): Parsing Face
[DBG INFO] /home/dartzon/Dev-Workspace/CPP/dotObj-parser/src/ObjFileParser.cpp(64): Obj file parsing ended
Automated tests source files are located in tests/
folder
Use the argument -test
with the building scripts to build the test program.
Linux:
./build.sh -test
Windows:
generateVSProject.bat -test
Use the argument -test
with the running script under Linux
to launch the tests.
Linux:
./run.sh -test
Windows:
build/bin/objparser_tests
The automated tests will open a 3D .obj file from tests/models
folder and check for a number of parameters like the count of Vertices, the type of Faces (Triangles or Quads) and the count of Groups (g). Any error will be displayed in the console.
- C++ 17 and STL
- Catch 2 - The test framework for unit-tests
- three.js - JavaScript 3D library used to display 3D content in web browsers
- Othmane AIT EL CADI - Initial work - dartzon
This project is licensed under the MIT License - see the LICENSE.md file for details