mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-19 14:03:20 +02:00
Get marketplaceID into imported entities
Rather than doing this on the backend, we can do it here at the time we import. Later we will have some support for getting an entities identity hash and querying the backend to get a marketplaceID for them as needed. However for now this is enough to get us moving forward.
This commit is contained in:
parent
5a4f56388b
commit
061f084d9f
2 changed files with 64 additions and 12 deletions
|
@ -29,8 +29,12 @@
|
|||
#include <QVector>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
#include <Gzip.h>
|
||||
|
@ -1667,7 +1671,30 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) {
|
|||
return readJSONFromStream(-1, jsonStream);
|
||||
}
|
||||
|
||||
// hack to get the marketplace id into the entities. We will create a way to get this from a hash of
|
||||
// the entity later, but this helps us move things along for now
|
||||
QString getMarketplaceID(const QString& urlString) {
|
||||
// the url should be http://mpassets.highfidelity.com/<uuid>-v1/<item name>.extension
|
||||
// a regex for the this is a PITA as there are several valid versions of uuids, and so
|
||||
// lets strip out the uuid (if any) and try to create a UUID from the string, relying on
|
||||
// QT to parse it
|
||||
static const QRegularExpression re("^http:\\/\\/mpassets.highfidelity.com\\/([0-9A-Fa-f\\-]+)v[\\d]+\\/.*");
|
||||
QRegularExpressionMatch match = re.match(urlString);
|
||||
if (match.hasMatch()) {
|
||||
QString matched = match.captured(1);
|
||||
// strip the hyphen off the end because my regex is crap
|
||||
matched.truncate(matched.size()-1);
|
||||
if (QUuid() == QUuid(matched)) {
|
||||
qDebug() << "invalid uuid for marketplaceID";
|
||||
} else {
|
||||
return matched;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool Octree::readFromURL(const QString& urlString) {
|
||||
QString marketplaceID = getMarketplaceID(urlString);
|
||||
auto request =
|
||||
std::unique_ptr<ResourceRequest>(DependencyManager::get<ResourceManager>()->createResourceRequest(this, urlString));
|
||||
|
||||
|
@ -1686,11 +1713,11 @@ bool Octree::readFromURL(const QString& urlString) {
|
|||
|
||||
auto data = request->getData();
|
||||
QDataStream inputStream(data);
|
||||
return readFromStream(data.size(), inputStream);
|
||||
return readFromStream(data.size(), inputStream, marketplaceID);
|
||||
}
|
||||
|
||||
|
||||
bool Octree::readFromStream(unsigned long streamLength, QDataStream& inputStream) {
|
||||
bool Octree::readFromStream(unsigned long streamLength, QDataStream& inputStream, const QString& marketplaceID) {
|
||||
// decide if this is binary SVO or JSON-formatted SVO
|
||||
QIODevice *device = inputStream.device();
|
||||
char firstChar;
|
||||
|
@ -1702,7 +1729,7 @@ bool Octree::readFromStream(unsigned long streamLength, QDataStream& inputStream
|
|||
return readSVOFromStream(streamLength, inputStream);
|
||||
} else {
|
||||
qCDebug(octree) << "Reading from JSON SVO Stream length:" << streamLength;
|
||||
return readJSONFromStream(streamLength, inputStream);
|
||||
return readJSONFromStream(streamLength, inputStream, marketplaceID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1838,9 +1865,31 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
|
|||
return fileOk;
|
||||
}
|
||||
|
||||
// hack to get the marketplace id into the entities. We will create a way to get this from a hash of
|
||||
// the entity later, but this helps us move things along for now
|
||||
QJsonDocument addMarketplaceIDToDocumentEntities(QJsonDocument& doc, const QString& marketplaceID) {
|
||||
if (!marketplaceID.isEmpty()) {
|
||||
QJsonDocument newDoc;
|
||||
QJsonObject rootObj = doc.object();
|
||||
QJsonArray newEntitiesArray;
|
||||
|
||||
// build a new entities array
|
||||
auto entitiesArray = rootObj["Entities"].toArray();
|
||||
for(auto it = entitiesArray.begin(); it != entitiesArray.end(); it++) {
|
||||
auto entity = (*it).toObject();
|
||||
entity["marketplaceID"] = marketplaceID;
|
||||
newEntitiesArray.append(entity);
|
||||
}
|
||||
rootObj["Entities"] = newEntitiesArray;
|
||||
newDoc.setObject(rootObj);
|
||||
return newDoc;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
const int READ_JSON_BUFFER_SIZE = 2048;
|
||||
|
||||
bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputStream) {
|
||||
bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputStream, const QString& marketplaceID /*=""*/) {
|
||||
// if the data is gzipped we may not have a useful bytesAvailable() result, so just keep reading until
|
||||
// we get an eof. Leave streamLength parameter for consistency.
|
||||
|
||||
|
@ -1860,6 +1909,9 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt
|
|||
}
|
||||
|
||||
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
||||
if (!marketplaceID.isEmpty()) {
|
||||
asDocument = addMarketplaceIDToDocumentEntities(asDocument, marketplaceID);
|
||||
}
|
||||
QVariant asVariant = asDocument.toVariant();
|
||||
QVariantMap asMap = asVariant.toMap();
|
||||
bool success = readFromMap(asMap);
|
||||
|
|
|
@ -212,14 +212,14 @@ public:
|
|||
virtual bool handlesEditPacketType(PacketType packetType) const { return false; }
|
||||
virtual int processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
||||
const SharedNodePointer& sourceNode) { return 0; }
|
||||
|
||||
|
||||
virtual bool recurseChildrenWithData() const { return true; }
|
||||
virtual bool rootElementHasData() const { return false; }
|
||||
virtual int minimumRequiredRootDataBytes() const { return 0; }
|
||||
virtual bool suppressEmptySubtrees() const { return true; }
|
||||
virtual void releaseSceneEncodeData(OctreeElementExtraEncodeData* extraEncodeData) const { }
|
||||
virtual bool mustIncludeAllChildData() const { return true; }
|
||||
|
||||
|
||||
/// some versions of the SVO file will include breaks with buffer lengths between each buffer chunk in the SVO
|
||||
/// file. If the Octree subclass expects this for this particular version of the file, it should override this
|
||||
/// method and return true.
|
||||
|
@ -236,15 +236,15 @@ public:
|
|||
void reaverageOctreeElements(OctreeElementPointer startElement = OctreeElementPointer());
|
||||
|
||||
void deleteOctreeElementAt(float x, float y, float z, float s);
|
||||
|
||||
|
||||
/// Find the voxel at position x,y,z,s
|
||||
/// \return pointer to the OctreeElement or NULL if none at x,y,z,s.
|
||||
OctreeElementPointer getOctreeElementAt(float x, float y, float z, float s) const;
|
||||
|
||||
|
||||
/// Find the voxel at position x,y,z,s
|
||||
/// \return pointer to the OctreeElement or to the smallest enclosing parent if none at x,y,z,s.
|
||||
OctreeElementPointer getOctreeEnclosingElementAt(float x, float y, float z, float s) const;
|
||||
|
||||
|
||||
OctreeElementPointer getOrCreateChildElementAt(float x, float y, float z, float s);
|
||||
OctreeElementPointer getOrCreateChildElementContaining(const AACube& box);
|
||||
|
||||
|
@ -261,7 +261,7 @@ public:
|
|||
|
||||
int encodeTreeBitstream(const OctreeElementPointer& element, OctreePacketData* packetData, OctreeElementBag& bag,
|
||||
EncodeBitstreamParams& params) ;
|
||||
|
||||
|
||||
bool isDirty() const { return _isDirty; }
|
||||
void clearDirtyBit() { _isDirty = false; }
|
||||
void setDirtyBit() { _isDirty = true; }
|
||||
|
@ -301,9 +301,9 @@ public:
|
|||
// Octree importers
|
||||
bool readFromFile(const char* filename);
|
||||
bool readFromURL(const QString& url); // will support file urls as well...
|
||||
bool readFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
bool readFromStream(unsigned long streamLength, QDataStream& inputStream, const QString& marketplaceID="");
|
||||
bool readSVOFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
bool readJSONFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
bool readJSONFromStream(unsigned long streamLength, QDataStream& inputStream, const QString& marketplaceID="");
|
||||
bool readJSONFromGzippedFile(QString qFileName);
|
||||
virtual bool readFromMap(QVariantMap& entityDescription) = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue