-
Notifications
You must be signed in to change notification settings - Fork 1
/
Live2DInterfaceMV.js
1543 lines (1314 loc) · 49.2 KB
/
Live2DInterfaceMV.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/
/* 更新履歴
* Slip 2020/01/20 ツクールMV用プラグイン向けに修正
* Slip 2021/09/02 戦闘シーンでのレイヤーを可変にする(スペシャルサンクス:こまさん@koma_neko)
*
* 本プラグインの再配布、改変はLive2D Open Software licenseに準拠します。
*
* Live2D Open Software 使用許諾契約書
* https://www.live2d.com/eula/live2d-open-software-license-agreement_jp.html
*/
/*:
* @plugindesc Plug-in that displays live2d on Maker MV
* ツクールMV上でlive2dを立ち絵表示するプラグイン
* @author Slip
*
* @param ModelPosition
* @type note
* @default Model placement
* @desc Model placement
* モデル配置
*
* @param ModelScaling
* @type note
* @default Scale model
* @desc Scale model
* モデルの拡大・縮小
*
* @param PlayBack
* @type note
* @default Motion playback
* @desc Motion playback
* モーション再生
*
* @param Screen
* @type note
* @default screen
* @desc screen
* 画面
*
* @param Scene
* @type note
* @default Scenes such as maps and battle screens
* @desc Scenes such as maps and battle screens
* マップ、戦闘画面等のシーン
*
* @param SaveData
* @type note
* @default Save data
* @desc Save data
* セーブデータ
*
* @param LinkEquipment
* @type note
* @default Linked setting with equipment
* @desc Linked setting with equipment.
* 装備品との連動設定
*
* @param upsidedown
* @type boolean
* @desc Upside down display
* 上下反転表示
* @default false
* @parent Screen
*
* @param displayOrder
* @type boolean
* @desc model stacking order.
* モデルの重なり順番。
* @default false
* @parent Screen
*
* @param playbackSpeed
* @type number
* @desc Playback speed
* 再生速度
* @default 8
* @parent PlayBack
*
* @param AdjustWeight
* @type number
* @desc Deformation weight adjustment parameter
* 変形の重み調整パラメータ
* @default 8
* @parent PlayBack
*
* @param ScaleGain
* @type number
* @desc Scaling growth rate
* 拡大縮小の増加率
* @default 2
* @parent ModelScaling
*
* @param vertical
* @type number
* @desc Vertical display position
* 縦の表示位置
* @default 320
* @min 0
* @max 640
* @parent ModelPosition
*
* @param left
* @type number
* @desc Horizontal display position (left)
* 横の表示位置(左)
* @default 100
* @min 0
* @max 816
* @parent ModelPosition
*
* @param middle
* @type number
* @desc Horizontal display position (center)
* 横の表示位置(中央)
* @default 408
* @min 0
* @max 816
* @parent ModelPosition
*
* @param right
* @type number
* @desc Horizontal display position (right)
* 横の表示位置(右)
* @default 716
* @min 0
* @max 816
* @parent ModelPosition
*
* @param includesave
* @desc Include the display status of live2d in save data
* live2dの表示状況をセーブデータに含める
* @default true
* @type boolean
* @parent SaveData
*
* @param useinbattle
* @desc use flag in battle scene
* 戦闘画面でのlive2dモデル使用フラグ
* @default false
* @type boolean
* @parent Scene
*
* @param IsBehindEnemies
* @desc Display the Live2d model behind the enemy graphic
* 戦闘画面での敵グラフィックの奥にLive2dモデルを表示する(trueは敵グラフィックの手前に表示)
* @default true
* @type boolean
* @parent Scene
*
* @param pictpriority
* @type number
* @desc The live2d model is displayed before the picture below this ID.
* このID以下のピクチャよりも手前にlive2dのモデルを表示します。
* @min 0
* @max 100
* @default 10
* @parent Screen
*
* @param useLinkEquipment
* @desc use flag LinkEquipment.
* 装備品との連動フラグ
* @default false
* @type boolean
* @parent LinkEquipment
*
* @param Modelcondition
* @desc live2d model individual setting
* live2dモデル個別設定
* @default
* @type struct<ModelconditionData>[]
*
*
* @help
* [English]
* live2d standing picture display plugin ver1.0.0
*
* It is a plug-in that displays a live2d (cubism 4.0) model while standing and talking.
*
* Usage:
* ↓ It is described here.
* https://github.com/MrSlip777/plugins_talk_live2d_cubism4/blob/master/README_en.md
*
* [日本語]
* live2d立ち絵表示プラグイン ver1.0.0
*
* live2d(cubism4.0)のモデルを会話中に立ち絵表示するプラグインです。
*
* 使い方:
* ↓こちらに記載しています。
* https://github.com/MrSlip777/plugins_talk_live2d_cubism4/blob/master/README.md
*/
/*~struct~ModelconditionData:
* @param Modelname
* @desc The name of the model used in the plugin command
* プラグインコマンドで使用するモデルの名前
* @default
*
* @param folderpath
* @desc folder path of model3.json file
* model3.jsonファイルのフォルダパス
* @default
*
* @param motiongroupnames
* @desc You can set the name of the motion.
* モーションの名称を設定できます。
* @type note
* @default "<basic:Idle_1,Idle_3>\n<angry:Idle_4>"
* @param individual_upsidedown
* @type boolean
* @desc Individual upside down flag
* 個々の上下反転フラグ
* @default false
*
* @param SettingLinkEquipment
* @type note
* @default 装備とのモーション連動設定
* @desc Linked setting with equipment.
* 装備とのモーション連動設定
*
* @param noWeapon
* @desc Motion without weapon.
* 武器なし時のモーション
* @default
* @parent SettingLinkEquipment
*
* @param noShield
* @desc Motion without shield.
* 盾なし時のモーション
* @default
* @parent SettingLinkEquipment
*
* @param noHead
* @desc Motion without head armor.
* 頭防具なし時のモーション
* @default
* @parent SettingLinkEquipment
*
* @param noBody
* @desc Motion without body armor.
* 体防具なし時のモーション
* @default
* @parent SettingLinkEquipment
*
* @param noOrnament
* @desc Motion without ornaments.
* 装飾品なし時のモーション
* @default
* @parent SettingLinkEquipment
*
*/
function parseStrToBoolean(str) {
// 文字列を判定
return (str == 'true') ? true : false;
}
const L2DINstringifyReplacer = function(key, value) {
if(value === 'null') return value;
try{
return JSON.parse(value);
}catch(e){
return value;
}
};
//設定値がある場合にはそれは配列になる。
const L2DINextractmeta = function(data) {
const req = /<([^<>:]+)(:?)([^>]*)>/g;
data.meta = {};
for (var i = 0; i < 1000; i++) {
var match = req.exec(data.motiongroupnames);
if (!!match) {
if (match[2] === ':') {
data.meta[match[1]] = match[3].split(', ');
} else {
data.meta[match[1]] = true;
}
} else {
break;
}
}
};
const L2DINfindnameindex = function(name) {
return L2DINmodels.findIndex(function(data){
return data.Modelname === name;
});
};
const L2DINgetmetaarray = function(data, tag) {
const meta = data.meta[tag];
if(!meta || meta === true){
return [];
}
return meta;
};
const L2DINPP = PluginManager.parameters('Live2DInterfaceMV');
const L2DINleft = Number(L2DINPP['left']) || 0;
const L2DINmiddle = Number(L2DINPP['middle']) || 0;
const L2DINright = Number(L2DINPP['right']) || 0;
const L2DINvertical = Number(L2DINPP['vertical']) || 0;
const L2DINscaleX = Number(L2DINPP['scale_V']) / 100;
const L2DINscaleY = Number(L2DINPP['scale_H']) / 100;
const L2DINincludesave = (L2DINPP['includesave'] === 'true');
const L2DINuseinbattle = (L2DINPP['useinbattle'] === 'true');
const L2DINIsBehindEnemies = (L2DINPP['IsBehindEnemies'] === 'true');
const L2DINuseLinkEquipment = (L2DINPP['useLinkEquipment'] === 'true');
const L2DINpictpriority = Number(L2DINPP['pictpriority']) || 0;
const L2DINdisplayOrder = (L2DINPP['displayOrder'] === 'true');
//Array型、各要素はobject
const L2DINmodels = JSON.parse(JSON.stringify(L2DINPP['Modelcondition'], L2DINstringifyReplacer));
L2DINmodels.forEach(function(Ldata) {
L2DINextractmeta(Ldata);
});
//他仕様定義
const model3expend = '.model3.json';
const motion3expend = '.motion3.json';
const L2DINgrawidth = 816;
const L2DINgraheight = 640;
//再生速度
const L2DINPlaybackSpeed = Number(L2DINPP['playbackSpeed']) / 10;
//重み調整
const AdjustWeight = Number(L2DINPP['AdjustWeight']) / 10;
const ScaleGain = Number(L2DINPP['ScaleGain']);
//Game_Live2dの追加
function Game_Live2d() {
this.initialize.apply(this, arguments);
}
Game_Live2d.prototype.initialize = function() {
this.clear();
};
//マジックナンバーだと分かりにくいのでパラメータ設定のモデル名をkeyにする。
Game_Live2d.prototype.clear = function() {
var parameters = PluginManager.parameters('Live2DInterfaceMV');
//エディタ(プラグインの設定)から取得する設定値
this._folderpath= {};
this._name = {};
this._model = {};
this._pos_left = Number(parameters['left']);
this._pos_middle = Number(parameters['middle']);
this._pos_right = Number(parameters['right']);
this._pos_vertical = Number(parameters['vertical']);
this._IsUpsidedown = parseStrToBoolean(parameters['upsidedown']);
//コマンド経由の設定値(ここでは初期値を設定する)
this.visible = {}; //モデルの表示、非表示
this.pos_x ={}; //モデルのX位置
this.pos_y ={}; //モデルのY位置
this._targetX ={}; //モデルのX目標位置
this._targetY ={}; //モデルのY目標位置
this._targetScale ={}; //モデルの目標スケール
this._duration ={}; //移動する時間
this._live2dmodelsaveonly = {}; //セーブ用データ
//モーション関係のデータ (セーブデータの保存、読み込み用として必要)
this.motionGroup = {};
this.motionNumber = {};
this.motionLoop = {};
this.paraminitskip = {};
this.meta = {};
this.scale = {}; //スケール
this.A = {};
this.R = {};
this.G = {};
this.B = {};
this._waitCount = 0;
//個々の上下反転フラグ(全体のフラグ、または個々のフラグがtrueになっていると上下反転の表示)
this.individual_upsidedown = {};
//装備品、衣装変更時に使用。装備なし時のモーション
this.linkEquip_None = {};
this.InitializeModelSetting();
//内部変数
//Cubism4対応 Slip 2020/01/13
this._textureManager = new LAppTextureManager();
this.gl = null;
this.canvas = null;
this._lappLive2dManager = null;
};
//各モデル設定値の初期化
Game_Live2d.prototype.InitializeModelSetting = function(){
var i = 1;
var data_no = L2DINmodels.length;
L2DINmodels.forEach(function(data) {
if(L2DINdisplayOrder){
data_no = L2DINmodels.length - i + 1;
}
else{
data_no = i;
}
this._folderpath[data_no] = data.folderpath;
this._name[data_no] = data.Modelname;
var strCopy = data.folderpath.split('/');
this._model[data_no] = strCopy[strCopy.length - 2];
this.visible[data_no] = false;
this.scale[data_no] = 1.0;
this.A[data_no] = 1.0;
this.R[data_no] = 1.0;
this.G[data_no] = 1.0;
this.B[data_no] = 1.0;
this._duration[data_no] = 0;
this.pos_x[data_no] =this._pos_middle;
this.pos_y[data_no] = 0;
this.motionGroup[data_no] = "Idle";
this.motionNumber[data_no] = 1;
this.motionLoop[data_no] = false;
this.paraminitskip[data_no] = false;
this.meta[data_no] = data.meta;
//個々の上下反転フラグ(全体のフラグ、または個々のフラグがtrueになっていると上下反転の表示)
this.individual_upsidedown[data_no] = data.individual_upsidedown;
//装備品、衣装変更時に使用。装備なし時のモーション
this.linkEquip_None[data_no] = {};
this.linkEquip_None[data_no][0] = data.noWeapon;
this.linkEquip_None[data_no][1] = data.noShield;
this.linkEquip_None[data_no][2] = data.noHead;
this.linkEquip_None[data_no][3] = data.noBody;
this.linkEquip_None[data_no][4] = data.noOrnament;
//セーブ用のlve2dデータ保存場所
this._live2dmodelsaveonly[data_no] = {};
i++;
}, this);
this.MAXNUMBER = L2DINmodels.length;
};
//セーブデータの設定値をモデルに反映
Game_Live2d.prototype.ReflectSavedataToReadsetting = function(){
for(var i = 1; i<=Object.keys($gameLive2d._name).length; i++){
var saveobj = this._live2dmodelsaveonly[i];
if(saveobj.name){
$gameLive2d._model[i] = saveobj.model;
$gameLive2d._name[i] = saveobj.name;
$gameLive2d._folderpath[i] = saveobj.folderpath;
$gameLive2d.individual_upsidedown[i] = saveobj.individual_upsidedown;
$gameLive2d.linkEquip_None[i][0] = saveobj.noWeapon;
$gameLive2d.linkEquip_None[i][1] = saveobj.noShield;
$gameLive2d.linkEquip_None[i][2] = saveobj.noHead;
$gameLive2d.linkEquip_None[i][3] = saveobj.noBody;
$gameLive2d.linkEquip_None[i][4] = saveobj.noOrnament;
}
}
};
//セーブデータの設定値をモデルに反映
Game_Live2d.prototype.ReflectSavedataToModels = function(){
for(var i = 1; i<=Object.keys($gameLive2d._name).length; i++){
var saveobj = this._live2dmodelsaveonly[i];
if(saveobj.name){
this.visible[i] = saveobj.visible;
this.scale[i] = saveobj.scale;
this.pos_x[i] = saveobj.pos_x;
this.pos_y[i] = saveobj.pos_y;
$gameLive2d._lappLive2dManager._models.at(i-1).motionGroup_Default
= saveobj.motionGroup;
$gameLive2d._lappLive2dManager._models.at(i-1).motionNumber_Default
= saveobj.motionNumber;
$gameLive2d._lappLive2dManager._models.at(i-1).motionLoop_Default
= saveobj.motionLoop;
$gameLive2d._lappLive2dManager._models.at(i-1).paraminitskip_Default
= saveobj.paraminitskip;
$gameLive2d.meta[i] = saveobj.meta;
}
}
};
//ニューゲームの時に前回セーブしたときの影響が残らないように
Game_Live2d.prototype.newgamefix = function() {
for(var i = 1; i<=Object.keys($gameLive2d._name).length; i++){
var saveobj = this._live2dmodelsaveonly[i];
if(saveobj.Modelname){
saveobj.isneedrestore = false;
}
}
this.InitializeModelSetting();
};
//モデルの全ての情報をセーブするわけではないことに注意。
Game_Live2d.prototype.Createsavemodel = function() {
//dataではなくgamelive2dの設定値が現状の値のため、名前ではなく番号で管理する
for(var i = 1; i<=Object.keys($gameLive2d._name).length; i++){
var saveobj = this._live2dmodelsaveonly[i];
//以下はゲーム開始時に設定する変数
saveobj.name = $gameLive2d._name[i];
saveobj.model = $gameLive2d._model[i];
saveobj.folderpath = $gameLive2d._folderpath[i];
saveobj.individual_upsidedown = $gameLive2d.individual_upsidedown[i];
saveobj.noWeapon = $gameLive2d.linkEquip_None[i][0];
saveobj.noShield = $gameLive2d.linkEquip_None[i][1];
saveobj.noHead = $gameLive2d.linkEquip_None[i][2];
saveobj.noBody = $gameLive2d.linkEquip_None[i][3];
saveobj.noOrnament = $gameLive2d.linkEquip_None[i][4];
saveobj.isneedrestore = true;
//以下は動的変数
saveobj.pos_x = $gameLive2d.pos_x[i];
saveobj.pos_y = $gameLive2d.pos_y[i];
saveobj.scale = $gameLive2d.scale[i];
saveobj.visible = $gameLive2d.visible[i];
saveobj.motionGroup = $gameLive2d.motionGroup[i];
saveobj.motionNumber = $gameLive2d.motionNumber[i];
saveobj.motionLoop = $gameLive2d.motionLoop[i];
saveobj.paraminitskip = $gameLive2d.paraminitskip[i];
saveobj.meta = $gameLive2d.meta[i];
}
return this._live2dmodelsaveonly;
};
//loaderより先に実行されることに注意。
Game_Live2d.prototype.Restoresavemodel = function(saveobj) {
this._live2dmodelsaveonly = saveobj;
};
//各シーンのupdateで呼ぶ
Game_Live2d.prototype.live2dupdate = function () {
L2DINmodels.forEach(function(targetobj) {
var model = this._live2dmodel[targetobj.Modelname];
if(model !== null){
this.live2dupdateMove(model);
}
}, this);
};
//Cubism4対応 Slip 2020/01/13
Game_Live2d.prototype.getTextureManager = function () {
return this._textureManager;
};
//各シーンのupdateで呼ぶ
Game_Live2d.prototype.live2dupdate = function () {
L2DINmodels.forEach(function(targetobj) {
var model_no = 1;
for(var number in $gameLive2d._name){
if($gameLive2d._name[number] == targetobj.Modelname){
break;
}
model_no++;
}
var model = $gameLive2d._lappLive2dManager._models.at(model_no-1);
if(model !== null){
this.live2dupdateMove(model_no);
}
}, this);
};
Game_Live2d.prototype.wait = function(dur) {
this._waitCount = dur;
};
//移動する
Game_Live2d.prototype.live2dupdateMove = function(model_no) {
var d = $gameLive2d._duration[model_no];
if (d > 0) {
$gameLive2d.pos_x[model_no]
= ($gameLive2d.pos_x[model_no] * (d - 1) + $gameLive2d._targetX[model_no]) / d;
$gameLive2d.pos_y[model_no]
= ($gameLive2d.pos_y[model_no] * (d - 1) + $gameLive2d._targetY[model_no]) / d;
$gameLive2d.scale[model_no]
= ($gameLive2d.scale[model_no] * (d - 1) + $gameLive2d._targetScale[model_no]) / d;
$gameLive2d._duration[model_no]--;
}
};
//内部のモーション名
Game_Live2d.prototype.InnerMotionName = function (name, group){
const index = L2DINfindnameindex(name);
if(index >= 0){
const innerMotionName = L2DINgetmetaarray(L2DINmodels[index], group);
return innerMotionName;
}else{
return null;
}
};
var $gameLive2d = null;
//---モデル描画するキャンバス設定---
function Live2DSprite(){
this.initialize.apply(this, arguments);
}
Live2DSprite.prototype = Object.create(Sprite.prototype);
Live2DSprite.prototype.constructor = Live2DSprite;
Live2DSprite.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this._cubismOption = new Live2DCubismFramework.Option();
this.modelReady = false;
this.frameBuffer = null;
this._programId = null;
this.onModelReady = [];
this.texture = null;
/* 上下逆転対策(暫定)
*/
this.scale.y *= -1;
this.anchor.y = 1;
};
/**
* 解放する。
*/
Live2DSprite.prototype.release = function () {
// リソースを解放する → 開放しないへ変更(ゲーム終了時まで)
//LAppLive2DManager.releaseInstance();
//$gameLive2d._lappLive2dManager = null;
// Cubism SDKの解放
Csm_CubismFramework.dispose();
};
/**
* シェーダーを登録する。
*/
Live2DSprite.prototype.createShader = function () {
// バーテックスシェーダーのコンパイル
var vertexShaderId = $gameLive2d.gl.createShader($gameLive2d.gl.VERTEX_SHADER);
if (vertexShaderId == null) {
LAppPal.printLog("failed to create vertexShader");
return null;
}
var vertexShader = "precision mediump float;" +
"attribute vec3 position;" +
"attribute vec2 uv;" +
"varying vec2 vuv;" +
"void main(void)" +
"{" +
" gl_Position = vec4(position, 1.0);" +
" vuv = uv;" +
"}";
$gameLive2d.gl.shaderSource(vertexShaderId, vertexShader);
$gameLive2d.gl.compileShader(vertexShaderId);
// フラグメントシェーダのコンパイル
var fragmentShaderId = $gameLive2d.gl.createShader($gameLive2d.gl.FRAGMENT_SHADER);
if (fragmentShaderId == null) {
LAppPal.printLog("failed to create fragmentShader");
return null;
}
var fragmentShader = "precision mediump float;" +
"varying vec2 vuv;" +
"uniform sampler2D texture;" +
"void main(void)" +
"{" +
" gl_FragColor = texture2D(texture, vuv);" +
"}";
$gameLive2d.gl.shaderSource(fragmentShaderId, fragmentShader);
$gameLive2d.gl.compileShader(fragmentShaderId);
// プログラムオブジェクトの作成
var programId = $gameLive2d.gl.createProgram();
$gameLive2d.gl.attachShader(programId, vertexShaderId);
$gameLive2d.gl.attachShader(programId, fragmentShaderId);
$gameLive2d.gl.deleteShader(vertexShaderId);
$gameLive2d.gl.deleteShader(fragmentShaderId);
// リンク
$gameLive2d.gl.linkProgram(programId);
$gameLive2d.gl.useProgram(programId);
return programId;
};
/* Live2DSpriteが持つWebGLテクスチャを利用してオフスクリーンレンダリング用のフレームバッファを作成
* this.texture.baseTexture._glTextures[0].texture ← これがWebGLテクスチャ
*/
Live2DSprite.prototype.createFramebuffer = function(renderer) {
if (!this.texture || !this.texture.baseTexture || !this.texture.baseTexture._glTextures[0]) {
return;
}
let gl = renderer.gl;
let glTexture = this.texture.baseTexture._glTextures[0];
let texture = glTexture.texture;
let _frameBuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
this.frameBuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, _frameBuffer);
};
Live2DSprite.prototype._renderWebGL = function(renderer) {
$gameLive2d.gl = renderer.gl;
$gameLive2d.canvas = renderer.view;
if (!this.frameBuffer) {
/* オフスクリーンレンダリング用のフレームバッファを作成
*/
// this.frameBuffer = $gameLive2d.gl.getParameter($gameLive2d.gl.FRAMEBUFFER_BINDING);
this.createFramebuffer(renderer);
}
// 透過設定
//$gameLive2d.gl.enable($gameLive2d.gl.BLEND);
//$gameLive2d.gl.blendFunc($gameLive2d.gl.SRC_ALPHA, $gameLive2d.gl.ONE_MINUS_SRC_ALPHA);
if (!this.modelReady) {
const gl = renderer.gl;
// it is unreasonable how the next line works...
gl.activeTexture(gl.TEXTURE0);
this.texture
= PIXI.RenderTexture.create($gameLive2d.canvas.width, $gameLive2d.canvas.height);
this.createShader();
this.modelReady = true;
return;
}
while (this.onModelReady.length) {
const func = this.onModelReady.shift();
func();
}
if (!this.visible) {
return;
}
const useVAO = !!(renderer.createVao && renderer.bindVao);
var _activeVao;
//let _activeVao; Slip 2017/03/24
if (useVAO) {
_activeVao = renderer._activeVao;
} else {
renderer.flush();
}
var temp_gl = renderer.gl;
const arrayBuffer = temp_gl.getParameter(temp_gl.ARRAY_BUFFER_BINDING);
const elementArrayBuffer = temp_gl.getParameter(temp_gl.ELEMENT_ARRAY_BUFFER_BINDING);
const currentProgram = temp_gl.getParameter(temp_gl.CURRENT_PROGRAM);
var activeTexture;
//let activeTexture; Slip 2017/03/24
if (!useVAO) {
activeTexture = temp_gl.getParameter(temp_gl.ACTIVE_TEXTURE);
}
temp_gl.activeTexture(temp_gl.TEXTURE0);
const texture0 = temp_gl.getParameter(temp_gl.TEXTURE_BINDING_2D);
temp_gl.activeTexture(temp_gl.TEXTURE1);
const texture1 = temp_gl.getParameter(temp_gl.TEXTURE_BINDING_2D);
const frontFace = temp_gl.getParameter(temp_gl.FRONT_FACE);
const colorWhiteMask = temp_gl.getParameter(temp_gl.COLOR_WRITEMASK);
//Slip 2017/03/24
var vertexAttr0Enabled, vertexAttr1Enabled, vertexAttr2Enabled, vertexAttr3Enabled;
if (!useVAO) {
vertexAttr0Enabled = temp_gl.getVertexAttrib(0, temp_gl.VERTEX_ATTRIB_ARRAY_ENABLED);
vertexAttr1Enabled = temp_gl.getVertexAttrib(1, temp_gl.VERTEX_ATTRIB_ARRAY_ENABLED);
vertexAttr2Enabled = temp_gl.getVertexAttrib(2, temp_gl.VERTEX_ATTRIB_ARRAY_ENABLED);
vertexAttr3Enabled = temp_gl.getVertexAttrib(3, temp_gl.VERTEX_ATTRIB_ARRAY_ENABLED);
}
const scissorTestEnabled = temp_gl.isEnabled(temp_gl.SCISSOR_TEST);
const stencilTestEnabled = temp_gl.isEnabled(temp_gl.STENCIL_TEST);
const depthTestEnabled = temp_gl.isEnabled(temp_gl.DEPTH_TEST);
const cullFaceEnabled = temp_gl.isEnabled(temp_gl.CULL_FACE);
const blendEnabled = temp_gl.isEnabled(temp_gl.BLEND);
const _activeTextureLocation = renderer._activeTexture ? renderer._activeTextureLocation : 0;
const _activeRenderTarget = renderer._activeRenderTarget;
var vao;
if (useVAO) {
vao = renderer.createVao();
renderer.bindVao(vao);
}
renderer.bindRenderTexture(this.texture);
/* 描画先をLive2DSpriteが持つフレームバッファに変更して描画処理を実行
* this.frameBufferの準備ができていなければ描画処理は飛ばす
*/
if (this.frameBuffer) {
// 本来の描画先(フレームバッファ)を取っておく
let _frameBuffer = temp_gl.getParameter(temp_gl.FRAMEBUFFER_BINDING);
// 描画先を変更
temp_gl.bindFramebuffer(temp_gl.FRAMEBUFFER, this.frameBuffer);
// onUpdateの処理の中で必要なので入れておく
$gameLive2d.frameBuffer = this.frameBuffer;
temp_gl.clearColor(0.0, 0.0, 0.0, 0.0);
temp_gl.clear(temp_gl.COLOR_BUFFER_BIT);
temp_gl.frontFace(temp_gl.CW);
if($gameLive2d._lappLive2dManager){
LAppPal.updateTime();
$gameLive2d.gl.flush();
$gameLive2d._lappLive2dManager.onUpdate();
}
// 本来の描画先に戻す
temp_gl.bindFramebuffer(temp_gl.FRAMEBUFFER, _frameBuffer);
}
if (!useVAO) {
renderer._activeTextureLocation = _activeTextureLocation;
temp_gl.activeTexture(temp_gl.TEXTURE0 + _activeTextureLocation);
}
temp_gl.bindTexture(temp_gl.TEXTURE_2D, null);
temp_gl.useProgram(currentProgram);
renderer.bindRenderTarget(_activeRenderTarget);
temp_gl.bindBuffer(temp_gl.ARRAY_BUFFER, arrayBuffer);
temp_gl.bindBuffer(temp_gl.ELEMENT_ARRAY_BUFFER, elementArrayBuffer);
temp_gl.activeTexture(temp_gl.TEXTURE0);
temp_gl.bindTexture(temp_gl.TEXTURE_2D, texture0);
temp_gl.activeTexture(temp_gl.TEXTURE1);
temp_gl.bindTexture(temp_gl.TEXTURE_2D, texture1);
if (!useVAO) {
temp_gl.activeTexture(activeTexture);
}
temp_gl.frontFace(frontFace);
temp_gl.colorMask(colorWhiteMask[0],colorWhiteMask[1],
colorWhiteMask[2],colorWhiteMask[3]); //Slip 2017/03/24
//
if (!useVAO) {
vertexAttr0Enabled ? temp_gl.enableVertexAttribArray(0) : temp_gl.disableVertexAttribArray(0);
vertexAttr1Enabled ? temp_gl.enableVertexAttribArray(1) : temp_gl.disableVertexAttribArray(1);
vertexAttr2Enabled ? temp_gl.enableVertexAttribArray(2) : temp_gl.disableVertexAttribArray(2);
vertexAttr3Enabled ? temp_gl.enableVertexAttribArray(3) : temp_gl.disableVertexAttribArray(3);
}
scissorTestEnabled ? temp_gl.enable(temp_gl.SCISSOR_TEST) : temp_gl.disable(temp_gl.SCISSOR_TEST);
stencilTestEnabled ? temp_gl.enable(temp_gl.STENCIL_TEST) : temp_gl.disable(temp_gl.STENCIL_TEST);
depthTestEnabled ? temp_gl.enable(temp_gl.DEPTH_TEST) : temp_gl.disable(temp_gl.DEPTH_TEST);
cullFaceEnabled ? temp_gl.enable(temp_gl.CULL_FACE) : temp_gl.disable(temp_gl.CULL_FACE);
blendEnabled ? temp_gl.enable(temp_gl.BLEND) : temp_gl.disable(temp_gl.BLEND);
if (useVAO) {
vao.unbind();
vao.destroy();
renderer.bindVao(_activeVao);
}
//copy of pixi-v4 internal code
this.calculateVertices();
if (this._isPicture) {
// use heavy renderer, which reduces artifacts and applies corrent blendMode,
// but does not use multitexture optimization
this._speedUpCustomBlendModes(renderer);
renderer.setObjectRenderer(renderer.plugins.picture);
renderer.plugins.picture.render(this);
} else {
// use pixi super-speed renderer
renderer.setObjectRenderer(renderer.plugins.sprite);
renderer.plugins.sprite.render(this);
}
}
var Csm_CubismFramework = Live2DCubismFramework.CubismFramework;
Live2DSprite.prototype.initializeCubism = function () {
// setup cubism
this._cubismOption.logFunction = LAppPal.printMessage;
this._cubismOption.loggingLevel = LAppDefine.CubismLoggingLevel;
Csm_CubismFramework.startUp(this._cubismOption);
// initialize cubism
Csm_CubismFramework.initialize();
// load model
$gameLive2d._lappLive2dManager = LAppLive2DManager.getInstance();
// default proj
var projection = new Csm_CubismMatrix44();
LAppPal.updateTime();
};
//argsは配列なので考慮すること slip 2017/03/24
Live2DSprite.prototype.destroy = function(args) {
this.model.release();
};
if (PIXI) {
PIXI.Live2DSprite = Live2DSprite;
} else {
console.error('Error: Cannot find global variable `PIXI`, Live2D plguin will not be installed.');
}
(function(){
'use strict'
const DataManager_createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects =function(){
DataManager_createGameObjects.call(this);
if($gameLive2d == null){
$gameLive2d = new Game_Live2d();
}
};
const Scene_Map_updateWaitCount =Scene_Map.prototype.updateWaitCount;
Scene_Map.prototype.updateWaitCount =function(){
Scene_Map_updateWaitCount.call(this);
};
const Scene_Map_terminate=Scene_Map.prototype.terminate;
Scene_Map.prototype.terminate =function(){
this.terminatelive2d();
Scene_Map_terminate.call(this);
};
const Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function(){
Scene_Map_start.call(this);
this.createlive2d();
};
const Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
Scene_Map_update.call(this);
$gameLive2d.live2dupdate();
};
const Game_Interpreter_updateWaitCount = Game_Interpreter.prototype.updateWaitCount;
Game_Interpreter.prototype.updateWaitCount = function() {
if ($gameLive2d._waitCount > 0) {
$gameLive2d._waitCount--;
return true;
}
return Game_Interpreter_updateWaitCount.call(this);
};
// プラグインコマンド
const Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
Game_Interpreter_pluginCommand.call(this, command, args);
var StrForComparison = 'TalkLive2d';
StrForComparison = StrForComparison.toLowerCase();
command = command.toLowerCase();
if (command === StrForComparison) {