Skip to content

Commit

Permalink
fixing issue with getting correct path for mtl file
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://edison.nersc.gov/project/projectdirs/visit/svn/visit/branches/2.13RC@33720 18c085ea-50e0-402c-830e-de6fd14e8384
  • Loading branch information
markcmiller86 authored and cyrush committed Jan 12, 2019
1 parent e128d97 commit 1bffef9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/databases/WavefrontOBJ/vtkVisItOBJReader.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
=========================================================================*/
#include "vtkVisItOBJReader.h"

#include <InvalidFilesException.h>
#include <FileFunctions.h>
#include <snprintf.h>

#include "vtkCellArray.h"
#include "vtkCellData.h"
Expand All @@ -26,6 +29,8 @@
#include "vtkPolyData.h"
#include "vtkStringArray.h"

#include <cstring>

vtkStandardNewMacro(vtkVisItOBJReader);

// Description:
Expand Down Expand Up @@ -112,14 +117,27 @@ int is_whitespace(char c)
// Parse an OBJ material file for material "names" and
// coloration. Only the ambient color (Ka) is examined.
static int
ParseMTLFile(char const *filename,
ParseMTLFile(char const *objFileName, char const *mtlFileName,
vtkStringArray *colorNames, vtkFloatArray *rgbValues)
{
FILE *in = fopen(filename,"r");
const int MAX_LINE=8192;
char line[MAX_LINE],*pChar;
float rgb[3];
int everything_ok = 1;
FILE *in;

if (mtlFileName[0] == '/') // abs path case
{
in = fopen(mtlFileName,"r");
}
else
{
char tmpFileName[2048];
SNPRINTF(tmpFileName, sizeof(tmpFileName), "%s/%s",
FileFunctions::Dirname(objFileName), mtlFileName);
in = fopen(FileFunctions::Normalize(tmpFileName),"r");
}
if (!in) return 0;
while (everything_ok && fgets(line,MAX_LINE,in)!=NULL)
{
if (strncmp(line,"newmtl ",7)==0)
Expand Down Expand Up @@ -359,7 +377,7 @@ int vtkVisItOBJReader::RequestData(
vtkStringArray *colorNames = vtkStringArray::New();
int len = (int) strlen(line);
line[len-1] = '\0'; // chop off newline char
if (ParseMTLFile(&line[7], colorNames, rgbValues))
if (ParseMTLFile(this->FileName, &line[7], colorNames, rgbValues))
{
colorNames->SetName("_vtkVisItOBJReader_ColorNames");
rgbValues->SetName("_vtkVisItOBJReader_RGBValues");
Expand Down

0 comments on commit 1bffef9

Please sign in to comment.