ugly-game 0.15.41 → 0.15.42
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/character.d.ts +95 -1
- package/dist/character.js +215 -1
- package/package.json +1 -1
package/dist/character.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CrowdBucket, GpuCrowdRenderer } from './assets/gpuCrowd.js';
|
|
2
|
+
import type { GpuSkinRenderer, SkinCreature } from './assets/gpuSkin.js';
|
|
2
3
|
export declare const GPU_CHARACTER_FACE_CHANNELS = 47;
|
|
3
4
|
export declare const GPU_CHARACTER_VISIBLE = 1;
|
|
4
5
|
export interface GpuCharacterTiers {
|
|
@@ -125,8 +126,101 @@ export interface GpuCrowdCharacterCompositionFrame {
|
|
|
125
126
|
bounds: Float32Array;
|
|
126
127
|
}
|
|
127
128
|
export interface GpuCrowdCharacterCompositionBackend {
|
|
128
|
-
submitComposition(frame: GpuCrowdCharacterCompositionFrame): void;
|
|
129
|
+
submitComposition(frame: GpuCrowdCharacterCompositionFrame, resources: GpuCrowdCharacterCompositionResources): void;
|
|
129
130
|
}
|
|
131
|
+
/** Shared skin data referenced by `paletteRows`; passed by reference, never copied. */
|
|
132
|
+
export interface GpuCrowdCharacterCompositionResources {
|
|
133
|
+
palettes: Float32Array;
|
|
134
|
+
boneCount: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* One directly drawable instanced part batch. Rows are grouped by kind, authored asset and LOD;
|
|
138
|
+
* models and palettes are packed instance-major for `GpuSkin` or an equivalent caller renderer.
|
|
139
|
+
* `bindingSlots` remain available to a pooled renderer and are deliberately opaque here.
|
|
140
|
+
*/
|
|
141
|
+
export interface GpuCrowdCharacterPartDrawBatch {
|
|
142
|
+
kind: GpuCharacterPartKind;
|
|
143
|
+
asset: number;
|
|
144
|
+
lod: number;
|
|
145
|
+
count: number;
|
|
146
|
+
actorSlots: Uint32Array;
|
|
147
|
+
bindingSlots: Uint32Array;
|
|
148
|
+
socketIndices: Int32Array;
|
|
149
|
+
models: Float32Array;
|
|
150
|
+
palettes: Float32Array;
|
|
151
|
+
bounds: Float32Array;
|
|
152
|
+
}
|
|
153
|
+
/** The game owns the actual render pass; this receives executable, asset-grouped draw inputs. */
|
|
154
|
+
export interface GpuCrowdCharacterPartDrawBackend {
|
|
155
|
+
submitPartDraws(batches: readonly GpuCrowdCharacterPartDrawBatch[]): void;
|
|
156
|
+
}
|
|
157
|
+
export interface GpuCrowdCharacterPartDispatcherOptions {
|
|
158
|
+
backend: GpuCrowdCharacterPartDrawBackend;
|
|
159
|
+
/** Body and face already use `GpuCrowdRenderer`; include them only for a replacement renderer. */
|
|
160
|
+
includeBodyAndFace?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts the unified composition table into concrete instanced draw submissions. This is the
|
|
164
|
+
* generic boundary the engine can provide without inventing a mesh format: the caller maps each
|
|
165
|
+
* authored `asset` to its own GPU renderer and encodes those prepared batches in its scene pass.
|
|
166
|
+
*/
|
|
167
|
+
export declare class GpuCrowdCharacterPartDispatcher implements GpuCrowdCharacterCompositionBackend {
|
|
168
|
+
private readonly backend;
|
|
169
|
+
private readonly includeBodyAndFace;
|
|
170
|
+
constructor(options: GpuCrowdCharacterPartDispatcherOptions);
|
|
171
|
+
submitComposition(frame: GpuCrowdCharacterCompositionFrame, resources: GpuCrowdCharacterCompositionResources): void;
|
|
172
|
+
}
|
|
173
|
+
export declare function createGpuCrowdCharacterPartDispatcher(options: GpuCrowdCharacterPartDispatcherOptions): GpuCrowdCharacterPartDispatcher;
|
|
174
|
+
/** Immutable mesh/material fields for one authored part; pose and placement come from the batch. */
|
|
175
|
+
export type GpuSkinCharacterPartAsset = Omit<SkinCreature, 'palette' | 'model' | 'instances'>;
|
|
176
|
+
export interface GpuSkinCharacterPartDrawBackendOptions {
|
|
177
|
+
renderer: Pick<GpuSkinRenderer, 'setCreatures'>;
|
|
178
|
+
resolveAsset: (kind: GpuCharacterPartKind, asset: number, lod: number) => GpuSkinCharacterPartAsset | null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Executable adapter for the engine's existing skinned-mesh renderer. After submission, the game's
|
|
182
|
+
* normal `GpuSkinRenderer.frame(...)` call deforms and draws every grouped part. Asset GPU resources
|
|
183
|
+
* remain caller-owned; a body-conformed garment must resolve to its conformed mesh (or use a pooled
|
|
184
|
+
* backend) because this adapter intentionally shares one immutable mesh per asset/LOD batch.
|
|
185
|
+
*/
|
|
186
|
+
export declare class GpuSkinCharacterPartDrawBackend implements GpuCrowdCharacterPartDrawBackend {
|
|
187
|
+
private readonly renderer;
|
|
188
|
+
private readonly resolveAsset;
|
|
189
|
+
constructor(options: GpuSkinCharacterPartDrawBackendOptions);
|
|
190
|
+
submitPartDraws(batches: readonly GpuCrowdCharacterPartDrawBatch[]): void;
|
|
191
|
+
}
|
|
192
|
+
export declare function createGpuSkinCharacterPartDrawBackend(options: GpuSkinCharacterPartDrawBackendOptions): GpuSkinCharacterPartDrawBackend;
|
|
193
|
+
export interface GpuCrowdCharacterPartAllocation {
|
|
194
|
+
actorSlot: number;
|
|
195
|
+
revision: number;
|
|
196
|
+
kind: GpuCharacterPartKind;
|
|
197
|
+
asset: number;
|
|
198
|
+
/** Index within the corresponding hair/garment/attachment list. */
|
|
199
|
+
partIndex: number;
|
|
200
|
+
lod: number;
|
|
201
|
+
slot: number;
|
|
202
|
+
}
|
|
203
|
+
export interface GpuCrowdCharacterPartBindingLifecycleOptions {
|
|
204
|
+
/** Resolve the existing body/face crowd allocations. Their format and ownership stay unchanged. */
|
|
205
|
+
resolveBase: (identity: Readonly<GpuCharacterIdentityUpdate>) => Omit<GpuCrowdCharacterBinding, 'hair' | 'garments' | 'socketAttachments'>;
|
|
206
|
+
releaseBase?: (binding: GpuCrowdCharacterBinding, identity: Readonly<GpuCharacterIdentityUpdate>) => void;
|
|
207
|
+
/** Number of authored LODs for a part asset. */
|
|
208
|
+
lodCount: (kind: GpuCharacterPartKind, asset: number) => number;
|
|
209
|
+
/** Allocate one caller-owned opaque slot. Null explicitly marks an unsupported LOD. */
|
|
210
|
+
allocate: (request: Omit<GpuCrowdCharacterPartAllocation, 'slot'>) => number | null;
|
|
211
|
+
release: (allocation: GpuCrowdCharacterPartAllocation) => void;
|
|
212
|
+
}
|
|
213
|
+
export interface GpuCrowdCharacterPartBindingLifecycle {
|
|
214
|
+
resolveBinding: GpuCrowdCharactersBackendOptions['resolveBinding'];
|
|
215
|
+
releaseBinding: NonNullable<GpuCrowdCharactersBackendOptions['releaseBinding']>;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Cold-path allocator for hair, garments and socket attachments. It gives every actor/part/LOD a
|
|
219
|
+
* retained caller-owned slot, rolls partial failures back, and releases exactly those slots on
|
|
220
|
+
* identity replacement, removal or backend disposal. Body and face remain delegated to the
|
|
221
|
+
* existing crowd allocator so current games do not have to change their pool layout.
|
|
222
|
+
*/
|
|
223
|
+
export declare function createGpuCrowdCharacterPartBindingLifecycle(options: GpuCrowdCharacterPartBindingLifecycleOptions): GpuCrowdCharacterPartBindingLifecycle;
|
|
130
224
|
/** The narrow renderer surface used by the concrete crowd backend (and by its CPU-only tests). */
|
|
131
225
|
export type GpuCrowdCharacterRenderer = Pick<GpuCrowdRenderer, 'morph' | 'enableFaceRig' | 'disableFaceRig' | 'setFaceWeights' | 'faceFrame' | 'setInstances' | 'setPalettes'>;
|
|
132
226
|
export interface GpuCrowdCharactersBackendOptions {
|
package/dist/character.js
CHANGED
|
@@ -49,6 +49,217 @@ export const GPU_CHARACTER_PART_KIND = {
|
|
|
49
49
|
garment: 3,
|
|
50
50
|
socketAttachment: 4,
|
|
51
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Converts the unified composition table into concrete instanced draw submissions. This is the
|
|
54
|
+
* generic boundary the engine can provide without inventing a mesh format: the caller maps each
|
|
55
|
+
* authored `asset` to its own GPU renderer and encodes those prepared batches in its scene pass.
|
|
56
|
+
*/
|
|
57
|
+
export class GpuCrowdCharacterPartDispatcher {
|
|
58
|
+
backend;
|
|
59
|
+
includeBodyAndFace;
|
|
60
|
+
constructor(options) {
|
|
61
|
+
this.backend = options.backend;
|
|
62
|
+
this.includeBodyAndFace = options.includeBodyAndFace ?? false;
|
|
63
|
+
}
|
|
64
|
+
submitComposition(frame, resources) {
|
|
65
|
+
const paletteStride = positiveInt(resources.boneCount, 'boneCount') * 16;
|
|
66
|
+
if (resources.palettes.length % paletteStride !== 0)
|
|
67
|
+
throw new Error('composition palettes do not contain whole rows');
|
|
68
|
+
const groups = new Map();
|
|
69
|
+
for (let row = 0; row < frame.count; row++) {
|
|
70
|
+
const kind = frame.kinds[row];
|
|
71
|
+
if (!this.includeBodyAndFace &&
|
|
72
|
+
(kind === GPU_CHARACTER_PART_KIND.body ||
|
|
73
|
+
kind === GPU_CHARACTER_PART_KIND.face))
|
|
74
|
+
continue;
|
|
75
|
+
const paletteRow = frame.paletteRows[row];
|
|
76
|
+
if ((paletteRow + 1) * paletteStride > resources.palettes.length)
|
|
77
|
+
throw new Error(`composition row ${row} references unavailable palette ${paletteRow}`);
|
|
78
|
+
const key = `${kind}:${frame.assets[row]}:${frame.lods[row]}`;
|
|
79
|
+
const rows = groups.get(key);
|
|
80
|
+
if (rows)
|
|
81
|
+
rows.push(row);
|
|
82
|
+
else
|
|
83
|
+
groups.set(key, [row]);
|
|
84
|
+
}
|
|
85
|
+
const batches = [];
|
|
86
|
+
for (const rows of groups.values()) {
|
|
87
|
+
const first = rows[0];
|
|
88
|
+
const count = rows.length;
|
|
89
|
+
const actorSlots = new Uint32Array(count);
|
|
90
|
+
const bindingSlots = new Uint32Array(count);
|
|
91
|
+
const socketIndices = new Int32Array(count);
|
|
92
|
+
const models = new Float32Array(count * 16);
|
|
93
|
+
const palettes = new Float32Array(count * paletteStride);
|
|
94
|
+
const bounds = new Float32Array(count * 4);
|
|
95
|
+
rows.forEach((row, instance) => {
|
|
96
|
+
actorSlots[instance] = frame.actorSlots[row];
|
|
97
|
+
bindingSlots[instance] = frame.bindingSlots[row];
|
|
98
|
+
socketIndices[instance] = frame.socketIndices[row];
|
|
99
|
+
models.set(frame.transforms.subarray(row * 16, row * 16 + 16), instance * 16);
|
|
100
|
+
const paletteRow = frame.paletteRows[row];
|
|
101
|
+
palettes.set(resources.palettes.subarray(paletteRow * paletteStride, (paletteRow + 1) * paletteStride), instance * paletteStride);
|
|
102
|
+
bounds.set(frame.bounds.subarray(row * 4, row * 4 + 4), instance * 4);
|
|
103
|
+
});
|
|
104
|
+
batches.push({
|
|
105
|
+
kind: frame.kinds[first],
|
|
106
|
+
asset: frame.assets[first],
|
|
107
|
+
lod: frame.lods[first],
|
|
108
|
+
count,
|
|
109
|
+
actorSlots,
|
|
110
|
+
bindingSlots,
|
|
111
|
+
socketIndices,
|
|
112
|
+
models,
|
|
113
|
+
palettes,
|
|
114
|
+
bounds,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
this.backend.submitPartDraws(batches);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function createGpuCrowdCharacterPartDispatcher(options) {
|
|
121
|
+
return new GpuCrowdCharacterPartDispatcher(options);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Executable adapter for the engine's existing skinned-mesh renderer. After submission, the game's
|
|
125
|
+
* normal `GpuSkinRenderer.frame(...)` call deforms and draws every grouped part. Asset GPU resources
|
|
126
|
+
* remain caller-owned; a body-conformed garment must resolve to its conformed mesh (or use a pooled
|
|
127
|
+
* backend) because this adapter intentionally shares one immutable mesh per asset/LOD batch.
|
|
128
|
+
*/
|
|
129
|
+
export class GpuSkinCharacterPartDrawBackend {
|
|
130
|
+
renderer;
|
|
131
|
+
resolveAsset;
|
|
132
|
+
constructor(options) {
|
|
133
|
+
this.renderer = options.renderer;
|
|
134
|
+
this.resolveAsset = options.resolveAsset;
|
|
135
|
+
}
|
|
136
|
+
submitPartDraws(batches) {
|
|
137
|
+
this.renderer.setCreatures(batches.map((batch) => {
|
|
138
|
+
positiveInt(batch.count, 'part draw count');
|
|
139
|
+
if (batch.models.length !== batch.count * 16)
|
|
140
|
+
throw new Error('part draw models do not match count');
|
|
141
|
+
if (batch.palettes.length === 0 ||
|
|
142
|
+
batch.palettes.length % (batch.count * 16) !== 0)
|
|
143
|
+
throw new Error('part draw palettes do not contain whole instance rows');
|
|
144
|
+
const asset = this.resolveAsset(batch.kind, batch.asset, batch.lod);
|
|
145
|
+
if (!asset)
|
|
146
|
+
throw new Error(`no GpuSkin asset for character part ${batch.kind}:${batch.asset}:LOD${batch.lod}`);
|
|
147
|
+
return {
|
|
148
|
+
...asset,
|
|
149
|
+
// GpuSkin's legacy required fields remain valid; `instances` is the active path.
|
|
150
|
+
palette: batch.palettes.subarray(0, batch.palettes.length / batch.count),
|
|
151
|
+
model: batch.models.subarray(0, 16),
|
|
152
|
+
instances: {
|
|
153
|
+
count: batch.count,
|
|
154
|
+
palettes: batch.palettes,
|
|
155
|
+
models: batch.models,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export function createGpuSkinCharacterPartDrawBackend(options) {
|
|
162
|
+
return new GpuSkinCharacterPartDrawBackend(options);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Cold-path allocator for hair, garments and socket attachments. It gives every actor/part/LOD a
|
|
166
|
+
* retained caller-owned slot, rolls partial failures back, and releases exactly those slots on
|
|
167
|
+
* identity replacement, removal or backend disposal. Body and face remain delegated to the
|
|
168
|
+
* existing crowd allocator so current games do not have to change their pool layout.
|
|
169
|
+
*/
|
|
170
|
+
export function createGpuCrowdCharacterPartBindingLifecycle(options) {
|
|
171
|
+
const allocationFor = (identity, kind, asset, partIndex) => {
|
|
172
|
+
if (asset < 0)
|
|
173
|
+
return null;
|
|
174
|
+
const count = positiveInt(options.lodCount(kind, asset), 'part lodCount');
|
|
175
|
+
const lodSlots = [];
|
|
176
|
+
try {
|
|
177
|
+
for (let lod = 0; lod < count; lod++) {
|
|
178
|
+
const slot = options.allocate({
|
|
179
|
+
actorSlot: identity.slot,
|
|
180
|
+
revision: identity.revision,
|
|
181
|
+
kind,
|
|
182
|
+
asset,
|
|
183
|
+
partIndex,
|
|
184
|
+
lod,
|
|
185
|
+
});
|
|
186
|
+
if (slot !== null)
|
|
187
|
+
nonNegativeInt(slot, 'part allocation slot');
|
|
188
|
+
lodSlots.push(slot);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
lodSlots.forEach((slot, lod) => {
|
|
193
|
+
if (slot === null)
|
|
194
|
+
return;
|
|
195
|
+
options.release({
|
|
196
|
+
actorSlot: identity.slot,
|
|
197
|
+
revision: identity.revision,
|
|
198
|
+
kind,
|
|
199
|
+
asset,
|
|
200
|
+
partIndex,
|
|
201
|
+
lod,
|
|
202
|
+
slot,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
return { asset, lodSlots };
|
|
208
|
+
};
|
|
209
|
+
const releaseParts = (binding, identity) => {
|
|
210
|
+
const releaseOne = (part, kind, partIndex) => {
|
|
211
|
+
if (!part)
|
|
212
|
+
return;
|
|
213
|
+
part.lodSlots.forEach((slot, lod) => {
|
|
214
|
+
if (slot === null)
|
|
215
|
+
return;
|
|
216
|
+
options.release({
|
|
217
|
+
actorSlot: identity.slot,
|
|
218
|
+
revision: identity.revision,
|
|
219
|
+
kind,
|
|
220
|
+
asset: part.asset,
|
|
221
|
+
partIndex,
|
|
222
|
+
lod,
|
|
223
|
+
slot,
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
releaseOne(binding.hair, GPU_CHARACTER_PART_KIND.hair, 0);
|
|
228
|
+
binding.garments?.forEach((part, index) => {
|
|
229
|
+
releaseOne(part, GPU_CHARACTER_PART_KIND.garment, index);
|
|
230
|
+
});
|
|
231
|
+
binding.socketAttachments?.forEach((part, index) => {
|
|
232
|
+
releaseOne(part, GPU_CHARACTER_PART_KIND.socketAttachment, index);
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
const resolveBinding = (identity) => {
|
|
236
|
+
const base = options.resolveBase(identity);
|
|
237
|
+
const binding = {
|
|
238
|
+
...base,
|
|
239
|
+
garments: [],
|
|
240
|
+
socketAttachments: [],
|
|
241
|
+
};
|
|
242
|
+
try {
|
|
243
|
+
binding.hair =
|
|
244
|
+
allocationFor(identity, GPU_CHARACTER_PART_KIND.hair, identity.hairAsset, 0) ?? undefined;
|
|
245
|
+
binding.garments = identity.garmentAssets.map((asset, index) => allocationFor(identity, GPU_CHARACTER_PART_KIND.garment, asset, index));
|
|
246
|
+
binding.socketAttachments = (identity.socketAttachments ?? []).map((attachment, index) => allocationFor(identity, GPU_CHARACTER_PART_KIND.socketAttachment, attachment.asset, index));
|
|
247
|
+
return binding;
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
releaseParts(binding, identity);
|
|
251
|
+
options.releaseBase?.(binding, identity);
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
return {
|
|
256
|
+
resolveBinding,
|
|
257
|
+
releaseBinding: (binding, identity) => {
|
|
258
|
+
releaseParts(binding, identity);
|
|
259
|
+
options.releaseBase?.(binding, identity);
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
52
263
|
function positiveInt(value, name) {
|
|
53
264
|
if (!Number.isInteger(value) || value <= 0)
|
|
54
265
|
throw new Error(`${name} must be a positive integer`);
|
|
@@ -530,7 +741,10 @@ export class GpuCrowdCharactersBackend {
|
|
|
530
741
|
buckets: buckets.map((bucket) => ({ ...bucket })),
|
|
531
742
|
composition,
|
|
532
743
|
};
|
|
533
|
-
this.compositionBackend?.submitComposition(composition
|
|
744
|
+
this.compositionBackend?.submitComposition(composition, {
|
|
745
|
+
palettes,
|
|
746
|
+
boneCount: this.boneCount,
|
|
747
|
+
});
|
|
534
748
|
}
|
|
535
749
|
lastPreparedFrame() {
|
|
536
750
|
return this.prepared;
|