.OBJ Files - 0x3C50/Renderer GitHub Wiki

The renderer library has inbuilt support for .obj and .mtl files, allowing them to be drawn in the world.

Note: Which models can be used?

The obj loader has been optimized to work with blender. See the javadoc on ObjFile for instructions on how to export a model properly.

Loading the .OBJ

To load an .OBJ file, you need to create a resource provider that best fits your use case. If you just want to load an .OBJ from disk, you can create one with ResourceProvider.ofPath(Path.of("/your/path")). All files related to the .OBJ will be assumed to be there.

With this, you can create a new ObjFile: new ObjFile("name_of_the.obj", ResourceProvider.ofPath(Path.of("/your/path"))).

Loading is automagically done once you create the ObjFile.

Drawing

Once you have your ObjFile, you can call its .draw(MatrixStack, Matrix4f, Vec3d) method. More information on that method specifically can be found in its javadoc.

Example

// mod main
ObjFile objFile = new ObjFile("cube.obj", ResourceProvider.ofPath(Path.of("/path/to/parent_of_cube")));

// world render event
objFile.draw(stack, new Matrix4f(), new Vec3d(0, 100, 0));