-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
160 lines (132 loc) · 5.95 KB
/
demo.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Live2D SampleApp1</title>
</meta>
<meta name="viewport" content="width=device-width, initial-scale=0.5, minimum-scale=1.0, maximum-scale=4.0">
</meta>
<style>
html, body {
oveflow: hidden;
height: 100%;
}
body{
margin:0px ;
padding:0px ;
}
</style>
</head>
<body>
<p>
<button id="btnChange">Change Model</button>
<button id="btnRelease">Release Model</button>
</p>
<p>
<button id="btnRandomExpression">Random Expression</button>
<button id="btnLoadExpressions">Load Expressions</button>
</p>
<div id="expressions"></div>
<p>
<select id="motionName">
<option value=""></option>
<option value="idle">idle</option>
<option value="tap_body">tap_body</option>
<option value="flick_head">flick_head</option>
<option value="pinch_in">pinch_in</option>
<option value="pinch_out">pinch_out</option>
<option value="shake">shake</option>
</select>
<input id="motionNum" value="0"></input>
<button id="btnStartMotion">Start Motion</button>
</p>
<p>
<button id="btnPlaySound">Play Sound</button>
</p>
<p style="margin-bottom: 50px">
<button id="btnZoomIn">Zoom In</button>
<button id="btnZoomOut">Zoom Out</button>
</p>
<div class="live2d">
<canvas id="glcanvas" width="400" height="600" style="border:dashed 1px #CCC"></canvas>
</div>
<!-- Live2D Library -->
<script src="lib/live2d.min.js"></script>
<!-- Live2D Framework -->
<script src="src/Live2DFramework.js"></script>
<script src="src/MatrixStack.js"></script>
<script src="src/ModelSettingJson.js"></script>
<script src="src/PlatformManager.js"></script>
<script src="src/LAppDefine.js"></script>
<script src="src/LAppModel.js"></script>
<script src="src/LAppLive2DManager.js"></script>
<script src="src/Live2DHelper.js"></script>
<!-- User's Script -->
<script type="text/javascript">
var live2DHelper = new Live2DHelper({canvas: 'glcanvas'});
window.onload = function() {
var path = "assets/models/asuna/asuna_01/asuna_01.model.json";
live2DHelper.loadModel(path, function(){
live2DHelper.startTurnHead();
document.getElementById("glcanvas").addEventListener("mousemove", followPointer, false);
});
};
function followPointer(e) {
live2DHelper.followPointer(e);
}
var i = 0;
document.getElementById("btnChange").onclick = function(){
var modelNumArr = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "33", "34", "35", "36", "37", "38", "39", "40", "41", "43", "44", "45", "46", "47", "48", "49", "50", "52", "53", "54"];
i++;
if(i == modelNumArr.length) {
i = 0;
}
console.log(modelNumArr[i]);
live2DHelper.releaseAllModel();
live2DHelper.changeModel("assets/models/asuna/asuna_" + modelNumArr[i] + "/asuna_" + modelNumArr[i] + ".model.json", function(){
live2DHelper.startTurnHead();
document.getElementById("glcanvas").addEventListener("mousemove", followPointer, false);
});
}
document.getElementById("btnRelease").onclick = function(){
live2DHelper.releaseModel();
}
document.getElementById("btnRandomExpression").onclick = function(){
live2DHelper.setRandomExpression();
}
document.getElementById("btnLoadExpressions").onclick = function(){
document.getElementById("expressions").innerHTML = '';
for (var name in live2DHelper.getExpressions()) {
var button = document.createElement("input");
button.setAttribute("type","button");
button.setAttribute("value",name);
button.setAttribute("id",name);
document.getElementById("expressions").appendChild(button);
}
for (var name in live2DHelper.getExpressions()) {
(function(name){
document.getElementById(name).onclick = function(){
live2DHelper.setExpression(name);
};
})(name);
}
}
document.getElementById("btnStartMotion").onclick = function(){
var motionName = document.getElementById("motionName");
var i1 = motionName.selectedIndex;
var motionNum = document.getElementById("motionNum");
live2DHelper.startMotion(motionName.options[i1].value, motionNum.value);
}
document.getElementById("btnPlaySound").onclick = function(){
//live2DHelper.playSoundAJAX("assets/sound/friend_06.ogg");
live2DHelper.playSound("assets/sound/2.mp3");
}
document.getElementById("btnZoomIn").onclick = function(){
live2DHelper.modelScaling(1.1);
}
document.getElementById("btnZoomOut").onclick = function(){
live2DHelper.modelScaling(0.9);
}
</script>
</body>
</html>