Examples - SethKitchen/ThreeMojo GitHub Wiki

Examples

examples/. Each example is one program that renders one image or animation into out/. make animation renders all of them except carla.mojo and carla_town.mojo.

Run one by hand:

mkdir -p out
.venv/bin/mojo run -I . examples/cubes.mojo out/cubes.png
Example Output Page
triangle.mojo triangle.png The smallest program that draws.
spin.mojo spin.png Image files
cube.mojo cube.png Why a software rasterizer
cubes.mojo cubes.png Scene graph
uv.mojo uv.png Why interpolation is perspective-correct
textured.mojo textured.png Textures
glass.mojo glass.png Why transparency is sorted
floor.mojo floor.png Why mipmaps
photo.mojo photo.png A decoded PNG on a cube. The README figure.
lamps.mojo lamps.png Lights
first_scene.mojo first_scene.png Render your first scene
lit_scene.mojo lit_scene.png Light, texture and animate
rotations.mojo rotations.png Rotations
ortho.mojo cameras.png Cameras
stereo.mojo stereo.png Cameras
geometry.mojo geometry.png Geometry
instances.mojo instances.png Meshes and assets
raycast.mojo raycast.png Raycasting
curves.mojo curves.png Curves and paths
lines.mojo lines.png Lines
sprites.mojo sprites.png Points and sprites
television.mojo television.png Textures
mirror.mojo mirror.png Textures
outlines.mojo helpers.png Helpers
keyframes.mojo keyframes.png Animation
skinning.mojo skinning.png Skinning
phong.mojo phong.png Materials
physical.mojo physical.png Materials
fog.mojo fog.png Fog
culling.mojo culling.png Renderer
split.mojo split.png Renderer
clipping.mojo clipping.png Rasterization
gpu_backend.mojo gpu_backend.png GPU backend
exposure.mojo exposure.png Render target and framebuffer
model.mojo model.png Model files
orbit.mojo math.png Math
clock.mojo units.png Units
chain.mojo chain.png Why the scene graph is an array
additive.mojo additive.png Why color is linear
normals.mojo normals.png Why a normal is not a color
fragments.mojo fragments.png Why shading is per fragment
edges.mojo coverage.png Why coverage uses fixed point
shadows.mojo shadows.png Lights
wide.mojo wide.png Lines
bloom.mojo postprocessing.png Post-processing
gizmo.mojo controls.png Windowing and controls
json_scene.mojo scenejson.png Scene JSON
reloaded.mojo exporters.png Exporters
gem.mojo transmission.png Materials
distance.mojo distance.png Materials
unfogged.mojo unfogged.png Materials
targets.mojo targets.png Render target and framebuffer
layers.mojo layers.png Materials
graph.mojo nodes.png Node materials
basis.mojo ktx2.png Textures
coats.mojo coats.png Materials
skyjson.mojo environment.png Scene JSON
daylight.mojo sky.png Scene objects
faces.mojo faces.png Meshes and assets
utah.mojo teapot.png Geometry addons
blobs.mojo blobs.png Scene objects
flipbook.mojo animated.png Animated objects
ripples.mojo computation.png GPU computation
baked.mojo lightmap.png Progressive light map
diagram.mojo svg.png SVG renderer
bricks.mojo models.png More model files
terrain.mojo mathaddons.png Math addons
override.mojo hooks.png Renderer hooks and material flags
clay.mojo sculptor.png Sculptor
cells.mojo tslfunctions.png TSL functions
cloud.mojo gaussian.png Gaussian splats
bounce.mojo vxgi.png Voxel global illumination
sunlight.mojo lighting.png Lighting addons
vase.mojo lofts.png Lofts and clipping groups
sapling.mojo generators.png Procedural generators
particles.mojo computenodes.png Compute nodes
towers.mojo procedural-towers.png Procedural towers
interiors.mojo floor-plans-and-interiors.png Floor plans and interiors
room_cells.mojo building-topology.png Building topology
building_model.mojo building-model.png Building model
exchange.mojo ifc-exchange.png IFC exchange
frame_modes.mojo frame-analysis.png Frame analysis
plate.mojo shell-analysis.png Shell analysis
heat.mojo building-energy.png Building energy
spring_modes.mojo numerics.png Numerics
audio_game_humanoid.mojo audio-character.glb Audio-aligned game faces
carla_towns.mojo carla_towns.png CARLA rendering
femur.mojo femur.png Femur
tibia.mojo tibia.png Tibia
fibula.mojo fibula.png Fibula
patella.mojo patella.png Patella
knee.mojo knee.png Knee
muscles.mojo muscles.png Muscles
leg.mojo leg.png Leg
legs.mojo legs.png Leg
foot.mojo foot.png Foot
limb.mojo limb.png Leg
vessels.mojo vessels.png Vessels
lymph.mojo lymph.png Lymph
nerves.mojo nerves.png Nerves
integument.mojo integument.png Integument
pelvis.mojo pelvis.png Pelvis
torso.mojo torso.png Torso
arm.mojo arm.png Arm
hand.mojo hand.png Hand
head.mojo head.png Head
genomes.mojo genomes.png Genome
family.mojo family.png Genome
expressions.mojo expressions.png Head
talking.mojo talking.png Head
hairstyles.mojo hairstyles.png Head
game_humanoid.mojo game_humanoid.png Game humanoid
water.mojo water.png Water
animals.mojo animals.png Animals
walk.mojo walk.png Animals
animal_anatomy.mojo animal_anatomy.png Animal anatomy
carla.mojo carla.png CARLA
carla_town.mojo carla_town.png CARLA rendering

photo.mojo takes the image path first: examples/photo.mojo assets/brick.png out/photo.png.

pelvis.mojo, torso.mojo, arm.mojo, hand.mojo, head.mojo, genomes.mojo, family.mojo, expressions.mojo, talking.mojo and hairstyles.mojo take a mesh quality after the path: low, medium, high or xhigh. See Mesh quality.

.venv/bin/mojo run -I . examples/torso.mojo out/torso.png low

make animation does not render the two CARLA examples. Run them by hand: mojo run -I . examples/carla.mojo out/carla.png and mojo run -I . examples/carla_town.mojo out/carla_town.png.

viewer.mojo writes no file. It opens a window in the terminal, and make viewer runs it. See Windowing and controls.

Animated outputs are APNG files. A browser or VS Code plays them. A viewer that does not know APNG shows the first frame.

Benchmarks

tools/bench_examples.mojo times the catalog against three.js and, when installed, Mojo 1.0. Benchmarks names every other CPU bench and records who wins. The refresh command is in How to measure examples.

Tools

Program Shows
tools/gpu_status.mojo Whether an accelerator is present. It needs MAX.
tools/doc_lint.mojo Whether the documentation follows the writing rules.