-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path12_json_skeleton_animation.html
executable file
·137 lines (95 loc) · 3.73 KB
/
12_json_skeleton_animation.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
<!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 #12</h2>
</div>
</div>
<div id="theContainer"></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-animation-minimal.json', function (model, modelMats) {
$.each(modelMats, function(index, mat) {
mat.skinning = true;
});
var facemat = new THREE.MeshFaceMaterial(modelMats);
mesh = new THREE.SkinnedMesh(model, facemat);
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];
scene.add(mesh);
setInterval(function() {
//behaviour(currentAnimation.currentTime);
}, 100);
});
$(container).on('mouseenter',function(event) {
currentAnimation.play();
});
$(container).on('mouseout', function(event) {
currentAnimation.stop();
});
function animate() {
renderer.render(scene, camera);
THREE.AnimationHandler.update(clock.getDelta()*0.5);
requestAnimationFrame(animate);
}
animate();
})();
</script>
</html>