Repository navigation
Model files
loaders/obj.mojo. read_obj reads a Wavefront OBJ file into named objects, each with a BufferGeometry. parse_obj reads the text of one.

three.js: OBJLoader.
var model = read_obj("assets/cube.obj")
for index in range(model.count()):
print(model.objects[index].name, model.objects[index].material)
var shape = assets.geometries.add(model.objects[0].take_geometry())| Function | Meaning |
|---|---|
read_obj(path) -> ObjModel |
Read a file. |
parse_obj(text) -> ObjModel |
Read the text of one. |
ObjModel.objects holds one ObjObject per object, in file order. count() says how many.
| Field | Meaning |
|---|---|
name |
From o or g. Empty when the file has neither. Faces read before the first o or g belong to it, as three.js has it. |
material |
The name from usemtl. Empty before one. The material library is not read. |
geometry |
A non-indexed BufferGeometry with position, and with normal and uv when the faces name them. |
take_geometry() swaps the geometry out for an empty one, so it can go into a store. A BufferGeometry moves and does not copy.
| Line | Meaning |
|---|---|
v x y z |
A position. A fourth number is ignored. |
vt u v |
A texture coordinate. |
vn x y z |
A normal. |
f a b c ... |
A face of three or more corners, cut into a fan of triangles. A polygon must be convex. Each corner is v, v/vt, v//vn or v/vt/vn. |
o name, g name
|
A new object. One with no faces is dropped. |
usemtl name |
A new object under that material, with the same name. |
# |
A comment, to the end of the line. |
An index counts from one. A negative index counts back from the last entry so far. mtllib, s, l, p and unknown lines are skipped.
Every face of one object must agree about normals and texture coordinates. A geometry without normals shades flat. See Renderer.
The parser raises, naming the line, for:
- A
v,vtorvnline with too few coordinates. A coordinate that is not a number, or is not finite as aFloat32. - A face with fewer than three corners, or a corner with more than three parts.
- A face of four or more corners that is not convex, or has no area. A fan covers a convex polygon and only that.
- An index that is not a whole number, is zero, or names an entry the file does not have.
- A face that names a normal or a texture coordinate where an earlier face of the object did not, or the other way round.
read_obj raises for a file it cannot read.
assets/cube.obj is a unit cube with normals and texture coordinates. tests/test_obj.mojo reads it and draws it.
Tutorials
How-to
Reference
- Scene graph
- Rotations
- Cameras
- Geometry
- Geometry addons
- Lofts and clipping groups
- Sculptor
- Procedural generators
- Meshes and assets
- Lines
- Points and sprites
- Helpers
- Scene objects
- Animated objects
- Raycasting
- Curves and paths
- Animation
- Skinning
- Materials
- Node materials
- TSL functions
- Lights
- Lighting addons
- Fog
- Textures
- Renderer
- Renderer hooks and material flags
- Rasterization
- GPU backend
- Render target
- Post-processing
- GPU computation
- Compute nodes
- Progressive light map
- Gaussian splats
- Voxel global illumination
- SVG renderer
- Image files
- Image decode queue
- Model files
- More model files
- Exporters
- Scene JSON
- Windowing and controls
- Math
- Norm consumers
- Math addons
- Units
- Coverage tool
- Commands
- Examples
- Benchmarks
- Extensions
- Shared physics
- Physics query snapshots
- Continuous collision
- Tick force restoration
- Water
- Animals
- Buildings
- CARLA
- Femur
- Tibia
- Fibula
- Patella
- Knee
- Muscles
- Vessels
- Lymph
- Nerves
- Integument
- Leg
- Foot
- Pelvis
- Torso
- Arm
- Hand
- Head
- Genome
- Game humanoid
- Humanoid fidelity
- Audio-aligned game faces
- Converted assets
- Mesh quality
- Segment inertia
Explanation
- Software rasterizer
- Scene graph as an array
- Linear color
- Normals are not colors
- Perspective correction
- Fixed-point coverage
- Per-fragment shading
- Mipmaps
- Sorted transparency
- Types and checks
- Render hooks as a trait
- Shared CPU and GPU code
- Bands and threads
- PNG structure
- Extensions beside the port
- CUDA teardown hang
- Mojo compiler hang