a few bugfixes for the OBJ loader (regarding unsuccessful material imports and incorrect object names)
parent
55ba3887bd
commit
5dcf9d8380
|
@ -28,7 +28,10 @@ Medium::Medium(const Properties &props)
|
||||||
defaultSigmaA.fromLinearRGB(0.0014f, 0.0025f, 0.0142f);
|
defaultSigmaA.fromLinearRGB(0.0014f, 0.0025f, 0.0142f);
|
||||||
defaultSigmaS.fromLinearRGB(0.7f, 1.22f, 1.9f);
|
defaultSigmaS.fromLinearRGB(0.7f, 1.22f, 1.9f);
|
||||||
|
|
||||||
m_sizeMultiplier = props.getFloat("sizeMultiplier", 1);
|
if (props.hasProperty("densityMultiplier"))
|
||||||
|
m_sizeMultiplier = props.getFloat("densityMultiplier");
|
||||||
|
else
|
||||||
|
m_sizeMultiplier = props.getFloat("sizeMultiplier", 1);
|
||||||
m_sigmaA = props.getSpectrum("sigmaA", defaultSigmaA);
|
m_sigmaA = props.getSpectrum("sigmaA", defaultSigmaA);
|
||||||
m_sigmaS = props.getSpectrum("sigmaS", defaultSigmaS);
|
m_sigmaS = props.getSpectrum("sigmaS", defaultSigmaS);
|
||||||
m_sigmaA *= m_sizeMultiplier;
|
m_sigmaA *= m_sizeMultiplier;
|
||||||
|
|
|
@ -102,6 +102,7 @@ public:
|
||||||
std::string name = m_name, line;
|
std::string name = m_name, line;
|
||||||
std::set<std::string> geomNames;
|
std::set<std::string> geomNames;
|
||||||
int geomIdx = 0;
|
int geomIdx = 0;
|
||||||
|
bool nameBeforeGeometry = false;
|
||||||
|
|
||||||
while (is.good() && !is.eof() && fetch_line(is, line)) {
|
while (is.good() && !is.eof() && fetch_line(is, line)) {
|
||||||
std::istringstream iss(line);
|
std::istringstream iss(line);
|
||||||
|
@ -113,42 +114,53 @@ public:
|
||||||
Point p;
|
Point p;
|
||||||
iss >> p.x >> p.y >> p.z;
|
iss >> p.x >> p.y >> p.z;
|
||||||
vertices.push_back(p);
|
vertices.push_back(p);
|
||||||
if (firstVertex) {
|
|
||||||
if (triangles.size() > 0) {
|
|
||||||
if (geomNames.find(name) != geomNames.end())
|
|
||||||
/// make sure that we have unique names
|
|
||||||
name = formatString("%s_%i", m_name.c_str(), geomIdx);
|
|
||||||
generateGeometry(name, vertices, normals, texcoords,
|
|
||||||
triangles, hasNormals, hasTexcoords, currentMaterial,
|
|
||||||
objectToWorld);
|
|
||||||
triangles.clear();
|
|
||||||
geomNames.insert(name);
|
|
||||||
geomIdx++;
|
|
||||||
}
|
|
||||||
hasNormals = false;
|
|
||||||
hasTexcoords = false;
|
|
||||||
firstVertex = false;
|
|
||||||
}
|
|
||||||
} else if (buf == "vn") {
|
} else if (buf == "vn") {
|
||||||
Normal n;
|
Normal n;
|
||||||
iss >> n.x >> n.y >> n.z;
|
iss >> n.x >> n.y >> n.z;
|
||||||
normals.push_back(n);
|
normals.push_back(n);
|
||||||
hasNormals = true;
|
hasNormals = true;
|
||||||
} else if (buf == "g") {
|
} else if (buf == "g") {
|
||||||
if (line.length() > 2) {
|
std::string targetName;
|
||||||
name = trim(line.substr(1, line.length()-1));
|
std::string newName = trim(line.substr(1, line.length()-1));
|
||||||
Log(EInfo, "Loading geometry \"%s\"", name.c_str());
|
|
||||||
}
|
/* There appear to be two different conventions
|
||||||
} else if (buf == "usemtl") {
|
for specifying object names in OBJ file -- try
|
||||||
std::string materialName = trim(line.substr(1, line.length()-1));
|
to detect which one is being used */
|
||||||
if (m_materials.find(materialName) != m_materials.end())
|
if (nameBeforeGeometry)
|
||||||
currentMaterial = m_materials[materialName];
|
// Save geometry under the previously specified name
|
||||||
|
targetName = name;
|
||||||
else
|
else
|
||||||
|
targetName = newName;
|
||||||
|
|
||||||
|
if (triangles.size() > 0) {
|
||||||
|
/// make sure that we have unique names
|
||||||
|
if (geomNames.find(targetName) != geomNames.end())
|
||||||
|
name = formatString("%s_%i", targetName.c_str(), geomIdx);
|
||||||
|
generateGeometry(targetName, vertices, normals, texcoords,
|
||||||
|
triangles, hasNormals, hasTexcoords, currentMaterial,
|
||||||
|
objectToWorld);
|
||||||
|
triangles.clear();
|
||||||
|
geomNames.insert(name);
|
||||||
|
geomIdx++;
|
||||||
|
hasNormals = false;
|
||||||
|
hasTexcoords = false;
|
||||||
|
firstVertex = false;
|
||||||
|
} else {
|
||||||
|
nameBeforeGeometry = true;
|
||||||
|
}
|
||||||
|
name = newName;
|
||||||
|
} else if (buf == "usemtl") {
|
||||||
|
std::string materialName = trim(line.substr(6, line.length()-1));
|
||||||
|
if (m_materials.find(materialName) != m_materials.end()) {
|
||||||
|
currentMaterial = m_materials[materialName];
|
||||||
|
} else {
|
||||||
|
Log(EWarn, "Unable to find material %s", materialName.c_str());
|
||||||
currentMaterial = NULL;
|
currentMaterial = NULL;
|
||||||
|
}
|
||||||
} else if (buf == "mtllib") {
|
} else if (buf == "mtllib") {
|
||||||
ref<FileResolver> frClone = fResolver->clone();
|
ref<FileResolver> frClone = fResolver->clone();
|
||||||
frClone->addPath(fs::complete(path).parent_path());
|
frClone->addPath(fs::complete(path).parent_path());
|
||||||
fs::path mtlName = frClone->resolve(trim(line.substr(1, line.length()-1)));
|
fs::path mtlName = frClone->resolve(trim(line.substr(6, line.length()-1)));
|
||||||
if (fs::exists(mtlName))
|
if (fs::exists(mtlName))
|
||||||
parseMaterials(mtlName);
|
parseMaterials(mtlName);
|
||||||
else
|
else
|
||||||
|
@ -181,6 +193,9 @@ public:
|
||||||
/* Ignore */
|
/* Ignore */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (geomNames.find(name) != geomNames.end())
|
||||||
|
/// make sure that we have unique names
|
||||||
|
name = formatString("%s_%i", m_name.c_str(), geomIdx);
|
||||||
|
|
||||||
generateGeometry(name, vertices, normals, texcoords,
|
generateGeometry(name, vertices, normals, texcoords,
|
||||||
triangles, hasNormals, hasTexcoords, currentMaterial,
|
triangles, hasNormals, hasTexcoords, currentMaterial,
|
||||||
|
@ -312,6 +327,7 @@ public:
|
||||||
const Transform &objectToWorld) {
|
const Transform &objectToWorld) {
|
||||||
if (triangles.size() == 0)
|
if (triangles.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
Log(EInfo, "Loading geometry \"%s\"", name.c_str());
|
||||||
|
|
||||||
std::map<Vertex, int, vertex_key_order> vertexMap;
|
std::map<Vertex, int, vertex_key_order> vertexMap;
|
||||||
std::vector<Vertex> vertexBuffer;
|
std::vector<Vertex> vertexBuffer;
|
||||||
|
|
Loading…
Reference in New Issue