git-svn-id: svn://db.shs.com.ru/libs@626 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
67
qglengine/formats/loader_qgl.cpp
Normal file
67
qglengine/formats/loader_qgl.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
QGLView
|
||||
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
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 3 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "loader_qgl.h"
|
||||
#include "glscene.h"
|
||||
#include <chunkstream.h>
|
||||
|
||||
|
||||
Scene * loadFromQGLFile(const QString & filepath) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader QGL] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&f);
|
||||
s.setVersion(QDataStream::Qt_5_0);
|
||||
char sign[4];
|
||||
s.readRawData(sign, 4);
|
||||
if ((sign[0] != 'Q') || (sign[1] != 'G') || (sign[2] != 'L') || (sign[3] != 'E')) {
|
||||
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" is not valid QGLEngine file!";
|
||||
return 0;
|
||||
}
|
||||
ushort version = 0x1;
|
||||
f.peek((char*)&version, 2);
|
||||
if (version != 1) {
|
||||
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" unsupported version!";
|
||||
return 0;
|
||||
}
|
||||
Scene * ret = 0;
|
||||
s.skipRawData(2);
|
||||
s >> ret;
|
||||
//root->buildTransform();
|
||||
qDebug() << "[Loader QGL] Loaded" << ret->objectsCount(true) << "objects from" << filepath;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool saveToQGLFile(const QString & filepath, const Scene * scene) {
|
||||
QFile f(filepath);
|
||||
if (!f.open(QIODevice::ReadWrite))
|
||||
return false;
|
||||
f.resize(0);
|
||||
QDataStream s(&f);
|
||||
s.setVersion(QDataStream::Qt_5_0);
|
||||
char sign[4] = {'Q', 'G', 'L', 'E'};
|
||||
ushort version = 0x1;
|
||||
s.writeRawData(sign, 4);
|
||||
s.writeRawData((char*)&version, 2);
|
||||
s << scene;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user