diff options
author | Sergey Dubitskiy <sergey.dubitskiy@nokia.com> | 2012-02-21 10:29:09 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-29 06:26:46 +0100 |
commit | 7c72ca5c3b3769713c5eaaec615abb80961f2e45 (patch) | |
tree | 74dd49c54b6d4ed39697065fa57c2d676aa1e1d7 /src/plugins | |
parent | 0d877888033c6be913199aac352e2bc9ad46bad5 (diff) |
Lib3DS was removed.
This code was a dead weight.
The loading of 3DS files is covered by Asset Importer library anyway.
Change-Id: I6ce254a42d2d21795d65019f0f670d1b60034222
Reviewed-by: Sarah Jane Smith <sarah.j.smith@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/sceneformats/3ds/3ds.pro | 30 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/README.txt | 55 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/main.cpp | 70 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsloader.cpp | 333 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsloader.h | 81 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsmesh.cpp | 755 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsmesh.h | 95 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsscene.cpp | 118 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsscene.h | 82 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsscenehandler.cpp | 249 | ||||
-rw-r--r-- | src/plugins/sceneformats/3ds/qgl3dsscenehandler.h | 99 | ||||
-rw-r--r-- | src/plugins/sceneformats/sceneformats.pro | 2 |
12 files changed, 1 insertions, 1968 deletions
diff --git a/src/plugins/sceneformats/3ds/3ds.pro b/src/plugins/sceneformats/3ds/3ds.pro deleted file mode 100644 index c7016f2bb..000000000 --- a/src/plugins/sceneformats/3ds/3ds.pro +++ /dev/null @@ -1,30 +0,0 @@ -TARGET = qscene3ds -include(../../qpluginbase.pri) -HEADERS += qgl3dsloader.h \ - qgl3dsscene.h \ - qgl3dsscenehandler.h \ - qgl3dsmesh.h -SOURCES += main.cpp \ - qgl3dsloader.cpp \ - qgl3dsscene.cpp \ - qgl3dsscenehandler.cpp \ - qgl3dsmesh.cpp - -QT += 3d - -DESTDIR = $$QT.3d.plugins/sceneformats -target.path = $$[QT_INSTALL_PLUGINS]/sceneformats -INSTALLS += target - -system_3ds { - !isEmpty(QMAKE_INCDIR_3DS):INCLUDEPATH += $$QMAKE_INCDIR_3DS - !isEmpty(QMAKE_LIBDIR_3DS):LIBS += -L$$QMAKE_LIBDIR_3DS - - !isEmpty(QMAKE_LIBS_3DS):LIBS += -l$$QMAKE_LIBS_3DS - else { - win32:LIBS += -llib3ds-1_3 - else:LIBS += -l3ds - } -} else { - include(../../../../3rdparty/lib3ds/lib3ds.pri) -} diff --git a/src/plugins/sceneformats/3ds/README.txt b/src/plugins/sceneformats/3ds/README.txt deleted file mode 100644 index 1fa00084b..000000000 --- a/src/plugins/sceneformats/3ds/README.txt +++ /dev/null @@ -1,55 +0,0 @@ -This implementation of 3D studio max file import relies on the library -lib3ds available from http://lib3ds.org/. A copy of this library is -included with Qt/3D, or you can download and build your own version -as described below. - -To enable building and use of the plugin, pass CONFIG+=system_3ds to qmake - -Currently version 1.3 is required. Do not use version 2.0 or later as it is incompatible. - -For Linux systems typically 1.3 can be obtained by installing a binary package, eg lib3ds-dev - -When compiling from source on Unix a simple ./configure, make, make install seems to work fine -on both linux and mac osx. - -On windows with Visual Studio the lib3ds library can be compiled as follows. - -1) Download the zipped source of 1.3 and expand it, cd into the directory created. - -2) Edit the file msvc8\lib3ds.rc - -#include "winres.h" - +#include "WinResrc.h" - -3) Locate the vcbuild.exe on the windows system: - - // this is needed for VS9 - C:\path\to\vcbuild.exe /upgrade msvc8\lib3ds.vcproj - C:\path\to\vcbuild.exe msvc8\lib3ds.vcproj - -4) Release and debug versions of the library files will be created. Install by: - - xcopy msvc8\release\* C:\path\to\bin - xcopy msvc8\debug\* C:\path\to\bin - -To avoid having to install the lib3ds.org library/dll/headers in a path where the compiler -will locate them, pass the following arguments to qmake: - QMAKE_LIBDIR_3DS=C:\build\lib3ds\msvc8\release - QMAKE_INCDIR_3DS=C:\build\lib3ds - -If the library is called something different to lib3ds-1_3 on windows or lib3ds.1.3.so on -Unix, for example to use the debug library on windows pass this argument to qmake: - QMAKE_LIBS_3DS=lib3ds-1_3d - -There is a handy 3dsplay utility in the lib3ds distribution - its not needed for Qt3D but is -convenient for debugging models. - -To build the 3dsplay utility - a command line 3ds viewer that uses GLUT and OpenGL - after -building and installing lib3ds as above, from the build directory use: -Linux: gcc -o 3dsplay -lGL -lglut -l3ds examples/3dsplay.c -MacOSX: gcc -FOpenGL -FGLUT -framework OpenGL -framework GLUT -l3ds -o 3dsplay examples/3dsplay.c - -To get image loading support to enable textures, this works on MacSOX: -First install SDL: http://www.libsdl.org/download-1.2.php -And SDL_image: http://www.libsdl.org/projects/SDL_image/ - gcc -c -DUSE_SDL -o examples/3dsplay.o -I/Library/Frameworks/SDL.framework/Headers -I/Library/Frameworks/SDL_image.framework/Headers examples/3dsplay.c - gcc -framework SDL_image -framework SDL -framework OpenGL -framework GLUT -l3ds -o 3dsplay examples/3dsplay.o diff --git a/src/plugins/sceneformats/3ds/main.cpp b/src/plugins/sceneformats/3ds/main.cpp deleted file mode 100644 index c79b6f293..000000000 --- a/src/plugins/sceneformats/3ds/main.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglsceneformatplugin.h" -#include "qgl3dsscenehandler.h" - -QT_BEGIN_NAMESPACE - -class QGL3dsScenePlugin : public QGLSceneFormatPlugin -{ -public: - QStringList keys() const; - virtual QGLSceneFormatHandler *create(QIODevice *device, const QUrl& url, const QString &format) const; -}; - -QStringList QGL3dsScenePlugin::keys() const -{ - return QStringList() << QLatin1String("3ds") << QLatin1String("application/x-3ds") << QLatin1String("image/x-3ds"); -} - -QGLSceneFormatHandler *QGL3dsScenePlugin::create(QIODevice *device, const QUrl& url, const QString &format) const -{ - Q_UNUSED(device); - Q_UNUSED(url); - Q_UNUSED(format); - return new QGL3dsSceneHandler; -} - -Q_EXPORT_STATIC_PLUGIN(QGL3dsScenePlugin) -Q_EXPORT_PLUGIN2(qscene3ds, QGL3dsScenePlugin) - -QT_END_NAMESPACE diff --git a/src/plugins/sceneformats/3ds/qgl3dsloader.cpp b/src/plugins/sceneformats/3ds/qgl3dsloader.cpp deleted file mode 100644 index e9d812c64..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsloader.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgl3dsloader.h" -#include "qglmaterial.h" -#include "qglmaterialcollection.h" -#include "qglpainter.h" -#include "qgltexture2d.h" -#include "qgl3dsscene.h" -#include "qglscenenode.h" -#include "qgl3dsmesh.h" - -#include <lib3ds/mesh.h> -#include <lib3ds/file.h> -#include <lib3ds/node.h> -#include <lib3ds/material.h> -#include <lib3ds/matrix.h> - -#include <QtCore/qvarlengtharray.h> -#include <QtCore/qdir.h> -#include <QtCore/qobject.h> -#include <QtCore/qfileinfo.h> - -QGL3dsLoader::QGL3dsLoader(Lib3dsFile *file, QGL3dsSceneHandler* sh) - : m_file(file) - , m_rootNode(new QGLSceneNode()) - , m_scene(sh) - , m_hasTextures(false) -{ - m_rootNode->setPalette(new QGLMaterialCollection(m_rootNode)); - m_rootNode->setObjectName(QString::fromLocal8Bit(file->name)); - setUrl(sh->url()); -} - -QGL3dsLoader::~QGL3dsLoader() -{ - // nothing to do here - m_rootNode is taken ownership of by caller of - // rootNode() method -} - -/*! - Sets the location for resolving resource paths to \a url. - - Only URL's with a "file" scheme are supported. -*/ -void QGL3dsLoader::setUrl(const QUrl &url) -{ - // TODO - handling of network URLs - if (url.scheme() == QLatin1String("file")) - m_url = url; - else - qWarning("QGL3dsLoader::setUrl(%s): ignored, only file urls supported", - url.encodedPath().constData()); -} - -void QGL3dsLoader::loadMesh(Lib3dsMesh *mesh) -{ -#ifndef QT_NO_DEBUG_STREAM - if (mesh->points == 0 && (m_scene->options() & QGL::ShowWarnings)) - qDebug() << "Mesh" << mesh->name << "has zero vertex count"; - else if (mesh->faces == 0 && (m_scene->options() & QGL::ShowWarnings)) - qDebug() << "Mesh" << mesh->name << "has zero face count"; -#endif - QGL3dsMesh m(mesh, m_rootNode->palette()); - QString name = QString::fromLatin1(mesh->name); - QGL::ModelOptions o = m_scene->meshOptions(name); - if (o == 0) - o = m_scene->options(); - m.setOptions(o); - QGLSceneNode *node; - if (mesh->faces == 0 || mesh->points == 0) - { - node = new QGLSceneNode(m_rootNode); - node->setObjectName(name); - m_meshes.insert(name, node); - return; - } - m.initialize(); - if (!m_hasTextures) - m_hasTextures = m.hasTexture(); - if (!m_hasLitMaterials) - m_hasLitMaterials = !m.hasTexture(); - node = m.finalizedSceneNode(); - m_meshes.insert(name, node); - m_rootNode->addNode(node); -} - -#ifndef QT_NO_DEBUG_STREAM -static const char *node_type_names[] = { - "LIB3DS_UNKNOWN_NODE", - "LIB3DS_AMBIENT_NODE", - "LIB3DS_OBJECT_NODE", - "LIB3DS_CAMERA_NODE", - "LIB3DS_TARGET_NODE", - "LIB3DS_LIGHT_NODE", - "LIB3DS_SPOT_NODE" -}; -#endif - -inline static QMatrix4x4 getNodeMatrix(Lib3dsNode *node) -{ - QMatrix4x4 nodeMatrix; - for (int col = 0; col < 4; ++col) - for (int row = 0; row < 4; ++row) - nodeMatrix(row, col) = node->matrix[col][row]; - nodeMatrix.optimize(); - Lib3dsObjectData *d = &node->data.object; - if (!qFuzzyIsNull(d->pivot[0]) || !qFuzzyIsNull(d->pivot[1]) || !qFuzzyIsNull(d->pivot[2])) - nodeMatrix.translate(-d->pivot[0], -d->pivot[1], -d->pivot[2]); - return nodeMatrix; -} - -void QGL3dsLoader::loadNodes(Lib3dsNode *nodeList, QGLSceneNode *parentNode) -{ - Lib3dsNode *node; - for (node = nodeList; node != NULL; node = node->next) - { - if (node->type == LIB3DS_OBJECT_NODE) - { - Lib3dsObjectData *d = &node->data.object; - QString meshName = QString::fromLatin1(d->morph); - if (meshName.isEmpty()) - meshName = QString::fromLatin1(d->instance); - if (meshName.isEmpty()) - meshName = QString::fromLatin1(node->name); - if (!meshName.isEmpty() && m_meshes.contains(meshName)) - { - QGLSceneNode *mesh = m_meshes[meshName]; - QMatrix4x4 mat = getNodeMatrix(node); - mat = mat * mesh->localTransform(); - mesh->setLocalTransform(mat); - } - else - { - QGLSceneNode *sceneNode = new QGLSceneNode(parentNode); - sceneNode->setPalette(parentNode->palette()); - sceneNode->setLocalTransform(getNodeMatrix(node)); - //sceneNode->userTransform().setToIdentity(); //DP: set matrix to identity so it is initialised in a useful way at least. - QString nodeName(QString::fromLatin1(node->name)); - if (nodeName == QLatin1String("$$$DUMMY")) - { - nodeName = QString::fromLatin1(node->data.object.instance); - sceneNode->setObjectName(nodeName); - loadNodes(node->childs, sceneNode); - } - } - } -#ifndef QT_NO_DEBUG_STREAM - else - { - qDebug() << "Node" << node->name << "of type" << node_type_names[node->type] << "not currently supported"; - } -#endif - } -} - -/*! - \internal - Loads all the geometry, materials, and texture associations from the assigned - file, and returns the root node of the resulting scene graph. - - The caller must take ownership of the root node returned, and delete it - when its no longer required. -*/ -QGLSceneNode *QGL3dsLoader::loadMeshes() -{ - Q_CHECK_PTR(m_file); - Lib3dsMaterial *mat; - for (mat = m_file->materials; mat != NULL; mat = mat->next) - loadMaterial(mat); - Lib3dsMesh * mesh; - for (mesh = m_file->meshes; mesh != NULL; mesh = mesh->next) - loadMesh(mesh); - QGL::MeshOptionMap optList = m_scene->meshOptions(); - QStringList optionedMeshes = optList.keys(); - QStringList gotMeshes = m_meshes.keys(); - for (int i = 0; i < gotMeshes.size(); ++i) - optionedMeshes.removeAll(gotMeshes.at(i)); - for (int i = 0; i < optionedMeshes.size(); ++i) - qWarning("Option specified, but mesh %s not found", - qPrintable(optionedMeshes.at(i))); - m_rootNode->palette()->removeUnusedMaterials(); - loadNodes(m_file->nodes, m_rootNode); - m_rootNode->setEffect(m_hasTextures ? QGL::LitModulateTexture2D : QGL::LitMaterial); - return m_rootNode; -} - -/*! - \internal - Search for a resource based on the given \a path. - - If the URL for the currently loading mesh has a scheme other than - "file" then a URL with the path relative to that URL is returned. - - If the URL for the currently loading mesh has a "file" scheme, then - first a case-sensitive search is done of all of the current directory, - and the :/ resource directory, and the directory of the current mesh - file. - - If the file is not found in any of those locations then they are - searched again case-insensitively. If the file is found, then a - URL based on the absolute file path of the matching file is returned. - - Otherwise an empty string is returned. -*/ -QUrl QGL3dsLoader::ensureResource(const QString &path) -{ - QUrl res; - if (m_url.scheme() == QLatin1String("file")) - { - res = m_url.resolved(path); - if (QFile::exists(res.path())) // shortcut common case - return res; - QStringList paths; - paths << QLatin1String(".") << QLatin1String(":/"); // current directory and aliased/root resource file - if (!m_url.isEmpty()) - { - QFileInfo fi(m_url.path()); - paths.prepend(fi.absoluteDir().absolutePath()); - } - bool caseInsensitive = false; - do { - QStringList::const_iterator it(paths.begin()); - for ( ; it != paths.end(); ++it) - { - QDir resDir(*it); - QStringList fileList = resDir.entryList(QDir::Files); - if (caseInsensitive) - { - QStringList::const_iterator fit(fileList.begin()); - for ( ; fit != fileList.end(); ++fit) - { - if (fit->toLower() == path.toLower()) - { - res.setScheme(QLatin1String("file")); - res.setPath(resDir.absoluteFilePath(*fit)); - break; - } - } - } - else - { - if (fileList.contains(path)) - { - //return resDir.absoluteFilePath(path); - res.setScheme(QLatin1String("file")); - res.setPath(resDir.absoluteFilePath(path)); - break; - } - } - } - if (caseInsensitive) - break; - caseInsensitive = true; - } while (true); - } - else - { - // non-file url - res = m_url.resolved(path); - } - return res; -} - -/*! - Load a material -*/ -void QGL3dsLoader::loadMaterial(Lib3dsMaterial *mat3ds) -{ - QGLMaterialCollection *palette = m_rootNode->palette(); - QGLMaterial *mat = new QGLMaterial(); - Lib3dsRgba &amb = mat3ds->ambient; - Lib3dsRgba &dif = mat3ds->diffuse; - Lib3dsRgba &spc = mat3ds->specular; - mat->setAmbientColor(QColor::fromRgbF(amb[0], amb[1], amb[2], amb[3])); - mat->setDiffuseColor(QColor::fromRgbF(dif[0], dif[1], dif[2], dif[3])); - mat->setSpecularColor(QColor::fromRgbF(spc[0], spc[1], spc[2], spc[3])); - mat->setShininess(128 * mat3ds->shininess); - mat->setObjectName(QString::fromLatin1(mat3ds->name)); - palette->addMaterial(mat); - if (mat3ds->texture1_map.name[0]) - { - QString txName(QString::fromLatin1(mat3ds->texture1_map.name)); - QUrl url = ensureResource(txName); - if (url.isEmpty()) - { - if (m_scene->options() & QGL::ShowWarnings) - qWarning("Could not load texture: %s", mat3ds->texture1_map.name); - } - else - { - mat->setTextureUrl(url); - } - } -} diff --git a/src/plugins/sceneformats/3ds/qgl3dsloader.h b/src/plugins/sceneformats/3ds/qgl3dsloader.h deleted file mode 100644 index 88e72019e..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsloader.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGL3DSLOADER_H -#define QGL3DSLOADER_H - -#include <QtCore/qurl.h> -#include <QtCore/qstring.h> -#include <QtCore/qmap.h> - -class Lib3dsFile; -class Lib3dsMesh; -class Lib3dsMaterial; -class Lib3dsNode; -class QGL3dsMesh; -class QGLSceneNode; -class QGL3dsSceneHandler; - -class QGL3dsLoader -{ -public: - QGL3dsLoader(Lib3dsFile *file, QGL3dsSceneHandler* sh); - ~QGL3dsLoader(); - QGLSceneNode *loadMeshes(); - -private: - void loadMesh(Lib3dsMesh *); - void loadNodes(Lib3dsNode *, QGLSceneNode *); - void loadMaterial(Lib3dsMaterial *); - QUrl ensureResource(const QString &); - void setUrl(const QUrl &url); - - Lib3dsFile *m_file; - QGLSceneNode *m_rootNode; - QGL3dsSceneHandler *m_scene; - QList<QGLSceneNode *> m_nodes; - QMap<QString, QGLSceneNode *> m_meshes; - QUrl m_url; - bool m_hasTextures; - bool m_hasLitMaterials; -}; - -#endif // QGL3DSLOADER_H diff --git a/src/plugins/sceneformats/3ds/qgl3dsmesh.cpp b/src/plugins/sceneformats/3ds/qgl3dsmesh.cpp deleted file mode 100644 index 03f8b51e9..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsmesh.cpp +++ /dev/null @@ -1,755 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgl3dsmesh.h" -#include "qglmaterialcollection.h" -#include "qglsection_p.h" -#include "qarray.h" -#include "qvector_utils_p.h" - -#include <lib3ds/mesh.h> -#include <lib3ds/material.h> -#include <lib3ds/vector.h> -#include <lib3ds/types.h> - -#include <QtGui/qmatrix4x4.h> -#include <QtCore/qmath.h> - -// Faceted meshes look terrible when they have more than a small number -// of faces. Usually if large meshes are faceted its some kind of error -// in the model, or in importing of the model by lib3ds. Force on -// smoothing when greater than this many faces are detected. -#define FACETED_THRESHOLD 1000 - -// Two faces that have an angle between their plane vectors with a cosine -// less than this are judged to form a sharp (acute) angle. -// -ve cosine (less than 0.0f) means 90 degrees or sharper like the sides -// of a rectangular prism so this is a good value. -#define ACUTE -0.0001f - -// Two vectors that have an angle between them with a cosine less than this -// value are judged to be approximately the inverse of each other, for the -// purposes of determining whether a normal has been inverted or not -#define INVERSE -0.20f - -// Only try to correct normals if this many neighbour faces contribute to -// the assessment. 2 or 3 are good values. 4 or greater is the same as -// defining DO_NORMAL_CORRECT false -#define AVG_CNT 2 - -// make a QVector3D from a Lib3dsVector - by a hard cast. Its required -// that QVector3D behave like a POD type - float[3] - for all of the -// OpenGL stuff -static inline QVector3D &l2v(Lib3dsVector &vec) -{ - return reinterpret_cast<QVector3D&>(vec); -} - -// is this a null 3ds vector - same as QVector3D::isNull() -static inline bool qIsNull(const Lib3dsVector &vec) -{ - return (qIsNull(vec[0]) && qIsNull(vec[1]) && qIsNull(vec[2])); -} - -static inline bool qFskCompare(const Lib3dsVector &a, const Lib3dsVector &b) -{ - return (qFskCompare(a[0], b[0]) && qFskCompare(a[1], b[1]) && qFskCompare(a[2], b[2])); -} - -// find the normalized plane vector, that is a unit vector perpendicular -// to the plane of the face. this is the same thing as the default normal -static inline void planeVec(Lib3dsFace *face, Lib3dsPoint *pointList, Lib3dsVector result) -{ - Lib3dsVector &l3a = pointList[face->points[0]].pos; - Lib3dsVector &l3b = pointList[face->points[1]].pos; - Lib3dsVector &l3c = pointList[face->points[2]].pos; - lib3ds_vector_normal(result, l3a, l3b, l3c); -} - -struct ModulateRecord -{ - bool disabled; - bool keyFresh; - int facesProcessed; - int numModulated; - Lib3dsDword altKey; - Lib3dsDword key; -}; - -QGL3dsMesh::QGL3dsMesh(Lib3dsMesh *mesh, QGLMaterialCollection *materials) - : QGLBuilder(materials) - , m_mesh(mesh) - , m_texFlip(false) - , m_hasZeroSmoothing(false) - , m_faceMap(0) -{ -} - -QGL3dsMesh::~QGL3dsMesh() -{ - delete[] m_faceMap; -} - -void QGL3dsMesh::processNodeForMaterial(int matIx, QGLSceneNode *node) -{ - QGLSceneNode *s = sceneNode(); - QString baseName = s->objectName(); - node->setMaterialIndex(matIx); - node->setObjectName(baseName + QLatin1String("::") + - ((matIx == -1) - ? QLatin1String("No_Material") - : s->palette()->materialName(matIx))); - checkTextures(matIx); - generateVertices(); - s->palette()->markMaterialAsUsed(matIx); -} - -void QGL3dsMesh::initAdjacencyMap() -{ - Lib3dsFace *face; - m_faceMap = new FacePtr[m_mesh->faces * 3]; - qMemSet(m_faceMap, 0, sizeof(m_faceMap)); - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - { - face = &m_mesh->faceL[f]; - planeVec(face, m_mesh->pointL, face->normal); - m_mesh->faceL[f].user.p = &m_faceMap[f*3]; - } -} - -void QGL3dsMesh::initialize() -{ - QGLSceneNode *s = sceneNode(); - s->setObjectName(QString::fromLatin1(m_mesh->name)); - if ((m_options & QGL::ForceSmooth) && (m_options & QGL::ForceFaceted)) - { - if (m_options & QGL::ShowWarnings) - qWarning("Both smooth and faceted forced on for %s: forcing smooth\n", - m_mesh->name); - m_options &= ~QGL::ForceFaceted; - } - initAdjacencyMap(); - if (m_options & (QGL::CorrectNormals | QGL::CorrectAcute)) - modulateMesh(); - analyzeMesh(); - - if (m_smoothingGroups == 0) - { - bool forceSmooth = (m_options & QGL::ForceSmooth); - if (!forceSmooth && m_mesh->faces > FACETED_THRESHOLD) - { - if (m_options & QGL::ShowWarnings) - qWarning("Mesh %s has %d faces (threshold is %d):" - "forcing smooth render", m_mesh->name, m_mesh->faces, - FACETED_THRESHOLD); - forceSmooth = true; - } - if (forceSmooth) - { - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - m_mesh->faceL[f].smoothing = 1; - analyzeMesh(); - } - } - - bool mixedTexturedAndPlain = m_plainMaterials.count() > 0 && - m_textureMaterials.count() > 0; - - s->setLocalTransform(meshMatrix()); - - // start a new section and node - newSection(m_smoothingGroups ? QGL::Smooth : QGL::Faceted); - QGLSceneNode *node = currentNode(); - - // process all the plain materials first, then textured to avoid effect swapping - QList<int> matList = m_plainMaterials.toList(); - if (mixedTexturedAndPlain) - { - node->setEffect(QGL::LitMaterial); - node->setObjectName(s->objectName() + QLatin1String("::Materials")); - //qDebug() << ">>> mixed:" << node; - pushNode(); - //qDebug() << " pushed - current now:" << currentNode(); - } - else - { - s->setEffect(m_textureMaterials.count() > 0 ? QGL::LitModulateTexture2D : QGL::LitMaterial); - } - //qDebug() << "processing:" << matList.count() << "materials"; - while (matList.count() > 0) - { - int matIx = matList.takeFirst(); - processNodeForMaterial(matIx, node); - if (matList.count() > 0) - node = newNode(); - } - matList = m_textureMaterials.toList(); - if (mixedTexturedAndPlain) - { - //qDebug() << "<<< mixed:" << currentNode(); - popNode(); - //qDebug() << " popped - current now:" << currentNode(); - node = currentNode(); - node->setEffect(QGL::LitModulateTexture2D); - node->setObjectName(s->objectName() + QLatin1String("::Textures")); - } - while (matList.count() > 0) - { - int matIx = matList.takeFirst(); - processNodeForMaterial(matIx, node); - if (matList.count() > 0) - node = newNode(); - } -} - -// Build a linked list, in a QArray: the first N*2 entries correspond -// to the N vertices: for each n'th vertex, n*2 is the face number, -// n*2+1is the index of the next entry for that vertex, or -1 if there -// is no next entry. -// -// While on the job find the smoothing keys and store in allKeys. -// -// And zero out the user data pointer for each face, and calculate the -// smoothing group count. -QArray<int> QGL3dsMesh::mapFacesToVerts(Lib3dsDword *allKeys) -{ - Lib3dsFace *face; - QArray<int> vlist(m_mesh->points * 2, -1); - int nx = 2 * m_mesh->points; - m_smoothingGroupCount = 0; - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - { - face = &m_mesh->faceL[f]; - if (face->smoothing) - { - if (!(face->smoothing & *allKeys)) - { - *allKeys |= face->smoothing; - m_smoothingGroupCount += 1; - } - } - for (int i = 0; i < 3; ++i) - { - int v = face->points[i]; - int ptr = v*2; - int prv = -1; - if (vlist[ptr] != -1) - { - prv = ptr; - while (vlist[ptr+1] != -1) - { - ptr = vlist[ptr+1]; - prv = ptr; - } - ptr = nx; - vlist.extend(2); - nx += 2; - } - vlist[ptr] = f; - vlist[ptr+1] = -1; - if (prv != -1) - vlist[prv+1] = ptr; - } - } - return vlist; -} - -void QGL3dsMesh::addToAdjacencyMap(Lib3dsFace *face, Lib3dsFace *neighbour) -{ - Q_ASSERT(face); - Q_ASSERT(face->user.p); - Q_ASSERT(neighbour); - FacePtr *h = static_cast<FacePtr*>(face->user.p); - while (*h != 0) - ++h; - *h = neighbour; -} - -// add to each face a linked list of its <= 3 neighbouring faces -// and also ensure each face knows is own normal. Rather than doing -// lots of small allocs, just assume every face has 3 neighbours -// and allocate the list nodes in one big lump - the m_faceMap. -// use the user data pointer in the lib3ds face struct to point -// to the first node in the list. -void QGL3dsMesh::buildAdjacencyMap(const QArray<int> &vlist) -{ - Lib3dsFace *face; - Lib3dsFace *nbr; - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - { - // for each edge (where an edge is a pair of verts) find ones - // adjacent, ie both verts in edge have same face (which is - // not this face). - face = &m_mesh->faceL[f]; - for (int i = 0; i < 3; ++i) - { - Q_ASSERT(face->points[i] < m_mesh->points); - int vi = 2 * face->points[i]; - int neighbouri = -1; - while (true) - { - neighbouri = vlist[vi]; - if (neighbouri != (int)f) - { - Q_ASSERT(face->points[(i + 1) % 3] < m_mesh->points); - int vj = 2 * face->points[(i + 1) % 3]; - int neighbourj = -1; - while (true) - { - neighbourj = vlist[vj]; - if (neighbourj == neighbouri) - { - nbr = &m_mesh->faceL[neighbouri]; - // only add as neighbour if at least one smoothing group - // is shared - still have to test again below for each group - if (nbr->smoothing & face->smoothing) - addToAdjacencyMap(face, nbr); - break; - } - if (vlist[vj+1] == -1) - break; - vj = vlist[vj+1]; - } - } - if (vlist[vi+1] == -1) - break; - else - vi = vlist[vi+1]; - } - } - } -} - -static inline void incOrWarn(ModulateRecord *mod) -{ - if (mod->altKey != 0x80000000) - { - mod->altKey <<= 1; - } - else - { - qWarning("Overflowed smoothing keys - modulation disabled."); - mod->disabled = true; - } -} - -static inline void nextUnusedKey(ModulateRecord *mod, const Lib3dsDword &allKeys) -{ - if (!mod->disabled) - { - if (mod->altKey != 0) - incOrWarn(mod); - else - { - mod->altKey = 1; // initialize - } - while ((mod->altKey & allKeys) && !mod->disabled) - { - incOrWarn(mod); - } - mod->keyFresh = true; - } -} - -static int numCorrected = 0; -static int numWindingCorrected = 0; - -static inline void doNormalCorrect(Lib3dsFace *face) -{ - QGL3dsMesh::FacePtr *n = reinterpret_cast<QGL3dsMesh::FacePtr*>(face->user.p); - int acnt = 0; - Lib3dsVector avgn = { 0 }; - for (; *n; ++n) - { - if ((*n)->smoothing & face->smoothing) - { - lib3ds_vector_add(avgn, avgn, (*n)->normal); - ++acnt; - } - } - if (acnt >= AVG_CNT) - { - lib3ds_vector_normalize(avgn); - float na = lib3ds_vector_dot(face->normal, avgn); - if (na < INVERSE) - { - //qWarning("corrected: %p - %d, %d, %d", face, - // face->points[0], face->points[1], face->points[2]); - //lib3ds_vector_dump(face->normal); - lib3ds_vector_neg(face->normal); - numWindingCorrected++; - qSwap(face->points[1], face->points[2]); - } - } -} - -static inline void modFace(Lib3dsFace *face, ModulateRecord *mod) -{ - ++mod->numModulated; - face->smoothing &= ~mod->key; // remove old key - face->smoothing |= mod->altKey; // add in new key - ::strncpy(face->material, "bright-red", 60); //debug -} - -static inline void doModulate(Lib3dsFace *face, ModulateRecord *mod) -{ - QGL3dsMesh::FacePtr *n = reinterpret_cast<QGL3dsMesh::FacePtr*>(face->user.p); - ++mod->facesProcessed; - for ( ; *n; ++n) - { - QGL3dsMesh::FacePtr neighbour = *n; - if (neighbour->smoothing & face->smoothing) - { - if (lib3ds_vector_dot(face->normal, neighbour->normal) < ACUTE) - { - qWarning("Modulated due to ACUTE\n"); - modFace(neighbour, mod); - mod->keyFresh = false; - } - } - } -} - -bool operator<(const QVector3D &a, const QVector3D &b) -{ - if (qFskCompare(a.x(), b.x())) - { - if (qFskCompare(a.y(), b.y())) - { - if (qFskCompare(a.z(), b.z())) - { - return false; // they're equal a is not less than b - } - else - { - return a.z() < b.z(); - } - } - else - { - return a.y() < b.y(); - } - } - else - { - return a.x() < b.x(); - } -} - -// Go thru each smoothing group - we don't care about the zero group since -// they're already faceted. In each group process all connected faces -// starting the queue off with a seed face (the first face in the group). -// Set the alternate group to be the first unused smoothing group key. -// -// To process a face: add the face to the processed set; for each adjacent -// face if its in this same smoothing group, add it to the queue. -// -// Modulate smoothing mode: if an adjacent face is at an acute angle to this -// face, move it to the alternate group. Note that the alternate groups are -// not further iterated since they are not in "each smoothing group" -// (the allKeys variable). -// -// When the queue is empty, go to the next smoothing group in the mesh. - -// Normal repair mode: if a face normal is flipped in error, ie a mistake -// in model building (typically points specified in the wrong order) -// this can be detected and repaired. The normal is flipped if the inverse -// of the normal is at an acute angle to the average of neighbour normals. -// If detected the normals is corrected and the winding is also checked to -// see if it needs to be corrected also. -void QGL3dsMesh::modulateMesh() -{ - if (!(m_options & (QGL::CorrectNormals | QGL::CorrectAcute))) - return; - FacePtr face; - Lib3dsDword allKeys = 0; - QArray<int> vlist = mapFacesToVerts(&allKeys); - buildAdjacencyMap(vlist); - QSet<FacePtr> processed; - ModulateRecord mod; - qMemSet(&mod, 0, sizeof(struct ModulateRecord)); - mod.key = 1; - while ((mod.key < allKeys) && !mod.disabled && mod.key) - { - if (!(allKeys & mod.key)) - { - ++mod.key; - continue; - } - QArray<FacePtr> queue; - Lib3dsDword fptr = 0; - int head = 0; - while (true) - { - if (head >= queue.size()) // seed another island of faces - { - if (!mod.keyFresh && head > 0) // if not first time thru, did we use last key? - allKeys = allKeys | mod.altKey; - FacePtr qf = 0; - for ( ; fptr < m_mesh->faces; ++fptr) - { - qf = &m_mesh->faceL[fptr]; - if ((mod.key & qf->smoothing) && !processed.contains(qf)) - break; - } - if (fptr == m_mesh->faces) - break; - queue.append(qf); - if (!mod.keyFresh) - { - nextUnusedKey(&mod, allKeys); - if (mod.disabled) - break; - } - } - face = queue.at(head++); - processed.insert(face); - doNormalCorrect(face); - doModulate(face, &mod); - FacePtr *n = reinterpret_cast<FacePtr*>(face->user.p); - for ( ; *n; ++n) - if ((mod.key & (*n)->smoothing) && !processed.contains(*n)) - queue.append(*n); - } - } - if ((m_options & QGL::CorrectNormals) && (m_options & QGL::ShowWarnings)) - qDebug() << "CorrectNormals mode:" << numCorrected << "normals corrected."; - if ((m_options & QGL::CorrectAcute) && (m_options & QGL::ShowWarnings)) - qDebug() << "CorrectAcute mode:" << mod.numModulated << "normals corrected"; -} - -int QGL3dsMesh::cachedMaterialLookup(const char *material) -{ - static bool initialized = false; - static int lastLookup = -1; - static char lastName[512]; - if (!initialized) - { - ::memset(lastName, 0, 512); - initialized = true; - } - if (qstrncmp(lastName, material, 510) != 0) - { - lastLookup = sceneNode()->palette()->indexOf(QString::fromLatin1(material)); - qstrncpy(lastName, material, 510); - } - return lastLookup; -} - -/*! - \internal - Find material indexes and smoothing groups used in this mesh. If any - face has no material assigned then a -1 index will be listed. - Also figures out how complex the mesh is, by finding the count of - smoothing groups for the material with the greatest number of groups. - If the mesh is faceted (no smoothing) but has greater than FACETED_THRESHOLD - faces then smoothing is forced on and the mesh rescanned. - -*/ -void QGL3dsMesh::analyzeMesh() -{ - QGLMaterialCollection *pal = sceneNode()->palette(); - Lib3dsFace *face; - Lib3dsDword allKeys = 0; - m_smoothingGroupCount = 0; - m_hasZeroSmoothing = false; - m_plainMaterials.clear(); - m_textureMaterials.clear(); - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - { - face = &m_mesh->faceL[f]; - int matIx = cachedMaterialLookup(face->material); -#ifndef QT_NO_DEBUG_STREAM - if (matIx == -1 && strlen(face->material) != 0 && (m_options & QGL::ShowWarnings)) - qDebug("Bad .3ds file: no material %s! (Referenced in mesh %s)\n", - face->material, m_mesh->name); -#endif - if (face->smoothing) - { - if ((face->smoothing & allKeys) != face->smoothing) - { - Lib3dsDword key = 1; - while (key) - { - if ((key & face->smoothing) && !(allKeys & key)) - { - allKeys = allKeys | key; - m_smoothingGroupCount += 1; - } - key <<= 1; - } - } - } - else - { - m_hasZeroSmoothing = true; - } - if (!m_plainMaterials.contains(matIx) && !m_textureMaterials.contains(matIx)) - { - QGLMaterial *mat = pal->material(matIx); - if (mat && mat->texture()) - m_textureMaterials.insert(matIx); - else - m_plainMaterials.insert(matIx); - } - } - m_smoothingGroups = allKeys; -} - -/*! - \internal - Check the meshes textures and update the record of whether this mesh - has textures or not. In debug mode issue a warning if the textures are - corrupt (number of texels and vertices not equal). -*/ -void QGL3dsMesh::checkTextures(int material) -{ - QGLMaterial *mat = sceneNode()->palette()->material(material); - QGLTexture2D *tex = (mat ? mat->texture() : 0); - m_hasTextures = false; - if (tex) - { - m_hasTextures = true; -#ifndef QT_NO_DEBUG_STREAM - if (m_mesh->points != m_mesh->texels) - qWarning("Mesh %s has unequal number of texels (%d) and vertices (%d)", - m_mesh->name, m_mesh->texels, m_mesh->points); -#endif - // all texture coordinates from 3ds have to be flipped because - // 3ds uses the correct coordinate system, whilst qt uses - // upside-down coordinates - m_texFlip = (tex->bindOptions() & QGLTexture2D::InvertedYBindOption) == 0; - } -} - -/*! - \internal - Returns any local transformation matrix for the mesh. -*/ -QMatrix4x4 QGL3dsMesh::meshMatrix() const -{ - Lib3dsMatrix &m = m_mesh->matrix; // typedef for float[4][4] - QMatrix4x4 mat; - for (int col = 0; col < 4; ++col) - for (int row = 0; row < 4; ++row) { - float e = m[col][row]; - if (qFuzzyIsNull(e)) - mat(row, col) = 0.0f; - else - mat(row, col) = e; - } - mat.optimize(); // setup to use optimizations - if (mat.isIdentity()) - return mat; - // The reverse transform is what we apply to model-view in order - // to draw the underlying geometry - bool invertible = true; - mat = mat.inverted(&invertible); - if (invertible) - return mat; - if (m_options & QGL::ShowWarnings) - qWarning("Could not invert matrix for mesh %s", m_mesh->name); - return QMatrix4x4(); -} - -/*! - \internal - Generate the vertices for the faces based on their smoothing keys and - the current nodes material. -*/ -void QGL3dsMesh::generateVertices() -{ - int matIx = currentNode()->materialIndex(); - int keyCount = m_smoothingGroupCount; - if (m_hasZeroSmoothing) - ++keyCount; - QString baseName = currentNode()->objectName(); - Lib3dsDword key = 0; - while (key <= m_smoothingGroups) - { - if ((key & m_smoothingGroups) || ((key == 0) && m_hasZeroSmoothing)) - { - if (key == 0) - currentSection()->setSmoothing(QGL::Faceted); - keyCount -= 1; - currentNode()->setMaterialIndex(matIx); - currentNode()->setObjectName(baseName + QLatin1String("::") + QString::number(key)); - QGeometryData tri; - int cur = 0; - for (Lib3dsDword f = 0; f < m_mesh->faces; ++f) - { - Lib3dsFace *face = &m_mesh->faceL[f]; - int faceMat = cachedMaterialLookup(face->material); - if (faceMat == matIx && - ((key & face->smoothing) || (key == 0 && face->smoothing == 0))) - { - QVector3D norm = l2v(face->normal); - for (int i = 0; i < 3; ++i) - { - int a = face->points[i]; - Lib3dsVector &l3a = m_mesh->pointL[a].pos; - tri.appendVertex(l2v(l3a)); - tri.appendNormal(norm); - if (m_hasTextures) - { - Lib3dsTexel &t0 = m_mesh->texelL[a]; - tri.appendTexCoord(QVector2D(t0[0], m_texFlip ? 1.0f - t0[1] : t0[1])); - } - if (m_options & QGL::NativeIndices) - currentSection()->appendSmooth(tri.logicalVertexAt(cur++), a); - } - } - } - if (m_options & QGL::NativeIndices) - currentNode()->setCount(cur); - else - addTriangles(tri); - if (keyCount > 0) - newSection(QGL::Smooth); - else - break; - } - if (key == 0) - key = 1; - else - key <<= 1; - } -} diff --git a/src/plugins/sceneformats/3ds/qgl3dsmesh.h b/src/plugins/sceneformats/3ds/qgl3dsmesh.h deleted file mode 100644 index 48ddcdb04..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsmesh.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGL3DSMESH_H -#define QGL3DSMESH_H - -#include "qglbuilder.h" -#include "qgl3dsscenehandler.h" - -#include <lib3ds/types.h> -#include <lib3ds/mesh.h> - -class QGLMaterialCollection; -class QGL3dsLoader; -class Lib3dsMesh; -class ModulateRecord; - -class QGL3dsMesh : public QGLBuilder -{ -public: - explicit QGL3dsMesh(Lib3dsMesh *mesh, QGLMaterialCollection *materials); - virtual ~QGL3dsMesh(); - void initialize(); - void setOptions(QGL::ModelOptions options) { m_options = options; } - bool hasTexture() { return m_hasTextures; } - - typedef Lib3dsFace *FacePtr; - -protected: - void analyzeMesh(); - void modulateMesh(); - void checkTextures(int); - QMatrix4x4 meshMatrix() const; - void generateVertices(); - -private: - void processNodeForMaterial(int matIx, QGLSceneNode *node); - QArray<int> mapFacesToVerts(Lib3dsDword *allKeys); - void addToAdjacencyMap(Lib3dsFace *face, Lib3dsFace *nbr); - void buildAdjacencyMap(const QArray<int> &vlist); - int cachedMaterialLookup(const char *material); - void findCommonNormal(ModulateRecord *mod) const; - void initAdjacencyMap(); - - Lib3dsMesh *m_mesh; - bool m_hasTextures; - Lib3dsDword m_smoothingGroups; - int m_smoothingGroupCount; - QSet<int> m_plainMaterials; - QSet<int> m_textureMaterials; - bool m_texFlip; - bool m_hasZeroSmoothing; - FacePtr *m_faceMap; - QGL::ModelOptions m_options; -}; - -#endif // QGL3DSMESH_H diff --git a/src/plugins/sceneformats/3ds/qgl3dsscene.cpp b/src/plugins/sceneformats/3ds/qgl3dsscene.cpp deleted file mode 100644 index f8aeaa8a5..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsscene.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgl3dsscene.h" - -#include "qglscenenode.h" -#include "qgl3dsmesh.h" -#include "qgl3dsloader.h" - -#include <lib3ds/file.h> - -QT_BEGIN_NAMESPACE - -/*! - \internal - \class QGL3dsScene - \brief The QGL3dsScene class manages and contains a 3ds scene. - The scene consists of a QGLSceneNode object which is the top-level node - and references the geometry in a 3D Studio Max ".3ds" file. That top - level node references sub-nodes -*/ - -/*! - \internal - Construct a new QGL3dsScene object using the data in the \a file, - and setting the given \a parent. Resources are searched for at the - given \a url. - - The QGL3dsScene object takes ownership of the \a file. -*/ -QGL3dsScene::QGL3dsScene(Lib3dsFile *file, QGL3dsSceneHandler *h) - : QGLAbstractScene(0) - , mFile(file) -{ - Q_ASSERT(h); - Q_ASSERT(file); - QGL3dsLoader loader(file, h); - mRootNode = loader.loadMeshes(); -} - -/*! - \internal - \reimp - Destroy this QGL3dsScene, recovering all resources. - - This method destroys the Lib3dsFile object the scene is based - on by calling the appropriate lib3ds function. -*/ -QGL3dsScene::~QGL3dsScene() -{ - lib3ds_file_free(mFile); -} - -/*! - \internal - \reimp -*/ -QList<QObject *> QGL3dsScene::objects() const -{ - QList<QObject *> objs; - if (!mRootNode) - return objs; - objs.append(mRootNode); - QList<QGLSceneNode*> children = mRootNode->allChildren(); - QList<QGLSceneNode*>::const_iterator it = children.constBegin(); - for ( ; it != children.constEnd(); ++it) - objs.append(*it); - return objs; -} - -/*! - \internal - \reimp -*/ -QGLSceneNode *QGL3dsScene::mainNode() const -{ - return mRootNode; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sceneformats/3ds/qgl3dsscene.h b/src/plugins/sceneformats/3ds/qgl3dsscene.h deleted file mode 100644 index 455991806..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsscene.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGL3DSSCENE_H -#define QGL3DSSCENE_H - -#include "qglabstractscene.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt3D) - -#include <QtCore/qurl.h> - -class QGLSceneNode; -class QGLSceneNode; -class QGL3dsSceneHandler; -class Lib3dsFile; - -class QGL3dsScene : public QGLAbstractScene -{ - Q_OBJECT -public: - explicit QGL3dsScene(Lib3dsFile *file, QGL3dsSceneHandler *h); - virtual ~QGL3dsScene(); - - QList<QObject *> objects() const; - QGLSceneNode *mainNode() const; - - QUrl url() const { return mUrl; } - -private: - Lib3dsFile *mFile; - QUrl mUrl; - QGLSceneNode *mRootNode; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/plugins/sceneformats/3ds/qgl3dsscenehandler.cpp b/src/plugins/sceneformats/3ds/qgl3dsscenehandler.cpp deleted file mode 100644 index 2ca9d430f..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsscenehandler.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgl3dsscenehandler.h" -#include "qgl3dsscene.h" - -#include <lib3ds/file.h> -#include <lib3ds/io.h> -#include <lib3ds/mesh.h> -#include <lib3ds/node.h> - -#include <QtCore/qdir.h> -#include <QtCore/qdebug.h> - -QT_BEGIN_NAMESPACE - -struct IODevice3ds -{ - QIODevice *dev; - bool errorState; - -}; - -extern "C" { - static Lib3dsBool qgl3ds_fileio_error_func(void *self) - { - IODevice3ds *io3d = (IODevice3ds*)self; - return io3d->errorState; - } - - static long qgl3ds_fileio_seek_func(void *self, long offset, Lib3dsIoSeek origin) - { - IODevice3ds *io3d = (IODevice3ds*)self; - // cannot deal with sockets right now - Q_ASSERT(!io3d->dev->isSequential()); - switch (origin) - { - case LIB3DS_SEEK_SET: - io3d->errorState = io3d->dev->seek(offset); - break; - case LIB3DS_SEEK_CUR: - io3d->errorState = io3d->dev->seek(io3d->dev->pos() + offset); - break; - case LIB3DS_SEEK_END: - io3d->errorState = io3d->dev->seek(io3d->dev->size() + offset); - break; - default: - Q_ASSERT(0); - return(0); - } - if (io3d->errorState) - return -1; - return io3d->dev->pos(); - } - - static long qgl3ds_fileio_tell_func(void *self) - { - IODevice3ds *io3d = (IODevice3ds*)self; - return io3d->dev->pos(); - } - - static size_t qgl3ds_fileio_read_func(void *self, void *buffer, size_t size) - { - IODevice3ds *io3d = (IODevice3ds*)self; - qint64 result = io3d->dev->read((char*)buffer, size); - io3d->errorState = (result == -1); - if (io3d->errorState) - qWarning("3ds io error: %s\n", io3d->dev->errorString().toLocal8Bit().constData()); - return result; - } - - static size_t qgl3ds_fileio_write_func(void *self, const void *buffer, size_t size) - { - IODevice3ds *io3d = (IODevice3ds*)self; - qint64 result = io3d->dev->write((char*)buffer, size); - io3d->errorState = (result == -1); - if (io3d->errorState) - qWarning("3ds io error: %s\n", io3d->dev->errorString().toLocal8Bit().constData()); - return result; - } -} - -static Lib3dsFile *qgl3ds_lib3ds_file_load(QIODevice *iod) -{ - Lib3dsFile *file; - Lib3dsIo *io; - Q_ASSERT(iod->isOpen() && iod->isReadable()); - file = lib3ds_file_new(); - if (!file) { - iod->close(); - return(0); - } - IODevice3ds io3d; - io3d.dev = iod; - io3d.errorState = false; - io = lib3ds_io_new( - &io3d, - qgl3ds_fileio_error_func, - qgl3ds_fileio_seek_func, - qgl3ds_fileio_tell_func, - qgl3ds_fileio_read_func, - qgl3ds_fileio_write_func - ); - if (!io) { - lib3ds_file_free(file); - iod->close(); - return(0); - } - if (!lib3ds_file_read(file, io)) { - lib3ds_file_free(file); - iod->close(); - return(0); - } - lib3ds_io_free(io); - iod->close(); - return(file); -} - -QGL3dsSceneHandler::QGL3dsSceneHandler() - : m_options(0) -{ -} - -QGL3dsSceneHandler::~QGL3dsSceneHandler() -{ - // nothing to do -} - -void QGL3dsSceneHandler::decodeOptions(const QString &options) -{ - static const char *validOptions[] = { - "NativeIndices", - "CorrectNormals", - "CorrectAcute", - "ForceSmooth", - "ForceFaceted", - "ShowWarnings" - }; - static int optionKeys[] = { - QGL::NativeIndices, - QGL::CorrectNormals, - QGL::CorrectAcute, - QGL::ForceSmooth, - QGL::ForceFaceted, - QGL::ShowWarnings, - -1 - }; - - // format: "mesh=option mesh=option option option" - // mesh: string name of a mesh in the file, with no spaces - // standalone option applies to the whole file - all meshes - // option: NativeIndices | CorrectNormals | CorrectAcute etc - QStringList opList = options.split(QLatin1Char(' '), QString::SkipEmptyParts); - for (int i = 0; i < opList.count(); ++i) - { - QString op = opList.at(i); - QString mdl; - if (op.contains(QLatin1Char('='))) - { - QStringList sl = op.split(QLatin1Char('='), QString::SkipEmptyParts); - mdl = sl[0]; - op = sl[1]; - } - int k = 0; - for ( ; optionKeys[k] != -1; ++k) - if (op == QLatin1String(validOptions[k])) - break; - if (optionKeys[k] != -1) // found - { - QGL::ModelOptions o = static_cast<QGL::ModelOptions>(optionKeys[k]); - if (!mdl.isEmpty()) - setMeshOptions(o, mdl); - else - setOptions(o); - } - else - { - qWarning("Bad option: \"%s\" in %s", qPrintable(op), - qPrintable(options)); - } - } -} - -QGLAbstractScene *QGL3dsSceneHandler::read() -{ - Lib3dsFile *file = qgl3ds_lib3ds_file_load(device()); - Q_CHECK_PTR(file); // wtf? - - if (!file->nodes) - { - Lib3dsMesh *mesh; - Lib3dsNode *node; - for (mesh = file->meshes; mesh; mesh = mesh->next) - { - if (mesh->faces && mesh->points) - { - node = lib3ds_node_new_object(); - qstrcpy(node->name, mesh->name); - node->parent_id = LIB3DS_NO_PARENT; - lib3ds_file_insert_node(file, node); - } - } - } - - lib3ds_file_eval(file, 0.0f); - - QGL3dsScene *scene = new QGL3dsScene(file, this); - return scene; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sceneformats/3ds/qgl3dsscenehandler.h b/src/plugins/sceneformats/3ds/qgl3dsscenehandler.h deleted file mode 100644 index 3c6dd9920..000000000 --- a/src/plugins/sceneformats/3ds/qgl3dsscenehandler.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGL3DSSCENEHANDLER_H -#define QGL3DSSCENEHANDLER_H - -#include "qglsceneformatplugin.h" -#include <QtCore/qmap.h> -#include <QtCore/qdebug.h> - -QT_BEGIN_NAMESPACE - -namespace QGL { - enum ModelOption - { - NativeIndices = 0x01, - CorrectNormals = 0x02, - CorrectAcute = 0x04, - ForceSmooth = 0x08, - ForceFaceted = 0x10, - ShowWarnings = 0x20 - }; - Q_DECLARE_FLAGS(ModelOptions, ModelOption); - - typedef QMap<QString, QGL::ModelOptions> MeshOptionMap; -}; - -class QGL3dsSceneHandler : public QGLSceneFormatHandler -{ -public: - QGL3dsSceneHandler(); - ~QGL3dsSceneHandler(); - - QGLAbstractScene *read(); - - void setOptions(QGL::ModelOptions options) { m_options |= options; } - QGL::ModelOptions options() const { return m_options; } - - void setMeshOptions(QGL::ModelOptions options, const QString &meshName) - { - m_meshOptions[meshName] |= options; - } - QGL::ModelOptions meshOptions(const QString &meshName) const - { - if (m_meshOptions.contains(meshName)) - return m_meshOptions.value(meshName); - return 0; - } - QGL::MeshOptionMap meshOptions() const { return m_meshOptions; } - void decodeOptions(const QString &options); - -private: - QGL::ModelOptions m_options; - QGL::MeshOptionMap m_meshOptions; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QGL::ModelOptions); - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/sceneformats/sceneformats.pro b/src/plugins/sceneformats/sceneformats.pro index 97ec09a6f..dd44a5dff 100644 --- a/src/plugins/sceneformats/sceneformats.pro +++ b/src/plugins/sceneformats/sceneformats.pro @@ -1,7 +1,7 @@ TEMPLATE = subdirs old_importer { - SUBDIRS = bezier 3ds obj + SUBDIRS = bezier obj } else { SUBDIRS = bezier assimp } |