From cd948f71aaea5d0e495a56fc2ca2f8e003a993bf Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Mon, 19 Jun 2006 13:42:53 +0000 Subject: [PATCH] collada importer --- src/meshlabplugins/colladaio/colladaio.cpp | 185 +++++++++++++++++++++ src/meshlabplugins/colladaio/colladaio.h | 58 +++++++ src/meshlabplugins/colladaio/colladaio.pro | 30 ++++ 3 files changed, 273 insertions(+) create mode 100644 src/meshlabplugins/colladaio/colladaio.cpp create mode 100644 src/meshlabplugins/colladaio/colladaio.h create mode 100644 src/meshlabplugins/colladaio/colladaio.pro diff --git a/src/meshlabplugins/colladaio/colladaio.cpp b/src/meshlabplugins/colladaio/colladaio.cpp new file mode 100644 index 000000000..ad94259b8 --- /dev/null +++ b/src/meshlabplugins/colladaio/colladaio.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +* MeshLab o o * +* An extendible mesh processor o o * +* _ O _ * +* Copyright(C) 2005, 2006 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + + $Log$ + Revision 1.1 2006/06/19 13:42:53 granzuglia + collada importer + +*****************************************************************************/ +#include +#include + +#include +#include "colladaio.h" +#include +#include +#include +#include +#include + +#include +#include + +using namespace vcg; + +bool ColladaIOPlugin::open(const QString &formatName, QString &fileName, MeshModel &m, int& mask, CallBackPos *cb, QWidget *parent) +{ + if (fileName.isEmpty()) + { + fileName = QFileDialog::getOpenFileName(parent,tr("Open File"),"../sample","Collada files (*.dae)"); + if (fileName.isEmpty()) + return false; + + QFileInfo fi(fileName); + // this change of dir is needed for subsequent textures/materials loading + QDir::setCurrent(fi.absoluteDir().absolutePath()); + } + + // initializing mask + mask = 0; + + // initializing progress bar status + if (cb != NULL) (*cb)(0, "Loading..."); + + QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; + std::string filename = fileName.toUtf8().data(); + + bool normalsUpdated = false; + + if(formatName.toUpper() == tr("DAE")) + { + //vcg::tri::io::ImporterOBJ::Info oi; + //oi.cb = cb; + //if (!vcg::tri::io::ImporterOBJ::LoadMask(filename.c_str(), oi)) + // return false; + // m.Enable(oi.mask); + + int result = vcg::tri::io::ImporterDAE::Open(m.cm, filename.c_str()); + if (result != vcg::tri::io::ImporterDAE::E_NOERROR) + { + /*if (result & vcg::tri::io::ImporterOBJ::E_NON_CRITICAL_ERROR) + QMessageBox::warning(parent, tr("OBJ Opening Warning"), vcg::tri::io::ImporterOBJ::ErrorMsg(result)); + else + { + QMessageBox::critical(parent, tr("OBJ Opening Error"), errorMsgFormat.arg(fileName, vcg::tri::io::ImporterOBJ::ErrorMsg(result))); + return false; + }*/ + QMessageBox::critical(parent, tr("DAE Opening Error"), errorMsgFormat.arg(fileName, vcg::tri::io::ImporterDAE::ErrorMsg(result))); + } + + /*if(oi.mask & MeshModel::IOM_WEDGNORMAL) + normalsUpdated = true; + + mask = oi.mask;*/ + } + + // verify if texture files are present + QString missingTextureFilesMsg = "The following texture files were not found:\n"; + bool someTextureNotFound = false; + for ( unsigned textureIdx = 0; textureIdx < m.cm.textures.size(); ++textureIdx) + { + FILE* pFile = fopen (m.cm.textures[textureIdx].c_str(), "r"); + if (pFile == NULL) + { + missingTextureFilesMsg.append("\n"); + missingTextureFilesMsg.append(m.cm.textures[textureIdx].c_str()); + someTextureNotFound = true; + } + else + fclose (pFile); + } + if (someTextureNotFound) + QMessageBox::warning(parent, tr("Missing texture files"), missingTextureFilesMsg); + + vcg::tri::UpdateBounding::Box(m.cm); // updates bounding box + if (!normalsUpdated) + vcg::tri::UpdateNormals::PerVertex(m.cm); // updates normals + + if (cb != NULL) (*cb)(99, "Done"); + + return true; +} + +bool ColladaIOPlugin::save(const QString &formatName,QString &fileName, MeshModel &m, const int &mask, vcg::CallBackPos *cb, QWidget *parent) +{ + //QString errorMsgFormat = "Error encountered while exportering file %1:\n%2"; + //string filename = fileName.toUtf8().data(); + //string ex = formatName.toUtf8().data(); + // + //int result = vcg::tri::io::Exporter::Save(m.cm,filename.c_str(),mask,cb); + //if(result!=0) + //{ + // QMessageBox::warning(parent, tr("Saving Error"), errorMsgFormat.arg(fileName, vcg::tri::io::Exporter::ErrorMsg(result))); + // return false; + //} + return true; +} + +/* + returns the list of the file's type which can be imported +*/ +QList ColladaIOPlugin::importFormats() const +{ + QList formatList; + formatList << Format("Collada File Format" ,tr("DAE")); + return formatList; +} + +/* + returns the list of the file's type which can be exported +*/ +QList ColladaIOPlugin::exportFormats() const +{ + QList formatList; + formatList << Format("Collada File Format" ,tr("DAE")); + return formatList; +} + +/* + returns the mask on the basis of the file's type. + otherwise it returns 0 if the file format is unknown +*/ +int ColladaIOPlugin::GetExportMaskCapability(QString &format) const +{ + //if(format.toUpper() == tr("DAE")){return vcg::tri::io::ExporterDAE::GetExportMaskCapability();} + return 0; +} + +const ActionInfo &ColladaIOPlugin::Info(QAction *action) +{ + static ActionInfo ai; + return ai; +} + +const PluginInfo &ColladaIOPlugin::Info() +{ + static PluginInfo ai; + ai.Date=tr("June 2006"); + ai.Version = tr("0.1"); + ai.Author = ("Guido Ranzuglia"); + return ai; + } + +Q_EXPORT_PLUGIN(ColladaIOPlugin) \ No newline at end of file diff --git a/src/meshlabplugins/colladaio/colladaio.h b/src/meshlabplugins/colladaio/colladaio.h new file mode 100644 index 000000000..674911504 --- /dev/null +++ b/src/meshlabplugins/colladaio/colladaio.h @@ -0,0 +1,58 @@ +/**************************************************************************** +* MeshLab o o * +* A versatile mesh processing toolbox o o * +* _ O _ * +* Copyright(C) 2005 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + + $Log$ + Revision 1.1 2006/06/19 13:42:53 granzuglia + collada importer + + *****************************************************************************/ +#ifndef COLLADAIOPLUGIN_H +#define COLLADAIOPLUGIN_H + +#include +#include +#include + +#include "../../meshlab/meshmodel.h" +#include "../../meshlab/interfaces.h" + +class ColladaIOPlugin : public QObject, public MeshIOInterface +{ + Q_OBJECT + Q_INTERFACES(MeshIOInterface) + + +public: + QList importFormats() const; + QList exportFormats() const; + const ActionInfo &Info(QAction *); + const PluginInfo &Info(); + int GetExportMaskCapability(QString &format) const; + + bool open(const QString &formatName, QString &fileName, MeshModel &m, int& mask, vcg::CallBackPos *cb=0, QWidget *parent=0); + bool save(const QString &formatName, QString &fileName, MeshModel &m, const int& mask, vcg::CallBackPos *cb=0, QWidget *parent= 0); +}; + +#endif diff --git a/src/meshlabplugins/colladaio/colladaio.pro b/src/meshlabplugins/colladaio/colladaio.pro new file mode 100644 index 000000000..afa8adf87 --- /dev/null +++ b/src/meshlabplugins/colladaio/colladaio.pro @@ -0,0 +1,30 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. ../../../../sf ../../../../code/lib/glew/include ../../../../code/lib/glut/include ../../../../code/lib/FCollada/ ../../../../code/lib/FCollada/LibXML/include +HEADERS = colladaio.h \ + io_dae.h +SOURCES = colladaio.cpp +TARGET = colladaio +DESTDIR = ../../meshlab/plugins + +win32-msvc.net:LIBS += ../../../../code/lib/FCollada/FColladaSU_MTD.lib +win32-msvc.net:LIBS -= LIBCMTD.lib + +# the following line is needed to avoid mismatch between +# the awful min/max macros of windows and the limits max +win32:DEFINES += NOMINMAX +unix{ + QMAKE_CC = gcc + QMAKE_CXX = g++ + QMAKE_LINK = gcc + CONFIG += warn_off debug_and_release + LIBS += -l3ds +} + + +contains(TEMPLATE,lib) { + CONFIG(debug, debug|release) { + unix:TARGET = $$member(TARGET, 0)_debug + else:TARGET = $$member(TARGET, 0)d + } +}