Class ObjLoader

java.lang.Object
eu.svjatoslav.aukio.e3d.renderer.raster.shapes.composite.obj.ObjLoader

public final class ObjLoader extends Object
Loader for Wavefront OBJ geometry files (with MTL material libraries).

Supported OBJ statements:

  • v x y z — vertex positions (extra components ignored)
  • f v1 v2 v3 [v4 ...] — faces; each index may be in any of the standard forms v, v/vt, v//vn, v/vt/vn; negative indices are relative to the most recently defined vertex. Faces may reference vertices defined later in the file (batch-flushing exporters do this). Texture/normal indices are parsed past and ignored.
  • usemtl name — selects the material for following faces
  • mtllib file [file ...] — material library, resolved relative to the OBJ file (or via the caller-provided resolver)
  • o, g, s, vt, vn, # — parsed past and ignored

Supported MTL statements: newmtl, Kd (diffuse color), d (opacity) and Tr (transparency). Everything else is ignored.

Coordinates are loaded verbatim — no axis conversion. Note the engine's world convention is "+Y points down", which matches OBJ exporters that wrote scenes for y-down pipelines; for standard "+Y up" exports rotate the resulting model 180° around X via its transform.

Limitation: faces are rendered as convex polygons (fan triangulation); non-convex faces may render with overlapping triangles.

Usage:

ObjModel model = ObjLoader.load(Path.of("city1.obj"));
model.setShadingEnabled(true);
shapes.addShape(model);
  • Method Details

    • load

      public static ObjModel load(Path objFile) throws IOException
      Loads an OBJ file, resolving mtllib references against the file's own directory.
      Parameters:
      objFile - path to the .obj file
      Returns:
      the parsed model, ready to add to a scene
      Throws:
      IOException - on read errors, malformed statements, or a missing material library
    • load

      public static ObjModel load(InputStream objStream, String sourceName, Function<String, InputStream> resourceResolver) throws IOException
      Loads an OBJ document from a stream.
      Parameters:
      objStream - the OBJ content
      sourceName - name used in error messages
      resourceResolver - opens referenced material libraries by name; may return null when not found
      Returns:
      the parsed model, ready to add to a scene
      Throws:
      IOException - on read errors or malformed statements