pixelkiln 0.122.0 → 0.123.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -154,6 +154,8 @@ var VALUE_FLAGS = [
154
154
  "--size",
155
155
  "--animation",
156
156
  "--direction",
157
+ "--action",
158
+ "--view",
157
159
  "--outline-rounding",
158
160
  "--part-shapes",
159
161
  "--surface-detail",
@@ -202,7 +204,8 @@ var BOOL_FLAGS = [
202
204
  "--keep",
203
205
  "--discard",
204
206
  "--pro",
205
- "--replace"
207
+ "--replace",
208
+ "--custom"
206
209
  ];
207
210
  var COMMANDS = [
208
211
  "init",
@@ -597,7 +600,7 @@ function parseArgs(argv) {
597
600
  artist: get("--artist"),
598
601
  weight: get("--weight"),
599
602
  glyphPx: numberOption("--glyph-px", { min: 8, max: 64, integer: true }),
600
- frames: command === "normal-map" ? numberOption("--frames", { min: 1, max: 32, integer: true }) : numberOption("--frames", { min: 3, max: 15, integer: true }),
603
+ frames: command === "normal-map" ? numberOption("--frames", { min: 1, max: 32, integer: true }) : command === "estimate-skeleton" && rest.includes("--custom") ? numberOption("--frames", { min: 1, max: 15, integer: true }) : numberOption("--frames", { min: 3, max: 15, integer: true }),
601
604
  convention: get("--convention"),
602
605
  estimateLimit: numberOption("--estimate-limit", { min: 0, max: 1e3, integer: true }),
603
606
  preset: get("--preset"),
@@ -642,6 +645,9 @@ function parseArgs(argv) {
642
645
  transition: get("--transition"),
643
646
  animation: get("--animation"),
644
647
  direction: get("--direction"),
648
+ custom: rest.includes("--custom"),
649
+ action: get("--action"),
650
+ view: get("--view"),
645
651
  keep: rest.includes("--keep"),
646
652
  discard: rest.includes("--discard"),
647
653
  pro: rest.includes("--pro"),
@@ -706,6 +712,7 @@ Commands
706
712
  tag Push manifest tags to the objects upstream (free).
707
713
  balance Show the provider's remaining balance.
708
714
  estimate-skeleton <image> [--out <file>] [--frames <n>] [--force]
715
+ [--custom --description <text> --action <text> --direction <dir> --view <camera>]
709
716
  PixelLab only: derive an 18-joint skeleton from a square 16-256px
710
717
  image, direct and un-budgeted (like balance, not a generation).
711
718
  Prints, or writes with --out, a ready keypoints file for an
@@ -1704,6 +1711,8 @@ function specHash(spec, styleImageHashes, providerOptionIdentity = spec.provider
1704
1711
  enhancePrompt: spec.revision.enhancePrompt,
1705
1712
  keypointsSha256: spec.revision.keypointsSha256,
1706
1713
  skeletonTemplate: spec.revision.skeletonTemplate,
1714
+ // Only when set, so revisions made before it keep their hash.
1715
+ writeMotionFrames: spec.revision.writeMotionFrames,
1707
1716
  description: spec.revision.description,
1708
1717
  removalTask: spec.revision.removalTask,
1709
1718
  convention: spec.revision.convention,
@@ -2418,6 +2427,13 @@ var RevisionSchema = z.object({
2418
2427
  * committed files rather than inline pixel data.
2419
2428
  */
2420
2429
  keypointsFile: z.string().min(1).optional(),
2430
+ /**
2431
+ * `animate-skeleton` only: have PixelLab write this many frames (3-15) of
2432
+ * motion from the asset's prompt, starting from the keypoints file's
2433
+ * `firstFrameKeypoints`, instead of posing every frame in the file. Works
2434
+ * with the 18 joints or a custom rig; the file's `frames` may then be empty.
2435
+ */
2436
+ writeMotionFrames: z.number().int().min(3).max(15).optional(),
2421
2437
  /**
2422
2438
  * `animate-skeleton` only: the body a joint's missing `depth` is taken
2423
2439
  * from. PixelLab's default is `mannequin`; free string like `character`'s
@@ -2623,7 +2639,7 @@ var RevisionSchema = z.object({
2623
2639
  path: ["description"]
2624
2640
  });
2625
2641
  }
2626
- for (const field of ["keypointsFile", "skeletonTemplate"]) {
2642
+ for (const field of ["keypointsFile", "skeletonTemplate", "writeMotionFrames"]) {
2627
2643
  if (revision[field] !== void 0 && revision.mode !== "animate-skeleton") {
2628
2644
  context.addIssue({
2629
2645
  code: z.ZodIssueCode.custom,
@@ -3631,9 +3647,9 @@ var LockEntrySchema = z.object({
3631
3647
  paletteImageSha256: z.string().regex(/^[0-9a-f]{64}$/).optional(),
3632
3648
  dithering: RevisionDitheringSchema.optional(),
3633
3649
  ditheringStrength: z.number().min(0).max(10).optional(),
3634
- // 4-40 for animate/animate-pixminimax; animate-skeleton's own 3-15
3635
- // range extends the floor down to 3, hence min(3) here rather than 4.
3636
- frames: z.number().int().min(3).max(40).optional(),
3650
+ // 4-40 for animate/animate-pixminimax; animate-skeleton takes 3-15, and
3651
+ // 1-15 with a custom rig, hence min(1) here.
3652
+ frames: z.number().int().min(1).max(40).optional(),
3637
3653
  fps: z.number().int().min(1).max(60).optional(),
3638
3654
  lastFrameSha256: z.string().regex(/^[0-9a-f]{64}$/).optional(),
3639
3655
  direction: CharacterDirectionSchema.optional(),
@@ -5161,10 +5177,83 @@ var SkeletonFrameSchema = z2.array(SkeletonKeypointSchema).length(18).superRefin
5161
5177
  seen.add(joint.label);
5162
5178
  }
5163
5179
  });
5164
- var SkeletonSetSchema = z2.object({
5165
- firstFrameKeypoints: SkeletonFrameSchema,
5166
- frames: z2.array(SkeletonFrameSchema).min(3).max(15)
5180
+ var RIG_SIDES = ["near", "mid", "far"];
5181
+ var RigJointSchema = z2.object({
5182
+ name: z2.string().min(1),
5183
+ parent: z2.string().min(1).nullable(),
5184
+ side: z2.enum(RIG_SIDES),
5185
+ estimate: z2.enum(SKELETON_LABELS).nullable().optional()
5186
+ }).strict();
5187
+ var SkeletonRigSchema = z2.array(RigJointSchema).min(2).max(64).superRefine((rig, context) => {
5188
+ const seen = /* @__PURE__ */ new Set();
5189
+ let roots = 0;
5190
+ for (const [index, joint] of rig.entries()) {
5191
+ if (seen.has(joint.name)) {
5192
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: `joint "${joint.name}" appears twice`, path: [index, "name"] });
5193
+ }
5194
+ if (joint.parent === null) roots++;
5195
+ else if (!seen.has(joint.parent)) {
5196
+ context.addIssue({
5197
+ code: z2.ZodIssueCode.custom,
5198
+ message: `"${joint.name}" hangs from "${joint.parent}", which is not listed before it`,
5199
+ path: [index, "parent"]
5200
+ });
5201
+ }
5202
+ seen.add(joint.name);
5203
+ }
5204
+ if (roots !== 1) context.addIssue({ code: z2.ZodIssueCode.custom, message: `a rig has exactly one root joint; this one has ${roots}` });
5205
+ });
5206
+ var RigKeypointSchema = z2.object({
5207
+ label: z2.string().min(1),
5208
+ x: z2.number().min(0).max(1),
5209
+ y: z2.number().min(0).max(1),
5210
+ z_index: z2.number(),
5211
+ depth: z2.number().optional()
5167
5212
  }).strict();
5213
+ var SkeletonSetSchema = z2.object({
5214
+ rig: SkeletonRigSchema.optional(),
5215
+ kind: z2.enum(["person", "four-legged", "other"]).nullable().optional(),
5216
+ firstFrameKeypoints: z2.array(RigKeypointSchema),
5217
+ frames: z2.array(z2.array(RigKeypointSchema)).max(15).default([])
5218
+ }).strict().superRefine((set, context) => {
5219
+ const poses = [
5220
+ [set.firstFrameKeypoints, ["firstFrameKeypoints"]],
5221
+ ...set.frames.map((frame, index) => [frame, ["frames", index]])
5222
+ ];
5223
+ if (!set.rig && set.frames.length > 0 && set.frames.length < 3) {
5224
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: "18-joint poses need 3 to 15 frames (a custom rig takes 1)", path: ["frames"] });
5225
+ }
5226
+ for (const [pose, where] of poses) {
5227
+ if (set.rig) {
5228
+ const names = set.rig.map((joint) => joint.name);
5229
+ const labels = pose.map((joint) => joint.label);
5230
+ const missing = names.filter((name) => !labels.includes(name));
5231
+ const extra = labels.filter((label) => !names.includes(label));
5232
+ const twice = labels.filter((label, index) => labels.indexOf(label) !== index);
5233
+ if (missing.length || extra.length || twice.length) {
5234
+ context.addIssue({
5235
+ code: z2.ZodIssueCode.custom,
5236
+ message: [
5237
+ missing.length ? `missing ${missing.slice(0, 3).join(", ")}` : "",
5238
+ extra.length ? `not in the rig: ${extra.slice(0, 3).join(", ")}` : "",
5239
+ twice.length ? `twice: ${twice.slice(0, 3).join(", ")}` : ""
5240
+ ].filter(Boolean).join("; "),
5241
+ path: where
5242
+ });
5243
+ }
5244
+ } else {
5245
+ const result = SkeletonFrameSchema.safeParse(pose);
5246
+ if (!result.success) {
5247
+ const issue = result.error.issues[0];
5248
+ context.addIssue({ code: z2.ZodIssueCode.custom, message: issue.message, path: [...where, ...issue.path] });
5249
+ }
5250
+ }
5251
+ }
5252
+ });
5253
+ function skeletonBones(set) {
5254
+ if (!set.rig) return SKELETON_BONES;
5255
+ return set.rig.flatMap((joint) => joint.parent ? [[joint.parent, joint.name]] : []);
5256
+ }
5168
5257
  function parseSkeletonSet(json, file) {
5169
5258
  const result = SkeletonSetSchema.safeParse(json);
5170
5259
  if (!result.success) {
@@ -5178,9 +5267,13 @@ function estimateSkeletonSizeProblem(width, height) {
5178
5267
  return width === height && ESTIMATE_SKELETON_SIZES.includes(width) ? null : `${width}x${height}; estimate-skeleton takes a square image of ${ESTIMATE_SKELETON_SIZES.join(", ")} pixels`;
5179
5268
  }
5180
5269
  var DEFAULT_SCAFFOLD_FRAMES = 4;
5181
- function scaffoldSkeletonSet(keypoints, frames = DEFAULT_SCAFFOLD_FRAMES) {
5270
+ function scaffoldSkeletonSet(keypoints, frames = DEFAULT_SCAFFOLD_FRAMES, rig) {
5182
5271
  const copy = () => keypoints.map((joint) => ({ ...joint }));
5183
- return { firstFrameKeypoints: copy(), frames: Array.from({ length: frames }, copy) };
5272
+ return {
5273
+ ...rig ? { rig: rig.rig, ...rig.kind ? { kind: rig.kind } : {} } : {},
5274
+ firstFrameKeypoints: copy(),
5275
+ frames: Array.from({ length: frames }, copy)
5276
+ };
5184
5277
  }
5185
5278
 
5186
5279
  // src/attach.ts
@@ -8902,6 +8995,11 @@ var EstimateSkeletonResponseSchema = z4.object({
8902
8995
  keypoints: z4.array(SkeletonKeypointSchema).length(18),
8903
8996
  usage: z4.unknown().optional()
8904
8997
  }).passthrough();
8998
+ var CustomSkeletonResultSchema = z4.object({
8999
+ rig: SkeletonRigSchema,
9000
+ kind: z4.enum(["person", "four-legged", "other"]).nullable().optional(),
9001
+ frames: z4.array(z4.array(RigKeypointSchema.extend({ z_index: z4.number().default(0) }))).min(1)
9002
+ }).passthrough();
8905
9003
  var CharacterSubmitSchema = z4.object({
8906
9004
  background_job_id: z4.string().min(1),
8907
9005
  character_id: z4.string().min(1),
@@ -10673,9 +10771,11 @@ var PixelLabClient = class {
10673
10771
  const body = {
10674
10772
  first_frame: args.firstFrame,
10675
10773
  first_frame_keypoints: args.firstFrameKeypoints,
10676
- keypoints: args.keypoints,
10677
10774
  direction: args.direction
10678
10775
  };
10776
+ if (args.writeMotionFrames != null) body.write_motion_frames = args.writeMotionFrames;
10777
+ else body.keypoints = args.keypoints;
10778
+ if (args.rig) body.rig = args.rig;
10679
10779
  if (args.view) body.view = args.view;
10680
10780
  if (args.templateId) body.template_id = args.templateId;
10681
10781
  if (args.action) body.action = args.action;
@@ -10709,6 +10809,48 @@ var PixelLabClient = class {
10709
10809
  );
10710
10810
  return { keypoints: res.keypoints, usage: res.usage };
10711
10811
  }
10812
+ /**
10813
+ * `/estimate-custom-skeleton` (beta): builds a rig of any shape for a sprite
10814
+ * (a staff, a cape, wings, a tail) from `description` and `action`, and places
10815
+ * it on the image. A background job; this submits it and waits for the
10816
+ * result, polling every `intervalMs` (most finish in about a minute). 1
10817
+ * generation per 8 images. Measured on four sprites in November 2026: given a
10818
+ * figure "swinging the staff", it hung a three-joint staff from the wrist.
10819
+ */
10820
+ async estimateCustomSkeleton(args, wait = {}) {
10821
+ const body = {
10822
+ images: [{ type: "base64", base64: args.image.base64, format: args.image.format }],
10823
+ direction: args.direction
10824
+ };
10825
+ if (args.view) body.view = args.view;
10826
+ if (args.description) body.description = args.description;
10827
+ if (args.action) body.action = args.action;
10828
+ const submitted = validateResponse(
10829
+ RevisionJobSubmitSchema,
10830
+ await this.request("/estimate-custom-skeleton", { method: "POST", body: JSON.stringify(body) }),
10831
+ "estimate-custom-skeleton"
10832
+ );
10833
+ const sleep3 = wait.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
10834
+ const deadline = Date.now() + (wait.timeoutMs ?? 5 * 6e4);
10835
+ for (; ; ) {
10836
+ const job = await this.getBackgroundJob(submitted.background_job_id);
10837
+ if (job.status === "completed") {
10838
+ const result = validateResponse(CustomSkeletonResultSchema, job.last_response, "estimate-custom-skeleton result");
10839
+ return {
10840
+ rig: result.rig,
10841
+ kind: result.kind ?? null,
10842
+ keypoints: result.frames[0],
10843
+ jobId: submitted.background_job_id,
10844
+ usage: job.usage ?? null
10845
+ };
10846
+ }
10847
+ if (job.status === "failed") throw new ProviderError("pixellab", `estimate-custom-skeleton job ${submitted.background_job_id} failed`);
10848
+ if (Date.now() > deadline) {
10849
+ throw new ProviderError("pixellab", `estimate-custom-skeleton job ${submitted.background_job_id} is still running; it was not charged until it finishes`);
10850
+ }
10851
+ await sleep3(wait.intervalMs ?? 5e3);
10852
+ }
10853
+ }
10712
10854
  async getBackgroundJob(jobId) {
10713
10855
  const raw = await this.request(`/background-jobs/${encodeURIComponent(jobId)}`);
10714
10856
  return validateResponse(BackgroundJobSchema, raw, "background-jobs/{id}");
@@ -12275,8 +12417,12 @@ var PixelLabProvider = class _PixelLabProvider {
12275
12417
  if (width != null && height != null && (width > 256 || height > 256)) {
12276
12418
  throw new Error(`PixelLab animate-skeleton source is ${width}x${height}; the API takes at most 256 pixels per side`);
12277
12419
  }
12278
- if (frames != null && (frames < 3 || frames > 15)) {
12279
- throw new Error(`PixelLab animate-skeleton takes 3 to 15 frames; the keypoints file has ${frames}`);
12420
+ const rig = spec.revision.skeleton?.rig;
12421
+ const fewest = rig && spec.revision.writeMotionFrames == null ? 1 : 3;
12422
+ if (frames != null && (frames < fewest || frames > 15)) {
12423
+ throw new Error(
12424
+ spec.revision.skeleton && frames === 0 && spec.revision.writeMotionFrames == null ? `${spec.styleId}/${spec.assetId}: the keypoints file has no frames; add the motion's poses, or set revision.writeMotionFrames to have PixelLab write them` : `PixelLab animate-skeleton takes ${fewest} to 15 frames; the keypoints file has ${frames}`
12425
+ );
12280
12426
  }
12281
12427
  if (skeletonTemplate && !CHARACTER_TEMPLATES.includes(skeletonTemplate)) {
12282
12428
  throw new Error(`PixelLab animate-skeleton template "${skeletonTemplate}" is not one of ${CHARACTER_TEMPLATES.join(", ")}`);
@@ -13916,15 +14062,19 @@ var PixelLabProvider = class _PixelLabProvider {
13916
14062
  if (sha256(keypointsBytes) !== revision.keypointsSha256) {
13917
14063
  throw new Error(`${spec.styleId}/${spec.assetId}: revision keypoints changed after the manifest was resolved`);
13918
14064
  }
14065
+ const rig = revision.skeleton.rig;
14066
+ const templateId = revision.skeletonTemplate ?? (rig ? revision.skeleton.kind === "four-legged" ? "dog" : "mannequin" : void 0);
13919
14067
  const res2 = await this.client.animateWithSkeletonV3({
13920
14068
  firstFrame: image,
13921
14069
  firstFrameKeypoints: revision.skeleton.firstFrameKeypoints,
13922
14070
  keypoints: revision.skeleton.frames,
14071
+ ...rig ? { rig } : {},
14072
+ ...revision.writeMotionFrames != null ? { writeMotionFrames: revision.writeMotionFrames } : {},
13923
14073
  direction: revision.direction,
13924
14074
  // The style's camera, when it is one this endpoint knows; its enum is
13925
14075
  // narrower than a style's free-string `view`.
13926
14076
  ...spec.view === "side" || spec.view === "low top-down" || spec.view === "high top-down" ? { view: spec.view } : {},
13927
- templateId: revision.skeletonTemplate,
14077
+ templateId,
13928
14078
  action: spec.prompt,
13929
14079
  description: revision.description,
13930
14080
  seed: spec.seed,
@@ -17251,10 +17401,12 @@ async function resolveSpecs(loaded, filter) {
17251
17401
  // The manifest's own `frames` field stays rejected for this
17252
17402
  // mode (superRefine, types.ts) — the real frame count comes
17253
17403
  // from the keypoints file once it exists, not a manifest
17254
- // number, so plan can only know it once authored.
17255
- ...keypoints ? { frames: keypoints.skeleton.frames.length } : {}
17404
+ // number, so plan can only know it once authored. Written
17405
+ // motion has its count in the manifest instead.
17406
+ ...asset.revision.writeMotionFrames != null ? { frames: asset.revision.writeMotionFrames } : keypoints ? { frames: keypoints.skeleton.frames.length } : {}
17256
17407
  } : {},
17257
17408
  ...asset.revision.skeletonTemplate ? { skeletonTemplate: asset.revision.skeletonTemplate } : {},
17409
+ ...asset.revision.writeMotionFrames != null ? { writeMotionFrames: asset.revision.writeMotionFrames } : {},
17258
17410
  ...asset.revision.description ? { description: asset.revision.description } : {},
17259
17411
  ...asset.revision.removalTask ? { removalTask: asset.revision.removalTask } : {},
17260
17412
  ...asset.revision.convention ? { convention: asset.revision.convention } : {},
@@ -34566,6 +34718,8 @@ import { readFile as readFile50, writeFile as writeFile31 } from "fs/promises";
34566
34718
  var RIGHT = [255, 140, 40, 255];
34567
34719
  var LEFT = [60, 150, 255, 255];
34568
34720
  var CENTER = [240, 240, 240, 255];
34721
+ var FACE = [150, 150, 150, 255];
34722
+ var PROP = [255, 215, 70, 255];
34569
34723
  var GROUND = [28, 28, 34, 255];
34570
34724
  var OUTLINE = [0, 0, 0, 255];
34571
34725
  var GUTTER = 4;
@@ -34582,20 +34736,27 @@ function renderSkeletonSheet(set, options = {}) {
34582
34736
  const height = rows * cellH + (rows + 1) * GUTTER;
34583
34737
  const canvas = new Canvas(width, height);
34584
34738
  canvas.fill(0, 0, width, height, [12, 12, 16, 255]);
34739
+ const bones = skeletonBones(set);
34740
+ const stands = new Map((set.rig ?? []).map((joint) => [joint.name, joint.estimate ?? null]));
34741
+ const colorOf = (label) => {
34742
+ if (!set.rig) return labelColor(label);
34743
+ const humanoid = stands.get(label);
34744
+ return humanoid ? labelColor(humanoid) : PROP;
34745
+ };
34585
34746
  poses.forEach((pose, index) => {
34586
34747
  const left = GUTTER + index % columns * (cellW + GUTTER);
34587
34748
  const top = GUTTER + Math.floor(index / columns) * (cellH + GUTTER);
34588
34749
  canvas.fill(left, top, cellW, cellH, GROUND);
34589
34750
  if (source) canvas.drawImage(source, left, top, scale2, index === 0 ? 1 : 0.45);
34590
- drawPose(canvas, pose, left, top, cellW, cellH, Math.max(1, Math.round(Math.min(cellW, cellH) / 128)));
34751
+ drawPose(canvas, pose, bones, colorOf, left, top, cellW, cellH, Math.max(1, Math.round(Math.min(cellW, cellH) / 128)));
34591
34752
  });
34592
34753
  return encodeRgbaPng(width, height, canvas.data);
34593
34754
  }
34594
- function drawPose(canvas, pose, left, top, w, h, stroke) {
34755
+ function drawPose(canvas, pose, bones, colorOf, left, top, w, h, stroke) {
34595
34756
  const at2 = new Map(pose.map((joint) => [joint.label, joint]));
34596
34757
  const point = (joint) => [left + joint.x * (w - 1), top + joint.y * (h - 1)];
34597
34758
  for (const outline of [true, false]) {
34598
- for (const [from, to] of SKELETON_BONES) {
34759
+ for (const [from, to] of bones) {
34599
34760
  const a = at2.get(from);
34600
34761
  const b = at2.get(to);
34601
34762
  if (!a || !b) continue;
@@ -34609,7 +34770,8 @@ function drawPose(canvas, pose, left, top, w, h, stroke) {
34609
34770
  }
34610
34771
  }
34611
34772
  }
34612
- function colorOf(label) {
34773
+ function labelColor(label) {
34774
+ if (label.endsWith(" EYE") || label.endsWith(" EAR")) return FACE;
34613
34775
  if (label.startsWith("RIGHT")) return RIGHT;
34614
34776
  if (label.startsWith("LEFT")) return LEFT;
34615
34777
  return CENTER;
@@ -34679,6 +34841,7 @@ async function runEstimateSkeleton(args) {
34679
34841
  const bytes = await readFile50(path74.resolve(image));
34680
34842
  const metadata = imageMetadata(bytes);
34681
34843
  if (!metadata) throw new UsageError(`${image} is not a readable PNG or JPEG`);
34844
+ if (args.custom) return estimateCustom(args, image, bytes, metadata);
34682
34845
  const sizeProblem = estimateSkeletonSizeProblem(metadata.width, metadata.height);
34683
34846
  if (sizeProblem) throw new UsageError(`${image} is ${sizeProblem}`);
34684
34847
  const client2 = clientFromEnv();
@@ -34695,6 +34858,42 @@ async function runEstimateSkeleton(args) {
34695
34858
  log(json);
34696
34859
  }
34697
34860
  }
34861
+ var VIEWS = ["side", "low top-down", "high top-down"];
34862
+ async function estimateCustom(args, image, bytes, metadata) {
34863
+ if (metadata.width > 256 || metadata.height > 256) {
34864
+ throw new UsageError(`${image} is ${metadata.width}x${metadata.height}; estimate-skeleton --custom takes images up to 256x256`);
34865
+ }
34866
+ const direction = args.direction ?? "south";
34867
+ if (!CHARACTER_DIRECTIONS_8.includes(direction)) {
34868
+ throw new UsageError(`--direction must be one of ${CHARACTER_DIRECTIONS_8.join(", ")}`);
34869
+ }
34870
+ if (args.view && !VIEWS.includes(args.view)) {
34871
+ throw new UsageError(`--view must be one of ${VIEWS.join(", ")}`);
34872
+ }
34873
+ if (!args.description && !args.action) {
34874
+ log(" tip: --description (what it is) and --action (what it will do) tell PixelLab which parts need joints");
34875
+ }
34876
+ const client2 = clientFromEnv();
34877
+ log(" estimating a custom rig (about a minute)\u2026");
34878
+ const res = await client2.estimateCustomSkeleton({
34879
+ image: { base64: bytes.toString("base64"), format: metadata.format },
34880
+ direction,
34881
+ ...args.view ? { view: args.view } : {},
34882
+ ...args.description ? { description: args.description } : {},
34883
+ ...args.action ? { action: args.action } : {}
34884
+ });
34885
+ const frames = args.frames ?? DEFAULT_SCAFFOLD_FRAMES;
34886
+ const json = JSON.stringify(scaffoldSkeletonSet(res.keypoints, frames, { rig: res.rig, kind: res.kind }), null, 2);
34887
+ const extra = res.rig.filter((joint) => !joint.estimate).map((joint) => joint.name);
34888
+ if (args.out) {
34889
+ await writeFile31(path74.resolve(args.out), json + "\n");
34890
+ log(` wrote ${args.out}: a ${res.kind ?? "custom"} rig of ${res.rig.length} joints and ${frames} frames to edit`);
34891
+ if (extra.length) log(` joints beyond the 18: ${extra.slice(0, 12).join(", ")}${extra.length > 12 ? ", \u2026" : ""}`);
34892
+ log(` preview it with: pixelkiln skeleton-preview ${args.out} --from ${image}`);
34893
+ } else {
34894
+ log(json);
34895
+ }
34896
+ }
34698
34897
  async function runSkeletonPreview(args) {
34699
34898
  const target = args.target;
34700
34899
  let keypointsFile;