@@ -1119,7 +1119,11 @@ std::vector<uint> Context::loadXML(const char *filename, bool quiet) {
11191119 helios_runtime_error (" failed.\n File " + fn + " is not XML format." );
11201120 }
11211121
1122- XMLfiles.emplace_back (filename);
1122+ // Resolve file path using unified resolution
1123+ std::filesystem::path resolved_path = resolveFilePath (filename);
1124+ std::string resolved_filename = resolved_path.string ();
1125+
1126+ XMLfiles.emplace_back (resolved_filename);
11231127
11241128 uint ID;
11251129 std::vector<uint> UUID;
@@ -1128,7 +1132,7 @@ std::vector<uint> Context::loadXML(const char *filename, bool quiet) {
11281132 pugi::xml_document xmldoc;
11291133
11301134 // load file
1131- pugi::xml_parse_result load_result = xmldoc.load_file (filename );
1135+ pugi::xml_parse_result load_result = xmldoc.load_file (resolved_filename. c_str () );
11321136
11331137 // error checking
11341138 if (!load_result) {
@@ -3222,8 +3226,12 @@ std::vector<uint> Context::loadPLY(const char *filename, const vec3 &origin, flo
32223226
32233227 bool ifColor = false ;
32243228
3229+ // Resolve file path using unified resolution
3230+ std::filesystem::path resolved_path = resolveFilePath (filename);
3231+ std::string resolved_filename = resolved_path.string ();
3232+
32253233 std::ifstream inputPly;
3226- inputPly.open (filename );
3234+ inputPly.open (resolved_filename );
32273235
32283236 if (!inputPly.is_open ()) {
32293237 helios_runtime_error (" ERROR (Context::loadPLY): Couldn't open " + std::string (filename));
@@ -3580,16 +3588,19 @@ std::vector<uint> Context::loadOBJ(const char *filename, const vec3 &origin, con
35803588
35813589 std::vector<uint> UUID;
35823590
3591+ // Resolve file path using unified resolution
3592+ std::filesystem::path resolved_path = resolveFilePath (filename);
3593+ std::string resolved_filename = resolved_path.string ();
3594+
35833595 std::ifstream inputOBJ, inputMTL;
3584- inputOBJ.open (filename );
3596+ inputOBJ.open (resolved_filename );
35853597
35863598 if (!inputOBJ.is_open ()) {
35873599 helios_runtime_error (" ERROR (Context::loadOBJ): Couldn't open " + std::string (filename));
35883600 }
35893601
3590- // determine the base file path for 'filename'
3591- std::string fstring = filename;
3592- std::string filebase = getFilePath (fstring);
3602+ // determine the base file path for resolved filename
3603+ std::string filebase = getFilePath (resolved_filename);
35933604
35943605 // determine bounding box
35953606 float boxmin = 100000 ;
@@ -3811,26 +3822,34 @@ std::map<std::string, Context::OBJmaterial> Context::loadMTL(const std::string &
38113822 std::ifstream inputMTL;
38123823
38133824 std::string file = material_file;
3814-
3815- // first look for mtl file using path given in obj file
3816- inputMTL.open (file.c_str ());
3817- if (!inputMTL.is_open ()) {
3818- // if that doesn't work, try looking in the same directory where obj file is located
3819- file = filebase + file;
3820- file.erase (remove (file.begin (), file.end (), ' ' ), file.end ());
3821- for (size_t i = file.size (); i-- > 0 ;) {
3822- if (strcmp (&file.at (i), " l" ) == 0 ) {
3823- break ;
3824- }
3825-
3826- file.erase (file.begin () + scast<int >(i));
3827- }
3828- if (file.empty ()) {
3829- helios_runtime_error (" ERROR (Context::loadMTL): Material file does not have correct file extension (.mtl)." );
3830- }
3825+ std::string resolved_file;
3826+
3827+ // Try unified resolution first
3828+ try {
3829+ std::filesystem::path resolved_path = resolveFilePath (file);
3830+ resolved_file = resolved_path.string ();
3831+ inputMTL.open (resolved_file.c_str ());
3832+ } catch (const std::runtime_error &) {
3833+ // If unified resolution fails, fall back to original logic
38313834 inputMTL.open (file.c_str ());
38323835 if (!inputMTL.is_open ()) {
3833- helios_runtime_error (" ERROR (Context::loadMTL): Material file " + std::string (file) + " given in .obj file cannot be found." );
3836+ // if that doesn't work, try looking in the same directory where obj file is located
3837+ file = filebase + file;
3838+ file.erase (remove (file.begin (), file.end (), ' ' ), file.end ());
3839+ for (size_t i = file.size (); i-- > 0 ;) {
3840+ if (strcmp (&file.at (i), " l" ) == 0 ) {
3841+ break ;
3842+ }
3843+
3844+ file.erase (file.begin () + scast<int >(i));
3845+ }
3846+ if (file.empty ()) {
3847+ helios_runtime_error (" ERROR (Context::loadMTL): Material file does not have correct file extension (.mtl)." );
3848+ }
3849+ inputMTL.open (file.c_str ());
3850+ if (!inputMTL.is_open ()) {
3851+ helios_runtime_error (" ERROR (Context::loadMTL): Material file " + std::string (file) + " given in .obj file cannot be found." );
3852+ }
38343853 }
38353854 }
38363855
@@ -4430,7 +4449,11 @@ void Context::writePrimitiveData(const std::string &filename, const std::vector<
44304449}
44314450
44324451void Context::loadTabularTimeseriesData (const std::string &data_file, const std::vector<std::string> &col_labels, const std::string &a_delimeter, const std::string &a_date_string_format, uint headerlines) {
4433- std::ifstream datafile (data_file); // open the file
4452+ // Resolve file path using project-based resolution
4453+ std::filesystem::path resolved_path = resolveProjectFile (data_file);
4454+ std::string resolved_filename = resolved_path.string ();
4455+
4456+ std::ifstream datafile (resolved_filename); // open the file
44344457
44354458 if (!datafile.is_open ()) { // check that file exists
44364459 helios_runtime_error (" ERROR (Context::loadTabularTimeseriesData): Weather data file '" + data_file + " ' does not exist." );
0 commit comments