33 */
44
55
6- /* import {
6+ import {
77 UtSystem ,
88 UtDebug ,
99 LDTransform ,
1919 DrawDataID ,
2020 BaseDataID ,
2121 ParamID
22- } from './lib/live2d.min';*/ /*
23- import './lib/live2d.min.js';
22+ } from './lib/live2d.core' ; /*
2423import { device } from 'current-device';
2524import { L2DTargetPoint, L2DViewMatrix, L2DMatrix44 } from "./lib/Live2DFramework";
2625import cManager from "./cManager";
@@ -29,7 +28,6 @@ import { cDefine } from "./cDefine";
2928
3029const live2DMgr = new cManager();
3130let isDrawStart = false;
32- let gl = null;
3331let canvas = null;
3432let dragMgr = null;
3533let viewMatrix = null;
@@ -44,7 +42,7 @@ let opacityHover = 1;
4442*/
4543
4644import { 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
5452export 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
125109function 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
176160function modelScaling ( scale ) {
0 commit comments