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-legacy.js
CHANGED
|
@@ -2,8 +2,25 @@
|
|
|
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;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
10
|
var __pow = Math.pow;
|
|
6
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
25
|
var __async = (__this, __arguments, generator) => {
|
|
9
26
|
return new Promise((resolve, reject) => {
|
|
@@ -91,7 +108,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
91
108
|
preserveExpressionOnMotion: true,
|
|
92
109
|
cubism: CubismFrameworkConfig
|
|
93
110
|
};
|
|
94
|
-
const VERSION = "1.0
|
|
111
|
+
const VERSION = "1.2.0";
|
|
95
112
|
const logger = {
|
|
96
113
|
log(tag, ...messages) {
|
|
97
114
|
if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
|
|
@@ -109,7 +126,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
};
|
|
112
|
-
function clamp(num, lower, upper) {
|
|
129
|
+
function clamp$1(num, lower, upper) {
|
|
113
130
|
return num < lower ? lower : num > upper ? upper : num;
|
|
114
131
|
}
|
|
115
132
|
function rand(min, max) {
|
|
@@ -384,8 +401,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
384
401
|
* @param instant - Should the focus position be instantly applied.
|
|
385
402
|
*/
|
|
386
403
|
focus(x, y, instant = false) {
|
|
387
|
-
this.targetX = clamp(x, -1, 1);
|
|
388
|
-
this.targetY = clamp(y, -1, 1);
|
|
404
|
+
this.targetX = clamp$1(x, -1, 1);
|
|
405
|
+
this.targetY = clamp$1(y, -1, 1);
|
|
389
406
|
if (instant) {
|
|
390
407
|
this.x = this.targetX;
|
|
391
408
|
this.y = this.targetY;
|
|
@@ -1902,6 +1919,68 @@ var __async = (__this, __arguments, generator) => {
|
|
|
1902
1919
|
}
|
|
1903
1920
|
}
|
|
1904
1921
|
}
|
|
1922
|
+
const DEFAULT_LOD_SCALE_THRESHOLD = 0.5;
|
|
1923
|
+
const DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD = 4096;
|
|
1924
|
+
function getTextureLODPlan({
|
|
1925
|
+
lod,
|
|
1926
|
+
effectiveScale,
|
|
1927
|
+
textureWidth,
|
|
1928
|
+
textureHeight,
|
|
1929
|
+
lodScaleThreshold,
|
|
1930
|
+
lodTextureSizeThreshold,
|
|
1931
|
+
lodMaxLevel
|
|
1932
|
+
}) {
|
|
1933
|
+
if (getTextureLODMode(lod) !== "single-auto") {
|
|
1934
|
+
return void 0;
|
|
1935
|
+
}
|
|
1936
|
+
if (!Number.isFinite(effectiveScale) || effectiveScale <= 0) {
|
|
1937
|
+
return void 0;
|
|
1938
|
+
}
|
|
1939
|
+
const width = Math.floor(textureWidth);
|
|
1940
|
+
const height = Math.floor(textureHeight);
|
|
1941
|
+
if (width <= 1 || height <= 1) {
|
|
1942
|
+
return void 0;
|
|
1943
|
+
}
|
|
1944
|
+
const scaleThreshold = validPositive(lodScaleThreshold, DEFAULT_LOD_SCALE_THRESHOLD);
|
|
1945
|
+
if (effectiveScale >= scaleThreshold) {
|
|
1946
|
+
return void 0;
|
|
1947
|
+
}
|
|
1948
|
+
const textureSizeThreshold = validPositive(
|
|
1949
|
+
lodTextureSizeThreshold,
|
|
1950
|
+
DEFAULT_LOD_TEXTURE_SIZE_THRESHOLD
|
|
1951
|
+
);
|
|
1952
|
+
if (Math.max(width, height) < textureSizeThreshold) {
|
|
1953
|
+
return void 0;
|
|
1954
|
+
}
|
|
1955
|
+
const rawLevel = Math.round(Math.log2(1 / effectiveScale));
|
|
1956
|
+
const maxDimensionLevel = Math.max(1, Math.floor(Math.log2(Math.max(width, height))));
|
|
1957
|
+
const maxLevel = Math.min(maxDimensionLevel, validMaxLevel(lodMaxLevel, maxDimensionLevel));
|
|
1958
|
+
const level = clamp(Math.max(1, rawLevel), 1, maxLevel);
|
|
1959
|
+
const factor = __pow(2, level);
|
|
1960
|
+
return {
|
|
1961
|
+
level,
|
|
1962
|
+
width: Math.max(1, Math.round(width / factor)),
|
|
1963
|
+
height: Math.max(1, Math.round(height / factor))
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
function getTextureLODMode(lod) {
|
|
1967
|
+
if (lod === false || lod === "single-auto") {
|
|
1968
|
+
return lod;
|
|
1969
|
+
}
|
|
1970
|
+
return "full";
|
|
1971
|
+
}
|
|
1972
|
+
function getTextureLODFilter(filter) {
|
|
1973
|
+
return filter === "nearest" ? "nearest" : "linear";
|
|
1974
|
+
}
|
|
1975
|
+
function validPositive(value, fallback) {
|
|
1976
|
+
return value !== void 0 && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
1977
|
+
}
|
|
1978
|
+
function validMaxLevel(value, fallback) {
|
|
1979
|
+
return value !== void 0 && Number.isFinite(value) && value >= 1 ? Math.floor(value) : fallback;
|
|
1980
|
+
}
|
|
1981
|
+
function clamp(value, min, max) {
|
|
1982
|
+
return Math.min(max, Math.max(min, value));
|
|
1983
|
+
}
|
|
1905
1984
|
function createTexture(url, options = {}) {
|
|
1906
1985
|
const config2 = pixi_js.loadTextures.config;
|
|
1907
1986
|
const previousCrossOrigin = config2 == null ? void 0 : config2.crossOrigin;
|
|
@@ -1914,7 +1993,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
1914
1993
|
config2.preferCreateImageBitmap = false;
|
|
1915
1994
|
config2.preferWorkers = false;
|
|
1916
1995
|
}
|
|
1917
|
-
return pixi_js.Assets.load(
|
|
1996
|
+
return pixi_js.Assets.load({
|
|
1997
|
+
src: url,
|
|
1998
|
+
data: {
|
|
1999
|
+
autoGenerateMipmaps: getTextureLODMode(options.lod) === "full"
|
|
2000
|
+
}
|
|
2001
|
+
}).catch((error) => {
|
|
1918
2002
|
if (error instanceof Error) {
|
|
1919
2003
|
throw error;
|
|
1920
2004
|
}
|
|
@@ -2047,9 +2131,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2047
2131
|
const setupEssentials = (context, next) => __async(null, null, function* () {
|
|
2048
2132
|
if (context.settings) {
|
|
2049
2133
|
const live2DModel = context.live2dModel;
|
|
2050
|
-
const textureOptions = {
|
|
2134
|
+
const textureOptions = __spreadValues({
|
|
2051
2135
|
crossOrigin: context.options.crossOrigin
|
|
2052
|
-
};
|
|
2136
|
+
}, context.options.textureOptions);
|
|
2053
2137
|
if (context.settings instanceof CubismLegacyModelSettings) {
|
|
2054
2138
|
textureOptions.preferCreateImageBitmap = false;
|
|
2055
2139
|
}
|
|
@@ -2095,114 +2179,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2095
2179
|
}
|
|
2096
2180
|
throw new TypeError("Missing settings.");
|
|
2097
2181
|
});
|
|
2098
|
-
const _ZipLoader = class _ZipLoader {
|
|
2099
|
-
static unzip(reader, settings) {
|
|
2100
|
-
return __async(this, null, function* () {
|
|
2101
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2102
|
-
const requiredFilePaths = [];
|
|
2103
|
-
for (const definedFile of settings.getDefinedFiles()) {
|
|
2104
|
-
const actualPath = decodeURI(resolveURL(settings.url, definedFile));
|
|
2105
|
-
if (filePaths.includes(actualPath)) {
|
|
2106
|
-
requiredFilePaths.push(actualPath);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
const files = yield _ZipLoader.getFiles(reader, requiredFilePaths);
|
|
2110
|
-
for (let i = 0; i < files.length; i++) {
|
|
2111
|
-
const path = requiredFilePaths[i];
|
|
2112
|
-
const file = files[i];
|
|
2113
|
-
Object.defineProperty(file, "webkitRelativePath", {
|
|
2114
|
-
value: path
|
|
2115
|
-
});
|
|
2116
|
-
}
|
|
2117
|
-
return files;
|
|
2118
|
-
});
|
|
2119
|
-
}
|
|
2120
|
-
static createSettings(reader) {
|
|
2121
|
-
return __async(this, null, function* () {
|
|
2122
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2123
|
-
const settingsFilePath = filePaths.find(
|
|
2124
|
-
(path) => path.endsWith("model.json") || path.endsWith("model3.json")
|
|
2125
|
-
);
|
|
2126
|
-
if (!settingsFilePath) {
|
|
2127
|
-
throw new Error("Settings file not found");
|
|
2128
|
-
}
|
|
2129
|
-
const settingsText = yield _ZipLoader.readText(reader, settingsFilePath);
|
|
2130
|
-
if (!settingsText) {
|
|
2131
|
-
throw new Error("Empty settings file: " + settingsFilePath);
|
|
2132
|
-
}
|
|
2133
|
-
const settingsJSON = JSON.parse(settingsText);
|
|
2134
|
-
settingsJSON.url = settingsFilePath;
|
|
2135
|
-
const runtime = _ZipLoader.live2dFactory.findRuntime(settingsJSON);
|
|
2136
|
-
if (!runtime) {
|
|
2137
|
-
throw new Error("Unknown settings JSON");
|
|
2138
|
-
}
|
|
2139
|
-
return runtime.createModelSettings(settingsJSON);
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
static zipReader(data, url) {
|
|
2143
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2144
|
-
}
|
|
2145
|
-
static getFilePaths(reader) {
|
|
2146
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2147
|
-
}
|
|
2148
|
-
static getFiles(reader, paths) {
|
|
2149
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2150
|
-
}
|
|
2151
|
-
static readText(reader, path) {
|
|
2152
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2153
|
-
}
|
|
2154
|
-
static releaseReader(reader) {
|
|
2155
|
-
}
|
|
2156
|
-
};
|
|
2157
|
-
// will be set by Live2DFactory
|
|
2158
|
-
__publicField(_ZipLoader, "live2dFactory");
|
|
2159
|
-
__publicField(_ZipLoader, "ZIP_PROTOCOL", "zip://");
|
|
2160
|
-
__publicField(_ZipLoader, "uid", 0);
|
|
2161
|
-
__publicField(_ZipLoader, "factory", (context, next) => __async(null, null, function* () {
|
|
2162
|
-
const source = context.source;
|
|
2163
|
-
let sourceURL;
|
|
2164
|
-
let zipBlob;
|
|
2165
|
-
let settings;
|
|
2166
|
-
if (typeof source === "string" && (source.endsWith(".zip") || source.startsWith(_ZipLoader.ZIP_PROTOCOL))) {
|
|
2167
|
-
if (source.startsWith(_ZipLoader.ZIP_PROTOCOL)) {
|
|
2168
|
-
sourceURL = source.slice(_ZipLoader.ZIP_PROTOCOL.length);
|
|
2169
|
-
} else {
|
|
2170
|
-
sourceURL = source;
|
|
2171
|
-
}
|
|
2172
|
-
zipBlob = yield Live2DLoader.load({
|
|
2173
|
-
url: sourceURL,
|
|
2174
|
-
type: "blob",
|
|
2175
|
-
target: context.live2dModel
|
|
2176
|
-
});
|
|
2177
|
-
} else if (Array.isArray(source) && source.length === 1 && source[0] instanceof File && source[0].name.endsWith(".zip")) {
|
|
2178
|
-
zipBlob = source[0];
|
|
2179
|
-
sourceURL = URL.createObjectURL(zipBlob);
|
|
2180
|
-
settings = source.settings;
|
|
2181
|
-
}
|
|
2182
|
-
if (zipBlob) {
|
|
2183
|
-
if (!zipBlob.size) {
|
|
2184
|
-
throw new Error("Empty zip file");
|
|
2185
|
-
}
|
|
2186
|
-
const reader = yield _ZipLoader.zipReader(zipBlob, sourceURL);
|
|
2187
|
-
if (!settings) {
|
|
2188
|
-
settings = yield _ZipLoader.createSettings(reader);
|
|
2189
|
-
}
|
|
2190
|
-
settings._objectURL = _ZipLoader.ZIP_PROTOCOL + _ZipLoader.uid + "/" + settings.url;
|
|
2191
|
-
const files = yield _ZipLoader.unzip(reader, settings);
|
|
2192
|
-
files.settings = settings;
|
|
2193
|
-
context.source = files;
|
|
2194
|
-
if (sourceURL.startsWith("blob:")) {
|
|
2195
|
-
context.live2dModel.once("modelLoaded", (internalModel) => {
|
|
2196
|
-
internalModel.once("destroy", function() {
|
|
2197
|
-
URL.revokeObjectURL(sourceURL);
|
|
2198
|
-
});
|
|
2199
|
-
});
|
|
2200
|
-
}
|
|
2201
|
-
_ZipLoader.releaseReader(reader);
|
|
2202
|
-
}
|
|
2203
|
-
return next();
|
|
2204
|
-
}));
|
|
2205
|
-
let ZipLoader = _ZipLoader;
|
|
2206
2182
|
const _FileLoader = class _FileLoader {
|
|
2207
2183
|
/**
|
|
2208
2184
|
* Resolves the path of a resource file to the object URL.
|
|
@@ -2483,7 +2459,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2483
2459
|
* Middlewares to run through when setting up a Live2DModel.
|
|
2484
2460
|
*/
|
|
2485
2461
|
__publicField(_Live2DFactory, "live2DModelMiddlewares", [
|
|
2486
|
-
ZipLoader.factory,
|
|
2487
2462
|
FileLoader.factory,
|
|
2488
2463
|
urlToJSON,
|
|
2489
2464
|
jsonToSettings,
|
|
@@ -2509,7 +2484,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2509
2484
|
return Live2DFactory.loadExpression(this, index);
|
|
2510
2485
|
};
|
|
2511
2486
|
FileLoader["live2dFactory"] = Live2DFactory;
|
|
2512
|
-
ZipLoader["live2dFactory"] = Live2DFactory;
|
|
2513
2487
|
const _Automator = class _Automator {
|
|
2514
2488
|
constructor(model, {
|
|
2515
2489
|
autoUpdate = true,
|
|
@@ -2663,10 +2637,17 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2663
2637
|
const tempWorldMatrix = new pixi_js.Matrix();
|
|
2664
2638
|
const tempDrawableBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
2665
2639
|
const tempModelBounds = new pixi_js.Bounds();
|
|
2640
|
+
let live2DPluginFallbackWarned = false;
|
|
2666
2641
|
class Live2DPipe {
|
|
2667
2642
|
constructor(renderer) {
|
|
2668
2643
|
this.renderer = renderer;
|
|
2669
2644
|
}
|
|
2645
|
+
addRenderable(model, instructionSet) {
|
|
2646
|
+
var _a, _b;
|
|
2647
|
+
const renderPipes = this.renderer.renderPipes;
|
|
2648
|
+
(_b = (_a = renderPipes.batch) == null ? void 0 : _a.break) == null ? void 0 : _b.call(_a, instructionSet);
|
|
2649
|
+
instructionSet.add(model);
|
|
2650
|
+
}
|
|
2670
2651
|
execute(model) {
|
|
2671
2652
|
if (!model.visible || model.alpha <= 0) {
|
|
2672
2653
|
return;
|
|
@@ -2675,15 +2656,86 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2675
2656
|
}
|
|
2676
2657
|
updateRenderable() {
|
|
2677
2658
|
}
|
|
2659
|
+
destroyRenderable() {
|
|
2660
|
+
}
|
|
2661
|
+
validateRenderable() {
|
|
2662
|
+
return false;
|
|
2663
|
+
}
|
|
2678
2664
|
destroy() {
|
|
2679
2665
|
}
|
|
2680
2666
|
}
|
|
2667
|
+
__publicField(Live2DPipe, "extension", {
|
|
2668
|
+
type: [pixi_js.ExtensionType.WebGLPipes],
|
|
2669
|
+
name: "live2d"
|
|
2670
|
+
});
|
|
2671
|
+
const Live2DPlugin = Live2DPipe;
|
|
2681
2672
|
function ensureLive2DPipe(renderer) {
|
|
2682
2673
|
const r = renderer;
|
|
2683
2674
|
if (!r.renderPipes.live2d) {
|
|
2675
|
+
if (!live2DPluginFallbackWarned) {
|
|
2676
|
+
live2DPluginFallbackWarned = true;
|
|
2677
|
+
console.warn(
|
|
2678
|
+
"[untitled-pixi-live2d-engine] Lazy Live2D render pipe registration is deprecated. Register Live2DPlugin explicitly with `extensions.add(Live2DPlugin)` before creating the Pixi renderer."
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2684
2681
|
r.renderPipes.live2d = new Live2DPipe(renderer);
|
|
2685
2682
|
}
|
|
2686
2683
|
}
|
|
2684
|
+
function getMatrixMaxScale(matrix) {
|
|
2685
|
+
return Math.max(Math.hypot(matrix.a, matrix.b), Math.hypot(matrix.c, matrix.d));
|
|
2686
|
+
}
|
|
2687
|
+
function isDrawableTextureResource(resource) {
|
|
2688
|
+
if (!resource || typeof resource !== "object") {
|
|
2689
|
+
return false;
|
|
2690
|
+
}
|
|
2691
|
+
const { width, height } = resource;
|
|
2692
|
+
return typeof width === "number" && width > 0 && typeof height === "number" && height > 0;
|
|
2693
|
+
}
|
|
2694
|
+
function createTextureLODTexture(sourceTexture, level, width, height, filter) {
|
|
2695
|
+
var _a, _b;
|
|
2696
|
+
const resource = sourceTexture.source.resource;
|
|
2697
|
+
if (!isDrawableTextureResource(resource)) {
|
|
2698
|
+
return void 0;
|
|
2699
|
+
}
|
|
2700
|
+
const canvas = pixi_js.DOMAdapter.get().createCanvas(width, height);
|
|
2701
|
+
const context = canvas.getContext("2d");
|
|
2702
|
+
if (!context) {
|
|
2703
|
+
return void 0;
|
|
2704
|
+
}
|
|
2705
|
+
try {
|
|
2706
|
+
context.clearRect(0, 0, width, height);
|
|
2707
|
+
context.imageSmoothingEnabled = filter !== "nearest";
|
|
2708
|
+
if ("imageSmoothingQuality" in context && filter !== "nearest") {
|
|
2709
|
+
context.imageSmoothingQuality = "high";
|
|
2710
|
+
}
|
|
2711
|
+
context.drawImage(
|
|
2712
|
+
resource,
|
|
2713
|
+
0,
|
|
2714
|
+
0,
|
|
2715
|
+
sourceTexture.source.pixelWidth,
|
|
2716
|
+
sourceTexture.source.pixelHeight,
|
|
2717
|
+
0,
|
|
2718
|
+
0,
|
|
2719
|
+
width,
|
|
2720
|
+
height
|
|
2721
|
+
);
|
|
2722
|
+
} catch (e) {
|
|
2723
|
+
return void 0;
|
|
2724
|
+
}
|
|
2725
|
+
const label = `${(_b = (_a = sourceTexture.label) != null ? _a : sourceTexture.source.label) != null ? _b : "Live2DTexture"} LOD ${level}`;
|
|
2726
|
+
return new pixi_js.Texture({
|
|
2727
|
+
label,
|
|
2728
|
+
source: new pixi_js.CanvasSource({
|
|
2729
|
+
resource: canvas,
|
|
2730
|
+
width,
|
|
2731
|
+
height,
|
|
2732
|
+
resolution: 1,
|
|
2733
|
+
scaleMode: getTextureLODFilter(filter),
|
|
2734
|
+
autoGenerateMipmaps: false,
|
|
2735
|
+
label
|
|
2736
|
+
})
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2687
2739
|
class Live2DModel extends pixi_js.Container {
|
|
2688
2740
|
/**
|
|
2689
2741
|
* Creates a new Live2DModel instance.
|
|
@@ -2707,6 +2759,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2707
2759
|
* @type {Texture[]}
|
|
2708
2760
|
*/
|
|
2709
2761
|
__publicField(this, "textures", []);
|
|
2762
|
+
__publicField(this, "textureOptions");
|
|
2763
|
+
__publicField(this, "textureLODStates", []);
|
|
2764
|
+
__publicField(this, "textureLODFailures", []);
|
|
2710
2765
|
/** @override
|
|
2711
2766
|
* The Live2DTransform instance for this model.
|
|
2712
2767
|
*/
|
|
@@ -2763,15 +2818,25 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2763
2818
|
this.internalModel.updateWebGLContext(renderer.gl, this.generateUID());
|
|
2764
2819
|
shouldUpdateTexture = true;
|
|
2765
2820
|
}
|
|
2821
|
+
const { projectionMatrix, offset, worldTransformMatrix } = renderer.globalUniforms.globalUniformData;
|
|
2822
|
+
const adjustedWorld = tempWorldMatrix.copyFrom(worldTransformMatrix).append(this.groupTransform);
|
|
2823
|
+
const effectiveScale = getMatrixMaxScale(adjustedWorld) * renderer.resolution;
|
|
2766
2824
|
for (let i = 0; i < this.textures.length; i++) {
|
|
2767
|
-
const
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2825
|
+
const originalTexture = this.textures[i];
|
|
2826
|
+
let texture = this.resolveTextureForRender(i, originalTexture, effectiveScale);
|
|
2827
|
+
try {
|
|
2828
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
2829
|
+
} catch (e) {
|
|
2830
|
+
if (texture === originalTexture) {
|
|
2831
|
+
throw new Error("Failed to upload Live2D texture.");
|
|
2832
|
+
}
|
|
2833
|
+
const state = this.textureLODStates[i];
|
|
2834
|
+
if ((state == null ? void 0 : state.texture) === texture) {
|
|
2835
|
+
this.markTextureLODFailure(i, originalTexture, state.level);
|
|
2836
|
+
this.destroyTextureLODState(i);
|
|
2837
|
+
}
|
|
2838
|
+
texture = originalTexture;
|
|
2839
|
+
this.uploadTextureForRender(renderer, texture, shouldUpdateTexture);
|
|
2775
2840
|
}
|
|
2776
2841
|
this.internalModel.bindTexture(i, renderer.texture.getGlSource(texture.source).texture);
|
|
2777
2842
|
}
|
|
@@ -2788,8 +2853,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2788
2853
|
if (frameDelta) {
|
|
2789
2854
|
this.internalModel.update(frameDelta, this.elapsedTime);
|
|
2790
2855
|
}
|
|
2791
|
-
const { projectionMatrix, offset } = renderer.globalUniforms.globalUniformData;
|
|
2792
|
-
const adjustedWorld = tempWorldMatrix.copyFrom(this.worldTransform);
|
|
2793
2856
|
adjustedWorld.tx -= (_a = offset == null ? void 0 : offset.x) != null ? _a : 0;
|
|
2794
2857
|
adjustedWorld.ty -= (_b = offset == null ? void 0 : offset.y) != null ? _b : 0;
|
|
2795
2858
|
const internalTransform = tempMatrix.copyFrom(projectionMatrix).append(adjustedWorld);
|
|
@@ -2812,6 +2875,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2812
2875
|
}
|
|
2813
2876
|
}
|
|
2814
2877
|
});
|
|
2878
|
+
this.textureOptions = options == null ? void 0 : options.textureOptions;
|
|
2815
2879
|
this.anchor = new pixi_js.ObservablePoint(
|
|
2816
2880
|
{
|
|
2817
2881
|
_onUpdate: () => this.onAnchorChange()
|
|
@@ -2963,9 +3027,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
2963
3027
|
ensureLive2DPipe(renderer);
|
|
2964
3028
|
const renderPipes = renderer.renderPipes;
|
|
2965
3029
|
const addRenderable = () => {
|
|
2966
|
-
|
|
2967
|
-
(_b2 = (_a2 = renderPipes.batch) == null ? void 0 : _a2.break) == null ? void 0 : _b2.call(_a2, instructionSet);
|
|
2968
|
-
instructionSet.add(this);
|
|
3030
|
+
renderPipes.live2d.addRenderable(this, instructionSet);
|
|
2969
3031
|
};
|
|
2970
3032
|
const collectChildren = () => {
|
|
2971
3033
|
const children = this.children;
|
|
@@ -3256,6 +3318,75 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3256
3318
|
this.deltaTime += dt;
|
|
3257
3319
|
this.elapsedTime += dt;
|
|
3258
3320
|
}
|
|
3321
|
+
resolveTextureForRender(index, texture, effectiveScale) {
|
|
3322
|
+
var _a;
|
|
3323
|
+
const plan = getTextureLODPlan(__spreadProps(__spreadValues({}, this.textureOptions), {
|
|
3324
|
+
effectiveScale,
|
|
3325
|
+
textureWidth: texture.source.pixelWidth,
|
|
3326
|
+
textureHeight: texture.source.pixelHeight
|
|
3327
|
+
}));
|
|
3328
|
+
if (!plan) {
|
|
3329
|
+
return texture;
|
|
3330
|
+
}
|
|
3331
|
+
const failure = this.textureLODFailures[index];
|
|
3332
|
+
if ((failure == null ? void 0 : failure.source) === texture && failure.levels.has(plan.level)) {
|
|
3333
|
+
return texture;
|
|
3334
|
+
}
|
|
3335
|
+
const existing = this.textureLODStates[index];
|
|
3336
|
+
if ((existing == null ? void 0 : existing.source) === texture && existing.level === plan.level && !existing.texture.destroyed) {
|
|
3337
|
+
return existing.texture;
|
|
3338
|
+
}
|
|
3339
|
+
this.destroyTextureLODState(index);
|
|
3340
|
+
const lodTexture = createTextureLODTexture(
|
|
3341
|
+
texture,
|
|
3342
|
+
plan.level,
|
|
3343
|
+
plan.width,
|
|
3344
|
+
plan.height,
|
|
3345
|
+
(_a = this.textureOptions) == null ? void 0 : _a.lodFilter
|
|
3346
|
+
);
|
|
3347
|
+
if (!lodTexture) {
|
|
3348
|
+
this.markTextureLODFailure(index, texture, plan.level);
|
|
3349
|
+
return texture;
|
|
3350
|
+
}
|
|
3351
|
+
this.textureLODStates[index] = {
|
|
3352
|
+
source: texture,
|
|
3353
|
+
level: plan.level,
|
|
3354
|
+
texture: lodTexture
|
|
3355
|
+
};
|
|
3356
|
+
return lodTexture;
|
|
3357
|
+
}
|
|
3358
|
+
markTextureLODFailure(index, texture, level) {
|
|
3359
|
+
let failure = this.textureLODFailures[index];
|
|
3360
|
+
if ((failure == null ? void 0 : failure.source) !== texture) {
|
|
3361
|
+
failure = { source: texture, levels: /* @__PURE__ */ new Set() };
|
|
3362
|
+
this.textureLODFailures[index] = failure;
|
|
3363
|
+
}
|
|
3364
|
+
failure.levels.add(level);
|
|
3365
|
+
}
|
|
3366
|
+
destroyTextureLODState(index) {
|
|
3367
|
+
const state = this.textureLODStates[index];
|
|
3368
|
+
if (!state) {
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
state.texture.destroy(true);
|
|
3372
|
+
this.textureLODStates[index] = void 0;
|
|
3373
|
+
}
|
|
3374
|
+
destroyTextureLODStates() {
|
|
3375
|
+
for (let i = 0; i < this.textureLODStates.length; i++) {
|
|
3376
|
+
this.destroyTextureLODState(i);
|
|
3377
|
+
}
|
|
3378
|
+
this.textureLODFailures.length = 0;
|
|
3379
|
+
}
|
|
3380
|
+
uploadTextureForRender(renderer, texture, shouldUpdateTexture) {
|
|
3381
|
+
const hasGlSource = Boolean(texture.source._gpuData[renderer.uid]);
|
|
3382
|
+
if (shouldUpdateTexture || !hasGlSource) {
|
|
3383
|
+
renderer.gl.pixelStorei(
|
|
3384
|
+
WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL,
|
|
3385
|
+
this.internalModel.textureFlipY
|
|
3386
|
+
);
|
|
3387
|
+
renderer.texture.bind(texture, 0);
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3259
3390
|
/**
|
|
3260
3391
|
* Destroys the model and all related resources. This takes the same options and also
|
|
3261
3392
|
* behaves the same as `PIXI.Container#destroy`.
|
|
@@ -3270,6 +3401,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3270
3401
|
*/
|
|
3271
3402
|
destroy(options) {
|
|
3272
3403
|
this.emit("destroy");
|
|
3404
|
+
this.destroyTextureLODStates();
|
|
3273
3405
|
if (options == null ? void 0 : options.texture) {
|
|
3274
3406
|
this.textures.forEach((texture) => texture.destroy(options.baseTexture));
|
|
3275
3407
|
}
|
|
@@ -3635,7 +3767,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3635
3767
|
this.rightParam = coreModel.getParamIndex("PARAM_EYE_R_OPEN");
|
|
3636
3768
|
}
|
|
3637
3769
|
setEyeParams(value) {
|
|
3638
|
-
this.eyeParamValue = clamp(value, 0, 1);
|
|
3770
|
+
this.eyeParamValue = clamp$1(value, 0, 1);
|
|
3639
3771
|
this.coreModel.setParamFloat(this.leftParam, this.eyeParamValue);
|
|
3640
3772
|
this.coreModel.setParamFloat(this.rightParam, this.eyeParamValue);
|
|
3641
3773
|
}
|
|
@@ -3725,6 +3857,12 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3725
3857
|
{ breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
|
|
3726
3858
|
options
|
|
3727
3859
|
);
|
|
3860
|
+
if ((options == null ? void 0 : options.useHighPrecisionMask) !== void 0 && options.useHighPrecisionMask !== false) {
|
|
3861
|
+
logger.warn(
|
|
3862
|
+
"CubismLegacyInternalModel",
|
|
3863
|
+
"`useHighPrecisionMask` is only supported by Cubism 3/4/5 models and will be ignored for Cubism 2 models."
|
|
3864
|
+
);
|
|
3865
|
+
}
|
|
3728
3866
|
this.motionManager = new CubismLegacyMotionManager(this);
|
|
3729
3867
|
this.parallelMotionManager = [];
|
|
3730
3868
|
this.eyeBlink = new Live2DEyeBlink(coreModel);
|
|
@@ -3862,7 +4000,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
3862
4000
|
const max_ = 1;
|
|
3863
4001
|
const min_ = value > 0 ? 0.1 : 0;
|
|
3864
4002
|
value = Math.pow(value, 1.15);
|
|
3865
|
-
value = clamp(value, min_, max_);
|
|
4003
|
+
value = clamp$1(value, min_, max_);
|
|
3866
4004
|
for (let i = 0; i < this.motionManager.lipSyncIds.length; ++i) {
|
|
3867
4005
|
this.coreModel.addToParamFloat(
|
|
3868
4006
|
this.coreModel.getParamIndex(this.motionManager.lipSyncIds[i]),
|
|
@@ -4102,7 +4240,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4102
4240
|
);
|
|
4103
4241
|
if (visibleIndex >= 0) {
|
|
4104
4242
|
const originalOpacity = model.getPartsOpacity(partsGroup[visibleIndex].partsIndex);
|
|
4105
|
-
visibleOpacity = clamp(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4243
|
+
visibleOpacity = clamp$1(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4106
4244
|
} else {
|
|
4107
4245
|
visibleIndex = 0;
|
|
4108
4246
|
visibleOpacity = 1;
|
|
@@ -4208,6 +4346,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4208
4346
|
exports2.Live2DLoader = Live2DLoader;
|
|
4209
4347
|
exports2.Live2DModel = Live2DModel;
|
|
4210
4348
|
exports2.Live2DPhysics = Live2DPhysics;
|
|
4349
|
+
exports2.Live2DPlugin = Live2DPlugin;
|
|
4211
4350
|
exports2.Live2DPose = Live2DPose;
|
|
4212
4351
|
exports2.Live2DTransform = Live2DTransform;
|
|
4213
4352
|
exports2.MBToByte = MBToByte;
|
|
@@ -4220,9 +4359,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
4220
4359
|
exports2.VERSION = VERSION;
|
|
4221
4360
|
exports2.VOLUME = VOLUME;
|
|
4222
4361
|
exports2.XHRLoader = XHRLoader;
|
|
4223
|
-
exports2.ZipLoader = ZipLoader;
|
|
4224
4362
|
exports2.applyMixins = applyMixins;
|
|
4225
|
-
exports2.clamp = clamp;
|
|
4363
|
+
exports2.clamp = clamp$1;
|
|
4226
4364
|
exports2.config = config;
|
|
4227
4365
|
exports2.copyArray = copyArray;
|
|
4228
4366
|
exports2.copyProperty = copyProperty;
|