Skip to content

Commit 26e3426

Browse files
Rebuild
1 parent 231c3fe commit 26e3426

21 files changed

+182
-101
lines changed

build/cubism2/LAppModel.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,10 @@ class LAppModel extends L2DBaseModel {
231231
}
232232
}
233233
setExpression(name) {
234+
var _b;
234235
const motion = this.expressions[name];
235236
logger.trace('Expression : ' + name);
236-
this.expressionManager.startMotion(motion, false);
237+
(_b = this.expressionManager) === null || _b === void 0 ? void 0 : _b.startMotion(motion, false);
237238
}
238239
draw(gl) {
239240
MatrixStack.push();
@@ -245,6 +246,17 @@ class LAppModel extends L2DBaseModel {
245246
}
246247
hitTest(id, testX, testY) {
247248
const len = this.modelSetting.getHitAreaNum();
249+
if (len == 0) {
250+
const hitAreasCustom = this.modelSetting.getHitAreaCustom();
251+
if (hitAreasCustom) {
252+
const x = hitAreasCustom[id + '_x'];
253+
const y = hitAreasCustom[id + '_y'];
254+
if (testX > Math.min(...x) && testX < Math.max(...x) &&
255+
testY > Math.min(...y) && testY < Math.max(...y)) {
256+
return true;
257+
}
258+
}
259+
}
248260
for (let i = 0; i < len; i++) {
249261
if (id == this.modelSetting.getHitAreaName(i)) {
250262
const drawID = this.modelSetting.getHitAreaID(i);

build/cubism2/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ declare class Cubism2Model {
88
viewMatrix: L2DViewMatrix;
99
projMatrix: L2DMatrix44;
1010
deviceToScreen: L2DMatrix44;
11-
drag: boolean;
1211
oldLen: number;
13-
lastMouseX: number;
14-
lastMouseY: number;
1512
_boundMouseEvent: any;
1613
_boundTouchEvent: any;
1714
initL2dCanvas(canvasId: any): void;

build/cubism2/index.js

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ import LAppDefine from './LAppDefine.js';
1212
import MatrixStack from './utils/MatrixStack.js';
1313
import LAppLive2DManager from './LAppLive2DManager.js';
1414
import logger from '../logger.js';
15+
function normalizePoint(x, y, x0, y0, w, h) {
16+
const dx = x - x0;
17+
const dy = y - y0;
18+
let targetX = 0, targetY = 0;
19+
if (dx >= 0) {
20+
targetX = dx / (w - x0);
21+
}
22+
else {
23+
targetX = dx / x0;
24+
}
25+
if (dy >= 0) {
26+
targetY = dy / (h - y0);
27+
}
28+
else {
29+
targetY = dy / y0;
30+
}
31+
return {
32+
vx: targetX,
33+
vy: -targetY
34+
};
35+
}
1536
class Cubism2Model {
1637
constructor() {
1738
this.live2DMgr = new LAppLive2DManager();
@@ -22,10 +43,7 @@ class Cubism2Model {
2243
this.viewMatrix = null;
2344
this.projMatrix = null;
2445
this.deviceToScreen = null;
25-
this.drag = false;
2646
this.oldLen = 0;
27-
this.lastMouseX = 0;
28-
this.lastMouseY = 0;
2947
this._boundMouseEvent = this.mouseEvent.bind(this);
3048
this._boundTouchEvent = this.touchEvent.bind(this);
3149
}
@@ -34,10 +52,8 @@ class Cubism2Model {
3452
if (this.canvas.addEventListener) {
3553
this.canvas.addEventListener('mousewheel', this._boundMouseEvent, false);
3654
this.canvas.addEventListener('click', this._boundMouseEvent, false);
37-
this.canvas.addEventListener('mousedown', this._boundMouseEvent, false);
38-
this.canvas.addEventListener('mousemove', this._boundMouseEvent, false);
39-
this.canvas.addEventListener('mouseup', this._boundMouseEvent, false);
40-
this.canvas.addEventListener('mouseout', this._boundMouseEvent, false);
55+
document.addEventListener('mousemove', this._boundMouseEvent, false);
56+
document.addEventListener('mouseout', this._boundMouseEvent, false);
4157
this.canvas.addEventListener('contextmenu', this._boundMouseEvent, false);
4258
this.canvas.addEventListener('touchstart', this._boundTouchEvent, false);
4359
this.canvas.addEventListener('touchend', this._boundTouchEvent, false);
@@ -80,10 +96,8 @@ class Cubism2Model {
8096
if (this.canvas) {
8197
this.canvas.removeEventListener('mousewheel', this._boundMouseEvent, false);
8298
this.canvas.removeEventListener('click', this._boundMouseEvent, false);
83-
this.canvas.removeEventListener('mousedown', this._boundMouseEvent, false);
84-
this.canvas.removeEventListener('mousemove', this._boundMouseEvent, false);
85-
this.canvas.removeEventListener('mouseup', this._boundMouseEvent, false);
86-
this.canvas.removeEventListener('mouseout', this._boundMouseEvent, false);
99+
document.removeEventListener('mousemove', this._boundMouseEvent, false);
100+
document.removeEventListener('mouseout', this._boundMouseEvent, false);
87101
this.canvas.removeEventListener('contextmenu', this._boundMouseEvent, false);
88102
this.canvas.removeEventListener('touchstart', this._boundTouchEvent, false);
89103
this.canvas.removeEventListener('touchend', this._boundTouchEvent, false);
@@ -160,12 +174,9 @@ class Cubism2Model {
160174
}
161175
}
162176
modelTurnHead(event) {
163-
this.drag = true;
164-
const rect = event.target.getBoundingClientRect();
165-
const sx = this.transformScreenX(event.clientX - rect.left);
166-
const sy = this.transformScreenY(event.clientY - rect.top);
167-
const vx = this.transformViewX(event.clientX - rect.left);
168-
const vy = this.transformViewY(event.clientY - rect.top);
177+
var _b;
178+
const rect = this.canvas.getBoundingClientRect();
179+
const { vx, vy } = normalizePoint(event.clientX, event.clientY, rect.left + rect.width / 2, rect.top + rect.height / 2, window.innerWidth, window.innerHeight);
169180
logger.trace('onMouseDown device( x:' +
170181
event.clientX +
171182
' y:' +
@@ -175,17 +186,16 @@ class Cubism2Model {
175186
' y:' +
176187
vy +
177188
')');
178-
this.lastMouseX = sx;
179-
this.lastMouseY = sy;
180189
this.dragMgr.setPoint(vx, vy);
181190
this.live2DMgr.tapEvent(vx, vy);
191+
if ((_b = this.live2DMgr) === null || _b === void 0 ? void 0 : _b.model.hitTest(LAppDefine.HIT_AREA_BODY, vx, vy)) {
192+
window.dispatchEvent(new Event('live2d:tapbody'));
193+
}
182194
}
183195
followPointer(event) {
196+
var _b;
184197
const rect = event.target.getBoundingClientRect();
185-
const sx = this.transformScreenX(event.clientX - rect.left);
186-
const sy = this.transformScreenY(event.clientY - rect.top);
187-
const vx = this.transformViewX(event.clientX - rect.left);
188-
const vy = this.transformViewY(event.clientY - rect.top);
198+
const { vx, vy } = normalizePoint(event.clientX, event.clientY, rect.left + rect.width / 2, rect.top + rect.height / 2, window.innerWidth, window.innerHeight);
189199
logger.trace('onMouseMove device( x:' +
190200
event.clientX +
191201
' y:' +
@@ -195,45 +205,28 @@ class Cubism2Model {
195205
' y:' +
196206
vy +
197207
')');
198-
if (this.drag) {
199-
this.lastMouseX = sx;
200-
this.lastMouseY = sy;
201-
this.dragMgr.setPoint(vx, vy);
208+
this.dragMgr.setPoint(vx, vy);
209+
if ((_b = this.live2DMgr) === null || _b === void 0 ? void 0 : _b.model.hitTest(LAppDefine.HIT_AREA_BODY, vx, vy)) {
210+
window.dispatchEvent(new Event('live2d:hoverbody'));
202211
}
203212
}
204213
lookFront() {
205-
if (this.drag) {
206-
this.drag = false;
207-
}
208214
this.dragMgr.setPoint(0, 0);
209215
}
210216
mouseEvent(e) {
211217
e.preventDefault();
212218
if (e.type == 'mousewheel') {
213-
if (e.clientX < 0 ||
214-
this.canvas.clientWidth < e.clientX ||
215-
e.clientY < 0 ||
216-
this.canvas.clientHeight < e.clientY) {
217-
return;
218-
}
219219
if (e.wheelDelta > 0)
220220
this.modelScaling(1.1);
221221
else
222-
this.modelScaling(0.9);
222+
this.modelScaling(1);
223223
}
224-
else if (e.type == 'mousedown') {
225-
if ('button' in e && e.button != 0)
226-
return;
224+
else if (e.type == 'click' || e.type == 'contextmenu') {
227225
this.modelTurnHead(e);
228226
}
229227
else if (e.type == 'mousemove') {
230228
this.followPointer(e);
231229
}
232-
else if (e.type == 'mouseup') {
233-
if ('button' in e && e.button != 0)
234-
return;
235-
this.lookFront();
236-
}
237230
else if (e.type == 'mouseout') {
238231
this.lookFront();
239232
}

build/cubism2/utils/ModelSettingJson.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare class ModelSettingJson {
55
MODEL: string;
66
TEXTURES: string;
77
HIT_AREAS: string;
8+
HIT_AREAS_CUSTOM: string;
89
PHYSICS: string;
910
POSE: string;
1011
EXPRESSIONS: string;
@@ -23,6 +24,7 @@ declare class ModelSettingJson {
2324
getModelFile(): any;
2425
getTextureNum(): any;
2526
getHitAreaNum(): any;
27+
getHitAreaCustom(): any;
2628
getHitAreaID(n: any): any;
2729
getHitAreaName(n: any): any;
2830
getPhysicsFile(): any;

build/cubism2/utils/ModelSettingJson.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class ModelSettingJson {
66
this.MODEL = 'model';
77
this.TEXTURES = 'textures';
88
this.HIT_AREAS = 'hit_areas';
9+
this.HIT_AREAS_CUSTOM = 'hit_areas_custom';
910
this.PHYSICS = 'physics';
1011
this.POSE = 'pose';
1112
this.EXPRESSIONS = 'expressions';
@@ -46,6 +47,9 @@ class ModelSettingJson {
4647
return 0;
4748
return this.json[this.HIT_AREAS].length;
4849
}
50+
getHitAreaCustom() {
51+
return this.json[this.HIT_AREAS_CUSTOM];
52+
}
4953
getHitAreaID(n) {
5054
if (this.json[this.HIT_AREAS] == null ||
5155
this.json[this.HIT_AREAS][n] == null)

build/cubism5/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
export class AppDelegate extends LAppDelegate {
22
_drawFrameId: number;
33
stop(): void;
4+
transformOffset(e: any): {
5+
x: number;
6+
y: number;
7+
};
8+
onMouseMove(e: any): void;
9+
onMouseEnd(e: any): void;
10+
onTap(e: any): void;
11+
mouseMoveEventListener: any;
12+
mouseEndedEventListener: any;
13+
tapEventListener: any;
414
changeModel(modelSettingPath: string): void;
515
get subdelegates(): import("@framework/type/csmvector.js").csmVector<LAppSubdelegate>;
616
}

build/cubism5/index.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as LAppDefine from '@demo/lappdefine.js';
44
import { LAppModel } from '@demo/lappmodel.js';
55
import { LAppPal } from '@demo/lapppal';
66
import logger from '../logger.js';
7+
LAppPal.printMessage = () => { };
78
class AppSubdelegate extends LAppSubdelegate {
89
initialize(canvas) {
910
if (!this._glManager.initialize(canvas)) {
@@ -85,23 +86,69 @@ export class AppDelegate extends LAppDelegate {
8586
this._subdelegates.clear();
8687
this._cubismOption = null;
8788
}
88-
releaseEventListener() {
89-
document.removeEventListener('pointerdown', this.pointBeganEventListener, {
89+
transformOffset(e) {
90+
const subdelegate = this._subdelegates.at(0);
91+
const rect = subdelegate.getCanvas().getBoundingClientRect();
92+
const localX = e.pageX - rect.left;
93+
const localY = e.pageY - rect.top;
94+
const posX = localX * window.devicePixelRatio;
95+
const posY = localY * window.devicePixelRatio;
96+
const x = subdelegate._view.transformViewX(posX);
97+
const y = subdelegate._view.transformViewY(posY);
98+
return {
99+
x, y
100+
};
101+
}
102+
onMouseMove(e) {
103+
const lapplive2dmanager = this._subdelegates.at(0).getLive2DManager();
104+
const { x, y } = this.transformOffset(e);
105+
const model = lapplive2dmanager._models.at(0);
106+
lapplive2dmanager.onDrag(x, y);
107+
lapplive2dmanager.onTap(x, y);
108+
if (model.hitTest(LAppDefine.HitAreaNameBody, x, y)) {
109+
window.dispatchEvent(new Event('live2d:hoverbody'));
110+
}
111+
}
112+
onMouseEnd(e) {
113+
const lapplive2dmanager = this._subdelegates.at(0).getLive2DManager();
114+
const { x, y } = this.transformOffset(e);
115+
lapplive2dmanager.onDrag(0.0, 0.0);
116+
lapplive2dmanager.onTap(x, y);
117+
}
118+
onTap(e) {
119+
const lapplive2dmanager = this._subdelegates.at(0).getLive2DManager();
120+
const { x, y } = this.transformOffset(e);
121+
const model = lapplive2dmanager._models.at(0);
122+
if (model.hitTest(LAppDefine.HitAreaNameBody, x, y)) {
123+
window.dispatchEvent(new Event('live2d:tapbody'));
124+
}
125+
}
126+
initializeEventListener() {
127+
this.mouseMoveEventListener = this.onMouseMove.bind(this);
128+
this.mouseEndedEventListener = this.onMouseEnd.bind(this);
129+
this.tapEventListener = this.onTap.bind(this);
130+
document.addEventListener('mousemove', this.mouseMoveEventListener, {
131+
passive: true
132+
});
133+
document.addEventListener('mouseout', this.mouseEndedEventListener, {
90134
passive: true
91135
});
92-
this.pointBeganEventListener = null;
93-
document.removeEventListener('pointermove', this.pointMovedEventListener, {
136+
document.addEventListener('pointerdown', this.tapEventListener, {
137+
passive: true
138+
});
139+
}
140+
releaseEventListener() {
141+
document.removeEventListener('mousemove', this.mouseMoveEventListener, {
94142
passive: true
95143
});
96-
this.pointMovedEventListener = null;
97-
document.removeEventListener('pointerup', this.pointEndedEventListener, {
144+
this.mouseMoveEventListener = null;
145+
document.removeEventListener('mouseout', this.mouseEndedEventListener, {
98146
passive: true
99147
});
100-
this.pointEndedEventListener = null;
101-
document.removeEventListener('pointercancel', this.pointCancelEventListener, {
148+
this.mouseEndedEventListener = null;
149+
document.removeEventListener('pointerdown', this.tapEventListener, {
102150
passive: true
103151
});
104-
this.pointCancelEventListener = null;
105152
}
106153
initializeSubdelegates() {
107154
this._canvases.prepareCapacity(LAppDefine.CanvasNum);

build/logger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class Logger {
1717
}
1818
warn(message, ...args) {
1919
if (this.shouldLog('warn')) {
20-
console.warn('[Live2D Widget][WARN ]', message, ...args);
20+
console.warn('[Live2D Widget][WARN]', message, ...args);
2121
}
2222
}
2323
info(message, ...args) {
2424
if (this.shouldLog('info')) {
25-
console.log('[Live2D Widget][INFO ]', message, ...args);
25+
console.log('[Live2D Widget][INFO]', message, ...args);
2626
}
2727
}
2828
trace(message, ...args) {

build/message.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ type Time = {
22
hour: string;
33
text: string;
44
}[];
5-
declare function showMessage(text: string | string[], timeout: number, priority: number): void;
5+
declare function showMessage(text: string | string[], timeout: number, priority: number, override?: boolean): void;
66
declare function welcomeMessage(time: Time, welcomeTemplate: string, referrerTemplate: string): string;
77
declare function i18n(template: string, ...args: string[]): string;
88
export { showMessage, welcomeMessage, i18n, Time };

build/message.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { randomSelection } from './utils.js';
22
let messageTimer = null;
3-
function showMessage(text, timeout, priority) {
3+
function showMessage(text, timeout, priority, override = true) {
4+
let currentPriority = parseInt(sessionStorage.getItem('waifu-message-priority'), 10);
5+
if (isNaN(currentPriority)) {
6+
currentPriority = 0;
7+
}
48
if (!text ||
5-
(sessionStorage.getItem('waifu-text') &&
6-
Number(sessionStorage.getItem('waifu-text')) > priority))
9+
(override && currentPriority > priority) ||
10+
(!override && currentPriority >= priority))
711
return;
812
if (messageTimer) {
913
clearTimeout(messageTimer);
1014
messageTimer = null;
1115
}
1216
text = randomSelection(text);
13-
sessionStorage.setItem('waifu-text', String(priority));
17+
sessionStorage.setItem('waifu-message-priority', String(priority));
1418
const tips = document.getElementById('waifu-tips');
1519
tips.innerHTML = text;
1620
tips.classList.add('waifu-tips-active');
1721
messageTimer = setTimeout(() => {
18-
sessionStorage.removeItem('waifu-text');
22+
sessionStorage.removeItem('waifu-message-priority');
1923
tips.classList.remove('waifu-tips-active');
2024
}, timeout);
2125
}

0 commit comments

Comments
 (0)