geometry自动生成
分类:包 · 清单:use "kernels/";
四元数旋转与刚体变换矩阵、相机矩阵、曲线、有符号距离场(SDF)及其组合、空间扭曲。
Rotations as quaternions and rigid transforms as matrices; a camera’s matrices and the ways between the world, clip space and the picture; curves through control points; signed distances to shapes, with the ways they are joined; and the ways space is bent before a distance is measured.
Layer: Foundation. Uses: no other package.
use "geometry.entpkg";Kernels
Section titled “Kernels”kernels/camera.ent— A camera’s matrices and the ways between the world, the clip space a rasterizer takes and the picture; a pinhole lens (Lens): the ray through a pixel (ray), where a point lands (project), its clip coordinates and depth back to distance (lens_clip,lens_distance), a lens orbiting a point (lens_orbiting).kernels/curve.ent— Curves through control points as the weights of four points, for points of any type: a uniform Catmull-Rom curve and a cubic Bezier curve, and their slopes.kernels/intersect.ent— Where a ray meets the plainest shapes: a sphere, an upright box, and how near it passes a segment.kernels/quaternion.ent— Rotations as unit quaternions, held in aVec4asx y z w, the order glTF and Blender write.kernels/sdf.ent— Signed distance functions.kernels/transform.ent— Rigid transforms.kernels/warp.ent— Space bent before a distance is measured: repeated, mirrored, turned into sectors or folded into a kaleidoscope, twisted, bent, rolled up round a cylinder, scaled.
tests/ holds scenes and their replays, run on every backend:
camera.replay, curves.replay, distances.replay, intersect.replay, lens.replay, turns.replay, warps.replay. Every Kernel of the
package is reached by one of them.
Used by the animation, culled, image, mesh, showcase, surface, voxel examples.
| 函数 | 简述 |
|---|---|
perspective(fov_y: Float, aspect: Float, near: Float, far: Float) -> Mat4 |
A perspective projection: fov_y radians from the bottom of the picture to its top, aspect its width over its height, the near and far planes at those distances. |
perspective_focal(f: Float, aspect: Float, near: Float, far: Float) -> Mat4 |
A perspective projection by its focal length f, how far the picture is from the eye in half heights of it (1 / tan(fov_y / 2)). |
look_at(eye: Vec3, target: Vec3, up: Vec3) -> Mat4 |
The view from eye toward target, up the way that stays up in the picture: a matrix taking the world into the camera’s space. |
orbit_eye(target: Vec3, yaw: Float, pitch: Float, distance: Float) -> Vec3 |
Where a camera orbiting target stands: distance away, turned yaw radians about up from +z and raised pitch radians above the horizon. |
orbit_view(target: Vec3, yaw: Float, pitch: Float, distance: Float) -> Mat4 |
The view of a camera orbiting target (see orbit_eye), up kept up. |
clip_point(m: Mat4, p: Vec3) -> Vec4 |
A point carried by a matrix into clip space. |
screen_point(clip: Vec4, size: Vec2) -> Vec3 |
Where a point in clip space lands on a picture size large: its pixel (x right, y down) and its depth, 0 at the near plane to 1 at the far. |
pixel_ray(view: Mat4, fov_y: Float, pixel: Vec2, size: Vec2) -> Vec3 |
The direction in the world through pixel pixel of a picture size large, seen by a camera of view view and field fov_y. |
view_eye(view: Mat4) -> Vec3 |
Where the camera of view view stands in the world. |
ray(l: Lens, q: Vec2, extent: Vec2) -> Vec3 |
The view ray of pixel q (in a picture extent large). |
project(l: Lens, p: Vec3, extent: Vec2) -> Vec3 |
The pixel of a screen extent large a world point p falls on (xy), and how far from the camera it is (z); behind the camera, z is negative. |
lens_clip(l: Lens, extent: Vec2, p: Vec3, near: Float, far: Float) -> Vec4 |
A world point p’s clip coordinates for the rasterizer (a picture extent large; near and far clipping planes near and far meters): x, y, depth times w, and w the distance along the lens’s facing. |
lens_distance(l: Lens, dir: Vec3, depth: Float, near: Float, far: Float) -> Float |
How far along view ray dir a depth the rasterizer drew lies, the depth of a point lens_clip placed between near and far. |
lens_looking(eye: Vec3, target: Vec3, focal: Float) -> Lens |
A lens at eye looking at target, the world’s up kept up. |
lens_orbiting(target: Vec3, yaw: Float, pitch: Float, distance: Float, focal: Float) -> Lens |
A lens orbiting target (see orbit_eye), up kept up, focal long. |
catmull_rom_weights(t: Float) -> Vec4 |
A uniform Catmull-Rom curve’s weights at t from 0 to 1 of the span from p1 to p2, p0 and p3 the points either side: the curve passes through every point, its slope at each half the way from the point before to the point after. |
catmull_rom_slopes(t: Float) -> Vec4 |
The slope of catmull_rom_weights at t, a change per span. |
bezier_weights(t: Float) -> Vec4 |
A cubic Bezier curve’s weights at t from 0 to 1: it starts at p0 toward p1 and ends at p3 from p2. |
bezier_slopes(t: Float) -> Vec4 |
The slope of bezier_weights at t, a change per curve. |
sphere_span(from: Vec3, dir: Vec3, c: Vec3, r: Float) -> Vec2 |
Where a ray enters and leaves a sphere (y below x: it misses). |
ray_segment(from: Vec3, dir: Vec3, a: Vec3, b: Vec3) -> Vec2 |
How far a ray passes from a segment, and how far along the ray. |
box_span(from: Vec3, dir: Vec3, c: Vec3, ax: Vec3, az: Vec3, h: Vec3) -> Vec2 |
Where a ray goes through a box standing upright at c: ax and az its axes across the ground, h its half sizes along them and up; (in, out), out below in where it misses. |
turn_about(axis: Vec3, angle: Float) -> Vec4 |
|
after(a: Vec4, b: Vec4) -> Vec4 |
|
back(q: Vec4) -> Vec4 |
|
between(a: Vec4, b: Vec4, t: Float) -> Vec4 |
|
rotating(q: Vec4, v: Vec3) -> Vec3 |
|
arc(a: Vec3, b: Vec3) -> Vec4 |
|
rotated(v: Vec3, axis: Vec3, angle: Float) -> Vec3 |
v turned angle radians about axis (Rodrigues’ rotation), the axis not of unit length needed; no axis is no turn. |
rotated_yaw(v: Vec3, angle: Float) -> Vec3 |
v turned angle radians about up, +z toward +x. |
rotated2(v: Vec2, angle: Float) -> Vec2 |
v turned angle radians in the plane, x toward y. |
sd_sphere(p: Vec3, r: Float) -> Float |
A sphere of radius r about the origin. |
sd_box(p: Vec3, half: Vec3) -> Float |
A box of half sizes half about the origin. |
sd_round_box(p: Vec3, half: Vec3, r: Float) -> Float |
A box of half sizes half, its edges rounded by r (within its half sizes). |
sd_capsule(p: Vec3, a: Vec3, b: Vec3, r: Float) -> Float |
A capsule: the segment from a to b grown by r. |
sd_torus(p: Vec3, ring: Float, tube: Float) -> Float |
A torus about up: its ring’s radius ring and its tube’s tube. |
sd_cylinder(p: Vec3, r: Float, half: Float) -> Float |
A cylinder about up: radius r, half height half. |
sd_chamfer_box(p: Vec3, half: Vec3, chamfer: Float) -> Float |
A box of half sizes half about up, its four upright edges cut flat chamfer back along each face (an octagon in plan). |
sd_cone(p: Vec3, low: Float, high: Float, half: Float) -> Float |
A cone about up cut flat at both ends: radius low at its foot, high at its top, half height half. |
sd_plane(p: Vec3, n: Vec3, offset: Float) -> Float |
A plane of unit normal n, offset from the origin along it. |
sd_circle(p: Vec2, r: Float) -> Float |
A circle of radius r in the plane. |
sd_rect(p: Vec2, half: Vec2) -> Float |
A rectangle of half sizes half in the plane. |
sd_round_rect(p: Vec2, half: Vec2, r: Float) -> Float |
A rectangle of half sizes half, its corners rounded by r. |
sd_segment(p: Vec2, a: Vec2, b: Vec2) -> Float |
The segment from a to b in the plane. |
sd_lattice_cube(local: Vec3, size: Float, fill: Float) -> Vec2 |
A shape built of cubes on a lattice size wide (warp_repeat’s cells), at local in a cell about its middle: how far the cell’s own cube is, fill of the cell wide (x), and how far any other cell’s cube is at the least (y: past the cell’s wall and the gap round its cube). A caller decides which cells hold a cube, and takes the cube’s distance where its cell holds one and the bound where it does not. |
smooth_union(a: Float, b: Float, k: Float) -> Float |
Two shapes as one, blended over k where they meet (0 a sharp join). |
smooth_subtract(a: Float, b: Float, k: Float) -> Float |
b cut out of a, the cut’s edge blended over k. |
smooth_intersect(a: Float, b: Float, k: Float) -> Float |
Where both shapes are, blended over k. |
turning(q: Vec4) -> Mat4 |
|
transform(at: Vec3, turn: Vec4, grow: Vec3) -> Mat4 |
|
rotate_x(a: Float) -> Mat3 |
|
rotate_y(a: Float) -> Mat3 |
|
rotate_z(a: Float) -> Mat3 |
|
tangent_of(n: Vec3) -> Vec3 |
A direction square to n (a unit vector): across the world’s up, or across x where n is nearly up or down. With cross(n, tangent_of(n)) it makes a frame round n. |
warp_repeat(p: Vec3, cell: Vec3) -> Vec3 |
p in the cell of a lattice cell wide that holds it, about the cell’s middle. |
warp_repeat_cell(p: Vec3, cell: Vec3) -> Vec3 |
Which cell of the lattice cell wide holds p (whole numbers, 0 the cell about the origin). |
warp_repeat_limited(p: Vec3, cell: Vec3, low: Vec3, high: Vec3) -> Vec3 |
p in the cell that holds it of the lattice’s cells low to high (by warp_repeat_cell), or the nearest of them past their ends. |
warp_repeat_wall(local: Vec3, cell: Vec3) -> Float |
How far local (a point about a cell’s middle, warp_repeat’s) is from its cell’s walls: what a shape repeated keeps its distance under, so a march never steps past the next cell’s shape. |
warp_repeat2(p: Vec2, cell: Vec2) -> Vec2 |
The flat ones: p in its cell of a lattice of the plane cell wide, and which cell. |
warp_repeat_cell2(p: Vec2, cell: Vec2) -> Vec2 |
|
warp_mirror(p: Vec3, n: Vec3, offset: Float) -> Vec3 |
p mirrored across the plane of unit normal n, offset from the origin along it: what is behind the plane brought in front of it. |
warp_sectors(q: Vec2, count: Int, turn: Float) -> Vec2 |
q (a point of a plane about its origin) turned into the first of count sectors round the origin, each the first turned (the first along x, either side of it), the sectors turned turn first. |
warp_fold(q: Vec2, count: Int, turn: Float) -> Vec2 |
q folded into the first of count sectors round the origin, each the one before mirrored (a kaleidoscope’s): the first lies from x to turn back of the sector’s width, then on. |
warp_twist(p: Vec3, rate: Float) -> Vec3 |
p twisted about up: each height turned rate radians a meter more. |
warp_twist_stretch(r: Float, rate: Float) -> Float |
How much a twist of rate stretches distances r meters from its axis. |
warp_bend(p: Vec3, rate: Float) -> Vec3 |
p bent in the plane of x and up: each step along x turned rate radians a meter more, so a bar along x curls round. |
warp_bend_stretch(r: Float, rate: Float) -> Float |
How much a bend of rate stretches distances r meters from its middle. |
warp_roll(p: Vec3, start: Float, radius: Float) -> Vec3 |
The ground (y 0) rolled up past start along z round a cylinder across it (along x) of radius radius: up into a wall, over into a ceiling. p of the world taken to the flat ground’s space; nearer than start as it is. |
warp_roll_stretch(p: Vec3, start: Float, radius: Float, most: Float) -> Float |
How much a roll stretches distances at p: within the cylinder, the ground’s length drawn in round a smaller circle (at most most). |
warp_scale(p: Vec3, center: Vec3, by: Vec3) -> Vec3 |
p scaled from center by by (a shape grown by times there): distances measured at the result are by’s least times shorter than in the world. |
类型与结构体
Section titled “类型与结构体”| 名称 | 写法 |
|---|---|
Lens |
struct Lens { eye: Vec3; ahead: Vec3; right: Vec3; up: Vec3; focal: Float; } |
Lenses |
type Lenses = Rows<Lens>; |
camera.replay, curves.replay, distances.replay, intersect.replay, lens.replay, turns.replay, warps.replay

