-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
002_animation_bvh.html
96 lines (72 loc) · 2.66 KB
/
002_animation_bvh.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
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title></head><body>
<script type="module">
//#region IMPORTS
import Starter, { THREE } from './_lib/Starter.js';
import DynLineMesh from './_lib/DynLineMesh.js';
import ShapePointsMesh from './_lib/ShapePointsMesh.js';
import { Armature, Bone, SkinMTX } from '../../src/armature/index';
import { Clip, Animator } from '../../src/animation/index';
import BoneDirMesh2 from './_lib/BoneDirMesh.js';
import Bvh from '../../src/parsers/bvh/index';
//#endregion
//#region MAIN
let App;
let Debug = {};
let Ref = {};
function onRender( dt=0, et=0 ){
Ref.animator
.update( dt )
.applyPose( Ref.pose );
Ref.pose.updateWorld( true );
Ref.boneView.updateFromPose( Ref.pose );
}
window.addEventListener( "load", async _=>{
App = new Starter( { webgl2:true, grid:true } );
App.setCamera( 0, 20, 4, [0,0.8,0] );
App.onRender = onRender;
// App.add( ( Debug.pnt = new ShapePointsMesh() ) );
// App.add( ( Debug.ln = new DynLineMesh() ) );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Load Animation
const bvh = await Bvh.fetch( '../_res/anim/dataset-1_walk_giant_001.bvh' );
bvh.ignoreRoot = true;
const anim = bvh.getAnimation();
const clip = Clip.fromBvh( anim, [0] );
Ref.animator = new Animator();
Ref.animator.inPlace = true;
Ref.animator.inPlaceScale[2] = 0;
Ref.animator.setClip( clip );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Build Armature
const arm = armature_from_bvh( bvh ); // Create an Armature from a GLTF Skeleton
arm.offset.setScl( [0.01,0.01,0.01] );
const pose = arm.newPose();
pose.updateWorld(); // Needed since adding offset scale to the armature.
Ref.pose = pose;
//console.log( 'arm bones', arm.bones );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// VIEW BONES
const boneView = new BoneDirMesh2( pose );
boneView.setBoneScale( 0.1 );
boneView.updateFromPose( pose );
App.add( boneView );
Ref.boneView = boneView;
onRender();
//console.log( 'pose', pose.bones );
App.render();
});
function armature_from_bvh( bvh, defaultBoneLen = 0.07 ){
const arm = new Armature();
const skin = bvh.getSkin();
for( let j of skin.joints ){
arm.addBone( j.name, j.parentIndex, j.rotation, j.position );
}
// Create Bind Pose
arm.bind( SkinMTX, defaultBoneLen );
return arm;
}
//#endregion
</script>
</body></html>