Skip to content

Commit

Permalink
Feat: x/y shift for Live2D initial position
Browse files Browse the repository at this point in the history
- "initialXshift" and "initialYshift" were added to adjust the initial position of the live2D model.
  • Loading branch information
t41372 committed Nov 16, 2024
1 parent 16272c4 commit fc0e6c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0-alpha.1"
__version__ = "0.3.1"
5 changes: 5 additions & 0 deletions doc/live2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ A configuration may look like this:
"description": "Orange-Haired Girl, locally available. no internet required.",
"url": "/live2d-models/shizuku/shizuku.model.json",
"kScale": 0.000625,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1150,
"idleMotionGroupName": "Idle",
"emotionMap": {
Expand All @@ -52,10 +54,13 @@ Something you want to change
- If the model files are hosted somewhere, you can just paste the url. The url should starts with `http://` or `https://`.
- If the model you are trying to load is on your computer, put the model folder into the `live2d-models` directory and enter the relative path for the `url`. Like this `/live2d-models/UG/ugofficial.model3.json`. Keep the `/live2d-models` intact and don't change it nor add dots before it like `./live2d-models`.
- `KScale`: How big the model should be. Make it smaller if the model is too big. Vice versa.
- `initialXshift` and `initialYshift` (added in `v0.3.1`): The initial position for the Live2D model. Position (0, 0) is the center. Use this to calibrate the initial position for the Live2D model. If these two parameters are absent, they will be assumed 0, which is the center of the screen.
- `emotionMap`: a dictionary of facial expressions available.
- The key (text left to the semicolon) is the name of the emotion. You can put any words into it, and the LLM will use these keywords to control the expression of the live2d model.
- The value (text right to the semicolon) is the emotion index. This is the index that specify the emotion of the live2d model. After loading the model in the server, you can try running the function `setExpression(index)` in the console of the browser. Put some numbers into the function, see what the live2d model would do, and edit the emotion map according to the behavior and the index.

- `kXOffset` and `kYOffset`: deprecated and useless. Feel free to delete them.



### Load the model
Expand Down
10 changes: 10 additions & 0 deletions model_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Orange-Haired Girl, locally available. no internet required.",
"url": "/live2d-models/shizuku/shizuku.model.json",
"kScale": 0.000625,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1150,
"idleMotionGroupName": "Idle",
"emotionMap": {
Expand All @@ -22,6 +24,8 @@
"description": "Orange-Haired Girl. Will fetch from CDN.",
"url": "https://cdn.jsdelivr.net/gh/guansss/pixi-live2d-display/test/assets/shizuku/shizuku.model.json",
"kScale": 0.000625,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1150,
"idleMotionGroupName": "Idle",
"emotionMap": {
Expand All @@ -40,6 +44,8 @@
"description": "Knight Mommy",
"url": "https://cdn.jsdelivr.net/gh/Eikanya/Live2d-model/VenusScramble/otherunits/other_unit_90001/live2d/model.json",
"kScale": 0.0011,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1500,
"kYOffset": -150,
"idleMotionGroupName": "idle",
Expand All @@ -58,6 +64,8 @@
"description": "Angel",
"url": "https://cdn.jsdelivr.net/gh/Eikanya/Live2d-model/VenusScramble/playerunits/player_unit_00003/live2d/model.json",
"kScale": 0.0011,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1500,
"kYOffset": -150,
"idleMotionGroupName": "idle",
Expand All @@ -83,6 +91,8 @@
"description": "Mashiro Shiina",
"url": "https://cdn.jsdelivr.net/gh/artulloss/live2d/Sakurasou/mashiro/ryoufuku.model.json",
"kScale": 0.0007,
"initialXshift": 0,
"initialYshift": 0,
"kXOffset": 1000,
"kYOffset": -200,
"idleMotionGroupName": "idle",
Expand Down
7 changes: 6 additions & 1 deletion static/live2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const live2dModule = (function() {
});

model2 = models[0];
model2.x = app.view.width / 2 - model2.width / 2;

if (!modelInfo.initialXshift) modelInfo.initialXshift = 0;
if (!modelInfo.initialYshift) modelInfo.initialYshift = 0;

model2.x = app.view.width / 2 - model2.width / 2 + modelInfo["initialXshift"];
model2.y = app.view.height / 2 - model2.height / 2 + modelInfo["initialYshift"];

// model2.on("hit", (hitAreas) => {
// if (hitAreas.includes("body")) {
Expand Down

0 comments on commit fc0e6c9

Please sign in to comment.