collada + obj importer robustness improvements

metadata
Wenzel Jakob 2012-10-08 21:40:37 -04:00
parent 80a41265c5
commit 527b661280
4 changed files with 40 additions and 14 deletions

View File

@ -1056,6 +1056,11 @@ void loadImage(ColladaContext &ctx, domImage &image) {
SLog(EDebug, "Converting texture \"%s\" ..", identifier.c_str());
std::string filename = cdom::uriToFilePath(image.getInit_from()->getValue().str());
/* Prevent Linux/OSX fs::path handling issues for DAE files created on Windows */
for (size_t i=0; i<filename.length(); ++i) {
if (filename[i] == '\\')
filename[i] = '/';
}
if (ctx.fileToId.find(filename) != ctx.fileToId.end()) {
ctx.idToTexture[identifier] = ctx.fileToId[filename];
return;
@ -1174,10 +1179,10 @@ void loadCamera(ColladaContext &ctx, Transform transform, domCamera &camera) {
ctx.os << "\t\t<transform name=\"toWorld\">" << endl;
ctx.os << "\t\t\t<matrix value=\"" << matrixValues.substr(0, matrixValues.length()-1) << "\"/>" << endl;
ctx.os << "\t\t</transform>" << endl << endl;
ctx.os << "\t\t<sampler id=\"sampler\" type=\"ldsampler\">" << endl;
ctx.os << "\t\t<sampler id=\"" << identifier << "_sampler\" type=\"ldsampler\">" << endl;
ctx.os << "\t\t\t<integer name=\"sampleCount\" value=\"4\"/>" << endl;
ctx.os << "\t\t</sampler>" << endl << endl;
ctx.os << "\t\t<film id=\"film\" type=\"" << ctx.cvt->m_filmType << "\">" << endl;
ctx.os << "\t\t<film id=\"" << identifier << "_film\" type=\"" << ctx.cvt->m_filmType << "\">" << endl;
ctx.os << "\t\t\t<integer name=\"width\" value=\"" << xres << "\"/>" << endl;
ctx.os << "\t\t\t<integer name=\"height\" value=\"" << (int) (xres/aspect) << "\"/>" << endl;
ctx.os << "\t\t\t<rfilter type=\"gaussian\"/>" << endl;

View File

@ -30,6 +30,12 @@ std::set<std::string> availableTextures;
void referenceTexture(GeometryConverter *cvt, std::ostream &os, const std::string &parameter,
const std::string &indent, const fs::path &textureDir, std::string filename) {
/* Prevent Linux/OSX fs::path handling issues for OBJ files created on Windows */
for (size_t i=0; i<filename.length(); ++i) {
if (filename[i] == '\\')
filename[i] = '/';
}
fs::path path = fs::path(filename);
fs::path targetPath = textureDir / path.filename();
std::string textureName = targetPath.filename().string();
@ -75,7 +81,7 @@ void addMaterial(GeometryConverter *cvt, std::ostream &os, const std::string &mt
const std::string &diffuseMap, const std::string maskMap) {
if (mtlName == "")
return;
SLog(EInfo, "Copying material \"%s\" ..", mtlName.c_str());
SLog(EInfo, "Importing material \"%s\" ..", mtlName.c_str());
std::string indent = "";
if (maskMap != "") {

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>353</width>
<height>273</height>
<width>358</width>
<height>282</height>
</rect>
</property>
<property name="windowTitle">
@ -234,9 +234,9 @@
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="linearButton">
<widget class="QRadioButton" name="sRGBButton">
<property name="text">
<string>Linear</string>
<string>sRGB</string>
</property>
<property name="checked">
<bool>true</bool>
@ -244,9 +244,12 @@
</widget>
</item>
<item>
<widget class="QRadioButton" name="sRGBButton">
<widget class="QRadioButton" name="linearButton">
<property name="text">
<string>sRGB</string>
<string>Linear</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>

View File

@ -377,13 +377,25 @@ public:
Texture *loadTexture(const FileResolver *fileResolver,
std::map<std::string, Texture *> &cache,
const fs::path &mtlPath, const std::string &filename) {
const fs::path &mtlPath, std::string filename) {
/* Prevent Linux/OSX fs::path handling issues for DAE files created on Windows */
for (size_t i=0; i<filename.length(); ++i) {
if (filename[i] == '\\')
filename[i] = '/';
}
if (cache.find(filename) != cache.end())
return cache[filename];
fs::path path = fileResolver->resolve(filename);
if (!fs::exists(path))
Log(EError, "Unable to find texture \"%s\" referenced from \"%s\"!",
if (!fs::exists(path)) {
path = fileResolver->resolve(fs::path(filename).filename());
if (!fs::exists(path)) {
Log(EWarn, "Unable to find texture \"%s\" referenced from \"%s\"!",
path.string().c_str(), mtlPath.string().c_str());
return new ConstantSpectrumTexture(Spectrum(0.0f));
}
}
Properties props("bitmap");
props.setString("filename", path.string());
ref<Texture> texture = static_cast<Texture *> (PluginManager::getInstance()->
@ -424,7 +436,7 @@ public:
if (mtlName != "")
addMaterial(mtlName, diffuse, specular, exponent, bump, mask, illum);
mtlName = trim(line.substr(7, line.length()-7));
mtlName = trim(line.substr(6, line.length()-6));
specular = new ConstantSpectrumTexture(Spectrum(0.0f));
diffuse = new ConstantSpectrumTexture(Spectrum(0.0f));