mirror of
https://github.com/Buriburizaem0n/live2d.git
synced 2026-02-04 03:20:02 +00:00
fixed size
This commit is contained in:
70
live2d/dist/waifu-tips.js
vendored
70
live2d/dist/waifu-tips.js
vendored
@@ -44752,32 +44752,6 @@
|
|||||||
transparent: true,
|
transparent: true,
|
||||||
resizeTo: window
|
resizeTo: window
|
||||||
});
|
});
|
||||||
const model = await Live2DModel.from(jsonpath);
|
|
||||||
app.stage.addChild(model);
|
|
||||||
|
|
||||||
const parentWidth = element.width;
|
|
||||||
const parentHeight = element.height;
|
|
||||||
// Scale to fit the stage
|
|
||||||
const ratio = Math.min(
|
|
||||||
parentWidth / model.width,
|
|
||||||
parentHeight / model.height
|
|
||||||
);
|
|
||||||
model.scale.set(ratio, ratio);
|
|
||||||
// Align bottom and center horizontally
|
|
||||||
model.x = (parentWidth - model.width) / 2;
|
|
||||||
model.y = parentHeight - model.height;
|
|
||||||
|
|
||||||
// read json file to find motion groups
|
|
||||||
let modelJson = await readJSON(`${jsonpath}`);
|
|
||||||
|
|
||||||
// change expression after click on model
|
|
||||||
model.on("pointerdown", () => {
|
|
||||||
model.expression();
|
|
||||||
if (modelJson.motions) {
|
|
||||||
const motionGroup = Object.keys(modelJson.motions)[Math.floor(Math.random() * Object.keys(modelJson.motions).length)];
|
|
||||||
model.motion(motionGroup);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// function to read json file
|
// function to read json file
|
||||||
function readJSON(path) {
|
function readJSON(path) {
|
||||||
@@ -44788,6 +44762,50 @@
|
|||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function draggable(model) {
|
||||||
|
model.buttonMode = true;
|
||||||
|
model.on("pointerdown", (e) => {
|
||||||
|
model.dragging = true;
|
||||||
|
model._pointerX = e.data.global.x - model.x;
|
||||||
|
model._pointerY = e.data.global.y - model.y;
|
||||||
|
});
|
||||||
|
model.on("pointermove", (e) => {
|
||||||
|
if (model.dragging) {
|
||||||
|
model.position.x = e.data.global.x - model._pointerX;
|
||||||
|
model.position.y = e.data.global.y - model._pointerY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
model.on("pointerupoutside", () => (model.dragging = false));
|
||||||
|
model.on("pointerup", () => (model.dragging = false));
|
||||||
|
}
|
||||||
|
const model = await Live2DModel.from(jsonpath);
|
||||||
|
app.stage.addChild(model);
|
||||||
|
|
||||||
|
const parentWidth = element.width;
|
||||||
|
const parentHeight = element.height;
|
||||||
|
// Scale to fit the stage
|
||||||
|
const ratio = Math.min(
|
||||||
|
parentWidth / model.width,
|
||||||
|
parentHeight / model.height
|
||||||
|
);
|
||||||
|
model.scale.set(ratio, ratio);
|
||||||
|
// Align bottom and center horizontally
|
||||||
|
model.x = (parentWidth - model.width) / 2;
|
||||||
|
model.y = parentHeight - model.height;
|
||||||
|
draggable(model);
|
||||||
|
// read json file to find motion groups
|
||||||
|
let modelJson = await readJSON(`${jsonpath}`);
|
||||||
|
|
||||||
|
// change expression after click on model
|
||||||
|
model.on("pointerdown", () => {
|
||||||
|
model.expression();
|
||||||
|
if (modelJson.motions) {
|
||||||
|
const motionGroup = Object.keys(modelJson.motions)[Math.floor(Math.random() * Object.keys(modelJson.motions).length)];
|
||||||
|
model.motion(motionGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,32 +232,6 @@ function loadWidget() {
|
|||||||
transparent: true,
|
transparent: true,
|
||||||
resizeTo: window
|
resizeTo: window
|
||||||
});
|
});
|
||||||
const model = await Live2DModel.from(jsonpath);
|
|
||||||
app.stage.addChild(model);
|
|
||||||
|
|
||||||
const parentWidth = element.width;
|
|
||||||
const parentHeight = element.height;
|
|
||||||
// Scale to fit the stage
|
|
||||||
const ratio = Math.min(
|
|
||||||
parentWidth / model.width,
|
|
||||||
parentHeight / model.height
|
|
||||||
);
|
|
||||||
model.scale.set(ratio, ratio);
|
|
||||||
// Align bottom and center horizontally
|
|
||||||
model.x = (parentWidth - model.width) / 2;
|
|
||||||
model.y = parentHeight - model.height;
|
|
||||||
|
|
||||||
// read json file to find motion groups
|
|
||||||
let modelJson = await readJSON(`${jsonpath}`);
|
|
||||||
|
|
||||||
// change expression after click on model
|
|
||||||
model.on("pointerdown", () => {
|
|
||||||
model.expression();
|
|
||||||
if (modelJson.motions) {
|
|
||||||
const motionGroup = Object.keys(modelJson.motions)[Math.floor(Math.random() * Object.keys(modelJson.motions).length)];
|
|
||||||
model.motion(motionGroup);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// function to read json file
|
// function to read json file
|
||||||
function readJSON(path) {
|
function readJSON(path) {
|
||||||
@@ -268,6 +242,50 @@ function loadWidget() {
|
|||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function draggable(model) {
|
||||||
|
model.buttonMode = true;
|
||||||
|
model.on("pointerdown", (e) => {
|
||||||
|
model.dragging = true;
|
||||||
|
model._pointerX = e.data.global.x - model.x;
|
||||||
|
model._pointerY = e.data.global.y - model.y;
|
||||||
|
});
|
||||||
|
model.on("pointermove", (e) => {
|
||||||
|
if (model.dragging) {
|
||||||
|
model.position.x = e.data.global.x - model._pointerX;
|
||||||
|
model.position.y = e.data.global.y - model._pointerY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
model.on("pointerupoutside", () => (model.dragging = false));
|
||||||
|
model.on("pointerup", () => (model.dragging = false));
|
||||||
|
}
|
||||||
|
const model = await Live2DModel.from(jsonpath);
|
||||||
|
app.stage.addChild(model);
|
||||||
|
|
||||||
|
const parentWidth = element.width;
|
||||||
|
const parentHeight = element.height;
|
||||||
|
// Scale to fit the stage
|
||||||
|
const ratio = Math.min(
|
||||||
|
parentWidth / model.width,
|
||||||
|
parentHeight / model.height
|
||||||
|
);
|
||||||
|
model.scale.set(ratio, ratio);
|
||||||
|
// Align bottom and center horizontally
|
||||||
|
model.x = (parentWidth - model.width) / 2;
|
||||||
|
model.y = parentHeight - model.height;
|
||||||
|
draggable(model);
|
||||||
|
// read json file to find motion groups
|
||||||
|
let modelJson = await readJSON(`${jsonpath}`);
|
||||||
|
|
||||||
|
// change expression after click on model
|
||||||
|
model.on("pointerdown", () => {
|
||||||
|
model.expression();
|
||||||
|
if (modelJson.motions) {
|
||||||
|
const motionGroup = Object.keys(modelJson.motions)[Math.floor(Math.random() * Object.keys(modelJson.motions).length)];
|
||||||
|
model.motion(motionGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
transform: translateY(3px);
|
transform: translateY(3px);
|
||||||
transition: transform .3s ease-in-out, bottom 3s ease-in-out;
|
transition: transform .3s ease-in-out, bottom 3s ease-in-out;
|
||||||
z-index: 1;
|
width: 25%;
|
||||||
|
height: 25%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#waifu:hover {
|
#waifu:hover {
|
||||||
@@ -98,10 +99,9 @@
|
|||||||
|
|
||||||
#waifu #live2d {
|
#waifu #live2d {
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
height: 280px;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 330px;
|
width: 100%;
|
||||||
/* z-index: -1; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#waifu #live2d:active {
|
#waifu #live2d:active {
|
||||||
|
|||||||
Reference in New Issue
Block a user