-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
104 lines (90 loc) · 3.29 KB
/
main.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
tm.main(function() {
var app = tm.hybrid.Application("#canvas2d", "#canvas3d");
app.fps = 60;
app.resize(640, 960).fitWindow().run();
app.enableStats();
app.replaceScene(tm.game.LoadingScene({
width: 640, height: 960,
assets: {
hiyoko: "assets/hiyoco_nomal_full.png",
bgm: "assets/smile.mp3",
//urlをモデルデータ、モーションデータの順に指定
//There is a need to specify the PMD and VMD together to play the MMD
miku: {
type: "mmd",
url: ["assets/pmd/miku_v2.pmd", "assets/vmd/wavefile_v2.vmd"],
},
//分けて読み込みも可能
neru: "assets/pmd/neru.pmd",
wave: "assets/vmd/wavefile_v2.vmd",
},
nextScene: MikuOnStage,
}));
});
tm.define("MikuOnStage", {
superClass: "tm.hybrid.Scene", // tm.app.Sceneの3D向け拡張
init: function() {
this.superInit();
// カメラ調整
this.camera.setPosition(0, 20, 30);
this.camera.lookAt(new THREE.Vector3(0, 10, 0));
// ライトを動かす
this.directionalLight.setPosition(0, 100, -80);
// メッシュを表示する
var miku = tm.hybrid.MMDMesh("miku")
.addChildTo(this)
.setPosition(0, 0, 0)
.on("enterframe", function() {
if (this.rolling) this.rotationY += 10; // Y軸回転
});
//分割読み込みからメッシュを生成
var neru = tm.hybrid.createMeshFromMMD("neru", "wave")
.addChildTo(this)
.setPosition(0, 0, -30)
.setRotation(0, 180, 0)
.on("enterframe", function() {
if (this.rolling) this.rotationY += 10; // Y軸回転
});
// 2Dスプライトとの併用も可能
var hiyoko = tm.display.Sprite("hiyoko", 32, 32)
.setScale(4)
.setFrameIndex(0)
// .addChildTo(this)
.on("enterframe", function() {
this.x += this.vx * 10;
this.y += this.vy * 10;
if (this.x < 0 || 640 < this.x) this.vx *= -1;
if (this.y < 0 || 960 < this.y) this.vy *= -1;
this.frameIndex = (this.frameIndex + 1) % 4;
this.rotation += 2;
});
hiyoko.vx = 1;
hiyoko.vy = 1;
var btn = tm.ui.FlatButton({ text: "スタート" })
.setPosition(320, 960*0.5)
.addChildTo(this)
.on("push", function() {
btn.visible = false;
}.bind(this));
this.bgm = tm.asset.AssetManager.get("bgm");
THREE.AnimationHandler.update(0);
this.start = false;
this.time = 0;
},
update: function(app) {
if (!this.start) return;
var t = this.bgm.context.currentTime;
var delta = t - this.beforeTime;
THREE.AnimationHandler.update(app.deltaTime/1000);
this.beforeTime = t;
},
ontouchstart: function(e) {
if (!this.start) {
tm.sound.WebAudio.unlock();
this.bgm.context.currentTime = 0;
this.bgm.play();
this.start = true;
this.beforeTime = 0;
}
},
});