dsh-game-material-master 0.3.0 → 0.6.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/lib/spine.js CHANGED
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import { createHash } from "node:crypto";
26
26
  import { buildRigMesh, buildWaveDeform } from "./rigmesh.js";
27
- import { pathSegmentLengths } from "./rigpath.js";
27
+ import { normalizePath, pathTotalLength, spinePathGeometry } from "./rigpath.js";
28
28
  // ── 拆件槽位定义 ────────────────────────────────────────────────────────
29
29
  /**
30
30
  * 默认拆件网格:4 列 × 4 行 = 16 个标准人形部件,按阅读顺序排列。
@@ -225,15 +225,10 @@ function round(value, digits) {
225
225
  /**
226
226
  * 挂点:有网格就出 `mesh`,否则出 `region`。
227
227
  *
228
- * **网格顶点用「部件中心为原点」的坐标**,与 region attachment 的 `-w/2, -h/2` 同一套系——
229
- * 这样运行时两种附件共用同一条变换链(骨骼世界矩阵 → 挂点 x/y/rotation → 顶点),
230
- * 不必为 mesh 另写一套定位逻辑。`buildRigMesh` 那边用的是「左上角为原点」,
231
- * 转换就发生在这里,且只发生一次。
232
- *
233
- * 暂时**不写 `weights`**:那是 LBS(多骨骼线性混合蒙皮),格式在两条导出路径里都绕
234
- * (Spine 的加权顶点是 `[骨骼数, (索引, x, y, 权重)…]` 的交错数组),而它解决的问题是
235
- * 「一块贴图被多根骨骼共同拉扯」——FFD 时间轴已经把「裙摆上缘不动、下缘甩出去」这件事
236
- * 做到了,先把能验证的那条链路走通。`RigMesh` 已经产出权重,接进导出是独立的一步。
228
+ * buildRigMesh 用图片左上角为原点、Y 向下;导出时先转到图片中心、Y 向上,
229
+ * 再烘附件变换。转换只发生一次,UV 不随动画或骨骼变换改变。
230
+ * Spine 的 mesh 不读取 region 的 x/y/rotation:非加权顶点必须烘到所属骨骼局部系,
231
+ * 加权顶点则烘到每根影响骨骼的局部系。UV 始终保留原图的 Y 向下顺序。
237
232
  */
238
233
  /** 每个变形循环采样几个关键帧。6 段对「裙摆左右摆」这种低频运动足够。 */
239
234
  export const ANIMATION_DEFORM_SAMPLES = 6;
@@ -258,15 +253,27 @@ function meshAttachmentOf(name, part, attachment, spec, context) {
258
253
  height: Math.max(1, part.height),
259
254
  cols: spec.cols,
260
255
  rows: spec.rows,
261
- bones: context.imageBones,
256
+ // 权重在未旋转的图片局部系里计算;把骨骼位置逆回同一套系,距离才与
257
+ // 实际旋转后的顶点一致(直接拿 world 图片坐标会给斜着的部件算错权重)。
258
+ bones: context.imageBones.map((bone) => {
259
+ const rad = -((part.rotation ?? 0) * Math.PI) / 180;
260
+ const cx = part.x + part.width / 2;
261
+ const cy = part.y + part.height / 2;
262
+ const dx = bone.x - cx;
263
+ const dy = bone.y - cy;
264
+ return { name: bone.name, x: cx + Math.cos(rad) * dx - Math.sin(rad) * dy, y: cy + Math.sin(rad) * dx + Math.cos(rad) * dy };
265
+ }),
262
266
  x: part.x,
263
267
  y: part.y
264
268
  });
265
269
  if (grid === undefined)
266
270
  return attachment;
267
271
  const vertices = [];
272
+ const attRad = (attachment.rotation * Math.PI) / 180;
268
273
  for (let i = 0; i < grid.vertices.length; i += 2) {
269
- vertices.push(round(grid.vertices[i] - part.width / 2, 3), round(grid.vertices[i + 1] - part.height / 2, 3));
274
+ const x = grid.vertices[i] - part.width / 2;
275
+ const y = part.height / 2 - grid.vertices[i + 1];
276
+ vertices.push(round(Math.cos(attRad) * x - Math.sin(attRad) * y + attachment.x, 3), round(Math.sin(attRad) * x + Math.cos(attRad) * y + attachment.y, 3));
270
277
  }
271
278
  const base = {
272
279
  ...attachment,
@@ -313,7 +320,7 @@ function buildWeightedVertices(mesh, part, attachment, context) {
313
320
  const out = [];
314
321
  for (let i = 0; i < mesh.vertices.length / 2; i++) {
315
322
  const localX = mesh.vertices[i * 2] - halfW;
316
- const localY = mesh.vertices[i * 2 + 1] - halfH;
323
+ const localY = halfH - mesh.vertices[i * 2 + 1];
317
324
  const attX = cosA * localX - sinA * localY + (attachment.x ?? 0);
318
325
  const attY = sinA * localX + cosA * localY + (attachment.y ?? 0);
319
326
  const worldX = cosB * attX - sinB * attY + owned.x;
@@ -348,6 +355,32 @@ function buildWeightedVertices(mesh, part, attachment, context) {
348
355
  function num(value, fallback) {
349
356
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
350
357
  }
358
+ /** 图像局部位移 → Spine 顶点位移;加权网格每个影响骨骼各占两个数。 */
359
+ function spineDeformOffsets(offsets, part, attachment, bones, world) {
360
+ const result = [];
361
+ const imageAngle = -(part.rotation ?? 0) * Math.PI / 180;
362
+ const imageCos = Math.cos(imageAngle), imageSin = Math.sin(imageAngle);
363
+ const weighted = attachment.vertices.length !== attachment.uvs.length;
364
+ let cursor = 0;
365
+ for (let vertex = 0; vertex < offsets.length / 2; vertex++) {
366
+ const dx = offsets[vertex * 2], dy = -offsets[vertex * 2 + 1];
367
+ const wx = dx * imageCos - dy * imageSin, wy = dx * imageSin + dy * imageCos;
368
+ const append = (name) => {
369
+ const angle = -(world.get(name)?.rotation ?? 0) * Math.PI / 180;
370
+ result.push(round(wx * Math.cos(angle) - wy * Math.sin(angle), 4), round(wx * Math.sin(angle) + wy * Math.cos(angle), 4));
371
+ };
372
+ if (!weighted)
373
+ append(part.name);
374
+ else {
375
+ const count = attachment.vertices[cursor++];
376
+ for (let influence = 0; influence < count; influence++) {
377
+ append(bones[attachment.vertices[cursor]]?.name ?? part.name);
378
+ cursor += 4;
379
+ }
380
+ }
381
+ }
382
+ return result;
383
+ }
351
384
  ;
352
385
  function has(bones, ...names) {
353
386
  return names.some((name) => bones.has(name));
@@ -814,8 +847,8 @@ function normalizeAngle(value) {
814
847
  * 核心:把「每个部件的像素框 + 层级」变成一份可动画的骨架。
815
848
  *
816
849
  * 对每个部件:
817
- * 1. 取近端/远端锚点,得到世界坐标下的骨骼原点与朝向(Spine 的 0° 指向 +Y,
818
- * 所以朝向向量 (dx,dy) 对应 `atan2(-dx, dy)`)。
850
+ * 1. 锚点先随装配角度绕图片中心旋转,再转到世界坐标;Spine 的 0° 指向 +X,
851
+ * 所以朝向向量 (dx,dy) 对应 `atan2(dy, dx)`。
819
852
  * 2. 骨骼 x/y 换算到**父骨骼的局部坐标系**里(spine-core 会先转父骨骼再平移)。
820
853
  * 3. 挂点用「图片中心 − 骨骼原点」再逆旋转到骨骼局部系,并用 `rotation`
821
854
  * 补偿骨骼朝向——这样**初始姿态和装配结果逐像素一致**,而动画一开始,
@@ -841,6 +874,9 @@ export function buildSkeleton(options) {
841
874
  // ① 语义层显式指定的父级优先。它可能指向一个被隐藏/未生成的部件——
842
875
  // 那种情况下不能让骨架断链,所以继续走 ②。
843
876
  const explicit = byName.get(name)?.parent;
877
+ // null 表示用户显式选择 root;undefined 才表示没有语义、需要按名字兜底。
878
+ if (explicit === null)
879
+ return "root";
844
880
  if (explicit !== undefined && explicit !== name && boneNames.has(explicit))
845
881
  return explicit;
846
882
  // ② 按名字关键词沿语义链往上找第一个真实存在的骨骼。
@@ -908,9 +944,11 @@ export function buildSkeleton(options) {
908
944
  warnings.push(`骨骼 ${name} 的兜底宿主 ${parent} 也在环上,改挂到 root`);
909
945
  parent = undefined;
910
946
  }
947
+ // 系统 root 是唯一没有父级的骨骼;普通部件即便挂 root 也要写出这个父级。
948
+ // 官方两骨 IK 要求链首骨有父骨,省略字段会把部件变成第二根系统根。
949
+ parent = parent ?? "root";
911
950
  resolvedParent.set(name, parent);
912
- if (parent !== undefined)
913
- visit(parent, stack);
951
+ visit(parent, stack);
914
952
  }
915
953
  else {
916
954
  resolvedParent.set("root", undefined);
@@ -934,6 +972,15 @@ export function buildSkeleton(options) {
934
972
  * 拿到子部件的近端坐标,而拓扑序里子部件排在后面。
935
973
  */
936
974
  const proxWorldOf = new Map();
975
+ const anchorWorldOf = (part, anchor) => {
976
+ const rad = ((part.rotation ?? 0) * Math.PI) / 180;
977
+ const dx = (anchor[0] - 0.5) * part.width;
978
+ const dy = (anchor[1] - 0.5) * part.height;
979
+ // 装配角度是图片坐标中的顺时针角度;像素转换到 Spine 后旋转符号会反过来。
980
+ const px = part.x + part.width / 2 + Math.cos(rad) * dx - Math.sin(rad) * dy;
981
+ const py = part.y + part.height / 2 + Math.sin(rad) * dx + Math.cos(rad) * dy;
982
+ return toWorld(px, py, options.canvasWidth, options.canvasHeight);
983
+ };
937
984
  for (const name of ordered) {
938
985
  if (name === "root")
939
986
  continue;
@@ -942,7 +989,7 @@ export function buildSkeleton(options) {
942
989
  continue;
943
990
  const anchors = anchorsOf(name);
944
991
  const proximal = part.proximal ?? anchors.proximal;
945
- proxWorldOf.set(name, toWorld(part.x + proximal[0] * part.width, part.y + proximal[1] * part.height, options.canvasWidth, options.canvasHeight));
992
+ proxWorldOf.set(name, anchorWorldOf(part, proximal));
946
993
  }
947
994
  /**
948
995
  * 父 → 子。
@@ -974,14 +1021,10 @@ export function buildSkeleton(options) {
974
1021
  const fallbackAnchors = anchorsOf(name);
975
1022
  const proximal = part.proximal ?? fallbackAnchors.proximal;
976
1023
  const distal = part.distal ?? fallbackAnchors.distal;
977
- const proxPx = part.x + proximal[0] * part.width;
978
- const proxPy = part.y + proximal[1] * part.height;
979
- const distPx = part.x + distal[0] * part.width;
980
- const distPy = part.y + distal[1] * part.height;
981
1024
  const centerPx = part.x + part.width / 2;
982
1025
  const centerPy = part.y + part.height / 2;
983
- const prox = toWorld(proxPx, proxPy, options.canvasWidth, options.canvasHeight);
984
- const ownDist = toWorld(distPx, distPy, options.canvasWidth, options.canvasHeight);
1026
+ const prox = anchorWorldOf(part, proximal);
1027
+ const ownDist = anchorWorldOf(part, distal);
985
1028
  const center = toWorld(centerPx, centerPy, options.canvasWidth, options.canvasHeight);
986
1029
  // 骨骼末端优先指到**子部件的近端**——「首尾相接」就是这么来的。
987
1030
  // 没有子部件(叶子骨,例如头、手、脚)才退回自己部件的远端。
@@ -993,7 +1036,7 @@ export function buildSkeleton(options) {
993
1036
  const dirX = dist.x - prox.x;
994
1037
  const dirY = dist.y - prox.y;
995
1038
  const length = Math.hypot(dirX, dirY) || Math.max(1, Math.max(part.width, part.height));
996
- const worldRot = deg(Math.atan2(-dirX, dirY));
1039
+ const worldRot = deg(Math.atan2(dirY, dirX));
997
1040
  const parentName = resolvedParent.get(name);
998
1041
  const parentWorld = world.get(parentName ?? "root") ?? world.get("root");
999
1042
  // 位移先逆旋转到父骨骼局部系,再作为骨骼 x/y。
@@ -1031,8 +1074,8 @@ export function buildSkeleton(options) {
1031
1074
  [name]: {
1032
1075
  x: round(offX * cosB - offY * sinB, 4),
1033
1076
  y: round(offX * sinB + offY * cosB, 4),
1034
- // 挂点自身旋转 = 抵消骨骼朝向(让初始姿态正立)+ 手动装配里拧的角度。
1035
- rotation: normalizeAngle(-worldRot + (part.rotation ?? 0)),
1077
+ // 抵消骨骼朝向,再把图片坐标的顺时针装配角转换成 Spine 的逆时针角。
1078
+ rotation: normalizeAngle(-worldRot - (part.rotation ?? 0)),
1036
1079
  width: round(part.width, 4),
1037
1080
  height: round(part.height, 4)
1038
1081
  }
@@ -1065,39 +1108,6 @@ export function buildSkeleton(options) {
1065
1108
  }
1066
1109
  const animations = JSON.parse(JSON.stringify(animationsRaw));
1067
1110
  toSpine42(animations);
1068
- // ── FFD 变形时间轴(M5 的 L3)───────────────────────────────────────
1069
- //
1070
- // 把波形**采样**成有限个关键帧再导出:两条导出路径的 deform/ffd 都是关键帧列表,
1071
- // 而波形是连续的。采样点数取 6(每周期 6 段),对「裙摆左右摆」这个低频运动足够,
1072
- // 也不会让 JSON 膨胀——顶点数是 49,每帧 98 个数字,6 帧约 600 个。
1073
- //
1074
- // 采样时间对齐到**每个动画自己的时长**:这样每个动画的 deform 都首尾闭合,
1075
- // 切成任何一台动画看,裙摆都不会在接缝处跳一下。
1076
- for (const [id, animation] of Object.entries(animations)) {
1077
- const duration = animationDurationOf(id, options.animationSettings ?? {});
1078
- for (const [name, deform] of Object.entries(options.deforms ?? {})) {
1079
- const grid = meshGridOf(options.meshes?.[name], byName.get(name));
1080
- if (grid === undefined || deform === null || deform === undefined)
1081
- continue;
1082
- const frames = [];
1083
- for (let i = 0; i <= ANIMATION_DEFORM_SAMPLES; i++) {
1084
- const at = (i / ANIMATION_DEFORM_SAMPLES) * duration;
1085
- const { offsets } = buildWaveDeform({
1086
- mesh: grid.mesh,
1087
- width: grid.width,
1088
- height: grid.height,
1089
- phase: at / Math.max(0.01, deform.duration),
1090
- amplitude: deform.amplitude,
1091
- cycles: deform.cycles,
1092
- direction: deform.direction,
1093
- anchor: deform.anchor
1094
- });
1095
- frames.push({ time: round(at, 4), offset: 0, vertices: offsets });
1096
- }
1097
- animation.deform = animation.deform ?? {};
1098
- animation.deform[name] = { default: frames };
1099
- }
1100
- }
1101
1111
  if (Object.keys(animations).length === 0) {
1102
1112
  warnings.push("没有生成任何动画:所选预设依赖的骨骼名在本次拆件里都不存在");
1103
1113
  }
@@ -1112,12 +1122,33 @@ export function buildSkeleton(options) {
1112
1122
  // 一个可以直接拖的目标点,而不是先跳一下。
1113
1123
  const ik = [];
1114
1124
  const boneParent = new Map(bones.map((bone) => [bone.name, bone.parent]));
1125
+ // 绑定缓存 world 不含人的 offset;IK 初始目标需要匹配实际 setup 姿态,另算一份。
1126
+ const setupWorld = new Map();
1127
+ const setupWorldOf = (name) => {
1128
+ const cached = setupWorld.get(name);
1129
+ if (cached !== undefined)
1130
+ return cached;
1131
+ const bone = bones.find((entry) => entry.name === name);
1132
+ const parent = bone.parent === undefined ? { x: 0, y: 0, rotation: 0 } : setupWorldOf(bone.parent);
1133
+ const rad = parent.rotation * Math.PI / 180;
1134
+ const value = {
1135
+ x: parent.x + Math.cos(rad) * bone.x - Math.sin(rad) * bone.y,
1136
+ y: parent.y + Math.sin(rad) * bone.x + Math.cos(rad) * bone.y,
1137
+ rotation: parent.rotation + bone.rotation
1138
+ };
1139
+ setupWorld.set(name, value);
1140
+ return value;
1141
+ };
1115
1142
  for (const constraint of options.constraints ?? []) {
1116
1143
  if (constraint === null || typeof constraint !== "object")
1117
1144
  continue;
1118
1145
  if (constraint.type !== undefined && constraint.type !== "ik")
1119
1146
  continue;
1120
1147
  const chainLength = Math.max(1, Math.min(8, Math.round(num(constraint.chain, 1))));
1148
+ if (chainLength !== 1) {
1149
+ warnings.push(`IK「${constraint.name}」只支持两骨链(chain = 1),已跳过`);
1150
+ continue;
1151
+ }
1121
1152
  const chain = ikChainOf(boneParent, constraint.bone, chainLength);
1122
1153
  if (chain.length < 2) {
1123
1154
  warnings.push(`IK「${constraint.name}」的链端骨骼不存在或没有父级:${constraint.bone}`);
@@ -1138,13 +1169,13 @@ export function buildSkeleton(options) {
1138
1169
  // 目标点落在链末端的**骨尖**上(原点沿自身朝向再走一个 length,和预览器的画法一致):
1139
1170
  // 加上约束的那一刻姿态不变,用户看到的是一个可以直接拖的点,而不是先跳一下。
1140
1171
  const tip = bones.find((bone) => bone.name === constraint.bone);
1141
- const origin = world.get(constraint.bone) ?? { x: tip.x, y: tip.y, rotation: 0 };
1172
+ const origin = setupWorldOf(constraint.bone);
1142
1173
  const dirRad = (origin.rotation * Math.PI) / 180;
1143
- const tipWorldX = origin.x - Math.sin(dirRad) * tip.length;
1144
- const tipWorldY = origin.y + Math.cos(dirRad) * tip.length;
1145
- bones.splice(bones.findIndex((bone) => bone.name === constraint.bone) + 1, 0, { name: targetName, x: round(tipWorldX, 4), y: round(tipWorldY, 4), rotation: 0, length: 0 });
1174
+ const tipWorldX = origin.x + Math.cos(dirRad) * tip.length;
1175
+ const tipWorldY = origin.y + Math.sin(dirRad) * tip.length;
1176
+ bones.splice(bones.findIndex((bone) => bone.name === constraint.bone) + 1, 0, { name: targetName, parent: "root", x: round(tipWorldX, 4), y: round(tipWorldY, 4), rotation: 0, length: 0 });
1146
1177
  boneNames.add(targetName);
1147
- boneParent.set(targetName, undefined);
1178
+ boneParent.set(targetName, "root");
1148
1179
  }
1149
1180
  ik.push({
1150
1181
  name: constraint.name,
@@ -1175,26 +1206,25 @@ export function buildSkeleton(options) {
1175
1206
  warnings.push(`Path「${name}」没有可用的骨骼链,已跳过`);
1176
1207
  continue;
1177
1208
  }
1178
- if (entry.points.length < 4) {
1209
+ const spec = normalizePath(entry);
1210
+ if (spec === undefined || pathTotalLength(spec) <= 1e-6) {
1179
1211
  warnings.push(`Path「${name}」点数不足,已跳过`);
1180
1212
  continue;
1181
1213
  }
1182
- const spec = { points: entry.points, closed: entry.closed === true };
1183
- const lengths = pathSegmentLengths(spec);
1184
1214
  // 路径点转成**骨骼世界坐标**:槽挂在 root(世界原点),所以 attachment 的顶点
1185
1215
  // 直接用世界坐标即可,不必再相对某根骨骼做一次逆变换。
1186
- const vertices = [];
1187
- for (let i = 0; i + 1 < entry.points.length; i += 2) {
1188
- const world = toWorld(entry.points[i], entry.points[i + 1], options.canvasWidth, options.canvasHeight);
1189
- vertices.push(round(world.x, 3), round(world.y, 3));
1216
+ const points = [];
1217
+ for (let i = 0; i + 1 < spec.points.length; i += 2) {
1218
+ const point = toWorld(spec.points[i], spec.points[i + 1], options.canvasWidth, options.canvasHeight);
1219
+ points.push(point.x, point.y);
1190
1220
  }
1221
+ const geometry = spinePathGeometry({ points, closed: spec.closed });
1191
1222
  const slotName = `path:${name}`;
1192
1223
  slots.push({ name: slotName, bone: "root", attachment: name });
1193
1224
  attachments[slotName] = {
1194
1225
  [name]: {
1195
1226
  type: "path",
1196
- vertices,
1197
- lengths,
1227
+ ...geometry,
1198
1228
  closed: spec.closed === true,
1199
1229
  // 恒定速度:让沿路径的采样按**弧长**而不是按段索引走,与预览器的算法一致。
1200
1230
  constantSpeed: true
@@ -1202,16 +1232,19 @@ export function buildSkeleton(options) {
1202
1232
  };
1203
1233
  pathConstraints.push({
1204
1234
  name,
1205
- order: pathConstraints.length,
1235
+ order: ik.length + pathConstraints.length,
1206
1236
  bones: chain,
1207
- target: "root",
1237
+ target: slotName,
1208
1238
  // spacing > 0 是「固定间距」,否则「均匀铺满整条路径」。
1209
1239
  positionMode: entry.spacing > 0 ? "fixed" : "percent",
1210
- spacingMode: "length",
1240
+ spacingMode: entry.spacing > 0 ? "fixed" : "percent",
1241
+ position: 0,
1242
+ spacing: entry.spacing > 0 ? entry.spacing : 1 / Math.max(1, chain.length - 1),
1211
1243
  rotateMode: "tangent",
1212
1244
  rotation: 0,
1213
- translateMix: Math.max(0, Math.min(1, num(entry.translateMix, 1))),
1214
- rotateMix: Math.max(0, Math.min(1, num(entry.rotateMix, 1)))
1245
+ mixX: Math.max(0, Math.min(1, num(entry.translateMix, 1))),
1246
+ mixY: Math.max(0, Math.min(1, num(entry.translateMix, 1))),
1247
+ mixRotate: Math.max(0, Math.min(1, num(entry.rotateMix, 1)))
1215
1248
  });
1216
1249
  }
1217
1250
  // ── 蒙皮网格附件(L1 / LBS)──────────────────────────────────────────
@@ -1245,7 +1278,8 @@ export function buildSkeleton(options) {
1245
1278
  for (const child of childrenOf.get(meshName) ?? [])
1246
1279
  related.add(child);
1247
1280
  const imageBones = [...world.entries()]
1248
- .filter(([name]) => name !== meshName && related.has(name) && boneNames.has(name))
1281
+ // root 只是坐标原点,没有解剖关节;给它权重会让叶子骨自身旋转被稀释。
1282
+ .filter(([name]) => name !== "root" && related.has(name) && boneNames.has(name))
1249
1283
  .map(([name, point]) => {
1250
1284
  const image = fromWorld(point.x, point.y);
1251
1285
  return { name, x: image.x, y: image.y };
@@ -1258,6 +1292,39 @@ export function buildSkeleton(options) {
1258
1292
  })
1259
1293
  };
1260
1294
  }
1295
+ // FFD 必须等最终网格编码完成:加权网格按每个骨骼影响写局部位移,不能用UV的点数。
1296
+ for (const [id, animation] of Object.entries(animations)) {
1297
+ const raw = animationsRaw[id];
1298
+ let latest = 0;
1299
+ for (const kinds of Object.values(raw?.bones ?? {})) {
1300
+ for (const frames of Object.values(kinds)) {
1301
+ if (Array.isArray(frames))
1302
+ for (const frame of frames)
1303
+ latest = Math.max(latest, num(frame?.time, 0));
1304
+ }
1305
+ }
1306
+ const duration = num(raw?.duration, 0) > 0 ? raw.duration : latest || animationDurationOf(id, settings);
1307
+ for (const [name, deform] of Object.entries(options.deforms ?? {})) {
1308
+ const part = byName.get(name);
1309
+ const attachment = attachments[name]?.[name];
1310
+ const grid = meshGridOf(options.meshes?.[name], part);
1311
+ if (!part || !grid || attachment?.type !== "mesh" || !deform)
1312
+ continue;
1313
+ const period = Math.max(0.01, num(deform.duration, duration));
1314
+ const samples = Math.min(600, Math.max(ANIMATION_DEFORM_SAMPLES, Math.ceil(duration / period * Math.abs(num(deform.cycles, 1)) * ANIMATION_DEFORM_SAMPLES)));
1315
+ const frames = [];
1316
+ for (let i = 0; i <= samples; i++) {
1317
+ const at = i / samples * duration;
1318
+ const { offsets } = buildWaveDeform({ mesh: grid.mesh, width: grid.width, height: grid.height,
1319
+ phase: at / period, amplitude: deform.amplitude, cycles: deform.cycles, direction: deform.direction, anchor: deform.anchor });
1320
+ frames.push({ time: round(at, 4), offset: 0, vertices: spineDeformOffsets(offsets, part, attachment, bones, world) });
1321
+ }
1322
+ animation.attachments ??= {};
1323
+ animation.attachments.default ??= {};
1324
+ animation.attachments.default[name] ??= {};
1325
+ animation.attachments.default[name][name] = { deform: frames };
1326
+ }
1327
+ }
1261
1328
  const spine = {
1262
1329
  skeleton: {
1263
1330
  hash,
package/lib/tilegen.js CHANGED
@@ -36,7 +36,7 @@ import { loadConfig, tileJobsRoot } from "./config.js";
36
36
  import { messageOf, readJson, writeJsonAtomic, appendJobLog, sweepTempFiles } from "./jsonio.js";
37
37
  import { DEFAULT_SETTINGS, assertSettings, decorAnchorY, diamondHeight, measureGroundDiamond, measurementLooksSane, regularizeBuilding, regularizeDecorSprite, regularizeToCell, renderBuildingTemplate, renderTemplate, upscale } from "./tilegeom.js";
38
38
  import { assembleMap, cropBitmap, emptyMapState, measureAssemblyBounds, pickVariantIndex, shapeOfEntry } from "./tilemap.js";
39
- import { decodeFile, encodeBitmap, pngSize, sniffImageExt } from "./tilemedia.js";
39
+ import { decodeFile, encodeBitmap, pngSize, sniffImageExt } from "./bitmap.js";
40
40
  export const TILE_STAGES = ["generate", "review", "map", "export"];
41
41
  export const TILE_INVALIDATION_ORDER = ["template", "generate", "review", "map", "export"];
42
42
  /** 由「列 × 行」矩形造形状。 */
package/lib/tilegeom.js CHANGED
@@ -28,7 +28,7 @@
28
28
  * ③ 颜色与 alpha **分开**缩放。
29
29
  * 实测白边像素 184 → 0,alpha 档位 2 → 115~208,剪影面积不变。
30
30
  */
31
- import { borderColor, foregroundMask, maskBounds, maskCount } from "./tilemedia.js";
31
+ import { borderColor, foregroundMask, maskBounds, maskCount } from "./bitmap.js";
32
32
  /** 目标菱形的固定尺寸:宽 2 份、高 1 份(严格的 2:1 等距)。 */
33
33
  export const DIAMOND_RATIO = 2;
34
34
  /**