|
|
@@ -35,7 +35,30 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
obj_file_name.c_str());
|
|
|
return false;
|
|
|
}
|
|
|
- return igl::readOBJ(obj_file,V,TC,N,F,FTC,FN);
|
|
|
+ std::vector<std::tuple<std::string, Index, Index >> FM;
|
|
|
+ return igl::readOBJ(obj_file,V,TC,N,F,FTC,FN, FM);
|
|
|
+}
|
|
|
+
|
|
|
+template <typename Scalar, typename Index>
|
|
|
+IGL_INLINE bool igl::readOBJ(
|
|
|
+ const std::string obj_file_name,
|
|
|
+ std::vector<std::vector<Scalar > > & V,
|
|
|
+ std::vector<std::vector<Scalar > > & TC,
|
|
|
+ std::vector<std::vector<Scalar > > & N,
|
|
|
+ std::vector<std::vector<Index > > & F,
|
|
|
+ std::vector<std::vector<Index > > & FTC,
|
|
|
+ std::vector<std::vector<Index > > & FN,
|
|
|
+ std::vector<std::tuple<std::string, Index, Index >> &FM)
|
|
|
+{
|
|
|
+ // Open file, and check for error
|
|
|
+ FILE * obj_file = fopen(obj_file_name.c_str(),"r");
|
|
|
+ if(NULL==obj_file)
|
|
|
+ {
|
|
|
+ fprintf(stderr,"IOError: %s could not be opened...\n",
|
|
|
+ obj_file_name.c_str());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return igl::readOBJ(obj_file,V,TC,N,F,FTC,FN,FM);
|
|
|
}
|
|
|
|
|
|
template <typename Scalar, typename Index>
|
|
|
@@ -46,7 +69,8 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
std::vector<std::vector<Scalar > > & N,
|
|
|
std::vector<std::vector<Index > > & F,
|
|
|
std::vector<std::vector<Index > > & FTC,
|
|
|
- std::vector<std::vector<Index > > & FN)
|
|
|
+ std::vector<std::vector<Index > > & FN,
|
|
|
+ std::vector<std::tuple<std::string, Index, Index >> &FM)
|
|
|
{
|
|
|
// File open was successful so clear outputs
|
|
|
V.clear();
|
|
|
@@ -65,10 +89,16 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
std::string tic_tac_toe("#");
|
|
|
#ifndef IGL_LINE_MAX
|
|
|
# define IGL_LINE_MAX 2048
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifndef MATERIAL_LINE_MAX
|
|
|
+# define MATERIAL_LINE_MAX 2048
|
|
|
#endif
|
|
|
|
|
|
char line[IGL_LINE_MAX];
|
|
|
- int line_no = 1;
|
|
|
+ char currentmaterialref[MATERIAL_LINE_MAX] = "";
|
|
|
+ bool FMwasinit = false;
|
|
|
+ int line_no = 1, previous_face_no=0, current_face_no = 0;
|
|
|
while (fgets(line, IGL_LINE_MAX, obj_file) != NULL)
|
|
|
{
|
|
|
char type[IGL_LINE_MAX];
|
|
|
@@ -193,6 +223,7 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
F.push_back(f);
|
|
|
FTC.push_back(ftc);
|
|
|
FN.push_back(fn);
|
|
|
+ current_face_no++;
|
|
|
}else
|
|
|
{
|
|
|
fprintf(stderr,
|
|
|
@@ -200,10 +231,20 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
fclose(obj_file);
|
|
|
return false;
|
|
|
}
|
|
|
- }else if(strlen(type) >= 1 && (type[0] == '#' ||
|
|
|
+ }else if(strlen(type) >= 1 && strcmp("usemtl",type)==0 )
|
|
|
+ {
|
|
|
+ if(FMwasinit){
|
|
|
+ FM.push_back(std::make_tuple(currentmaterialref,previous_face_no,current_face_no-1));
|
|
|
+ previous_face_no = current_face_no;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ FMwasinit=true;
|
|
|
+ }
|
|
|
+ sscanf(l, "%s\n", ¤tmaterialref);
|
|
|
+ }
|
|
|
+ else if(strlen(type) >= 1 && (type[0] == '#' ||
|
|
|
type[0] == 'g' ||
|
|
|
type[0] == 's' ||
|
|
|
- strcmp("usemtl",type)==0 ||
|
|
|
strcmp("mtllib",type)==0))
|
|
|
{
|
|
|
//ignore comments or other shit
|
|
|
@@ -221,6 +262,8 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
}
|
|
|
line_no++;
|
|
|
}
|
|
|
+ if(strcmp(currentmaterialref,"")!=0)
|
|
|
+ FM.push_back(std::make_tuple(currentmaterialref,previous_face_no,current_face_no-1));
|
|
|
fclose(obj_file);
|
|
|
|
|
|
assert(F.size() == FN.size());
|
|
|
@@ -237,6 +280,8 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
{
|
|
|
std::vector<std::vector<Scalar > > TC,N;
|
|
|
std::vector<std::vector<Index > > FTC,FN;
|
|
|
+ std::vector<std::tuple<std::string, Index, Index >> FM;
|
|
|
+
|
|
|
return readOBJ(obj_file_name,V,TC,N,F,FTC,FN);
|
|
|
}
|
|
|
|
|
|
@@ -351,6 +396,7 @@ IGL_INLINE bool igl::readOBJ(
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
// Explicit template instantiation
|
|
|
// generated by autoexplicit.sh
|
|
|
@@ -359,5 +405,5 @@ template bool igl::readOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matr
|
|
|
template bool igl::readOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
|
|
template bool igl::readOBJ<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
|
|
template bool igl::readOBJ<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
|
|
|
-template bool igl::readOBJ<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
|
|
|
+template bool igl::readOBJ<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, std::vector<std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int>, std::allocator<std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int> > >&);
|
|
|
#endif
|