-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodule-bone.js
88 lines (71 loc) · 1.59 KB
/
module-bone.js
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
import node from '../boot/node.js'
const matrix = node.load('boot/gl-matrix.js');
const {vec3, mat4} = matrix;
const person = {
body : 0,
waist : 1,
lThigh : 2,
lCalf : 3,
lFoot : 4,
rThigh : 5,
rCalf : 6,
rFoot : 7,
head : 8,
lBigarm : 9,
lForearm : 10,
lHand : 11,
rBigarm : 12,
rForearm : 13,
rHand : 14,
}
const _mapp = {
// Leon module
50: person,
}
function fixMoveStep() {
return 30;
}
function _getBonePos(initPos, trans) {
let v = vec3.create();
vec3.transformMat4(v, v, trans);
return v;
}
function calculateFootstepLength(bone) {
const l = _getBonePos(bone[this.lFoot]._pos, bone[this.lFoot].lastTrans);
const r = _getBonePos(bone[this.rFoot]._pos, bone[this.rFoot].lastTrans);
const res = l;
return l[0] - r[0];
// vec3.subtract(res, l, r);
// return vec3.length(res);
}
function bind(name, md) {
let boneIdx = md.boneIdx = {
// 返回模型两脚间的距离
stepLength : fixMoveStep,
};
let reg = /.\/em(.)(..)\.emd/i;
let match = reg.exec(name);
if (! match) {
console.warn("invaild module file name", name);
return;
}
let map = _mapp[ match[2] ];
if (! map) {
// TODO: 默认绑定 person !!!
console.warn("not found Module Bind", match[2], 'use person.');
map = person;
}
if (! md.bone) {
console.warn("Module not bone");
return;
}
for (let name in map) {
boneIdx[name] = map[name];
}
if (boneIdx.lFoot >= 0 && boneIdx.lFoot >= 0) {
boneIdx.stepLength = calculateFootstepLength;
}
}
export default {
bind,
}