@doki-land/live2d 0.0.22 → 0.0.24
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 +128 -11
- package/dist/index.js +406 -44
- package/package.json +4 -4
- package/src/expression/apply-expression.ts +41 -0
- package/src/expression/index.ts +7 -0
- package/src/expression/parse-expression3.ts +45 -0
- package/src/expression/types.ts +13 -0
- package/src/facade/create-live2d.ts +10 -3
- package/src/index.ts +32 -4
- package/src/physics/apply-physics3.ts +26 -0
- package/src/physics/index.ts +7 -0
- package/src/physics/parse-physics3.ts +52 -0
- package/src/physics/types.ts +20 -0
- package/src/pose/apply-pose3.ts +19 -0
- package/src/pose/index.ts +3 -0
- package/src/pose/parse-pose3.ts +33 -0
- package/src/pose/types.ts +4 -0
- package/src/stage/actor-model-slot.ts +172 -21
- package/src/stage/actor.ts +36 -1
- package/src/stage/hit-area.ts +24 -0
- package/src/stage/index.ts +5 -1
- package/src/stage/model-asset-registry.ts +49 -15
- package/src/stage/single-facade.ts +27 -7
- package/src/stage/stage.ts +12 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import * as _doki_land_live2d_core from '@doki-land/live2d-core';
|
|
2
|
-
import { Live2dStageAssets, ModelSource, AssetResolver, ModelAsset, LoadProgress, ModelSettings, InternalModel, Live2dActor, CreateActorOptions, ActorTransform, PlayMotionActorOptions, ActorHit, CreateLive2dStageOptions, Live2dStage, PointerTrackingPolicy, StagePointerEvent,
|
|
3
|
-
export { ActorHit, ActorInstance, ActorTransform, AssetResolver, CreateActorOptions, CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, EventEmitter, FrameProfile, FrameSnapshot, InternalModel,
|
|
2
|
+
import { Live2dStageAssets, ModelSource, AssetResolver, ModelAsset, LoadProgress, ModelSettings, InternalModel, Live2dActor, CreateActorOptions, ActorTransform, PlayMotionActorOptions, ActorHit, CreateLive2dStageOptions, Live2dStage, PointerTrackingPolicy, StagePointerEvent, Live2dSession, HitAreaDefinition } from '@doki-land/live2d-core';
|
|
3
|
+
export { ActorHit, ActorInstance, ActorTransform, AssetResolver, CreateActorOptions, CreateLive2dStageOptions, DEFAULT_ACTOR_TRANSFORM, EventEmitter, FrameProfile, FrameSnapshot, InternalModel, Live2dActor, Live2dSession, Live2dStage, Live2dStageAssets, LoadProgress, LoadProgressStage, ModelAsset, ModelFormat, ModelInstance, ModelProgram, ModelSettings, ModelSource, PlayMotionActorOptions, PointerTrackingMode, PointerTrackingPolicy, SessionPhase, SessionState, StagePointerEvent, StageUpdateMode } from '@doki-land/live2d-core';
|
|
4
4
|
export { DEFAULT_NPM_CDN, resolveModelSourceUrl, resolveNpmSpecifier } from '@doki-land/live2d-loader';
|
|
5
5
|
import * as _doki_land_live2d_renderer from '@doki-land/live2d-renderer';
|
|
6
6
|
import { ModelBackend, compileSharedModelCompile, TextureData, Renderer, ParameterBinding, DrawableMesh, RendererKind } from '@doki-land/live2d-renderer';
|
|
7
7
|
export { ModelBackend, ParameterBinding, Renderer, RendererKind, createCanvas2DRenderer, createMoc2Backend, createMoc3Backend, createQuadProgram, createRenderer, createWebGl2Renderer, createWebGpuRenderer, decodeMoc3, evaluateFrame, fingerprintSnapshot, parseCpuProgram, serializeCpuProgram } from '@doki-land/live2d-renderer';
|
|
8
8
|
|
|
9
|
+
type ExpressionBlendMode = "Add" | "Multiply" | "Override";
|
|
10
|
+
interface Expression3Parameter {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly value: number;
|
|
13
|
+
readonly blend: ExpressionBlendMode;
|
|
14
|
+
}
|
|
15
|
+
/** Parsed Cubism `exp3.json`. */
|
|
16
|
+
interface Expression3Clip {
|
|
17
|
+
readonly version: number;
|
|
18
|
+
readonly parameters: readonly Expression3Parameter[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ExpressionApplyBinding {
|
|
22
|
+
readonly value: number;
|
|
23
|
+
}
|
|
24
|
+
/** Apply expression parameters on top of the current parameter state. */
|
|
25
|
+
declare function applyExpression3Clip(clip: Expression3Clip, weight: number, bindings: ReadonlyMap<string, ExpressionApplyBinding>, setParameter: (id: string, value: number) => void): void;
|
|
26
|
+
|
|
27
|
+
/** Parse Cubism `exp3.json` (FileFormats/exp3.json.md subset). */
|
|
28
|
+
declare function parseExpression3(json: unknown): Expression3Clip;
|
|
29
|
+
|
|
9
30
|
/** Cubism motion3 segment kinds (spec). */
|
|
10
31
|
type MotionSegmentKind = "linear" | "bezier" | "stepped" | "inverseStepped";
|
|
11
32
|
type MotionCurveTarget = "Parameter" | "PartOpacity" | "Model";
|
|
@@ -198,7 +219,9 @@ declare class ModelAssetRegistry implements Live2dStageAssets {
|
|
|
198
219
|
#private;
|
|
199
220
|
constructor(options: ModelAssetRegistryOptions);
|
|
200
221
|
load(source: ModelSource, resolver?: AssetResolver): Promise<ModelAsset>;
|
|
201
|
-
acquire(source: ModelSource, resolver: AssetResolver | undefined, onProgress?: (payload: LoadProgress) => void
|
|
222
|
+
acquire(source: ModelSource, resolver: AssetResolver | undefined, onProgress?: (payload: LoadProgress) => void, options?: {
|
|
223
|
+
signal?: AbortSignal;
|
|
224
|
+
}): Promise<ModelAssetLease>;
|
|
202
225
|
acquireExisting(asset: ModelAsset): ModelAssetLease;
|
|
203
226
|
destroy(): void;
|
|
204
227
|
}
|
|
@@ -229,11 +252,15 @@ declare class ActorModelSlot {
|
|
|
229
252
|
/** Load-time stable id → binding map (binding.value updated on setParameter). */
|
|
230
253
|
parameterMap(): ReadonlyMap<string, ParameterBinding>;
|
|
231
254
|
resolveParameter(id: string): number | undefined;
|
|
232
|
-
load(source: ModelSource, resolver?: AssetResolver
|
|
255
|
+
load(source: ModelSource, resolver?: AssetResolver, options?: {
|
|
256
|
+
signal?: AbortSignal;
|
|
257
|
+
}): Promise<InternalModel>;
|
|
233
258
|
loadAsset(asset: ModelAsset): Promise<InternalModel>;
|
|
234
259
|
setParameter(id: string, value: number): void;
|
|
235
260
|
listParameters(): readonly ParameterBinding[];
|
|
236
261
|
listMotionGroups(): Record<string, readonly _doki_land_live2d_core.MotionDefinition[]>;
|
|
262
|
+
listExpressions(): readonly _doki_land_live2d_core.ExpressionDefinition[];
|
|
263
|
+
setExpression(name: string | null): Promise<boolean>;
|
|
237
264
|
playMotion(group: string, index?: number, options?: PlayMotionOptions): Promise<boolean>;
|
|
238
265
|
stopMotion(opts?: {
|
|
239
266
|
fade?: boolean;
|
|
@@ -262,6 +289,19 @@ declare class Live2dActorImpl implements Live2dActor {
|
|
|
262
289
|
readonly id: string;
|
|
263
290
|
readonly creationIndex: number;
|
|
264
291
|
constructor(options: CreateActorOptions | undefined, shared: Live2dActorImplOptions);
|
|
292
|
+
/** Bridge MotionPlayer lifecycle into Stage/facade event buses. */
|
|
293
|
+
setMotionEventHandlers(handlers: {
|
|
294
|
+
onStart?: (payload: {
|
|
295
|
+
group: string;
|
|
296
|
+
index: number;
|
|
297
|
+
slot: string;
|
|
298
|
+
}) => void;
|
|
299
|
+
onFinish?: (payload: {
|
|
300
|
+
group: string;
|
|
301
|
+
index: number;
|
|
302
|
+
slot: string;
|
|
303
|
+
}) => void;
|
|
304
|
+
}): void;
|
|
265
305
|
get model(): InternalModel | null;
|
|
266
306
|
get visible(): boolean;
|
|
267
307
|
set visible(value: boolean);
|
|
@@ -273,7 +313,9 @@ declare class Live2dActorImpl implements Live2dActor {
|
|
|
273
313
|
set order(value: number);
|
|
274
314
|
getTransform(): ActorTransform;
|
|
275
315
|
setTransform(patch: Partial<ActorTransform>): void;
|
|
276
|
-
load(source: Parameters<Live2dActor["load"]>[0], resolver?: Parameters<Live2dActor["load"]>[1]
|
|
316
|
+
load(source: Parameters<Live2dActor["load"]>[0], resolver?: Parameters<Live2dActor["load"]>[1], options?: {
|
|
317
|
+
signal?: AbortSignal;
|
|
318
|
+
}): Promise<InternalModel>;
|
|
277
319
|
loadAsset(asset: ModelAsset): Promise<InternalModel>;
|
|
278
320
|
setParameter(id: string, value: number): void;
|
|
279
321
|
listParameters(): readonly _doki_land_live2d_renderer.ParameterBinding[];
|
|
@@ -292,6 +334,8 @@ declare class Live2dActorImpl implements Live2dActor {
|
|
|
292
334
|
time: number;
|
|
293
335
|
priority: number;
|
|
294
336
|
}[];
|
|
337
|
+
listExpressions(): readonly _doki_land_live2d_core.ExpressionDefinition[];
|
|
338
|
+
setExpression(name: string | null): Promise<boolean>;
|
|
295
339
|
lookAt(stageX: number, stageY: number): void;
|
|
296
340
|
/** Internal: evaluate motion/physics and cache drawables for render. */
|
|
297
341
|
update(deltaTimeSeconds: number): DrawableMesh[] | null;
|
|
@@ -300,6 +344,7 @@ declare class Live2dActorImpl implements Live2dActor {
|
|
|
300
344
|
hitTestStage(stageX: number, stageY: number): Omit<ActorHit, "actor"> | null;
|
|
301
345
|
destroy(): void;
|
|
302
346
|
}
|
|
347
|
+
declare function allocateActorId(prefix?: string): string;
|
|
303
348
|
|
|
304
349
|
interface CreateLive2dStageFullOptions extends CreateLive2dStageOptions {
|
|
305
350
|
backends?: ModelBackend[];
|
|
@@ -322,6 +367,7 @@ declare class Live2dStageImpl implements Live2dStage {
|
|
|
322
367
|
removeActor(actorOrId: Live2dActor | string): void;
|
|
323
368
|
defineLayers(layers: readonly string[]): void;
|
|
324
369
|
update(deltaTimeSeconds: number): void;
|
|
370
|
+
onFrame(listener: (deltaTimeSeconds: number) => void): () => void;
|
|
325
371
|
render(): void;
|
|
326
372
|
start(): void;
|
|
327
373
|
pause(): void;
|
|
@@ -335,13 +381,13 @@ declare class Live2dStageImpl implements Live2dStage {
|
|
|
335
381
|
}
|
|
336
382
|
declare function createLive2dStage(options?: CreateLive2dStageFullOptions): Live2dStage;
|
|
337
383
|
|
|
338
|
-
interface
|
|
384
|
+
interface CreateLive2dOptions {
|
|
339
385
|
backends?: ModelBackend[];
|
|
340
386
|
renderer?: Renderer;
|
|
341
387
|
prefer?: RendererKind[];
|
|
342
388
|
updateMode?: "auto" | "manual";
|
|
343
389
|
}
|
|
344
|
-
interface
|
|
390
|
+
interface Live2dRuntime extends Live2dSession {
|
|
345
391
|
readonly renderer: Renderer;
|
|
346
392
|
readonly backends: readonly ModelBackend[];
|
|
347
393
|
readonly stage: Live2dStageImpl;
|
|
@@ -365,14 +411,73 @@ interface Live2DRuntime extends Live2DSession {
|
|
|
365
411
|
time: number;
|
|
366
412
|
priority: number;
|
|
367
413
|
}>;
|
|
414
|
+
listExpressions(): ReadonlyArray<_doki_land_live2d_core.ExpressionDefinition>;
|
|
415
|
+
setExpression(name: string | null): Promise<boolean>;
|
|
368
416
|
capturePng(opts?: {
|
|
369
417
|
mimeType?: "image/png";
|
|
370
418
|
quality?: number;
|
|
371
419
|
}): Promise<Blob>;
|
|
372
420
|
}
|
|
421
|
+
/** @deprecated Use `CreateLive2dOptions`. */
|
|
422
|
+
type CreateLive2DOptions = CreateLive2dOptions;
|
|
423
|
+
/** @deprecated Use `Live2dRuntime`. */
|
|
424
|
+
type Live2DRuntime = Live2dRuntime;
|
|
373
425
|
|
|
374
426
|
/** Wire moc backends and a renderer into one single-actor session. */
|
|
375
|
-
declare function
|
|
427
|
+
declare function createLive2d(options?: CreateLive2dOptions): Live2dRuntime;
|
|
428
|
+
/** @deprecated Use `createLive2d`. */
|
|
429
|
+
declare const createLive2D: typeof createLive2d;
|
|
430
|
+
|
|
431
|
+
/** One physics output destination (parameter id only for the thin gate). */
|
|
432
|
+
interface Physics3Output {
|
|
433
|
+
readonly destinationId: string;
|
|
434
|
+
}
|
|
435
|
+
/** One PhysicsSettings entry with output destinations. */
|
|
436
|
+
interface Physics3Setting {
|
|
437
|
+
readonly id: string;
|
|
438
|
+
readonly outputs: readonly Physics3Output[];
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Parsed Cubism `physics3.json` (minimal).
|
|
442
|
+
* Full spring / pendulum simulation is intentionally out of scope for this gate.
|
|
443
|
+
*/
|
|
444
|
+
interface Physics3Clip {
|
|
445
|
+
readonly settings: readonly Physics3Setting[];
|
|
446
|
+
/** Flattened destination parameter ids from all outputs. */
|
|
447
|
+
readonly outputParameterIds: readonly string[];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
interface Physics3ApplyBinding {
|
|
451
|
+
readonly value: number;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Minimal Physics3 apply gate — **not** a full Cubism spring / pendulum solver.
|
|
455
|
+
*
|
|
456
|
+
* For each output destination parameter id that exists in `bindings`, performs a
|
|
457
|
+
* trivial identity step (write current value back). Exists so load → update can
|
|
458
|
+
* exercise the physics clip API; real physics evaluation is a later milestone.
|
|
459
|
+
*/
|
|
460
|
+
declare function applyPhysics3(clip: Physics3Clip, _deltaTimeSeconds: number, bindings: ReadonlyMap<string, Physics3ApplyBinding>, setParameter: (id: string, value: number) => void): void;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Parse Cubism `physics3.json` enough to expose PhysicsSettings output parameter ids.
|
|
464
|
+
* Tolerates minimal fixtures (missing / empty PhysicsSettings → empty clip).
|
|
465
|
+
*/
|
|
466
|
+
declare function parsePhysics3(json: unknown): Physics3Clip;
|
|
467
|
+
|
|
468
|
+
/** Parsed Cubism `pose3.json` / legacy `pose.json` groups. */
|
|
469
|
+
interface Pose3Clip {
|
|
470
|
+
readonly groups: readonly (readonly string[])[];
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* When a part in a pose group becomes visible, hide sibling parts in that group.
|
|
475
|
+
* Mirrors Cubism Pose minimum semantics for part-opacity switching.
|
|
476
|
+
*/
|
|
477
|
+
declare function applyPose3Activation(clip: Pose3Clip, activatedPartId: string, setPartOpacity: (partId: string, opacity: number) => void): void;
|
|
478
|
+
|
|
479
|
+
/** Parse Cubism pose file (`pose3.json` or legacy `pose.json`). */
|
|
480
|
+
declare function parsePose3(json: unknown): Pose3Clip;
|
|
376
481
|
|
|
377
482
|
/**
|
|
378
483
|
* Map canvas focus (-1..1, Y-up) onto commonly used model parameter IDs.
|
|
@@ -388,20 +493,32 @@ declare function focusParameterUpdates(parameters: readonly ParameterBinding[] |
|
|
|
388
493
|
value: number;
|
|
389
494
|
}>;
|
|
390
495
|
|
|
496
|
+
interface ResolveHitAreaInput {
|
|
497
|
+
readonly hitAreas: readonly HitAreaDefinition[];
|
|
498
|
+
readonly drawableIndex: number;
|
|
499
|
+
/** Art-mesh / drawable id from MOC when available. */
|
|
500
|
+
readonly artMeshId?: string | null;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Resolve a triangle hit to a named HitArea when settings id matches the drawable.
|
|
504
|
+
* Falls back to `drawable:N` when no mapping exists.
|
|
505
|
+
*/
|
|
506
|
+
declare function resolveHitAreaName(input: ResolveHitAreaInput): string;
|
|
507
|
+
|
|
391
508
|
/**
|
|
392
509
|
* `@doki-land/live2d` — public facade.
|
|
393
510
|
*
|
|
394
511
|
* Layout:
|
|
395
|
-
* - `facade/` — `
|
|
512
|
+
* - `facade/` — `createLive2d()` default stage + actor entry
|
|
396
513
|
* - `motion/` — motion3 parse + playback
|
|
397
514
|
* - `stage/` — multi-actor stage, assets, transforms
|
|
398
515
|
* - `reexports/` — optional subpath `@doki-land/live2d/{core,loader,renderer}`
|
|
399
516
|
*
|
|
400
517
|
* ```ts
|
|
401
|
-
* import {
|
|
518
|
+
* import { createLive2d } from "@doki-land/live2d";
|
|
402
519
|
* ```
|
|
403
520
|
*/
|
|
404
521
|
|
|
405
522
|
declare const LIVE2D_VERSION: "0.0.0";
|
|
406
523
|
|
|
407
|
-
export { type CreateLive2DOptions, type CreateLive2dStageFullOptions, LIVE2D_VERSION, type Live2DRuntime, type Motion3Clip, type MotionApplySample, MotionPlayer, MotionPriority, type PlayMotionOptions, blendMotionLayers, createLive2D, createLive2dStage, evaluateCurve, evaluateMotion3, focusParameterUpdates, parseMotion3 };
|
|
524
|
+
export { type CreateLive2DOptions, type CreateLive2dOptions, type CreateLive2dStageFullOptions, type Expression3Clip, type Expression3Parameter, type ExpressionBlendMode, LIVE2D_VERSION, type Live2DRuntime, type Live2dRuntime, type Motion3Clip, type MotionApplySample, MotionPlayer, MotionPriority, type Physics3ApplyBinding, type Physics3Clip, type Physics3Output, type Physics3Setting, type PlayMotionOptions, type Pose3Clip, allocateActorId, applyExpression3Clip, applyPhysics3, applyPose3Activation, blendMotionLayers, createLive2D, createLive2d, createLive2dStage, evaluateCurve, evaluateMotion3, focusParameterUpdates, parseExpression3, parseMotion3, parsePhysics3, parsePose3, resolveHitAreaName };
|