Modules / Physics & movement

interactplugin

A body working a machine, such as getting into a car, as clips played in turn on the machine's points.

Putting it in a scene

interact has no row of its own. A body's rule calls its functions on its own row, whose prefab carries "interact": null. Each interaction a machine kind has is a file of steps, a json entry of the loader. The browser half, listed after the plugins its mods name and before ik3d, draws the body on the machine's point as the page draws it and hands ik3d the limbs a step bends.

"plugins": ["loader", "scenemanager", "player", "box3d", "box3dvehicle", "anim", "interact", "ik3d", "render3d"],
"world": {
  "loader": { "assets": {
    "box3dvehicle-enter": { "type": "json", "url": "/games/drive/assets/box3dvehicle.enter.interaction.json", "preload": true },
    "box3dvehicle-exit": { "type": "json", "url": "/games/drive/assets/box3dvehicle.exit.interaction.json", "preload": true }
  } },
  "interact": {
    "kinds": { "box3dvehicle": { "enter": "box3dvehicle-enter", "exit": "box3dvehicle-exit" } },
    "mods": { "point": "box3dvehicle", "object": "box3dvehicle", "body": "anim" }
  },
  "ik3d": { "mods": { "body": "anim", "limbs": "interact" }, "kinds": {} }
}

Properties

Read from world.interact.

.kinds : { [machine kind]: { [interaction]: entry } }

The interactions a machine of each kind has, each the name of the loader json entry of its file. A kind or a name not listed has no interaction.

.mods : { point, object?, body? }

The plugins that say where a machine's points are and that hand the drawn body (see Mods). point is required by every interaction. object is required when a step bends limbs or a body is named. Without body, the body is drawn where its row stands.

The interaction file

Named <machine>.<interaction>.interaction.json beside the machine's model. A file out of shape throws naming the interaction and the field, the first time it is read and whenever its content changes.

KeyMeaning
bodyThe anim kind that plays it, a name. The clips are read from the rig of the row that plays it.
stepsThe steps, played in order, at least one. Each is described below.
Step keyMeaning
nameUnique in the interaction. A game reads it with stepOf to do what the machine does meanwhile, such as kneeling or opening a door.
clipThe clip of the body's rig the step plays, as an anim act that holds. The step lasts the clip's measured length.
atThe machine's point the body's root, its feet, stands at on every step.
turnOptional, degrees, positive left: the body faces the point's frame's yaw turned this far. 0 when left out.
travelOptional, "from" or "to": the step carries its clip's measured travel in the point's frame, scaled by the clip's scale, its turn kept only where anim keeps a one-shot's turn. "from" starts the body at the point facing turn and goes where the clip takes it. "to" ends it at the point facing turn at the clip's end, starting wherever that puts it. Without it the body stays on the point.
holdOptional: true makes the step last until end is called. Only the last step may hold, and a step that holds may not travel. An interaction whose last step does not hold ends when that step's clip does.
ikOptional: [{ bones, target, pole }], limbs bent while the step lasts, each as an ik3d limb, with target a point of the machine. pole is not zero.

The row

The field interact keeps on the body's row.

FieldMeaning
interactnull when the body is in no interaction, else { machine, kind, name, step, t }: the machine's row id and kind, the interaction's name, the index of the step it is in, and the seconds it has been in it.

While it is in one, the body is placed on every begin and advance: its root at the step's point, or where its travel has it, facing the point's yaw turned by turn, with vel zero and grounded true, through the fields its anim kind's reads names.

On the page

The page draws a machine moving in ways no rule sees, such as a walker's bob or a car rolling on its springs. So in its tick, and again after every plugin's tick, interact moves each drawn body in an interaction onto its step's point as drawn: at the point object's world place, or moved along that frame's x and z as far as the clip's travel has taken it, and turned as the frame is and then by the step's turn and the travel's turn. The tick uses the points as drawn the frame before, so an actor's tick reads the body on the machine, and the second pass uses this frame's. The props hung on the body move with it, and its scale is kept. A body that is limp, or whose point is not drawn, is left where its plugin drew it.

Methods

From #plugins/interact/interact.sim.ts. me is the body's row and machine the machine's row.

begin( me, w, machine, name )

Starts the machine's interaction name at its first step: the step's clip played from 0 and the body placed. Throws for an interaction the machine's kind has not.

advance( me, w, dt ) : { name, done } | undefined

Called by the body's rule each step it is in an interaction, after the machine has moved. t goes up by dt seconds. A step whose clip has run its length gives way to the next, whose clip is played from 0 with the time past the end carried into it. Past a last step that does not hold, the interaction ends with the body where that step left it. Returns the step it is in and whether the interaction ended this step, or undefined when the body is in none. A machine whose row has ended ends the interaction, with done true.

end( me, w )

Ends the interaction where it is: interact is set to null and anim's act is stopped, so the body is back in its gears.

stepOf( me, w ) : string | undefined

The name of the step the body is in, or undefined when it is in none.

startOf( w, me, machine, name ) : { at, yaw }

Where the interaction stands the body as it begins: its first step's point and turn, moved back along the clip's travel when that step travels "to". at is [x, y, z] in metres and yaw the facing in radians. A game stands the body there before it calls begin, and measures how near the body is from it. Throws for an interaction the machine's kind has not.

placeOf( w, machine, name ) : { at, yaw }

The world place of the machine's point name this step, through the point mod. Throws for a point the machine has not.

travelOf( from, me, step, t ) : { at, yaw }

Where a step has the body at t seconds into it, in the point's frame: at is [x, z] in metres along the frame's x and z, and yaw is radians left of the frame's facing. A step that does not travel gives [0, 0] and its turn. from is a rule's w or a page's plugins.wire.

interactionOf( w, kind, name ) : Interaction | undefined

The interaction name of machines of kind, its file read and checked, or undefined when the kind has no such one.

check( file, where )

Checks an interaction file and throws a sentence that names where and the field out of shape.

Mods

Name them in world.interact.mods. Each plugin named is listed before interact in the scene's plugins.

  • box3dvehicle
    point and object, the points of a car's look.points, each in the chassis's frame, for getting in, driving and getting out. point(w, car, name) → { at, yaw } is the chassis row's pos plus the point's at turned by the chassis's rot, with a point on the steering wheel taken with the wheel straight, and yaw the chassis's facing about world up. Before the car's first step it is taken from the car row's own pos and rot. object(plugins, car, name) is the empty the page draws for the point this frame, undefined while the car is not drawn. Both are undefined for a name the look has not.
  • anim
    body: (plugins, row) → { root, props, limp }, the model anim draws for the row, the props it has hung on it, and whether it lies limp. Undefined for a row anim does not draw, or whose model is not built yet.

A game that draws its own machines gives point, (w, machine, name) → { at, yaw }, and object, (plugins, machine, name) → Object3D | undefined, the drawn twin of the point: with the machine drawn as its row stands, the object is at the point's place and its parent is turned to the point's yaw.

interact gives one mod.

  • ik3d
    limbs: name it in world.ik3d.mods as { limbs: "interact" }. The limbs the row's current step bends, each reaching the object of its point as the object mod hands it this frame. A point not yet drawn is left out, so its limb stands as the clip draws it until it is.