Skip to content
View source

voxelGenerated

Category: Packages · Manifest: use "kernels/";

Worlds of voxels drawn by walking rays through them.

Worlds of voxels drawn by walking rays through them: boxes of voxels placed in the world, a place shaded from the sun, shapes as data, and bodies posed by their joints.

Layer: Graphics. Uses: no other package.

use "voxel.entpkg";
  • kernels/body.ent — Bodies. Kernels: voxel.unposing@1, voxel.posed@1.
  • kernels/ray.ent — Worlds of voxels.
  • kernels/shade.ent — A place shaded from the sun: a walk toward it that meets a voxel (voxel_shaded).
  • kernels/shape.ent — Shapes as data, a sphere, a rounded cuboid or a capsule, each painting a number or carving, baked into a volume or painted over one. Kernels: voxel.shapes@1, voxel.paint@1.

tests/ holds scenes and their replays, run on every backend: world.replay. Every Kernel of the package is reached by one of them.

Used by the voxel example.

Kernel Mode Brief
voxel.paint@1 map A volume painted over by shapes, in order, as voxel.shapes@1 paints an empty one. Fed back (volume <~ world.result from...) it is a world edited a frame at a time; given no shapes, it is the volume as it was, and what reads it does not run again.
voxel.posed@1 map A body posed into a box of voxels the size of its domain, its floor’s middle where the rest body’s is: as voxel_posed, every row of unposing a joint.
voxel.shapes@1 map A volume of shapes: each voxel the number of the last of shapes holding its middle, empty where none does. Its domain is the volume’s size.
voxel.unposing@1 map Each joint’s matrix from a pose back to rest: the inverse of the matrix that carries a point at rest into the pose, which is what the skin package’s animation.palette@1 gives.
Function Brief
voxel_body(look: Int, joint: Int) -> Int A body’s number at rest: the look its voxel shows (below 65536) and the joint it moves with. A body at rest is a volume of these, baked once (voxel.shapes@1 paints them as any number), and posed; it is not drawn itself.
voxel_look(number: Int) -> Int
voxel_joint(number: Int) -> Int
voxel_posed(rest: Voxels, unposing: Rows<Mat4>, first: Int, joints: Int, grain: Float, p: Vec3) -> Int What a posed body shows at p, in its box’s voxels (its floor’s middle at the origin), each voxel grain skin units wide: the body at rest rest (its floor’s middle at the skin’s origin), p carried back to rest by each of the joints rows of unposing from first on, in order, and taken where the voxel it lands in moves with that joint; the look of the first so found, 0 none.
voxel_over(d: Float) -> Float
voxel_within(c: Vec3, n: Vec3) -> Bool
voxel_walk_past(vox: Voxels, from: Vec3, dir: Vec3, base: Vec3, n: Vec3, pass: IVec2) -> VoxelStep A ray from from along dir, in voxels, walked (Amanatides and Woo) through the box of n voxels at base in the volume vox (a walk takes at most 1024 steps: boxes of a few hundred voxels a side), to the first voxel neither empty nor numbered from pass.x to pass.y (water a ray sees through, say; ivec2(1, 0) passes nothing); id 0 for none. Its distance t is in voxels along dir.
voxel_walk(vox: Voxels, from: Vec3, dir: Vec3, base: Vec3, n: Vec3) -> VoxelStep The first voxel that is not empty, as voxel_walk_past passing none.
voxel_nothing() -> VoxelMeet
voxel_nearer(a: VoxelMeet, b: VoxelMeet) -> VoxelMeet The nearer of two meetings.
voxel_local(m: Vec3, foot: Vec3, turn: Float, size: Float) -> Vec3 A world point in a box’s own frame, in its voxels, its floor’s middle at the origin.
voxel_unturned(v: Vec3, turn: Float) -> Vec3 A direction in a box’s own frame turned back into the world.
voxel_meet_past(vox: Voxels, b: VoxelBox, eye: Vec3, dir: Vec3, near: Float, pass: IVec2) -> VoxelMeet The first voxel of box b a ray from eye along the unit dir (the world’s) meets, its voxels within near world units of the eye left out (so a box beside the camera never fills the picture), and those numbered pass.x to pass.y seen through.
voxel_cell(b: VoxelBox, eye: Vec3, dir: Vec3, met: VoxelMeet) -> Vec3 The cell of box b a ray from eye along dir met, in the box’s voxels: the one behind the face met found.
voxel_meet(vox: Voxels, b: VoxelBox, eye: Vec3, dir: Vec3, near: Float) -> VoxelMeet The first voxel of box b a ray meets, as voxel_meet_past seeing through none.
voxel_shaded(vox: Voxels, from: Vec3, sun: Vec3, base: Vec3, n: Vec3, pass: IVec2) -> Bool Whether a place, from in a box’s voxels, is shaded from a sun along sun (a unit direction toward it, in the box’s frame): a walk toward it meets a voxel, those numbered pass.x to pass.y seen through.
voxel_sphere(at: Vec3, r: Float, id: Int) -> VoxelShape
voxel_cuboid(at: Vec3, half: Vec3, round: Float, id: Int) -> VoxelShape
voxel_capsule(from: Vec3, to: Vec3, r: Float, id: Int) -> VoxelShape
voxel_distance(s: VoxelShape, p: Vec3) -> Float How far p is outside a shape, in voxels; less than 0 inside.
voxel_painted(id: Int, c: IVec3, shapes: Rows<VoxelShape>) -> Int The voxel at cell c, holding id, painted over by each of shapes in order: the last holding its middle gives it its number.
Name Syntax
Voxels type Voxels = Volume<Int>;
VoxelStep struct VoxelStep { cell: Vec3; side: Vec3; t: Float; face: Vec3; id: Int; }
VoxelBox struct VoxelBox { base: Vec3; n: Vec3; size: Float; foot: Vec3; turn: Float; }
VoxelMeet struct VoxelMeet { t: Float; id: Int; face: Vec3; }
VoxelForm type VoxelForm = enum { Sphere, Cuboid, Capsule };
VoxelShape struct VoxelShape { form: VoxelForm; a: Vec3; b: Vec3; r: Float; id: Int; }

A volume painted over by shapes, in order, as voxel.shapes@1 paints an empty one. Fed back (volume <~ world.result from...) it is a world edited a frame at a time; given no shapes, it is the volume as it was, and what reads it does not run again.

Mode map
Requires field.read, field.write
Inputs volume: Volume<Int>, shapes: Rows<VoxelShape>
Params —
Outputs result: Volume<Int>
Source packages/voxel.entpkg/kernels/shape.ent

A body posed into a box of voxels the size of its domain, its floor’s middle where the rest body’s is: as voxel_posed, every row of unposing a joint.

Mode map
Requires field.read, field.write
Inputs rest: Volume<Int>, unposing: Rows<Mat4>
Params grain: Float = 1.0
Outputs result: Volume<Int>
Source packages/voxel.entpkg/kernels/body.ent

A volume of shapes: each voxel the number of the last of shapes holding its middle, empty where none does. Its domain is the volume’s size.

Mode map
Requires field.read, field.write
Inputs shapes: Rows<VoxelShape>
Params —
Outputs result: Volume<Int>
Source packages/voxel.entpkg/kernels/shape.ent

Each joint’s matrix from a pose back to rest: the inverse of the matrix that carries a point at rest into the pose, which is what the skin package’s animation.palette@1 gives.

Mode map
Requires field.read, field.write
Inputs palette: Rows<Mat4>
Params —
Outputs result: Rows<Mat4>
Source packages/voxel.entpkg/kernels/body.ent

world.replay