Skip to main content

Module cook

Module cook 

Source
Expand description

Compile authored worlds into runnable Worlds, entirely in memory.

Requires the cook feature, which is off by default: the importers this module needs are build-time weight a shipped application does not carry.

An application declares what it wants – a texture from this file, a room of that size – and the runtime plays only the finished result. This module is the step between: it checks the declarations, expands the ones that stand for several assets, prepares each asset’s data, and then either assembles a World to run straight away or writes the result to a file for a later run to play. Prepared payloads are cached under the build root a host installs – the dev CLI’s is .concinnity/ inside the project – so a second compile with unchanged sources skips the expensive work. A process that installed none has nowhere to cache and prepares them every time.

§The authoring vocabulary

This module is also the other half of the asset vocabulary: the types a world declares and the cook consumes, which never reach a running world as components. Those are the build-only assets it expands (Prefab, MainMenu, CharacterSchema, …) and the resources it prepares (Texture, Mesh, Material, Font, …). The stored half is components.

Five assets are authored as something other than what they bake into, and are named here for the asset they declare: cook::AppConfig, cook::Camera3D, cook::File, cook::Room, and cook::Spawner are the authored forms of the components of the same name. That makes those five names ambiguous when both namespaces are glob-imported, so glob components and path-qualify this module.

§Declaring a world in code

Each asset is declared by its own authored struct, so the type is carried by the value rather than spelled as a string:

use concinnity::App;
use concinnity::components::DirectionalLight;
use concinnity::cook;

fn main() {
    let world = cook::world()
        .add("sun", DirectionalLight {
            color: [1.0, 0.96, 0.86],
            direction: [-0.35, 0.85, 0.35],
            intensity: 2.2,
        })
        .add("room", cook::Room {
            size: Some([16.0, 20.0, 5.0]),
            ..Default::default()
        })
        .compile()
        .expect("the declared world compiles");

    App::from_world(world).run().expect("the app runs");
}

A field that references another asset holds a resolved handle rather than a name, so the name is given alongside the value with reference:

cook::world()
    .add("stone", cook::Material { roughness: 0.9, ..Default::default() })
    .add("pillar", Prop::default())
    .reference("material", "stone");

Most assets are plain runtime components, so one needing no preparation can equally be added straight to a World with add_component. A Room is what this module is for: its geometry is generated here, and its texture names become the handles the runtime reads, neither of which exists beforehand.

§Compiling ahead of time

write_blob takes the same declarations and writes them to a file instead of building a world. That file is a blob: the compiled form of a world, holding the components and the prepared asset data together. Producing one moves the preparation to a build tool, off every launch. The shipped application plays it with App::from_blob and needs neither this module nor the importers behind it.

cook::world()
    .add("sun", DirectionalLight::default())
    .write_blob("data/0")
    .expect("the world is written to data/0");

Structs§

AppConfig
Names, identifies, and sizes the application.
AudioClip
A baked audio clip: the sound an AudioEmitter plays.
Camera3D
Authored fields of a Camera3D; the runtime view matrix and per-frame input intent are not declared.
CameraShot
A reusable Camera3D preset: reference it from a Scene’s camera_shot, or use it standalone.
CharacterCapsule
A kinematic character capsule for a SkinnedMesh, in world units (after the mesh’s scale).
CharacterModel
A character body that conforms to a CharacterSchema.
CharacterSchema
The contract between a character body and everything that uses it.
ColorLut
A 3D colour-grading lookup table applied as a final post-process step. The build bakes the source into a colour cube; the graded result is blended over the image by PostProcessConfig’s lut_strength.
CubemapTexture
A six-face HDR cubemap baked from an equirectangular Radiance HDR source.
EnvironmentMap
A baked lighting environment built from an equirectangular source (or a built-in generator). It provides the scene’s ambient image-based lighting (soft diffuse fill plus glossy reflections that follow surface roughness) and the on-screen sky.
File
Authored fields of a File.
Font
Rasterises a TrueType font into a glyph atlas at build time.
LightRig
A named grouping of lights.
MainMenu
A ready-made menu declared in a single line.
MainMenuItem
One entry in a MainMenu.
Material
A Material bundles the surface parameters that control how a Prop is lit and shaded.
MaterialPalette
A named set of Material entries with short aliases.
Mesh
Raw geometry. Supply vertices and indices directly, or import them from a binary glTF file with source + primitive_index.
MorphDelta
One morph-target vertex delta: offsets added to the bind-pose position and normal, scaled by the target’s weight at runtime.
OptionSelect
A settings row that cycles through a fixed set of values on click.
PaletteEntry
One entry in a MaterialPalette. Each carries an alias (the suffix of the expanded Material name) plus the Material fields the expansion fills in. Names in albedo / normal_map are unresolved Texture references, resolved on the expanded Material.
Panel
A titled background container for grouping UI overlay elements.
PanelSection
One panel section: a caption over the rows of the listed regions.
Prefab
A reusable template of Props, PointLights, and nested prefabs.
PrefabEntry
One entry in a Prefab’s props list. The fields consulted depend on kind: a prop uses the render / collision / transform fields, a point_light uses the light_* fields, and a prefab uses prefab. Names in model / mesh / material / texture / parent / prefab are unresolved references to other assets, resolved when the entry expands.
ProportionGroup
A proportion slider: one value in [-1, 1] written as a scale and / or length change on every listed joint.
Room
Authored fields of a Room; the resolved dimensions and payload locator are runtime state.
SceneImport
Imports a 3D scene file as a single declaration.
SchemaJoint
One joint the schema expects in a conforming skeleton.
SchemaKey
One shape key the schema knows, authored on the source or synthesized.
SchemaRegion
A named group of joints. A vertex belongs to a region by the skin weight it gives the region’s joints.
ShapePreset
A named slider vector the panel offers as a button.
SkeletonJoint
One joint of a skeleton’s bind pose.
SkinnedMesh
A skeletally animated mesh placed directly in the world.
SkinnedVertexData
One vertex of a skinned mesh. Beyond position / colour / uv it carries up to four joint bindings: joints[k] indexes the skeleton, weights[k] is its blend weight. Weights are normalised at build time.
Slider
A settings row that sets a continuous value by dragging a handle along a track.
Spawner
Authored fields of a Spawner; the runtime accumulator is not declared.
StoryImport
Imports a Markdown story file as a single declaration.
SynthParams
Generator parameters for a synthesized target. Each generator reads the fields it needs and ignores the rest.
SynthesizedTarget
A morph target the build generates from the mesh instead of reading from the source.
Texture
A 2D texture image.
VertexData
A single vertex as supplied in raw Mesh args.
WorldBuilder
A world under construction: typed authored assets, compiled together into a runnable World or a blob file.

Enums§

KeyPolarity
Whether a shape key is one target or a + / - pair.
PrefabKind
Which kind of asset a PrefabEntry expands into.
SettingsProfile
Which settings screen a MainMenu’s "settings" item builds.

Traits§

Authored
The authored-value trait: the bridge from a typed authoring struct to the world line that declares it. Implemented for every declarable asset’s args schema (the args: override where the authored form diverges from the component, the component itself where it does not) and for every resource asset, so a caller hands the cook a typed value instead of a name/type/args triple assembled by hand.

Functions§

world
Start an empty world.