untitled-pixi-live2d-engine 1.0.2 → 1.2.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 +99 -90
- package/dist/cubism-legacy.es.js +274 -136
- package/dist/cubism-legacy.js +273 -135
- package/dist/cubism-legacy.min.js +1 -1
- package/dist/cubism.es.js +306 -134
- package/dist/cubism.js +305 -133
- package/dist/cubism.min.js +1 -1
- package/dist/index.es.js +315 -137
- package/dist/index.js +314 -136
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +145 -21
package/dist/cubism.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("pixi.js"), require("@pixi/sound")) : typeof define === "function" && define.amd ? define(["exports", "pixi.js", "@pixi/sound"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory((global.PIXI = global.PIXI || {}, global.PIXI.live2d = global.PIXI.live2d || {}), global.PIXI, global.PIXI));
|
|
3
3
|
})(this, (function(exports2, pixi_js, sound) {
|
|
4
4
|
"use strict";var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -18,6 +20,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
20
|
}
|
|
19
21
|
return a;
|
|
20
22
|
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
24
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
25
|
var __async = (__this, __arguments, generator) => {
|
|
23
26
|
return new Promise((resolve, reject) => {
|
|
@@ -2759,7 +2762,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2759
2762
|
preserveExpressionOnMotion: true,
|
|
2760
2763
|
cubism: CubismFrameworkConfig
|
|
2761
2764
|
};
|
|
2762
|
-
const VERSION = "1.0
|
|
2765
|
+
const VERSION = "1.2.0";
|
|
2763
2766
|
const logger = {
|
|
2764
2767
|
log(tag, ...messages) {
|
|
2765
2768
|
if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
|
|
@@ -2777,7 +2780,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2777
2780
|
}
|
|
2778
2781
|
}
|
|
2779
2782
|
};
|
|
2780
|
-
function clamp(num, lower, upper) {
|
|
2783
|
+
function clamp$1(num, lower, upper) {
|
|
2781
2784
|
return num < lower ? lower : num > upper ? upper : num;
|
|
2782
2785
|
}
|
|
2783
2786
|
function rand(min, max) {
|
|
@@ -3052,8 +3055,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3052
3055
|
* @param instant - Should the focus position be instantly applied.
|
|
3053
3056
|
*/
|
|
3054
3057
|
focus(x, y, instant = false) {
|
|
3055
|
-
this.targetX = clamp(x, -1, 1);
|
|
3056
|
-
this.targetY = clamp(y, -1, 1);
|
|
3058
|
+
this.targetX = clamp$1(x, -1, 1);
|
|
3059
|
+
this.targetY = clamp$1(y, -1, 1);
|
|
3057
3060
|
if (instant) {
|
|
3058
3061
|
this.x = this.targetX;
|
|
3059
3062
|
this.y = this.targetY;
|
|
@@ -4570,6 +4573,68 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4570
4573
|
}
|
|
4571
4574
|
}
|
|
4572
4575
|
}
|
|
4576
|
+
const DEFAULT_LOD_SCALE_THRESHOLD = 0.5;
|
|
4577
|
+
const DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD = 4096;
|
|
4578
|
+
function getTextureLODPlan({
|
|
4579
|
+
lod,
|
|
4580
|
+
effectiveScale,
|
|
4581
|
+
textureWidth,
|
|
4582
|
+
textureHeight,
|
|
4583
|
+
lodScaleThreshold,
|
|
4584
|
+
lodTextureSizeThreshold,
|
|
4585
|
+
lodMaxLevel
|
|
4586
|
+
}) {
|
|
4587
|
+
if (getTextureLODMode(lod) !== "single-auto") {
|
|
4588
|
+
return void 0;
|
|
4589
|
+
}
|
|
4590
|
+
if (!Number.isFinite(effectiveScale) || effectiveScale <= 0) {
|
|
4591
|
+
return void 0;
|
|
4592
|
+
}
|
|
4593
|
+
const width = Math.floor(textureWidth);
|
|
4594
|
+
const height = Math.floor(textureHeight);
|
|
4595
|
+
if (width <= 1 || height <= 1) {
|
|
4596
|
+
return void 0;
|
|
4597
|
+
}
|
|
4598
|
+
const scaleThreshold = validPositive(lodScaleThreshold, DEFAULT_LOD_SCALE_THRESHOLD);
|
|
4599
|
+
if (effectiveScale >= scaleThreshold) {
|
|
4600
|
+
return void 0;
|
|
4601
|
+
}
|
|
4602
|
+
const textureSizeThreshold = validPositive(
|
|
4603
|
+
lodTextureSizeThreshold,
|
|
4604
|
+
DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD
|
|
4605
|
+
);
|
|
4606
|
+
if (Math.max(width, height) < textureSizeThreshold) {
|
|
4607
|
+
return void 0;
|
|
4608
|
+
}
|
|
4609
|
+
const rawLevel = Math.round(Math.log2(1 / effectiveScale));
|
|
4610
|
+
const maxDimensionLevel = Math.max(1, Math.floor(Math.log2(Math.max(width, height))));
|
|
4611
|
+
const maxLevel = Math.min(maxDimensionLevel, validMaxLevel(lodMaxLevel, maxDimensionLevel));
|
|
4612
|
+
const level = clamp(Math.max(1, rawLevel), 1, maxLevel);
|
|
4613
|
+
const factor = __pow(2, level);
|
|
4614
|
+
return {
|
|
4615
|
+
level,
|
|
4616
|
+
width: Math.max(1, Math.round(width / factor)),
|
|
4617
|
+
height: Math.max(1, Math.round(height / factor))
|
|
4618
|
+
};
|
|
4619
|
+
}
|
|
4620
|
+
function getTextureLODMode(lod) {
|
|
4621
|
+
if (lod === false || lod === "single-auto") {
|
|
4622
|
+
return lod;
|
|
4623
|
+
}
|
|
4624
|
+
return "full";
|
|
4625
|
+
}
|
|
4626
|
+
function getTextureLODFilter(filter) {
|
|
4627
|
+
return filter === "nearest" ? "nearest" : "linear";
|
|
4628
|
+
}
|
|
4629
|
+
function validPositive(value, fallback) {
|
|
4630
|
+
return value !== void 0 && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
4631
|
+
}
|
|
4632
|
+
function validMaxLevel(value, fallback) {
|
|
4633
|
+
return value !== void 0 && Number.isFinite(value) && value >= 1 ? Math.floor(value) : fallback;
|
|
4634
|
+
}
|
|
4635
|
+
function clamp(value, min, max) {
|
|
4636
|
+
return Math.min(max, Math.max(min, value));
|
|
4637
|
+
}
|
|
4573
4638
|
function createTexture(url, options = {}) {
|
|
4574
4639
|
const config2 = pixi_js.loadTextures.config;
|
|
4575
4640
|
const previousCrossOrigin = config2 == null ? void 0 : config2.crossOrigin;
|
|
@@ -4582,7 +4647,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4582
4647
|
config2.preferCreateImageBitmap = false;
|
|
4583
4648
|
config2.preferWorkers = false;
|
|
4584
4649
|
}
|
|
4585
|
-
return pixi_js.Assets.load(
|
|
4650
|
+
return pixi_js.Assets.load({
|
|
4651
|
+
src: url,
|
|
4652
|
+
data: {
|
|
4653
|
+
autoGenerateMipmaps: getTextureLODMode(options.lod) === "full"
|
|
4654
|
+
}
|
|
4655
|
+
}).catch((error) => {
|
|
4586
4656
|
if (error instanceof Error) {
|
|
4587
4657
|
throw error;
|
|
4588
4658
|
}
|
|
@@ -4715,9 +4785,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4715
4785
|
const setupEssentials = (context, next) => __async(null, null, function* () {
|
|
4716
4786
|
if (context.settings) {
|
|
4717
4787
|
const live2DModel = context.live2dModel;
|
|
4718
|
-
const textureOptions = {
|
|
4788
|
+
const textureOptions = __spreadValues({
|
|
4719
4789
|
crossOrigin: context.options.crossOrigin
|
|
4720
|
-
};
|
|
4790
|
+
}, context.options.textureOptions);
|
|
4721
4791
|
if (context.settings instanceof CubismLegacyModelSettings) {
|
|
4722
4792
|
textureOptions.preferCreateImageBitmap = false;
|
|
4723
4793
|
}
|
|
@@ -4763,114 +4833,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4763
4833
|
}
|
|
4764
4834
|
throw new TypeError("Missing settings.");
|
|
4765
4835
|
});
|
|
4766
|
-
const _ZipLoader = class _ZipLoader {
|
|
4767
|
-
static unzip(reader, settings) {
|
|
4768
|
-
return __async(this, null, function* () {
|
|
4769
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
4770
|
-
const requiredFilePaths = [];
|
|
4771
|
-
for (const definedFile of settings.getDefinedFiles()) {
|
|
4772
|
-
const actualPath = decodeURI(resolveURL(settings.url, definedFile));
|
|
4773
|
-
if (filePaths.includes(actualPath)) {
|
|
4774
|
-
requiredFilePaths.push(actualPath);
|
|
4775
|
-
}
|
|
4776
|
-
}
|
|
4777
|
-
const files = yield _ZipLoader.getFiles(reader, requiredFilePaths);
|
|
4778
|
-
for (let i = 0; i < files.length; i++) {
|
|
4779
|
-
const path = requiredFilePaths[i];
|
|
4780
|
-
const file = files[i];
|
|
4781
|
-
Object.defineProperty(file, "webkitRelativePath", {
|
|
4782
|
-
value: path
|
|
4783
|
-
});
|
|
4784
|
-
}
|
|
4785
|
-
return files;
|
|
4786
|
-
});
|
|
4787
|
-
}
|
|
4788
|
-
static createSettings(reader) {
|
|
4789
|
-
return __async(this, null, function* () {
|
|
4790
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
4791
|
-
const settingsFilePath = filePaths.find(
|
|
4792
|
-
(path) => path.endsWith("model.json") || path.endsWith("model3.json")
|
|
4793
|
-
);
|
|
4794
|
-
if (!settingsFilePath) {
|
|
4795
|
-
throw new Error("Settings file not found");
|
|
4796
|
-
}
|
|
4797
|
-
const settingsText = yield _ZipLoader.readText(reader, settingsFilePath);
|
|
4798
|
-
if (!settingsText) {
|
|
4799
|
-
throw new Error("Empty settings file: " + settingsFilePath);
|
|
4800
|
-
}
|
|
4801
|
-
const settingsJSON = JSON.parse(settingsText);
|
|
4802
|
-
settingsJSON.url = settingsFilePath;
|
|
4803
|
-
const runtime = _ZipLoader.live2dFactory.findRuntime(settingsJSON);
|
|
4804
|
-
if (!runtime) {
|
|
4805
|
-
throw new Error("Unknown settings JSON");
|
|
4806
|
-
}
|
|
4807
|
-
return runtime.createModelSettings(settingsJSON);
|
|
4808
|
-
});
|
|
4809
|
-
}
|
|
4810
|
-
static zipReader(data, url) {
|
|
4811
|
-
return Promise.reject(new Error("Not implemented"));
|
|
4812
|
-
}
|
|
4813
|
-
static getFilePaths(reader) {
|
|
4814
|
-
return Promise.reject(new Error("Not implemented"));
|
|
4815
|
-
}
|
|
4816
|
-
static getFiles(reader, paths) {
|
|
4817
|
-
return Promise.reject(new Error("Not implemented"));
|
|
4818
|
-
}
|
|
4819
|
-
static readText(reader, path) {
|
|
4820
|
-
return Promise.reject(new Error("Not implemented"));
|
|
4821
|
-
}
|
|
4822
|
-
static releaseReader(reader) {
|
|
4823
|
-
}
|
|
4824
|
-
};
|
|
4825
|
-
// will be set by Live2DFactory
|
|
4826
|
-
__publicField(_ZipLoader, "live2dFactory");
|
|
4827
|
-
__publicField(_ZipLoader, "ZIP_PROTOCOL", "zip://");
|
|
4828
|
-
__publicField(_ZipLoader, "uid", 0);
|
|
4829
|
-
__publicField(_ZipLoader, "factory", (context, next) => __async(null, null, function* () {
|
|
4830
|
-
const source = context.source;
|
|
4831
|
-
let sourceURL;
|
|
4832
|
-
let zipBlob;
|
|
4833
|
-
let settings;
|
|
4834
|
-
if (typeof source === "string" && (source.endsWith(".zip") || source.startsWith(_ZipLoader.ZIP_PROTOCOL))) {
|
|
4835
|
-
if (source.startsWith(_ZipLoader.ZIP_PROTOCOL)) {
|
|
4836
|
-
sourceURL = source.slice(_ZipLoader.ZIP_PROTOCOL.length);
|
|
4837
|
-
} else {
|
|
4838
|
-
sourceURL = source;
|
|
4839
|
-
}
|
|
4840
|
-
zipBlob = yield Live2DLoader.load({
|
|
4841
|
-
url: sourceURL,
|
|
4842
|
-
type: "blob",
|
|
4843
|
-
target: context.live2dModel
|
|
4844
|
-
});
|
|
4845
|
-
} else if (Array.isArray(source) && source.length === 1 && source[0] instanceof File && source[0].name.endsWith(".zip")) {
|
|
4846
|
-
zipBlob = source[0];
|
|
4847
|
-
sourceURL = URL.createObjectURL(zipBlob);
|
|
4848
|
-
settings = source.settings;
|
|
4849
|
-
}
|
|
4850
|
-
if (zipBlob) {
|
|
4851
|
-
if (!zipBlob.size) {
|
|
4852
|
-
throw new Error("Empty zip file");
|
|
4853
|
-
}
|
|
4854
|
-
const reader = yield _ZipLoader.zipReader(zipBlob, sourceURL);
|
|
4855
|
-
if (!settings) {
|
|
4856
|
-
settings = yield _ZipLoader.createSettings(reader);
|
|
4857
|
-
}
|
|
4858
|
-
settings._objectURL = _ZipLoader.ZIP_PROTOCOL + _ZipLoader.uid + "/" + settings.url;
|
|
4859
|
-
const files = yield _ZipLoader.unzip(reader, settings);
|
|
4860
|
-
files.settings = settings;
|
|
4861
|
-
context.source = files;
|
|
4862
|
-
if (sourceURL.startsWith("blob:")) {
|
|
4863
|
-
context.live2dModel.once("modelLoaded", (internalModel) => {
|
|
4864
|
-
internalModel.once("destroy", function() {
|
|
4865
|
-
URL.revokeObjectURL(sourceURL);
|
|
4866
|
-
});
|
|
4867
|
-
});
|
|
4868
|
-
}
|
|
4869
|
-
_ZipLoader.releaseReader(reader);
|
|
4870
|
-
}
|
|
4871
|
-
return next();
|
|
4872
|
-
}));
|
|
4873
|
-
let ZipLoader = _ZipLoader;
|
|
4874
4836
|
const _FileLoader = class _FileLoader {
|
|
4875
4837
|
/**
|
|
4876
4838
|
* Resolves the path of a resource file to the object URL.
|
|
@@ -5151,7 +5113,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5151
5113
|
* Middlewares to run through when setting up a Live2DModel.
|
|
5152
5114
|
*/
|
|
5153
5115
|
__publicField(_Live2DFactory, "live2DModelMiddlewares", [
|
|
5154
|
-
ZipLoader.factory,
|
|
5155
5116
|
FileLoader.factory,
|
|
5156
5117
|
urlToJSON,
|
|
5157
5118
|
jsonToSettings,
|
|
@@ -5177,7 +5138,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5177
5138
|
return Live2DFactory.loadExpression(this, index);
|
|
5178
5139
|
};
|
|
5179
5140
|
FileLoader["live2dFactory"] = Live2DFactory;
|
|
5180
|
-
ZipLoader["live2dFactory"] = Live2DFactory;
|
|
5181
5141
|
const _Automator = class _Automator {
|
|
5182
5142
|
constructor(model, {
|
|
5183
5143
|
autoUpdate = true,
|
|
@@ -5331,10 +5291,17 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5331
5291
|
const tempWorldMatrix = new pixi_js.Matrix();
|
|
5332
5292
|
const tempDrawableBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
5333
5293
|
const tempModelBounds = new pixi_js.Bounds();
|
|
5294
|
+
let live2DPluginFallbackWarned = false;
|
|
5334
5295
|
class Live2DPipe {
|
|
5335
5296
|
constructor(renderer) {
|
|
5336
5297
|
this.renderer = renderer;
|
|
5337
5298
|
}
|
|
5299
|
+
addRenderable(model, instructionSet) {
|
|
5300
|
+
var _a, _b;
|
|
5301
|
+
const renderPipes = this.renderer.renderPipes;
|
|
5302
|
+
(_b = (_a = renderPipes.batch) == null ? void 0 : _a.break) == null ? void 0 : _b.call(_a, instructionSet);
|
|
5303
|
+
instructionSet.add(model);
|
|
5304
|
+
}
|
|
5338
5305
|
execute(model) {
|
|
5339
5306
|
if (!model.visible || model.alpha <= 0) {
|
|
5340
5307
|
return;
|
|
@@ -5343,15 +5310,86 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5343
5310
|
}
|
|
5344
5311
|
updateRenderable() {
|
|
5345
5312
|
}
|
|
5313
|
+
destroyRenderable() {
|
|
5314
|
+
}
|
|
5315
|
+
validateRenderable() {
|
|
5316
|
+
return false;
|
|
5317
|
+
}
|
|
5346
5318
|
destroy() {
|
|
5347
5319
|
}
|
|
5348
5320
|
}
|
|
5321
|
+
__publicField(Live2DPipe, "extension", {
|
|
5322
|
+
type: [pixi_js.ExtensionType.WebGLPipes],
|
|
5323
|
+
name: "live2d"
|
|
5324
|
+
});
|
|
5325
|
+
const Live2DPlugin = Live2DPipe;
|
|
5349
5326
|
function ensureLive2DPipe(renderer) {
|
|
5350
5327
|
const r = renderer;
|
|
5351
5328
|
if (!r.renderPipes.live2d) {
|
|
5329
|
+
if (!live2DPluginFallbackWarned) {
|
|
5330
|
+
live2DPluginFallbackWarned = true;
|
|
5331
|
+
console.warn(
|
|
5332
|
+
"[untitled-pixi-live2d-engine] Lazy Live2D render pipe registration is deprecated. Register Live2DPlugin explicitly with `extensions.add(Live2DPlugin)` before creating the Pixi renderer."
|
|
5333
|
+
);
|
|
5334
|
+
}
|
|
5352
5335
|
r.renderPipes.live2d = new Live2DPipe(renderer);
|
|
5353
5336
|
}
|
|
5354
5337
|
}
|
|
5338
|
+
function getMatrixMaxScale(matrix) {
|
|
5339
|
+
return Math.max(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d));
|
|
5340
|
+
}
|
|
5341
|
+
function isDrawableTextureResource(resource) {
|
|
5342
|
+
if (!resource || typeof resource !== "object") {
|
|
5343
|
+
return false;
|
|
5344
|
+
}
|
|
5345
|
+
const { width, height } = resource;
|
|
5346
|
+
return typeof width === "number" && width > 0 && typeof height === "number" && height > 0;
|
|
5347
|
+
}
|
|
5348
|
+
function createTextureLODTexture(sourceTexture, level, width, height, filter) {
|
|
5349
|
+
var _a, _b;
|
|
5350
|
+
const resource = sourceTexture.source.resource;
|
|
5351
|
+
if (!isDrawableTextureResource(resource)) {
|
|
5352
|
+
return void 0;
|
|
5353
|
+
}
|
|
5354
|
+
const canvas = pixi_js.DOMAdapter.get().createCanvas(width, height);
|
|
5355
|
+
const context = canvas.getContext("2d");
|
|
5356
|
+
if (!context) {
|
|
5357
|
+
return void 0;
|
|
5358
|
+
}
|
|
5359
|
+
try {
|
|
5360
|
+
context.clearRect(0, 0, width, height);
|
|
5361
|
+
context.imageSmoothingEnabled = filter !== "nearest";
|
|
5362
|
+
if ("imageSmoothingQuality" in context && filter !== "nearest") {
|
|
5363
|
+
context.imageSmoothingQuality = "high";
|
|
5364
|
+
}
|
|
5365
|
+
context.drawImage(
|
|
5366
|
+
resource,
|
|
5367
|
+
0,
|
|
5368
|
+
0,
|
|
5369
|
+
sourceTexture.source.pixelWidth,
|
|
5370
|
+
sourceTexture.source.pixelHeight,
|
|
5371
|
+
0,
|
|
5372
|
+
0,
|
|
5373
|
+
width,
|
|
5374
|
+
height
|
|
5375
|
+
);
|
|
5376
|
+
} catch (e) {
|
|
5377
|
+
return void 0;
|
|
5378
|
+
}
|
|
5379
|
+
const label = `${(_b = (_a = sourceTexture.label) != null ? _a : sourceTexture.source.label) != null ? _b : "Live2DTexture"} LOD ${level}`;
|
|
5380
|
+
return new pixi_js.Texture({
|
|
5381
|
+
label,
|
|
5382
|
+
source: new pixi_js.CanvasSource({
|
|
5383
|
+
resource: canvas,
|
|
5384
|
+
width,
|
|
5385
|
+
height,
|
|
5386
|
+
resolution: 1,
|
|
5387
|
+
scaleMode: getTextureLODFilter(filter),
|
|
5388
|
+
autoGenerateMipmaps: false,
|
|
5389
|
+
label
|
|
5390
|
+
})
|
|
5391
|
+
});
|
|
5392
|
+
}
|
|
5355
5393
|
class Live2DModel extends pixi_js.Container {
|
|
5356
5394
|
/**
|
|
5357
5395
|
* Creates a new Live2DModel instance.
|
|
@@ -5375,6 +5413,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5375
5413
|
* @type {Texture[]}
|
|
5376
5414
|
*/
|
|
5377
5415
|
__publicField(this, "textures", []);
|
|
5416
|
+
__publicField(this, "textureOptions");
|
|
5417
|
+
__publicField(this, "textureLODStates", []);
|
|
5418
|
+
__publicField(this, "textureLODFailures", []);
|
|
5378
5419
|
/** @override
|
|
5379
5420
|
* The Live2DTransform instance for this model.
|
|
5380
5421
|
*/
|
|
@@ -5431,15 +5472,25 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5431
5472
|
this.internalModel.updateWebGLContext(renderer.gl, this.generateUID());
|
|
5432
5473
|
shouldUpdateTexture = true;
|
|
5433
5474
|
}
|
|
5475
|
+
const { projectionMatrix, offset, worldTransformMatrix } = renderer.globalUniforms.globalUniformData;
|
|
5476
|
+
const adjustedWorld = tempWorldMatrix.copyFrom(worldTransformMatrix).append(this.groupTransform);
|
|
5477
|
+
const effectiveScale = getMatrixMaxScale(adjustedWorld) * renderer.resolution;
|
|
5434
5478
|
for (let i = 0; i < this.textures.length; i++) {
|
|
5435
|
-
const
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5479
|
+
const originalTexture = this.textures[i];
|
|
5480
|
+
let texture = this.resolveTextureForRender(i, originalTexture, effectiveScale);
|
|
5481
|
+
try {
|
|
5482
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
5483
|
+
} catch (e) {
|
|
5484
|
+
if (texture === originalTexture) {
|
|
5485
|
+
throw new Error("Failed to upload Live2D texture.");
|
|
5486
|
+
}
|
|
5487
|
+
const state = this.textureLODStates[i];
|
|
5488
|
+
if ((state == null ? void 0 : state.texture) === texture) {
|
|
5489
|
+
this.markTextureLODFailure(i, originalTexture, state.level);
|
|
5490
|
+
this.destroyTextureLODState(i);
|
|
5491
|
+
}
|
|
5492
|
+
texture = originalTexture;
|
|
5493
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
5443
5494
|
}
|
|
5444
5495
|
this.internalModel.bindTexture(i, renderer.texture.getGlSource(texture.source).texture);
|
|
5445
5496
|
}
|
|
@@ -5456,8 +5507,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5456
5507
|
if (frameDelta) {
|
|
5457
5508
|
this.internalModel.update(frameDelta, this.elapsedTime);
|
|
5458
5509
|
}
|
|
5459
|
-
const { projectionMatrix, offset } = renderer.globalUniforms.globalUniformData;
|
|
5460
|
-
const adjustedWorld = tempWorldMatrix.copyFrom(this.worldTransform);
|
|
5461
5510
|
adjustedWorld.tx -= (_a = offset == null ? void 0 : offset.x) != null ? _a : 0;
|
|
5462
5511
|
adjustedWorld.ty -= (_b = offset == null ? void 0 : offset.y) != null ? _b : 0;
|
|
5463
5512
|
const internalTransform = tempMatrix$1.copyFrom(projectionMatrix).append(adjustedWorld);
|
|
@@ -5480,6 +5529,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5480
5529
|
}
|
|
5481
5530
|
}
|
|
5482
5531
|
});
|
|
5532
|
+
this.textureOptions = options == null ? void 0 : options.textureOptions;
|
|
5483
5533
|
this.anchor = new pixi_js.ObservablePoint(
|
|
5484
5534
|
{
|
|
5485
5535
|
_onUpdate: () => this.onAnchorChange()
|
|
@@ -5631,9 +5681,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5631
5681
|
ensureLive2DPipe(renderer);
|
|
5632
5682
|
const renderPipes = renderer.renderPipes;
|
|
5633
5683
|
const addRenderable = () => {
|
|
5634
|
-
|
|
5635
|
-
(_b2 = (_a2 = renderPipes.batch) == null ? void 0 : _a2.break) == null ? void 0 : _b2.call(_a2, instructionSet);
|
|
5636
|
-
instructionSet.add(this);
|
|
5684
|
+
renderPipes.live2d.addRenderable(this, instructionSet);
|
|
5637
5685
|
};
|
|
5638
5686
|
const collectChildren = () => {
|
|
5639
5687
|
const children = this.children;
|
|
@@ -5924,6 +5972,75 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5924
5972
|
this.deltaTime += dt;
|
|
5925
5973
|
this.elapsedTime += dt;
|
|
5926
5974
|
}
|
|
5975
|
+
resolveTextureForRender(index, texture, effectiveScale) {
|
|
5976
|
+
var _a;
|
|
5977
|
+
const plan = getTextureLODPlan(__spreadProps(__spreadValues({}, this.textureOptions), {
|
|
5978
|
+
effectiveScale,
|
|
5979
|
+
textureWidth: texture.source.pixelWidth,
|
|
5980
|
+
textureHeight: texture.source.pixelHeight
|
|
5981
|
+
}));
|
|
5982
|
+
if (!plan) {
|
|
5983
|
+
return texture;
|
|
5984
|
+
}
|
|
5985
|
+
const failure = this.textureLODFailures[index];
|
|
5986
|
+
if ((failure == null ? void 0 : failure.source) === texture && failure.levels.has(plan.level)) {
|
|
5987
|
+
return texture;
|
|
5988
|
+
}
|
|
5989
|
+
const existing = this.textureLODStates[index];
|
|
5990
|
+
if ((existing == null ? void 0 : existing.source) === texture && existing.level === plan.level && !existing.texture.destroyed) {
|
|
5991
|
+
return existing.texture;
|
|
5992
|
+
}
|
|
5993
|
+
this.destroyTextureLODState(index);
|
|
5994
|
+
const lodTexture = createTextureLODTexture(
|
|
5995
|
+
texture,
|
|
5996
|
+
plan.level,
|
|
5997
|
+
plan.width,
|
|
5998
|
+
plan.height,
|
|
5999
|
+
(_a = this.textureOptions) == null ? void 0 : _a.lodFilter
|
|
6000
|
+
);
|
|
6001
|
+
if (!lodTexture) {
|
|
6002
|
+
this.markTextureLODFailure(index, texture, plan.level);
|
|
6003
|
+
return texture;
|
|
6004
|
+
}
|
|
6005
|
+
this.textureLODStates[index] = {
|
|
6006
|
+
source: texture,
|
|
6007
|
+
level: plan.level,
|
|
6008
|
+
texture: lodTexture
|
|
6009
|
+
};
|
|
6010
|
+
return lodTexture;
|
|
6011
|
+
}
|
|
6012
|
+
markTextureLODFailure(index, texture, level) {
|
|
6013
|
+
let failure = this.textureLODFailures[index];
|
|
6014
|
+
if ((failure == null ? void 0 : failure.source) !== texture) {
|
|
6015
|
+
failure = { source: texture, levels: /* @__PURE__ */ new Set() };
|
|
6016
|
+
this.textureLODFailures[index] = failure;
|
|
6017
|
+
}
|
|
6018
|
+
failure.levels.add(level);
|
|
6019
|
+
}
|
|
6020
|
+
destroyTextureLODState(index) {
|
|
6021
|
+
const state = this.textureLODStates[index];
|
|
6022
|
+
if (!state) {
|
|
6023
|
+
return;
|
|
6024
|
+
}
|
|
6025
|
+
state.texture.destroy(true);
|
|
6026
|
+
this.textureLODStates[index] = void 0;
|
|
6027
|
+
}
|
|
6028
|
+
destroyTextureLODStates() {
|
|
6029
|
+
for (let i = 0; i < this.textureLODStates.length; i++) {
|
|
6030
|
+
this.destroyTextureLODState(i);
|
|
6031
|
+
}
|
|
6032
|
+
this.textureLODFailures.length = 0;
|
|
6033
|
+
}
|
|
6034
|
+
uploadTextureForRender(renderer, texture, shouldUpdateTexture) {
|
|
6035
|
+
const hasGlSource = Boolean(texture.source._gpuData[renderer.uid]);
|
|
6036
|
+
if (shouldUpdateTexture || !hasGlSource) {
|
|
6037
|
+
renderer.gl.pixelStorei(
|
|
6038
|
+
WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,
|
|
6039
|
+
this.internalModel.textureFlipY
|
|
6040
|
+
);
|
|
6041
|
+
renderer.texture.bind(texture, 0);
|
|
6042
|
+
}
|
|
6043
|
+
}
|
|
5927
6044
|
/**
|
|
5928
6045
|
* Destroys the model and all related resources. This takes the same options and also
|
|
5929
6046
|
* behaves the same as `PIXI.Container#destroy`.
|
|
@@ -5938,6 +6055,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
5938
6055
|
*/
|
|
5939
6056
|
destroy(options) {
|
|
5940
6057
|
this.emit("destroy");
|
|
6058
|
+
this.destroyTextureLODStates();
|
|
5941
6059
|
if (options == null ? void 0 : options.texture) {
|
|
5942
6060
|
this.textures.forEach((texture) => texture.destroy(options.baseTexture));
|
|
5943
6061
|
}
|
|
@@ -11235,6 +11353,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
11235
11353
|
const tempMatrix = new CubismMatrix44();
|
|
11236
11354
|
const DEFAULT_MASKS_PER_RENDER_TEXTURE = 36;
|
|
11237
11355
|
const MASKS_PER_RENDER_TEXTURE = 32;
|
|
11356
|
+
const HIGH_PRECISION_MASK_UNIQUE_MASK_SET_THRESHOLD = 16;
|
|
11357
|
+
const HIGH_PRECISION_MASK_MASKED_DRAWABLE_THRESHOLD = 64;
|
|
11358
|
+
const HIGH_PRECISION_MASK_MAX_MASKS_PER_DRAWABLE_THRESHOLD = 3;
|
|
11359
|
+
const HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD = 4096;
|
|
11360
|
+
const HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD = 0.5;
|
|
11361
|
+
const HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD = 24;
|
|
11238
11362
|
function getRequiredMaskRenderTextureCount(model) {
|
|
11239
11363
|
var _a;
|
|
11240
11364
|
if (!model.isUsingMasking()) {
|
|
@@ -11257,6 +11381,51 @@ var __async = (__this, __arguments, generator) => {
|
|
|
11257
11381
|
}
|
|
11258
11382
|
return Math.ceil(clippingContextCount / MASKS_PER_RENDER_TEXTURE);
|
|
11259
11383
|
}
|
|
11384
|
+
function getMaskProfile(model) {
|
|
11385
|
+
var _a, _b;
|
|
11386
|
+
const maskCounts = model.getDrawableMaskCounts();
|
|
11387
|
+
const masks = model.getDrawableMasks();
|
|
11388
|
+
const uniqueMaskSets = /* @__PURE__ */ new Set();
|
|
11389
|
+
const drawableCount = model.getDrawableCount();
|
|
11390
|
+
let maskedDrawableCount = 0;
|
|
11391
|
+
let maxMasksPerDrawable = 0;
|
|
11392
|
+
let maskedVertexCount = 0;
|
|
11393
|
+
let totalVertexCount = 0;
|
|
11394
|
+
for (let i = 0; i < drawableCount; i++) {
|
|
11395
|
+
const vertexCount = model.getDrawableVertexCount(i);
|
|
11396
|
+
const maskCount = (_a = maskCounts[i]) != null ? _a : 0;
|
|
11397
|
+
totalVertexCount += vertexCount;
|
|
11398
|
+
if (maskCount <= 0) {
|
|
11399
|
+
continue;
|
|
11400
|
+
}
|
|
11401
|
+
maskedDrawableCount++;
|
|
11402
|
+
maskedVertexCount += vertexCount;
|
|
11403
|
+
maxMasksPerDrawable = Math.max(maxMasksPerDrawable, maskCount);
|
|
11404
|
+
const maskSet = Array.from((_b = masks[i]) != null ? _b : []).slice(0, maskCount).sort((a, b) => a - b).join(",");
|
|
11405
|
+
uniqueMaskSets.add(maskSet);
|
|
11406
|
+
}
|
|
11407
|
+
return {
|
|
11408
|
+
maskedDrawableCount,
|
|
11409
|
+
uniqueMaskSetCount: uniqueMaskSets.size,
|
|
11410
|
+
maxMasksPerDrawable,
|
|
11411
|
+
maskedVertexCount,
|
|
11412
|
+
totalVertexCount
|
|
11413
|
+
};
|
|
11414
|
+
}
|
|
11415
|
+
function shouldUseHighPrecisionMask(model) {
|
|
11416
|
+
if (!model.isUsingMasking()) {
|
|
11417
|
+
return false;
|
|
11418
|
+
}
|
|
11419
|
+
const profile = getMaskProfile(model);
|
|
11420
|
+
const maskedVertexRatio = profile.totalVertexCount > 0 ? profile.maskedVertexCount / profile.totalVertexCount : 0;
|
|
11421
|
+
return profile.uniqueMaskSetCount > HIGH_PRECISION_MASK_UNIQUE_MASK_SET_THRESHOLD || profile.maskedDrawableCount > HIGH_PRECISION_MASK_MASKED_DRAWABLE_THRESHOLD || profile.maxMasksPerDrawable >= HIGH_PRECISION_MASK_MAX_MASKS_PER_DRAWABLE_THRESHOLD || profile.maskedVertexCount > HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD || maskedVertexRatio >= HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD && profile.maskedDrawableCount > HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD;
|
|
11422
|
+
}
|
|
11423
|
+
function resolveHighPrecisionMaskOption(model, option) {
|
|
11424
|
+
if (typeof option === "boolean") {
|
|
11425
|
+
return option;
|
|
11426
|
+
}
|
|
11427
|
+
return shouldUseHighPrecisionMask(model);
|
|
11428
|
+
}
|
|
11260
11429
|
class CubismInternalModel extends InternalModel {
|
|
11261
11430
|
constructor(coreModel, settings, options) {
|
|
11262
11431
|
super();
|
|
@@ -11357,6 +11526,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
11357
11526
|
breathParams.pushBack(new BreathParameterData(this.idParamBreath, 0, 0.5, 3.2345, 0.5));
|
|
11358
11527
|
this.breath.setParameters(breathParams);
|
|
11359
11528
|
this.renderer.initialize(this.coreModel, getRequiredMaskRenderTextureCount(this.coreModel));
|
|
11529
|
+
this.renderer.useHighPrecisionMask(
|
|
11530
|
+
resolveHighPrecisionMaskOption(this.coreModel, this.options.useHighPrecisionMask)
|
|
11531
|
+
);
|
|
11360
11532
|
this.renderer.setIsPremultipliedAlpha(true);
|
|
11361
11533
|
}
|
|
11362
11534
|
getIdSafe(id) {
|
|
@@ -11455,7 +11627,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
11455
11627
|
value = Math.pow(value, 1.15);
|
|
11456
11628
|
const min_ = value > 0 ? 0.1 : 0;
|
|
11457
11629
|
const max_ = 1;
|
|
11458
|
-
value = clamp(value, min_, max_);
|
|
11630
|
+
value = clamp$1(value, min_, max_);
|
|
11459
11631
|
this.motionManager.lipSyncIds.forEach((lipSyncId) => {
|
|
11460
11632
|
model.addParameterValueById(this.getIdSafe(lipSyncId), value, this.options.lipSyncWeight);
|
|
11461
11633
|
});
|
|
@@ -15709,6 +15881,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
15709
15881
|
exports2.Live2DFactory = Live2DFactory;
|
|
15710
15882
|
exports2.Live2DLoader = Live2DLoader;
|
|
15711
15883
|
exports2.Live2DModel = Live2DModel;
|
|
15884
|
+
exports2.Live2DPlugin = Live2DPlugin;
|
|
15712
15885
|
exports2.Live2DTransform = Live2DTransform;
|
|
15713
15886
|
exports2.LogLevel = LogLevel;
|
|
15714
15887
|
exports2.MBToByte = MBToByte;
|
|
@@ -15722,9 +15895,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
15722
15895
|
exports2.VERSION = VERSION;
|
|
15723
15896
|
exports2.VOLUME = VOLUME;
|
|
15724
15897
|
exports2.XHRLoader = XHRLoader;
|
|
15725
|
-
exports2.ZipLoader = ZipLoader;
|
|
15726
15898
|
exports2.applyMixins = applyMixins;
|
|
15727
|
-
exports2.clamp = clamp;
|
|
15899
|
+
exports2.clamp = clamp$1;
|
|
15728
15900
|
exports2.config = config;
|
|
15729
15901
|
exports2.configureCubismSDK = configureCubismSDK;
|
|
15730
15902
|
exports2.copyArray = copyArray;
|