-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.cpp
More file actions
224 lines (201 loc) · 6.81 KB
/
main.cpp
File metadata and controls
224 lines (201 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (c) 2019 Nobuyuki Umetani
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @brief putting cloth on SMPL modl
* @details
*/
#include <random>
#if defined(_WIN32) // windows
# define NOMINMAX // to remove min,max macro
# include <windows.h>
#endif
#define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h>
#include "inputs_garment.h"
#include "delfem2/fem_quadratic_bending.h"
#include "delfem2/garment.h"
#include "delfem2/pbd_geo3.h"
#include "delfem2/rig_geo3.h"
#include "delfem2/srch_bv3_aabb.h"
#include "delfem2/mshmisc.h"
#include "delfem2/cad2_io_svg.h"
#include "delfem2/cnpy/smpl_cnpy.h"
#include "delfem2/stb_opengl/glyph.h"
#include "delfem2/glfw/util.h"
#include "delfem2/glfw/viewer2.h"
#include "delfem2/glfw/viewer3.h"
#include "delfem2/opengl/old/cad2dtriv2.h"
#include "delfem2/opengl/old/funcs.h"
#include "delfem2/opengl/old/v3q.h"
#include "delfem2/opengl/old/color.h"
#include "delfem2/opengl/old/mshuni.h"
#include "delfem2/opengl/old/caddtri_v3.h"
namespace dfm2 = delfem2;
void Draw(
const std::vector<dfm2::CDynTri>& aETri_Cloth,
std::vector<unsigned int> aLine_Cloth,
const std::vector<double>& aXYZ_Cloth,
[[maybe_unused]] const std::vector<dfm2::CVec2d>& aVec2,
const dfm2::CProjector_RigMesh& projector_smpl,
dfm2::glfw::CViewer3& viewer)
{
viewer.DrawBegin_oldGL();
{ // draw seam
::glDisable(GL_TEXTURE_2D);
::glDisable(GL_LIGHTING);
::glColor3d(0,1,1);
const unsigned int nline = aLine_Cloth.size()/2;
::glBegin(GL_LINES);
for(unsigned int il=0;il<nline;++il) {
const unsigned int ip0 = aLine_Cloth[il * 2 + 0];
const unsigned int ip1 = aLine_Cloth[il * 2 + 1];
::glVertex3dv(aXYZ_Cloth.data()+ip0*3);
::glVertex3dv(aXYZ_Cloth.data()+ip1*3);
}
::glEnd();
}
::glDisable(GL_TEXTURE_2D);
::glEnable(GL_NORMALIZE);
::glEnable(GL_LIGHTING);
dfm2::opengl::myGlColorDiffuse( dfm2::CColor::Gray(0.8f) );
// delfem2::opengl::DrawMeshTri3D_Edge(aXYZ_Contact.data(), aXYZ_Contact.size()/3,
// aTri_Contact.data(), aTri_Contact.size()/3);
// draw body
::glEnable(GL_LIGHTING);
dfm2::opengl::myGlColorDiffuse( dfm2::CColor::Gray(0.8f) );
delfem2::opengl::DrawMeshTri3D_FaceNorm(
projector_smpl.aXYZ1_Body.data(),
projector_smpl.aTri_Body.data(),
projector_smpl.aTri_Body.size()/3);
// draw cloth edge
::glDisable(GL_LIGHTING);
::glColor3d(0,0,0);
// delfem2::opengl::DrawMeshDynTri3D_Edge(aXYZ, aETri);
delfem2::opengl::DrawMeshDynTri3D_Edge(aXYZ_Cloth, aETri_Cloth);
::glEnable(GL_LIGHTING);
dfm2::opengl::myGlColorDiffuse( dfm2::CColor::Red() );
delfem2::opengl::DrawMeshDynTri_FaceNorm(aETri_Cloth, aXYZ_Cloth.data());
// delfem2::opengl::DrawMeshDynTri_FaceNormTex(aETri_Cloth, aXYZ_Cloth.data(), aVec2);
glfwSwapBuffers(viewer.window);
}
// --------------------
int main()
{
const double mesher_edge_length = 0.02;
// -----------------------------
std::vector<dfm2::CDynTri> tri_vtx_cloth;
std::vector<dfm2::CVec2d> vtx_xy_cloth;
std::vector<double> vtx_xyz_pattern; // deformed vertex positions
std::vector<unsigned int> line_vtx_cloth;
delfem2::CCad2D cad;
{ // prepare clothing input data
dfm2::CMesher_Cad2D mesher;
std::string name_cad_in_test_input;
double scale_adjust = 0.0;
std::vector<unsigned int> aIESeam;
double mesher_edge_length0;
std::vector<dfm2::CRigidTrans_2DTo3D> aRT23;
// -------
dfm2::Inputs_SmplTshirt2(
name_cad_in_test_input,
scale_adjust,
aIESeam,
mesher_edge_length0,
aRT23);
std::string path_svg = std::string(PATH_INPUT_DIR)+"/"+name_cad_in_test_input;
std::cout << "open svg: " << path_svg << std::endl;
dfm2::ReadSVG_Cad2D(cad, path_svg, 0.001*scale_adjust);
// -------
dfm2::MeshingPattern(
tri_vtx_cloth, vtx_xy_cloth, vtx_xyz_pattern, line_vtx_cloth, mesher,
aRT23, cad, aIESeam, mesher_edge_length);
}
std::vector<double> aXYZt_Cloth = vtx_xyz_pattern;
std::vector<double> vtx_uvw_cloth(vtx_xyz_pattern.size(), 0.0);
const std::vector<int> dof_bcflag_cloth(vtx_xyz_pattern.size()/3, 0);
// ----------
dfm2::CProjector_RigMesh body_smpl;
{
std::vector<double> aW_Body;
std::vector<unsigned int> aIndBoneParent;
std::vector<double> aJntRgrs;
dfm2::cnpy::LoadSmpl_Bone(
body_smpl.aXYZ0_Body,
aW_Body,
body_smpl.aTri_Body,
aIndBoneParent,
aJntRgrs,
std::string(PATH_INPUT_DIR)+"/smpl_model_f.npz");
{
std::vector<double> aJntPos0;
dfm2::Points3_WeighttranspPosition(
aJntPos0,
aJntRgrs, body_smpl.aXYZ0_Body);
dfm2::InitBones_JointPosition(
body_smpl.aBone,
aIndBoneParent.size(), aIndBoneParent.data(), aJntPos0.data());
}
dfm2::SparsifyMatrixRow(
body_smpl.aSkinningSparseWeight,
body_smpl.aSkinningSparseIdBone,
aW_Body.data(),
body_smpl.aXYZ0_Body.size() / 3,
body_smpl.aBone.size(),
1.0e-5);
}
body_smpl.UpdatePose(true);
std::vector< dfm2::CQuatd > aQuatTarget;
{
std::ifstream fin(std::string(PATH_INPUT_DIR)+"/pose_smpl1.txt");
for(unsigned int ib=0; ib < body_smpl.aBone.size(); ++ib){
double d0,d1,d2,d3;
fin >> d0 >> d1 >> d2 >> d3;
auto q = dfm2::CQuatd(d0,d1,d2,d3);
q.SetSmallerRotation();
aQuatTarget.push_back( q );
}
{
dfm2::CVec3d posTarget;
double d0,d1,d2;
fin >> d0 >> d1 >> d2;
posTarget = dfm2::CVec3d(d0,d1,d2);
}
}
delfem2::openglstb::CGlyph glyph(std::string(PATH_INPUT_DIR)+"/myFont.png");
glyph.ParseGlyphInfo(std::string(PATH_INPUT_DIR)+"/myFont.fnt");
// -----------
dfm2::glfw::CViewer3 viewer3;
dfm2::glfw::CViewer2 viewer2;
dfm2::glfw::InitGLOld();
viewer3.OpenWindow();
dfm2::opengl::setSomeLighting();
viewer2.OpenWindow();
::glfwMakeContextCurrent(viewer2.window);
glyph.InitGL();
while( !glfwWindowShouldClose(viewer2.window) && !glfwWindowShouldClose(viewer3.window) ) {
::glfwMakeContextCurrent(viewer3.window);
Draw(
tri_vtx_cloth, line_vtx_cloth, vtx_xyz_pattern, vtx_xy_cloth,
body_smpl, viewer3);
viewer2.DrawBegin_oldGL();
delfem2::opengl::DrawCad2Vtxs(cad, UINT_MAX);
delfem2::opengl::DrawCad2Edges(cad, UINT_MAX);
{
::glTranslated(0,0,+0.9);
for(unsigned int ie=0;ie<cad.topo.edges.size();++ie){
unsigned int iv0 = cad.topo.edges[ie].iv0;
unsigned int iv1 = cad.topo.edges[ie].iv1;
dfm2::CVec2d p = (cad.aVtx[iv0].pos+cad.aVtx[iv1].pos)*0.5;
glyph.DrawStringAt(std::to_string(ie),0.001, p.x, p.y);
}
::glTranslated(0,0,-0.9);
}
glfwSwapBuffers(viewer2.window);
glfwPollEvents();
viewer3.ExitIfClosed();
}
}