stevenjoezhang / live2d-widget

把萌萌哒的看板娘抱回家 (ノ≧∇≦)ノ | Live2D widget for web platform
https://zhangshuqiao.org/2018-07/在网页中添加Live2D看板娘
GNU General Public License v3.0
8.76k stars 2.38k forks source link

关于加载模型的方式 #19

Closed wu-kan closed 4 years ago

wu-kan commented 4 years ago

目前想要加载自定义模型要自己搭后端,感觉不太方便。能否修改成通过这个live2d-helper或者类似的方式加载模型?这样既不用自己搭后端,也可以通过jsdelivr之类的cdn加速live2d贴图的访问。

换成html代码大概长下面这个样子。

<script
  defer="defer"
  src="https://cdn.jsdelivr.net/npm/live2d-helper@1.0.0/dist/index.min.js"
  onload='if (screen.width >= 768) {
    document.body.insertAdjacentHTML("beforeend", `
      <div id="waifu">
        <canvas id="live2d"></canvas>
      </div>`);
    setTimeout(() => {
        document.getElementById("waifu").style.bottom = 0;
        document.getElementById("waifu").style.right = 0;
        document.getElementById("waifu").style.zIndex = 1;
        document.getElementById("waifu").style.position = "fixed";
      }, 0);
    loadLive2d({
        canvas: "live2d",
        baseUrl: "https:\/\/cdn.jsdelivr.net/gh/fghrsh/live2d_api/model/HyperdimensionNeptunia/nepnep",
        model: "https:\/\/cdn.jsdelivr.net/gh/fghrsh/live2d_api/model/HyperdimensionNeptunia/nepnep/index.json",
        width: "300",
        height: "415"
      })
  }'
></script>
stevenjoezhang commented 4 years ago

你这不都已经实现了 😂 自己用就好了嘛

wu-kan commented 4 years ago

你这不都已经实现了 😂 自己用就好了嘛

所以是建议嘛😂

stevenjoezhang commented 4 years ago

@wu-kan 我确认了一下后台的源代码,其实就是通过 302 重定向用的 jsDelivr 的 CDN。

截屏2020-02-20下午12 51 57
stevenjoezhang commented 4 years ago

现在已改为默认通过 jsDelivr 的 CDN 加载,代替原有的 API。