ugly-game 0.15.39 → 0.15.41

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.
@@ -24,7 +24,7 @@
24
24
  // "must match" comment, and a crowd that disagreed would light its characters out of a different
25
25
  // number of cascades than the ground they stand on.
26
26
  import { MAX_CASCADES } from './gpuSkin';
27
- import { CROWD_MATERIAL_COUNT as CROWD_MATERIAL_COUNT_VALUE, CROWD_RECORD_FLOATS as CROWD_RECORD_FLOATS_VALUE, CROWD_REC_LAYER as CROWD_REC_LAYER_VALUE, CROWD_REC_MATERIAL as CROWD_REC_MATERIAL_VALUE, CROWD_REC_MODEL as CROWD_REC_MODEL_VALUE, CROWD_REC_PALETTE_SLOT as CROWD_REC_PALETTE_SLOT_VALUE, CROWD_REC_POOL_SLOT as CROWD_REC_POOL_SLOT_VALUE, CROWD_REC_TINT as CROWD_REC_TINT_VALUE, writeCrowdRecord as writeCrowdRecordValue, } from './crowdRecord';
27
+ import { CROWD_MATERIAL_COUNT as CROWD_MATERIAL_COUNT_VALUE, CROWD_RECORD_FLOATS as CROWD_RECORD_FLOATS_VALUE, CROWD_REC_LAYER as CROWD_REC_LAYER_VALUE, CROWD_REC_MATERIAL as CROWD_REC_MATERIAL_VALUE, CROWD_REC_MODEL as CROWD_REC_MODEL_VALUE, CROWD_REC_PALETTE_SLOT as CROWD_REC_PALETTE_SLOT_VALUE, CROWD_REC_POOL_SLOT as CROWD_REC_POOL_SLOT_VALUE, CROWD_REC_TINT as CROWD_REC_TINT_VALUE, writeCrowdRecord as writeCrowdRecordValue, } from './crowdRecord.js';
28
28
  export const CROWD_MATERIAL_COUNT = CROWD_MATERIAL_COUNT_VALUE;
29
29
  export const CROWD_RECORD_FLOATS = CROWD_RECORD_FLOATS_VALUE;
30
30
  export const CROWD_REC_LAYER = CROWD_REC_LAYER_VALUE;
@@ -1,4 +1,4 @@
1
- import type { CrowdBucket, GpuCrowdRenderer } from './assets/gpuCrowd';
1
+ import type { CrowdBucket, GpuCrowdRenderer } from './assets/gpuCrowd.js';
2
2
  export declare const GPU_CHARACTER_FACE_CHANNELS = 47;
3
3
  export declare const GPU_CHARACTER_VISIBLE = 1;
4
4
  export interface GpuCharacterTiers {
@@ -15,15 +15,28 @@ export interface GpuCharactersOptions {
15
15
  maxCharacters: number;
16
16
  boneCount: number;
17
17
  faceChannels?: number;
18
+ /** Fixed socket rows packed per actor in each hot frame. Defaults to zero. */
19
+ socketCount?: number;
20
+ }
21
+ export interface GpuCharacterSocketAttachment {
22
+ /** Stable authored asset id; negative ids mean no attachment. */
23
+ asset: number;
24
+ /** Row in `GpuCharacterFrame.socketTransforms`. */
25
+ socket: number;
18
26
  }
19
27
  export interface GpuCharacterIdentity {
20
28
  revision: number;
21
29
  morphWeights: Float32Array;
30
+ /** Optional for compatibility with single-kit renderers where the body is implicit. */
31
+ bodyAsset?: number;
32
+ /** Defaults to bodyAsset when the face is part of the body kit. */
33
+ faceAsset?: number;
22
34
  material: number;
23
35
  skinLayer: number;
24
36
  eyeLayer: number;
25
37
  hairAsset: number;
26
38
  garmentAssets: readonly number[];
39
+ socketAttachments?: readonly GpuCharacterSocketAttachment[];
27
40
  }
28
41
  export interface GpuCharacterIdentityUpdate extends GpuCharacterIdentity {
29
42
  slot: number;
@@ -37,6 +50,8 @@ export interface GpuCharacterFrame {
37
50
  palettes: Float32Array;
38
51
  /** count × faceChannels. */
39
52
  faceWeights: Float32Array;
53
+ /** count × socketCount × 16 world matrices. */
54
+ socketTransforms?: Float32Array;
40
55
  /** count × xyzr, in world space. */
41
56
  bounds: Float32Array;
42
57
  /** count packed visibility/tier flags. */
@@ -65,9 +80,53 @@ export interface GpuCharactersBackend {
65
80
  export interface GpuCrowdCharacterBinding {
66
81
  poolSlots: readonly number[];
67
82
  facePoolSlots?: readonly (number | null)[];
83
+ /** Caller-owned draw/allocation handles, selected by the corresponding hot tier. */
84
+ hair?: GpuCrowdCharacterPartBinding;
85
+ /** One binding per identity.garmentAssets entry, in the same order. */
86
+ garments?: readonly (GpuCrowdCharacterPartBinding | null)[];
87
+ /** One binding per identity.socketAttachments entry, in the same order. */
88
+ socketAttachments?: readonly (GpuCrowdCharacterPartBinding | null)[];
68
89
  tint?: Float32Array;
69
90
  layer?: number;
70
91
  }
92
+ /** A retained caller-owned part allocation. The numeric slots are opaque to this adapter. */
93
+ export interface GpuCrowdCharacterPartBinding {
94
+ asset: number;
95
+ lodSlots: readonly (number | null)[];
96
+ }
97
+ export declare const GPU_CHARACTER_PART_KIND: {
98
+ readonly body: 0;
99
+ readonly face: 1;
100
+ readonly hair: 2;
101
+ readonly garment: 3;
102
+ readonly socketAttachment: 4;
103
+ };
104
+ export type GpuCharacterPartKind = (typeof GPU_CHARACTER_PART_KIND)[keyof typeof GPU_CHARACTER_PART_KIND];
105
+ /**
106
+ * Packed same-frame handoff for caller-owned part passes. Body and face rows are included so
107
+ * model/palette/LOD agreement across every composed part is directly observable and testable.
108
+ */
109
+ export interface GpuCrowdCharacterCompositionFrame {
110
+ count: number;
111
+ actorSlots: Uint32Array;
112
+ kinds: Uint8Array;
113
+ assets: Int32Array;
114
+ bindingSlots: Uint32Array;
115
+ lods: Uint8Array;
116
+ tiers: Uint8Array;
117
+ /** Animation sampling tier selected for the actor in this same hot frame. */
118
+ animationTiers: Uint8Array;
119
+ paletteRows: Uint32Array;
120
+ /** -1 for actor-root parts; otherwise the identity's canonical socket row. */
121
+ socketIndices: Int32Array;
122
+ /** count × 16 world matrices. */
123
+ transforms: Float32Array;
124
+ /** count × xyzr world bounds. */
125
+ bounds: Float32Array;
126
+ }
127
+ export interface GpuCrowdCharacterCompositionBackend {
128
+ submitComposition(frame: GpuCrowdCharacterCompositionFrame): void;
129
+ }
71
130
  /** The narrow renderer surface used by the concrete crowd backend (and by its CPU-only tests). */
72
131
  export type GpuCrowdCharacterRenderer = Pick<GpuCrowdRenderer, 'morph' | 'enableFaceRig' | 'disableFaceRig' | 'setFaceWeights' | 'faceFrame' | 'setInstances' | 'setPalettes'>;
73
132
  export interface GpuCrowdCharactersBackendOptions {
@@ -79,6 +138,10 @@ export interface GpuCrowdCharactersBackendOptions {
79
138
  releaseBinding?: (binding: GpuCrowdCharacterBinding, identity: Readonly<GpuCharacterIdentityUpdate>) => void;
80
139
  /** Highest face quality tier that receives the per-frame face rig. Defaults to 1. */
81
140
  maxRiggedFaceTier?: number;
141
+ /** Must match GpuCharactersOptions.socketCount when attachments are used. */
142
+ socketCount?: number;
143
+ /** Explicit handoff to caller-owned hair, garment and attachment render passes. */
144
+ composition?: GpuCrowdCharacterCompositionBackend;
82
145
  }
83
146
  export interface GpuCrowdCharactersPreparedFrame {
84
147
  renderedCount: number;
@@ -87,6 +150,7 @@ export interface GpuCrowdCharactersPreparedFrame {
87
150
  records: Float32Array;
88
151
  palettes: Float32Array;
89
152
  buckets: readonly CrowdBucket[];
153
+ composition: GpuCrowdCharacterCompositionFrame;
90
154
  }
91
155
  export interface GpuCharactersReport {
92
156
  capacity: number;
@@ -100,7 +164,7 @@ export interface GpuCharactersReport {
100
164
  lastTierCounts: Record<'body' | 'face' | 'animation' | 'hair' | 'cloth', number[]>;
101
165
  }
102
166
  /** Validate a hot frame without allocating or converting it. */
103
- export declare function validateGpuCharacterFrame(frame: GpuCharacterFrame, options: Required<GpuCharactersOptions>): void;
167
+ export declare function validateGpuCharacterFrame(frame: GpuCharacterFrame, options: Omit<Required<GpuCharactersOptions>, 'socketCount'> & Pick<GpuCharactersOptions, 'socketCount'>): void;
104
168
  export declare class GpuCharacters {
105
169
  readonly options: Required<GpuCharactersOptions>;
106
170
  private readonly backend;
@@ -136,7 +200,9 @@ export declare class GpuCrowdCharactersBackend implements GpuCharactersBackend {
136
200
  private readonly renderer;
137
201
  private readonly boneCount;
138
202
  private readonly faceChannels;
203
+ private readonly socketCount;
139
204
  private readonly maxRiggedFaceTier;
205
+ private readonly compositionBackend;
140
206
  private readonly resolveBinding;
141
207
  private readonly releaseBinding;
142
208
  private readonly states;
@@ -147,6 +213,7 @@ export declare class GpuCrowdCharactersBackend implements GpuCharactersBackend {
147
213
  dispose(): void;
148
214
  private applyRemovals;
149
215
  private applyIdentityUpdates;
216
+ private validateBinding;
150
217
  private releaseState;
151
218
  }
152
219
  export declare function createGpuCrowdCharactersBackend(options: GpuCrowdCharactersBackendOptions): GpuCrowdCharactersBackend;
package/dist/character.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // ─────────────────────────────────────────────────────────────────────────────
2
- import { CROWD_RECORD_FLOATS, writeCrowdRecord } from './assets/crowdRecord';
2
+ import { CROWD_RECORD_FLOATS, writeCrowdRecord } from './assets/crowdRecord.js';
3
3
  // BATCHED CHARACTERS — retained identity, packed hot frames, renderer seam.
4
4
  //
5
5
  // A character's identity changes rarely; its transform, palette and face change every
@@ -42,11 +42,28 @@ export function unpackGpuCharacterFlags(flags) {
42
42
  cloth: (flags >>> TIER_SHIFT.cloth) & TIER_MASK,
43
43
  };
44
44
  }
45
+ export const GPU_CHARACTER_PART_KIND = {
46
+ body: 0,
47
+ face: 1,
48
+ hair: 2,
49
+ garment: 3,
50
+ socketAttachment: 4,
51
+ };
45
52
  function positiveInt(value, name) {
46
53
  if (!Number.isInteger(value) || value <= 0)
47
54
  throw new Error(`${name} must be a positive integer`);
48
55
  return value;
49
56
  }
57
+ function nonNegativeInt(value, name) {
58
+ if (!Number.isInteger(value) || value < 0)
59
+ throw new Error(`${name} must be a non-negative integer`);
60
+ return value;
61
+ }
62
+ function integer(value, name) {
63
+ if (!Number.isInteger(value))
64
+ throw new Error(`${name} must be an integer`);
65
+ return value;
66
+ }
50
67
  function finiteArray(value, name) {
51
68
  for (let i = 0; i < value.length; i++)
52
69
  if (!Number.isFinite(value[i]))
@@ -56,6 +73,10 @@ function cloneIdentity(slot, identity) {
56
73
  if (!Number.isInteger(identity.revision) || identity.revision < 0)
57
74
  throw new Error('identity revision must be a non-negative integer');
58
75
  finiteArray(identity.morphWeights, 'morphWeights');
76
+ if (identity.bodyAsset !== undefined)
77
+ integer(identity.bodyAsset, 'bodyAsset');
78
+ if (identity.faceAsset !== undefined)
79
+ integer(identity.faceAsset, 'faceAsset');
59
80
  for (const [name, value] of [
60
81
  ['material', identity.material],
61
82
  ['skinLayer', identity.skinLayer],
@@ -67,15 +88,32 @@ function cloneIdentity(slot, identity) {
67
88
  for (const [i, value] of identity.garmentAssets.entries())
68
89
  if (!Number.isInteger(value))
69
90
  throw new Error(`garmentAssets[${i}] must be an integer`);
91
+ for (const [i, attachment] of (identity.socketAttachments ?? []).entries()) {
92
+ integer(attachment.asset, `socketAttachments[${i}].asset`);
93
+ nonNegativeInt(attachment.socket, `socketAttachments[${i}].socket`);
94
+ }
70
95
  return {
71
96
  slot,
72
97
  revision: identity.revision,
73
98
  morphWeights: identity.morphWeights.slice(),
99
+ ...(identity.bodyAsset === undefined
100
+ ? {}
101
+ : { bodyAsset: identity.bodyAsset }),
102
+ ...(identity.faceAsset === undefined
103
+ ? {}
104
+ : { faceAsset: identity.faceAsset }),
74
105
  material: identity.material,
75
106
  skinLayer: identity.skinLayer,
76
107
  eyeLayer: identity.eyeLayer,
77
108
  hairAsset: identity.hairAsset,
78
109
  garmentAssets: [...identity.garmentAssets],
110
+ ...(identity.socketAttachments === undefined
111
+ ? {}
112
+ : {
113
+ socketAttachments: identity.socketAttachments.map((attachment) => ({
114
+ ...attachment,
115
+ })),
116
+ }),
79
117
  };
80
118
  }
81
119
  /** Validate a hot frame without allocating or converting it. */
@@ -93,6 +131,11 @@ export function validateGpuCharacterFrame(frame, options) {
93
131
  frame.faceWeights.length,
94
132
  frame.count * options.faceChannels,
95
133
  ],
134
+ [
135
+ 'socketTransforms',
136
+ frame.socketTransforms?.length ?? 0,
137
+ frame.count * (options.socketCount ?? 0) * 16,
138
+ ],
96
139
  ['bounds', frame.bounds.length, frame.count * 4],
97
140
  ['flags', frame.flags.length, frame.count],
98
141
  ];
@@ -102,6 +145,8 @@ export function validateGpuCharacterFrame(frame, options) {
102
145
  finiteArray(frame.transforms, 'transforms');
103
146
  finiteArray(frame.palettes, 'palettes');
104
147
  finiteArray(frame.faceWeights, 'faceWeights');
148
+ if (frame.socketTransforms)
149
+ finiteArray(frame.socketTransforms, 'socketTransforms');
105
150
  finiteArray(frame.bounds, 'bounds');
106
151
  }
107
152
  export class GpuCharacters {
@@ -122,6 +167,7 @@ export class GpuCharacters {
122
167
  maxCharacters: positiveInt(options.maxCharacters, 'maxCharacters'),
123
168
  boneCount: positiveInt(options.boneCount, 'boneCount'),
124
169
  faceChannels: positiveInt(options.faceChannels ?? GPU_CHARACTER_FACE_CHANNELS, 'faceChannels'),
170
+ socketCount: nonNegativeInt(options.socketCount ?? 0, 'socketCount'),
125
171
  };
126
172
  // pop() returns 0, 1, 2… so stable low slots are reused first.
127
173
  this.freeSlots = Array.from({ length: this.options.maxCharacters }, (_, i) => this.options.maxCharacters - i - 1);
@@ -254,6 +300,47 @@ function bindingFaceSlot(binding, lod) {
254
300
  throw new Error(`character binding has an invalid face pool slot for LOD ${lod}`);
255
301
  return slot;
256
302
  }
303
+ function partBindingSlot(binding, lod, label) {
304
+ const slot = binding.lodSlots[lod];
305
+ if (typeof slot !== 'number' || !Number.isInteger(slot) || slot < 0)
306
+ throw new Error(`${label} binding has no valid slot for LOD ${lod}`);
307
+ return slot;
308
+ }
309
+ function indexedPartBinding(bindings, index, label) {
310
+ const binding = bindings?.[index];
311
+ if (!binding)
312
+ throw new Error(`${label} binding is unavailable`);
313
+ return binding;
314
+ }
315
+ function emptyComposition() {
316
+ return {
317
+ count: 0,
318
+ actorSlots: new Uint32Array(0),
319
+ kinds: new Uint8Array(0),
320
+ assets: new Int32Array(0),
321
+ bindingSlots: new Uint32Array(0),
322
+ lods: new Uint8Array(0),
323
+ tiers: new Uint8Array(0),
324
+ animationTiers: new Uint8Array(0),
325
+ paletteRows: new Uint32Array(0),
326
+ socketIndices: new Int32Array(0),
327
+ transforms: new Float32Array(0),
328
+ bounds: new Float32Array(0),
329
+ };
330
+ }
331
+ function validatePartBinding(binding, asset, label) {
332
+ if (asset < 0) {
333
+ if (binding)
334
+ throw new Error(`${label} binding was supplied for disabled asset ${asset}`);
335
+ return;
336
+ }
337
+ if (!binding)
338
+ throw new Error(`${label} binding is required for asset ${asset}`);
339
+ if (binding.asset !== asset)
340
+ throw new Error(`${label} binding asset ${binding.asset} does not match identity asset ${asset}`);
341
+ if (binding.lodSlots.length === 0)
342
+ throw new Error(`${label} binding must declare at least one LOD slot`);
343
+ }
257
344
  /**
258
345
  * Concrete adapter from the retained character batch to {@link GpuCrowdRenderer}.
259
346
  *
@@ -266,7 +353,9 @@ export class GpuCrowdCharactersBackend {
266
353
  renderer;
267
354
  boneCount;
268
355
  faceChannels;
356
+ socketCount;
269
357
  maxRiggedFaceTier;
358
+ compositionBackend;
270
359
  resolveBinding;
271
360
  releaseBinding;
272
361
  states = new Map();
@@ -276,6 +365,7 @@ export class GpuCrowdCharactersBackend {
276
365
  records: new Float32Array(0),
277
366
  palettes: new Float32Array(0),
278
367
  buckets: [],
368
+ composition: emptyComposition(),
279
369
  };
280
370
  constructor(options) {
281
371
  this.renderer = options.renderer;
@@ -283,6 +373,8 @@ export class GpuCrowdCharactersBackend {
283
373
  this.faceChannels = positiveInt(options.faceChannels ?? GPU_CHARACTER_FACE_CHANNELS, 'faceChannels');
284
374
  if (this.faceChannels !== GPU_CHARACTER_FACE_CHANNELS)
285
375
  throw new Error(`GpuCrowdRenderer requires ${GPU_CHARACTER_FACE_CHANNELS} face channels`);
376
+ this.socketCount = nonNegativeInt(options.socketCount ?? 0, 'socketCount');
377
+ this.compositionBackend = options.composition;
286
378
  this.resolveBinding = options.resolveBinding;
287
379
  this.releaseBinding = options.releaseBinding;
288
380
  const faceTier = options.maxRiggedFaceTier ?? 1;
@@ -291,6 +383,10 @@ export class GpuCrowdCharactersBackend {
291
383
  this.maxRiggedFaceTier = faceTier;
292
384
  }
293
385
  submit(batch) {
386
+ const expectedSocketValues = batch.frame.count * this.socketCount * 16;
387
+ const socketValues = batch.frame.socketTransforms?.length ?? 0;
388
+ if (socketValues !== expectedSocketValues)
389
+ throw new Error(`socketTransforms length ${socketValues} does not match backend requirement ${expectedSocketValues}`);
294
390
  this.applyRemovals(batch.removedSlots);
295
391
  this.applyIdentityUpdates(batch.identityUpdates);
296
392
  const entries = [];
@@ -318,6 +414,29 @@ export class GpuCrowdCharactersBackend {
318
414
  const actorSlots = new Uint32Array(entries.length);
319
415
  const buckets = [];
320
416
  const paletteStride = this.boneCount * 16;
417
+ const compositionCount = entries.reduce((count, entry) => {
418
+ const identity = entry.state.identity;
419
+ return (count +
420
+ 2 +
421
+ (identity.hairAsset < 0 ? 0 : 1) +
422
+ identity.garmentAssets.filter((asset) => asset >= 0).length +
423
+ (identity.socketAttachments ?? []).filter((attachment) => attachment.asset >= 0).length);
424
+ }, 0);
425
+ const composition = {
426
+ count: compositionCount,
427
+ actorSlots: new Uint32Array(compositionCount),
428
+ kinds: new Uint8Array(compositionCount),
429
+ assets: new Int32Array(compositionCount),
430
+ bindingSlots: new Uint32Array(compositionCount),
431
+ lods: new Uint8Array(compositionCount),
432
+ tiers: new Uint8Array(compositionCount),
433
+ animationTiers: new Uint8Array(compositionCount),
434
+ paletteRows: new Uint32Array(compositionCount),
435
+ socketIndices: new Int32Array(compositionCount).fill(-1),
436
+ transforms: new Float32Array(compositionCount * 16),
437
+ bounds: new Float32Array(compositionCount * 4),
438
+ };
439
+ let partIndex = 0;
321
440
  for (const [recordIndex, entry] of entries.entries()) {
322
441
  const { actorSlot, sourceIndex, lod, tiers, state } = entry;
323
442
  const sourcePoolSlot = bindingPoolSlot(state.binding, lod);
@@ -350,6 +469,50 @@ export class GpuCrowdCharactersBackend {
350
469
  writeCrowdRecord(records, recordIndex * CROWD_RECORD_FLOATS, transform, tint, state.binding.layer ?? state.identity.skinLayer, recordIndex, facePoolSlot ?? sourcePoolSlot, state.identity.material);
351
470
  palettes.set(batch.frame.palettes.subarray(sourceIndex * paletteStride, (sourceIndex + 1) * paletteStride), recordIndex * paletteStride);
352
471
  actorSlots[recordIndex] = actorSlot;
472
+ const sourceBounds = batch.frame.bounds.subarray(sourceIndex * 4, (sourceIndex + 1) * 4);
473
+ const writePart = (kind, asset, bindingSlot, partLod, tier, partTransform, socketIndex = -1) => {
474
+ const index = partIndex++;
475
+ composition.actorSlots[index] = actorSlot;
476
+ composition.kinds[index] = kind;
477
+ composition.assets[index] = asset;
478
+ composition.bindingSlots[index] = bindingSlot;
479
+ composition.lods[index] = partLod;
480
+ composition.tiers[index] = tier;
481
+ composition.animationTiers[index] = tiers.animation;
482
+ composition.paletteRows[index] = recordIndex;
483
+ composition.socketIndices[index] = socketIndex;
484
+ composition.transforms.set(partTransform, index * 16);
485
+ composition.bounds.set(sourceBounds, index * 4);
486
+ };
487
+ const bodyAsset = state.identity.bodyAsset ?? -1;
488
+ const faceAsset = state.identity.faceAsset ?? bodyAsset;
489
+ writePart(GPU_CHARACTER_PART_KIND.body, bodyAsset, sourcePoolSlot, lod, tiers.body, transform);
490
+ writePart(GPU_CHARACTER_PART_KIND.face, faceAsset, facePoolSlot ?? sourcePoolSlot, lod, tiers.face, transform);
491
+ if (state.identity.hairAsset >= 0) {
492
+ const binding = state.binding.hair;
493
+ if (!binding)
494
+ throw new Error('hair binding is unavailable');
495
+ writePart(GPU_CHARACTER_PART_KIND.hair, state.identity.hairAsset, partBindingSlot(binding, tiers.hair, 'hair'), tiers.hair, tiers.hair, transform);
496
+ }
497
+ for (const [garmentIndex, asset,] of state.identity.garmentAssets.entries()) {
498
+ if (asset < 0)
499
+ continue;
500
+ const binding = indexedPartBinding(state.binding.garments, garmentIndex, `garment ${garmentIndex}`);
501
+ writePart(GPU_CHARACTER_PART_KIND.garment, asset, partBindingSlot(binding, tiers.cloth, `garment ${garmentIndex}`), tiers.cloth, tiers.cloth, transform);
502
+ }
503
+ for (const [attachmentIndex, attachment] of (state.identity.socketAttachments ?? []).entries()) {
504
+ if (attachment.asset < 0)
505
+ continue;
506
+ const socketTransforms = batch.frame.socketTransforms;
507
+ if (!socketTransforms)
508
+ throw new Error('socketTransforms are required for socket attachments');
509
+ const offset = (sourceIndex * this.socketCount + attachment.socket) * 16;
510
+ const socketTransform = socketTransforms.subarray(offset, offset + 16);
511
+ if (socketTransform.length !== 16)
512
+ throw new Error(`socket transform ${attachment.socket} is unavailable for actor ${actorSlot}`);
513
+ const binding = indexedPartBinding(state.binding.socketAttachments, attachmentIndex, `socket attachment ${attachmentIndex}`);
514
+ writePart(GPU_CHARACTER_PART_KIND.socketAttachment, attachment.asset, partBindingSlot(binding, tiers.body, `socket attachment ${attachmentIndex}`), tiers.body, tiers.body, socketTransform, attachment.socket);
515
+ }
353
516
  const bucket = buckets[buckets.length - 1];
354
517
  if (buckets.length > 0 && bucket.lod === lod)
355
518
  bucket.count++;
@@ -365,7 +528,9 @@ export class GpuCrowdCharactersBackend {
365
528
  records,
366
529
  palettes,
367
530
  buckets: buckets.map((bucket) => ({ ...bucket })),
531
+ composition,
368
532
  };
533
+ this.compositionBackend?.submitComposition(composition);
369
534
  }
370
535
  lastPreparedFrame() {
371
536
  return this.prepared;
@@ -387,7 +552,18 @@ export class GpuCrowdCharactersBackend {
387
552
  applyIdentityUpdates(updates) {
388
553
  for (const identity of updates) {
389
554
  const previous = this.states.get(identity.slot);
555
+ // A failed hot submit leaves cold updates pending in GpuCharacters. If this revision was
556
+ // already installed before the failure, retry must not allocate/release it a second time.
557
+ if (previous?.identity === identity)
558
+ continue;
390
559
  const binding = this.resolveBinding(identity);
560
+ try {
561
+ this.validateBinding(binding, identity);
562
+ }
563
+ catch (error) {
564
+ this.releaseBinding?.(binding, identity);
565
+ throw error;
566
+ }
391
567
  if (previous)
392
568
  this.releaseState(previous);
393
569
  this.states.set(identity.slot, {
@@ -398,6 +574,32 @@ export class GpuCrowdCharactersBackend {
398
574
  });
399
575
  }
400
576
  }
577
+ validateBinding(binding, identity) {
578
+ if (binding.poolSlots.length === 0)
579
+ throw new Error('character binding must declare at least one body LOD slot');
580
+ for (const [lod, slot] of binding.poolSlots.entries())
581
+ nonNegativeInt(slot, `body binding LOD ${lod}`);
582
+ if (binding.tint) {
583
+ if (binding.tint.length !== 4)
584
+ throw new Error('character binding tint must contain four values');
585
+ finiteArray(binding.tint, 'character binding tint');
586
+ }
587
+ validatePartBinding(binding.hair, identity.hairAsset, 'hair');
588
+ const garments = binding.garments ?? [];
589
+ if (garments.length !== identity.garmentAssets.length)
590
+ throw new Error(`garment binding count ${garments.length} does not match identity count ${identity.garmentAssets.length}`);
591
+ for (const [index, asset] of identity.garmentAssets.entries())
592
+ validatePartBinding(garments[index], asset, `garment ${index}`);
593
+ const attachments = identity.socketAttachments ?? [];
594
+ const attachmentBindings = binding.socketAttachments ?? [];
595
+ if (attachmentBindings.length !== attachments.length)
596
+ throw new Error(`socket attachment binding count ${attachmentBindings.length} does not match identity count ${attachments.length}`);
597
+ for (const [index, attachment] of attachments.entries()) {
598
+ if (attachment.socket >= this.socketCount)
599
+ throw new Error(`socket attachment ${index} names socket ${attachment.socket}, but socketCount is ${this.socketCount}`);
600
+ validatePartBinding(attachmentBindings[index], attachment.asset, `socket attachment ${index}`);
601
+ }
602
+ }
401
603
  releaseState(state) {
402
604
  if (state.rigSource !== null)
403
605
  this.renderer.disableFaceRig(state.rigSource);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugly-game",
3
- "version": "0.15.39",
3
+ "version": "0.15.41",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {