Skip to content

Commit

Permalink
add smpl pose_blend_shapes && update models
Browse files Browse the repository at this point in the history
  • Loading branch information
FishWoWater committed Jun 12, 2022
1 parent d435aea commit 632729d
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 9 deletions.
4 changes: 3 additions & 1 deletion models/female_model.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion models/male_model.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion v0.2.1/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,24 @@ void parse_smpl_motions(vector<Motion> &motions, const Json::Value &json, bool&
Quaternion rest = Quaternion();
rest.s = 1.;
rest.v = Vec3(0., 0., 0.);
/*
if(pid == 0){
rest.s = 0.707106;
rest.v[0] = 0.707106;
}
*/
motions[0].points[fid].x.rotations.push_back(rest * (1 - scale) + q * scale);
// nonsense
motions[0].points[fid].x.rotation = q;
motions[0].points[fid].v.rotations.emplace_back(Quaternion());
}
// interpolation for dynamic betas
for(int i=0;i<10;i++){
motions[0].points[fid].x.dynamic_betas[i] = smpl_betas[i] * scale;
// if(i == 1){
// motions[0].points[fid].x.dynamic_betas[i] = smpl_betas[i] * scale + (1 - scale);
// }else{
motions[0].points[fid].x.dynamic_betas[i] = smpl_betas[i] * scale;
// }
// if(i == 1) motions[0].points[fid].x.dynamic_betas[i] = 2;
}
motions[0].points[fid].t = (fid / fps) - 0;
Expand Down
4 changes: 4 additions & 0 deletions v0.2.1/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ void advance_step(Simulation &sim) {
update_obstacles(sim, sim.is_smpl);
vector<Constraint *> cons = get_constraints(sim, true);
physics_step(sim, cons);
// std::cout << "physics step finished" << std::endl;
plasticity_step(sim);
// std::cout << "plasticity step finished" << std::endl;
strainlimiting_step(sim, cons);
// std::cout << "strainlimiting step finished" << std::endl;
collision_step(sim);
// std::cout << "collision step finished" << std::endl;
if (sim.step % sim.frame_steps == 0) {
// remeshing_step(sim);
sim.frame++;
Expand Down
34 changes: 29 additions & 5 deletions v0.2.1/smpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ bool SMPL::loadPoseFromJSONFile(std::string filePath){
}

bool SMPL::loadModelFromJSONFile(std::string filePath){
std::cout << "begin to load smpl model" << std::endl;
ifstream in(filePath);
Json::Value root;
in >> root;
Expand All @@ -148,6 +147,7 @@ bool SMPL::loadModelFromJSONFile(std::string filePath){

loadEigenFromJSON(root["pose"], mPose);
loadTensorFromJSON(root["shapedirs"], mShapedDirsTensor);
loadTensorFromJSON(root["posedirs"], mPoseDirsTensor);
loadEigenFromJSON(root["f"], mF);
loadEigenFromJSON(root["kintree_table"], mKintreeTable);
loadEigenFromJSON(root["J"], mJ);
Expand All @@ -167,7 +167,7 @@ bool SMPL::loadModelFromJSONFile(std::string filePath){
mWeightsT = mWeights.transpose();

loadEigenFromJSON(root["vert_sym_idxs"], vertSymIdxs);
loadSparseFromJSON(root["J_regressor"], mJR, 24, mV.rows());
loadEigenFromJSON(root["J_regressor"], mJR);

return true;
}
Expand Down Expand Up @@ -222,13 +222,36 @@ bool SMPL::updateModel(bool jointsOnly){
mVTemp1(i,2) = mV(i,2) + AB(i,2,0);
mVTemp1(i,3) = 1;
}
// obtain poses_flat(207-dim vector from mPoses)
for(int i=0; i<23; i++){
cv::Mat src(cv::Size(1,3),CV_32FC1,cv::Scalar(0));
src.at<float>(0) = mPose(i+1, 0);
src.at<float>(1) = mPose(i+1, 1);
src.at<float>(2) = mPose(i+1, 2);
cv::Mat dst;
cv::Rodrigues(src, dst);
for(int j=0; j<3; j++){
for(int k=0; k<3; k++){
if(j == k) mPose_flat(i * 9 + 3 * j + k, 0) = dst.at<float>(j, k) - 1;
else mPose_flat(i * 9 + 3 * j + k, 0) = dst.at<float>(j, k);
}
}
}


// Shape J
mJTemp2.row(0) = mJ.row(0);
mJTemp1 = mJR * mVTemp1;
//mJTemp1 = mJ;

// cout << mJTemp1 << endl;
TensorD<3> pose_blend_shapes = mPoseDirsTensor.dot(mPose_flat);
for(int i=0; i<mVTemp1.rows(); i++){
mVTemp1(i,0) = mVTemp1(i,0) + pose_blend_shapes(i,0,0);
mVTemp1(i,1) = mVTemp1(i,1) + pose_blend_shapes(i,1,0);
mVTemp1(i,2) = mVTemp1(i,2) + pose_blend_shapes(i,2,0);
mVTemp1(i,3) = 1;
}

// cout << mJTemp1 << endl;

// Body pose
Eigen::Matrix4f& bodyPose = globalTransforms[0];
Expand Down Expand Up @@ -289,4 +312,5 @@ bool SMPL::updateModel(bool jointsOnly){
}

return true;
}

}
5 changes: 4 additions & 1 deletion v0.2.1/smpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ class SMPL{
Eigen::MatrixXf mWeightsT;
Eigen::MatrixXf vertSymIdxs;
Eigen::MatrixXf mBetas;
Eigen::SparseMatrix<float> mJR;
Eigen::MatrixXf mPose_flat;
Eigen::MatrixXf mJR;
typedef Eigen::Matrix<float, 4, 24> BlockMatrix;
std::vector<Eigen::MatrixXf> weightedBlockMatrix1;
std::vector<BlockMatrix> blocks;
TensorD<3> mShapedDirsTensor;
TensorD<3> mPoseDirsTensor;

SMPL(){
blocks.resize(4);
weightedBlockMatrix1.resize(4);
mBetas.resize(10,1);
mPose.resize(24, 3);
mBetas.setZero();
mPose_flat.resize(207, 1);
}

enum Part
Expand Down
Loading

0 comments on commit 632729d

Please sign in to comment.