Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit d3c7ab5

Browse files
committed
feat: modified live2d core js
1 parent 1a8db01 commit d3c7ab5

File tree

5 files changed

+7658
-45
lines changed

5 files changed

+7658
-45
lines changed

src/_lib/_live2d.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/cLive2DApp.js

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55

6-
/*import {
6+
import {
77
UtSystem,
88
UtDebug,
99
LDTransform,
@@ -19,8 +19,7 @@
1919
DrawDataID,
2020
BaseDataID,
2121
ParamID
22-
} from './lib/live2d.min';*//*
23-
import './lib/live2d.min.js';
22+
} from './lib/live2d.core';/*
2423
import { device } from 'current-device';
2524
import { L2DTargetPoint, L2DViewMatrix, L2DMatrix44 } from "./lib/Live2DFramework";
2625
import cManager from "./cManager";
@@ -29,7 +28,6 @@ import { cDefine } from "./cDefine";
2928
3029
const live2DMgr = new cManager();
3130
let isDrawStart = false;
32-
let gl = null;
3331
let canvas = null;
3432
let dragMgr = null;
3533
let viewMatrix = null;
@@ -44,7 +42,7 @@ let opacityHover = 1;
4442
*/
4543

4644
import { config } from './config/configMgr';
47-
import { createCanvas, setCurrWebGL, getCurrWebGL } from './elementManager';
45+
import { createElement, currWebGL } from './elementManager';
4846

4947
/**
5048
* Main function of live2d-widget
@@ -53,32 +51,10 @@ import { createCanvas, setCurrWebGL, getCurrWebGL } from './elementManager';
5351

5452
export default () => {
5553

56-
createCanvas();
57-
// initL2D();
54+
createElement();
5855

59-
}
60-
61-
62-
function initCanvas(){/*
63-
canvas = document.getElementById(canvasId);
64-
if (canvas.addEventListener) {
65-
window.addEventListener("click", mouseEvent);
66-
window.addEventListener("mousedown", mouseEvent);
67-
window.addEventListener("mousemove", mouseEvent);
68-
window.addEventListener("mouseup", mouseEvent);
69-
document.addEventListener("mouseleave", mouseEvent);
70-
window.addEventListener("touchstart", touchEvent);
71-
window.addEventListener("touchend", touchEvent);
72-
window.addEventListener("touchmove", touchEvent);
73-
}*/
74-
}
75-
76-
function initL2D() {
77-
// 此处获取的是canvas的大小 即绘制大小,与实际显示大小无关
7856
let width = canvas.width;
7957
let height = canvas.height;
80-
// 以下为实际显示大小
81-
// #32
8258
let sWidth = parseInt(canvas.style.width);
8359
let sHeight = parseInt(canvas.style.height);
8460

@@ -107,19 +83,27 @@ function initL2D() {
10783
deviceToScreen.multTranslate(-sWidth / 2.0, -sHeight / 2.0); // #32
10884
deviceToScreen.multScale(2 / sWidth, -2 / sHeight); // #32
10985

110-
gl = getWebGLContext();
111-
setContext(gl);
112-
if (!gl) { // Check if WebGL element is created successfully.
113-
console.error("Failed to create WebGL context.");
114-
if(!window.WebGLRenderingContext){
115-
console.error("Your browser don't support WebGL, check https://get.webgl.org/ for futher information.");
116-
}
117-
return;
118-
}
119-
window.Live2D.setGL(gl);
120-
gl.clearColor(0.0, 0.0, 0.0, 0.0);
121-
changeModel(modelUrl);
86+
87+
Live2D.setGL(currWebGL);
88+
currWebGL.clearColor(0.0, 0.0, 0.0, 0.0);
89+
changeModel(config.model.jsonPath);
12290
startDraw();
91+
92+
}
93+
94+
95+
function initEvent(){/*
96+
canvas = document.getElementById(canvasId);
97+
if (canvas.addEventListener) {
98+
window.addEventListener("click", mouseEvent);
99+
window.addEventListener("mousedown", mouseEvent);
100+
window.addEventListener("mousemove", mouseEvent);
101+
window.addEventListener("mouseup", mouseEvent);
102+
document.addEventListener("mouseleave", mouseEvent);
103+
window.addEventListener("touchstart", touchEvent);
104+
window.addEventListener("touchend", touchEvent);
105+
window.addEventListener("touchmove", touchEvent);
106+
}*/
123107
}
124108

125109
function startDraw() {
@@ -145,7 +129,7 @@ function draw()
145129
dragMgr.update();
146130
live2DMgr.setDrag(dragMgr.getX(), dragMgr.getY());
147131

148-
gl.clear(gl.COLOR_BUFFER_BIT);
132+
currWebGL.clear(currWebGL.COLOR_BUFFER_BIT);
149133

150134
MatrixStack.multMatrix(projMatrix.getArray());
151135
MatrixStack.multMatrix(viewMatrix.getArray());
@@ -160,7 +144,7 @@ function draw()
160144
if (model.initialized && !model.updating)
161145
{
162146
model.update();
163-
model.draw(gl);
147+
model.draw(currWebGL);
164148
}
165149
}
166150
MatrixStack.pop();
@@ -170,7 +154,7 @@ function changeModel(modelurl) // 更换模型
170154
{
171155
live2DMgr.reloadFlg = true;
172156
live2DMgr.count++; // 现在仍有多模型支持,稍后可以精简
173-
live2DMgr.changeModel(gl, modelurl);
157+
live2DMgr.changeModel(currWebGL, modelurl);
174158
}
175159

176160
function modelScaling(scale) {
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)