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.es.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2
7
|
var __pow = Math.pow;
|
|
3
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
4
21
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
22
|
var __async = (__this, __arguments, generator) => {
|
|
6
23
|
return new Promise((resolve, reject) => {
|
|
@@ -22,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
22
39
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
40
|
});
|
|
24
41
|
};
|
|
25
|
-
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";
|
|
26
43
|
import { sound, Sound, webaudio } from "@pixi/sound";
|
|
27
44
|
const LOGICAL_WIDTH = 2;
|
|
28
45
|
const LOGICAL_HEIGHT = 2;
|
|
@@ -89,7 +106,7 @@ const config = {
|
|
|
89
106
|
preserveExpressionOnMotion: true,
|
|
90
107
|
cubism: CubismFrameworkConfig
|
|
91
108
|
};
|
|
92
|
-
const VERSION = "1.0
|
|
109
|
+
const VERSION = "1.2.0";
|
|
93
110
|
const logger = {
|
|
94
111
|
log(tag, ...messages) {
|
|
95
112
|
if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
|
|
@@ -107,7 +124,7 @@ const logger = {
|
|
|
107
124
|
}
|
|
108
125
|
}
|
|
109
126
|
};
|
|
110
|
-
function clamp(num, lower, upper) {
|
|
127
|
+
function clamp$1(num, lower, upper) {
|
|
111
128
|
return num < lower ? lower : num > upper ? upper : num;
|
|
112
129
|
}
|
|
113
130
|
function rand(min, max) {
|
|
@@ -382,8 +399,8 @@ class FocusController {
|
|
|
382
399
|
* @param instant - Should the focus position be instantly applied.
|
|
383
400
|
*/
|
|
384
401
|
focus(x, y, instant = false) {
|
|
385
|
-
this.targetX = clamp(x, -1, 1);
|
|
386
|
-
this.targetY = clamp(y, -1, 1);
|
|
402
|
+
this.targetX = clamp$1(x, -1, 1);
|
|
403
|
+
this.targetY = clamp$1(y, -1, 1);
|
|
387
404
|
if (instant) {
|
|
388
405
|
this.x = this.targetX;
|
|
389
406
|
this.y = this.targetY;
|
|
@@ -1900,6 +1917,68 @@ class CubismLegacyModelSettings extends ModelSettings {
|
|
|
1900
1917
|
}
|
|
1901
1918
|
}
|
|
1902
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
|
+
}
|
|
1903
1982
|
function createTexture(url, options = {}) {
|
|
1904
1983
|
const config2 = loadTextures.config;
|
|
1905
1984
|
const previousCrossOrigin = config2 == null ? void 0 : config2.crossOrigin;
|
|
@@ -1912,7 +1991,12 @@ function createTexture(url, options = {}) {
|
|
|
1912
1991
|
config2.preferCreateImageBitmap = false;
|
|
1913
1992
|
config2.preferWorkers = false;
|
|
1914
1993
|
}
|
|
1915
|
-
return Assets.load(
|
|
1994
|
+
return Assets.load({
|
|
1995
|
+
src: url,
|
|
1996
|
+
data: {
|
|
1997
|
+
autoGenerateMipmaps: getTextureLODMode(options.lod) === "full"
|
|
1998
|
+
}
|
|
1999
|
+
}).catch((error) => {
|
|
1916
2000
|
if (error instanceof Error) {
|
|
1917
2001
|
throw error;
|
|
1918
2002
|
}
|
|
@@ -2045,9 +2129,9 @@ const setupOptionals = (context, next) => __async(null, null, function* () {
|
|
|
2045
2129
|
const setupEssentials = (context, next) => __async(null, null, function* () {
|
|
2046
2130
|
if (context.settings) {
|
|
2047
2131
|
const live2DModel = context.live2dModel;
|
|
2048
|
-
const textureOptions = {
|
|
2132
|
+
const textureOptions = __spreadValues({
|
|
2049
2133
|
crossOrigin: context.options.crossOrigin
|
|
2050
|
-
};
|
|
2134
|
+
}, context.options.textureOptions);
|
|
2051
2135
|
if (context.settings instanceof CubismLegacyModelSettings) {
|
|
2052
2136
|
textureOptions.preferCreateImageBitmap = false;
|
|
2053
2137
|
}
|
|
@@ -2093,114 +2177,6 @@ const createInternalModel = (context, next) => __async(null, null, function* ()
|
|
|
2093
2177
|
}
|
|
2094
2178
|
throw new TypeError("Missing settings.");
|
|
2095
2179
|
});
|
|
2096
|
-
const _ZipLoader = class _ZipLoader {
|
|
2097
|
-
static unzip(reader, settings) {
|
|
2098
|
-
return __async(this, null, function* () {
|
|
2099
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2100
|
-
const requiredFilePaths = [];
|
|
2101
|
-
for (const definedFile of settings.getDefinedFiles()) {
|
|
2102
|
-
const actualPath = decodeURI(resolveURL(settings.url, definedFile));
|
|
2103
|
-
if (filePaths.includes(actualPath)) {
|
|
2104
|
-
requiredFilePaths.push(actualPath);
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
const files = yield _ZipLoader.getFiles(reader, requiredFilePaths);
|
|
2108
|
-
for (let i = 0; i < files.length; i++) {
|
|
2109
|
-
const path = requiredFilePaths[i];
|
|
2110
|
-
const file = files[i];
|
|
2111
|
-
Object.defineProperty(file, "webkitRelativePath", {
|
|
2112
|
-
value: path
|
|
2113
|
-
});
|
|
2114
|
-
}
|
|
2115
|
-
return files;
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
static createSettings(reader) {
|
|
2119
|
-
return __async(this, null, function* () {
|
|
2120
|
-
const filePaths = yield _ZipLoader.getFilePaths(reader);
|
|
2121
|
-
const settingsFilePath = filePaths.find(
|
|
2122
|
-
(path) => path.endsWith("model.json") || path.endsWith("model3.json")
|
|
2123
|
-
);
|
|
2124
|
-
if (!settingsFilePath) {
|
|
2125
|
-
throw new Error("Settings file not found");
|
|
2126
|
-
}
|
|
2127
|
-
const settingsText = yield _ZipLoader.readText(reader, settingsFilePath);
|
|
2128
|
-
if (!settingsText) {
|
|
2129
|
-
throw new Error("Empty settings file: " + settingsFilePath);
|
|
2130
|
-
}
|
|
2131
|
-
const settingsJSON = JSON.parse(settingsText);
|
|
2132
|
-
settingsJSON.url = settingsFilePath;
|
|
2133
|
-
const runtime = _ZipLoader.live2dFactory.findRuntime(settingsJSON);
|
|
2134
|
-
if (!runtime) {
|
|
2135
|
-
throw new Error("Unknown settings JSON");
|
|
2136
|
-
}
|
|
2137
|
-
return runtime.createModelSettings(settingsJSON);
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
static zipReader(data, url) {
|
|
2141
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2142
|
-
}
|
|
2143
|
-
static getFilePaths(reader) {
|
|
2144
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2145
|
-
}
|
|
2146
|
-
static getFiles(reader, paths) {
|
|
2147
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2148
|
-
}
|
|
2149
|
-
static readText(reader, path) {
|
|
2150
|
-
return Promise.reject(new Error("Not implemented"));
|
|
2151
|
-
}
|
|
2152
|
-
static releaseReader(reader) {
|
|
2153
|
-
}
|
|
2154
|
-
};
|
|
2155
|
-
// will be set by Live2DFactory
|
|
2156
|
-
__publicField(_ZipLoader, "live2dFactory");
|
|
2157
|
-
__publicField(_ZipLoader, "ZIP_PROTOCOL", "zip://");
|
|
2158
|
-
__publicField(_ZipLoader, "uid", 0);
|
|
2159
|
-
__publicField(_ZipLoader, "factory", (context, next) => __async(null, null, function* () {
|
|
2160
|
-
const source = context.source;
|
|
2161
|
-
let sourceURL;
|
|
2162
|
-
let zipBlob;
|
|
2163
|
-
let settings;
|
|
2164
|
-
if (typeof source === "string" && (source.endsWith(".zip") || source.startsWith(_ZipLoader.ZIP_PROTOCOL))) {
|
|
2165
|
-
if (source.startsWith(_ZipLoader.ZIP_PROTOCOL)) {
|
|
2166
|
-
sourceURL = source.slice(_ZipLoader.ZIP_PROTOCOL.length);
|
|
2167
|
-
} else {
|
|
2168
|
-
sourceURL = source;
|
|
2169
|
-
}
|
|
2170
|
-
zipBlob = yield Live2DLoader.load({
|
|
2171
|
-
url: sourceURL,
|
|
2172
|
-
type: "blob",
|
|
2173
|
-
target: context.live2dModel
|
|
2174
|
-
});
|
|
2175
|
-
} else if (Array.isArray(source) && source.length === 1 && source[0] instanceof File && source[0].name.endsWith(".zip")) {
|
|
2176
|
-
zipBlob = source[0];
|
|
2177
|
-
sourceURL = URL.createObjectURL(zipBlob);
|
|
2178
|
-
settings = source.settings;
|
|
2179
|
-
}
|
|
2180
|
-
if (zipBlob) {
|
|
2181
|
-
if (!zipBlob.size) {
|
|
2182
|
-
throw new Error("Empty zip file");
|
|
2183
|
-
}
|
|
2184
|
-
const reader = yield _ZipLoader.zipReader(zipBlob, sourceURL);
|
|
2185
|
-
if (!settings) {
|
|
2186
|
-
settings = yield _ZipLoader.createSettings(reader);
|
|
2187
|
-
}
|
|
2188
|
-
settings._objectURL = _ZipLoader.ZIP_PROTOCOL + _ZipLoader.uid + "/" + settings.url;
|
|
2189
|
-
const files = yield _ZipLoader.unzip(reader, settings);
|
|
2190
|
-
files.settings = settings;
|
|
2191
|
-
context.source = files;
|
|
2192
|
-
if (sourceURL.startsWith("blob:")) {
|
|
2193
|
-
context.live2dModel.once("modelLoaded", (internalModel) => {
|
|
2194
|
-
internalModel.once("destroy", function() {
|
|
2195
|
-
URL.revokeObjectURL(sourceURL);
|
|
2196
|
-
});
|
|
2197
|
-
});
|
|
2198
|
-
}
|
|
2199
|
-
_ZipLoader.releaseReader(reader);
|
|
2200
|
-
}
|
|
2201
|
-
return next();
|
|
2202
|
-
}));
|
|
2203
|
-
let ZipLoader = _ZipLoader;
|
|
2204
2180
|
const _FileLoader = class _FileLoader {
|
|
2205
2181
|
/**
|
|
2206
2182
|
* Resolves the path of a resource file to the object URL.
|
|
@@ -2481,7 +2457,6 @@ __publicField(_Live2DFactory, "createInternalModel", createInternalModel);
|
|
|
2481
2457
|
* Middlewares to run through when setting up a Live2DModel.
|
|
2482
2458
|
*/
|
|
2483
2459
|
__publicField(_Live2DFactory, "live2DModelMiddlewares", [
|
|
2484
|
-
ZipLoader.factory,
|
|
2485
2460
|
FileLoader.factory,
|
|
2486
2461
|
urlToJSON,
|
|
2487
2462
|
jsonToSettings,
|
|
@@ -2507,7 +2482,6 @@ ExpressionManager.prototype["_loadExpression"] = function(index) {
|
|
|
2507
2482
|
return Live2DFactory.loadExpression(this, index);
|
|
2508
2483
|
};
|
|
2509
2484
|
FileLoader["live2dFactory"] = Live2DFactory;
|
|
2510
|
-
ZipLoader["live2dFactory"] = Live2DFactory;
|
|
2511
2485
|
const _Automator = class _Automator {
|
|
2512
2486
|
constructor(model, {
|
|
2513
2487
|
autoUpdate = true,
|
|
@@ -2661,10 +2635,17 @@ const tempMatrix = new Matrix();
|
|
|
2661
2635
|
const tempWorldMatrix = new Matrix();
|
|
2662
2636
|
const tempDrawableBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
2663
2637
|
const tempModelBounds = new Bounds();
|
|
2638
|
+
let live2DPluginFallbackWarned = false;
|
|
2664
2639
|
class Live2DPipe {
|
|
2665
2640
|
constructor(renderer) {
|
|
2666
2641
|
this.renderer = renderer;
|
|
2667
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
|
+
}
|
|
2668
2649
|
execute(model) {
|
|
2669
2650
|
if (!model.visible || model.alpha <= 0) {
|
|
2670
2651
|
return;
|
|
@@ -2673,15 +2654,86 @@ class Live2DPipe {
|
|
|
2673
2654
|
}
|
|
2674
2655
|
updateRenderable() {
|
|
2675
2656
|
}
|
|
2657
|
+
destroyRenderable() {
|
|
2658
|
+
}
|
|
2659
|
+
validateRenderable() {
|
|
2660
|
+
return false;
|
|
2661
|
+
}
|
|
2676
2662
|
destroy() {
|
|
2677
2663
|
}
|
|
2678
2664
|
}
|
|
2665
|
+
__publicField(Live2DPipe, "extension", {
|
|
2666
|
+
type: [ExtensionType.WebGLPipes],
|
|
2667
|
+
name: "live2d"
|
|
2668
|
+
});
|
|
2669
|
+
const Live2DPlugin = Live2DPipe;
|
|
2679
2670
|
function ensureLive2DPipe(renderer) {
|
|
2680
2671
|
const r = renderer;
|
|
2681
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
|
+
}
|
|
2682
2679
|
r.renderPipes.live2d = new Live2DPipe(renderer);
|
|
2683
2680
|
}
|
|
2684
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
|
+
}
|
|
2685
2737
|
class Live2DModel extends Container {
|
|
2686
2738
|
/**
|
|
2687
2739
|
* Creates a new Live2DModel instance.
|
|
@@ -2705,6 +2757,9 @@ class Live2DModel extends Container {
|
|
|
2705
2757
|
* @type {Texture[]}
|
|
2706
2758
|
*/
|
|
2707
2759
|
__publicField(this, "textures", []);
|
|
2760
|
+
__publicField(this, "textureOptions");
|
|
2761
|
+
__publicField(this, "textureLODStates", []);
|
|
2762
|
+
__publicField(this, "textureLODFailures", []);
|
|
2708
2763
|
/** @override
|
|
2709
2764
|
* The Live2DTransform instance for this model.
|
|
2710
2765
|
*/
|
|
@@ -2761,15 +2816,25 @@ class Live2DModel extends Container {
|
|
|
2761
2816
|
this.internalModel.updateWebGLContext(renderer.gl, this.generateUID());
|
|
2762
2817
|
shouldUpdateTexture = true;
|
|
2763
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;
|
|
2764
2822
|
for (let i = 0; i < this.textures.length; i++) {
|
|
2765
|
-
const
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
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);
|
|
2773
2838
|
}
|
|
2774
2839
|
this.internalModel.bindTexture(i, renderer.texture.getGlSource(texture.source).texture);
|
|
2775
2840
|
}
|
|
@@ -2786,8 +2851,6 @@ class Live2DModel extends Container {
|
|
|
2786
2851
|
if (frameDelta) {
|
|
2787
2852
|
this.internalModel.update(frameDelta, this.elapsedTime);
|
|
2788
2853
|
}
|
|
2789
|
-
const { projectionMatrix, offset } = renderer.globalUniforms.globalUniformData;
|
|
2790
|
-
const adjustedWorld = tempWorldMatrix.copyFrom(this.worldTransform);
|
|
2791
2854
|
adjustedWorld.tx -= (_a = offset == null ? void 0 : offset.x) != null ? _a : 0;
|
|
2792
2855
|
adjustedWorld.ty -= (_b = offset == null ? void 0 : offset.y) != null ? _b : 0;
|
|
2793
2856
|
const internalTransform = tempMatrix.copyFrom(projectionMatrix).append(adjustedWorld);
|
|
@@ -2810,6 +2873,7 @@ class Live2DModel extends Container {
|
|
|
2810
2873
|
}
|
|
2811
2874
|
}
|
|
2812
2875
|
});
|
|
2876
|
+
this.textureOptions = options == null ? void 0 : options.textureOptions;
|
|
2813
2877
|
this.anchor = new ObservablePoint(
|
|
2814
2878
|
{
|
|
2815
2879
|
_onUpdate: () => this.onAnchorChange()
|
|
@@ -2961,9 +3025,7 @@ class Live2DModel extends Container {
|
|
|
2961
3025
|
ensureLive2DPipe(renderer);
|
|
2962
3026
|
const renderPipes = renderer.renderPipes;
|
|
2963
3027
|
const addRenderable = () => {
|
|
2964
|
-
|
|
2965
|
-
(_b2 = (_a2 = renderPipes.batch) == null ? void 0 : _a2.break) == null ? void 0 : _b2.call(_a2, instructionSet);
|
|
2966
|
-
instructionSet.add(this);
|
|
3028
|
+
renderPipes.live2d.addRenderable(this, instructionSet);
|
|
2967
3029
|
};
|
|
2968
3030
|
const collectChildren = () => {
|
|
2969
3031
|
const children = this.children;
|
|
@@ -3254,6 +3316,75 @@ class Live2DModel extends Container {
|
|
|
3254
3316
|
this.deltaTime += dt;
|
|
3255
3317
|
this.elapsedTime += dt;
|
|
3256
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
|
+
}
|
|
3257
3388
|
/**
|
|
3258
3389
|
* Destroys the model and all related resources. This takes the same options and also
|
|
3259
3390
|
* behaves the same as `PIXI.Container#destroy`.
|
|
@@ -3268,6 +3399,7 @@ class Live2DModel extends Container {
|
|
|
3268
3399
|
*/
|
|
3269
3400
|
destroy(options) {
|
|
3270
3401
|
this.emit("destroy");
|
|
3402
|
+
this.destroyTextureLODStates();
|
|
3271
3403
|
if (options == null ? void 0 : options.texture) {
|
|
3272
3404
|
this.textures.forEach((texture) => texture.destroy(options.baseTexture));
|
|
3273
3405
|
}
|
|
@@ -3633,7 +3765,7 @@ class Live2DEyeBlink {
|
|
|
3633
3765
|
this.rightParam = coreModel.getParamIndex("PARAM_EYE_R_OPEN");
|
|
3634
3766
|
}
|
|
3635
3767
|
setEyeParams(value) {
|
|
3636
|
-
this.eyeParamValue = clamp(value, 0, 1);
|
|
3768
|
+
this.eyeParamValue = clamp$1(value, 0, 1);
|
|
3637
3769
|
this.coreModel.setParamFloat(this.leftParam, this.eyeParamValue);
|
|
3638
3770
|
this.coreModel.setParamFloat(this.rightParam, this.eyeParamValue);
|
|
3639
3771
|
}
|
|
@@ -3723,6 +3855,12 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3723
3855
|
{ breathDepth: 1, lipSyncGain: 1.5, lipSyncWeight: 0.4 },
|
|
3724
3856
|
options
|
|
3725
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
|
+
}
|
|
3726
3864
|
this.motionManager = new CubismLegacyMotionManager(this);
|
|
3727
3865
|
this.parallelMotionManager = [];
|
|
3728
3866
|
this.eyeBlink = new Live2DEyeBlink(coreModel);
|
|
@@ -3860,7 +3998,7 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3860
3998
|
const max_ = 1;
|
|
3861
3999
|
const min_ = value > 0 ? 0.1 : 0;
|
|
3862
4000
|
value = Math.pow(value, 1.15);
|
|
3863
|
-
value = clamp(value, min_, max_);
|
|
4001
|
+
value = clamp$1(value, min_, max_);
|
|
3864
4002
|
for (let i = 0; i < this.motionManager.lipSyncIds.length; ++i) {
|
|
3865
4003
|
this.coreModel.addToParamFloat(
|
|
3866
4004
|
this.coreModel.getParamIndex(this.motionManager.lipSyncIds[i]),
|
|
@@ -4100,7 +4238,7 @@ class Live2DPose {
|
|
|
4100
4238
|
);
|
|
4101
4239
|
if (visibleIndex >= 0) {
|
|
4102
4240
|
const originalOpacity = model.getPartsOpacity(partsGroup[visibleIndex].partsIndex);
|
|
4103
|
-
visibleOpacity = clamp(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4241
|
+
visibleOpacity = clamp$1(originalOpacity + dt / this.opacityAnimDuration, 0, 1);
|
|
4104
4242
|
} else {
|
|
4105
4243
|
visibleIndex = 0;
|
|
4106
4244
|
visibleOpacity = 1;
|
|
@@ -4207,6 +4345,7 @@ export {
|
|
|
4207
4345
|
Live2DLoader,
|
|
4208
4346
|
Live2DModel,
|
|
4209
4347
|
Live2DPhysics,
|
|
4348
|
+
Live2DPlugin,
|
|
4210
4349
|
Live2DPose,
|
|
4211
4350
|
Live2DTransform,
|
|
4212
4351
|
MBToByte,
|
|
@@ -4219,9 +4358,8 @@ export {
|
|
|
4219
4358
|
VERSION,
|
|
4220
4359
|
VOLUME,
|
|
4221
4360
|
XHRLoader,
|
|
4222
|
-
ZipLoader,
|
|
4223
4361
|
applyMixins,
|
|
4224
|
-
clamp,
|
|
4362
|
+
clamp$1 as clamp,
|
|
4225
4363
|
config,
|
|
4226
4364
|
copyArray,
|
|
4227
4365
|
copyProperty,
|