@charivo/render-live2d 0.0.1 → 0.1.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/dist/live2dcubismcore.min-V7VE6BAG.js +14 -0
- package/dist/live2dcubismcore.min-V7VE6BAG.js.map +1 -0
- package/dist/renderer.js +26 -8
- package/dist/renderer.js.map +1 -1
- package/dist/src/renderer.d.ts.map +1 -1
- package/dist/src/utils/cubism-core.d.ts +3 -0
- package/dist/src/utils/cubism-core.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/renderer.js
CHANGED
|
@@ -14240,6 +14240,31 @@ var CubismModelHost = class {
|
|
|
14240
14240
|
}
|
|
14241
14241
|
};
|
|
14242
14242
|
|
|
14243
|
+
// src/utils/cubism-core.ts
|
|
14244
|
+
async function loadCubismCore() {
|
|
14245
|
+
if (typeof window === "undefined") return;
|
|
14246
|
+
if (isCubismCoreReady()) return;
|
|
14247
|
+
const { default: coreScript } = await import('./live2dcubismcore.min-V7VE6BAG.js');
|
|
14248
|
+
const script = document.createElement("script");
|
|
14249
|
+
script.text = coreScript;
|
|
14250
|
+
document.head.appendChild(script);
|
|
14251
|
+
await new Promise((resolve) => {
|
|
14252
|
+
const check = () => {
|
|
14253
|
+
if (isCubismCoreReady()) resolve();
|
|
14254
|
+
else setTimeout(check, 16);
|
|
14255
|
+
};
|
|
14256
|
+
check();
|
|
14257
|
+
});
|
|
14258
|
+
}
|
|
14259
|
+
function isCubismCoreReady() {
|
|
14260
|
+
try {
|
|
14261
|
+
Live2DCubismCore.Version.csmGetVersion();
|
|
14262
|
+
return true;
|
|
14263
|
+
} catch {
|
|
14264
|
+
return false;
|
|
14265
|
+
}
|
|
14266
|
+
}
|
|
14267
|
+
|
|
14243
14268
|
// src/utils/motion.ts
|
|
14244
14269
|
function playSafe(model, group, index = 0, priority = PriorityNormal) {
|
|
14245
14270
|
if (!model.hasMotion(group, index)) return;
|
|
@@ -14308,6 +14333,7 @@ var Live2DRenderer = class _Live2DRenderer {
|
|
|
14308
14333
|
async initialize() {
|
|
14309
14334
|
if (!this.canvas)
|
|
14310
14335
|
throw new Error("Canvas element is required for Live2D rendering");
|
|
14336
|
+
await loadCubismCore();
|
|
14311
14337
|
this.initializeCubism();
|
|
14312
14338
|
this.host = new CubismModelHost(this.canvas);
|
|
14313
14339
|
this.host.initialize();
|
|
@@ -14320,14 +14346,6 @@ var Live2DRenderer = class _Live2DRenderer {
|
|
|
14320
14346
|
}
|
|
14321
14347
|
async loadModel(modelPath) {
|
|
14322
14348
|
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
14349
|
this.model?.release();
|
|
14332
14350
|
const model = new LAppModel();
|
|
14333
14351
|
await model.loadAssets(modelPath, this.host);
|