diff --git a/IO/Import/vtkOBJImporter.cxx b/IO/Import/vtkOBJImporter.cxx index 5f76c1955d3203b237f094186aa661a9e7215043..475641426197167337eb70980641fabc8a907f36 100644 --- a/IO/Import/vtkOBJImporter.cxx +++ b/IO/Import/vtkOBJImporter.cxx @@ -211,7 +211,8 @@ vtkOBJPolyDataProcessor::vtkOBJPolyDataProcessor() this->FileName = ""; this->MTLFileName = ""; this->DefaultMTLFileName = true; - this->TexturePath = "./"; + this->TexturePath = ""; + this->DefaultTexturePath = true; this->VertexScale = 1.0; this->SuccessParsingFiles = 1; this->SetNumberOfInputPorts(0); @@ -483,6 +484,11 @@ int vtkOBJPolyDataProcessor::RequestData(vtkInformation* vtkNotUsed(request), } } + if (this->DefaultTexturePath) + { + this->SetTexturePath(vtksys::SystemTools::GetFilenamePath(this->FileName).c_str()); + } + int mtlParseResult; this->parsedMTLs = ParseOBJandMTL(this->MTLFileName, mtlParseResult); if (this->parsedMTLs.empty()) diff --git a/IO/Import/vtkOBJImporterInternals.h b/IO/Import/vtkOBJImporterInternals.h index 1f43bfb772703bceb352041c0cf92fca59b8e984..46aa2efe2b562d839e485705a62c81023983a717 100644 --- a/IO/Import/vtkOBJImporterInternals.h +++ b/IO/Import/vtkOBJImporterInternals.h @@ -57,7 +57,7 @@ public: { return; } - FileName = std::string(arg); + this->FileName = std::string(arg); } void SetMTLfileName(const char* arg) { @@ -69,27 +69,32 @@ public: { return; } - MTLFileName = std::string(arg); + this->MTLFileName = std::string(arg); this->DefaultMTLFileName = false; } void SetTexturePath(const char* arg) { - TexturePath = std::string(arg); - if (TexturePath.empty()) + this->TexturePath = std::string(arg); + if (this->TexturePath.empty()) + { return; + } #if defined(_WIN32) const char sep = '\\'; #else const char sep = '/'; #endif - if (TexturePath.at(TexturePath.size() - 1) != sep) - TexturePath += sep; + if (this->TexturePath.at(this->TexturePath.size() - 1) != sep) + { + this->TexturePath += sep; + } + this->DefaultTexturePath = false; } - const std::string& GetTexturePath() const { return TexturePath; } + const std::string& GetTexturePath() const { return this->TexturePath; } - const std::string& GetFileName() const { return FileName; } + const std::string& GetFileName() const { return this->FileName; } - const std::string& GetMTLFileName() const { return MTLFileName; } + const std::string& GetMTLFileName() const { return this->MTLFileName; } vtkSetMacro(VertexScale, double); vtkGetMacro(VertexScale, double); @@ -132,8 +137,9 @@ protected: std::string FileName; // filename (.obj) being read std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl - bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used + bool DefaultMTLFileName; // tells whether default MTL should be used std::string TexturePath; + bool DefaultTexturePath; // tells whether default texture path should be used int SuccessParsingFiles; private: