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