1- var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
2- function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
3- return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
4- function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
5- function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
6- function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
7- step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
8- } ) ;
9- } ;
101import { L2DMatrix44 , L2DTargetPoint , L2DViewMatrix } from './Live2DFramework.js' ;
112import LAppDefine from './LAppDefine.js' ;
123import MatrixStack from './utils/MatrixStack.js' ;
@@ -60,37 +51,35 @@ class Cubism2Model {
6051 this . canvas . addEventListener ( 'touchmove' , this . _boundTouchEvent , false ) ;
6152 }
6253 }
63- init ( canvasId , modelSettingPath , modelSetting ) {
64- return __awaiter ( this , void 0 , void 0 , function * ( ) {
65- this . initL2dCanvas ( canvasId ) ;
66- const width = this . canvas . width ;
67- const height = this . canvas . height ;
68- this . dragMgr = new L2DTargetPoint ( ) ;
69- const ratio = height / width ;
70- const left = LAppDefine . VIEW_LOGICAL_LEFT ;
71- const right = LAppDefine . VIEW_LOGICAL_RIGHT ;
72- const bottom = - ratio ;
73- const top = ratio ;
74- this . viewMatrix = new L2DViewMatrix ( ) ;
75- this . viewMatrix . setScreenRect ( left , right , bottom , top ) ;
76- this . viewMatrix . setMaxScreenRect ( LAppDefine . VIEW_LOGICAL_MAX_LEFT , LAppDefine . VIEW_LOGICAL_MAX_RIGHT , LAppDefine . VIEW_LOGICAL_MAX_BOTTOM , LAppDefine . VIEW_LOGICAL_MAX_TOP ) ;
77- this . viewMatrix . setMaxScale ( LAppDefine . VIEW_MAX_SCALE ) ;
78- this . viewMatrix . setMinScale ( LAppDefine . VIEW_MIN_SCALE ) ;
79- this . projMatrix = new L2DMatrix44 ( ) ;
80- this . projMatrix . multScale ( 1 , width / height ) ;
81- this . deviceToScreen = new L2DMatrix44 ( ) ;
82- this . deviceToScreen . multTranslate ( - width / 2.0 , - height / 2.0 ) ;
83- this . deviceToScreen . multScale ( 2 / width , - 2 / width ) ;
84- this . gl = this . canvas . getContext ( 'webgl2' , { premultipliedAlpha : true , preserveDrawingBuffer : true } ) ;
85- if ( ! this . gl ) {
86- logger . error ( 'Failed to create WebGL context.' ) ;
87- return ;
88- }
89- Live2D . setGL ( this . gl ) ;
90- this . gl . clearColor ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
91- yield this . changeModelWithJSON ( modelSettingPath , modelSetting ) ;
92- this . startDraw ( ) ;
93- } ) ;
54+ async init ( canvasId , modelSettingPath , modelSetting ) {
55+ this . initL2dCanvas ( canvasId ) ;
56+ const width = this . canvas . width ;
57+ const height = this . canvas . height ;
58+ this . dragMgr = new L2DTargetPoint ( ) ;
59+ const ratio = height / width ;
60+ const left = LAppDefine . VIEW_LOGICAL_LEFT ;
61+ const right = LAppDefine . VIEW_LOGICAL_RIGHT ;
62+ const bottom = - ratio ;
63+ const top = ratio ;
64+ this . viewMatrix = new L2DViewMatrix ( ) ;
65+ this . viewMatrix . setScreenRect ( left , right , bottom , top ) ;
66+ this . viewMatrix . setMaxScreenRect ( LAppDefine . VIEW_LOGICAL_MAX_LEFT , LAppDefine . VIEW_LOGICAL_MAX_RIGHT , LAppDefine . VIEW_LOGICAL_MAX_BOTTOM , LAppDefine . VIEW_LOGICAL_MAX_TOP ) ;
67+ this . viewMatrix . setMaxScale ( LAppDefine . VIEW_MAX_SCALE ) ;
68+ this . viewMatrix . setMinScale ( LAppDefine . VIEW_MIN_SCALE ) ;
69+ this . projMatrix = new L2DMatrix44 ( ) ;
70+ this . projMatrix . multScale ( 1 , width / height ) ;
71+ this . deviceToScreen = new L2DMatrix44 ( ) ;
72+ this . deviceToScreen . multTranslate ( - width / 2.0 , - height / 2.0 ) ;
73+ this . deviceToScreen . multScale ( 2 / width , - 2 / width ) ;
74+ this . gl = this . canvas . getContext ( 'webgl2' , { premultipliedAlpha : true , preserveDrawingBuffer : true } ) ;
75+ if ( ! this . gl ) {
76+ logger . error ( 'Failed to create WebGL context.' ) ;
77+ return ;
78+ }
79+ Live2D . setGL ( this . gl ) ;
80+ this . gl . clearColor ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
81+ await this . changeModelWithJSON ( modelSettingPath , modelSetting ) ;
82+ this . startDraw ( ) ;
9483 }
9584 destroy ( ) {
9685 if ( this . canvas ) {
@@ -148,15 +137,11 @@ class Cubism2Model {
148137 }
149138 MatrixStack . pop ( ) ;
150139 }
151- changeModel ( modelSettingPath ) {
152- return __awaiter ( this , void 0 , void 0 , function * ( ) {
153- yield this . live2DMgr . changeModel ( this . gl , modelSettingPath ) ;
154- } ) ;
140+ async changeModel ( modelSettingPath ) {
141+ await this . live2DMgr . changeModel ( this . gl , modelSettingPath ) ;
155142 }
156- changeModelWithJSON ( modelSettingPath , modelSetting ) {
157- return __awaiter ( this , void 0 , void 0 , function * ( ) {
158- yield this . live2DMgr . changeModelWithJSON ( this . gl , modelSettingPath , modelSetting ) ;
159- } ) ;
143+ async changeModelWithJSON ( modelSettingPath , modelSetting ) {
144+ await this . live2DMgr . changeModelWithJSON ( this . gl , modelSettingPath , modelSetting ) ;
160145 }
161146 modelScaling ( scale ) {
162147 const isMaxScale = this . viewMatrix . isMaxScale ( ) ;
@@ -174,7 +159,7 @@ class Cubism2Model {
174159 }
175160 }
176161 modelTurnHead ( event ) {
177- var _a ;
162+ var _b ;
178163 const rect = this . canvas . getBoundingClientRect ( ) ;
179164 const { vx, vy } = normalizePoint ( event . clientX , event . clientY , rect . left + rect . width / 2 , rect . top + rect . height / 2 , window . innerWidth , window . innerHeight ) ;
180165 logger . trace ( 'onMouseDown device( x:' +
@@ -188,12 +173,12 @@ class Cubism2Model {
188173 ')' ) ;
189174 this . dragMgr . setPoint ( vx , vy ) ;
190175 this . live2DMgr . tapEvent ( vx , vy ) ;
191- if ( ( _a = this . live2DMgr ) === null || _a === void 0 ? void 0 : _a . model . hitTest ( LAppDefine . HIT_AREA_BODY , vx , vy ) ) {
176+ if ( ( _b = this . live2DMgr ) === null || _b === void 0 ? void 0 : _b . model . hitTest ( LAppDefine . HIT_AREA_BODY , vx , vy ) ) {
192177 window . dispatchEvent ( new Event ( 'live2d:tapbody' ) ) ;
193178 }
194179 }
195180 followPointer ( event ) {
196- var _a ;
181+ var _b ;
197182 const rect = this . canvas . getBoundingClientRect ( ) ;
198183 const { vx, vy } = normalizePoint ( event . clientX , event . clientY , rect . left + rect . width / 2 , rect . top + rect . height / 2 , window . innerWidth , window . innerHeight ) ;
199184 logger . trace ( 'onMouseMove device( x:' +
@@ -206,7 +191,7 @@ class Cubism2Model {
206191 vy +
207192 ')' ) ;
208193 this . dragMgr . setPoint ( vx , vy ) ;
209- if ( ( _a = this . live2DMgr ) === null || _a === void 0 ? void 0 : _a . model . hitTest ( LAppDefine . HIT_AREA_BODY , vx , vy ) ) {
194+ if ( ( _b = this . live2DMgr ) === null || _b === void 0 ? void 0 : _b . model . hitTest ( LAppDefine . HIT_AREA_BODY , vx , vy ) ) {
210195 window . dispatchEvent ( new Event ( 'live2d:hoverbody' ) ) ;
211196 }
212197 }
0 commit comments