Paperdoll layers

Held items and accessories

There are two ways to put something in a character's hand, and they suit different things.

Placed (attach)Inpainted (region: "around")
Good forRigid items: swords, shields, tools, lanternsSoft or worn ones: capes, packs, scarves
The item across framesThe same pixels in every frameRedrawn per frame; consistent, with drift
Which handThe one you name, alwaysWhichever the model draws; it can swap
CostFree once the item and the anchors exist; one inpaint more with grasp10 to 25 generations per item
Reuse on another characterYes, the same item filesNo, redrawn for each
Fingers over the gripWith grasp, for one inpaintSometimes
An arm that reachesNoSometimes

Placed: a sprite pinned to the hand

A layer with attach draws nothing. It takes a sprite of the item for each direction, finds the hand in every frame, and writes the same per-frame layer files an inpainted layer does.

"hero.sword": {
  "layer": {
    "of": ["hero", "hero.walk.south", "hero.walk.east"],
    "attach": { "item": "items/sword-{direction}.png", "anchors": "anchors/hero.json" }
  }
}

It needs two things on disk first.

The item, one PNG per direction the frames face, named with the direction: items/sword-south.png, items/sword-south-east.png and so on. The run on this page used PixelLab's 8-direction object tool at 32px (10 generations, quoted) and its exported rotations as they came. Any sprites will do, including ones you drew. Without {direction} in the path, one image is used for every direction.

Draw the item the way it is held. An object generated upright stands straight up out of the fist. The description that worked:

steel longsword with a brown leather grip and brass crossguard, held at an
angle: the grip is at the bottom and the blade leans forward at 45 degrees,
tip pointing forward and up, no hand, no character

It came back leaning toward each of its 8 facings, which is the way the character holding it faces:

An armoured character turning through eight directions, its greatsword leaning the way it faces

The anchors file, which is every frame's skeleton and so where its hands are (see Skeletons and rigging for how it relates to the other skeletons):

pixelkiln anchors hero.sword

That is one PixelLab skeleton estimate per frame at 0.1 generation each, a direct call outside the plan and budget like estimate-skeleton. It is paid once per character, not per item: every item the character holds reads the same file. Run it again after adding or regenerating a loop and it estimates only the frames that are new or changed. --dry-run counts them first.

Then pixelkiln gen places the item, at no cost. Measured: 56 frames (8 rotations, a 6-frame walk in 8 directions) cost 5.6 generations to anchor by the published price and nothing to place, and the sword stayed in the right hand in all 56.

Six frames of the armoured character walking toward the viewer, the greatsword in its right hand and a shield in its left

How it is placed, and what to change when it is wrong:

  • The hand is a little past the skeleton's wrist, along the forearm. joint picks right-hand (default) or left-hand.

  • The grip is the point of the item that goes on the hand. By default it is the middle of the item's lowest fifth, which is the handle of anything drawn handle-down, upright or leaning. A shield is held by its middle: "grip": "center". For anything else, name the point in the item's own pixels, "grip": [16, 20], or one per direction as { "south": [16, 20], "east": [12, 20] } when they differ.

  • The size. An object generator fills its canvas, so an item often comes back bigger than the hand it goes in. "scale": 0.7 resizes it before placing, nearest-neighbour, so no new colours appear. Shrinking drops rows and columns outright: fine for taking an item down a size, rough on fine detail. An item drawn at the size you want is crisper.

  • In front or behind. The skeleton says whether each hand is on the near or far side of the body. On the far side, the item's pixels under the figure are left out of the layer, so the body covers it. depth forces "front" or "behind" for every frame.

  • tilt and lean turn an item that was drawn upright, in degrees, nearest-neighbour so no new colours appear. tilt leans it the way the figure faces, which shows from the side; lean tips it outward from the body, which shows from the front and back. "tilt": 40, "lean": 15 made an upright sword read as held. A sprite drawn already leaning is crisper than a turned one, and wants both left at 0.

  • One frame is off. Open the anchors file, find the frame under its asset and role, and add a place for the joint, in frame pixels:

    "frame-03": { "sha256": "…", "width": 64, "height": 64, "keypoints": [ … ],
                  "place": { "right-hand": { "x": 19, "y": 41, "behind": false, "angle": -10 } } }
    

    angle turns the item for that frame alone. The correction survives re-running pixelkiln anchors for as long as the frame itself does.

The layer fails, naming the frame, when a frame has no anchor or has changed since its anchor was estimated: an item pinned where the old pose had its hand is worse than no item.

A placed item's canvas is its source frame's grown by padding, 12 by default. When part of the item falls outside it, gen says how many pixels were lost; raise padding.

A shield in the left hand was run the same way:

"attach": { "item": "items/shield-{direction}.png", "anchors": "anchors/hero.json",
            "joint": "left-hand", "grip": "center", "scale": 0.7 }

It was placed on all 56 frames for nothing, face-on from the front, its back and straps from behind. Two things it showed. The 32px object came back 28 pixels across on a figure about 25 wide, which is what scale is for; at 0.7 it sits on the arm in proportion, its rim a little rougher. And facing east the left arm is on the far side, so the body hides all but a sliver of the shield through that whole walk, which is correct and may not be what you want; "depth": "front" overrides it.

Closing the hand around it. A placed item rests on the hand. grasp has the provider draw the grip, and nothing else:

"hero.sword": {
  "prompt": "a black greatsword with a red leather grip",
  "layer": {
    "of": ["hero", "hero.walk.south", "hero.walk.east"],
    "attach": { "item": "items/sword-{direction}.png", "anchors": "anchors/hero.json", "grasp": true }
  }
}

The item is placed as before and pasted onto the keyed sheet. The mask is a small disc at each hand, 7 pixels in radius on a 64px frame, and black everywhere else, so the blade, the body and every other frame's item come back exactly as they went in. Inside the disc the provider draws a fist on a handle that is already there. The layer is then the placed item with each disc replaced by what came back:

  • pixels that are not skin are the item, redrawn where the fist meets it;
  • skin drawn where the item was is a finger across the handle, and goes into the layer in the figure's own skin colour, matched by brightness;
  • any other skin is the hand and body the frame already has, and is left out, so the layer never paints skin over a sleeve or a trouser leg.

A frame whose hand is behind the body gets no disc and keeps its placed item.

grasp makes the layer a paid one: one inpaint, priced by the sheet like any other layer, and stale whenever the item, the anchors or a source frame changes. The optional prompt tells the provider what the item is. "grasp": { "radius": 9 } widens the disc for a bigger hand or a thicker handle. The fingers are skin: over a layer that puts a glove on that hand they will not match it.

What a placed item still cannot do: the arm does not move to carry it. For a swing or a block, animate the character making the motion empty-handed, and the item follows the hand.

Inpainted: drawn onto the frames

"region": "around" masks everything below the neck, empty space included, and leaves the head black: room beside the body for a cape or a pack, or for an item you want the model to fit to the pose.

"hero.sword": {
  "prompt": "Give every cyan mannequin on this spritesheet the same steel longsword with a brown leather grip and brass crossguard, held in its right hand, blade pointing up and slightly outward. Draw it correctly for the direction each figure faces. Keep the sword the same length, shape and colours in every cell. Do not change the cyan bodies: keep every body, arm, leg and pose exactly as it is and keep the skin cyan. Do not add clothes, armour, hats, hair, shields or extra characters.",
  "layer": { "of": ["hero", "hero.walk.south", "hero.walk.east"], "region": "around", "padding": 12 }
}

Measured on 20 frames with 12px of padding: the sword kept its length, shape and colours in all 20, and was drawn correctly for each of the 8 directions.

Which hand is not reliable. In the south-facing walk the sword was in the character's right hand for 4 frames and its left for 2. The east walk held it on one side for all 6. This is the same handedness problem PixelLab's animation tools have, and a mask does not fix it. A placed item does.

Nor is which way the item faces. A shield inpainted on the same 20 frames (25 generations, quoted) was right from the front, with the arm drawn through its straps, which a placed item cannot do. In the east-facing walk it was drawn edge-on in 1 frame and face-on, as if seen from the front, in the other 5.

Worn items are where this works best. A cloak and a backpack were each inpainted over the same 20 frames (15 generations each, quoted) and came back right in every one: the cloak covering the back from behind, showing only its clasp and edges from the front, and swaying with the walk; the pack on the back, its straps across the chest from the front, standing out behind in profile. The body fixes where a worn thing goes, so the model has nothing to guess.

Small held items look natural and are not reliable. A lantern in the left hand (15 generations, quoted) was drawn well wherever it was drawn once, hung from the hand and lit. It was also on the other side for part of the south-facing walk, and drawn twice in a few frames, the last two of the east-facing walk among them. Nothing tells a model which hand, so it is the sword's problem again.

Layers are tidied. Given room around the figure, a provider redraws stretches of the body's outline a pixel off, leaves dark blots where it redrew an eye or a shadow, and lets a long blade run into the next cell. The cut step drops:

  • dark pixels that neither border a coloured layer pixel nor sit in a solid 2×2 block (outline scribbles; this is also what removes the wire figure from a partial outfit),
  • fragments with no coloured pixel at all, under 40 pixels (blots),
  • for head and around layers, fragments under 8 pixels, and fragments under 20 that touch their cell's edge (specks, and tips bleeding in from the next cell). A body layer's cells are cut to the figures, so there it is only fragments under 4 pixels.

An item smaller than 8 pixels does not survive an around layer. Give it a hand-made mask and the body region instead.

A blade longer than the padding still crosses into the next cell, and one such fragment survived in 20 frames. Raise padding until the item fits.