Class ObjLoader
java.lang.Object
eu.svjatoslav.aukio.e3d.renderer.raster.shapes.composite.obj.ObjLoader
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 formsv,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 facesmtllib 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 Summary
Modifier and TypeMethodDescriptionstatic ObjModelload(InputStream objStream, String sourceName, Function<String, InputStream> resourceResolver) Loads an OBJ document from a stream.static ObjModelLoads an OBJ file, resolvingmtllibreferences against the file's own directory.
-
Method Details
-
load
Loads an OBJ file, resolvingmtllibreferences 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 contentsourceName- name used in error messagesresourceResolver- opens referenced material libraries by name; may returnnullwhen not found- Returns:
- the parsed model, ready to add to a scene
- Throws:
IOException- on read errors or malformed statements
-