-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path13_json_skeleton_animation_tracked.html
executable file
·236 lines (186 loc) · 8 KB
/
13_json_skeleton_animation_tracked.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html>
<head>
<!-- using Bootstrap for styling -->
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<!-- ThreeJS r71
<script src="js/three.js"></script>
-->
<!-- ThreeJS r69 -->
<script src="js/three-69.js"></script>
<!-- OrbitControls is used for scene navigation -->
<script src="js/OrbitControls.js"></script>
<!-- jQuery is needed for tutorials about user interaction -->
<script src="js/jquery-2.1.4.min.js"></script>
<!-- ColladaLoader is needed for external models loading -->
<script src="js/ColladaLoader.js"></script>
<!-- custom stylesheed -->
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><a href="http://3DWeb.cc">3DWeb</a> - WebGL Workshop - Example #9</h2>
</div>
</div>
<div id="theContainer">
<div data_playground_x="1" data_playground_y='2' class="leap-focusable left" style="background-color: blue; left: 30%;">
1 - 2
</div>
<div data_playground_x="1" data_playground_y='1' class="leap-focusable left top" style="background-color: #0000bb;">
1 - 1
</div>
<div ata_playground_x="2" data_playground_y='1' class="leap-focusable left " style="background-color: #0000aa; top: 23%;">
2 - 1
</div>
<div data_playground_x="3" data_playground_y='1' class="leap-focusable left " style="background-color: #00006f; top: 36%;">
3 - 1
</div>
<div data_playground_x="3" data_playground_y='2' class="leap-focusable left middle" style="background-color: #00aaaa; top: 50%; left:20%;">
3 - 2
</div>
<div data_playground_x="4" data_playground_y='2' class="leap-focusable left bottom" style="background-color: #00dd00; bottom: 20%; left: 20%;">
4 - 2
</div>
<div data_playground_x="4" data_playground_y='3' class="leap-focusable bottom" style="background-color: #00bb00; left: 35%;">
4 - 3
</div>
<div data_playground_x="4" data_playground_y='4' class="leap-focusable center bottom" style="background-color: whitesmoke;">
4 - 4
</div>
<div data_playground_x="4" data_playground_y='5' class="leap-focusable bottom" style="background-color: #00bb00; right: 35%;">
4 - 5
</div>
<div data_playground_x="4" data_playground_y='6' class="leap-focusable right bottom" style="background-color: #00dd00; bottom: 20%; right: 20%;">
4 - 6
</div>
<div data_playground_x="3" data_playground_y='6' class="leap-focusable right middle" style="background-color: #aa00aa; top: 50%; right: 20%;">
3 - 6
</div>
<div data_playground_x="3" data_playground_y='7' class="leap-focusable right" style="background-color: #6a0000; top: 36%;">
3 - 7
</div>
<div data_playground_x="2" data_playground_y='7' class="leap-focusable right " style="background-color: #6f0000;top: 23%;">
2 - 7
</div>
<div data_playground_x="1" data_playground_y='7' class="leap-focusable right top " style="background-color: #bb0000;">
1 - 7
</div>
<div data_playground_x="1" data_playground_y='6' class="leap-focusable right" style="background-color: red; right: 30%">
1 - 6
</div>
</div>
</body>
<script type="text/javascript">
/**
* WebGL workshop scene template - www.3dweb.cc
*
* Instructions:
* - you need a WebGL enabled browser (check it on http://get.webgl.org)
* - if you load assets (textures, models...) you need also a local webserver (see tutorials)
*/
// put the variables you want to access from the console here
var container, renderer, scene, camera, materials = {}, clock = new THREE.Clock(), animations = [], currentAnimation,
behaviour = function(time) { console.log(time) };
(function () {
// boilerplate
container = document.getElementById('theContainer');
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xaabbff);
renderer.setSize(640, 480);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, 640 / 480, 0.1, 8000);
camera.position.set(0, 4, 10);
//camera.lookAt(0, 2, 0);
container.appendChild(renderer.domElement);
// warmer light from upper right
var theLight1 = new THREE.SpotLight(0xffdddd, 2);
theLight1.position.set(10, 10, 20);
scene.add(theLight1);
// colder light from upper left
var theLight2 = new THREE.SpotLight(0xddddff, 1.7);
theLight2.position.set(10, 10, -20);
scene.add(theLight2);
//controls = new THREE.OrbitControls(camera, renderer.domElement);
// write your code here
var loader = new THREE.JSONLoader();
loader.load('models/frankie-no-armature-no-subsurf.json', function (model, modelMats) {
$.each(modelMats, function(index, mat) {
mat.skinning = true;
});
var facemat = new THREE.MeshFaceMaterial(modelMats);
mesh = new THREE.SkinnedMesh(model, facemat);
//mesh.scale.set(0.5,0.5,0.5);
var animation;
if (model.animations !== undefined) {
for (var i = 0; i < model.animations.length; i += 1) {
animation = new THREE.Animation(mesh, model.animations[i]);
console.log(i+' '+animation.data.name);
animations.push(animation);
}
}
currentAnimation = animations[0];
currentAnimation.play();
scene.add(mesh);
var bone;
var regex = new RegExp('DEF');
for (var k = 0; k < mesh.skeleton.bones.length; k += 1) {
bone = mesh.skeleton.bones[k];
if (regex.test(bone.name)) {
//console.log(k + ' ' + bone.name);
}
}
setInterval(function() {
//behaviour(currentAnimation.currentTime);
}, 100);
});
var END_OF_GREETINGS = 4;
/*
$(container).on('mouseover', '.leap-focusable', function(event) {
var dpx = $(event.currentTarget).attr('data_playground_x');
var dpy = $(event.currentTarget).attr('data_playground_y');
var dataX = dpx !== undefined ? parseInt(dpx, 10) : -1;
var dataY = dpy !== undefined ? parseInt(dpy, 10) : -1;
console.log('over! '+dataX+' and '+dataX);
if (dataX === 4 && dataY === 4) {
behaviour = function (time) {
if (time < 0.1) {
currentAnimation.stop();
} else if (time > END_OF_GREETINGS) {
currentAnimation.play(0.005);
}
}
} else if (dataX === 1 && dataY === 6) {
console.log('1x6');
behaviour = function(time) {
if (time <= 6.40) {
currentAnimation.play(6.40);
} else if (time >= 8.4) {
currentAnimation.stop();
} else {
// nothing
}
}
} else {
}
});
$(container).on('mouseout', '.leap-focusable', function(event) {
behaviour = function(time) {
if (time > 4) {
currentAnimation.play(0.1);
} else {
currentAnimation.play(0.1);
currentAnimation.stop();
}
}
});
*/
function animate() {
renderer.render(scene, camera);
THREE.AnimationHandler.update(clock.getDelta());
requestAnimationFrame(animate);
}
animate();
})();
</script>
</html>