|
KGLLib
|
00001 /* 00002 * Copyright 2008 Rivo Laks <rivolaks@hot.ee> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef KGLLIB_MODELLOADER_H 00019 #define KGLLIB_MODELLOADER_H 00020 00021 #include "kgllib.h" 00022 00023 #include <Eigen/Core> 00024 00025 #include <QtCore/QList> 00026 00027 class QString; 00028 00029 00030 namespace KGLLib 00031 { 00032 class Batch; 00033 class Mesh; 00034 00035 class KGLLIB_EXTRAS_EXPORT ModelLoader 00036 { 00037 public: 00038 ModelLoader(); 00039 ModelLoader(const QString& filename); 00040 virtual ~ModelLoader(); 00041 00042 virtual bool load(const QString& filename); 00043 00044 bool isValid() const { return mValid; } 00045 00046 KGLLib::Batch* createBatch(); 00047 KGLLib::Mesh* createMesh(); 00048 // TODO: rename 00049 void loadIntoBatch(KGLLib::Batch* b); 00050 00051 void centerModel(); 00052 void recalcNormals(); 00053 void scaleModel(float scale); 00054 void translateModel(const Eigen::Vector3f& trans); 00055 00056 int vertexCount() const; 00057 int indexCount() const; 00058 00059 protected: 00060 bool loadFromObj(const QString& filename); 00061 00062 struct FaceVertex; 00063 friend uint qHash(const FaceVertex& v); 00064 void createDuplicateVertices(); 00065 00066 private: 00067 bool mValid; 00068 00069 QList<Eigen::Vector3f> mVertices; 00070 QList<Eigen::Vector3f> mNormals; 00071 QList<Eigen::Vector2f> mTexcoords; 00072 QList<unsigned int> mIndices; 00073 00074 QList<FaceVertex> mFaceVertices; 00075 }; 00076 00077 } 00078 00079 #endif
1.7.4