StelOBJ.cpp   StelOBJ.cpp 
skipping to change at line 431 skipping to change at line 431
QFile file(filename); QFile file(filename);
if(!file.open(QIODevice::ReadOnly)) if(!file.open(QIODevice::ReadOnly))
{ {
qCWarning(stelOBJ)<<"Could not open MTL file"<<filename<<fil e.errorString(); qCWarning(stelOBJ)<<"Could not open MTL file"<<filename<<fil e.errorString();
return list; return list;
} }
QTextStream stream(&file); QTextStream stream(&file);
Material* curMaterial = Q_NULLPTR; Material* curMaterial = Q_NULLPTR;
int lineNr = 0; int lineNr = 0;
// some exporters give d and Tr, and some give contradicting interpr
etations. Track a warning with these.
bool dHasBeenGiven = false;
bool trHasBeenGiven = false;
while(!stream.atEnd()) while(!stream.atEnd())
{ {
++lineNr; ++lineNr;
bool ok = true; bool ok = true;
//make sure only spaces are the separator //make sure only spaces are the separator
QString line = stream.readLine().simplified(); QString line = stream.readLine().simplified();
//split line by space //split line by space
QVector<QStringRef> splits = line.splitRef(' ',QString::Skip EmptyParts); QVector<QStringRef> splits = line.splitRef(' ',QString::Skip EmptyParts);
if(!splits.isEmpty()) if(!splits.isEmpty())
skipping to change at line 458 skipping to change at line 461
if(CMD_CMP("newmtl")) //define new material if(CMD_CMP("newmtl")) //define new material
{ {
//use rest of line to support spaces in file name //use rest of line to support spaces in file name
QString name = getRestOfString(QStringLitera l("newmtl"),line); QString name = getRestOfString(QStringLitera l("newmtl"),line);
ok = !name.isEmpty(); ok = !name.isEmpty();
if(ok) if(ok)
{ {
//add a new material with the specif ied name //add a new material with the specif ied name
curMaterial = &INC_LIST(list); curMaterial = &INC_LIST(list);
curMaterial->name = name; curMaterial->name = name;
dHasBeenGiven = false;
trHasBeenGiven = false;
} }
else else
{ {
qCCritical(stelOBJ)<<"Invalid newmtl statement"<<line; qCCritical(stelOBJ)<<"Invalid newmtl statement"<<line;
} }
} }
else if(CMD_CMP("Ka")) //define ambient color else if(CMD_CMP("Ka")) //define ambient color
{ {
CHECK_MTL(); CHECK_MTL();
if(ok) if(ok)
skipping to change at line 501 skipping to change at line 506
if(ok) if(ok)
ok = StelOBJ::parseFloat(splits,curM aterial->Ns); ok = StelOBJ::parseFloat(splits,curM aterial->Ns);
} }
else if(CMD_CMP("d")) else if(CMD_CMP("d"))
{ {
CHECK_MTL(); CHECK_MTL();
if(ok) if(ok)
{ {
ok = StelOBJ::parseFloat(splits,curM aterial->d); ok = StelOBJ::parseFloat(splits,curM aterial->d);
//clamp d to [0,1] //clamp d to [0,1]
curMaterial->d = std::max(0.0f, std: curMaterial->d = qBound(0.0f, curMat
:min(curMaterial->d,1.0f)); erial->d, 1.0f);
if (trHasBeenGiven)
{
qWarning(stelOBJ) << "Materi
al" << curMaterial->name << "warning: Tr and d both given. The latter wins,
d=" << curMaterial->d;
}
dHasBeenGiven=true;
} }
} }
else if(CMD_CMP("Tr")) else if(CMD_CMP("Tr"))
{ {
CHECK_MTL(); CHECK_MTL();
if(ok) if(ok)
{ {
//Tr should be the inverse of d, in theory //Tr should be the inverse of d, in theory
//not all exporters seem to follow t his rule... //not all exporters seem to follow t his rule...
ok = StelOBJ::parseFloat(splits,curM aterial->d); ok = StelOBJ::parseFloat(splits,curM aterial->d);
//clamp d to [0,1] //clamp d to [0,1]
curMaterial->d = 1.0f - std::max(0.0 curMaterial->d = 1.0f - qBound(0.0f,
f, std::min(curMaterial->d,1.0f)); curMaterial->d, 1.0f);
if (dHasBeenGiven)
{
qWarning(stelOBJ) << "Materi
al" << curMaterial->name << "warning: d and Tr both given. The latter wins,
Tr=" << 1.0f-curMaterial->d;
}
trHasBeenGiven=true;
} }
} }
else if(CMD_CMP("map_Ka")) //define ambient map else if(CMD_CMP("map_Ka")) //define ambient map
{ {
CHECK_MTL(); CHECK_MTL();
if(ok) if(ok)
{ {
//use rest of line to support spaces in file name //use rest of line to support spaces in file name
curMaterial->map_Ka = getRestOfStrin g(QStringLiteral("map_Ka"),line); curMaterial->map_Ka = getRestOfStrin g(QStringLiteral("map_Ka"),line);
ok = !curMaterial->map_Ka.isEmpty(); ok = !curMaterial->map_Ka.isEmpty();
skipping to change at line 700 skipping to change at line 715
{ {
clear(); clear();
QDir baseDir(basePath); QDir baseDir(basePath);
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
QTextStream stream(&device); QTextStream stream(&device);
bool smoothGroupWarned = false; bool smoothGroupWarned = false;
bool vertexWWarned = false;
bool textureWWarned = false;
//contains the parsed vertex positions //contains the parsed vertex positions
V3Vec posList; V3Vec posList;
//contains the parsed normals //contains the parsed normals
V3Vec normalList; V3Vec normalList;
//contains the parsed texture coords //contains the parsed texture coords
V2Vec texList; V2Vec texList;
VertexCache vertCache; VertexCache vertCache;
CurrentParserState state = CurrentParserState(); CurrentParserState state = CurrentParserState();
skipping to change at line 744 skipping to change at line 761
else if(CMD_CMP("v")) else if(CMD_CMP("v"))
{ {
//we have to handle the vertex order //we have to handle the vertex order
Vec3f& target = INC_LIST(posList); Vec3f& target = INC_LIST(posList);
ok = parseVec3(splits,target); ok = parseVec3(splits,target);
//check the optional w coord if we have a ve c4, must be 1 //check the optional w coord if we have a ve c4, must be 1
if(splits.size()>4) if(splits.size()>4)
{ {
float w; float w;
parseFloat(splits,w,4); parseFloat(splits,w,4);
if(!qFuzzyCompare(w,1.0f)) if((!qFuzzyCompare(w,1.0f)) && (!ver
qWarning(stelOBJ)<<"Vertex w texWWarned))
coordinates different from 1.0 are not supported, changed to 1.0, on line" {
<<lineNr; qWarning(stelOBJ)<<"Vertex w
coordinates different from 1.0 are not supported, changed to 1.0, starting
on line"<<lineNr;
vertexWWarned=true;
}
} }
switch(vertexOrder) switch(vertexOrder)
{ {
case XYZ: case XYZ:
//no change //no change
break; break;
case XZY: case XZY:
target.set(target[0],-target [2],target[1]); target.set(target[0],-target [2],target[1]);
break; break;
case YXZ: case YXZ:
skipping to change at line 781 skipping to change at line 801
} }
} }
else if(CMD_CMP("vt")) else if(CMD_CMP("vt"))
{ {
ok = parseVec2(splits,INC_LIST(texList)); ok = parseVec2(splits,INC_LIST(texList));
//check the optional w coord if we have a ve c3, must be 0 //check the optional w coord if we have a ve c3, must be 0
if(splits.size()>3) if(splits.size()>3)
{ {
float w; float w;
parseFloat(splits,w,3); parseFloat(splits,w,3);
if(!qFuzzyIsNull(w)) if( (!qFuzzyIsNull(w)) && (!textureW
qWarning(stelOBJ)<<"Texture Warned))
w coordinates are not supported, on line"<<lineNr; {
qWarning(stelOBJ)<<"Texture
w coordinates are not supported, starting on line"<<lineNr;
textureWWarned=true;
}
} }
} }
else if(CMD_CMP("vn")) else if(CMD_CMP("vn"))
{ {
//we have to handle the vertex order //we have to handle the vertex order
Vec3f& target = INC_LIST(normalList); Vec3f& target = INC_LIST(normalList);
ok = parseVec3(splits,target); ok = parseVec3(splits,target);
switch(vertexOrder) switch(vertexOrder)
{ {
case XYZ: case XYZ:
 End of changes. 7 change blocks. 
11 lines changed or deleted 41 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/