This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/obj.cpp
github-classroom[bot] 5985bb8445
Initial commit
2024-10-24 10:26:51 +00:00

75 lines
2 KiB
C++

#include "cube.h"
#include "sphere.h"
#include "write_obj.h"
#include "QuadViewer.h"
#include "set_texture_from_png.h"
#include <igl/readOBJ.h>
#include <Eigen/Core>
#include <vector>
#include <iostream>
#include <memory>
#include <limits>
#include <functional>
int main(int argc, char * argv[])
{
// parse command line arguments
std::string path_to_cube_png;
std::string path_to_earth_png;
if (argc == 3) {
std::string args0 = argv[1];
std::string args1 = argv[2];
// check if ends with .png
if (args0.size() > 4 && args0.substr(args0.size() - 3, 3) == "png") {
path_to_cube_png = args0;
}
if (args1.size() > 4 && args1.substr(args1.size() - 3, 3) == "png") {
path_to_earth_png = args1;
}
}
if (argc != 3 || path_to_cube_png.empty() || path_to_earth_png.empty()) {
printf(
"Error: received unexpected command line arguments. \n"
"Correct usage: \n"
" Linux: ./obj <path to rubiks-cube.png> <path to earth-square.png>\n"
" Windows: obj.exe <path to rubiks-cube.png> <path to earth-square.png> \n"
"For example: \n"
" Linux: ./obj ../data/rubiks-cube.png ../data/earth-square.png \n"
" Windows: obj.exe ../../../data/rubiks-cube.png ../../../data/earth-square.png \n"
);
return -1;
}
{
// Create mesh of a cube
Eigen::MatrixXd V,UV,NV;
Eigen::MatrixXi F,UF,NF;
cube(V,F,UV,UF,NV,NF);
write_obj("cube.obj",V,F,UV,UF,NV,NF);
printf("wrote to cube.obj \n");
igl::readOBJ("cube.obj",V,UV,NV,F,UF,NF);
{
QuadViewer v;
v.set_mesh(V,F,UV,UF,NV,NF);
set_texture_from_png(path_to_cube_png, v.viewer.data());
v.launch();
}
}
{
// Create mesh of a sphere
Eigen::MatrixXd V,UV,NV;
Eigen::MatrixXi F,UF,NF;
sphere(60,40,V,F,UV,UF,NV,NF);
write_obj("sphere.obj",V,F,UV,UF,NV,NF);
printf("wrote to sphere.obj \n");
igl::readOBJ("sphere.obj",V,UV,NV,F,UF,NF);
{
QuadViewer v;
v.set_mesh(V,F,UV,UF,NV,NF);
set_texture_from_png(path_to_earth_png, v.viewer.data());
v.launch();
}
}
}