@charivo/render-live2d 0.5.3 → 0.6.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/renderer.js +51 -14
- package/dist/renderer.js.map +1 -1
- package/dist/src/cubism/lappmodel.d.ts +3 -1
- package/dist/src/cubism/lappmodel.d.ts.map +1 -1
- package/dist/src/cubism/lappwavfilehandler.d.ts +6 -0
- package/dist/src/cubism/lappwavfilehandler.d.ts.map +1 -1
- package/dist/src/live2d-renderer.d.ts +3 -1
- package/dist/src/live2d-renderer.d.ts.map +1 -1
- package/dist/src/renderer.d.ts +3 -1
- package/dist/src/renderer.d.ts.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -39,7 +39,10 @@ The renderer exposes:
|
|
|
39
39
|
- `getAvailableMotionGroups()`
|
|
40
40
|
- `playExpression(expressionId)`
|
|
41
41
|
- `stopExpression()`
|
|
42
|
-
- `playMotionByGroup(group, index)`
|
|
42
|
+
- `playMotionByGroup(group, index, options?)` — `options.muteSound` plays the
|
|
43
|
+
motion without the sample clip baked into it, and interrupts one already
|
|
44
|
+
playing; an unflagged call keeps the sound, which is what leaves a
|
|
45
|
+
human-triggered motion audible
|
|
43
46
|
- `lookAt({ x, y })`
|
|
44
47
|
|
|
45
48
|
When used through `@charivo/render`, realtime lip sync, mouse tracking,
|
package/dist/renderer.js
CHANGED
|
@@ -13557,13 +13557,21 @@ var LAppWavFileHandler = class {
|
|
|
13557
13557
|
gainNode;
|
|
13558
13558
|
rms = 0;
|
|
13559
13559
|
isActive = false;
|
|
13560
|
+
// Bumped by every start and stop. A fetch/decode begun before one of those
|
|
13561
|
+
// can still resolve after it, and without this check it would start playing
|
|
13562
|
+
// into the silence that was just asked for.
|
|
13563
|
+
requestToken = 0;
|
|
13560
13564
|
start(filePath) {
|
|
13561
13565
|
if (typeof window === "undefined") return;
|
|
13562
13566
|
this.stop();
|
|
13563
13567
|
this.ensureContext();
|
|
13564
13568
|
if (!this.audioContext) return;
|
|
13565
13569
|
const context = this.audioContext;
|
|
13570
|
+
const token = ++this.requestToken;
|
|
13566
13571
|
fetch(filePath).then((response) => response.arrayBuffer()).then((arrayBuffer) => context.decodeAudioData(arrayBuffer)).then((buffer) => {
|
|
13572
|
+
if (token !== this.requestToken) {
|
|
13573
|
+
return;
|
|
13574
|
+
}
|
|
13567
13575
|
this.audioBufferSourceNode = context.createBufferSource();
|
|
13568
13576
|
this.gainNode = context.createGain();
|
|
13569
13577
|
this.audioBufferSourceNode.buffer = buffer;
|
|
@@ -13604,6 +13612,14 @@ var LAppWavFileHandler = class {
|
|
|
13604
13612
|
getRms() {
|
|
13605
13613
|
return this.rms;
|
|
13606
13614
|
}
|
|
13615
|
+
/**
|
|
13616
|
+
* Stops playback and supersedes any load still in flight. Silence that was
|
|
13617
|
+
* explicitly asked for has to survive a fetch that resolves afterwards.
|
|
13618
|
+
*/
|
|
13619
|
+
cancel() {
|
|
13620
|
+
this.requestToken += 1;
|
|
13621
|
+
this.stop();
|
|
13622
|
+
}
|
|
13607
13623
|
stop() {
|
|
13608
13624
|
if (this.audioBufferSourceNode) {
|
|
13609
13625
|
try {
|
|
@@ -13830,7 +13846,7 @@ var LAppModel = class extends CubismUserModel {
|
|
|
13830
13846
|
this.getRenderer().setMvpMatrix(projection);
|
|
13831
13847
|
this.getRenderer().drawModel();
|
|
13832
13848
|
}
|
|
13833
|
-
startMotion(group, index, priority, onFinished, onBegan) {
|
|
13849
|
+
startMotion(group, index, priority, onFinished, onBegan, options) {
|
|
13834
13850
|
if (!this.ready || !this.modelSetting) {
|
|
13835
13851
|
return InvalidMotionQueueEntryHandleValue;
|
|
13836
13852
|
}
|
|
@@ -13845,8 +13861,26 @@ var LAppModel = class extends CubismUserModel {
|
|
|
13845
13861
|
this._motionManager.setReservePriority(PriorityNone);
|
|
13846
13862
|
return InvalidMotionQueueEntryHandleValue;
|
|
13847
13863
|
}
|
|
13848
|
-
|
|
13849
|
-
|
|
13864
|
+
const soundFile = this.modelSetting.getMotionSoundFileName(group, index);
|
|
13865
|
+
const soundPath = soundFile ? `${this.modelHomeDir}${soundFile}` : null;
|
|
13866
|
+
const muted = options?.muteSound === true;
|
|
13867
|
+
if (muted) {
|
|
13868
|
+
this.wavHandler.cancel();
|
|
13869
|
+
}
|
|
13870
|
+
motion.setBeganMotionHandler((self) => {
|
|
13871
|
+
if (muted) {
|
|
13872
|
+
this.wavHandler.cancel();
|
|
13873
|
+
} else if (soundPath) {
|
|
13874
|
+
this.wavHandler.start(soundPath);
|
|
13875
|
+
}
|
|
13876
|
+
onBegan?.(self);
|
|
13877
|
+
});
|
|
13878
|
+
motion.setFinishedMotionHandler((self) => {
|
|
13879
|
+
if (!muted && soundPath) {
|
|
13880
|
+
this.wavHandler.stop();
|
|
13881
|
+
}
|
|
13882
|
+
onFinished?.(self);
|
|
13883
|
+
});
|
|
13850
13884
|
return this._motionManager.startMotionPriority(motion, false, priority);
|
|
13851
13885
|
}
|
|
13852
13886
|
startRandomMotion(group, priority, onFinished, onBegan) {
|
|
@@ -13963,7 +13997,7 @@ var LAppModel = class extends CubismUserModel {
|
|
|
13963
13997
|
release() {
|
|
13964
13998
|
this.releaseMotions();
|
|
13965
13999
|
this.releaseExpressions();
|
|
13966
|
-
this.wavHandler.
|
|
14000
|
+
this.wavHandler.cancel();
|
|
13967
14001
|
this.setRealtimeLipSync(false);
|
|
13968
14002
|
this.ready = false;
|
|
13969
14003
|
}
|
|
@@ -14106,14 +14140,6 @@ var LAppModel = class extends CubismUserModel {
|
|
|
14106
14140
|
return;
|
|
14107
14141
|
}
|
|
14108
14142
|
motion.setEffectIds(this.eyeBlinkIds, this.lipSyncIds);
|
|
14109
|
-
if (setting.getMotionSoundFileName(group, index)) {
|
|
14110
|
-
motion.setFinishedMotionHandler(() => this.wavHandler.stop());
|
|
14111
|
-
motion.setBeganMotionHandler(
|
|
14112
|
-
() => this.wavHandler.start(
|
|
14113
|
-
`${this.modelHomeDir}${setting.getMotionSoundFileName(group, index)}`
|
|
14114
|
-
)
|
|
14115
|
-
);
|
|
14116
|
-
}
|
|
14117
14143
|
this.motions.setValue(key, motion);
|
|
14118
14144
|
}
|
|
14119
14145
|
async loadTextures(setting) {
|
|
@@ -14567,10 +14593,21 @@ var Live2DRendererImpl = class _Live2DRendererImpl {
|
|
|
14567
14593
|
/**
|
|
14568
14594
|
* Play a specific motion by group and index
|
|
14569
14595
|
*/
|
|
14570
|
-
playMotionByGroup(group, index) {
|
|
14596
|
+
playMotionByGroup(group, index, options) {
|
|
14571
14597
|
if (!this.model?.isReady()) return;
|
|
14572
14598
|
if (this.model.hasMotion(group, index)) {
|
|
14573
|
-
|
|
14599
|
+
if (options?.muteSound) {
|
|
14600
|
+
this.model.startMotion(
|
|
14601
|
+
group,
|
|
14602
|
+
index,
|
|
14603
|
+
PriorityNormal,
|
|
14604
|
+
void 0,
|
|
14605
|
+
void 0,
|
|
14606
|
+
{ muteSound: true }
|
|
14607
|
+
);
|
|
14608
|
+
} else {
|
|
14609
|
+
this.model.startMotion(group, index, PriorityNormal);
|
|
14610
|
+
}
|
|
14574
14611
|
}
|
|
14575
14612
|
}
|
|
14576
14613
|
lookAt(coords) {
|