-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (99 loc) · 2.85 KB
/
main.cpp
File metadata and controls
106 lines (99 loc) · 2.85 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
/*
* 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 edit rigged shape
* @details rotation for each bone and translation for root bone
*/
#include <cstdlib>
#include <fstream>
#if defined(_WIN32) // windows
# define NOMINMAX // to remove min,max macro
# include <windows.h>
#endif
#define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h>
#include "delfem2/rig_geo3.h"
#include "delfem2/mat4.h"
#include "delfem2/cnpy/smpl_cnpy.h"
#include "delfem2/glfw/ViewRig.h"
#include "delfem2/glfw/util.h"
#include "delfem2/opengl/old/funcs.h"
#include "delfem2/opengl/tex.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
namespace dfm2 = delfem2;
// ---------------------------
int main() {
dfm2::glfw::CViewerGlfw_RiggedMesh viewer;
{
std::vector<double> aXYZ0, aXYZ1;
std::vector<unsigned int> aTri;
std::vector<double> aWeightRigSparse;
std::vector<unsigned int> aIdBoneRigSparse;
std::vector<dfm2::CRigBone> aBone;
//
std::vector<double> aW;
std::vector<unsigned int> aIndBoneParent;
std::vector<double> aJntRgrs;
dfm2::cnpy::LoadSmpl_Bone(
aXYZ0,
aW,
aTri,
aIndBoneParent,
aJntRgrs,
std::string(PATH_INPUT_DIR) + "/smpl_model_f.npz");
{
std::vector<double> aJntPos0;
dfm2::Points3_WeighttranspPosition(
aJntPos0,
aJntRgrs, aXYZ0);
dfm2::InitBones_JointPosition(
aBone,
aIndBoneParent.size(), aIndBoneParent.data(), aJntPos0.data());
}
dfm2::SparsifyMatrixRow(
aWeightRigSparse, aIdBoneRigSparse,
aW.data(), aXYZ0.size() / 3, aBone.size(),
1.0e-5);
viewer.SetRiggedMesh(aXYZ0, aTri, aWeightRigSparse, aIdBoneRigSparse, aBone);
}
// -----------
dfm2::opengl::CTexRGB_Rect2D tex;
int width, height;
{
int channels;
{
unsigned char *img = stbi_load((std::string(PATH_INPUT_DIR) + "/uglysweater.jpg").c_str(),
&width, &height, &channels, 0);
tex.Initialize(width, height, channels, img);
stbi_image_free(img);
}
double scale = 0.0020;
tex.max_x = -scale * width * 0.5;
tex.min_x = +scale * width * 0.5;
tex.max_y = -scale * height * 0.5;
tex.min_y = +scale * height * 0.5;
tex.z = -0.5;
std::cout << width << " " << height << std::endl;
}
// -------------------------
// below: opengl window open
delfem2::glfw::InitGLOld();
viewer.OpenWindow();
tex.InitGL();
dfm2::opengl::setSomeLighting();
while (!glfwWindowShouldClose(viewer.window)) {
viewer.DrawBegin_oldGL();
tex.Draw_oldGL();
viewer.Draw();
glfwSwapBuffers(viewer.window);
glfwPollEvents();
}
glfwDestroyWindow(viewer.window);
glfwTerminate();
exit(EXIT_SUCCESS);
}