mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Make HFMSerializer return a smart pointer to an HFMModel
This commit is contained in:
parent
5a9af5b2c3
commit
f971294d6d
14 changed files with 21 additions and 22 deletions
|
@ -109,7 +109,7 @@ bool ModelPackager::loadModel() {
|
|||
qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath();
|
||||
QByteArray fbxContents = fbx.readAll();
|
||||
|
||||
_hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath()));
|
||||
_hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath());
|
||||
|
||||
// make sure we have some basic mappings
|
||||
populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel);
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
QString _scriptDir;
|
||||
|
||||
QVariantHash _mapping;
|
||||
std::unique_ptr<hfm::Model> _hfmModel;
|
||||
std::shared_ptr<hfm::Model> _hfmModel;
|
||||
QStringList _textures;
|
||||
QStringList _scripts;
|
||||
};
|
||||
|
|
|
@ -71,7 +71,7 @@ void AnimationReader::run() {
|
|||
// Parse the FBX directly from the QNetworkReply
|
||||
HFMModel::Pointer hfmModel;
|
||||
if (_url.path().toLower().endsWith(".fbx")) {
|
||||
hfmModel.reset(FBXSerializer().read(_data, QVariantHash(), _url.path()));
|
||||
hfmModel = FBXSerializer().read(_data, QVariantHash(), _url.path());
|
||||
} else {
|
||||
QString errorStr("usupported format");
|
||||
emit onError(299, errorStr);
|
||||
|
|
|
@ -1796,10 +1796,10 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
|
|||
return hfmModelPtr;
|
||||
}
|
||||
|
||||
HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
QBuffer buffer(const_cast<QByteArray*>(&data));
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
return read(&buffer, mapping, url);
|
||||
return HFMModel::Pointer(read(&buffer, mapping, url));
|
||||
}
|
||||
|
||||
HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url) {
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
HFMModel* _hfmModel;
|
||||
/// Reads HFMModel from the supplied model and mapping data.
|
||||
/// \exception QString if an error occurs in parsing
|
||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl());
|
||||
|
||||
FBXNode _rootNode;
|
||||
|
|
|
@ -910,7 +910,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
|||
return true;
|
||||
}
|
||||
|
||||
HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
|
||||
_url = url;
|
||||
|
||||
|
@ -923,7 +923,7 @@ HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mappi
|
|||
|
||||
parseGLTF(data);
|
||||
//_file.dump();
|
||||
HFMModel* hfmModelPtr = new HFMModel();
|
||||
auto hfmModelPtr = std::make_shared<HFMModel>();
|
||||
HFMModel& hfmModel = *hfmModelPtr;
|
||||
|
||||
buildGeometry(hfmModel, _url);
|
||||
|
|
|
@ -707,7 +707,7 @@ class GLTFSerializer : public QObject, public HFMSerializer {
|
|||
Q_OBJECT
|
||||
public:
|
||||
GLTFSerializer();
|
||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
private:
|
||||
GLTFFile _file;
|
||||
QUrl _url;
|
||||
|
|
|
@ -652,12 +652,12 @@ done:
|
|||
}
|
||||
|
||||
|
||||
HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
||||
QBuffer buffer { const_cast<QByteArray*>(&data) };
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
||||
auto hfmModelPtr = new HFMModel();
|
||||
auto hfmModelPtr = std::make_shared<HFMModel>();
|
||||
HFMModel& hfmModel { *hfmModelPtr };
|
||||
OBJTokenizer tokenizer { &buffer };
|
||||
float scaleGuess = 1.0f;
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
QString currentMaterialName;
|
||||
QHash<QString, OBJMaterial> materials;
|
||||
|
||||
HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
|
||||
private:
|
||||
QUrl _url;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
namespace hfm {
|
||||
|
||||
class Serializer {
|
||||
virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0;
|
||||
virtual Model::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -199,22 +199,22 @@ void GeometryReader::run() {
|
|||
serializerMapping["combineParts"] = _combineParts;
|
||||
|
||||
if (_url.path().toLower().endsWith(".fbx")) {
|
||||
hfmModel.reset(FBXSerializer().read(_data, serializerMapping, _url));
|
||||
hfmModel = FBXSerializer().read(_data, serializerMapping, _url);
|
||||
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
||||
throw QString("empty geometry, possibly due to an unsupported FBX version");
|
||||
}
|
||||
} else if (_url.path().toLower().endsWith(".obj")) {
|
||||
hfmModel.reset(OBJSerializer().read(_data, serializerMapping, _url));
|
||||
hfmModel = OBJSerializer().read(_data, serializerMapping, _url);
|
||||
} else if (_url.path().toLower().endsWith(".obj.gz")) {
|
||||
QByteArray uncompressedData;
|
||||
if (gunzip(_data, uncompressedData)){
|
||||
hfmModel.reset(OBJSerializer().read(uncompressedData, serializerMapping, _url));
|
||||
hfmModel = OBJSerializer().read(uncompressedData, serializerMapping, _url);
|
||||
} else {
|
||||
throw QString("failed to decompress .obj.gz");
|
||||
}
|
||||
|
||||
} else if (_url.path().toLower().endsWith(".gltf")) {
|
||||
hfmModel.reset(GLTFSerializer().read(_data, serializerMapping, _url));
|
||||
hfmModel = GLTFSerializer().read(_data, serializerMapping, _url);
|
||||
if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) {
|
||||
throw QString("empty geometry, possibly due to an unsupported GLTF version");
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ bool TestFbx::isReady() const {
|
|||
|
||||
void TestFbx::parseFbx(const QByteArray& fbxData) {
|
||||
QVariantHash mapping;
|
||||
HFMModel* hfmModel = FBXSerializer().read(fbxData, mapping);
|
||||
HFMModel::Pointer hfmModel = FBXSerializer().read(fbxData, mapping);
|
||||
size_t totalVertexCount = 0;
|
||||
size_t totalIndexCount = 0;
|
||||
size_t totalPartCount = 0;
|
||||
|
@ -163,7 +163,6 @@ void TestFbx::parseFbx(const QByteArray& fbxData) {
|
|||
_vertexBuffer->append(vertices);
|
||||
_indexBuffer->append(indices);
|
||||
_indirectBuffer->append(parts);
|
||||
delete hfmModel;
|
||||
}
|
||||
|
||||
void TestFbx::renderTest(size_t testId, RenderArgs* args) {
|
||||
|
|
|
@ -54,7 +54,7 @@ SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc
|
|||
return;
|
||||
}
|
||||
QByteArray blob = file.readAll();
|
||||
std::unique_ptr<HFMModel> geometry(FBXSerializer().read(blob, QVariantHash()));
|
||||
HFMModel::Pointer geometry = FBXSerializer().read(blob, QVariantHash());
|
||||
std::unique_ptr<AnimSkeleton> skeleton(new AnimSkeleton(*geometry));
|
||||
skeleton->dump(verbose);
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) {
|
|||
QByteArray fbxContents = fbx.readAll();
|
||||
HFMModel::Pointer hfmModel;
|
||||
if (filename.toLower().endsWith(".obj")) {
|
||||
hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename));
|
||||
hfmModel = OBJSerializer().read(fbxContents, QVariantHash(), filename);
|
||||
} else if (filename.toLower().endsWith(".fbx")) {
|
||||
hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename));
|
||||
hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), filename);
|
||||
} else {
|
||||
qWarning() << "file has unknown extension" << filename;
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue