mirror of
https://github.com/Buriburizaem0n/live2d.git
synced 2025-12-17 00:21:06 +00:00
fixed error
This commit is contained in:
2
live2d/dist/bundle.js
vendored
2
live2d/dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,3 +1,6 @@
|
|||||||
|
import * as PIXI from "pixi.js";
|
||||||
|
import { Live2DModel } from "pixi-live2d-display";
|
||||||
|
|
||||||
function ap_init() {
|
function ap_init() {
|
||||||
$(".aplayer-body").addClass("my-hide");
|
$(".aplayer-body").addClass("my-hide");
|
||||||
ap.lrc.hide(); //初始化时隐藏歌词
|
ap.lrc.hide(); //初始化时隐藏歌词
|
||||||
@@ -192,8 +195,7 @@ function loadWidget() {
|
|||||||
}
|
}
|
||||||
modelTexturesId = 0; // 材质ID
|
modelTexturesId = 0; // 材质ID
|
||||||
}
|
}
|
||||||
// loadModel(modelId, modelTexturesId);
|
loadModel(modelId, modelTexturesId);
|
||||||
loadModelPixi(modelId, modelTexturesId);
|
|
||||||
fetch(`${live2d_path}waifu-tips.json`)
|
fetch(`${live2d_path}waifu-tips.json`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(registerEventListener);
|
.then(registerEventListener);
|
||||||
@@ -211,7 +213,8 @@ function loadWidget() {
|
|||||||
showMessage(message, 4000, 10);
|
showMessage(message, 4000, 10);
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let target = modelList.models[modelId];
|
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} 加载完成`);
|
console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,40 +222,35 @@ function loadWidget() {
|
|||||||
let modelId = localStorage.getItem("modelId");
|
let modelId = localStorage.getItem("modelId");
|
||||||
if (!modelList) await loadModelList();
|
if (!modelList) await loadModelList();
|
||||||
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
let index = (++modelId >= modelList.models.length) ? 0 : modelId;
|
||||||
// loadModel(index, 0, modelList.messages[index]);
|
loadModel(index, 0, modelList.messages[index]);
|
||||||
loadModelPixi(index, 0, modelList.messages[index]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadModelPixi(modelId, modelTexturesId, message) {
|
window.PIXI = PIXI;
|
||||||
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);
|
|
||||||
|
|
||||||
app.stage.addChild(model);
|
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);
|
||||||
|
|
||||||
const parentWidth = element.width;
|
app.stage.addChild(model);
|
||||||
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;
|
const parentWidth = element.width;
|
||||||
model.y = parentHeight - model.height;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user