File size: 8,401 Bytes
2d47d90 |
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
<!DOCTYPE html>
<!-- GrooveNet Player - V 0.3
By Omid Alemi
-->
<html lang="en">
<head>
<title>BVH 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>
</style>
<link rel="stylesheet" href="styles/pace.css"></link>
<script src="libs/pace.min.js"></script>
<script src="libs/math.min.js"></script>
<script src="libs/jquery.min.js"></script>
<script src="libs/threejs/three.min.js"></script>
<script src="libs/threejs/OrbitControls.js"></script>
<script src="libs/papaparse.min.js"></script>
<script src="libs/mocapjs.js"></script>
<script src="js/skeletonFactory.js"></script>
</head>
<body>
<script type="text/javascript">
var characters = [];
var playing = false;
$(document).on("keypress", function(e) {
if (e.charCode == 32)
playing = !playing;
characters.forEach(function(c) {
c.playing = playing;
if (playing)
c.animStartTimeRef = Date.now();
else
c.animOffset = c.animIndex;
});
});
$(window).on("resize", function(e) {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
</script>
<script>
var scene, camera, renderer;
var geometry, material, mesh;
var played_count = 0;
function set_the_scene3() {
// Add the light
light = new THREE.PointLight(0xffffff, 0.9, 0);
light.position.set(0, 160, 40);
scene.add(light);
// Create a grid for the floor
var size = 200,
step = 20;
// Draw the plane
var planeGeometry = new THREE.PlaneGeometry(size * 2, size * 2);
var planeMaterial = new THREE.MeshPhongMaterial({
color: 0x444444,
emissive: 0x000000,
specular: 0x111111,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.6
});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.position.set(0, 0, 0);
plane.rotation.set(math.pi / 2, 0, 0);
scene.add(plane);
//Draw the lines
var lineGeometry = new THREE.Geometry();
var lineMaterial = new THREE.LineBasicMaterial({
color: 0x555555,
linewidth: 1.2
});
for (var i = -size; i <= size; i += step) {
lineGeometry.vertices.push(new THREE.Vector3(-size, -0.04, i));
lineGeometry.vertices.push(new THREE.Vector3(size, -0.04, i));
lineGeometry.vertices.push(new THREE.Vector3(i, -0.04, -size));
lineGeometry.vertices.push(new THREE.Vector3(i, -0.04, size));
}
var line = new THREE.LineSegments(lineGeometry, lineMaterial);
scene.add(line);
}
function add_basic_lights() {
// Add the light
var light = new THREE.HemisphereLight(0xffffff, 0x000000, 0.8);
scene.add(light);
}
function add_floor_theo() {
var textureLoader = new THREE.TextureLoader();
var texture = textureLoader.load('theo_floor1.jpg', function(tt) {
});
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat = new THREE.Vector2(1,1.66);
var material = new THREE.MeshPhongMaterial({
color: 0xffffff,
specular: 0xffffff,
shininess: 100,
map: texture,
});
var geometry = new THREE.CubeGeometry(300, 300, 5);
var mesh = new THREE.Mesh(geometry, material);
mesh.position.y = -2;
mesh.rotation.x = -Math.PI / 2;
scene.add(mesh);
}
function init(cz) {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 1, 4000);
camera.position.set(0, 80, 0);
camera.position.z = cz;
scene.add(camera);
// set_the_scene3();
}
function loadBVHFile(bvhURL, cname, jm, bm, scale) {
var c2 = new BVHCharacter(cname, jm, bm, makeJointGeometry_Dode, makeBoneGeometry_Cylinder2);
// c2.setOriginPosition(0, 0, 0);
c2.skelScale = scale;
c2.loadFromURL(bvhURL, function() {
scene.add(c2.skeleton);
});
characters.push(c2);
}
function loadPosFile(csvURL, cname, jm, bm, scale, fr) {
var c2 = new C3DCharacter(cname, markermaterial, makeJointGeometry_Sphere2);
// c2.setOriginPosition(0, 0, 0);
c2.scale = scale;
c2.frameTime = fr;
c2.loadFromURL(csvURL, function() {});
characters.push(c2);
}
function initRenderer() {
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
//renderer.setSize(600, 500);
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.setPixelRatio(window.devicePixelRatio);
// renderer.setClearColor(0xdddddd, 1);
renderer.setClearColor(0xffffff, 1);
document.body.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
}
function animate() {
// if (!playing)
// return;
requestAnimationFrame(animate);
characters.forEach(function(c) {
// console.log(c.playing);
if (1 && c.ready) {
if (c.playing) {
c.animIndex = c.animOffset + Math.floor((Date.now() - c.animStartTimeRef) / c.frameTime / 1000);
if (c.animIndex >= c.frameCount) {
c.animOffset = 0;
c.animStartTimeRef = Date.now();
c.animIndex = 0;
played_count++;
// if (played_count> 1)
// c.playing = false;
}
c.animFrame(c.animIndex);
}
}
});
renderer.render(scene, camera);
}
$(document).ready(function () {
var dataURL = getUrlParameter('data_url');
var cz = getUrlParameter('cz');
var scale = getUrlParameter('scale');
var frameTime = getUrlParameter('frame_time');
if (cz === undefined)
cz = 550;
if (scale === undefined)
scale = 1.0;
if (frameTime === undefined)
frameTime = 1/120;
init(cz);
add_basic_lights();
add_floor_theo();
initRenderer();
if (dataURL !== undefined) {
console.log("Loading " + dataURL);
if (dataURL.endsWith('.bvh'))
loadBVHFile(dataURL, 'Fig', jm_a, bm_a, scale);
else if (dataURL.endsWith('.csv'))
loadPosFile(dataURL, 'Fig', jm_a, bm_a, scale, frameTime);
else
console.error('Unsupport file.');
}
animate();
});
</script>
</body>
</html>
|