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/index.es.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -15,6 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
15
17
|
}
|
|
16
18
|
return a;
|
|
17
19
|
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
18
21
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
22
|
var __async = (__this, __arguments, generator) => {
|
|
20
23
|
return new Promise((resolve, reject) => {
|
|
@@ -36,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
36
39
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
40
|
});
|
|
38
41
|
};
|
|
39
|
-
import { EventEmitter, Matrix, loadTextures, Assets, Ticker, Transform, Point, Bounds, Container, ObservablePoint, WebGLRenderer } from "pixi.js";
|
|
42
|
+
import { EventEmitter, Matrix, loadTextures, Assets, Ticker, Transform, Point, Bounds, ExtensionType, Container, ObservablePoint, WebGLRenderer, DOMAdapter, Texture, CanvasSource } from "pixi.js";
|
|
40
43
|
import { sound, Sound, webaudio } from "@pixi/sound";
|
|
41
44
|
const LOGICAL_WIDTH = 2;
|
|
42
45
|
const LOGICAL_HEIGHT = 2;
|
|
@@ -103,7 +106,7 @@ const config = {
|
|
|
103
106
|
preserveExpressionOnMotion: true,
|
|
104
107
|
cubism: CubismFrameworkConfig
|
|
105
108
|
};
|
|
106
|
-
const VERSION = "1.0
|
|
109
|
+
const VERSION = "1.2.0";
|
|
107
110
|
const logger = {
|
|
108
111
|
log(tag, ...messages) {
|
|
109
112
|
if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
|
|
@@ -121,7 +124,7 @@ const logger = {
|
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
};
|
|
124
|
-
function clamp(num, lower, upper) {
|
|
127
|
+
function clamp$1(num, lower, upper) {
|
|
125
128
|
return num < lower ? lower : num > upper ? upper : num;
|
|
126
129
|
}
|
|
127
130
|
function rand(min, max) {
|
|
@@ -396,8 +399,8 @@ class FocusController {
|
|
|
396
399
|
* @param instant - Should the focus position be instantly applied.
|
|
397
400
|
*/
|
|
398
401
|
focus(x, y, instant = false) {
|
|
399
|
-
this.targetX = clamp(x, -1, 1);
|
|
400
|
-
this.targetY = clamp(y, -1, 1);
|
|
402
|
+
this.targetX = clamp$1(x, -1, 1);
|
|
403
|
+
this.targetY = clamp$1(y, -1, 1);
|
|
401
404
|
if (instant) {
|
|
402
405
|
this.x = this.targetX;
|
|
403
406
|
this.y = this.targetY;
|
|
@@ -1914,6 +1917,68 @@ class CubismLegacyModelSettings extends ModelSettings {
|
|
|
1914
1917
|
}
|
|
1915
1918
|
}
|
|
1916
1919
|
}
|
|
1920
|
+
const DEFAULT_LOD_SCALE_THRESHOLD = 0.5;
|
|
1921
|
+
const DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD = 4096;
|
|
1922
|
+
function getTextureLODPlan({
|
|
1923
|
+
lod,
|
|
1924
|
+
effectiveScale,
|
|
1925
|
+
textureWidth,
|
|
1926
|
+
textureHeight,
|
|
1927
|
+
lodScaleThreshold,
|
|
1928
|
+
lodTextureSizeThreshold,
|
|
1929
|
+
lodMaxLevel
|
|
1930
|
+
}) {
|
|
1931
|
+
if (getTextureLODMode(lod) !== "single-auto") {
|
|
1932
|
+
return void 0;
|
|
1933
|
+
}
|
|
1934
|
+
if (!Number.isFinite(effectiveScale) || effectiveScale <= 0) {
|
|
1935
|
+
return void 0;
|
|
1936
|
+
}
|
|
1937
|
+
const width = Math.floor(textureWidth);
|
|
1938
|
+
const height = Math.floor(textureHeight);
|
|
1939
|
+
if (width <= 1 || height <= 1) {
|
|
1940
|
+
return void 0;
|
|
1941
|
+
}
|
|
1942
|
+
const scaleThreshold = validPositive(lodScaleThreshold, DEFAULT_LOD_SCALE_THRESHOLD);
|
|
1943
|
+
if (effectiveScale >= scaleThreshold) {
|
|
1944
|
+
return void 0;
|
|
1945
|
+
}
|
|
1946
|
+
const textureSizeThreshold = validPositive(
|
|
1947
|
+
lodTextureSizeThreshold,
|
|
1948
|
+
DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD
|
|
1949
|
+
);
|
|
1950
|
+
if (Math.max(width, height) < textureSizeThreshold) {
|
|
1951
|
+
return void 0;
|
|
1952
|
+
}
|
|
1953
|
+
const rawLevel = Math.round(Math.log2(1 / effectiveScale));
|
|
1954
|
+
const maxDimensionLevel = Math.max(1, Math.floor(Math.log2(Math.max(width, height))));
|
|
1955
|
+
const maxLevel = Math.min(maxDimensionLevel, validMaxLevel(lodMaxLevel, maxDimensionLevel));
|
|
1956
|
+
const level = clamp(Math.max(1, rawLevel), 1, maxLevel);
|
|
1957
|
+
const factor = __pow(2, level);
|
|
1958
|
+
return {
|
|
1959
|
+
level,
|
|
1960
|
+
width: Math.max(1, Math.round(width / factor)),
|
|
1961
|
+
height: Math.max(1, Math.round(height / factor))
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
function getTextureLODMode(lod) {
|
|
1965
|
+
if (lod === false || lod === "single-auto") {
|
|
1966
|
+
return lod;
|
|
1967
|
+
}
|
|
1968
|
+
return "full";
|
|
1969
|
+
}
|
|
1970
|
+
function getTextureLODFilter(filter) {
|
|
1971
|
+
return filter === "nearest" ? "nearest" : "linear";
|
|
1972
|
+
}
|
|
1973
|
+
function validPositive(value, fallback) {
|
|
1974
|
+
return value !== void 0 && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
1975
|
+
}
|
|
1976
|
+
function validMaxLevel(value, fallback) {
|
|
1977
|
+
return value !== void 0 && Number.isFinite(value) && value >= 1 ? Math.floor(value) : fallback;
|
|
1978
|
+
}
|
|
1979
|
+
function clamp(value, min, max) {
|
|
1980
|
+
return Math.min(max, Math.max(min, value));
|
|
1981
|
+
}
|
|
1917
1982
|
function createTexture(url, options = {}) {
|
|
1918
1983
|
const config2 = loadTextures.config;
|
|
1919
1984
|
const previousCrossOrigin = config2 == null ? void 0 : config2.crossOrigin;
|
|
@@ -1926,7 +1991,12 @@ function createTexture(url, options = {}) {
|
|
|
1926
1991
|
config2.preferCreateImageBitmap = false;
|
|
1927
1992
|
config2.preferWorkers = false;
|
|
1928
1993
|
}
|
|
1929
|
-
return Assets.load(
|
|
1994
|
+
return Assets.load({
|
|
1995
|
+
src: url,
|
|
1996
|
+
data: {
|
|
1997
|
+
autoGenerateMipmaps: getTextureLODMode(options.lod) === "full"
|
|
1998
|
+
}
|
|
1999
|
+
}).catch((error) => {
|
|
1930
2000
|
if (error instanceof Error) {
|
|
1931
2001
|
throw error;
|
|
1932
2002
|
}
|
|
@@ -2059,9 +2129,9 @@ const setupOptionals = (context, next) => __async(null, null, function* () {
|
|
|
2059
2129
|
const setupEssentials = (context, next) => __async(null, null, function* () {
|
|
2060
2130
|
if (context.settings) {
|
|
2061
2131
|
const live2DModel = context.live2dModel;
|
|
2062
|
-
const textureOptions = {
|
|
2132
|
+
const textureOptions = __spreadValues({
|
|
2063
2133
|
crossOrigin: context.options.crossOrigin
|
|
2064
|
-
};
|
|
2134
|
+
}, context.options.textureOptions);
|
|
2065
2135
|
if (context.settings instanceof CubismLegacyModelSettings) {
|
|
2066
2136
|
textureOptions.preferCreateImageBitmap = false;
|
|
2067
2137
|
}
|
|
@@ -2107,114 +2177,6 @@ const createInternalModel = (context, next) => __async(null, null, function* ()
|
|
|
2107
2177
|
}
|
|
2108
2178
|
throw new TypeError("Missing settings.");
|
|
2109
2179
|
});
|
|
2110
|
-
const _ZipLoader = class _ZipLoader {
|
|
2111
|
-
static unzip(reader, settings) {
|
|
2112
|
-
return __async(this, null, function* () {
|
|
2113
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2114
|
-
const requiredFilePaths = [];
|
|
2115
|
-
for (const definedFile of settings.getDefinedFiles()) {
|
|
2116
|
-
const actualPath = decodeURI(resolveURL(settings.url, definedFile));
|
|
2117
|
-
if (filePaths.includes(actualPath)) {
|
|
2118
|
-
requiredFilePaths.push(actualPath);
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
const files = yield _ZipLoader.getFiles(reader, requiredFilePaths);
|
|
2122
|
-
for (let i = 0; i < files.length; i++) {
|
|
2123
|
-
const path = requiredFilePaths[i];
|
|
2124
|
-
const file = files[i];
|
|
2125
|
-
Object.defineProperty(file, "webkitRelativePath", {
|
|
2126
|
-
value: path
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
return files;
|
|
2130
|
-
});
|
|
2131
|
-
}
|
|
2132
|
-
static createSettings(reader) {
|
|
2133
|
-
return __async(this, null, function* () {
|
|
2134
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2135
|
-
const settingsFilePath = filePaths.find(
|
|
2136
|
-
(path) => path.endsWith("model.json") || path.endsWith("model3.json")
|
|
2137
|
-
);
|
|
2138
|
-
if (!settingsFilePath) {
|
|
2139
|
-
throw new Error("Settings file not found");
|
|
2140
|
-
}
|
|
2141
|
-
const settingsText = yield _ZipLoader.readText(reader, settingsFilePath);
|
|
2142
|
-
if (!settingsText) {
|
|
2143
|
-
throw new Error("Empty settings file: " + settingsFilePath);
|
|
2144
|
-
}
|
|
2145
|
-
const settingsJSON = JSON.parse(settingsText);
|
|
2146
|
-
settingsJSON.url = settingsFilePath;
|
|
2147
|
-
const runtime = _ZipLoader.live2dFactory.findRuntime(settingsJSON);
|
|
2148
|
-
if (!runtime) {
|
|
2149
|
-
throw new Error("Unknown settings JSON");
|
|
2150
|
-
}
|
|
2151
|
-
return runtime.createModelSettings(settingsJSON);
|
|
2152
|
-
});
|
|
2153
|
-
}
|
|
2154
|
-
static zipReader(data, url) {
|
|
2155
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2156
|
-
}
|
|
2157
|
-
static getFilePaths(reader) {
|
|
2158
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2159
|
-
}
|
|
2160
|
-
static getFiles(reader, paths) {
|
|
2161
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2162
|
-
}
|
|
2163
|
-
static readText(reader, path) {
|
|
2164
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2165
|
-
}
|
|
2166
|
-
static releaseReader(reader) {
|
|
2167
|
-
}
|
|
2168
|
-
};
|
|
2169
|
-
// will be set by Live2DFactory
|
|
2170
|
-
__publicField(_ZipLoader, "live2dFactory");
|
|
2171
|
-
__publicField(_ZipLoader, "ZIP_PROTOCOL", "zip://");
|
|
2172
|
-
__publicField(_ZipLoader, "uid", 0);
|
|
2173
|
-
__publicField(_ZipLoader, "factory", (context, next) => __async(null, null, function* () {
|
|
2174
|
-
const source = context.source;
|
|
2175
|
-
let sourceURL;
|
|
2176
|
-
let zipBlob;
|
|
2177
|
-
let settings;
|
|
2178
|
-
if (typeof source === "string" && (source.endsWith(".zip") || source.startsWith(_ZipLoader.ZIP_PROTOCOL))) {
|
|
2179
|
-
if (source.startsWith(_ZipLoader.ZIP_PROTOCOL)) {
|
|
2180
|
-
sourceURL = source.slice(_ZipLoader.ZIP_PROTOCOL.length);
|
|
2181
|
-
} else {
|
|
2182
|
-
sourceURL = source;
|
|
2183
|
-
}
|
|
2184
|
-
zipBlob = yield Live2DLoader.load({
|
|
2185
|
-
url: sourceURL,
|
|
2186
|
-
type: "blob",
|
|
2187
|
-
target: context.live2dModel
|
|
2188
|
-
});
|
|
2189
|
-
} else if (Array.isArray(source) && source.length === 1 && source[0] instanceof File && source[0].name.endsWith(".zip")) {
|
|
2190
|
-
zipBlob = source[0];
|
|
2191
|
-
sourceURL = URL.createObjectURL(zipBlob);
|
|
2192
|
-
settings = source.settings;
|
|
2193
|
-
}
|
|
2194
|
-
if (zipBlob) {
|
|
2195
|
-
if (!zipBlob.size) {
|
|
2196
|
-
throw new Error("Empty zip file");
|
|
2197
|
-
}
|
|
2198
|
-
const reader = yield _ZipLoader.zipReader(zipBlob, sourceURL);
|
|
2199
|
-
if (!settings) {
|
|
2200
|
-
settings = yield _ZipLoader.createSettings(reader);
|
|
2201
|
-
}
|
|
2202
|
-
settings._objectURL = _ZipLoader.ZIP_PROTOCOL + _ZipLoader.uid + "/" + settings.url;
|
|
2203
|
-
const files = yield _ZipLoader.unzip(reader, settings);
|
|
2204
|
-
files.settings = settings;
|
|
2205
|
-
context.source = files;
|
|
2206
|
-
if (sourceURL.startsWith("blob:")) {
|
|
2207
|
-
context.live2dModel.once("modelLoaded", (internalModel) => {
|
|
2208
|
-
internalModel.once("destroy", function() {
|
|
2209
|
-
URL.revokeObjectURL(sourceURL);
|
|
2210
|
-
});
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2213
|
-
_ZipLoader.releaseReader(reader);
|
|
2214
|
-
}
|
|
2215
|
-
return next();
|
|
2216
|
-
}));
|
|
2217
|
-
let ZipLoader = _ZipLoader;
|
|
2218
2180
|
const _FileLoader = class _FileLoader {
|
|
2219
2181
|
/**
|
|
2220
2182
|
* Resolves the path of a resource file to the object URL.
|
|
@@ -2495,7 +2457,6 @@ __publicField(_Live2DFactory, "createInternalModel", createInternalModel);
|
|
|
2495
2457
|
* Middlewares to run through when setting up a Live2DModel.
|
|
2496
2458
|
*/
|
|
2497
2459
|
__publicField(_Live2DFactory, "live2DModelMiddlewares", [
|
|
2498
|
-
ZipLoader.factory,
|
|
2499
2460
|
FileLoader.factory,
|
|
2500
2461
|
urlToJSON,
|
|
2501
2462
|
jsonToSettings,
|
|
@@ -2521,7 +2482,6 @@ ExpressionManager.prototype["_loadExpression"] = function(index) {
|
|
|
2521
2482
|
return Live2DFactory.loadExpression(this, index);
|
|
2522
2483
|
};
|
|
2523
2484
|
FileLoader["live2dFactory"] = Live2DFactory;
|
|
2524
|
-
ZipLoader["live2dFactory"] = Live2DFactory;
|
|
2525
2485
|
const _Automator = class _Automator {
|
|
2526
2486
|
constructor(model, {
|
|
2527
2487
|
autoUpdate = true,
|
|
@@ -2675,10 +2635,17 @@ const tempMatrix$1 = new Matrix();
|
|
|
2675
2635
|
const tempWorldMatrix = new Matrix();
|
|
2676
2636
|
const tempDrawableBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
2677
2637
|
const tempModelBounds = new Bounds();
|
|
2638
|
+
let live2DPluginFallbackWarned = false;
|
|
2678
2639
|
class Live2DPipe {
|
|
2679
2640
|
constructor(renderer) {
|
|
2680
2641
|
this.renderer = renderer;
|
|
2681
2642
|
}
|
|
2643
|
+
addRenderable(model, instructionSet) {
|
|
2644
|
+
var _a, _b;
|
|
2645
|
+
const renderPipes = this.renderer.renderPipes;
|
|
2646
|
+
(_b = (_a = renderPipes.batch) == null ? void 0 : _a.break) == null ? void 0 : _b.call(_a, instructionSet);
|
|
2647
|
+
instructionSet.add(model);
|
|
2648
|
+
}
|
|
2682
2649
|
execute(model) {
|
|
2683
2650
|
if (!model.visible || model.alpha <= 0) {
|
|
2684
2651
|
return;
|
|
@@ -2687,15 +2654,86 @@ class Live2DPipe {
|
|
|
2687
2654
|
}
|
|
2688
2655
|
updateRenderable() {
|
|
2689
2656
|
}
|
|
2657
|
+
destroyRenderable() {
|
|
2658
|
+
}
|
|
2659
|
+
validateRenderable() {
|
|
2660
|
+
return false;
|
|
2661
|
+
}
|
|
2690
2662
|
destroy() {
|
|
2691
2663
|
}
|
|
2692
2664
|
}
|
|
2665
|
+
__publicField(Live2DPipe, "extension", {
|
|
2666
|
+
type: [ExtensionType.WebGLPipes],
|
|
2667
|
+
name: "live2d"
|
|
2668
|
+
});
|
|
2669
|
+
const Live2DPlugin = Live2DPipe;
|
|
2693
2670
|
function ensureLive2DPipe(renderer) {
|
|
2694
2671
|
const r = renderer;
|
|
2695
2672
|
if (!r.renderPipes.live2d) {
|
|
2673
|
+
if (!live2DPluginFallbackWarned) {
|
|
2674
|
+
live2DPluginFallbackWarned = true;
|
|
2675
|
+
console.warn(
|
|
2676
|
+
"[untitled-pixi-live2d-engine] Lazy Live2D render pipe registration is deprecated. Register Live2DPlugin explicitly with `extensions.add(Live2DPlugin)` before creating the Pixi renderer."
|
|
2677
|
+
);
|
|
2678
|
+
}
|
|
2696
2679
|
r.renderPipes.live2d = new Live2DPipe(renderer);
|
|
2697
2680
|
}
|
|
2698
2681
|
}
|
|
2682
|
+
function getMatrixMaxScale(matrix) {
|
|
2683
|
+
return Math.max(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d));
|
|
2684
|
+
}
|
|
2685
|
+
function isDrawableTextureResource(resource) {
|
|
2686
|
+
if (!resource || typeof resource !== "object") {
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
const { width, height } = resource;
|
|
2690
|
+
return typeof width === "number" && width > 0 && typeof height === "number" && height > 0;
|
|
2691
|
+
}
|
|
2692
|
+
function createTextureLODTexture(sourceTexture, level, width, height, filter) {
|
|
2693
|
+
var _a, _b;
|
|
2694
|
+
const resource = sourceTexture.source.resource;
|
|
2695
|
+
if (!isDrawableTextureResource(resource)) {
|
|
2696
|
+
return void 0;
|
|
2697
|
+
}
|
|
2698
|
+
const canvas = DOMAdapter.get().createCanvas(width, height);
|
|
2699
|
+
const context = canvas.getContext("2d");
|
|
2700
|
+
if (!context) {
|
|
2701
|
+
return void 0;
|
|
2702
|
+
}
|
|
2703
|
+
try {
|
|
2704
|
+
context.clearRect(0, 0, width, height);
|
|
2705
|
+
context.imageSmoothingEnabled = filter !== "nearest";
|
|
2706
|
+
if ("imageSmoothingQuality" in context && filter !== "nearest") {
|
|
2707
|
+
context.imageSmoothingQuality = "high";
|
|
2708
|
+
}
|
|
2709
|
+
context.drawImage(
|
|
2710
|
+
resource,
|
|
2711
|
+
0,
|
|
2712
|
+
0,
|
|
2713
|
+
sourceTexture.source.pixelWidth,
|
|
2714
|
+
sourceTexture.source.pixelHeight,
|
|
2715
|
+
0,
|
|
2716
|
+
0,
|
|
2717
|
+
width,
|
|
2718
|
+
height
|
|
2719
|
+
);
|
|
2720
|
+
} catch (e) {
|
|
2721
|
+
return void 0;
|
|
2722
|
+
}
|
|
2723
|
+
const label = `${(_b = (_a = sourceTexture.label) != null ? _a : sourceTexture.source.label) != null ? _b : "Live2DTexture"} LOD ${level}`;
|
|
2724
|
+
return new Texture({
|
|
2725
|
+
label,
|
|
2726
|
+
source: new CanvasSource({
|
|
2727
|
+
resource: canvas,
|
|
2728
|
+
width,
|
|
2729
|
+
height,
|
|
2730
|
+
resolution: 1,
|
|
2731
|
+
scaleMode: getTextureLODFilter(filter),
|
|
2732
|
+
autoGenerateMipmaps: false,
|
|
2733
|
+
label
|
|
2734
|
+
})
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2699
2737
|
class Live2DModel extends Container {
|
|
2700
2738
|
/**
|
|
2701
2739
|
* Creates a new Live2DModel instance.
|
|
@@ -2719,6 +2757,9 @@ class Live2DModel extends Container {
|
|
|
2719
2757
|
* @type {Texture[]}
|
|
2720
2758
|
*/
|
|
2721
2759
|
__publicField(this, "textures", []);
|
|
2760
|
+
__publicField(this, "textureOptions");
|
|
2761
|
+
__publicField(this, "textureLODStates", []);
|
|
2762
|
+
__publicField(this, "textureLODFailures", []);
|
|
2722
2763
|
/** @override
|
|
2723
2764
|
* The Live2DTransform instance for this model.
|
|
2724
2765
|
*/
|
|
@@ -2775,15 +2816,25 @@ class Live2DModel extends Container {
|
|
|
2775
2816
|
this.internalModel.updateWebGLContext(renderer.gl, this.generateUID());
|
|
2776
2817
|
shouldUpdateTexture = true;
|
|
2777
2818
|
}
|
|
2819
|
+
const { projectionMatrix, offset, worldTransformMatrix } = renderer.globalUniforms.globalUniformData;
|
|
2820
|
+
const adjustedWorld = tempWorldMatrix.copyFrom(worldTransformMatrix).append(this.groupTransform);
|
|
2821
|
+
const effectiveScale = getMatrixMaxScale(adjustedWorld) * renderer.resolution;
|
|
2778
2822
|
for (let i = 0; i < this.textures.length; i++) {
|
|
2779
|
-
const
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2823
|
+
const originalTexture = this.textures[i];
|
|
2824
|
+
let texture = this.resolveTextureForRender(i, originalTexture, effectiveScale);
|
|
2825
|
+
try {
|
|
2826
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
2827
|
+
} catch (e) {
|
|
2828
|
+
if (texture === originalTexture) {
|
|
2829
|
+
throw new Error("Failed to upload Live2D texture.");
|
|
2830
|
+
}
|
|
2831
|
+
const state = this.textureLODStates[i];
|
|
2832
|
+
if ((state == null ? void 0 : state.texture) === texture) {
|
|
2833
|
+
this.markTextureLODFailure(i, originalTexture, state.level);
|
|
2834
|
+
this.destroyTextureLODState(i);
|
|
2835
|
+
}
|
|
2836
|
+
texture = originalTexture;
|
|
2837
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
2787
2838
|
}
|
|
2788
2839
|
this.internalModel.bindTexture(i, renderer.texture.getGlSource(texture.source).texture);
|
|
2789
2840
|
}
|
|
@@ -2800,8 +2851,6 @@ class Live2DModel extends Container {
|
|
|
2800
2851
|
if (frameDelta) {
|
|
2801
2852
|
this.internalModel.update(frameDelta, this.elapsedTime);
|
|
2802
2853
|
}
|
|
2803
|
-
const { projectionMatrix, offset } = renderer.globalUniforms.globalUniformData;
|
|
2804
|
-
const adjustedWorld = tempWorldMatrix.copyFrom(this.worldTransform);
|
|
2805
2854
|
adjustedWorld.tx -= (_a = offset == null ? void 0 : offset.x) != null ? _a : 0;
|
|
2806
2855
|
adjustedWorld.ty -= (_b = offset == null ? void 0 : offset.y) != null ? _b : 0;
|
|
2807
2856
|
const internalTransform = tempMatrix$1.copyFrom(projectionMatrix).append(adjustedWorld);
|
|
@@ -2824,6 +2873,7 @@ class Live2DModel extends Container {
|
|
|
2824
2873
|
}
|
|
2825
2874
|
}
|
|
2826
2875
|
});
|
|
2876
|
+
this.textureOptions = options == null ? void 0 : options.textureOptions;
|
|
2827
2877
|
this.anchor = new ObservablePoint(
|
|
2828
2878
|
{
|
|
2829
2879
|
_onUpdate: () => this.onAnchorChange()
|
|
@@ -2975,9 +3025,7 @@ class Live2DModel extends Container {
|
|
|
2975
3025
|
ensureLive2DPipe(renderer);
|
|
2976
3026
|
const renderPipes = renderer.renderPipes;
|
|
2977
3027
|
const addRenderable = () => {
|
|
2978
|
-
|
|
2979
|
-
(_b2 = (_a2 = renderPipes.batch) == null ? void 0 : _a2.break) == null ? void 0 : _b2.call(_a2, instructionSet);
|
|
2980
|
-
instructionSet.add(this);
|
|
3028
|
+
renderPipes.live2d.addRenderable(this, instructionSet);
|
|
2981
3029
|
};
|
|
2982
3030
|
const collectChildren = () => {
|
|
2983
3031
|
const children = this.children;
|
|
@@ -3268,6 +3316,75 @@ class Live2DModel extends Container {
|
|
|
3268
3316
|
this.deltaTime += dt;
|
|
3269
3317
|
this.elapsedTime += dt;
|
|
3270
3318
|
}
|
|
3319
|
+
resolveTextureForRender(index, texture, effectiveScale) {
|
|
3320
|
+
var _a;
|
|
3321
|
+
const plan = getTextureLODPlan(__spreadProps(__spreadValues({}, this.textureOptions), {
|
|
3322
|
+
effectiveScale,
|
|
3323
|
+
textureWidth: texture.source.pixelWidth,
|
|
3324
|
+
textureHeight: texture.source.pixelHeight
|
|
3325
|
+
}));
|
|
3326
|
+
if (!plan) {
|
|
3327
|
+
return texture;
|
|
3328
|
+
}
|
|
3329
|
+
const failure = this.textureLODFailures[index];
|
|
3330
|
+
if ((failure == null ? void 0 : failure.source) === texture && failure.levels.has(plan.level)) {
|
|
3331
|
+
return texture;
|
|
3332
|
+
}
|
|
3333
|
+
const existing = this.textureLODStates[index];
|
|
3334
|
+
if ((existing == null ? void 0 : existing.source) === texture && existing.level === plan.level && !existing.texture.destroyed) {
|
|
3335
|
+
return existing.texture;
|
|
3336
|
+
}
|
|
3337
|
+
this.destroyTextureLODState(index);
|
|
3338
|
+
const lodTexture = createTextureLODTexture(
|
|
3339
|
+
texture,
|
|
3340
|
+
plan.level,
|
|
3341
|
+
plan.width,
|
|
3342
|
+
plan.height,
|
|
3343
|
+
(_a = this.textureOptions) == null ? void 0 : _a.lodFilter
|
|
3344
|
+
);
|
|
3345
|
+
if (!lodTexture) {
|
|
3346
|
+
this.markTextureLODFailure(index, texture, plan.level);
|
|
3347
|
+
return texture;
|
|
3348
|
+
}
|
|
3349
|
+
this.textureLODStates[index] = {
|
|
3350
|
+
source: texture,
|
|
3351
|
+
level: plan.level,
|
|
3352
|
+
texture: lodTexture
|
|
3353
|
+
};
|
|
3354
|
+
return lodTexture;
|
|
3355
|
+
}
|
|
3356
|
+
markTextureLODFailure(index, texture, level) {
|
|
3357
|
+
let failure = this.textureLODFailures[index];
|
|
3358
|
+
if ((failure == null ? void 0 : failure.source) !== texture) {
|
|
3359
|
+
failure = { source: texture, levels: /* @__PURE__ */ new Set() };
|
|
3360
|
+
this.textureLODFailures[index] = failure;
|
|
3361
|
+
}
|
|
3362
|
+
failure.levels.add(level);
|
|
3363
|
+
}
|
|
3364
|
+
destroyTextureLODState(index) {
|
|
3365
|
+
const state = this.textureLODStates[index];
|
|
3366
|
+
if (!state) {
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
state.texture.destroy(true);
|
|
3370
|
+
this.textureLODStates[index] = void 0;
|
|
3371
|
+
}
|
|
3372
|
+
destroyTextureLODStates() {
|
|
3373
|
+
for (let i = 0; i < this.textureLODStates.length; i++) {
|
|
3374
|
+
this.destroyTextureLODState(i);
|
|
3375
|
+
}
|
|
3376
|
+
this.textureLODFailures.length = 0;
|
|
3377
|
+
}
|
|
3378
|
+
uploadTextureForRender(renderer, texture, shouldUpdateTexture) {
|
|
3379
|
+
const hasGlSource = Boolean(texture.source._gpuData[renderer.uid]);
|
|
3380
|
+
if (shouldUpdateTexture || !hasGlSource) {
|
|
3381
|
+
renderer.gl.pixelStorei(
|
|
3382
|
+
WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,
|
|
3383
|
+
this.internalModel.textureFlipY
|
|
3384
|
+
);
|
|
3385
|
+
renderer.texture.bind(texture, 0);
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3271
3388
|
/**
|
|
3272
3389
|
* Destroys the model and all related resources. This takes the same options and also
|
|
3273
3390
|
* behaves the same as `PIXI.Container#destroy`.
|
|
@@ -3282,6 +3399,7 @@ class Live2DModel extends Container {
|
|
|
3282
3399
|
*/
|
|
3283
3400
|
destroy(options) {
|
|
3284
3401
|
this.emit("destroy");
|
|
3402
|
+
this.destroyTextureLODStates();
|
|
3285
3403
|
if (options == null ? void 0 : options.texture) {
|
|
3286
3404
|
this.textures.forEach((texture) => texture.destroy(options.baseTexture));
|
|
3287
3405
|
}
|
|
@@ -3647,7 +3765,7 @@ class Live2DEyeBlink {
|
|
|
3647
3765
|
this.rightParam = coreModel.getParamIndex("PARAM_EYE_R_OPEN");
|
|
3648
3766
|
}
|
|
3649
3767
|
setEyeParams(value) {
|
|
3650
|
-
this.eyeParamValue = clamp(value, 0, 1);
|
|
3768
|
+
this.eyeParamValue = clamp$1(value, 0, 1);
|
|
3651
3769
|
this.coreModel.setParamFloat(this.leftParam, this.eyeParamValue);
|
|
3652
3770
|
this.coreModel.setParamFloat(this.rightParam, this.eyeParamValue);
|
|
3653
3771
|
}
|
|
@@ -3737,6 +3855,12 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3737
3855
|
{ breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
|
|
3738
3856
|
options
|
|
3739
3857
|
);
|
|
3858
|
+
if ((options == null ? void 0 : options.useHighPrecisionMask) !== void 0 && options.useHighPrecisionMask !== false) {
|
|
3859
|
+
logger.warn(
|
|
3860
|
+
"CubismLegacyInternalModel",
|
|
3861
|
+
"`useHighPrecisionMask` is only supported by Cubism 3/4/5 models and will be ignored for Cubism 2 models."
|
|
3862
|
+
);
|
|
3863
|
+
}
|
|
3740
3864
|
this.motionManager = new CubismLegacyMotionManager(this);
|
|
3741
3865
|
this.parallelMotionManager = [];
|
|
3742
3866
|
this.eyeBlink = new Live2DEyeBlink(coreModel);
|
|
@@ -3874,7 +3998,7 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3874
3998
|
const max_ = 1;
|
|
3875
3999
|
const min_ = value > 0 ? 0.1 : 0;
|
|
3876
4000
|
value = Math.pow(value, 1.15);
|
|
3877
|
-
value = clamp(value, min_, max_);
|
|
4001
|
+
value = clamp$1(value, min_, max_);
|
|
3878
4002
|
for (let i = 0; i < this.motionManager.lipSyncIds.length; ++i) {
|
|
3879
4003
|
this.coreModel.addToParamFloat(
|
|
3880
4004
|
this.coreModel.getParamIndex(this.motionManager.lipSyncIds[i]),
|
|
@@ -4114,7 +4238,7 @@ class Live2DPose {
|
|
|
4114
4238
|
);
|
|
4115
4239
|
if (visibleIndex >= 0) {
|
|
4116
4240
|
const originalOpacity = model.getPartsOpacity(partsGroup[visibleIndex].partsIndex);
|
|
4117
|
-
visibleOpacity = clamp(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4241
|
+
visibleOpacity = clamp$1(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4118
4242
|
} else {
|
|
4119
4243
|
visibleIndex = 0;
|
|
4120
4244
|
visibleOpacity = 1;
|
|
@@ -12024,6 +12148,12 @@ var Live2DCubismFramework$8;
|
|
|
12024
12148
|
const tempMatrix = new CubismMatrix44();
|
|
12025
12149
|
const DEFAULT_MASKS_PER_RENDER_TEXTURE = 36;
|
|
12026
12150
|
const MASKS_PER_RENDER_TEXTURE = 32;
|
|
12151
|
+
const HIGH_PRECISION_MASK_UNIQUE_MASK_SET_THRESHOLD = 16;
|
|
12152
|
+
const HIGH_PRECISION_MASK_MASKED_DRAWABLE_THRESHOLD = 64;
|
|
12153
|
+
const HIGH_PRECISION_MASK_MAX_MASKS_PER_DRAWABLE_THRESHOLD = 3;
|
|
12154
|
+
const HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD = 4096;
|
|
12155
|
+
const HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD = 0.5;
|
|
12156
|
+
const HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD = 24;
|
|
12027
12157
|
function getRequiredMaskRenderTextureCount(model) {
|
|
12028
12158
|
var _a;
|
|
12029
12159
|
if (!model.isUsingMasking()) {
|
|
@@ -12046,6 +12176,51 @@ function getRequiredMaskRenderTextureCount(model) {
|
|
|
12046
12176
|
}
|
|
12047
12177
|
return Math.ceil(clippingContextCount / MASKS_PER_RENDER_TEXTURE);
|
|
12048
12178
|
}
|
|
12179
|
+
function getMaskProfile(model) {
|
|
12180
|
+
var _a, _b;
|
|
12181
|
+
const maskCounts = model.getDrawableMaskCounts();
|
|
12182
|
+
const masks = model.getDrawableMasks();
|
|
12183
|
+
const uniqueMaskSets = /* @__PURE__ */ new Set();
|
|
12184
|
+
const drawableCount = model.getDrawableCount();
|
|
12185
|
+
let maskedDrawableCount = 0;
|
|
12186
|
+
let maxMasksPerDrawable = 0;
|
|
12187
|
+
let maskedVertexCount = 0;
|
|
12188
|
+
let totalVertexCount = 0;
|
|
12189
|
+
for (let i = 0; i < drawableCount; i++) {
|
|
12190
|
+
const vertexCount = model.getDrawableVertexCount(i);
|
|
12191
|
+
const maskCount = (_a = maskCounts[i]) != null ? _a : 0;
|
|
12192
|
+
totalVertexCount += vertexCount;
|
|
12193
|
+
if (maskCount <= 0) {
|
|
12194
|
+
continue;
|
|
12195
|
+
}
|
|
12196
|
+
maskedDrawableCount++;
|
|
12197
|
+
maskedVertexCount += vertexCount;
|
|
12198
|
+
maxMasksPerDrawable = Math.max(maxMasksPerDrawable, maskCount);
|
|
12199
|
+
const maskSet = Array.from((_b = masks[i]) != null ? _b : []).slice(0, maskCount).sort((a, b) => a - b).join(",");
|
|
12200
|
+
uniqueMaskSets.add(maskSet);
|
|
12201
|
+
}
|
|
12202
|
+
return {
|
|
12203
|
+
maskedDrawableCount,
|
|
12204
|
+
uniqueMaskSetCount: uniqueMaskSets.size,
|
|
12205
|
+
maxMasksPerDrawable,
|
|
12206
|
+
maskedVertexCount,
|
|
12207
|
+
totalVertexCount
|
|
12208
|
+
};
|
|
12209
|
+
}
|
|
12210
|
+
function shouldUseHighPrecisionMask(model) {
|
|
12211
|
+
if (!model.isUsingMasking()) {
|
|
12212
|
+
return false;
|
|
12213
|
+
}
|
|
12214
|
+
const profile = getMaskProfile(model);
|
|
12215
|
+
const maskedVertexRatio = profile.totalVertexCount > 0 ? profile.maskedVertexCount / profile.totalVertexCount : 0;
|
|
12216
|
+
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;
|
|
12217
|
+
}
|
|
12218
|
+
function resolveHighPrecisionMaskOption(model, option) {
|
|
12219
|
+
if (typeof option === "boolean") {
|
|
12220
|
+
return option;
|
|
12221
|
+
}
|
|
12222
|
+
return shouldUseHighPrecisionMask(model);
|
|
12223
|
+
}
|
|
12049
12224
|
class CubismInternalModel extends InternalModel {
|
|
12050
12225
|
constructor(coreModel, settings, options) {
|
|
12051
12226
|
super();
|
|
@@ -12146,6 +12321,9 @@ class CubismInternalModel extends InternalModel {
|
|
|
12146
12321
|
breathParams.pushBack(new BreathParameterData(this.idParamBreath, 0, 0.5, 3.2345, 0.5));
|
|
12147
12322
|
this.breath.setParameters(breathParams);
|
|
12148
12323
|
this.renderer.initialize(this.coreModel, getRequiredMaskRenderTextureCount(this.coreModel));
|
|
12324
|
+
this.renderer.useHighPrecisionMask(
|
|
12325
|
+
resolveHighPrecisionMaskOption(this.coreModel, this.options.useHighPrecisionMask)
|
|
12326
|
+
);
|
|
12149
12327
|
this.renderer.setIsPremultipliedAlpha(true);
|
|
12150
12328
|
}
|
|
12151
12329
|
getIdSafe(id) {
|
|
@@ -12244,7 +12422,7 @@ class CubismInternalModel extends InternalModel {
|
|
|
12244
12422
|
value = Math.pow(value, 1.15);
|
|
12245
12423
|
const min_ = value > 0 ? 0.1 : 0;
|
|
12246
12424
|
const max_ = 1;
|
|
12247
|
-
value = clamp(value, min_, max_);
|
|
12425
|
+
value = clamp$1(value, min_, max_);
|
|
12248
12426
|
this.motionManager.lipSyncIds.forEach((lipSyncId) => {
|
|
12249
12427
|
model.addParameterValueById(this.getIdSafe(lipSyncId), value, this.options.lipSyncWeight);
|
|
12250
12428
|
});
|
|
@@ -16505,6 +16683,7 @@ export {
|
|
|
16505
16683
|
Live2DLoader,
|
|
16506
16684
|
Live2DModel,
|
|
16507
16685
|
Live2DPhysics,
|
|
16686
|
+
Live2DPlugin,
|
|
16508
16687
|
Live2DPose,
|
|
16509
16688
|
Live2DTransform,
|
|
16510
16689
|
MBToByte,
|
|
@@ -16517,9 +16696,8 @@ export {
|
|
|
16517
16696
|
VERSION,
|
|
16518
16697
|
VOLUME,
|
|
16519
16698
|
XHRLoader,
|
|
16520
|
-
ZipLoader,
|
|
16521
16699
|
applyMixins,
|
|
16522
|
-
clamp,
|
|
16700
|
+
clamp$1 as clamp,
|
|
16523
16701
|
config,
|
|
16524
16702
|
configureCubismSDK,
|
|
16525
16703
|
copyArray,
|