fixed error

This commit is contained in:
2024-09-20 00:18:47 +02:00
parent ea5e227b43
commit 1fe6c80b37
2 changed files with 33 additions and 35 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,6 @@
import * as PIXI from "pixi.js";
import { Live2DModel } from "pixi-live2d-display";
function ap_init() {
$(".aplayer-body").addClass("my-hide");
ap.lrc.hide(); //初始化时隐藏歌词
@@ -192,8 +195,7 @@ function loadWidget() {
}
modelTexturesId = 0; // 材质ID
}
// loadModel(modelId, modelTexturesId);
loadModelPixi(modelId, modelTexturesId);
loadModel(modelId, modelTexturesId);
fetch(`${live2d_path}waifu-tips.json`)
.then(response => response.json())
.then(registerEventListener);
@@ -211,7 +213,8 @@ function loadWidget() {
showMessage(message, 4000, 10);
if (!modelList) await loadModelList();
let target = modelList.models[modelId];
loadlive2d("live2d", `${live2d_path}model/${target}/index.json`);
// loadlive2d("live2d", `${live2d_path}model/${target}/index.json`);
loadModelPixi("live2d", `${live2d_path}model/${target}/index.json`);
console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
}
@@ -219,40 +222,35 @@ function loadWidget() {
let modelId = localStorage.getItem("modelId");
if (!modelList) await loadModelList();
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
// loadModel(index, 0, modelList.messages[index]);
loadModelPixi(index, 0, modelList.messages[index]);
loadModel(index, 0, modelList.messages[index]);
}
async function loadModelPixi(modelId, modelTexturesId, message) {
localStorage.setItem("modelId", modelId);
localStorage.setItem("modelTexturesId", modelTexturesId);
showMessage(message, 4000, 10);
if (!modelList) await loadModelList();
let target = modelList.models[modelId];
const jsonpath = `${live2d_path}model/${target}/index.json`;
const element = document.getElementById(modelId);
const app = new PIXI.Application({
view: element,
transparent: true,
});
const model = await Live2DModel.from(jsonpath);
window.PIXI = PIXI;
app.stage.addChild(model);
const parentWidth = element.width;
const parentHeight = element.height;
// Scale to fit the stage
const ratio = Math.min(
parentWidth / model.width,
parentHeight / model.height
);
model.scale.set(ratio, ratio);
// Align bottom and center horizontally
model.x = (parentWidth - model.width) / 2;
model.y = parentHeight - model.height;
}
async function loadModelPixi(id, jsonpath) {
const element = document.getElementById(id);
const app = new PIXI.Application({
view: element,
transparent: true,
});
const model = await Live2DModel.from(jsonpath);
app.stage.addChild(model);
const parentWidth = element.width;
const parentHeight = element.height;
// Scale to fit the stage
const ratio = Math.min(
parentWidth / model.width,
parentHeight / model.height
);
model.scale.set(ratio, ratio);
// Align bottom and center horizontally
model.x = (parentWidth - model.width) / 2;
model.y = parentHeight - model.height;
}
}