forked from perfume-dev/example-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
217 lines (183 loc) · 6.3 KB
/
index.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
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
<!doctype html>
<html>
<head>
<title>perfume.js</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<meta charset="utf-8">
<style>
* {
padding: 0;
margin: 0;
}
@media screen {
body {
height: 100%;
}
}
@media only screen and (max-device-width:480px) {
body {
width: 320px;
height: 460px;
}
}
@media only screen and (device-width: 768px) {
body {
width: 1024px;
height: 768px;
}
}
body {
overflow: hidden;
color: white;
background-color: black;
}
</style>
<script src="vendor/three.js/Three.js"></script>
<script src="vendor/three.js/Detector.js"></script>
<script src="vendor/three.js/Stats.js"></script>
<script src="vendor/jquery-1.7.1.min.js"></script>
<script src="vendor/underscore-min.js"></script>
<script src="vendor/mustache.min.js"></script>
<script src="src/perfume.js"></script>
</head>
<body>
<!-- three.js container -->
<div id="container"></div>
<script type="text/javascript">
var stats, scene, renderer, camera, girls = [], music,
lastX, lastY, isDragging, theta = -Math.PI * 3 / 4, phi = Math.PI / 6;
init();
// init the scene
function init(){
setupEnv();
music = loadAudio(['./audio/Perfume_globalsite_sound.mp3'], function() {
setupModel();
});
}
// animation loop
var clock, lastLoopCount = 0;
function animate() {
if (!clock) {
clock = new THREE.Clock();
music.play();
}
var elapsedTime = clock.getElapsedTime(),
loopCount = Math.floor(elapsedTime / (girls[0].frameTime * girls[0].numFrames));
_.each(girls, function(g) {
g.update(elapsedTime);
});
if (lastLoopCount !== loopCount) {
music.load();
music.play();
}
lastLoopCount = loopCount;
// loop on request animation loop
// - it has to be at the begining of the function
// - see details at http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
requestAnimationFrame(animate);
// do the render
render();
// update stats
stats.update();
}
// render the scene
function render() {
// actually render the scene
renderer.render(scene, camera);
}
// rotate camera with mouse
function updateCamera() {
var RADIUS = 650;
camera.position.x = RADIUS * Math.sin(theta) * Math.cos(phi);
camera.position.y = RADIUS * Math.sin(phi);
camera.position.z = RADIUS * Math.cos(theta) * Math.cos(phi);
camera.lookAt(new THREE.Vector3(0, 100, 0));
camera.updateMatrix();
}
document.addEventListener('mousedown', function(event) {
isDragging = true;
lastX = event.clientX;
lastY = event.clientY;
});
document.addEventListener('mousemove', function(event) {
if (camera && isDragging) {
var SPEED = 0.01;
theta -= (event.clientX - lastX) * SPEED;
phi += (event.clientY - lastY) * SPEED;
phi = Math.min(Math.PI / 2, Math.max(-Math.PI / 2, phi));
updateCamera();
}
lastX = event.clientX;
lastY = event.clientY;
});
document.addEventListener('mouseup', function(event) {
isDragging = false;
});
//
// setuppers
//
function setupEnv() {
if( Detector.webgl ){
renderer = new THREE.WebGLRenderer({
antialias: true, // to get smoother output
preserveDrawingBuffer: true // to allow screenshot
});
}else{
renderer = new THREE.CanvasRenderer();
}
renderer.setClearColorHex(0x0, 1);
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('container').appendChild(renderer.domElement);
// add Stats.js - https://github.com/mrdoob/stats.js
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
document.body.appendChild(stats.domElement);
// create a scene
scene = new THREE.Scene();
// put a camera in the scene
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
updateCamera();
scene.add(camera);
// Light
var directionalLight = new THREE.DirectionalLight(0xffeedd);
directionalLight.position.set(0, -70, 100).normalize();
scene.add(directionalLight);
}
function loadAudio(sources, ready) {
var audio = document.createElement('audio');
for (var i = 0; i < sources.length; ++i) {
var source = document.createElement('source');
source.src = sources[i];
audio.appendChild(source);
}
audio.autoplay = false;
audio.loop = true;
if (ready) {
audio.addEventListener("canplay", ready);
}
audio.load();
return audio;
};
function setupModel() {
_.each(
[
{path: 'bvhfiles/aachan.bvh', color: 0xFF3333},
{path: 'bvhfiles/kashiyuka.bvh', color: 0x33FF33},
{path: 'bvhfiles/nocchi.bvh', color: 0x3333FF}
],
function(def, index, cont) {
perfume.load(def.path, def.color, function(girl) {
scene.add(girl.rootBone);
girls.push(girl);
if (girls.length >= cont.length) {
animate();
}
});
});
}
</script>
<a href="http://www.perfume-global.com/" style='position: absolute; top: 0; left: 0; border: 0;'>music and bvh data are here</a>
<a href="http://github.com/ando-takahiro/perfume.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/e6bef7a091f5f3138b8cd40bc3e114258dd68ddf/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub"></a>
</body>
</html>