@charivo/render-live2d 0.0.1 → 0.1.1

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/renderer.js CHANGED
@@ -13513,7 +13513,6 @@ var LAppPal = class {
13513
13513
  this.lastFrame = this.currentFrame;
13514
13514
  }
13515
13515
  static printMessage(message) {
13516
- console.log(message);
13517
13516
  }
13518
13517
  static lastUpdate = Date.now();
13519
13518
  static currentFrame = 0;
@@ -13628,7 +13627,6 @@ var LAppModel = class extends CubismUserModel {
13628
13627
  CubismDefaultParameterId.ParamBodyAngleX
13629
13628
  );
13630
13629
  async loadAssets(modelPath, host) {
13631
- console.log(`\u{1F3AF} LAppModel: Loading model from ${modelPath}`);
13632
13630
  this.host = host;
13633
13631
  const separator = modelPath.lastIndexOf("/") + 1;
13634
13632
  this.modelHomeDir = separator > 0 ? modelPath.substring(0, separator) : "";
@@ -13941,14 +13939,12 @@ var LAppModel = class extends CubismUserModel {
13941
13939
  }
13942
13940
  setupLipSyncIds(setting) {
13943
13941
  const count = setting.getLipSyncParameterCount();
13944
- console.log(`\u{1F3AF} LAppModel: Setting up ${count} lip sync parameters`);
13945
13942
  for (let i = 0; i < count; i++) {
13946
13943
  const paramId = setting.getLipSyncParameterId(i);
13947
13944
  this.lipSyncIds.pushBack(paramId);
13948
- console.log(`\u{1F3AF} LAppModel: Lip sync parameter ${i}:`, paramId);
13949
13945
  }
13950
13946
  if (count === 0) {
13951
- console.warn(`\u26A0\uFE0F LAppModel: No lip sync parameters found in model!`);
13947
+ console.warn("Live2D model has no lip sync parameters.");
13952
13948
  }
13953
13949
  }
13954
13950
  setupLayout(setting) {
@@ -14240,6 +14236,31 @@ var CubismModelHost = class {
14240
14236
  }
14241
14237
  };
14242
14238
 
14239
+ // src/utils/cubism-core.ts
14240
+ async function loadCubismCore() {
14241
+ if (typeof window === "undefined") return;
14242
+ if (isCubismCoreReady()) return;
14243
+ const { default: coreScript } = await import('./live2dcubismcore.min-V7VE6BAG.js');
14244
+ const script = document.createElement("script");
14245
+ script.text = coreScript;
14246
+ document.head.appendChild(script);
14247
+ await new Promise((resolve) => {
14248
+ const check = () => {
14249
+ if (isCubismCoreReady()) resolve();
14250
+ else setTimeout(check, 16);
14251
+ };
14252
+ check();
14253
+ });
14254
+ }
14255
+ function isCubismCoreReady() {
14256
+ try {
14257
+ Live2DCubismCore.Version.csmGetVersion();
14258
+ return true;
14259
+ } catch {
14260
+ return false;
14261
+ }
14262
+ }
14263
+
14243
14264
  // src/utils/motion.ts
14244
14265
  function playSafe(model, group, index = 0, priority = PriorityNormal) {
14245
14266
  if (!model.hasMotion(group, index)) return;
@@ -14308,6 +14329,7 @@ var Live2DRenderer = class _Live2DRenderer {
14308
14329
  async initialize() {
14309
14330
  if (!this.canvas)
14310
14331
  throw new Error("Canvas element is required for Live2D rendering");
14332
+ await loadCubismCore();
14311
14333
  this.initializeCubism();
14312
14334
  this.host = new CubismModelHost(this.canvas);
14313
14335
  this.host.initialize();
@@ -14320,14 +14342,6 @@ var Live2DRenderer = class _Live2DRenderer {
14320
14342
  }
14321
14343
  async loadModel(modelPath) {
14322
14344
  if (!this.host) throw new Error("Live2D renderer is not initialized");
14323
- if (typeof window !== "undefined") {
14324
- const core = window.Live2DCubismCore;
14325
- if (!core) {
14326
- console.warn(
14327
- "\u26A0\uFE0F Live2DCubismCore not found. Include live2dcubismcore.min.js on the page before initializing the renderer."
14328
- );
14329
- }
14330
- }
14331
14345
  this.model?.release();
14332
14346
  const model = new LAppModel();
14333
14347
  await model.loadAssets(modelPath, this.host);