Repository navigation
Geometry
core/buffer_geometry.mojo, core/buffer_attribute.mojo, core/geometry_store.mojo and geometries/. A BufferGeometry holds named vertex attributes and an optional index. Three builders make a box, a sphere and a plane.
three.js: BufferGeometry, BufferAttribute, BoxGeometry, SphereGeometry, PlaneGeometry.
A flat List[Float32] with an item size. BufferAttribute(data, 3) holds vectors of three floats.
| Member | Meaning |
|---|---|
count() -> Int |
The number of items. |
component(index, offset) -> Float32 |
One float of one item. |
vector3(index) -> Vector3 |
One item as a vector. Item size must be three. |
| Member | Meaning |
|---|---|
set_attribute(name, attribute) |
Add or replace an attribute. |
attribute_view(name) -> ref BufferAttribute |
Borrow an attribute. Bind it with ref. |
clone_attribute(name) -> BufferAttribute |
Copy an attribute. |
has_attribute(name) -> Bool |
Whether the attribute exists. |
set_index(index) |
Set the triangle index. An empty list clears it. |
vertex_count() -> Int |
The number of vertices in position. |
triangle_count() -> Int |
The number of triangles. |
corner(triangle, corner) -> Vector3 |
A corner position. |
corner_index(triangle, corner) -> Int |
Which vertex that corner is. |
Attribute names are the constants POSITION, NORMAL and UV. A geometry needs position. It needs normal for smooth shading and uv for a texture.
assets.geometries.add(geometry) stores a geometry and returns a GeometryId. get(id) borrows it. Many meshes share one geometry. See Meshes and assets.
var solid = cube(Length(1.0, METER))
var brick = box(Length(2.0, METER), Length(1.0, METER), Length(0.5, METER))A box has twenty-four vertices, four per face. Each face carries its own normal and texture coordinates. The whole image covers each face once.
var ball = sphere(Length(1.0, METER), 24, 16) # segments around, rings downA latitude and longitude sphere. Each normal points away from the center, so shading is smooth. u runs once around the equator. v runs from one at the north pole to zero at the south pole. It needs at least three segments and two rings.
var sheet = plane(Length(2.0, METER), Length(1.0, METER)) # one quad
var grid = plane(Length(20.0, METER), Length(20.0, METER), 4, 4) # sixteen quadsA rectangle in the xy plane, facing +z, centered on the origin. The vertex order, winding and texture coordinates match three.js. Turn the node a quarter turn about x to make a floor.
The texture coordinates run once across the rectangle. To tile an image, rewrite the uv attribute, as examples/floor.mojo does.
- A negative or zero extent raises.
- A sphere with too few segments or rings raises.
- A plane with fewer than one segment raises.
- An index entry beyond the last vertex raises.
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
- Streamline
- 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