mirror of
https://github.com/Buriburizaem0n/live2d.git
synced 2026-02-04 03:20:02 +00:00
allow 2 load method at same time
This commit is contained in:
@@ -1,67 +0,0 @@
|
|||||||
<!-- 宠物播放器 -->
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/live2dcubismcore@1.0.2/live2dcubismcore.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/pixi-live2d-display/dist/index.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/pixi.js@7.x/dist/pixi.min.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const live2d_path = "https://www.luoyangdonghui.de/wp-content/uploads/live2d_test16/live2d/";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<meting-js server="netease" type="playlist" id="2142063878" theme="#339981" fixed="true" preload="none" autoplay="false" loop="all" volume="0.3" order="random" mutex="true"></meting-js>;
|
|
||||||
<script>
|
|
||||||
// 封装异步加载资源的方法
|
|
||||||
function loadExternalResource(url, type, scriptType = null) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let tag;
|
|
||||||
|
|
||||||
if (type === "css") {
|
|
||||||
tag = document.createElement("link");
|
|
||||||
tag.rel = "stylesheet";
|
|
||||||
tag.href = url;
|
|
||||||
tag.type = "text/css"; // 添加 CSS 类型
|
|
||||||
} else if (type === "js") {
|
|
||||||
tag = document.createElement("script");
|
|
||||||
tag.src = url;
|
|
||||||
|
|
||||||
// 如果 scriptType 存在,则为 <script> 添加 type 属性
|
|
||||||
if (scriptType) {
|
|
||||||
tag.type = scriptType; // 如 "module" 或 "text/javascript"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.onload = () => resolve(url);
|
|
||||||
tag.onerror = () => reject(new Error(`Failed to load resource: ${url}`));
|
|
||||||
|
|
||||||
// 将标签追加到 <head> 中
|
|
||||||
document.head.appendChild(tag);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 手机和电脑都加载的音乐播放器相关资源
|
|
||||||
Promise.all([
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css", "css"),
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js", "js"),
|
|
||||||
]).then(() => {
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js", "js");
|
|
||||||
});
|
|
||||||
|
|
||||||
ap = null;
|
|
||||||
Object.defineProperty(document.querySelector('meting-js'), "aplayer", {
|
|
||||||
set: function(aplayer) {
|
|
||||||
ap = aplayer;
|
|
||||||
ap_init();
|
|
||||||
initWidget();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 只有电脑加载Live2D模块
|
|
||||||
if (screen.width >= 768) {
|
|
||||||
Promise.all([
|
|
||||||
loadExternalResource(live2d_path + "waifu.css", "css"),
|
|
||||||
loadExternalResource(live2d_path + "live2d.min.js", "js"),
|
|
||||||
loadExternalResource(live2d_path + "waifu-tips.js", "js", "module")
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
@@ -1,35 +1,56 @@
|
|||||||
<!--宠物播放器-->
|
<!--宠物播放器-->
|
||||||
<script>const live2d_path = "https://cdn.jsdelivr.net/gh/crowya/live2d/live2d/";</script>
|
<script>
|
||||||
<meting-js server="tencent" type="playlist" id="8559460487" theme="#339981" fixed="true" preload="none" autoplay="false" loop="all" order="random" volume="0.3"></meting-js>
|
const live2d_path = "https://www.luoyangdonghui.de/wp-content/uploads/live2d_test18/live2d/";
|
||||||
|
</script>
|
||||||
|
<meting-js server="netease" type="playlist" id="2142063878" theme="#339981" fixed="true" preload="none" autoplay="false" loop="all" volume="0.3" order="random" mutex="true"></meting-js>;
|
||||||
<script>
|
<script>
|
||||||
//封装异步加载资源的方法
|
//封装异步加载资源的方法
|
||||||
function loadExternalResource(url, type) {
|
function loadExternalResource(url, type) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let tag;
|
let tag;
|
||||||
if (type === "css") {
|
|
||||||
tag = document.createElement("link");
|
if (type === "css") {
|
||||||
tag.rel = "stylesheet";
|
tag = document.createElement("link");
|
||||||
tag.href = url;
|
tag.rel = "stylesheet";
|
||||||
}
|
tag.href = url;
|
||||||
else if (type === "js") {
|
} else if (type === "js") {
|
||||||
tag = document.createElement("script");
|
tag = document.createElement("script");
|
||||||
tag.src = url;
|
tag.src = url;
|
||||||
}
|
tag.async = true; // 确保脚本是异步加载的
|
||||||
if (tag) {
|
}
|
||||||
tag.onload = () => resolve(url);
|
|
||||||
tag.onerror = () => reject(url);
|
if (tag) {
|
||||||
document.head.appendChild(tag);
|
tag.onload = () => {
|
||||||
}
|
resolve(`Resource loaded: ${url}`);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
tag.onerror = (error) => {
|
||||||
|
reject(new Error(`Failed to load resource: ${url} - ${error.message}`));
|
||||||
|
};
|
||||||
|
|
||||||
|
// 确保只在没有相同资源的情况下加载,避免重复加载
|
||||||
|
if (!document.head.querySelector(`[src="${url}"]`) && !document.head.querySelector(`[href="${url}"]`)) {
|
||||||
|
document.head.appendChild(tag);
|
||||||
|
} else {
|
||||||
|
resolve(`Resource already loaded: ${url}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(new Error(`Invalid resource type: ${type}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (screen.width >= 768) {
|
if (screen.width >= 768) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/gh/crowya/live2d/live2d/waifu.min.css", "css"),
|
loadExternalResource(live2d_path + "waifu.css", "css"),
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/gh/crowya/live2d/live2d/live2d.min.js", "js"),
|
loadExternalResource(live2d_path + "live2d.min.js", "js"),
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/gh/crowya/live2d/live2d/waifu-tips.min.js", "js"),
|
loadExternalResource(live2d_path + "waifu-tips.js", "js"),
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css", "css"),
|
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css", "css"),
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js", "js"),
|
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js", "js"),
|
||||||
|
loadExternalResource("https://cdn.jsdelivr.net/npm/live2dcubismcore@1.0.2/live2dcubismcore.min.js", "js"),
|
||||||
|
loadExternalResource("https://cdnjs.cloudflare.com/ajax/libs/pixi.js/6.5.2/browser/pixi.min.js", "js"),
|
||||||
|
loadExternalResource("https://cdn.jsdelivr.net/npm/pixi-live2d-display@latest/dist/index.min.js", "js"),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js", "js");
|
loadExternalResource("https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js", "js");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
|
|
||||||
<!--宠物播放器-->
|
|
||||||
<script src="https://www.luoyangdonghui.de/wp-content/uploads/live2d_test16/live2d/live2d.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/live2dcubismcore@1.0.2/live2dcubismcore.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/pixi-live2d-display@beta/dist/index.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/pixi.js@7.x/dist/pixi.min.js"></script>
|
|
||||||
<script>
|
|
||||||
const live2d_path = "https://www.luoyangdonghui.de/wp-content/uploads/live2d_test16/live2d/";
|
|
||||||
</script>
|
|
||||||
<meting-js server="netease" type="playlist" id="2142063878" theme="#339981" fixed="true" preload="none" autoplay="false" loop="all" volume="0.3" order="random" mutex="true"></meting-js>;
|
|
||||||
<script>
|
|
||||||
//封装异步加载资源的方法
|
|
||||||
function loadExternalResource(url, type) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let tag;
|
|
||||||
if (type === "css") {
|
|
||||||
tag = document.createElement("link");
|
|
||||||
tag.rel = "stylesheet";
|
|
||||||
tag.href = url;
|
|
||||||
}
|
|
||||||
else if (type === "js") {
|
|
||||||
tag = document.createElement("script");
|
|
||||||
tag.src = url;
|
|
||||||
}
|
|
||||||
if (tag) {
|
|
||||||
tag.onload = () => resolve(url);
|
|
||||||
tag.onerror = () => reject(url);
|
|
||||||
document.head.appendChild(tag);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (screen.width >= 768) {
|
|
||||||
Promise.all([
|
|
||||||
loadExternalResource(live2d_path + "waifu.css", "css"),
|
|
||||||
loadExternalResource(live2d_path + "live2d.min.js", "js"),
|
|
||||||
loadExternalResource(live2d_path + "waifu-tips.js", "js"),
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css", "css"),
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js", "js"),
|
|
||||||
]).then(() => {
|
|
||||||
loadExternalResource("https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js", "js");
|
|
||||||
});
|
|
||||||
ap = null;
|
|
||||||
Object.defineProperty(document.querySelector('meting-js'), "aplayer", {
|
|
||||||
set: function(aplayer) {
|
|
||||||
ap = aplayer;
|
|
||||||
ap_init();
|
|
||||||
initWidget();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -204,15 +204,43 @@ function loadWidget() {
|
|||||||
modelList = result;
|
modelList = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async function loadModel(modelId, modelTexturesId, message) {
|
||||||
|
// localStorage.setItem("modelId", modelId);
|
||||||
|
// localStorage.setItem("modelTexturesId", modelTexturesId);
|
||||||
|
// showMessage(message, 4000, 10);
|
||||||
|
// if (!modelList) await loadModelList();
|
||||||
|
// let target = modelList.models[modelId];
|
||||||
|
// // loadlive2d("live2d", `${live2d_path}model/${target}/index.json`);
|
||||||
|
// loadModelPixi("live2d", `${live2d_path}model/${target}/index.json`);
|
||||||
|
// console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
|
||||||
|
// }
|
||||||
|
|
||||||
async function loadModel(modelId, modelTexturesId, message) {
|
async function loadModel(modelId, modelTexturesId, message) {
|
||||||
localStorage.setItem("modelId", modelId);
|
localStorage.setItem("modelId", modelId);
|
||||||
localStorage.setItem("modelTexturesId", modelTexturesId);
|
localStorage.setItem("modelTexturesId", modelTexturesId);
|
||||||
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`);
|
|
||||||
loadModelPixi("live2d", `${live2d_path}model/${target}/index.json`);
|
// 模型路径
|
||||||
console.log(`Live2D 模型 ${modelId}-${target} 加载完成`);
|
const modelPath = `${live2d_path}model/${target}/index.json`;
|
||||||
|
const modelPathAlt = `${live2d_path}model/${target}/index3.json`;
|
||||||
|
|
||||||
|
// 先尝试使用 loadlive2d 加载
|
||||||
|
try {
|
||||||
|
await loadlive2d("live2d", modelPath); // 假设 loadlive2d 返回的是 Promise
|
||||||
|
console.log(`Live2D 模型 ${modelId}-${target} 的 index.json 文件加载完成`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`加载 Live2D 模型失败: ${error.message},尝试使用 Pixi 加载模型`);
|
||||||
|
try {
|
||||||
|
// 如果 loadlive2d 失败,尝试使用 loadModelPixi 加载 index3.json
|
||||||
|
await loadModelPixi("live2d", modelPathAlt);
|
||||||
|
console.log(`Live2D 模型 ${modelId}-${target} 的 index3.json 文件加载完成 (使用 Pixi)`);
|
||||||
|
} catch (pixiError) {
|
||||||
|
console.error(`使用 Pixi 加载模型也失败: ${pixiError.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadNextModel() {
|
async function loadNextModel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user