Export pinocchio file

This commit is contained in:
hodasemi 2018-06-29 16:30:56 +02:00
parent ca018300a1
commit ae74a5d55d
5 changed files with 2582 additions and 90 deletions

View file

@ -266,6 +266,19 @@ void print_vec3(const Vec3 &v)
std::cout << "(" << v.x() << ", " << v.y() << ", " << v.z() << ")" << std::endl;
}
Bone *find_root(Bone *bone)
{
float len = length(bone->get_bone_local_root_position() - bone->get_bone_local_tip_position());
if (len > 0.0f)
return bone;
for (int i = 0; i < bone->childCount(); i++)
{
return find_root(bone->child_at(i));
}
}
void Skeleton::get_bones(Bone *bone, std::vector<Bone *> &bone_list)
{
float len = length(bone->get_bone_local_root_position() - bone->get_bone_local_tip_position());
@ -316,6 +329,26 @@ void calc_points(Bone *bone, std::vector<Vec3> &points, Vec3 parent_pos, float c
}
}
struct BonePoint
{
Bone *bone;
Vec3 point;
};
void calc_points_off_set(Bone *bone, std::vector<BonePoint> &points, Vec3 parent_pos, float correction)
{
Vec3 new_pos = parent_pos + (into_vec3(bone->get_bone_local_tip_position()) / correction);
BonePoint bp = {bone, new_pos};
points.emplace_back(bp);
for (int i = 0; i < bone->childCount(); i++)
{
calc_points_off_set(bone->child_at(i), points, new_pos, correction);
}
}
float abs(float &v)
{
if (v < 0.0f)
@ -326,27 +359,16 @@ float abs(float &v)
return v;
}
void Skeleton::write_pinocchio_file(const std::string &filename)
struct Differences
{
std::ofstream o;
#ifdef _WIN32
std::wstring wfilename = cgv::utils::str2wstr(filename);
o.open(wfilename, std::ios::out);
#else
o.open(filename, std::ios::out);
#endif
if (o)
{
/*Task 4.1: Write Pinocchio file into o */
std::vector<Bone *> bone_list;
get_bones(root, bone_list);
// gather all points
std::vector<Vec3> points;
calc_points(root, points, Vec3(0.0f, 0.0f, 0.0f));
Vec3 min;
Vec3 max;
Vec3 diff;
float max_diff;
};
Differences calc_diffs(std::vector<Vec3> &points)
{
Vec3 min(0.0f, 0.0f, 0.0f);
Vec3 max(0.0f, 0.0f, 0.0f);
@ -385,28 +407,98 @@ void Skeleton::write_pinocchio_file(const std::string &filename)
}
}
//std::cout << "min: ";
//print_vec3(min);
//std::cout << "max: ";
//print_vec3(max);
float x_diff = abs(min.x()) + abs(max.x());
float y_diff = abs(min.y()) + abs(max.y());
float z_diff = abs(min.z()) + abs(max.z());
float max_diff = std::max(x_diff, std::max(y_diff, z_diff));
std::vector<Vec3> points2;
calc_points(root, points2, Vec3(0.0f, 0.0f, 0.0f), max_diff);
Differences diffs = {
min, max, Vec3(x_diff, y_diff, z_diff), max_diff};
for (auto p : points2)
return diffs;
}
float nip(float v)
{
if (v < 0.0f)
return -v;
return 0.0f;
}
Vec3 nip(Vec3 v)
{
return Vec3(nip(v.x()), nip(v.y()), nip(v.z()));
}
float correct_fract(float &f)
{
float almost_zero = 0.0000001f;
if (abs(f) < almost_zero)
return 0.0f;
return f;
}
Vec3 correct_fract(Vec3 &v)
{
return Vec3(correct_fract(v.x()), correct_fract(v.y()), correct_fract(v.z()));
}
Vec3 find_point(Bone *bone, std::vector<BonePoint> &bps)
{
for (BonePoint &bp : bps)
{
print_vec3(p);
if (bp.bone == bone)
return correct_fract(bp.point);
}
// bone not found, something went wrong
abort();
}
void Skeleton::write_pinocchio_file(const std::string &filename)
{
std::ofstream o;
#ifdef _WIN32
std::wstring wfilename = cgv::utils::str2wstr(filename);
o.open(wfilename, std::ios::out);
#else
o.open(filename, std::ios::out);
#endif
if (o)
{
/*Task 4.1: Write Pinocchio file into o */
std::vector<Bone *> bone_list;
get_bones(root, bone_list);
// gather all points
std::vector<Vec3> points;
calc_points(root, points, Vec3(0.0f, 0.0f, 0.0f));
Differences diffs = calc_diffs(points);
std::vector<Vec3> points2;
calc_points(root, points2, Vec3(0.0f, 0.0f, 0.0f), diffs.max_diff);
Differences diffs2 = calc_diffs(points2);
Vec3 offset(nip(diffs2.min));
std::cout << "offset: ";
print_vec3(offset);
std::vector<BonePoint> points3;
calc_points_off_set(root, points3, offset, diffs.max_diff);
//std::cout << "max_diff: " << max_diff << std::endl;
Bone *new_root = find_root(root);
// ---------------------------- info ----------------------------
int i = 0;
for (Bone *bone : bone_list)
@ -415,9 +507,17 @@ void Skeleton::write_pinocchio_file(const std::string &filename)
int parent_index = find_bone(bone->get_parent(), bone_list);
if (parent_index == -1)
{
if (bone != new_root)
{
parent_index = find_bone(new_root, bone_list);
}
}
//std::cout << i++ << ": " << bone->get_name() << ": " << len << " parent: " << parent_index << std::endl;
Vec3 c = into_vec3(bone->get_bone_local_tip_position()) / max_diff;
Vec3 c = find_point(bone, points3);
o << i++ << " " << c.x() << " " << c.y() << " " << c.z() << " " << parent_index << std::endl;
}

View file

@ -1,5 +0,0 @@
(cos((r*pi)/180)+x²*(1-cos(r*pi)/180))*xl+(-z*sin((r*pi)/180)+x*y*(1-cos(r*pi)/180))*yl+(y*sin((r*pi)/180)+z*x*(1-cos(r*pi)/180))*zl = xs
(z*sin((r*pi)/180)+x*y*(1-cos(r*pi)/180))*xl+(cos((r*pi)/180)+y²*(1-cos(r*pi)/180))*yl+(-x*sin((r*pi)/180)+z*y*(1-cos(r*pi)/180))*zl = ys
(-y*sin((r*pi)/180)+x*z*(1-cos(r*pi)/180))*xl+(x*sin((r*pi)/180)+y*z(1-cos(r*pi)/180))*yl+(cos((r*pi)/180)+z²*(1-cos(r*pi)/180))*zl = zs
(cos((r*pi)/180)+x²*(1-cos(r*pi)/180))*xl+(-z*sin((r*pi)/180)+x*y*(1-cos(r*pi)/180))*yl+(y*sin((r*pi)/180)+z*x*(1-cos(r*pi)/180))*zl)-xt)²+((z*sin((r*pi)/180)+x*y*(1-cos(r*pi)/180))*xl+(cos((r*pi)/180)+y²*(1-cos(r*pi)/180))*yl+(-x*sin((r*pi)/180)+z*y*(1-cos(r*pi)/180))*zl-yt)²+((-y*sin((r*pi)/180)+x*z*(1-cos(r*pi)/180))*xl+(x*sin((r*pi)/180)+y*z(1-cos(r*pi)/180))*yl+(cos((r*pi)/180)+z²*(1-cos(r*pi)/180))*zl-zt)²

2367
attachment.out Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,30 +1,30 @@
0 0.0429472 -0.0565452 0.0264444 -1
1 -7.5121e-09 -0.225528 0 0
2 0 -0.236038 0 1
3 8.92062e-09 -0.073179 -0.014522 2
4 -5.48289e-17 -0.0374839 4.69168e-08 3
5 -0.0411343 -0.0565452 0.0264444 -1
6 0 -0.234226 0 5
7 -7.5121e-09 -0.236596 0 6
8 4.69506e-09 -0.0744582 -0.0151752 7
9 2.00063e-16 -0.0381506 4.77513e-08 8
10 0.000890649 0.0641375 -0.00609295 -1
11 0.00178704 0.0645553 -0.00134698 10
12 0.00128702 0.0650298 0.00152129 11
13 -0.00170664 0.0550206 0.00542001 12
14 0.00327919 0.0554969 -0.00390619 13
15 0.00117224 0.0557831 -0.00196647 14
16 0.105943 0.0378376 -0.00980558 12
17 1.68454e-07 -0.157005 -2.90101e-07 16
18 1.17764e-07 -0.10976 -2.02806e-07 17
19 -3.12333e-18 -0.0548801 7.10897e-08 18
20 -1.28279e-18 -0.0225364 2.91929e-08 19
21 -1.0339e-18 -0.0181695 2.35361e-08 20
22 1.78412e-08 -0.0260878 3.10974e-08 19
23 -0.0988282 0.0432937 -0.0127496 12
24 -1.77206e-07 -0.165162 -3.05173e-07 23
25 -1.16433e-07 -0.108519 -2.00513e-07 24
26 3.08802e-18 -0.0542597 6.70519e-08 25
27 1.11643e-18 -0.0196147 2.4239e-08 26
28 8.99718e-19 -0.0158139 1.95421e-08 27
29 -1.50242e-08 -0.0227056 2.70658e-08 26
0 0.137811 0.583432 0.0451131 -1
1 0.137811 0.357903 0.0451131 0
2 0.137811 0.121865 0.0451131 1
3 0.137811 0.0486858 0.0305911 2
4 0.137811 0.011202 0.0305911 3
5 0.0537295 0.583432 0.0451131 0
6 0.0537295 0.349205 0.0451131 5
7 0.0537295 0.112609 0.0451131 6
8 0.0537295 0.0381506 0.0299378 7
9 0.0537295 0 0.0299379 8
10 0.0957544 0.704114 0.0125758 0
11 0.0975414 0.768669 0.0112288 10
12 0.0988285 0.833699 0.0127501 11
13 0.0971218 0.88872 0.0181701 12
14 0.100401 0.944217 0.0142639 13
15 0.101573 1 0.0122974 14
16 0.204771 0.871537 0.0029445 12
17 0.204771 0.714532 0.00294421 16
18 0.204772 0.604772 0.00294401 17
19 0.204772 0.549892 0.00294408 18
20 0.204772 0.527356 0.00294411 19
21 0.204772 0.509186 0.00294413 20
22 0.204772 0.523804 0.00294411 19
23 3.12924e-07 0.876993 5.06639e-07 12
24 1.35718e-07 0.711831 2.01466e-07 23
25 0 0.603312 0 24
26 0 0.549052 0 25
27 0 0.529438 0 26
28 0 0.513624 1.11786e-07 27
29 0 0.526347 0 26

30
skeleton.out Normal file
View file

@ -0,0 +1,30 @@
0 2.3462 53.9829 1.04428 -1
1 5.75874 34.4147 0.482767 0
2 6.48344 11.7505 -0.628775 1
3 6.65659 5.263 -0.586761 2
4 6.77683 1.34023 -0.33446 3
5 -4.64843 48.7597 1.71993 0
6 -5.72403 29.1603 0.0568622 5
7 -6.62952 11.1159 -0.574507 6
8 -6.66423 4.90962 -0.5577 7
9 -6.74013 1.14803 -0.275692 8
10 -0.604978 63.0263 0.779478 0
11 -0.130926 69.2639 -1.52999 10
12 0.115879 74.5396 -2.65442 11
13 -0.15631 79.638 -0.895521 12
14 0.0588091 84.345 -0.695696 13
15 0.0437946 89.1495 -0.353748 14
16 9.09887 72.4755 -2.84531 12
17 16.8129 64.0465 -2.13472 16
18 23.1151 58.5242 -0.650485 17
19 27.4567 54.6228 1.36793 18
20 28.2612 52.7851 1.45856 19
21 29.4334 50.6264 1.52051 20
22 27.5264 52.6479 1.44833 19
23 -8.56763 72.9413 -2.96782 12
24 -18.5195 62.3423 -2.08202 23
25 -25.8688 56.1692 0.456197 24
26 -28.335 53.0878 1.24571 25
27 -29.673 51.1485 1.84335 26
28 -29.8857 50.0595 1.80841 27
29 -28.5799 51.4408 1.22361 26