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