mesh-avatar 0.3.1 → 0.5.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/README.md +4 -1
- package/dist/engine/arms.d.ts +24 -0
- package/dist/engine/cloth-grid.d.ts +14 -0
- package/dist/engine/cloth-pendulum.d.ts +13 -0
- package/dist/engine/cloth-tuning.d.ts +8 -0
- package/dist/engine/cloth.d.ts +62 -0
- package/dist/engine/createMeshAvatar.d.ts +4 -1
- package/dist/engine/index.d.ts +7 -2
- package/dist/engine/legs.d.ts +25 -0
- package/dist/engine/motion.d.ts +9 -15
- package/dist/engine/overlays.d.ts +15 -0
- package/dist/engine/rig.d.ts +28 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2427 -1673
- package/dist/rig/types.d.ts +74 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,9 @@ avatar.setVoiceLevel(0.6);
|
|
|
68
68
|
avatar.setEmotion('happy', { playMotion: false });
|
|
69
69
|
avatar.setExpression('smile');
|
|
70
70
|
|
|
71
|
+
// Show optional overlay layers (such as glasses) by name; [] hides them all.
|
|
72
|
+
avatar.setOverlays(['glasses']);
|
|
73
|
+
|
|
71
74
|
// Apply tracked or posed parameters. Each call replaces the supplied overrides.
|
|
72
75
|
avatar.setParameters({ angleX: 10, gazeX: 0.25 }, 1);
|
|
73
76
|
|
|
@@ -82,7 +85,7 @@ avatar.setParameters({});
|
|
|
82
85
|
avatar.destroy();
|
|
83
86
|
```
|
|
84
87
|
|
|
85
|
-
Emotion tags are `happy`, `sad`, `angry`, `surprised`, `relaxed` and `neutral` (or `null` to reset). Expressions are `neutral`, `smile`, `shy`, `surprise`, `halfLidded`, `angry`, `sad` and `wink`; `LIVE_EXPRESSIONS` exports that list. `PARAMS` exports the parameter IDs, ranges and defaults. Voice methods animate the avatar; your app handles audio playback.
|
|
88
|
+
Emotion tags are `happy`, `sad`, `angry`, `surprised`, `relaxed` and `neutral` (or `null` to reset). Expressions are `neutral`, `smile`, `shy`, `surprise`, `halfLidded`, `angry`, `sad` and `wink`; `LIVE_EXPRESSIONS` exports that list. `PARAMS` exports the parameter IDs, ranges and defaults. Overlay names come from the avatar's optional `built/overlays/overlays.json`; unknown names are ignored. Voice methods animate the avatar; your app handles audio playback.
|
|
86
89
|
|
|
87
90
|
`loadMeshAvatar` releases archives it opens on `destroy()` or load failure; when passed an existing `AvatarPackage` from `openAvatar`, the caller owns it and must call `release()` after its last user is destroyed.
|
|
88
91
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Optional hanging arms, with image-left/right joints in source pixels. */
|
|
2
|
+
export function createArms(arms: any, body: any, _legs?: null): {
|
|
3
|
+
weights: (x: any, y: any) => {
|
|
4
|
+
arm: number;
|
|
5
|
+
forearm: number;
|
|
6
|
+
}[];
|
|
7
|
+
frame: (P: any, move?: (p: any) => any[]) => {
|
|
8
|
+
shoulder: any[];
|
|
9
|
+
elbow: any[];
|
|
10
|
+
swing: number;
|
|
11
|
+
bend: number;
|
|
12
|
+
}[];
|
|
13
|
+
apply: (p: any, _x: any, _y: any, w: any, P: any, F?: {
|
|
14
|
+
shoulder: any[];
|
|
15
|
+
elbow: any[];
|
|
16
|
+
swing: number;
|
|
17
|
+
bend: number;
|
|
18
|
+
}[]) => void;
|
|
19
|
+
} | null;
|
|
20
|
+
export const ARM_DEFAULTS: Readonly<{
|
|
21
|
+
swing: 4;
|
|
22
|
+
bend: 6;
|
|
23
|
+
inward: 0.4;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Shared source-space grid for runtime skinning and Studio overlays. */
|
|
2
|
+
export function sampleLine(line: any, fraction: any): any;
|
|
3
|
+
export function clothGrid(c: any): {
|
|
4
|
+
custom: boolean;
|
|
5
|
+
cols: any;
|
|
6
|
+
rows: any;
|
|
7
|
+
rest: Float64Array<ArrayBuffer>;
|
|
8
|
+
seams: any;
|
|
9
|
+
joints: any;
|
|
10
|
+
fractions: never[][];
|
|
11
|
+
lengths: any;
|
|
12
|
+
top: any;
|
|
13
|
+
};
|
|
14
|
+
export function lineLength(line: any): any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function solve(matrix: any, rhs: any): number[];
|
|
2
|
+
export function pendulumSystem(lengths: any, gravity: any, zeta: any, highModeDamping?: number): {
|
|
3
|
+
lengths: any;
|
|
4
|
+
mass: any;
|
|
5
|
+
coefficient: any;
|
|
6
|
+
stiffness: any;
|
|
7
|
+
damping: any;
|
|
8
|
+
frequencies: any;
|
|
9
|
+
angles: any;
|
|
10
|
+
velocities: any;
|
|
11
|
+
};
|
|
12
|
+
export function pendulumEnergy(s: any, q?: any, v?: any): any;
|
|
13
|
+
export function stepPendulum(s: any, h: any, ax?: number, gravityRatio?: number): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Validate a partial override before applying it to any garment. */
|
|
2
|
+
export function checkClothTuning(tuning: any): void;
|
|
3
|
+
/** @type {Readonly<import('../rig/types').ClothTuning>} */
|
|
4
|
+
export const CLOTH_DEFAULTS: Readonly<import("../rig/types.js").ClothTuning>;
|
|
5
|
+
export const CLOTH_OPTIONAL_DEFAULTS: Readonly<{
|
|
6
|
+
tierGain: 1;
|
|
7
|
+
highModeDamping: 1;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** @param {ReturnType<import('./rig.js').createRig>} engine
|
|
2
|
+
* @param {import('../rig/types').Rig} rig */
|
|
3
|
+
export function createCloth(engine: ReturnType<typeof import("./rig.js").createRig>, rig: import("../rig/types.js").Rig): {
|
|
4
|
+
Cloth: {
|
|
5
|
+
new (): {
|
|
6
|
+
gain: number;
|
|
7
|
+
time: number;
|
|
8
|
+
setTuning(name: any, tuning: any): void;
|
|
9
|
+
/** Skin a layer mesh (rest/pos arrays in source px) to the named garment. */
|
|
10
|
+
attach(name: any, mesh: any): void;
|
|
11
|
+
step(P: any, dt: any, phys: any): void;
|
|
12
|
+
deform(): void;
|
|
13
|
+
/** Grid nodes per garment, for debug overlays. */
|
|
14
|
+
get grids(): {
|
|
15
|
+
name: string;
|
|
16
|
+
cols: any;
|
|
17
|
+
rows: any;
|
|
18
|
+
nodes: Float64Array<ArrayBuffer>;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
garments: {
|
|
23
|
+
grid: {
|
|
24
|
+
custom: boolean;
|
|
25
|
+
cols: any;
|
|
26
|
+
rows: any;
|
|
27
|
+
rest: Float64Array<ArrayBuffer>;
|
|
28
|
+
seams: any;
|
|
29
|
+
joints: any;
|
|
30
|
+
fractions: never[][];
|
|
31
|
+
lengths: any;
|
|
32
|
+
top: any;
|
|
33
|
+
};
|
|
34
|
+
pendulums: ReturnType<typeof pendulumSystem>[];
|
|
35
|
+
systemKey: null;
|
|
36
|
+
c: import("../index.js").Cloth;
|
|
37
|
+
gravity: number;
|
|
38
|
+
tuning: {
|
|
39
|
+
[k: string]: any;
|
|
40
|
+
};
|
|
41
|
+
cols: any;
|
|
42
|
+
rows: any;
|
|
43
|
+
rest: Float64Array<ArrayBuffer>;
|
|
44
|
+
top: any;
|
|
45
|
+
weights: any;
|
|
46
|
+
target: Float64Array<ArrayBuffer>;
|
|
47
|
+
previous: null;
|
|
48
|
+
pivotVelocity: Float64Array<ArrayBuffer>;
|
|
49
|
+
angle: Float64Array<any>;
|
|
50
|
+
angularVelocity: Float64Array<any>;
|
|
51
|
+
lowerAngle: Float64Array<any>;
|
|
52
|
+
lowerAngularVelocity: Float64Array<any>;
|
|
53
|
+
bounce: Float64Array<any>;
|
|
54
|
+
bounceVelocity: Float64Array<any>;
|
|
55
|
+
out: Float64Array<ArrayBuffer>;
|
|
56
|
+
physicalOut: Float64Array<ArrayBuffer>;
|
|
57
|
+
parent: null;
|
|
58
|
+
parentLoc: null;
|
|
59
|
+
meshes: never[];
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
import { pendulumSystem } from './cloth-pendulum.js';
|
|
@@ -6,7 +6,7 @@ export function createMeshAvatarImpl(canvas: HTMLCanvasElement, options: import(
|
|
|
6
6
|
label: string;
|
|
7
7
|
idle: boolean;
|
|
8
8
|
}[];
|
|
9
|
-
setParameters(values: any, weight?: number): void;
|
|
9
|
+
setParameters(values: any, weight?: number, weights?: {}): void;
|
|
10
10
|
getParameters(): {};
|
|
11
11
|
/** 0..1 loudness of the voice being played (e.g. normalised RMS). */
|
|
12
12
|
setVoiceLevel(v: any): void;
|
|
@@ -18,6 +18,8 @@ export function createMeshAvatarImpl(canvas: HTMLCanvasElement, options: import(
|
|
|
18
18
|
setEmotion(tag: any, opts: any): void;
|
|
19
19
|
/** Live expression layered over tracking (see OVERLAY_EXPRESSIONS); 'neutral' clears it. */
|
|
20
20
|
setExpression(name: any): void;
|
|
21
|
+
/** Show the named overlay layers (built/overlays/overlays.json) and hide the others. */
|
|
22
|
+
setOverlays(names: any): void;
|
|
21
23
|
getExpression(): {
|
|
22
24
|
name: "smile" | "shy" | "surprise" | "wink" | "neutral" | "halfLidded" | "angry" | "sad";
|
|
23
25
|
active: boolean;
|
|
@@ -45,6 +47,7 @@ export function createMeshAvatarImpl(canvas: HTMLCanvasElement, options: import(
|
|
|
45
47
|
setAutoMotion(on: any): void;
|
|
46
48
|
/** Hair / tassel sway multiplier (1 = default). */
|
|
47
49
|
setSwayGain(g: any): void;
|
|
50
|
+
setClothTuning(name: any, tuning: any): void;
|
|
48
51
|
/** Called with the motion id when a motion starts and with null when it ends. */
|
|
49
52
|
onMotion(fn: any): () => boolean;
|
|
50
53
|
/** Advance the simulation by `sec` and draw (for tests / hidden tabs). */
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LightingSettings } from '../lighting/settings.js';
|
|
2
|
-
import type { Rig } from '../rig/types.js';
|
|
2
|
+
import type { Rig, ClothTuning } from '../rig/types.js';
|
|
3
3
|
import { OVERLAY_EXPRESSIONS } from './expression-overlay.js';
|
|
4
4
|
import type { LipSyncSettings } from './lip-sync.js';
|
|
5
5
|
export type LiveExpression = keyof typeof OVERLAY_EXPRESSIONS;
|
|
@@ -27,7 +27,8 @@ export interface MeshAvatar {
|
|
|
27
27
|
computedLayers: number;
|
|
28
28
|
cachedLayers: number;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
/** Optional per-parameter weights multiply weight and blend against underlying motion; null clears them. */
|
|
31
|
+
setParameters(parameters: Record<string, number>, weight?: number, weights?: Record<string, number> | null): void;
|
|
31
32
|
getParameters(): Record<string, number>;
|
|
32
33
|
setVoiceLevel(value: number): void;
|
|
33
34
|
/** Partial mouth-movement settings; omitted fields retain their current values. */
|
|
@@ -37,6 +38,8 @@ export interface MeshAvatar {
|
|
|
37
38
|
playMotion?: boolean;
|
|
38
39
|
}): void;
|
|
39
40
|
setExpression(name: LiveExpression): void;
|
|
41
|
+
/** Show the named overlay layers from built/overlays/overlays.json and hide the rest; unknown names are ignored. */
|
|
42
|
+
setOverlays(names: string[]): void;
|
|
40
43
|
getExpression(): {
|
|
41
44
|
name: LiveExpression;
|
|
42
45
|
active: boolean;
|
|
@@ -57,6 +60,8 @@ export interface MeshAvatar {
|
|
|
57
60
|
setAutoIdle(on: boolean): void;
|
|
58
61
|
setAutoMotion(on: boolean): void;
|
|
59
62
|
setSwayGain(gain: number): void;
|
|
63
|
+
/** Override garment physics without rebuilding layers; null applies to every garment. */
|
|
64
|
+
setClothTuning(name: string | null, tuning: Partial<ClothTuning>): void;
|
|
60
65
|
onMotion(listener: (id: string | null) => void): () => void;
|
|
61
66
|
advance(seconds: number, fps?: number): void;
|
|
62
67
|
advanceParameters(seconds: number): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @param {{pivotX:number, pivotY:number, weightBand:number[]}|null} [head] */
|
|
2
|
+
export function createLegs(legs: any, body: any, head?: {
|
|
3
|
+
pivotX: number;
|
|
4
|
+
pivotY: number;
|
|
5
|
+
weightBand: number[];
|
|
6
|
+
} | null): {
|
|
7
|
+
frame: (P: any) => any;
|
|
8
|
+
weights: (x: any, y: any) => {
|
|
9
|
+
right: number;
|
|
10
|
+
perBone: {
|
|
11
|
+
leg: number;
|
|
12
|
+
shin: number;
|
|
13
|
+
pin: number;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
apply: (p: any, _x: any, y: any, w: any, P: any) => void;
|
|
17
|
+
pin: (y: any) => number;
|
|
18
|
+
step: (P: any, dt: any) => void;
|
|
19
|
+
} | null;
|
|
20
|
+
/** Optional planted, two-bone legs. All coordinates are in source pixels. */
|
|
21
|
+
export const LEG_DEFAULTS: Readonly<{
|
|
22
|
+
spine: 0.7;
|
|
23
|
+
bob: 2;
|
|
24
|
+
twist: 0;
|
|
25
|
+
}>;
|
package/dist/engine/motion.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Five-second held transfer:0.9s quintic S,1.6s hold per half-cycle. */
|
|
2
|
+
export function weightTransfer(t: any): number;
|
|
1
3
|
export namespace IDLE_GAIN {
|
|
2
4
|
let amp: number;
|
|
3
5
|
let stiff: number;
|
|
@@ -151,8 +153,12 @@ export namespace EXPRESSIONS {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
export class Motion {
|
|
154
|
-
/** @param {number[]} gazeCenter */
|
|
155
|
-
constructor(gazeCenter: number[]);
|
|
156
|
+
/** @param {number[]} gazeCenter @param {boolean} [planted] @param {import('../rig/types').Rig|null} [armRig] */
|
|
157
|
+
constructor(gazeCenter: number[], planted?: boolean, armRig?: import("../rig/types.js").Rig | null);
|
|
158
|
+
armRig: import("../index.js").Rig | null;
|
|
159
|
+
armFollow: number;
|
|
160
|
+
armVelocity: number;
|
|
161
|
+
planted: boolean;
|
|
156
162
|
mode: string;
|
|
157
163
|
P: {
|
|
158
164
|
[k: string]: number;
|
|
@@ -258,18 +264,6 @@ export class Motion {
|
|
|
258
264
|
playRandom(ids: any): void;
|
|
259
265
|
playMotion(id: any): void;
|
|
260
266
|
blinkValue(dt: any): number;
|
|
261
|
-
update(dt: any):
|
|
262
|
-
eyeROpen: number;
|
|
263
|
-
eyeLOpen: number;
|
|
264
|
-
eyeSmile: any;
|
|
265
|
-
eyeSmileL: any;
|
|
266
|
-
mouthOpen: any;
|
|
267
|
-
mouthForm: any;
|
|
268
|
-
blush: any;
|
|
269
|
-
browY: any;
|
|
270
|
-
browAngle: any;
|
|
271
|
-
gazeX: any;
|
|
272
|
-
gazeY: any;
|
|
273
|
-
};
|
|
267
|
+
update(dt: any): Record<string, number>;
|
|
274
268
|
talkNod: any;
|
|
275
269
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** [x, y, w, h] around the opaque pixels (alpha > 3) plus `pad`, or null when fully transparent. */
|
|
2
|
+
export function opaqueRect(alpha: any, width: any, height: any, pad?: number): number[] | null;
|
|
3
|
+
/**
|
|
4
|
+
* Builds one layer per overlay. Like the sprites, only the opaque part of each drawing gets a
|
|
5
|
+
* grid: a grid over the whole image would move every transparent vertex each frame (about
|
|
6
|
+
* 100k vertices for a 1254 x 1254 image at 4 px, ~12 ms per frame on a mid-range phone).
|
|
7
|
+
* `crop(img, rect)` returns that part of the image (a canvas, for example) for the texture.
|
|
8
|
+
* Brows and jaw do not move an accessory, so their weights are zeroed; hair weight is 0 as for
|
|
9
|
+
* the sprites.
|
|
10
|
+
*/
|
|
11
|
+
export function createOverlayLayers(renderer: any, sheet: any, images: any, buildGrid: any, alphaOf: any, baseWeights: any, cell: number | undefined, width: any, height: any, crop: any): {
|
|
12
|
+
/** Shows the named overlays and hides the rest. Unknown names are ignored. */
|
|
13
|
+
set(names: any): void;
|
|
14
|
+
update(P: any, phys: any, deformBase: any, out: any): void;
|
|
15
|
+
};
|
package/dist/engine/rig.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
/** @param {import('../rig/types').Rig} rig */
|
|
2
2
|
export function createRig(rig: import("../rig/types.js").Rig): {
|
|
3
|
+
legs: {
|
|
4
|
+
frame: (P: any) => any;
|
|
5
|
+
weights: (x: any, y: any) => {
|
|
6
|
+
right: number;
|
|
7
|
+
perBone: {
|
|
8
|
+
leg: number;
|
|
9
|
+
shin: number;
|
|
10
|
+
pin: number;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
apply: (p: any, _x: any, y: any, w: any, P: any) => void;
|
|
14
|
+
pin: (y: any) => number;
|
|
15
|
+
step: (P: any, dt: any) => void;
|
|
16
|
+
} | null;
|
|
17
|
+
stepBody: (P: any, dt: any) => void | undefined;
|
|
3
18
|
IMG: {
|
|
4
19
|
w: number;
|
|
5
20
|
h: number;
|
|
@@ -21,6 +36,18 @@ export function createRig(rig: import("../rig/types.js").Rig): {
|
|
|
21
36
|
headWeight: (x: any, y: any) => number;
|
|
22
37
|
turnWeight: (x: any, y: any) => number;
|
|
23
38
|
baseWeights: (x: any, y: any, hair?: number) => {
|
|
39
|
+
arms?: {
|
|
40
|
+
arm: number;
|
|
41
|
+
forearm: number;
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
legs?: {
|
|
44
|
+
right: number;
|
|
45
|
+
perBone: {
|
|
46
|
+
leg: number;
|
|
47
|
+
shin: number;
|
|
48
|
+
pin: number;
|
|
49
|
+
}[];
|
|
50
|
+
} | undefined;
|
|
24
51
|
head: number;
|
|
25
52
|
turn: number;
|
|
26
53
|
strands: any[][];
|
|
@@ -40,7 +67,7 @@ export function createRig(rig: import("../rig/types.js").Rig): {
|
|
|
40
67
|
};
|
|
41
68
|
deformBase: (x: any, y: any, w: any, P: any, phys: any, out: any) => any;
|
|
42
69
|
applyHead: (p: any, w: any, P: any, wTurn?: any) => void;
|
|
43
|
-
applyBody: (p: any, restY: any, P: any, chest
|
|
70
|
+
applyBody: (p: any, restY: any, P: any, chest: number | undefined, breathW: number | undefined, shoulder: number | undefined, legWeights: any) => void;
|
|
44
71
|
handWeights: (x: any, y: any) => {
|
|
45
72
|
arm: number;
|
|
46
73
|
wrist: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createMeshAvatar, LIVE_EXPRESSIONS } from './engine/index.js';
|
|
2
2
|
export type { MeshAvatar, MeshAvatarOptions, LiveExpression } from './engine/index.js';
|
|
3
3
|
export type { LipSyncSettings } from './engine/lip-sync.js';
|
|
4
|
-
export type { Rig, Eye, Strand, Accessory, Hand, Ellipse, Point, Band } from './rig/types.js';
|
|
4
|
+
export type { Rig, Eye, Strand, Accessory, Hand, Arm, Arms, Leg, Legs, Cloth, ClothTuning, Ellipse, Point, Band } from './rig/types.js';
|
|
5
5
|
export { validateRig, parseRig } from './rig/validate.js';
|
|
6
6
|
export { PARAMS } from './engine/rig.js';
|
|
7
7
|
export type { LightingSettings } from './lighting/settings.js';
|
|
@@ -12,3 +12,4 @@ export { validateAvatarFiles } from './format/validate.js';
|
|
|
12
12
|
export { packAvatar, unpackAvatar } from './format/zip.js';
|
|
13
13
|
export { openAvatar, loadMeshAvatar } from './format/open.js';
|
|
14
14
|
export type { AvatarPackage, AvatarSource, OpenAvatarOptions } from './format/open.js';
|
|
15
|
+
export { ARM_DEFAULTS } from './engine/arms.js';
|