Handle broken blender 2.5 DAE files

metadata
Wenzel Jakob 2010-08-16 11:09:02 +02:00
parent c26b116f11
commit 59cf5a8a3e
3 changed files with 62 additions and 13 deletions

View File

@ -645,6 +645,15 @@ void loadLight(Transform transform, std::ostream &os, domLight &light) {
domLight::domTechnique_common::domPoint *point = light.getTechnique_common()->getPoint().cast(); domLight::domTechnique_common::domPoint *point = light.getTechnique_common()->getPoint().cast();
if (point) { if (point) {
bool notQuadratic = false;
if (point->getConstant_attenuation() && point->getConstant_attenuation()->getValue() != 1)
notQuadratic = true;
if (point->getLinear_attenuation() && point->getLinear_attenuation()->getValue() != 0)
notQuadratic = true;
if (point->getQuadratic_attenuation() && point->getQuadratic_attenuation()->getValue() != 1)
notQuadratic = true;
if (notQuadratic)
SLog(EWarn, "Point light \"%s\" is not a quadratic light! Treating it as one -- expect problems.", light.getId());
domFloat3 &color = point->getColor()->getValue(); domFloat3 &color = point->getColor()->getValue();
os << "\t<luminaire id=\"" << light.getId() << "\" type=\"point\">" << endl; os << "\t<luminaire id=\"" << light.getId() << "\" type=\"point\">" << endl;
os << "\t\t<rgb name=\"intensity\" value=\"" << color[0]*intensity << " " << color[1]*intensity << " " << color[2]*intensity << "\"/>" << endl << endl; os << "\t\t<rgb name=\"intensity\" value=\"" << color[0]*intensity << " " << color[1]*intensity << " " << color[2]*intensity << "\"/>" << endl << endl;
@ -667,6 +676,15 @@ void loadLight(Transform transform, std::ostream &os, domLight &light) {
domLight::domTechnique_common::domSpot *spot = light.getTechnique_common()->getSpot().cast(); domLight::domTechnique_common::domSpot *spot = light.getTechnique_common()->getSpot().cast();
if (spot) { if (spot) {
bool notQuadratic = false;
if (spot->getConstant_attenuation() && spot->getConstant_attenuation()->getValue() != 1)
notQuadratic = true;
if (spot->getLinear_attenuation() && spot->getLinear_attenuation()->getValue() != 0)
notQuadratic = true;
if (spot->getQuadratic_attenuation() && spot->getQuadratic_attenuation()->getValue() != 1)
notQuadratic = true;
if (notQuadratic)
SLog(EWarn, "Spot light \"%s\" is not a quadratic light! Treating it as one -- expect problems.", light.getId());
domFloat3 &color = spot->getColor()->getValue(); domFloat3 &color = spot->getColor()->getValue();
Float falloffAngle = 180.0f; Float falloffAngle = 180.0f;
if (spot->getFalloff_angle()) if (spot->getFalloff_angle())
@ -758,32 +776,52 @@ void loadCamera(ColladaConverter *cvt, Transform transform, std::ostream &os, do
domCamera::domOptics::domTechnique_common::domPerspective* persp = camera.getOptics()-> domCamera::domOptics::domTechnique_common::domPerspective* persp = camera.getOptics()->
getTechnique_common()->getPerspective().cast(); getTechnique_common()->getPerspective().cast();
if (persp) { if (persp) {
if (persp->getAspect_ratio().cast() != 0)
aspect = (Float) persp->getAspect_ratio()->getValue();
if (cvt->m_xres != -1) { if (cvt->m_xres != -1) {
xres = cvt->m_xres; xres = cvt->m_xres;
aspect = (Float) cvt->m_xres / (Float) cvt->m_yres; aspect = (Float) cvt->m_xres / (Float) cvt->m_yres;
} else {
if (persp->getAspect_ratio().cast() != 0) {
aspect = (Float) persp->getAspect_ratio()->getValue();
if (std::abs(aspect-0.1) < Epsilon) {
SLog(EWarn, "Found the suspicious aspect ratio \"0.1\", which is likely due to a bug in Blender 2.5"
" - setting to 1.0. Please use the \"-r\" parameter to override the resolution.");
aspect = 1.0f;
}
}
} }
os << "\t<camera id=\"" << camera.getId() << "\" type=\"perspective\">" << endl; os << "\t<camera id=\"" << camera.getId() << "\" type=\"perspective\">" << endl;
if (persp->getXfov().cast()) { if (persp->getXfov().cast()) {
Float yFov = radToDeg(2 * std::atan(std::tan(degToRad((Float) persp->getXfov()->getValue())/2) / aspect)); Float xFov = persp->getXfov()->getValue();
if (std::abs(xFov-1.0f) < Epsilon && cvt->m_fov == -1) {
SLog(EWarn, "Found the suspicious field of view value \"1.0\", which is likely due to a bug in Blender 2.5"
" - setting to 45deg. Please use the \"-f\" parameter to override this.");
xFov = 45.0f;
}
Float yFov = radToDeg(2 * std::atan(std::tan(degToRad(xFov)/1) / aspect));
if (cvt->m_fov != -1)
xFov = yFov = cvt->m_fov;
if (aspect <= 1.0f) if (aspect <= 1.0f)
os << "\t\t<float name=\"fov\" value=\"" << persp->getXfov()->getValue() << "\"/>" << endl; os << "\t\t<float name=\"fov\" value=\"" << xFov << "\"/>" << endl;
else else
os << "\t\t<float name=\"fov\" value=\"" << yFov << "\"/>" << endl; os << "\t\t<float name=\"fov\" value=\"" << yFov << "\"/>" << endl;
os << "\t\t<float name=\"nearClip\" value=\"" << persp->getZnear()->getValue() << "\"/>" << endl;
os << "\t\t<float name=\"farClip\" value=\"" << persp->getZfar()->getValue() << "\"/>" << endl;
os << "\t\t<boolean name=\"mapSmallerSide\" value=\"" <<(cvt->m_mapSmallerSide ? "true" : "false") << "\"/>" << endl;
} else if (persp->getYfov().cast()) { } else if (persp->getYfov().cast()) {
Float xFov = radToDeg(2 * std::atan(std::tan(degToRad((Float) persp->getYfov()->getValue())/2) * aspect)); Float yFov = persp->getYfov()->getValue();
if (std::abs(yFov-1.0) < Epsilon && cvt->m_fov == -1) {
SLog(EWarn, "Found the suspicious field of view value \"1.0\", which is likely due to a bug in Blender 2.5"
" - setting to 45deg. Please use the \"-f\" parameter to override this.");
yFov = 45.0f;
}
Float xFov = radToDeg(2 * std::atan(std::tan(degToRad(yFov)/2) * aspect));
if (cvt->m_fov != -1)
xFov = yFov = cvt->m_fov;
if (aspect > 1.0f) if (aspect > 1.0f)
os << "\t\t<float name=\"fov\" value=\"" << persp->getYfov()->getValue() << "\"/>" << endl; os << "\t\t<float name=\"fov\" value=\"" << yFov << "\"/>" << endl;
else else
os << "\t\t<float name=\"fov\" value=\"" << xFov << "\"/>" << endl; os << "\t\t<float name=\"fov\" value=\"" << xFov << "\"/>" << endl;
os << "\t\t<float name=\"nearClip\" value=\"" << persp->getZnear()->getValue() << "\"/>" << endl;
os << "\t\t<float name=\"farClip\" value=\"" << persp->getZfar()->getValue() << "\"/>" << endl;
os << "\t\t<boolean name=\"mapSmallerSide\" value=\"" << (cvt->m_mapSmallerSide ? "true" : "false") << "\"/>" << endl;
} }
os << "\t\t<float name=\"nearClip\" value=\"" << persp->getZnear()->getValue() << "\"/>" << endl;
os << "\t\t<float name=\"farClip\" value=\"" << persp->getZfar()->getValue() << "\"/>" << endl;
os << "\t\t<boolean name=\"mapSmallerSide\" value=\"" << (cvt->m_mapSmallerSide ? "true" : "false") << "\"/>" << endl;
} }
os << endl; os << endl;

View File

@ -9,6 +9,7 @@ public:
m_mapSmallerSide = true; m_mapSmallerSide = true;
m_xres = m_yres = -1; m_xres = m_yres = -1;
m_samplesPerPixel = 8; m_samplesPerPixel = 8;
m_fov = -1;
} }
void convert(const std::string &inputFile, void convert(const std::string &inputFile,
@ -22,9 +23,11 @@ public:
inline void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; } inline void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; }
inline void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; } inline void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; }
inline void setSamplesPerPixel(int samplesPerPixel) { m_samplesPerPixel = samplesPerPixel; } inline void setSamplesPerPixel(int samplesPerPixel) { m_samplesPerPixel = samplesPerPixel; }
inline void setFov(Float fov) { m_fov = fov; }
inline const std::string &getFilename() const { return m_filename; } inline const std::string &getFilename() const { return m_filename; }
public: public:
bool m_srgb, m_mapSmallerSide; bool m_srgb, m_mapSmallerSide;
int m_xres, m_yres, m_samplesPerPixel; int m_xres, m_yres, m_samplesPerPixel;
Float m_fov;
std::string m_filename; std::string m_filename;
}; };

View File

@ -56,6 +56,7 @@ void help() {
<< " -s Assume that colors are in sRGB space." << endl << endl << " -s Assume that colors are in sRGB space." << endl << endl
<< " -m Map the larger image side to the full field of view" << endl << endl << " -m Map the larger image side to the full field of view" << endl << endl
<< " -r <w>x<h> Override the image resolution to e.g. 1920×1080" << endl << endl << " -r <w>x<h> Override the image resolution to e.g. 1920×1080" << endl << endl
<< " -f <fov> Override the field of view to the given value specified in degrees." << endl << endl
<< "Please see the documentation for more information." << endl; << "Please see the documentation for more information." << endl;
} }
@ -64,10 +65,11 @@ int colladaMain(int argc, char **argv) {
char optchar, *end_ptr = NULL; char optchar, *end_ptr = NULL;
int xres = -1, yres = -1; int xres = -1, yres = -1;
int samplesPerPixel = 8; int samplesPerPixel = 8;
Float fov = -1;
optind = 1; optind = 1;
while ((optchar = getopt(argc, argv, "shmr:p:")) != -1) { while ((optchar = getopt(argc, argv, "shmr:p:f:")) != -1) {
switch (optchar) { switch (optchar) {
case 's': case 's':
srgb = true; srgb = true;
@ -80,6 +82,11 @@ int colladaMain(int argc, char **argv) {
if (*end_ptr != '\0') if (*end_ptr != '\0')
SLog(EError, "Invalid number of samples per pixel!"); SLog(EError, "Invalid number of samples per pixel!");
break; break;
case 'f':
fov = strtod(optarg, &end_ptr);
if (*end_ptr != '\0')
SLog(EError, "Invalid field of view value!");
break;
case 'r': { case 'r': {
std::vector<std::string> tokens = tokenize(optarg, "x"); std::vector<std::string> tokens = tokenize(optarg, "x");
if (tokens.size() != 2) if (tokens.size() != 2)
@ -109,6 +116,7 @@ int colladaMain(int argc, char **argv) {
converter.setResolution(xres, yres); converter.setResolution(xres, yres);
converter.setMapSmallerSide(mapSmallerSide); converter.setMapSmallerSide(mapSmallerSide);
converter.setSamplesPerPixel(samplesPerPixel); converter.setSamplesPerPixel(samplesPerPixel);
converter.setFov(fov);
converter.convert(argv[optind], "", argv[optind+1], argc > optind+2 ? argv[optind+2] : ""); converter.convert(argv[optind], "", argv[optind+1], argc > optind+2 ? argv[optind+2] : "");
return 0; return 0;