collada importer bugfixes (substituting missing textures)
parent
41efe48e01
commit
22a8a654ad
|
@ -269,6 +269,7 @@ struct triangle_key_order : public std::binary_function<SimpleTriangle, SimpleTr
|
|||
else if (v1.z > v2.z) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool operator()(const SimpleTriangle &t1, const SimpleTriangle &t2) const {
|
||||
int result;
|
||||
result = compare(t1.p0, t2.p0);
|
||||
|
@ -332,9 +333,7 @@ void writeGeometry(GeometryConverter *cvt, std::string prefixName, std::string i
|
|||
if (vData->typeToOffset[EUV] != -1) {
|
||||
domUint uvRef = tess_data[i+vData->typeToOffsetInStream[EUV]];
|
||||
vertex.uv = vData->data[vData->typeToOffset[EUV]][uvRef].toPoint2();
|
||||
#if 1
|
||||
vertex.uv.y = 1-vertex.uv.y; // Invert the V coordinate
|
||||
#endif
|
||||
} else {
|
||||
vertex.uv = Point2(0.0f);
|
||||
}
|
||||
|
@ -936,19 +935,22 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const fs::path &texture
|
|||
if (!fs::exists(resolved)) {
|
||||
SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str());
|
||||
resolved = cvt->locateResource(path.leaf());
|
||||
targetPath = targetPath.parent_path() / resolved.leaf();
|
||||
if (resolved.empty())
|
||||
SLog(EError, "Unable to locate a resource -- aborting conversion.");
|
||||
}
|
||||
}
|
||||
ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly);
|
||||
ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
|
||||
input->copyTo(output);
|
||||
input->close();
|
||||
output->close();
|
||||
if (fs::complete(resolved) != fs::complete(targetPath)) {
|
||||
ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly);
|
||||
ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
|
||||
input->copyTo(output);
|
||||
input->close();
|
||||
output->close();
|
||||
}
|
||||
}
|
||||
|
||||
os << "\t<texture id=\"" << identifier << "\" type=\"ldrtexture\">" << endl;
|
||||
os << "\t\t<string name=\"filename\" value=\"textures/" << path.leaf() << "\"/>" << endl;
|
||||
os << "\t\t<string name=\"filename\" value=\"textures/" << targetPath.leaf() << "\"/>" << endl;
|
||||
os << "\t</texture>" << endl << endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,19 +39,22 @@ std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std:
|
|||
if (!fs::exists(resolved)) {
|
||||
SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str());
|
||||
resolved = cvt->locateResource(path.leaf());
|
||||
targetPath = targetPath.parent_path() / resolved.leaf();
|
||||
if (resolved.empty())
|
||||
SLog(EError, "Unable to locate a resource -- aborting conversion.");
|
||||
}
|
||||
}
|
||||
|
||||
ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly);
|
||||
ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
|
||||
input->copyTo(output);
|
||||
output->close();
|
||||
input->close();
|
||||
if (fs::complete(resolved) != fs::complete(targetPath)) {
|
||||
ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly);
|
||||
ref<FileStream> output = new FileStream(targetPath, FileStream::ETruncReadWrite);
|
||||
input->copyTo(output);
|
||||
output->close();
|
||||
input->close();
|
||||
}
|
||||
}
|
||||
|
||||
return path.leaf();
|
||||
return targetPath.leaf();
|
||||
}
|
||||
|
||||
void addMaterial(GeometryConverter *cvt, std::ostream &os, const std::string &mtlName,
|
||||
|
|
|
@ -146,6 +146,12 @@ extern "C" {
|
|||
|
||||
METHODDEF(void) dsm_term_source (j_decompress_ptr cinfo) {
|
||||
}
|
||||
|
||||
METHODDEF(void) dsm_error_exit (j_common_ptr cinfo) {
|
||||
char msg[JMSG_LENGTH_MAX];
|
||||
(*cinfo->err->format_message) (cinfo, msg);
|
||||
SLog(EError, "Critcal libjpeg error: %s", msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* ========================== *
|
||||
|
@ -462,6 +468,8 @@ void Bitmap::loadJPEG(Stream *stream) {
|
|||
|
||||
memset(&jbuf, 0, sizeof(jbuf_t));
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jerr.error_exit = dsm_error_exit;
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
cinfo.src = (struct jpeg_source_mgr *) &jbuf;
|
||||
jbuf.buffer = new JOCTET[length];
|
||||
|
@ -597,7 +605,6 @@ void Bitmap::savePNG(Stream *stream) const {
|
|||
}
|
||||
|
||||
png_set_write_fn(png_ptr, stream, (png_rw_ptr) png_write_data, (png_flush_ptr) png_flush_data);
|
||||
// png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
||||
png_set_compression_level(png_ptr, 5);
|
||||
|
||||
memset(text, 0, sizeof(png_text)*4);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "acknowledgmentdlg.h"
|
||||
#include "mainwindow.h"
|
||||
#include "sceneimporter.h"
|
||||
#include <mitsuba/core/fresolver.h>
|
||||
#include "locateresourcedlg.h"
|
||||
|
||||
ImportDialog::ImportDialog(QWidget *parent, FileResolver *resolver) :
|
||||
QDialog(parent, Qt::Sheet), ui(new Ui::ImportDialog), m_resolver(resolver) {
|
||||
|
@ -135,12 +135,17 @@ void ImportDialog::accept() {
|
|||
const Logger *logger = Thread::getThread()->getLogger();
|
||||
size_t initialWarningCount = logger->getWarningCount();
|
||||
|
||||
ref<SceneImporter> importingThread = new SceneImporter(this,
|
||||
ref<SceneImporter> importingThread = new SceneImporter(
|
||||
resolver, sourceFile.toStdString(), directory.toStdString(),
|
||||
targetScene.toStdString(), adjustmentFile.toStdString(),
|
||||
ui->sRGBButton->isChecked());
|
||||
importingThread->start();
|
||||
|
||||
connect(importingThread->getConverter(),
|
||||
SIGNAL(locateResource(const fs::path &, fs::path *)),
|
||||
this, SLOT(onLocateResource(const fs::path &, fs::path *)),
|
||||
Qt::BlockingQueuedConnection);
|
||||
|
||||
while (importingThread->isRunning()) {
|
||||
QCoreApplication::processEvents();
|
||||
importingThread->wait(20);
|
||||
|
@ -164,3 +169,10 @@ void ImportDialog::accept() {
|
|||
QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
void ImportDialog::onLocateResource(const fs::path &path, fs::path *target) {
|
||||
LocateResourceDialog locateResource(this, path.file_string().c_str());
|
||||
locateResource.setWindowModality(Qt::ApplicationModal);
|
||||
if (locateResource.exec())
|
||||
*target = fs::path(locateResource.getFilename().toStdString());
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ protected slots:
|
|||
void on_inputBrowse_clicked(bool checked);
|
||||
void on_directoryBrowse_clicked(bool checked);
|
||||
void on_adjustmentBrowse_clicked(bool checked);
|
||||
void onLocateResource(const fs::path &path, fs::path *target);
|
||||
void refresh();
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
|
|
@ -139,6 +139,7 @@ int main(int argc, char *argv[]) {
|
|||
#endif
|
||||
|
||||
qRegisterMetaType<ELogLevel>("ELogLevel");
|
||||
qRegisterMetaType<fs::path>("fs::path");
|
||||
|
||||
MitsubaApplication app(argc, argv);
|
||||
try {
|
||||
|
|
|
@ -17,31 +17,18 @@
|
|||
*/
|
||||
|
||||
#include "sceneimporter.h"
|
||||
#include "../converter/converter.h"
|
||||
#include "locateresourcedlg.h"
|
||||
|
||||
class GUIGeometryConverter : public GeometryConverter {
|
||||
public:
|
||||
inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) {
|
||||
}
|
||||
fs::path GUIGeometryConverter::locateResource(const fs::path &resource) {
|
||||
fs::path result;
|
||||
emit locateResource(resource, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
fs::path locateResource(const fs::path &resource) {
|
||||
LocateResourceDialog locateResource(m_parent, resource.file_string().c_str());
|
||||
locateResource.setWindowModality(Qt::ApplicationModal);
|
||||
if (locateResource.exec())
|
||||
return fs::path(locateResource.getFilename().toStdString());
|
||||
|
||||
return fs::path();
|
||||
}
|
||||
private:
|
||||
QWidget *m_parent;
|
||||
};
|
||||
|
||||
SceneImporter::SceneImporter(QWidget *parent, FileResolver *resolver,
|
||||
SceneImporter::SceneImporter(FileResolver *resolver,
|
||||
const fs::path &sourceFile, const fs::path &directory,
|
||||
const fs::path &targetScene, const fs::path &adjustmentFile,
|
||||
bool sRGB)
|
||||
: Thread("impt"), m_parent(parent), m_resolver(resolver),
|
||||
: Thread("impt"), m_resolver(resolver),
|
||||
m_sourceFile(sourceFile), m_directory(directory),
|
||||
m_targetScene(targetScene), m_adjustmentFile(adjustmentFile), m_srgb(sRGB) {
|
||||
m_wait = new WaitFlag();
|
||||
|
@ -54,10 +41,9 @@ void SceneImporter::run() {
|
|||
Thread::getThread()->setFileResolver(m_resolver);
|
||||
#if defined(MTS_HAS_COLLADA)
|
||||
try {
|
||||
GUIGeometryConverter cvt(m_parent);
|
||||
cvt.setSRGB(m_srgb);
|
||||
cvt.convert(m_sourceFile, m_directory, m_targetScene, m_adjustmentFile);
|
||||
m_result = cvt.getFilename();
|
||||
m_converter.setSRGB(m_srgb);
|
||||
m_converter.convert(m_sourceFile, m_directory, m_targetScene, m_adjustmentFile);
|
||||
m_result = m_converter.getFilename();
|
||||
} catch (const std::exception &ex) {
|
||||
SLog(EWarn, "Conversion failed: %s", ex.what());
|
||||
} catch (...) {
|
||||
|
|
|
@ -22,12 +22,23 @@
|
|||
#include <QtGui>
|
||||
#include <mitsuba/core/lock.h>
|
||||
#include <mitsuba/core/fresolver.h>
|
||||
#include "../converter/converter.h"
|
||||
|
||||
using namespace mitsuba;
|
||||
|
||||
class GUIGeometryConverter : public QObject, public GeometryConverter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
inline GUIGeometryConverter() { }
|
||||
protected:
|
||||
fs::path locateResource(const fs::path &resource);
|
||||
signals:
|
||||
void locateResource(const fs::path &resource, fs::path *result);
|
||||
};
|
||||
|
||||
class SceneImporter : public Thread {
|
||||
public:
|
||||
SceneImporter(QWidget *parent, FileResolver *resolver,
|
||||
SceneImporter(FileResolver *resolver,
|
||||
const fs::path &sourceFile, const fs::path &directory,
|
||||
const fs::path &targetScene, const fs::path &adjustmentFile,
|
||||
bool sRGB);
|
||||
|
@ -36,11 +47,14 @@ public:
|
|||
|
||||
inline void wait(int ms) { m_wait->wait(ms); }
|
||||
|
||||
inline GUIGeometryConverter *getConverter() { return &m_converter; }
|
||||
|
||||
inline const fs::path &getResult() const { return m_result; }
|
||||
protected:
|
||||
virtual ~SceneImporter();
|
||||
|
||||
private:
|
||||
QWidget *m_parent;
|
||||
GUIGeometryConverter m_converter;
|
||||
ref<FileResolver> m_resolver;
|
||||
ref<WaitFlag> m_wait;
|
||||
fs::path m_sourceFile;
|
||||
|
|
Loading…
Reference in New Issue