mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 19:13:38 +02:00
Implement hfm::Format/hfm::Factory for model serializers
This commit is contained in:
parent
d1ac501967
commit
74015a1a5e
6 changed files with 83 additions and 0 deletions
|
@ -1833,6 +1833,22 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
|
|||
return hfmModelPtr;
|
||||
}
|
||||
|
||||
void FBXFormat::registerFormat(hfm::FormatRegistry& registry) {
|
||||
MIMEType mimeType("fbx");
|
||||
mimeType.extensions.push_back("fbx");
|
||||
mimeType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0);
|
||||
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<FBXSerializer::Factory>());
|
||||
}
|
||||
|
||||
void FBXFormat::unregisterFormat(hfm::FormatRegistry& registry) {
|
||||
registry.unregisterMIMEType(mimeTypeID);
|
||||
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
}
|
||||
|
||||
std::shared_ptr<HFMSerializer> FBXSerializer::Factory::get() {
|
||||
return std::make_shared<FBXSerializer>();
|
||||
}
|
||||
|
||||
HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
QBuffer buffer(const_cast<QByteArray*>(&data));
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "FBX.h"
|
||||
#include <hfm/HFMSerializer.h>
|
||||
#include <hfm/HFMFormat.h>
|
||||
|
||||
#include <graphics/Geometry.h>
|
||||
#include <graphics/Material.h>
|
||||
|
@ -94,8 +95,20 @@ public:
|
|||
|
||||
class ExtractedMesh;
|
||||
|
||||
class FBXFormat : public hfm::Format {
|
||||
public:
|
||||
virtual void registerFormat(hfm::FormatRegistry& registry) override;
|
||||
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
|
||||
protected:
|
||||
hfm::FormatRegistry::MIMETypeID mimeTypeID { hfm::FormatRegistry::INVALID_MIME_TYPE_ID };
|
||||
};
|
||||
|
||||
class FBXSerializer : public HFMSerializer {
|
||||
public:
|
||||
class Factory : public HFMSerializer::Factory {
|
||||
std::shared_ptr<HFMSerializer> get() override;
|
||||
};
|
||||
|
||||
HFMModel* _hfmModel;
|
||||
/// Reads HFMModel from the supplied model and mapping data.
|
||||
/// \exception QString if an error occurs in parsing
|
||||
|
|
|
@ -910,6 +910,22 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLTFFormat::registerFormat(hfm::FormatRegistry& registry) {
|
||||
MIMEType mimeType("gltf");
|
||||
mimeType.extensions.push_back("gltf");
|
||||
mimeType.webMediaTypes.push_back("model/gltf+json");
|
||||
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<GLTFSerializer::Factory>());
|
||||
}
|
||||
|
||||
void GLTFFormat::unregisterFormat(hfm::FormatRegistry& registry) {
|
||||
registry.unregisterMIMEType(mimeTypeID);
|
||||
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
}
|
||||
|
||||
std::shared_ptr<HFMSerializer> GLTFSerializer::Factory::get() {
|
||||
return std::make_shared<GLTFSerializer>();
|
||||
}
|
||||
|
||||
HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
|
||||
_url = url;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QtNetwork/QNetworkReply>
|
||||
#include <hfm/ModelFormatLogging.h>
|
||||
#include <hfm/HFMSerializer.h>
|
||||
#include <hfm/HFMFormat.h>
|
||||
#include "FBXSerializer.h"
|
||||
|
||||
|
||||
|
@ -700,9 +701,20 @@ struct GLTFFile {
|
|||
}
|
||||
};
|
||||
|
||||
class GLTFFormat : public hfm::Format {
|
||||
public:
|
||||
virtual void registerFormat(hfm::FormatRegistry& registry) override;
|
||||
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
|
||||
protected:
|
||||
hfm::FormatRegistry::MIMETypeID mimeTypeID;
|
||||
};
|
||||
|
||||
class GLTFSerializer : public QObject, public HFMSerializer {
|
||||
Q_OBJECT
|
||||
public:
|
||||
class Factory : public HFMSerializer::Factory {
|
||||
std::shared_ptr<HFMSerializer> get() override;
|
||||
};
|
||||
GLTFSerializer();
|
||||
HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override;
|
||||
private:
|
||||
|
|
|
@ -651,6 +651,20 @@ done:
|
|||
return result;
|
||||
}
|
||||
|
||||
void OBJFormat::registerFormat(hfm::FormatRegistry& registry) {
|
||||
MIMEType mimeType("obj");
|
||||
mimeType.extensions.push_back("obj");
|
||||
mimeTypeID = registry.registerMIMEType(mimeType, std::make_shared<OBJSerializer::Factory>());
|
||||
}
|
||||
|
||||
void OBJFormat::unregisterFormat(hfm::FormatRegistry& registry) {
|
||||
registry.unregisterMIMEType(mimeTypeID);
|
||||
mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
}
|
||||
|
||||
std::shared_ptr<HFMSerializer> OBJSerializer::Factory::get() {
|
||||
return std::make_shared<OBJSerializer>();
|
||||
}
|
||||
|
||||
HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <hfm/HFMSerializer.h>
|
||||
#include <hfm/HFMFormat.h>
|
||||
#include "FBXSerializer.h"
|
||||
|
||||
class OBJTokenizer {
|
||||
|
@ -89,9 +90,20 @@ public:
|
|||
OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {}
|
||||
};
|
||||
|
||||
class OBJFormat : public hfm::Format {
|
||||
public:
|
||||
virtual void registerFormat(hfm::FormatRegistry& registry) override;
|
||||
virtual void unregisterFormat(hfm::FormatRegistry& registry) override;
|
||||
protected:
|
||||
hfm::FormatRegistry::MIMETypeID mimeTypeID;
|
||||
};
|
||||
|
||||
class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can make network requests.
|
||||
Q_OBJECT
|
||||
public:
|
||||
class Factory : public HFMSerializer::Factory {
|
||||
std::shared_ptr<HFMSerializer> get() override;
|
||||
};
|
||||
typedef QVector<OBJFace> FaceGroup;
|
||||
QVector<glm::vec3> vertices;
|
||||
QVector<glm::vec3> vertexColors;
|
||||
|
|
Loading…
Reference in a new issue