untitled-pixi-live2d-engine 1.0.0 → 1.0.2

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.es.js CHANGED
@@ -103,7 +103,7 @@ const config = {
103
103
  preserveExpressionOnMotion: true,
104
104
  cubism: CubismFrameworkConfig
105
105
  };
106
- const VERSION = "1.0.0";
106
+ const VERSION = "1.0.2";
107
107
  const logger = {
108
108
  log(tag, ...messages) {
109
109
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -1970,7 +1970,35 @@ const jsonToSettings = (context, next) => __async(null, null, function* () {
1970
1970
  return next();
1971
1971
  }
1972
1972
  }
1973
- throw new TypeError("Unknown settings format.");
1973
+ const url = context.source && typeof context.source.url === "string" ? context.source.url : void 0;
1974
+ const runtimeVersions = Live2DFactory.runtimes.map((r) => r.version).join(", ");
1975
+ if (Live2DFactory.runtimes.length === 0) {
1976
+ throw new TypeError(
1977
+ [
1978
+ "Unknown settings format: no Live2D runtimes registered.",
1979
+ 'Import a published runtime entry before loading models (e.g. "<package>/cubism" for Cubism 3/4/5, "<package>/cubism-legacy" for Cubism 2).',
1980
+ url ? `Settings URL: ${url}` : void 0
1981
+ ].filter(Boolean).join("\n")
1982
+ );
1983
+ }
1984
+ const topLevelKeys = (() => {
1985
+ try {
1986
+ if (!context.source || typeof context.source !== "object" || Array.isArray(context.source)) {
1987
+ return void 0;
1988
+ }
1989
+ return Object.keys(context.source).slice(0, 30).join(", ");
1990
+ } catch (e) {
1991
+ return void 0;
1992
+ }
1993
+ })();
1994
+ throw new TypeError(
1995
+ [
1996
+ "Unknown settings format: no matching runtime found for the loaded settings JSON.",
1997
+ runtimeVersions ? `Registered runtimes (versions): ${runtimeVersions}` : void 0,
1998
+ topLevelKeys ? `Settings JSON keys: ${topLevelKeys}` : void 0,
1999
+ url ? `Settings URL: ${url}` : void 0
2000
+ ].filter(Boolean).join("\n")
2001
+ );
1974
2002
  });
1975
2003
  const waitUntilReady = (context, next) => {
1976
2004
  if (context.settings) {
@@ -3704,7 +3732,11 @@ class CubismLegacyInternalModel extends InternalModel {
3704
3732
  __publicField(this, "customHitAreas");
3705
3733
  this.coreModel = coreModel;
3706
3734
  this.settings = settings;
3707
- this.options = Object.assign({}, { breathDepth: 1 }, options);
3735
+ this.options = Object.assign(
3736
+ {},
3737
+ { breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
3738
+ options
3739
+ );
3708
3740
  this.motionManager = new CubismLegacyMotionManager(this);
3709
3741
  this.parallelMotionManager = [];
3710
3742
  this.eyeBlink = new Live2DEyeBlink(coreModel);
@@ -3838,17 +3870,16 @@ class CubismLegacyInternalModel extends InternalModel {
3838
3870
  this.updateFocus();
3839
3871
  this.updateNaturalMovements(dt, now);
3840
3872
  if (this.lipSync && this.motionManager.currentAudio) {
3841
- const lipSyncGain = 1.5;
3842
- let value = this.motionManager.mouthSync() * lipSyncGain;
3873
+ let value = this.motionManager.mouthSync() * this.options.lipSyncGain;
3843
3874
  const max_ = 1;
3844
- const bias_power = 1.15;
3845
3875
  const min_ = value > 0 ? 0.1 : 0;
3846
- value = Math.pow(value, bias_power);
3876
+ value = Math.pow(value, 1.15);
3847
3877
  value = clamp(value, min_, max_);
3848
3878
  for (let i = 0; i < this.motionManager.lipSyncIds.length; ++i) {
3849
- this.coreModel.setParamFloat(
3879
+ this.coreModel.addToParamFloat(
3850
3880
  this.coreModel.getParamIndex(this.motionManager.lipSyncIds[i]),
3851
- value
3881
+ value,
3882
+ this.options.lipSyncWeight
3852
3883
  );
3853
3884
  }
3854
3885
  }
@@ -11991,6 +12022,30 @@ var Live2DCubismFramework$8;
11991
12022
  Live2DCubismFramework2.CubismRenderer_WebGL = CubismRenderer_WebGL;
11992
12023
  })(Live2DCubismFramework$8 || (Live2DCubismFramework$8 = {}));
11993
12024
  const tempMatrix = new CubismMatrix44();
12025
+ const DEFAULT_MASKS_PER_RENDER_TEXTURE = 36;
12026
+ const MASKS_PER_RENDER_TEXTURE = 32;
12027
+ function getRequiredMaskRenderTextureCount(model) {
12028
+ var _a;
12029
+ if (!model.isUsingMasking()) {
12030
+ return 1;
12031
+ }
12032
+ const maskCounts = model.getDrawableMaskCounts();
12033
+ const masks = model.getDrawableMasks();
12034
+ const uniqueMaskSets = /* @__PURE__ */ new Set();
12035
+ for (let i = 0; i < model.getDrawableCount(); i++) {
12036
+ const maskCount = maskCounts[i];
12037
+ if (!maskCount || maskCount <= 0) {
12038
+ continue;
12039
+ }
12040
+ const maskSet = Array.from((_a = masks[i]) != null ? _a : []).slice(0, maskCount).sort((a, b) => a - b).join(",");
12041
+ uniqueMaskSets.add(maskSet);
12042
+ }
12043
+ const clippingContextCount = uniqueMaskSets.size;
12044
+ if (clippingContextCount <= DEFAULT_MASKS_PER_RENDER_TEXTURE) {
12045
+ return 1;
12046
+ }
12047
+ return Math.ceil(clippingContextCount / MASKS_PER_RENDER_TEXTURE);
12048
+ }
11994
12049
  class CubismInternalModel extends InternalModel {
11995
12050
  constructor(coreModel, settings, options) {
11996
12051
  super();
@@ -12022,7 +12077,11 @@ class CubismInternalModel extends InternalModel {
12022
12077
  __publicField(this, "modelTransform", new Matrix());
12023
12078
  this.coreModel = coreModel;
12024
12079
  this.settings = settings;
12025
- this.options = Object.assign({}, { breathDepth: 1 }, options);
12080
+ this.options = Object.assign(
12081
+ {},
12082
+ { breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
12083
+ options
12084
+ );
12026
12085
  this.idManager = CubismFramework.getIdManager();
12027
12086
  this.idParamAngleX = this.getIdSafe(CubismDefaultParameterId.ParamAngleX);
12028
12087
  this.idParamAngleY = this.getIdSafe(CubismDefaultParameterId.ParamAngleY);
@@ -12086,7 +12145,7 @@ class CubismInternalModel extends InternalModel {
12086
12145
  );
12087
12146
  breathParams.pushBack(new BreathParameterData(this.idParamBreath, 0, 0.5, 3.2345, 0.5));
12088
12147
  this.breath.setParameters(breathParams);
12089
- this.renderer.initialize(this.coreModel);
12148
+ this.renderer.initialize(this.coreModel, getRequiredMaskRenderTextureCount(this.coreModel));
12090
12149
  this.renderer.setIsPremultipliedAlpha(true);
12091
12150
  }
12092
12151
  getIdSafe(id) {
@@ -12181,15 +12240,13 @@ class CubismInternalModel extends InternalModel {
12181
12240
  this.updateFocus();
12182
12241
  this.updateNaturalMovements(dt * 1e3, now * 1e3);
12183
12242
  if (this.lipSync && this.motionManager.currentAudio) {
12184
- const lipSyncGain = 1.5;
12185
- const smoothing = 0.4;
12186
- let value = this.motionManager.mouthSync() * lipSyncGain;
12243
+ let value = this.motionManager.mouthSync() * this.options.lipSyncGain;
12187
12244
  value = Math.pow(value, 1.15);
12188
12245
  const min_ = value > 0 ? 0.1 : 0;
12189
12246
  const max_ = 1;
12190
12247
  value = clamp(value, min_, max_);
12191
12248
  this.motionManager.lipSyncIds.forEach((lipSyncId) => {
12192
- model.addParameterValueById(this.getIdSafe(lipSyncId), value, smoothing);
12249
+ model.addParameterValueById(this.getIdSafe(lipSyncId), value, this.options.lipSyncWeight);
12193
12250
  });
12194
12251
  }
12195
12252
  (_d = this.physics) == null ? void 0 : _d.evaluate(model, dt);
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ var __async = (__this, __arguments, generator) => {
105
105
  preserveExpressionOnMotion: true,
106
106
  cubism: CubismFrameworkConfig
107
107
  };
108
- const VERSION = "1.0.0";
108
+ const VERSION = "1.0.2";
109
109
  const logger = {
110
110
  log(tag, ...messages) {
111
111
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -1972,7 +1972,35 @@ var __async = (__this, __arguments, generator) => {
1972
1972
  return next();
1973
1973
  }
1974
1974
  }
1975
- throw new TypeError("Unknown settings format.");
1975
+ const url = context.source && typeof context.source.url === "string" ? context.source.url : void 0;
1976
+ const runtimeVersions = Live2DFactory.runtimes.map((r) => r.version).join(", ");
1977
+ if (Live2DFactory.runtimes.length === 0) {
1978
+ throw new TypeError(
1979
+ [
1980
+ "Unknown settings format: no Live2D runtimes registered.",
1981
+ 'Import a published runtime entry before loading models (e.g. "<package>/cubism" for Cubism 3/4/5, "<package>/cubism-legacy" for Cubism 2).',
1982
+ url ? `Settings URL: ${url}` : void 0
1983
+ ].filter(Boolean).join("\n")
1984
+ );
1985
+ }
1986
+ const topLevelKeys = (() => {
1987
+ try {
1988
+ if (!context.source || typeof context.source !== "object" || Array.isArray(context.source)) {
1989
+ return void 0;
1990
+ }
1991
+ return Object.keys(context.source).slice(0, 30).join(", ");
1992
+ } catch (e) {
1993
+ return void 0;
1994
+ }
1995
+ })();
1996
+ throw new TypeError(
1997
+ [
1998
+ "Unknown settings format: no matching runtime found for the loaded settings JSON.",
1999
+ runtimeVersions ? `Registered runtimes (versions): ${runtimeVersions}` : void 0,
2000
+ topLevelKeys ? `Settings JSON keys: ${topLevelKeys}` : void 0,
2001
+ url ? `Settings URL: ${url}` : void 0
2002
+ ].filter(Boolean).join("\n")
2003
+ );
1976
2004
  });
1977
2005
  const waitUntilReady = (context, next) => {
1978
2006
  if (context.settings) {
@@ -3706,7 +3734,11 @@ var __async = (__this, __arguments, generator) => {
3706
3734
  __publicField(this, "customHitAreas");
3707
3735
  this.coreModel = coreModel;
3708
3736
  this.settings = settings;
3709
- this.options = Object.assign({}, { breathDepth: 1 }, options);
3737
+ this.options = Object.assign(
3738
+ {},
3739
+ { breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
3740
+ options
3741
+ );
3710
3742
  this.motionManager = new CubismLegacyMotionManager(this);
3711
3743
  this.parallelMotionManager = [];
3712
3744
  this.eyeBlink = new Live2DEyeBlink(coreModel);
@@ -3840,17 +3872,16 @@ var __async = (__this, __arguments, generator) => {
3840
3872
  this.updateFocus();
3841
3873
  this.updateNaturalMovements(dt, now);
3842
3874
  if (this.lipSync && this.motionManager.currentAudio) {
3843
- const lipSyncGain = 1.5;
3844
- let value = this.motionManager.mouthSync() * lipSyncGain;
3875
+ let value = this.motionManager.mouthSync() * this.options.lipSyncGain;
3845
3876
  const max_ = 1;
3846
- const bias_power = 1.15;
3847
3877
  const min_ = value > 0 ? 0.1 : 0;
3848
- value = Math.pow(value, bias_power);
3878
+ value = Math.pow(value, 1.15);
3849
3879
  value = clamp(value, min_, max_);
3850
3880
  for (let i = 0; i < this.motionManager.lipSyncIds.length; ++i) {
3851
- this.coreModel.setParamFloat(
3881
+ this.coreModel.addToParamFloat(
3852
3882
  this.coreModel.getParamIndex(this.motionManager.lipSyncIds[i]),
3853
- value
3883
+ value,
3884
+ this.options.lipSyncWeight
3854
3885
  );
3855
3886
  }
3856
3887
  }
@@ -11993,6 +12024,30 @@ var __async = (__this, __arguments, generator) => {
11993
12024
  Live2DCubismFramework2.CubismRenderer_WebGL = CubismRenderer_WebGL;
11994
12025
  })(Live2DCubismFramework$8 || (Live2DCubismFramework$8 = {}));
11995
12026
  const tempMatrix = new CubismMatrix44();
12027
+ const DEFAULT_MASKS_PER_RENDER_TEXTURE = 36;
12028
+ const MASKS_PER_RENDER_TEXTURE = 32;
12029
+ function getRequiredMaskRenderTextureCount(model) {
12030
+ var _a;
12031
+ if (!model.isUsingMasking()) {
12032
+ return 1;
12033
+ }
12034
+ const maskCounts = model.getDrawableMaskCounts();
12035
+ const masks = model.getDrawableMasks();
12036
+ const uniqueMaskSets = /* @__PURE__ */ new Set();
12037
+ for (let i = 0; i < model.getDrawableCount(); i++) {
12038
+ const maskCount = maskCounts[i];
12039
+ if (!maskCount || maskCount <= 0) {
12040
+ continue;
12041
+ }
12042
+ const maskSet = Array.from((_a = masks[i]) != null ? _a : []).slice(0, maskCount).sort((a, b) => a - b).join(",");
12043
+ uniqueMaskSets.add(maskSet);
12044
+ }
12045
+ const clippingContextCount = uniqueMaskSets.size;
12046
+ if (clippingContextCount <= DEFAULT_MASKS_PER_RENDER_TEXTURE) {
12047
+ return 1;
12048
+ }
12049
+ return Math.ceil(clippingContextCount / MASKS_PER_RENDER_TEXTURE);
12050
+ }
11996
12051
  class CubismInternalModel extends InternalModel {
11997
12052
  constructor(coreModel, settings, options) {
11998
12053
  super();
@@ -12024,7 +12079,11 @@ var __async = (__this, __arguments, generator) => {
12024
12079
  __publicField(this, "modelTransform", new pixi_js.Matrix());
12025
12080
  this.coreModel = coreModel;
12026
12081
  this.settings = settings;
12027
- this.options = Object.assign({}, { breathDepth: 1 }, options);
12082
+ this.options = Object.assign(
12083
+ {},
12084
+ { breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
12085
+ options
12086
+ );
12028
12087
  this.idManager = CubismFramework.getIdManager();
12029
12088
  this.idParamAngleX = this.getIdSafe(CubismDefaultParameterId.ParamAngleX);
12030
12089
  this.idParamAngleY = this.getIdSafe(CubismDefaultParameterId.ParamAngleY);
@@ -12088,7 +12147,7 @@ var __async = (__this, __arguments, generator) => {
12088
12147
  );
12089
12148
  breathParams.pushBack(new BreathParameterData(this.idParamBreath, 0, 0.5, 3.2345, 0.5));
12090
12149
  this.breath.setParameters(breathParams);
12091
- this.renderer.initialize(this.coreModel);
12150
+ this.renderer.initialize(this.coreModel, getRequiredMaskRenderTextureCount(this.coreModel));
12092
12151
  this.renderer.setIsPremultipliedAlpha(true);
12093
12152
  }
12094
12153
  getIdSafe(id) {
@@ -12183,15 +12242,13 @@ var __async = (__this, __arguments, generator) => {
12183
12242
  this.updateFocus();
12184
12243
  this.updateNaturalMovements(dt * 1e3, now * 1e3);
12185
12244
  if (this.lipSync && this.motionManager.currentAudio) {
12186
- const lipSyncGain = 1.5;
12187
- const smoothing = 0.4;
12188
- let value = this.motionManager.mouthSync() * lipSyncGain;
12245
+ let value = this.motionManager.mouthSync() * this.options.lipSyncGain;
12189
12246
  value = Math.pow(value, 1.15);
12190
12247
  const min_ = value > 0 ? 0.1 : 0;
12191
12248
  const max_ = 1;
12192
12249
  value = clamp(value, min_, max_);
12193
12250
  this.motionManager.lipSyncIds.forEach((lipSyncId) => {
12194
- model.addParameterValueById(this.getIdSafe(lipSyncId), value, smoothing);
12251
+ model.addParameterValueById(this.getIdSafe(lipSyncId), value, this.options.lipSyncWeight);
12195
12252
  });
12196
12253
  }
12197
12254
  (_d = this.physics) == null ? void 0 : _d.evaluate(model, dt);