diff --git a/v0.2.1/conf.cpp b/v0.2.1/conf.cpp index a48ee4e..89f6565 100755 --- a/v0.2.1/conf.cpp +++ b/v0.2.1/conf.cpp @@ -371,13 +371,14 @@ void parse_smpl_motions(vector &motions, const Json::Value &json, bool& trans(fid, i) = tmp; } } + int keep_frames = 10; // thetas now have F x 72 in axis-angle representations // should parse thetas into one motion // motion is Spline // only one part for SMPL motions.resize(1); // points is a structure with x and v, where x is the transformation - motions[0].points.resize(num_frames + initialization_frames); + motions[0].points.resize(num_frames + initialization_frames + keep_frames); // consider the interpolation process for(int fid = 0;fid < initialization_frames;fid++){ double scale = double(fid) / double(initialization_frames); @@ -415,9 +416,32 @@ void parse_smpl_motions(vector &motions, const Json::Value &json, bool& } motions[0].points[fid].t = (fid / fps) - 0; } + for(int fid = initialization_frames; fid < initialization_frames + keep_frames; fid++){ + motions[0].points[fid].x.translation = Vec3(trans(0, 0), trans(0, 1), trans(0, 2)); + for(int pid = 0;pid < 24; pid++){ + float thetax = thetas(0,3 * pid), thetay = thetas(0,3 * pid + 1), thetaz = thetas(0,3 * pid + 2); + // calculate the normalize angle and axis + float angle = sqrt(thetax * thetax + thetay * thetay + thetaz * thetaz) + 1e-8; + Vec3 axis = Vec3(thetax / angle, thetay / angle, thetaz / angle); + Quaternion q = Quaternion::from_axisangle(axis, angle); + // rotations contain 24 parts + motions[0].points[fid].x.rotations.push_back(q); + // setup the translation + // nonsense + motions[0].points[fid].x.rotation = q; + motions[0].points[fid].v.rotations.emplace_back(Quaternion()); - for (int fid = initialization_frames; fid < num_frames + initialization_frames; fid++) { - int fid2 = fid - initialization_frames; + } + motions[0].points[fid].v = Transformation(); + motions[0].points[fid].x.dynamic_betas.resize(10); + for(int i=0;i<10;i++){ + motions[0].points[fid].x.dynamic_betas[i] = smpl_betas[i]; + } + motions[0].points[fid].t = (fid / fps) - 0; // here 0 indicates the start time + } + + for (int fid = initialization_frames + keep_frames; fid < num_frames + initialization_frames + keep_frames; fid++) { + int fid2 = fid - initialization_frames - keep_frames; motions[0].points[fid].x.translation = Vec3(trans(fid2, 0), trans(fid2, 1), trans(fid2, 2)); for(int pid = 0;pid < 24; pid++){ float thetax = thetas(fid2,3 * pid), thetay = thetas(fid2,3 * pid + 1), thetaz = thetas(fid2,3 * pid + 2); @@ -442,6 +466,14 @@ void parse_smpl_motions(vector &motions, const Json::Value &json, bool& motions[0].points[fid].t = (fid / fps) - 0; // here 0 indicates the start time } + // fill in the velocity + for(int fid=0;fidsetAllShapes(dyna_betas); smpl->updateModel(); - // std::cout << "smpl model updated" << std::endl; +// std::cout << "smpl model updated" << std::endl; // smpl->saveToOBJ("rest_smpl.obj"); // exit(0); @@ -142,3 +142,20 @@ void Obstacle::blend_with_previous (double t, double dt, double blend) { } compute_ws_data(mesh); } + +void Obstacle::smpl_blend_with_previous (double t, double dt, double blend) { + const Motion *spline = smpl_motion; +// Transformation trans = (spline) +// ? get_trans(*spline, t) +// * inverse(get_trans(*spline, t-dt)) +// : identity_(); + Mesh &mesh = curr_state_mesh; + for (int n = 0; n < mesh.nodes.size(); n++) { + Node *node = mesh.nodes[n]; +// Vec3 x0 = trans.apply(node->x0); + Vec3 x0 = node -> x0; + node->x = x0 + blend*(node->x - x0); + } + compute_ws_data(mesh); +} + diff --git a/v0.2.1/obstacle.hpp b/v0.2.1/obstacle.hpp index 901c980..9895911 100755 --- a/v0.2.1/obstacle.hpp +++ b/v0.2.1/obstacle.hpp @@ -53,6 +53,7 @@ struct Obstacle { // lerp with previous mesh at time t - dt void blend_with_previous (double t, double dt, double blend); + void smpl_blend_with_previous (double t, double dt, double blend); const Motion *transform_spline; diff --git a/v0.2.1/runphysics.cpp b/v0.2.1/runphysics.cpp index 955b2d4..b245b3c 100755 --- a/v0.2.1/runphysics.cpp +++ b/v0.2.1/runphysics.cpp @@ -114,7 +114,7 @@ static void save_timings () { void save (const Simulation &sim, int frame) { save(sim.cloth_meshes, frame); // also to save the obstacles - // save(sim.obstacle_meshes, frame, true); + save(sim.obstacle_meshes, frame, true); save_obstacle_transforms(sim.obstacles, frame, sim.time); // std::cout << "end saving obs transform" <v = (node -> x - node -> x) / sim.step_time; + // node->v = (node -> x - node -> x) / sim.step_time; + node->v = (node->x - node->x0) / sim.step_time; + node->x = node->x0; } } } diff --git a/v0.2.1/spline.cpp b/v0.2.1/spline.cpp index c91bd0e..4ceb675 100755 --- a/v0.2.1/spline.cpp +++ b/v0.2.1/spline.cpp @@ -57,15 +57,28 @@ T Spline::pos (double t) const { const Point &p0 = points[i-1], &p1 = points[i]; // return p0.x; double s = (t - p0.t)/(p1.t - p0.t), s2 = s*s, s3 = s2*s; - -// T tmp2 = p0.x*(2*s3 - 3*s2 + 1) + p1.x*(-2*s3 + 3*s2) -// + (p0.v*(s3 - 2*s2 + s) + p1.v*(s3 - s2))*(p1.t - p0.t); - -// return tmp2; +// std::cout << "p0, p1t t " << p0.t << " " <