mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 15:09:34 +02:00
Merge pull request #10983 from davidkelly/dk/marketplaceIDHack
Get marketplaceID into imported entities
This commit is contained in:
commit
4d4d9421d3
2 changed files with 62 additions and 12 deletions
|
@ -29,8 +29,12 @@
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
|
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
#include <Gzip.h>
|
#include <Gzip.h>
|
||||||
|
@ -1667,7 +1671,28 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) {
|
||||||
return readJSONFromStream(-1, jsonStream);
|
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-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-v[\\d]+\\/.*");
|
||||||
|
QRegularExpressionMatch match = re.match(urlString);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
QString matched = match.captured(1);
|
||||||
|
if (QUuid(matched).isNull()) {
|
||||||
|
qDebug() << "invalid uuid for marketplaceID";
|
||||||
|
} else {
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
bool Octree::readFromURL(const QString& urlString) {
|
bool Octree::readFromURL(const QString& urlString) {
|
||||||
|
QString marketplaceID = getMarketplaceID(urlString);
|
||||||
auto request =
|
auto request =
|
||||||
std::unique_ptr<ResourceRequest>(DependencyManager::get<ResourceManager>()->createResourceRequest(this, urlString));
|
std::unique_ptr<ResourceRequest>(DependencyManager::get<ResourceManager>()->createResourceRequest(this, urlString));
|
||||||
|
|
||||||
|
@ -1686,11 +1711,11 @@ bool Octree::readFromURL(const QString& urlString) {
|
||||||
|
|
||||||
auto data = request->getData();
|
auto data = request->getData();
|
||||||
QDataStream inputStream(data);
|
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
|
// decide if this is binary SVO or JSON-formatted SVO
|
||||||
QIODevice *device = inputStream.device();
|
QIODevice *device = inputStream.device();
|
||||||
char firstChar;
|
char firstChar;
|
||||||
|
@ -1702,7 +1727,7 @@ bool Octree::readFromStream(unsigned long streamLength, QDataStream& inputStream
|
||||||
return readSVOFromStream(streamLength, inputStream);
|
return readSVOFromStream(streamLength, inputStream);
|
||||||
} else {
|
} else {
|
||||||
qCDebug(octree) << "Reading from JSON SVO Stream length:" << streamLength;
|
qCDebug(octree) << "Reading from JSON SVO Stream length:" << streamLength;
|
||||||
return readJSONFromStream(streamLength, inputStream);
|
return readJSONFromStream(streamLength, inputStream, marketplaceID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1838,9 +1863,31 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
|
||||||
return fileOk;
|
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;
|
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
|
// 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.
|
// we get an eof. Leave streamLength parameter for consistency.
|
||||||
|
|
||||||
|
@ -1860,6 +1907,9 @@ bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputSt
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
QJsonDocument asDocument = QJsonDocument::fromJson(jsonBuffer);
|
||||||
|
if (!marketplaceID.isEmpty()) {
|
||||||
|
asDocument = addMarketplaceIDToDocumentEntities(asDocument, marketplaceID);
|
||||||
|
}
|
||||||
QVariant asVariant = asDocument.toVariant();
|
QVariant asVariant = asDocument.toVariant();
|
||||||
QVariantMap asMap = asVariant.toMap();
|
QVariantMap asMap = asVariant.toMap();
|
||||||
bool success = readFromMap(asMap);
|
bool success = readFromMap(asMap);
|
||||||
|
|
|
@ -212,14 +212,14 @@ public:
|
||||||
virtual bool handlesEditPacketType(PacketType packetType) const { return false; }
|
virtual bool handlesEditPacketType(PacketType packetType) const { return false; }
|
||||||
virtual int processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
virtual int processEditPacketData(ReceivedMessage& message, const unsigned char* editData, int maxLength,
|
||||||
const SharedNodePointer& sourceNode) { return 0; }
|
const SharedNodePointer& sourceNode) { return 0; }
|
||||||
|
|
||||||
virtual bool recurseChildrenWithData() const { return true; }
|
virtual bool recurseChildrenWithData() const { return true; }
|
||||||
virtual bool rootElementHasData() const { return false; }
|
virtual bool rootElementHasData() const { return false; }
|
||||||
virtual int minimumRequiredRootDataBytes() const { return 0; }
|
virtual int minimumRequiredRootDataBytes() const { return 0; }
|
||||||
virtual bool suppressEmptySubtrees() const { return true; }
|
virtual bool suppressEmptySubtrees() const { return true; }
|
||||||
virtual void releaseSceneEncodeData(OctreeElementExtraEncodeData* extraEncodeData) const { }
|
virtual void releaseSceneEncodeData(OctreeElementExtraEncodeData* extraEncodeData) const { }
|
||||||
virtual bool mustIncludeAllChildData() const { return true; }
|
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
|
/// 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
|
/// file. If the Octree subclass expects this for this particular version of the file, it should override this
|
||||||
/// method and return true.
|
/// method and return true.
|
||||||
|
@ -236,15 +236,15 @@ public:
|
||||||
void reaverageOctreeElements(OctreeElementPointer startElement = OctreeElementPointer());
|
void reaverageOctreeElements(OctreeElementPointer startElement = OctreeElementPointer());
|
||||||
|
|
||||||
void deleteOctreeElementAt(float x, float y, float z, float s);
|
void deleteOctreeElementAt(float x, float y, float z, float s);
|
||||||
|
|
||||||
/// Find the voxel at position x,y,z,s
|
/// Find the voxel at position x,y,z,s
|
||||||
/// \return pointer to the OctreeElement or NULL if none at 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;
|
OctreeElementPointer getOctreeElementAt(float x, float y, float z, float s) const;
|
||||||
|
|
||||||
/// Find the voxel at position x,y,z,s
|
/// 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.
|
/// \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 getOctreeEnclosingElementAt(float x, float y, float z, float s) const;
|
||||||
|
|
||||||
OctreeElementPointer getOrCreateChildElementAt(float x, float y, float z, float s);
|
OctreeElementPointer getOrCreateChildElementAt(float x, float y, float z, float s);
|
||||||
OctreeElementPointer getOrCreateChildElementContaining(const AACube& box);
|
OctreeElementPointer getOrCreateChildElementContaining(const AACube& box);
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ public:
|
||||||
|
|
||||||
int encodeTreeBitstream(const OctreeElementPointer& element, OctreePacketData* packetData, OctreeElementBag& bag,
|
int encodeTreeBitstream(const OctreeElementPointer& element, OctreePacketData* packetData, OctreeElementBag& bag,
|
||||||
EncodeBitstreamParams& params) ;
|
EncodeBitstreamParams& params) ;
|
||||||
|
|
||||||
bool isDirty() const { return _isDirty; }
|
bool isDirty() const { return _isDirty; }
|
||||||
void clearDirtyBit() { _isDirty = false; }
|
void clearDirtyBit() { _isDirty = false; }
|
||||||
void setDirtyBit() { _isDirty = true; }
|
void setDirtyBit() { _isDirty = true; }
|
||||||
|
@ -301,9 +301,9 @@ public:
|
||||||
// Octree importers
|
// Octree importers
|
||||||
bool readFromFile(const char* filename);
|
bool readFromFile(const char* filename);
|
||||||
bool readFromURL(const QString& url); // will support file urls as well...
|
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 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);
|
bool readJSONFromGzippedFile(QString qFileName);
|
||||||
virtual bool readFromMap(QVariantMap& entityDescription) = 0;
|
virtual bool readFromMap(QVariantMap& entityDescription) = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue