@doki-land/live2d-renderer 0.0.18 → 0.0.20

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/index.d.ts CHANGED
@@ -34,7 +34,7 @@ interface TextureData {
34
34
  }
35
35
  interface ModelDrawPass {
36
36
  setTextures(textures: TextureData[]): void;
37
- draw(drawables: DrawableMesh[], modelMatrix: Float32Array): void;
37
+ draw(drawables: readonly DrawableMesh[], modelMatrix: Float32Array): void;
38
38
  destroy(): void;
39
39
  }
40
40
  /** Top-level renderer bound to a canvas. */
@@ -177,7 +177,7 @@ declare function parseCpuProgram(bytes: ArrayBuffer): ModelProgram;
177
177
  /** Create a runtime instance with default parameter values. */
178
178
  declare function createModelInstance(program: ModelProgram): ModelInstance;
179
179
  declare function setParameterValue(instance: ModelInstance, parameterId: string, value: number): void;
180
- /** CPU deform 鈫?FrameSnapshot. */
180
+ /** CPU deform FrameSnapshot. */
181
181
  declare function evaluateFrame(instance: ModelInstance): FrameSnapshot;
182
182
  /** Stable fingerprint for golden tests (positions + topology). */
183
183
  declare function fingerprintSnapshot(snapshot: FrameSnapshot): string;
@@ -279,6 +279,11 @@ interface ModelBackend {
279
279
  setParameter?(model: InternalModel, id: string, value: number): void;
280
280
  /** Optional PartOpacity override (moc3 parts / pose / motion). */
281
281
  setPartOpacity?(model: InternalModel, id: string, value: number): void;
282
+ /**
283
+ * Resolve parameter id → index (O(1) after load).
284
+ * Used by motion blend / hosts instead of `listParameters().find`.
285
+ */
286
+ resolveParameter?(model: InternalModel, id: string): number | undefined;
282
287
  listParameters?(model: InternalModel): readonly ParameterBinding[];
283
288
  }
284
289
  declare function selectModelBackend(backends: ModelBackend[], json: unknown): ModelBackend;
@@ -292,9 +297,12 @@ declare class Moc2Backend implements ModelBackend {
292
297
  getDrawables(model: InternalModel): DrawableMesh[];
293
298
  captureFrame(model: InternalModel): FrameSnapshot | null;
294
299
  setParameter(model: InternalModel, id: string, value: number): void;
300
+ resolveParameter(model: InternalModel, id: string): number | undefined;
295
301
  listParameters(model: InternalModel): readonly ParameterBinding[];
296
302
  hitTest(_model: InternalModel, _x: number, _y: number): string | null;
297
303
  destroyModel(model: InternalModel): void;
304
+ /** Test/harness: stable program + instance refs. */
305
+ getResidentInstance(model: InternalModel): ModelInstance | null;
298
306
  }
299
307
  declare function createMoc2Backend(): Moc2Backend;
300
308
 
@@ -308,9 +316,11 @@ declare class Moc3Backend implements ModelBackend {
308
316
  captureFrame(model: InternalModel): FrameSnapshot | null;
309
317
  setParameter(model: InternalModel, id: string, value: number): void;
310
318
  setPartOpacity(model: InternalModel, id: string, value: number): void;
319
+ resolveParameter(model: InternalModel, id: string): number | undefined;
311
320
  listParameters(model: InternalModel): readonly ParameterBinding[];
312
321
  hitTest(_model: InternalModel, _x: number, _y: number): string | null;
313
322
  destroyModel(model: InternalModel): void;
323
+ getResidentInstance(model: InternalModel): ModelInstance | null;
314
324
  }
315
325
  declare function createMoc3Backend(): Moc3Backend;
316
326
 
@@ -501,10 +511,56 @@ declare function calcClippedDrawableBounds(clippedIndices: readonly number[], by
501
511
  * drawable AABB into the atlas cell (higher mask texel density).
502
512
  */
503
513
  declare function fitClippingContexts(contexts: readonly LaidOutClippingContext[], byIndex: ReadonlyMap<number, MaskBoundsMeshRef>, margin?: number): LaidOutClippingContext[];
504
- /** Flatten layout to `[x, y, w, h]` for GPU uniforms. */
505
- declare function maskLayoutVec4(layout: MaskLayoutRect): Float32Array;
506
- /** Flatten channel flag to `[r, g, b, a]` for GPU uniforms. */
507
- declare function maskChannelVec4(flag: MaskChannelFlag): Float32Array;
514
+ /** Flatten layout to `[x, y, w, h]` for GPU uniforms. Reuses `into` when provided. */
515
+ declare function maskLayoutVec4(layout: MaskLayoutRect, into?: Float32Array): Float32Array;
516
+ /** Flatten channel flag to `[r, g, b, a]` for GPU uniforms. Reuses `into` when provided. */
517
+ declare function maskChannelVec4(flag: MaskChannelFlag, into?: Float32Array): Float32Array;
518
+
519
+ /**
520
+ * Resident clipping / mask atlas plan.
521
+ *
522
+ * Topology (maskIndices / invert / packing options) is compiled once; per frame
523
+ * only `modelBounds` is refreshed from current vertex positions.
524
+ */
525
+
526
+ /** Stable key for mask topology (ignores vertex positions / opacity). */
527
+ declare function clippingTopologyKey(drawables: readonly ClippingDrawableRef[]): string;
528
+ type ResidentContext = {
529
+ -readonly [K in keyof LaidOutClippingContext]: LaidOutClippingContext[K];
530
+ } & {
531
+ modelBounds: MaskLayoutRect;
532
+ };
533
+ /**
534
+ * Update `modelBounds` on resident contexts without reallocating the plan.
535
+ */
536
+ declare function fitClippingContextsInPlace(contexts: readonly ResidentContext[], byIndex: ReadonlyMap<number, MaskBoundsMeshRef>, margin?: number): void;
537
+ /**
538
+ * Caches atlas layout + mask/clipped sets while drawable mask topology is
539
+ * unchanged. Call {@link resolve} each frame; call {@link clear} on destroy.
540
+ */
541
+ declare class ResidentClippingPlan {
542
+ #private;
543
+ /**
544
+ * Returns a partition whose `contexts` array identity is stable across
545
+ * frames with the same topology. `modelBounds` are refreshed in place.
546
+ */
547
+ resolve(drawables: readonly ClippingDrawableRef[], options?: MaskAtlasOptions): ClippingPartition;
548
+ /** Convenience for full drawable meshes (GPU backends). */
549
+ resolveMeshes(drawables: readonly DrawableMesh[], options?: MaskAtlasOptions): ClippingPartition;
550
+ /** True when the last {@link resolve} reused the cached atlas layout. */
551
+ get hasPlan(): boolean;
552
+ /** Exposed for tests — context array identity while topology holds. */
553
+ get residentContexts(): readonly LaidOutClippingContext[];
554
+ clear(): void;
555
+ }
556
+
557
+ /**
558
+ * Pos/UV interleave with optional resident output buffer (GPU upload scratch).
559
+ */
560
+ /** Interleave `[x,y]` + `[u,v]` into `[x,y,u,v,…]`. Reuses `into` when large enough. */
561
+ declare function interleavePosUv(positions: Float32Array, uvs: Float32Array, into?: Float32Array): Float32Array;
562
+ /** Byte length of the live interleaved prefix (vertexCount * 16). */
563
+ declare function interleaveByteLength(positions: Float32Array): number;
508
564
 
509
565
  /** Shared untextured preview colors (Canvas2D / WebGL2 / WebGPU parity). */
510
566
  declare const PREVIEW_FILL: {
@@ -556,4 +612,4 @@ declare function compileSharedModelCompile(settings: ModelSettings, mocBytes: Ar
556
612
 
557
613
  declare const LIVE2D_RENDERER_VERSION: "0.0.0";
558
614
 
559
- export { BlendMode, CPU_PROGRAM_KIND, Canvas2DRendererImpl, type Canvas2DRendererOptions, type ClippingContext, type ClippingDrawableRef, type ClippingPartition, type CpuProgramFile, type CreateRendererOptions, type DecodedMoc2, type DecodedMoc3, type DrawableMesh, FULL_NDC_BOUNDS, LIVE2D_RENDERER_VERSION, type LaidOutClippingContext, MASK_CHANNEL_FLAGS, type MaskAtlasMode, type MaskAtlasOptions, type MaskChannelFlag, type MaskLayoutRect, Moc2Backend, Moc3Backend, Moc3DrawableFlag, type Moc3GlueDef, type Moc3GluePair, type ModelBackend, type ModelBackendOptions, type ModelDrawPass, PREVIEW_FILL, PREVIEW_STROKE, type ParameterBinding, type Renderer, type RendererKind, type SharedModelCompile, type TextureData, type WebGl2Renderer, WebGl2RendererImpl, type WebGl2RendererOptions, type WebGpuRenderer, WebGpuRendererImpl, type WebGpuRendererOptions, applyMoc3Glues, applyWebGl2BlendMode, buildClippingContexts, calcClippedDrawableBounds, calcVertexBounds, canvasCompositeForBlendMode, compileSharedModelCompile, createCanvas2DRenderer, createMoc2Backend, createMoc3Backend, createModelInstance, createQuadProgram, createRenderer, createWebGl2Renderer, createWebGpuRenderer, decodeMoc2, decodeMoc2ColorComposition, decodeMoc3, decodeMoc3DrawableFlags, detectMocBinaryFormat, evaluateFrame, expandBounds, fingerprintSnapshot, fitClippingContexts, isCanvas2DAvailable, isCpuProgramBytes, isWebGl2Available, isWebGpuAvailable, layoutMaskAtlas, layoutMaskAtlasRgba, layoutMaskAtlasUvGrid, loadMoc3Glues, maskChannelVec4, maskLayoutVec4, meanGlueSeamDistance, parseCpuProgram, partitionForClipping, selectModelBackend, serializeCpuProgram, setParameterValue, triangleEdgesToLineList, webGpuBlendState };
615
+ export { BlendMode, CPU_PROGRAM_KIND, Canvas2DRendererImpl, type Canvas2DRendererOptions, type ClippingContext, type ClippingDrawableRef, type ClippingPartition, type CpuProgramFile, type CreateRendererOptions, type DecodedMoc2, type DecodedMoc3, type DrawableMesh, FULL_NDC_BOUNDS, LIVE2D_RENDERER_VERSION, type LaidOutClippingContext, MASK_CHANNEL_FLAGS, type MaskAtlasMode, type MaskAtlasOptions, type MaskChannelFlag, type MaskLayoutRect, Moc2Backend, Moc3Backend, Moc3DrawableFlag, type Moc3GlueDef, type Moc3GluePair, type ModelBackend, type ModelBackendOptions, type ModelDrawPass, PREVIEW_FILL, PREVIEW_STROKE, type ParameterBinding, type Renderer, type RendererKind, ResidentClippingPlan, type SharedModelCompile, type TextureData, type WebGl2Renderer, WebGl2RendererImpl, type WebGl2RendererOptions, type WebGpuRenderer, WebGpuRendererImpl, type WebGpuRendererOptions, applyMoc3Glues, applyWebGl2BlendMode, buildClippingContexts, calcClippedDrawableBounds, calcVertexBounds, canvasCompositeForBlendMode, clippingTopologyKey, compileSharedModelCompile, createCanvas2DRenderer, createMoc2Backend, createMoc3Backend, createModelInstance, createQuadProgram, createRenderer, createWebGl2Renderer, createWebGpuRenderer, decodeMoc2, decodeMoc2ColorComposition, decodeMoc3, decodeMoc3DrawableFlags, detectMocBinaryFormat, evaluateFrame, expandBounds, fingerprintSnapshot, fitClippingContexts, fitClippingContextsInPlace, interleaveByteLength, interleavePosUv, isCanvas2DAvailable, isCpuProgramBytes, isWebGl2Available, isWebGpuAvailable, layoutMaskAtlas, layoutMaskAtlasRgba, layoutMaskAtlasUvGrid, loadMoc3Glues, maskChannelVec4, maskLayoutVec4, meanGlueSeamDistance, parseCpuProgram, partitionForClipping, selectModelBackend, serializeCpuProgram, setParameterValue, triangleEdgesToLineList, webGpuBlendState };