live2d-widget/README.md

157 lines
7.8 KiB
Markdown
Raw Normal View History

2019-02-11 06:39:40 +00:00
# Live2D Widget
2018-07-11 07:38:35 +00:00
2019-12-25 17:37:11 +00:00
![](https://forthebadge.com/images/badges/built-with-love.svg)
![](https://forthebadge.com/images/badges/uses-html.svg)
![](https://forthebadge.com/images/badges/made-with-javascript.svg)
![](https://forthebadge.com/images/badges/contains-cat-gifs.svg)
![](https://forthebadge.com/images/badges/powered-by-electricity.svg)
![](https://forthebadge.com/images/badges/makes-people-smile.svg)
2019-03-25 02:54:43 +00:00
## 特性 Feature
2019-09-27 16:29:46 +00:00
2019-12-14 08:04:44 +00:00
在网页中添加 Live2D 看板娘。兼容 PJAX支持无刷新加载。
2019-08-06 17:32:43 +00:00
Add Live2D widget to web page. Compatible with PJAX.
2018-07-11 07:38:35 +00:00
2020-04-13 04:59:07 +00:00
**警告:本项目使用了大量 ES6 语法,不支持 IE 11 等老旧浏览器。**
2019-12-14 08:04:44 +00:00
**WARNING: This project does not support legacy browsers such as IE 11.**
2019-01-20 17:53:34 +00:00
2019-03-25 02:54:43 +00:00
## 示例 Demo
2019-09-27 16:29:46 +00:00
2020-04-09 07:54:05 +00:00
在[米米的博客](https://zhangshuqiao.org)的左下角可查看效果。(注:以下人物模型仅供展示之用,本仓库并不包含任何模型。)
2019-01-02 12:36:35 +00:00
2020-04-09 02:24:31 +00:00
<img src="assets/screenshot-1.png"><img src="assets/screenshot-2.png" width="300"><img src="assets/screenshot-3.png" width="300">
2018-07-11 07:38:35 +00:00
2020-04-09 07:54:05 +00:00
你也可以在允许的范围内进行二次开发,这里有一些示例
2019-03-25 02:54:43 +00:00
2020-04-18 06:13:16 +00:00
- [demo.html](https://mi.js.org/live2d-widget/demo/demo.html) ,展现基础效果
- [login.html](https://mi.js.org/live2d-widget/demo/login.html) ,仿 NPM 的登陆界面
2019-03-25 02:54:43 +00:00
2018-12-17 16:01:42 +00:00
## 依赖 Dependencies
2019-09-27 16:29:46 +00:00
2020-04-01 07:46:22 +00:00
本插件需要 Font Awesome (v4 或 v5) 图标支持,请确保相关样式表已在页面中加载。以 Font Awesome v4 为例,请在 `<head>` 中加入:
Font Awesome (v4 or v5) is required for this plugin. Take Font Awesome v4 as an example, please add the following in `<head>`:
2018-12-11 11:57:55 +00:00
```xml
2019-08-06 17:49:39 +00:00
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
2018-11-02 15:04:54 +00:00
```
2020-04-13 04:59:07 +00:00
否则图标将无法正常显示。(如果网页中已经加载了任何版本的 Font Awesome就不要重复加载了
2018-07-11 07:38:35 +00:00
2018-12-17 16:01:42 +00:00
## 使用 Usage
2019-01-02 12:36:35 +00:00
2020-02-01 07:27:00 +00:00
将这一行代码加入 `<head>``<body>`,即可展现出效果:
2019-01-02 12:36:35 +00:00
```xml
2020-02-10 14:20:54 +00:00
<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>
2019-01-02 12:36:35 +00:00
```
2020-02-01 07:27:00 +00:00
如果网站启用了 PJAX由于看板娘不必每页刷新因此要注意将相关脚本放到 PJAX 刷新区域之外。
2019-08-06 17:32:43 +00:00
2020-02-01 07:27:00 +00:00
换句话说,如果你是小白,或者只需要最基础的功能,就只用把这一行代码,连同前面加载 Font Awesome 的一行代码,一起放到 html 的 `<head>` 中即可。
2020-04-09 07:54:05 +00:00
对于用各种模版引擎(例如 NunjucksJinja 或者 PHP生成的页面也要自行修改方法类似只是可能略为麻烦。以 [Hexo](https://hexo.io) 为例,需要在主题相关的 ejs 或 njk 模版中正确配置路径,才可以加载。
2019-01-02 12:36:35 +00:00
**但是!我们强烈推荐自己进行配置,否则很多功能是不完整的,并且可能产生问题!**
如果你有兴趣自己折腾的话,请看下面的详细说明。
2019-06-13 06:42:07 +00:00
### Using CDN
2019-12-26 03:13:42 +00:00
要自定义有关内容,可以把这个仓库 Fork 一份,然后进行修改。这时,使用方法对应地变为
2019-06-13 06:42:07 +00:00
```xml
2020-02-10 14:20:54 +00:00
<script src="https://cdn.jsdelivr.net/gh/username/live2d-widget@latest/autoload.js"></script>
2019-06-13 06:42:07 +00:00
```
2019-12-14 08:04:44 +00:00
`username` 替换为你的 GitHub 用户名即可。
2019-06-13 06:42:07 +00:00
2019-01-02 12:36:35 +00:00
### Self-host
2019-04-11 05:21:57 +00:00
2019-12-14 08:04:44 +00:00
你也可以直接把这些文件放到服务器上,而不是通过 CDN 加载。
2019-06-13 06:42:07 +00:00
2020-02-01 07:27:00 +00:00
- 如果你能够通过 `ssh` 访问你的主机,请把整个仓库克隆到服务器上。执行:
2019-12-31 17:22:52 +00:00
```bash
cd /path/to/your/webroot
# Clone this repository
git clone https://github.com/stevenjoezhang/live2d-widget.git
```
- 如果你的主机无法用 `ssh` 连接(例如一般的虚拟主机),请选择 `Download ZIP`,然后通过 `ftp` 等方式上传到主机上,再解压到网站的目录下。
2020-04-09 07:54:05 +00:00
- 如果你是通过 Hexo 等工具部署的静态博客,请在本地的博客目录中(例如 `source` 下与 `_posts` 同级的目录),执行前述的 `git clone` 命令。重新部署博客时,相关文件就会自动上传到对应的路径下。为了避免这些文件被 Hexo 插件错误地修改,可能需要设置 `skip_render`
2018-12-11 11:57:55 +00:00
2020-04-09 07:54:05 +00:00
这样,整个项目就可以通过你的服务器 IP 或者域名从公网访问了。不妨试试能否正常地通过浏览器打开 `autoload.js``live2d.min.js` 等文件,并确认这些文件的内容是完整和正确的。
2019-12-30 03:56:11 +00:00
一切正常的话,接下来修改一些配置就行了。(需要通过服务器上的文本编辑器修改;你也可以先在本地完成这一步骤,再上传到服务器上)
2020-02-01 07:27:00 +00:00
修改 `autoload.js` 中的常量 `live2d_path``live2d-widget` 这一文件夹在公网上的路径。比如说,如果你能够通过
2018-12-11 11:57:55 +00:00
```
https://www.example.com/path/to/live2d-widget/live2d.min.js
```
2019-12-14 08:04:44 +00:00
访问到 `live2d.min.js`,那么就把 `live2d_path` 的值修改为
2018-12-11 11:57:55 +00:00
```
https://www.example.com/path/to/live2d-widget/
2018-07-11 07:38:35 +00:00
```
2019-12-14 08:04:44 +00:00
路径末尾的 `/` 一定要加上。具体可以参考 `autoload.js` 内的注释。
2018-12-11 11:57:55 +00:00
完成后,在你要添加看板娘的界面加入
```xml
<script src="https://www.example.com/path/to/live2d-widget/autoload.js"></script>
2018-07-11 07:38:35 +00:00
```
2018-11-02 15:04:54 +00:00
就可以加载了。
2018-07-11 07:38:35 +00:00
2019-08-09 01:11:48 +00:00
## 目录结构 Files
2019-09-27 16:29:46 +00:00
2020-04-09 07:54:05 +00:00
- `waifu-tips.js` 包含了按钮和对话框的逻辑;
- `waifu-tips.json` 中定义了触发条件(`selector`CSS 选择器)和触发时显示的文字(`text`
2019-12-14 08:04:44 +00:00
- `waifu.css` 是看板娘的样式表。
2019-02-11 06:39:40 +00:00
2020-04-09 07:54:05 +00:00
源文件是对 Hexo 的 [NexT 主题](http://github.com/hexo-next/hexo-theme-next)有效的,为了适用于你自己的网页,可能需要自行修改,或增加新内容。
**警告:作者不对包括但不限于 `waifu-tips.js``waifu-tips.json` 文件中的内容负责,请自行确保它们是合适的。**
2019-02-11 06:39:40 +00:00
2019-12-28 16:52:13 +00:00
如果有任何疑问,欢迎提 Issue。如果有任何修改建议欢迎提 Pull Request。
2019-06-13 06:42:07 +00:00
2020-04-14 13:49:44 +00:00
## 鸣谢 Thanks
2019-09-27 16:29:46 +00:00
2020-04-14 13:49:44 +00:00
<a href="https://www.browserstack.com/">
<img src="https://live.browserstack.com/images/opensource/browserstack-logo.svg" alt="BrowserStack Logo" width="300">
</a>
2019-12-22 02:55:12 +00:00
感谢 BrowserStack 容许我们在真实的浏览器中测试此项目。
2020-04-14 13:49:44 +00:00
Thanks to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to test in real browsers!
2019-12-22 02:55:12 +00:00
2018-07-11 07:38:35 +00:00
代码自这篇博文魔改而来:
2019-12-28 16:52:13 +00:00
https://www.fghrsh.net/post/123.html
2018-07-11 07:38:35 +00:00
2019-12-26 03:13:42 +00:00
点击看板娘的纸飞机按钮时,会出现一个彩蛋,这来自于 [WebsiteAsteroids](http://www.websiteasteroids.com)。
## 更多 More
2018-07-11 07:38:35 +00:00
更多内容可以参考:
https://imjad.cn/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02
2019-12-04 12:17:40 +00:00
https://github.com/xiazeyu/live2d-widget.js
2019-03-25 02:54:43 +00:00
https://github.com/summerscar/live2dDemo
2018-07-11 07:38:35 +00:00
2019-12-25 17:37:11 +00:00
还可以自行搭建后端 API并增加模型需要修改的内容比较多此处不再赘述
2019-04-11 05:21:57 +00:00
https://github.com/fghrsh/live2d_api
2018-11-13 17:28:01 +00:00
https://github.com/xiazeyu/live2d-widget-models
https://github.com/xiaoski/live2d_models_collection
2018-11-03 10:52:03 +00:00
2019-03-25 02:54:43 +00:00
除此之外,还有桌面版本:
https://github.com/amorist/platelet
https://github.com/akiroz/Live2D-Widget
## 许可证 License
2019-09-27 16:29:46 +00:00
2019-01-20 17:53:34 +00:00
Released under the GNU General Public License v3
http://www.gnu.org/licenses/gpl-3.0.html
2019-12-28 16:52:13 +00:00
本仓库中涉及的所有 Live2D 模型、图片、动作数据等版权均属于其原作者,仅供研究学习,不得用于商业用途。
2019-12-29 16:21:00 +00:00
2019-12-30 03:56:11 +00:00
Live2D 官方网站:
https://www.live2d.com/en/
https://live2d.github.io
Live2D Cubism Core は Live2D Proprietary Software License で提供しています。
https://www.live2d.com/eula/live2d-proprietary-software-license-agreement_en.html
Live2D Cubism Components は Live2D Open Software License で提供しています。
http://www.live2d.com/eula/live2d-open-software-license-agreement_en.html
> The terms and conditions do prohibit modification, but obfuscating in `live2d.min.js` would not be considered illegal modification.
https://community.live2d.com/discussion/140/webgl-developer-licence-and-javascript-question
2019-12-29 16:21:00 +00:00
## 更新 Update
2018年10月31日由 fghrsh 提供的原 API 停用,请更新至新地址。参考文章:
https://www.fghrsh.net/post/170.html
2020年1月1日起本项目不再依赖于 jQuery。