Skip to content

BlobscapeLesson 22 of 24

Your first creature

Every creature on this site is a few shapes and a few bones, written in code. Here is the smallest: a slug on two bones. What does a shape need to be told before it bends with a bone?

Things to try

  1. Try nowTry now: Make the tail bend with its boneHint: The bone turns already. Look at what the skin listens to.
  2. Up nextLater: Bend the tail hard with no crease where it joins
  3. Up nextLater: Let the tail swing behind as the slug turns

Starting the splat engine…

6,236 blobs on 2 bones. Where the tail joins, the skin has pulled 0.0 blobs apart.

0 of 3 goals done.

Skin the shape, cut into blobs

bones: the skin listens to
Blobs

Pose bones turned

Move a pose from the time

What you just saw

Shapes, bones, and who listens to whom

blob = Σ weight × bone × rest
restwhere the blob was cut, on the gridbonehow far each bone it listens to has turned and movedweightits share of each bone, from how near it sits: blend sets how far that reaches

The engine makes a creature the way the pixel scenes are made. Shapes are distance functions, a grid is laid through them, and every cell on a surface becomes one blob, colored and shaded where it sits. Each part of the creature names the bones that move it, and each of its blobs takes a share of those bones by how near it is.

A bone no part names moves nothing, so the tail bone turned and the slug didn’t notice. Named, but with each blob given wholly to its nearest bone, the skin folds where one bone hands over to the other. Let a weight reach a little way and the blobs near the join take some of each, turn part of the way, and the bend runs smoothly round.

A pose is just bones turned, from the time, and the engine moves every blob on the graphics card from them. The swing sits on top of that: the tail’s end is pulled toward where the pose puts it, loosely, with a little weight, so it trails, overshoots and settles. Nothing in the move changed.

Take it with you

This slug, as code

The same slug, with the settings you chose, written with the engine package. Paste it into a page with a canvas, with three.js installed.

Install it with npm install @blobscape/engine three.

import { Stage, sculptToCount, smooth, ellipsoid, sphere, cone, set, Y, type Bone } from '@blobscape/engine'

// two bones: the body, and the tail hanging from it
const bones: Bone[] = [
  { name: 'body', parent: -1, head: [0, 0.3, -0.1], tail: [0, 0.3, 0.55] },
  { name: 'tail', parent: 0, head: [0, 0.3, -0.1], tail: [0, 0.22, -0.95] },
]

// shapes on a grid: every cell on a surface becomes one blob, tied to the bones its part lists
const slug = sculptToCount(() => ({
  bones,
  blend: 0.02, // how far a blob's weight spreads from a bone
  parts: [
    // the skin: body, head and tail as one shape
    { shape: smooth(0.12, ellipsoid([0, 0.3, 0.15], [0.22, 0.2, 0.42]), sphere([0, 0.42, 0.5], 0.17), cone([0, 0.3, -0.1], [0, 0.22, -0.95], 0.17, 0.03)), color: [0.93, 0.62, 0.28], bones: ['body'] },
    // the eyes
    { shape: sphere([0.08, 0.5, 0.62], 0.04), color: [0.1, 0.08, 0.1], bones: ['body'] },
    { shape: sphere([-0.08, 0.5, 0.62], 0.04), color: [0.1, 0.08, 0.1], bones: ['body'] },
  ],
}), 6000)

const stage = await Stage.start(document.querySelector('canvas')!)
stage.setActor(slug)
stage.orbit = { target: [0, 0.3, 0], distance: 3, azimuth: 60, elevation: 25 }
// a pose is bones turned, from the time
stage.setPoser((sk, t) => {
  sk.reset()
  set(sk, 'body', Y, 0.9 * Math.sin(t * 2.4))
  sk.update()
})