ObjParser
Parses .obj text files into PolyList[] arrays, extracting vertex positions (v), normals (vn), texture coordinates (vt), faces (f), groups (g) and material names (usemtl).
import ObjParser from 'bg2e-js/ts/db/ObjParser';
const parser = new ObjParser(objText);console.log(parser.polyListArray); // Array of PolyList objectsSee also: index, obj-loader-plugin
Constructor
Section titled “Constructor”ObjParser(objText: string): Initializes the parser with OBJ text content. Tokenizes lines by first character to dispatch parsing (v → vertex, vn → normal, vt → texcoord, g → group name, usemtl → material name, s → smoothing groups), f → face/geometry). Supports line continuation with backslash (\). Ignores comment lines starting with #.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
polyListArray | PolyList[] | Read-only accessor returning the parsed geometry arrays. Each PolyList corresponds to a group or mesh in the OBJ file. |
Parsing details
Section titled “Parsing details”- Vertex positions, normals and texture coordinates are stored internally in separate arrays
- Faces define geometry through vertex/normal/texcoord indexing with support for polygons via triangulation
- Group names from
gstatements are stored in the PolyList’snameproperty - Material names from
usemtlstatements are stored temporarily and can become group/PolyList names if PolyList has no name yet .mtlfiles are parsed but not loaded —ObjLoaderPluginmarks MTL loading as a TODO