Skip to content

Commit

Permalink
fix macos?
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilliams committed Sep 14, 2023
1 parent b2b8a59 commit e413c6e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/common/obj_loader.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#include <npe.h>

#include <string>
#include <filesystem>
#include <unordered_map>

#ifdef __APPLE__
#include <cstdlib>
#include <libgen.h>
#else
#include <filesystem>
#endif

#define TINYOBJLOADER_IMPLEMENTATION
#include <tiny_obj_loader.h>

Expand All @@ -12,8 +18,17 @@

std::unordered_map<std::string, pybind11::object> load_mesh_obj(const std::string& filename) {

std::filesystem::path abspath = std::filesystem::absolute(filename);
std::string dir = abspath.parent_path().string();
#ifdef __APPLE__
if (filename.size() >= PATH_MAX) {
throw pybind11::value_error("Filename is too long");
}
char resolved_path[PATH_MAX];
realpath(filename.c_str(), resolved_path);
std::string dir = std::string(dirname(resolved_path));
#else
std::filesystem::path abspath = std::filesystem::absolute(filename);
std::string dir = abspath.parent_path().string();
#endif

tinyobj::ObjReaderConfig reader_config;
reader_config.mtl_search_path = dir; // Path to material files
Expand Down

0 comments on commit e413c6e

Please sign in to comment.