2025-08-28 15:35:54 +08:00
|
|
|
|
// 看板娘模型配置(基于原始代码提取)
|
|
|
|
|
const models = {
|
|
|
|
|
shizuku: { jsonPath: "https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json", name: "小智" },
|
|
|
|
|
koharu: { jsonPath: "https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json", name: "小荷" },
|
|
|
|
|
wanko: { jsonPath: "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json", name: "汪喵" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 获取URL参数工具函数
|
|
|
|
|
function getUrlParam(name) {
|
|
|
|
|
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
|
|
|
|
|
const r = window.location.search.substr(1).match(reg);
|
|
|
|
|
return r ? unescape(r[2]) : null;
|
|
|
|
|
}
|
2025-08-28 12:59:00 +08:00
|
|
|
|
|
2025-08-28 15:35:54 +08:00
|
|
|
|
// 看板娘初始化函数
|
|
|
|
|
function initL2Dwidget() {
|
|
|
|
|
const modelId = getUrlParam('id') || 'koharu';
|
|
|
|
|
const model = models[modelId] || models.koharu;
|
|
|
|
|
|
|
|
|
|
// 设置下拉框选中状态
|
|
|
|
|
if (document.getElementById('model-select')) {
|
|
|
|
|
document.getElementById('model-select').value = modelId;
|
2025-08-28 12:59:00 +08:00
|
|
|
|
}
|
2025-08-28 15:35:54 +08:00
|
|
|
|
console.log('加载模型:', model.name, model.jsonPath);
|
|
|
|
|
|
|
|
|
|
// 初始化L2Dwidget(保留原始配置)
|
2025-08-28 12:59:00 +08:00
|
|
|
|
L2Dwidget.init({
|
2025-08-28 15:35:54 +08:00
|
|
|
|
"model": { "jsonPath": model.jsonPath, "scale": 1 },
|
2025-08-28 12:59:00 +08:00
|
|
|
|
"display": {
|
|
|
|
|
"position": "right",
|
|
|
|
|
"width": 150,
|
|
|
|
|
"height": 300,
|
|
|
|
|
"hOffset": 0,
|
|
|
|
|
"vOffset": -20
|
|
|
|
|
},
|
2025-08-28 15:35:54 +08:00
|
|
|
|
"mobile": { "show": true, "scale": 0.5 },
|
|
|
|
|
"react": { "opacityDefault": 0.8, "opacityOnHover": 1 },
|
|
|
|
|
"dialog": { "enable": true, "script": {
|
|
|
|
|
'tap body': `你好啊,我是${model.name}。`,
|
|
|
|
|
'tap face': '有什么问题或者烦心事都可以和我聊聊~'
|
|
|
|
|
}}
|
2025-08-28 12:59:00 +08:00
|
|
|
|
});
|
2025-08-28 15:35:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 页面加载完成后初始化看板娘
|
|
|
|
|
window.addEventListener('load', initL2Dwidget);
|
|
|
|
|
|
|
|
|
|
// 暴露模型切换功能接口
|
|
|
|
|
window.switchL2DModel = function(modelId) {
|
|
|
|
|
window.location.search = '?id=' + modelId;
|
|
|
|
|
};
|