Geometry
Back to the reference

Geometry

The shapes models are made of.

30 symbols

createGeometryfunctionnacatamalon

createGeometry(data: TGeometryData) => TGeometry

Makes a shape of your own, corner by corner: a terrain from a height map, a trail, a ramp, a star pushed out into a solid, anything the shape hooks do not make. Hand it to createMesh.

Only positions has to be there. Without indices, every three corners are a triangle; without normals, the facings are worked out from the triangles, smooth, or one per triangle with flat; without uvs, every corner reads the picture's top left; without uv2, it is uvs again; without colors, white. uvs can also be worked out by name, 'box' for a rock or a building, 'planar' for a terrain, 'cylinder' or 'sphere', with uvScale to lay the picture by the units the corners are given in rather than once over it.

It belongs to the object that made it. Unlike a shape hook's, which every object asking for the same size shares, this one is the object's own: it goes when the object goes, and a mesh elsewhere still wearing it then draws nothing. Change it while the game runs with updateGeometry.

A shape made this way cannot be written in a scene document, since it is not a recipe but the corners themselves: make it in code, in the body of the object that wears it.

Parameters

dataTGeometryData

Its corners, and whatever else it has of them.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { y: 1, z: 4 } });
    useDirectionalLight({ intensity: 1 });

    // A ramp: four corners and two triangles, counter-clockwise from the side that is seen.
    const ramp = createGeometry({
        positions: [-1, 0, 1, 1, 0, 1, 1, 1, -1, -1, 1, -1],
        indices: [0, 1, 2, 0, 2, 3],
        uvs: [0, 1, 1, 1, 1, 0, 0, 0],
    });
    createMesh({ geometry: ramp, tint: '#ff9e3d' });

    return createScene();
};
View source · geometry/create_geometry.ts:306

getGeometryfunctionnacatamalon

getGeometry(key: string) => TGeometry | null

Resolves the name a shape is kept under, the same string a model's geometry field holds, to the shape itself, or null when nothing has been loaded under it.

A model looks this up on its own, which was enough while a model was the only thing that could name a shape. A collider names one too ({ shape: 'hull', geometry: 'crate' }), and that happens outside the engine, in whichever package does the simulating, so the lookup has to be reachable rather than re-derived against the running game's insides by every one of them.

It answers while a scene is being built, which is when a collider is made, and that is the whole of what it is for: there is no running game to ask outside of that, and the answer is null.

Parameters

keystring

The name the shape is kept under.

View source · geometry/get_geometry.ts:22

mergeGeometriesfunctionnacatamalon

mergeGeometries(pieces: typeOperator) => TGeometry

Makes one shape out of several, each where it sits: a fence of posts and rails, a table of a top and four legs, the separators round a wheel. Hand it to createMesh, and what was a draw a piece is one draw.

One draw only for pieces that share a surface. A merged shape is drawn in one material, so pieces in nine materials are nine merges and nine meshes, not one. Pieces that differ only in colour can share one, with a tint each painted on their corners.

Each piece is placed as an instance of createMeshInstances is: x, y, z, a turn in radians (rotationX, rotationY, rotation about Z, or a quaternion), a scale, or scaleX, scaleY, scaleZ one way apart. Its facings turn with it, and a piece mirrored by a negative scale is turned inside out again, so it is seen from the same side as before. Every piece keeps its picture places, so one picture is laid on each as it was on its own.

Pieces may be any shape hook's, one made by createGeometry, or another merge. Not a piece of a model file: its corners are on the graphics card alone and cannot be read back. A shape hook's is built again from its recipe to be read, once a merge however many pieces wear it.

It belongs to the object that made it, as one from createGeometry does: it goes when the object goes, and updateGeometry changes it. It is made in code, in the body of the object that wears it: a scene document cannot write it down. The pieces are read once, when it is made, so changing one later does not change it.

Merge what does not move apart. Pieces that each move are separate meshes; many of one shape, each placed apart, are createMeshInstances.

Parameters

piecestypeOperator

The shapes, each with where it sits.

Example

const Fence = () => {
    useCamera3d({ projection: 'perspective', transform: { y: 2, z: 8 } });
    useDirectionalLight({ intensity: 1 });

    const post = useCubeGeometry({ width: 0.2, height: 1.2, depth: 0.2 });
    const rail = useCubeGeometry({ width: 6, height: 0.15, depth: 0.1 });
    const pieces: TMergePiece[] = [];
    for (let i = 0; i < 7; i++) {
        pieces.push({ geometry: post, x: i - 3, y: 0.6 });
    }
    pieces.push({ geometry: rail, y: 0.4 }, { geometry: rail, y: 0.9 });

    // Nine pieces, one draw.
    createMesh({ geometry: mergeGeometries(pieces), tint: '#a0703d' });

    return createScene();
};
View source · geometry/merge_geometries.ts:133

updateGeometryfunctionnacatamalon

updateGeometry(geometry: TGeometry, data: TGeometryData) => void

Changes a shape made by createGeometry while the game runs: a terrain being dug, water worked out on this side, a trail behind a ship, a rope or a cloth. Give it the shape again, whole, as createGeometry took it; what is left out is worked out again the same way, and picture places asked for by name are worked out again from where the corners are now.

It is written over what the card already holds while it fits, and in new room when it grows past it, with some to spare so a shape that grows a little each frame is not made again each frame. Every mesh wearing it shows the change on the next frame. Call it anywhere, a useUpdate included.

Only for a shape of your own: one from a shape hook is shared by every object that asked for the same size, so changing it would change all of them, and it is refused.

Parameters

geometryTGeometry

The shape createGeometry made.

dataTGeometryData

Its corners now, and whatever else it has of them.

Example

const Sea = () => {
    const size = 32;
    const positions = new Float32Array(size * size * 3);
    const indices: number[] = [];
    for (let z = 0; z < size - 1; z++) {
        for (let x = 0; x < size - 1; x++) {
            const a = z * size + x;
            indices.push(a, a + size, a + 1, a + 1, a + size, a + size + 1);
        }
    }
    const wave = (time: number) => {
        for (let i = 0; i < size * size; i++) {
            const x = (i % size) - size / 2;
            const z = Math.floor(i / size) - size / 2;
            positions.set([x, Math.sin(x * 0.4 + time) * 0.5, z], i * 3);
        }
        return { positions, indices };
    };
    const sea = createGeometry(wave(0));
    createMesh({ geometry: sea, tint: '#3d7bff' });

    let time = 0;
    useUpdate((delta) => {
        time += delta;
        updateGeometry(sea, wave(time));
    });
};
View source · geometry/create_geometry.ts:392

useCircleGeometryfunctionhooknacatamalon

useCircleGeometry(options: TCircleGeometryOptions) => TGeometry

A flat disc facing up.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture is laid flat over it, as over a plane: the middle of the picture at the middle of the disc, u along +x and v along +z.

Parameters

optionsTCircleGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useCircleGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_circle_geometry.ts:60

useConeGeometryfunctionhooknacatamalon

useConeGeometry(options: TConeGeometryOptions) => TGeometry

A cone with a base.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture goes once round the slanted side and once down it: u from 0 at +x, growing to the right as the side is seen from outside, v from 0 at the tip to 1 at the rim. The base is laid flat as a disc is, the right way round as it is seen from below.

Parameters

optionsTConeGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useConeGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_cone_geometry.ts:65

useCubeGeometryfunctionhooknacatamalon

useCubeGeometry(options: TCubeGeometryOptions) => TGeometry

A cube, or any box shape: as wide, tall and deep as you ask, its edges sharp or cut off with a bevel: rounded, or a straight cut.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture is laid once on each face, upright as the face is seen from outside, 0, 0 at the face's top left: the sides with up as up, the top as seen from the front (its far edge at the top of the picture), the bottom as seen from below. The same as uvs: 'box'; with uvScale the picture is laid by the box's units instead, the same size on a box of any size. With a bevel each face's picture reaches round to the middle of its edges, laid by length.

Parameters

optionsTCubeGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useCubeGeometry();
    createMesh({ geometry: shape });

    // A button with its edges rounded off.
    const button = useCubeGeometry({ width: 1, height: 0.3, depth: 1, bevel: { size: 0.1 } });
    createMesh({ geometry: button, transform: { x: 1.5 } });

    return createScene();
};
View source · hooks/geometry/use_cube_geometry.ts:82

useCylinderGeometryfunctionhooknacatamalon

useCylinderGeometry(options: TCylinderGeometryOptions) => TGeometry

A tube with a lid and a base.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture goes once round the side and once down it: u from 0 at +x, growing to the right as the side is seen from outside, v from 0 at the top to 1 at the bottom. The lid and the base are laid flat as a disc is (useCircleGeometry), the base the right way round as it is seen from below.

Parameters

optionsTCylinderGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useCylinderGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_cylinder_geometry.ts:66

useExtrudeGeometryfunctionhooknacatamalon

useExtrudeGeometry(options: TExtrudeGeometryOptions) => TGeometry

A flat outline pushed out into a solid, as a cookie cutter goes through dough: a diamond, a star, a letter, a gear, a notched separator, a deflector, a frame with its window cut out. Draw the outline in points, say how deep, and round its edges off with a bevel if they should not be sharp.

 the outline       what it makes
    ●                 /\
  ●   ●     →        /  \|
    ●                \  /|
                      / /

It stands as the outline is drawn, x across and y up, pushed out depth along z and centred on its middle: its front face looks at a camera on +z. Asking for the same outline twice gives back the same shape, so a wheel of thirty-seven separators costs one shape.

Its picture is laid once over each face, by the box round the outline, upright as each face is seen; and once round the sides, along the outline (u) and from the front to the back (v). Give uvs: 'box' and uvScale to lay it by the world's units instead.

Parameters

optionsTExtrudeGeometryOptions

The outline, its holes, how deep and how its edges are cut.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 3 } });
    useDirectionalLight({ intensity: 1 });

    // A diamond with its edges rounded off.
    const diamond = useExtrudeGeometry({
        outline: [{ x: 0, y: 0.5 }, { x: 0.3, y: 0 }, { x: 0, y: -0.5 }, { x: -0.3, y: 0 }],
        depth: 0.1,
        bevel: { size: 0.02, segments: 2 },
    });
    createMesh({ geometry: diamond, tint: '#e8c547' });

    // A frame: a square with a square window.
    const frame = useExtrudeGeometry({
        outline: [{ x: -1, y: -1 }, { x: 1, y: -1 }, { x: 1, y: 1 }, { x: -1, y: 1 }],
        holes: [[{ x: -0.7, y: -0.7 }, { x: 0.7, y: -0.7 }, { x: 0.7, y: 0.7 }, { x: -0.7, y: 0.7 }]],
        depth: 0.2,
    });
    createMesh({ geometry: frame, tint: '#8a5a33', transform: { x: 2 } });

    return createScene();
};
View source · hooks/geometry/use_extrude_geometry.ts:113

useIcoSphereGeometryfunctionhooknacatamalon

useIcoSphereGeometry(options: TIcoSphereGeometryOptions) => TGeometry

A ball whose triangles are all about the same size. The one to reach for when the surface is going to be lit or bent, because the globe-style ball has slivers at its poles and they show.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture goes round as on useSphereGeometry: u from 0 at +x, growing to the right as the ball is seen from outside, v from 0 at the top to 1 at the bottom. A triangle across the seam reads on past 1 rather than back across the picture, which the default wrap, 'repeat', shows as one picture; with 'clamp' that strip smears the picture's edge.

Parameters

optionsTIcoSphereGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useIcoSphereGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_ico_sphere_geometry.ts:62

useLatheGeometryfunctionhooknacatamalon

useLatheGeometry(options: TLatheGeometryOptions) => TGeometry

A shape turned on a lathe: half an outline, its profile, spun about the upright axis into a solid, as a turner shapes a chair leg or a potter a vase. A bottle, a glass, a vase, a chess piece, a column, a barrel, a lamp, a bowling pin, in a handful of points.

 the profile        what it makes
  ●                    ___
   ●                  (   )
  ●         →          \ /
  ●                    | |
 ●                    /___\

Asking for the same profile twice gives back the same shape, so a shelf of a hundred bottles costs one shape and a hundred placements. The profile goes from the bottom up; given the other way, the shape is turned inside out and seen only from within.

Part of the way round, arc from startAngle, it is a slice: the pocket of a roulette wheel, a half pipe, an arch. Its ends are left open. Slices in different colours are one shape with mergeGeometries, each turned to its place with its own tint: one draw for the whole wheel.

Its picture goes once round (u, from 0 at startAngle, growing to the right as the side is seen from outside; across the slice when it goes part of the way) and once down the profile by its length (v, from 0 at the top), so a label wrapped round a bottle is not stretched where the profile is steep. A flat ring (the numbers round a wheel, a dial's rim) is two points, from the outside in, [{ x: 1.3, y: 0 }, { x: 1, y: 0 }]: it faces up, and a strip of pictures goes once round it with its top at the inner edge, each one upright for whoever reads it from outside.

Parameters

optionsTLatheGeometryOptions

The profile, how many faces round, how far round and where its edges are hard.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { y: 1, z: 4 } });
    useDirectionalLight({ intensity: 1 });

    const bottle = useLatheGeometry({
        profile: [
            { x: 0, y: 0 },       // the middle of the base
            { x: 0.4, y: 0 },     // its rim, given twice: a hard edge
            { x: 0.4, y: 0 },
            { x: 0.4, y: 1.2 },   // the body
            { x: 0.15, y: 1.6 },  // the shoulder
            { x: 0.12, y: 2 },    // the neck, open at the top
        ],
        segments: 24,
    });
    createMesh({ geometry: bottle, tint: '#5fd068' });

    // A wheel of 37 pockets, red and black and one green, as one shape.
    const pocket = useLatheGeometry({
        profile: [{ x: 1.3, y: 0 }, { x: 1, y: 0 }],
        arc: (Math.PI * 2) / 37,
        segments: 1,
    });
    const wheel = mergeGeometries(Array.from({ length: 37 }, (_, i) => ({
        geometry: pocket,
        rotationY: (i * Math.PI * 2) / 37,
        tint: i === 0 ? '#1f8a3b' : i % 2 === 1 ? '#c0282d' : '#1b1b1b',
    })));
    createMesh({ geometry: wheel, transform: { x: 2 } });

    return createScene();
};
View source · hooks/geometry/use_lathe_geometry.ts:128

usePlaneGeometryfunctionhooknacatamalon

usePlaneGeometry(options: TPlaneGeometryOptions) => TGeometry

A flat sheet lying like a floor, facing up. Cut it into squares to bend it later.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture is laid once over it as seen from above, the far edge (-z) at the top: 0, 0 at its -x, -z corner, u along +x and v along +z. uvs: 'planar' with uvScale lays it by the plane's units instead, so a big floor repeats it rather than stretching it.

Parameters

optionsTPlaneGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = usePlaneGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_plane_geometry.ts:69

useSphereGeometryfunctionhooknacatamalon

useSphereGeometry(options: TSphereGeometryOptions) => TGeometry

A ball built as lines of latitude, the way a globe is drawn. Its squares bunch up at the poles, which is the price of a picture that wraps round it neatly.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture goes once round and once down, the way a map of the world wraps a globe: u from 0 at +x, growing to the right as the ball is seen from outside (0.25 at -z, 0.5 at -x, 0.75 at +z), v from 0 at the top pole to 1 at the bottom one.

Parameters

optionsTSphereGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useSphereGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_sphere_geometry.ts:65

useTorusGeometryfunctionhooknacatamalon

useTorusGeometry(options: TTorusGeometryOptions) => TGeometry

A ring, like a doughnut.

Built and put on the graphics card at once, so it is ready the moment you have it: nothing is fetched and nothing is waited for. Hand it to createMesh as its geometry.

Asking for the same size twice gives back the same shape, so a hundred of them cost one shape and a hundred placements.

Its picture goes once round the tube and once round the ring: u round the tube, from 0 on its outer edge (0.25 on top, 0.5 on the inner edge, 0.75 underneath); v round the ring, from 0 at +x (0.25 at -z, 0.5 at -x, 0.75 at +z).

Parameters

optionsTTorusGeometryOptions

Its size, how smooth it is, and what to keep it under.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', transform: { z: 4 } });
    const shape = useTorusGeometry();
    createMesh({ geometry: shape });

    return createScene();
};
View source · hooks/geometry/use_torus_geometry.ts:69

TCircleGeometryOptionstypenacatamalon

TCircleGeometryOptions: TGeometryUvOptions & { radius, segments, key }

What useCircleGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

Default 0.5, so it is one across.

segmentsoptionalnumber

How round it is. Default 32.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_circle_geometry.ts:13

TConeGeometryOptionstypenacatamalon

TConeGeometryOptions: TGeometryUvOptions & { radius, height, segments, key }

What useConeGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

Default 0.5.

heightoptionalnumber

Default 1.

segmentsoptionalnumber

How round it is. Default 32.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_cone_geometry.ts:13

TCubeGeometryOptionstypenacatamalon

TCubeGeometryOptions: TGeometryUvOptions & { width, height, depth, bevel, key }

What useCubeGeometry can be asked for. Everything is optional.

Properties

widthoptionalnumber

Across. Default 1.

heightoptionalnumber

Up. Default 1.

depthoptionalnumber

Towards the viewer. Default 1.

beveloptional{ size, segments }

Its edges cut off, size in from every face: a rounded box, a cushioned table edge, a 3D button, a die. The box still fills width by height by depth, and its faces are smaller by size all round. segments is in how many steps across each edge, 1 a straight cut at 45° and more a rounder one, with the corners rounded like a ball's; default 3. Each face takes half of every edge, so a rounded one is cut in an even number of steps: 3 is cut in 4. Left out, the edges are sharp. At most half the box's smallest side.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_cube_geometry.ts:14

TCylinderGeometryOptionstypenacatamalon

TCylinderGeometryOptions: TGeometryUvOptions & { radius, height, segments, key }

What useCylinderGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

Default 0.5.

heightoptionalnumber

Default 1.

segmentsoptionalnumber

How round it is. Default 32.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_cylinder_geometry.ts:13

TExtrudeGeometryOptionstypenacatamalon

TExtrudeGeometryOptions: TGeometryUvOptions & { outline, holes, depth, bevel, creaseAngle, key }

What useExtrudeGeometry can be asked for.

Properties

outlineReadonlyArray<{ x, y }>

The flat outline, its points in order round it, either way: x across and y up, as the front face is seen. At least three, not crossing itself. A notch or a hollow is drawn in it.

holesoptionalReadonlyArray<ReadonlyArray<{ x, y }>>

Outlines cut out of it, right through: the window of a frame, the middle of a ring, the insides of an "O". Each inside the outline with some of the solid all round it, and none meeting another.

depthoptionalnumber

How deep it is pushed out, front to back, centred on z = 0. Default 1.

beveloptional{ size, segments }

The edges between its faces and its sides cut off, size in from both: the solid still fills the outline by depth, and its faces are smaller by size. segments is in how many steps, 1 a straight cut at 45° and more a rounder one; default 3. Left out, the edges are sharp. At most half the depth, less than half as wide as the outline is at its narrowest (it cuts in from both sides), and less than the rounding of a corner given in points: a card's corners rounded by 0.05 in eight points take a bevel up to 0.0496. A sharp corner pointing into the solid, a narrow notch or the tip of a pointed hole, is cut back further than the bevel, and leaves room for less: a notch 0.1 wide at its mouth and 1 deep takes about 0.048.

creaseAngleoptionalnumber

How sharply, in radians, the outline has to turn at a point for the sides to meet there in a hard edge rather than round smoothly: a diamond's corners are hard, a circle given in points is round. Default Math.PI / 6, 30°.

keyoptionalstring

What to keep it under. By default everything it is asked for is the name, so two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_extrude_geometry.ts:14

TGeometrytypenacatamalon

A shape on the graphics card: its corners, and the order they make triangles in.

It is an asset, like an image: built or loaded once, kept under a name, and shared by every model that shows it. A hundred crates are a hundred placements over one of these.

The corners are eight numbers each, in one run: where the corner is, which way the surface faces there, and which part of the picture it shows. One run rather than three, because the graphics card reads a corner at a time and three separate runs would make it jump about for every one.

Properties

type'geometry'
keystring

What it is kept under. A shape asked for twice with the same size is the same one.

statusTLoadStatus

A built shape is ready the moment you have it. One that came out of a file is 'loading' until the file arrives, and models showing it simply are not drawn until then.

sourceTGeometrySource | null

How it was made, so it can be made again from a file. null for a shape built from raw vertex data, which nothing can write down and which a scene document leaves out.

vertexCountnumber

How many corners, and how many triangle points.

indexCountnumber
bounds{ min, max } | null

The box it fits inside, in its own units.

positionsFloat32Array | null

Where each corner is, kept on this side: the graphics card's copy cannot be read back.

indicesUint16Array | Uint32Array | null

Which corners make up each triangle, three at a time: the companion of positions, kept on this side for the same reason and useless without it.

The pair of them is what a collider made of a shape's real triangles is built from, dents and all, which is how a room or a piece of ground is collided with. The corners alone answer a looser question (the smallest solid that wraps them), and the box it fits inside answers a looser one still.

vertexBufferIBuffer | null
indexBufferIBuffer | null
indexType'uint16' | 'uint32'

How wide each triangle point is. Small shapes use the narrow one, which is half the memory; a shape of more than 65.536 corners cannot be addressed that way and uses the wide one.

skinBufferIBuffer | null

Which bones move each corner and how much, for a shape that came off a rig. null for everything else, which is nearly everything.

A run of its own rather than mixed in with the rest: a shape without bones would otherwise carry eight unused numbers per corner, and every piece of code that walks corners would have to ask how wide they are this time.

colorBufferIBuffer | null

The colour painted on each corner, four bytes apiece (red, green, blue, and how opaque), which the card smears across each triangle and multiplies into the surface.

It is how the consoles of this engine's era lit a level: the light was worked out once, by the artist or the tools, and baked into the corners, so a cave could be dark in its corners and bright by its torches without a single lamp being computed. A shape nobody painted is white all over, which changes nothing, so every shape has one and every model is drawn the same way.

A run of its own for the same reason the bones have one: the first run stays exactly what it always was.

detailBufferIBuffer | null

For each corner, the way across its surface the picture runs (its tangent, with which hand its other edge goes in the fourth number) and a second picture coordinate: six numbers.

What a material reads to find its way over a surface: a relief or a ripple that moves the picture needs to know which way is across it and which way is down, and a second picture (baked light, a decal, a detail) needs coordinates of its own. A file that has them keeps them; any other shape has them worked out when it is made, so every shape has one.

A run of its own for the reason the colours and the bones have one: only a material's shader reads it, and the engine's own drawing never binds it.

View source · geometry/types/t_geometry.ts:19

TGeometryDatatypenacatamalon

A shape given corner by corner: what createGeometry makes and updateGeometry changes.

Every list is flat, a few numbers per corner one after another, and may be a plain array or a typed one.

Properties

positionsArrayLike<number>

Where each corner is: x, y, z, three numbers a corner. The only list that has to be there.

indicesoptionalArrayLike<number>

Which corners make each triangle, three a triangle, counter-clockwise as seen from the side that is drawn (the front, unless the material's cull says otherwise). Left out, every three corners in order are a triangle of their own.

normalsoptionalArrayLike<number>

Which way the surface faces at each corner: x, y, z, three numbers a corner. Left out, it is worked out from the triangles, smooth across corners in the same place.

uvsoptionalArrayLike<number> | TUvProjection

Where in the picture each corner is: u, v, two numbers a corner, 0, 0 the top left. Or the name of a way to work them out from where the corners are, 'planar', 'box', 'cylinder' or 'sphere' (see TUvProjection): a corner that two faces want at two places of the picture is split in two then, so the shape can come out with more corners than it was given. Left out, every corner reads the picture's top left.

uvScaleoptionalnumber

With uvs worked out by name, how many times the picture is laid every unit the corners are given in, rather than stretched once over the shape: 1 a picture each unit, 0.25 one every four. A wall twice as long then has twice the bricks. It reads the corners as given, before the object's transform: a shape scaled up gets bigger bricks, and two shapes carry on each other's only when their corners are given where they stand. Round an axis ('cylinder', 'sphere') it is rounded to whole times, so the seam meets itself.

uv2optionalArrayLike<number>

A second place in a picture for each corner: u, v, two numbers a corner, like uvs. For a picture laid out differently from the colour picture: an occlusion map baked over the whole shape once while the colour repeats (occlusion: { texture, uv: 'uv2' }), or a hook that reads ctx.uv2. A corner uvs worked out by name splits keeps its second place. Left out, it is uvs again.

colorsoptionalArrayLike<number>

The colour painted on each corner: r, g, b, a from 0 to 1, four numbers a corner, multiplied with the picture and the tint and smeared across each triangle. Left out, white.

flatoptionalboolean

Every triangle faces its own way, with hard edges between: the faceted look. The facings are worked out from the triangles, so normals is not read. Default false, smooth.

View source · geometry/create_geometry.ts:26

TGeometrySourcetypenacatamalon

TGeometrySource: { kind, width, height, depth, bevel } & TGeometryUvOptions | { kind, width, depth, widthSegments, depthSegments } & TGeometryUvOptions | { kind, radius, segments } & TGeometryUvOptions | { kind, radius, segments, rings } & TGeometryUvOptions | { kind, radius, subdivisions } & TGeometryUvOptions | { kind, radius, height, segments } & TGeometryUvOptions | { kind, radius, height, segments } & TGeometryUvOptions | { kind, radius, tube, radialSegments, tubularSegments } & TGeometryUvOptions | { kind, profile, segments, startAngle, arc, creaseAngle } & TGeometryUvOptions | { kind, outline, holes, depth, bevel, creaseAngle } & TGeometryUvOptions | { kind, src, node, occurrence }

How a shape is made, when it was made rather than drawn by an artist.

A recipe and not the corners themselves, which is the whole point: a cube is a handful of numbers of description or a few hundred of vertex data, and the description is what a person edits, what a diff shows and what survives the engine changing how it builds a cube.

It is kept on the shape rather than worked out again from the key it was cached under. The key does spell the recipe for every shape this engine builds (cube:1:1:1), but only until somebody passes a key of their own, and then reading it back would be reading a name as if it were a fact.

A shape this engine builds keeps uvs and uvScale too, when they were given (TGeometryUvOptions). Every field but gltf's src may be left out, and leaving one out means its default, exactly as calling useCubeGeometry({}) does. So the smallest cube is { kind: 'cube' }.

View source · geometry/types/t_geometry_source.ts:22

TGeometryUvOptionstypenacatamalon

How a shape hook's picture places are worked out: by name, and how often the picture is laid.

Properties

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · geometry/build/project_uvs.ts:242

TIcoSphereGeometryOptionstypenacatamalon

TIcoSphereGeometryOptions: TGeometryUvOptions & { radius, subdivisions, key }

What useIcoSphereGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

Default 0.5.

subdivisionsoptionalnumber

How many times each triangle is split. Default 2. Each one costs four times as many.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_ico_sphere_geometry.ts:13

TLatheGeometryOptionstypenacatamalon

TLatheGeometryOptions: TGeometryUvOptions & { profile, segments, startAngle, arc, creaseAngle, key }

What useLatheGeometry can be asked for.

Properties

profileReadonlyArray<{ x, y }>

Half the outline, from the bottom up: for each point, x is how far it is from the axis and y how high. At least two points. A point on the axis (x: 0) closes the shape there, as the middle of a bottle's base; a point given twice in a row is a hard edge, as the rim of the base, and so is every turn sharper than creaseAngle when one is given.

segmentsoptionalnumber

How many faces round, or across arc when it goes part of the way. Few is the faceted look of the time; many is round. Default 32. At least one for every third of a turn: 3 all the way round, 2 for half of it, 1 for a narrow slice, one face across.

startAngleoptionalnumber

Where the turn starts, in radians from +x, the way rotationY turns (a quarter, Math.PI / 2, is -z). Default 0.

arcoptionalnumber

How far round it is turned, in radians, from startAngle: Math.PI is half of it, a slice of a wheel is Math.PI * 2 / 37. Above 0 and at most Math.PI * 2, the default, all the way round. Part of the way, its two ends are left open.

creaseAngleoptionalnumber

How sharply, in radians, the profile has to turn at a point for the surface to meet there in a hard edge rather than round smoothly: with Math.PI / 6, 30°, the rim of a can is hard and the belly of a vase drawn in many points is round. Left out, it is smooth all along, because a profile is mostly a curve drawn in a few points, each turning well past 30°; the corners meant hard are given twice. (useExtrudeGeometry has one by default, as an outline in a few points is mostly a shape with corners.) Round the axis it is always smooth.

keyoptionalstring

What to keep it under. By default everything it is asked for is the name, so two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_lathe_geometry.ts:13

TMergePiecetypenacatamalon

TMergePiece: Omit<TMeshInstancePlacement, 'data' | 'tint'> & { geometry, tint }

One piece of a mergeGeometries: a shape, and where it sits in the merged one, said the way an instance of createMeshInstances is placed. Everything left out is the plain answer: at the middle, unturned, its own size, and white.

Properties

geometryTGeometry

The shape: one of a shape hook's, one made by createGeometry, or one made by another mergeGeometries.

tintoptionalindexedAccess

Its colour, painted on its corners in the merged shape and so multiplied into the material's tint and picture, as a corner colour of its own is: pieces that differ only in colour (red and black pockets, a team's shirts) then share one material and one draw. Its alpha below 1 is only seen through on a material that is transparent, or cut out with alphaCutoff.

View source · geometry/merge_geometries.ts:23

TPlaneGeometryOptionstypenacatamalon

TPlaneGeometryOptions: TGeometryUvOptions & { width, depth, widthSegments, depthSegments, key }

What usePlaneGeometry can be asked for. Everything is optional.

Properties

widthoptionalnumber

Across. Default 1.

depthoptionalnumber

Away. Default 1.

widthSegmentsoptionalnumber

How many squares across. Default 1.

depthSegmentsoptionalnumber

How many away. Default 1.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_plane_geometry.ts:13

TSphereGeometryOptionstypenacatamalon

TSphereGeometryOptions: TGeometryUvOptions & { radius, segments, rings, key }

What useSphereGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

Default 0.5, so it is one across.

segmentsoptionalnumber

Around. Default 32.

ringsoptionalnumber

From pole to pole. Default 16.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_sphere_geometry.ts:13

TTorusGeometryOptionstypenacatamalon

TTorusGeometryOptions: TGeometryUvOptions & { radius, tube, radialSegments, tubularSegments, key }

What useTorusGeometry can be asked for. Everything is optional.

Properties

radiusoptionalnumber

From the middle to the middle of the tube. Default 0.5.

tubeoptionalnumber

How thick the tube is. Default 0.2.

radialSegmentsoptionalnumber

Around the ring. Default 32.

tubularSegmentsoptionalnumber

Around the tube. Default 16.

keyoptionalstring

What to keep it under. By default every number it is asked for and how its picture is laid are the name, so two that differ in any never get mixed up and two the same are the same shape. Give one only to have a friendlier name: a name already taken gives back that shape, whatever is asked.

uvsoptionalTUvProjection

The picture places worked out from where the corners are, instead of the shape's own: 'planar' (seen from above, a floor), 'box' (each face from the side it faces, a wall, a crate), 'cylinder' (round the upright axis, a column) or 'sphere' (by longitude and latitude). See TUvProjection. A corner two faces want at two places of the picture is split in two. Left out, the shape keeps its own, described on each hook.

uvScaleoptionalnumber

With uvs, how many times the picture is laid every unit of the shape, rather than stretched once over it: 1 a picture each unit, 0.25 one every four. Two walls of different sizes then have bricks of one size. It reads the shape's own size, before the object's transform: a shape scaled up gets bigger bricks. Round an axis it is rounded to whole times, so the seam meets itself. Only with uvs: a shape's own picture places are laid once, and are not scaled.

View source · hooks/geometry/use_torus_geometry.ts:13

TUvProjectiontypenacatamalon

TUvProjection: 'planar' | 'box' | 'cylinder' | 'sphere'

How a shape's picture places are worked out from where its corners are, rather than given.

  • 'planar': seen from above, x across and z down: a terrain, a floor, a field.
  • 'box': each triangle from the side it faces most, as the six faces of a box: a rock, a building, a wall.
  • 'cylinder': once round the upright axis and down its height: a trunk, a column, a barrel.
  • 'sphere': round by longitude and down by latitude: a planet, a head.
View source · geometry/build/project_uvs.ts:14