Skip to content

Commit

Permalink
clean code & add demofile
Browse files Browse the repository at this point in the history
  • Loading branch information
FishWoWater committed Apr 26, 2022
1 parent 2bb0ba3 commit 8ee8ab0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,42 @@ addons

* SMPL forward kinematics (based on [SMPL_cpp](https://github.com/soulslicer/smpl_cpp))
* SMPL integration with ARCSim (forwarded SMPL model as the obstacle)
* SMPL shape interpolation and pose interpolation to simulate any SMPL pose
* SMPL shape interpolation and pose interpolation to simulate any SMPL pose (for the details of interpolation, refer to [Discussion](https://github.com/isantesteban/vto-dataset/issues/1))
* a `play` option like original `replay`, for checkout the SMPL motion and don't care the cloth

flags:
fields:
* `is_smpl`
* `motions`->`'smpl_fps` how fast smpl model act
* `motions`->`smpl_fps` how fast smpl model act
* `motions`->`smpl_motfile`
* `motions`->`smpl_initialization_steps` (for shape and pose interpolation)



Usage

* Simulate a simple motion `hands raise up` with shape / pose interpolation

* `./build-Release/bin/arcsim_0.2.1 simulate smpl_demo/pbns_sbs_male.json`

* Just checkout the motion and save each screen shot to some directory(optional)

* `./build-Release/bin/arcsim_0.2.1 play smpl_demo/pbns_sbs_male.json vis`

* the visualization will be saved to `vis` directory, this is a useful tool for the visualization of MoCap sequences



Demo

![](imgs/demo_handsup.gif)



TODOs

- [ ] Support SMPL female model (now only male model is supported)
- [ ] Support CMU MoCap sequence reading from npz or json file (now read from txt motion file)



Thanks for @[isantesteban](https://github.com/isantesteban) for valuable discussions
Binary file added imgs/demo_handsup.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
1 change: 0 additions & 1 deletion v0.2.1/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ void load_json(const string &configFilename, Simulation &sim) {
sim.enabled[Simulation::StrainLimiting] = false;
if (!has_plasticity)
sim.enabled[Simulation::Plasticity] = false;
std::cout << "obstacled parsed" << std::endl;
}

// Basic data types
Expand Down
2 changes: 1 addition & 1 deletion v0.2.1/displayreplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool running = true;
static void reload () {
int fullframe = ::frame*::frameskip;
sim.time = fullframe * sim.frame_time;
std::cout << "cloth file" << stringf("%s/%04d_00.obj",inprefix.c_str(), fullframe) << std::endl;
// std::cout << "cloth file" << stringf("%s/%04d_00.obj",inprefix.c_str(), fullframe) << std::endl;
if(!boost::filesystem::exists(stringf("%s/%04d_00.obj",inprefix.c_str(), fullframe))){
std::cout << "can not find cloth file" << std::endl;
if (::frame == 0)
Expand Down
6 changes: 3 additions & 3 deletions v0.2.1/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ vector<Face*> triangulate (const vector<Vert*> &verts) {
}

void save_obj (const Mesh &mesh, const string &filename) {
std::cout << "start saving obj" << filename << std::endl;
// std::cout << "start saving obj" << filename << std::endl;
fstream file(filename.c_str(), ios::out);
for (int v = 0; v < mesh.verts.size(); v++) {
const Vert *vert = mesh.verts[v];
Expand Down Expand Up @@ -264,11 +264,11 @@ void save_obj (const Mesh &mesh, const string &filename) {
if (face->damage)
file << "td " << face->damage << endl;
}
std::cout << "end saving obj" << filename << std::endl;
// std::cout << "end saving obj" << filename << std::endl;
}

void save_objs (const vector<Mesh*> &meshes, const string &prefix) {
std::cout << "insidebefore saving cloth mesh" <<std::endl;
// std::cout << "insidebefore saving cloth mesh" <<std::endl;
for (int m = 0; m < meshes.size(); m++)
save_obj(*meshes[m], stringf("%s_%02d.obj", prefix.c_str(), m));
}
Expand Down
10 changes: 5 additions & 5 deletions v0.2.1/obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Mesh& Obstacle::get_smpl_mesh(double time) {
// 1. interpolate the quaternion in transformation
// 2. convert quaternion to axis-angle
// 3. parse axis-angle poses and betas to smpl model;
std::cout << "entering get smpl mesh" << std::endl;
// std::cout << "entering get smpl mesh" << std::endl;
Quaternion x;
// x.to_axisangle;
if (time > end_time)
Expand All @@ -81,7 +81,7 @@ Mesh& Obstacle::get_smpl_mesh(double time) {
Vec3 smpl_translation = smpl_transformation.translation;
// used for interpolation
std::vector<double> dynamic_betas = smpl_transformation.dynamic_betas;
std::cout << "smpl translation:" << smpl_translation << std::endl;
// std::cout << "smpl translation:" << smpl_translation << std::endl;
Eigen::VectorXf thetas, dyna_betas;
thetas.resize(72);
dyna_betas.resize(10);
Expand All @@ -102,7 +102,7 @@ Mesh& Obstacle::get_smpl_mesh(double time) {

smpl->setAllShapes(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);

Expand All @@ -118,13 +118,13 @@ Mesh& Obstacle::get_smpl_mesh(double time) {
mesh.nodes[n]->x[1] = vertices(n, 1) + smpl_translation[1];
mesh.nodes[n]->x[2] = vertices(n, 2) + smpl_translation[2];
}
std::cout << "smpl mesh assigned to arcsim mesh" << std::endl;
// std::cout << "smpl mesh assigned to arcsim mesh" << std::endl;
compute_ws_data(mesh);
}
if (!activated)
update_x0(curr_state_mesh);
activated = true;
std::cout << "smpl mesh updated" << std::endl;
// std::cout << "smpl mesh updated" << std::endl;
return curr_state_mesh;
}

Expand Down
10 changes: 5 additions & 5 deletions v0.2.1/runphysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ void init_physics (const string &json_file, string outprefix,

static void save (const vector<Mesh*> &meshes, int frame, bool is_obs=false) {
if (!outprefix.empty() && frame < 10000)
std::cout << "before saving cloth mesh" <<std::endl;
// std::cout << "before saving cloth mesh" <<std::endl;
if(is_obs) save_objs(meshes, stringf("%s/obs_%04d", outprefix.c_str(), frame));
else save_objs(meshes, stringf("%s/%04d", outprefix.c_str(), frame));
std::cout << "end saving cloth mesh" <<std::endl;
// std::cout << "end saving cloth mesh" <<std::endl;
}

static void save_obstacle_transforms (const vector<Obstacle> &obs, int frame,
Expand All @@ -85,12 +85,12 @@ static void save_obstacle_transforms (const vector<Obstacle> &obs, int frame,
Transformation trans = identity_();
if (obs[o].transform_spline) {
trans = get_dtrans(*obs[o].transform_spline, time).first;
std::cout << "get dtrans finished, to save transformation" << std::endl;
// std::cout << "get dtrans finished, to save transformation" << std::endl;
save_transformation(trans, stringf("%s/%04dobs%02d.txt",
outprefix.c_str(), frame, o));
}else if(obs[o].smpl_motion){
trans = get_smpl_transformation(*obs[0].smpl_motion, time);
std::cout << "get smpl transform finished, to save transformation" << std::endl;
// std::cout << "get smpl transform finished, to save transformation" << std::endl;
// logic for saving smpl transform
save_smpl_transformation(trans, stringf("%s/%04dobs%02d.txt",
outprefix.c_str(), frame, o));
Expand All @@ -116,7 +116,7 @@ void save (const Simulation &sim, int frame) {
// also to save the obstacles
// save(sim.obstacle_meshes, frame, true);
save_obstacle_transforms(sim.obstacles, frame, sim.time);
std::cout << "end saving obs transform" <<std::endl;
// std::cout << "end saving obs transform" <<std::endl;
}

void sim_step() {
Expand Down
12 changes: 6 additions & 6 deletions v0.2.1/transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ DTransformation get_dtrans (const Motion &motion, double t) {

std::vector<Quaternion> get_smpl_quaternions(const Motion &motion, double t){
// input transform_spline: spline<transformation> where
std::cout << "entering get smpl quaternions" << std::endl;
std::cout << "T.rotations" << motion.points[0].x.rotations.size() << std::endl;
// std::cout << "entering get smpl quaternions" << std::endl;
// std::cout << "T.rotations" << motion.points[0].x.rotations.size() << std::endl;
// for(int i=0;i<motion.points.size();i++) {
// std::cout << motion.points[i].x.rotations[0] << std::endl;
// }
Expand All @@ -267,20 +267,20 @@ std::vector<Quaternion> get_smpl_quaternions(const Motion &motion, double t){
for(int i=0;i<T.rotations.size();i++){
T.rotations[i] = normalize(T.rotations[i]);
}
std::cout << "T.rotations" << T.rotations.size() << std::endl;
// std::cout << "T.rotations" << T.rotations.size() << std::endl;
return T.rotations;
}

Transformation get_smpl_transformation(const Motion &motion, double t){
// input transform_spline: spline<transformation> where
std::cout << "entering get smpl transformation" << std::endl;
std::cout << "T.rotations" << motion.points[0].x.rotations.size() << std::endl;
// std::cout << "entering get smpl transformation" << std::endl;
// std::cout << "T.rotations" << motion.points[0].x.rotations.size() << std::endl;

Transformation T = motion.pos(t);
for(int i=0;i<T.rotations.size();i++){
T.rotations[i] = normalize(T.rotations[i]);
}
std::cout << "T.rotations" << T.rotations.size() << std::endl;
// std::cout << "T.rotations" << T.rotations.size() << std::endl;
return T;
}

Expand Down

0 comments on commit 8ee8ab0

Please sign in to comment.