-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
218 lines (173 loc) · 8.42 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
218
<!DOCTYPE html>
<html lang="en">
<!--
https://github.com/drdaxxy/rneanim
This project contains third-party code, see THIRDPARTY in this directory
-->
<head>
<title>Robotics;Notes Elite animation player</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0px;
background-color: #000;
overflow: hidden;
}
#progress {
position: absolute;
width: 100%;
text-align: center;
font-family: monospace;
font-size: 1.2em;
top: 2em;
}
</style>
</head>
<body>
<link rel="stylesheet" type="text/css" href="dat.gui.css">
<script src="js/dat.gui.min.js"></script>
<script src="js/three.js"></script>
<script src="js/OutlineEffect.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/MonkeyPatchLightingModel.js"></script>
<script src="js/GXTLoader.js"></script>
<script src="js/RNEModelLoader.js"></script>
<script src="js/RNEAnimLoader.js"></script>
<script src="js/RNEAnimPlayer.js"></script>
<script src="js/allModels.js"></script>
<script>
var first = true;
var defaults = {
repeatOffset: 210,
introOffset: 0
}
var config = {
targetModel: "c002_010",
targetAnim: "0001",
repeatOffset: 210,
introOffset: 0,
playbackSpeed: 1,
tweening: true,
background: true
};
function onProgress(xhr) {
document.getElementById('progress').innerText = "Progress: " + (xhr.loaded / xhr.total * 100).toFixed(2) + "%";
}
function onModelLoad(name) {
return function(result) {
if (name != config.targetModel) return;
document.getElementById('progress').innerText = "";
config.targetAnim = "0001";
new RNEAnimLoader().load('models/' + name + '/' + config.targetAnim, function(animResult) {
if (animController) gui.remove(animController);
animController = gui.add(config, 'targetAnim', allModels[name]).name("Animation").onFinishChange(function(newValue) {
config.targetAnim = newValue;
new RNEAnimLoader().load('models/' + name + '/' + newValue, onAnimLoad(name, newValue, result));
});
onAnimLoad(name, config.targetAnim, result)(animResult);
}, onProgress);
};
}
function onAnimLoad(modelName, animName, loadedModel) {
return function(result) {
if (modelName != config.targetModel || animName != config.targetAnim) return;
document.getElementById('progress').innerText = "";
if (mesh) scene.remove(mesh);
scene.add(loadedModel.model);
mesh = loadedModel.model;
meshGroups = loadedModel.meshGroups; // only for debug
if (repeatController) gui.remove(repeatController);
repeatController = gui.add(config, 'repeatOffset').min(0).max(result.duration / 30).step(1).name("Repeat from x frames");
repeatController.setValue(defaults.repeatOffset < result.duration / 30 ? defaults.repeatOffset : 0);
player = new RNEAnimPlayer(loadedModel.model, loadedModel.meshGroups, result, config.repeatOffset * 30, config.introOffset * 30);
}
}
var camera, scene, renderer, controls, effect, ambientLight, bgTexture, meshGroups;
var gui = new dat.GUI();
var repeatController, modelController, animController;
var mesh = null;
var player = null;
var t = window.performance.now();
init();
animate();
function init() {
gui.width = 300;
gui.add(config, 'playbackSpeed', 0.25, 4.0, 0.25).name("Playback speed");
modelController = gui.add(config, 'targetModel', Object.keys(allModels)).name("Model").onFinishChange(function(newValue) {
config.targetModel = newValue;
if (animController) gui.remove(animController);
animController = null;
new RNEModelLoader().load('models/' + newValue + '/0000', onModelLoad(newValue));
}, onProgress);
gui.add(window, 'resetCamera').name("Reset camera");
gui.add(config, 'tweening').name("Tweening");
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
bgTexture = new THREE.TextureLoader().load("flatbg.png");
scene = new THREE.Scene();
scene.background = bgTexture;
new RNEModelLoader().load('models/c002_010/0000', onModelLoad('c002_010'));
ambientLight = new THREE.AmbientLight(0xC8AB99);
scene.add(ambientLight);
light = new THREE.DirectionalLight(0xFFFFFF, 1.0);
light.position.set(1,1,1);
scene.add(light);
gui.add(config, 'background').name('Background').onFinishChange(function(newValue) {
if (newValue) {
scene.background = bgTexture;
ambientLight.color = new THREE.Color(0xC8AB99);
} else {
scene.background = new THREE.Color(0xA0A0A0);
ambientLight.color = new THREE.Color(0xC0C0C0);
}
});
var grid = new THREE.GridHelper( 100, 20, 0x000000, 0x000000 );
grid.material.opacity = 0.2;
grid.material.transparent = true;
scene.add( grid );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// TODO accurate parameters, see also material params in RNEModelLoader
// TODO modify OutlineEffect to use Shader_Line.gxt? (colored perlin noise)
// TODO not render on things like aki's skirt (...model file data?)
effect = new THREE.OutlineEffect(renderer, {
defaultThickness: 0.001,
defaultColor: new THREE.Color(0.4648, 0.2773, 0.2227)
});
controls = new THREE.OrbitControls(camera, renderer.domElement);
resetCamera();
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
controls.update();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function resetCamera() {
camera.position.x = 0;
camera.position.y = 12;
camera.position.z = 12;
controls.target = new THREE.Vector3(0,10,0);
controls.update();
}
function animate() {
var t2 = window.performance.now();
var dt = t2 - t;
t = t2;
if (player) {
player.tweening = config.tweening;
player.repeatOffset = config.repeatOffset * 30;
player.introOffset = config.introOffset * 30;
player.update(config.playbackSpeed * dt);
}
// TODO: update all materials' ambientWeight/darkMode and put them in GUI
requestAnimationFrame( animate );
effect.render( scene, camera );
}
</script>
<div id="progress"></div>
</body>
</html>