Skip to content

Commit

Permalink
Merge pull request #256 from zenustech/LSLTQL
Browse files Browse the repository at this point in the history
cihou zhouhang
  • Loading branch information
zhouhang95 authored Dec 17, 2021
2 parents 17bc491 + d21028d commit f3516af
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 504 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "projects/cgmesh/libigl"]
path = projects/cgmesh/libigl
url = https://github.com/zenustech/libigl.git
[submodule "projects/FEM/OpenSim"]
path = projects/FEM/OpenSim
url = https://github.com/zenustech/opensim-core.git
3 changes: 3 additions & 0 deletions docs/dev_win10.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ vcpkg install lapack:x64-windows
@rem (Optional) Install Alembic for the extension Alembic:
vcpkg install alembic[hdf5]:x64-windows
@rem (Optional) Install libigl for the extension Skinning:
vcpkg install libigl:x64-windows
```

> Notice that you may need to install the `English Pack` for VS2019 for vcpkg to work.
Expand Down
5 changes: 5 additions & 0 deletions projects/FEM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)

if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif(WIN32)

project(zeno_FEM)

find_package(Eigen3 REQUIRED NO_MODULE)
Expand Down
1 change: 0 additions & 1 deletion projects/FEM/OpenSim
Submodule OpenSim deleted from 6faaed
4 changes: 2 additions & 2 deletions projects/FEM/nodesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ struct SolveEquaUsingNRSolver : zeno::INode {
}

stop_error *= epsilon;
stop_error *= sqrt(mesh->_mesh->size());
stop_error *= sqrt((double)mesh->_mesh->size());

std::cout << "STOP_ERROR : " << stop_error << std::endl;
}
Expand Down Expand Up @@ -2701,7 +2701,7 @@ struct GetEffectiveStress : zeno::INode {


dynamic_cast<ElasticModel*>(force_model->_forceModel.get())->ComputePrincipalStress(attrbs,s,ps);
FEM_Scaler vm = pow(ps[0] - ps[1],2) + pow(ps[1] - ps[2],2) + pow(ps[0] - ps[2],2);
FEM_Scaler vm = pow(ps[0] - ps[1], 2.0) + pow(ps[1] - ps[2], 2.0) + pow(ps[0] - ps[2], 2.0);
vm = vm / 2;
vm = sqrt(vm);

Expand Down
2 changes: 1 addition & 1 deletion projects/FEM/src/bspline/cubicBspline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void UniformCubicBasisSpline::Interpolate(const VecXd& interps,const Vec2d& _int
}

void UniformCubicBasisSpline::SetCtrlPoints(const VecXd& _ctrlps) {
assert(_ctrlsps.size() == ctrlps.size());
assert(_ctrlps.size() == ctrlps.size());
ctrlps = _ctrlps;
poly_bezier_ctrlps = cp2pp_map * ctrlps;
update_integration_offset();
Expand Down
1 change: 1 addition & 0 deletions projects/FEM/src/force_model/base_elastic_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <iostream>
#include <limits>
#include <array>

/**
* @class <ElasticModel>
Expand Down
12 changes: 10 additions & 2 deletions projects/Skinning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ project(zeno_SKINNING)

find_package(Eigen3 REQUIRED NO_MODULE)

if(WIN32)
find_package(libigl REQUIRED)
endif(WIN32)

find_package(OpenMP)
if(NOT OpenMP_CXX_FOUND)

endif(NOT OpenMP_CXX_FOUND)

set(SKINNING_SOURCE_FILES
skinning_nodesys.cpp
bone_animation.cpp
bone_system.cpp
igl_file_reader.cpp
skinning_bbw.cpp
skinning.cpp
)

add_library(zeno_SKINNING SHARED ${SKINNING_SOURCE_FILES})
target_link_libraries(zeno_SKINNING PRIVATE Eigen3::Eigen)
target_link_libraries(zeno_SKINNING PUBLIC OpenMP::OpenMP_CXX)

target_link_libraries(zeno_SKINNING PRIVATE igl::core igl::cgal)
target_link_libraries(zeno_SKINNING PRIVATE igl::core)

target_link_libraries(zeno_SKINNING PUBLIC zeno)
target_link_libraries(zeno_SKINNING PRIVATE zeno_nodep)
Expand Down
44 changes: 44 additions & 0 deletions projects/Skinning/bone_animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <zeno/zeno.h>
#include <zeno/logger.h>
#include <zeno/ListObject.h>
#include <zeno/NumericObject.h>
#include <zeno/PrimitiveObject.h>
#include <zeno/utils/UserData.h>
#include <zeno/StringObject.h>


#include <igl/readDMAT.h>
#include <igl/column_to_quats.h>

#include "skinning_iobject.h"

namespace{
using namespace zeno;

struct ReadPoseFrame : zeno::INode {
virtual void apply() override {
auto res = std::make_shared<PosesAnimationFrame>();
auto bones = get_input<zeno::PrimitiveObject>("bones");
auto dmat_path = get_input<zeno::StringObject>("dmat_path")->get();

Eigen::MatrixXd Q;
igl::readDMAT(dmat_path,Q);

if(bones->lines.size() != Q.rows()/4 || Q.rows() % 4 != 0){
std::cout << "THE DIMENSION OF BONES DOES NOT MATCH POSES " << bones->lines.size() << "\t" << Q.rows() << std::endl;
throw std::runtime_error("THE DIMENSION OF BONES DOES NOT MATCH POSES");
}

igl::column_to_quats(Q,res->posesFrame);
set_output("posesFrame",std::move(res));
}
};

ZENDEFNODE(ReadPoseFrame, {
{{"readpath","dmat_path"},"bones"},
{"posesFrame"},
{},
{"Skinning"},
});

}
55 changes: 55 additions & 0 deletions projects/Skinning/bone_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <zeno/zeno.h>
#include <zeno/logger.h>
#include <zeno/ListObject.h>
#include <zeno/NumericObject.h>
#include <zeno/PrimitiveObject.h>
#include <zeno/utils/UserData.h>
#include <zeno/StringObject.h>

#include "skinning_iobject.h"

namespace{
using namespace zeno;

struct MakeEmptyBones : zeno::INode {
virtual void apply() override {
auto root = get_input<zeno::NumericObject>("root")->get<zeno::vec3f>();
auto res = std::make_shared<zeno::PrimitiveObject>();

res->resize(1);
res->verts[0] = root;

set_output("bones",std::move(res));
}
};

ZENDEFNODE(MakeEmptyBones, {
{"root"},
{"bones"},
{},
{"Skinning"},
});

struct AddBone : zeno::INode {
virtual void apply() override {
auto bones = get_input<zeno::PrimitiveObject>("bones");
auto node = get_input<zeno::NumericObject>("node")->get<zeno::vec3f>();
auto connect_to = get_input<zeno::NumericObject>("conn_to")->get<int>();

int idx = bones->size();

bones->verts.emplace_back(node);
bones->lines.emplace_back(connect_to,idx);

set_output("bones_out",bones);
}
};

ZENDEFNODE(AddBone, {
{"bones","node","conn_to"},
{"bones_out"},
{},
{"Skinning"},
});

};
102 changes: 102 additions & 0 deletions projects/Skinning/igl_file_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <zeno/zeno.h>
#include <zeno/logger.h>
#include <zeno/ListObject.h>
#include <zeno/NumericObject.h>
#include <zeno/PrimitiveObject.h>
#include <zeno/utils/UserData.h>
#include <zeno/StringObject.h>

#include <igl/readOBJ.h>
#include <igl/readTGF.h>
#include <igl/readMESH.h>

#include "skinning_iobject.h"

namespace{
using namespace zeno;

struct LoadTFGPrimitiveFromFile : zeno::INode {
virtual void apply() override {
auto res = std::make_shared<zeno::PrimitiveObject>();
auto tfg_path = get_input<zeno::StringObject>("tfg")->get();

Eigen::MatrixXd C;
Eigen::MatrixXi BE;
igl::readTGF(tfg_path,C,BE);

assert(C.cols() == 3);
assert(BE.cols() == 2);


// auto& parents = res->add_attr<int>("parents");
res->resize(C.rows());
auto& pos = res->attr<zeno::vec3f>("pos");
auto& segs = res->lines;
segs.resize(BE.rows());

for(size_t i = 0;i < C.rows();++i)
pos[i] = zeno::vec3f(C.row(i)[0],C.row(i)[1],C.row(i)[2]);
for(size_t i = 0;i < BE.rows();++i)
segs[i] = zeno::vec2i(BE.row(i)[0],BE.row(i)[1]);

// Eigen::VectorXi P;
// igl::directed_edge_parents(BE,P);

// std::cout << "BE : " << std::endl << BE << std::endl;
// std::cout << "P : " << std::endl << P.transpose() << std::endl;

// std::cout << "P : " << P.rows() << "\t" << P.cols() << std::endl;
// std::cout << "parents : " << parents.size() << std::endl;

// for(size_t i = 0;i < parents.size();++i)
// parents[i] = P[i];

set_output("res",std::move(res));
}
};

ZENDEFNODE(LoadTFGPrimitiveFromFile, {
{{"readpath","tfg"}},
{"res"},
{},
{"Skinning"},
});

struct ReadMesh : zeno::INode {
virtual void apply() override {
auto res = std::make_shared<PrimitiveObject>();
auto mesh_path = get_input<zeno::StringObject>("mesh")->get();

Eigen::MatrixXd V;
Eigen::MatrixXi T,F;
igl::readMESH(mesh_path,V,T,F);

// we only support 3d simplex volumetric meshing
assert(V.cols() == 3 && T.cols() == 4 && F.cols() == 3);

res->resize(V.rows());
for(size_t i = 0;i < V.rows();++i)
res->verts[i] = zeno::vec3f(V.row(i)[0],V.row(i)[1],V.row(i)[2]);
for(size_t i = 0;i < T.rows();++i)
res->quads.emplace_back(T.row(i)[0],T.row(i)[1],T.row(i)[2],T.row(i)[3]);

for(size_t i = 0;i < res->quads.size();++i){
auto tet = res->quads[i];
res->tris.emplace_back(tet[0],tet[1],tet[2]);
res->tris.emplace_back(tet[1],tet[3],tet[2]);
res->tris.emplace_back(tet[0],tet[2],tet[3]);
res->tris.emplace_back(tet[0],tet[3],tet[1]);
}

set_output("res",std::move(res));
}
};

ZENDEFNODE(ReadMesh, {
{{"readpath","mesh"}},
{"res"},
{},
{"Skinning"},
});

};
Loading

0 comments on commit f3516af

Please sign in to comment.