mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-17 13:08:46 +02:00
Merge pull request #14878 from raveenajain/glb_files
Case 20966: glb files
This commit is contained in:
commit
51e7c6a83b
2 changed files with 63 additions and 5 deletions
|
@ -124,6 +124,31 @@ bool GLTFSerializer::getObjectArrayVal(const QJsonObject& object, const QString&
|
||||||
return _defined;
|
return _defined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray GLTFSerializer::setGLBChunks(const QByteArray& data) {
|
||||||
|
int byte = 4;
|
||||||
|
int jsonStart = data.indexOf("JSON", Qt::CaseSensitive);
|
||||||
|
int binStart = data.indexOf("BIN", Qt::CaseSensitive);
|
||||||
|
int jsonLength, binLength;
|
||||||
|
QByteArray jsonLengthChunk, binLengthChunk;
|
||||||
|
|
||||||
|
jsonLengthChunk = data.mid(jsonStart - byte, byte);
|
||||||
|
QDataStream tempJsonLen(jsonLengthChunk);
|
||||||
|
tempJsonLen.setByteOrder(QDataStream::LittleEndian);
|
||||||
|
tempJsonLen >> jsonLength;
|
||||||
|
QByteArray jsonChunk = data.mid(jsonStart + byte, jsonLength);
|
||||||
|
|
||||||
|
if (binStart != -1) {
|
||||||
|
binLengthChunk = data.mid(binStart - byte, byte);
|
||||||
|
|
||||||
|
QDataStream tempBinLen(binLengthChunk);
|
||||||
|
tempBinLen.setByteOrder(QDataStream::LittleEndian);
|
||||||
|
tempBinLen >> binLength;
|
||||||
|
|
||||||
|
_glbBinary = data.mid(binStart + byte, binLength);
|
||||||
|
}
|
||||||
|
return jsonChunk;
|
||||||
|
}
|
||||||
|
|
||||||
int GLTFSerializer::getMeshPrimitiveRenderingMode(const QString& type)
|
int GLTFSerializer::getMeshPrimitiveRenderingMode(const QString& type)
|
||||||
{
|
{
|
||||||
if (type == "POINTS") {
|
if (type == "POINTS") {
|
||||||
|
@ -309,6 +334,14 @@ bool GLTFSerializer::addBuffer(const QJsonObject& object) {
|
||||||
GLTFBuffer buffer;
|
GLTFBuffer buffer;
|
||||||
|
|
||||||
getIntVal(object, "byteLength", buffer.byteLength, buffer.defined);
|
getIntVal(object, "byteLength", buffer.byteLength, buffer.defined);
|
||||||
|
|
||||||
|
if (_url.toString().endsWith("glb")) {
|
||||||
|
if (!_glbBinary.isEmpty()) {
|
||||||
|
buffer.blob = _glbBinary;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (getStringVal(object, "uri", buffer.uri, buffer.defined)) {
|
if (getStringVal(object, "uri", buffer.uri, buffer.defined)) {
|
||||||
if (!readBinary(buffer.uri, buffer.blob)) {
|
if (!readBinary(buffer.uri, buffer.blob)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -536,8 +569,15 @@ bool GLTFSerializer::addTexture(const QJsonObject& object) {
|
||||||
bool GLTFSerializer::parseGLTF(const QByteArray& data) {
|
bool GLTFSerializer::parseGLTF(const QByteArray& data) {
|
||||||
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
||||||
|
|
||||||
QJsonDocument d = QJsonDocument::fromJson(data);
|
QByteArray jsonChunk = data;
|
||||||
|
|
||||||
|
if (_url.toString().endsWith("glb") && data.indexOf("glTF") == 0 && data.contains("JSON")) {
|
||||||
|
jsonChunk = setGLBChunks(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument d = QJsonDocument::fromJson(jsonChunk);
|
||||||
QJsonObject jsFile = d.object();
|
QJsonObject jsFile = d.object();
|
||||||
|
|
||||||
bool success = setAsset(jsFile);
|
bool success = setAsset(jsFile);
|
||||||
if (success) {
|
if (success) {
|
||||||
QJsonArray accessors;
|
QJsonArray accessors;
|
||||||
|
@ -924,6 +964,10 @@ MediaType GLTFSerializer::getMediaType() const {
|
||||||
MediaType mediaType("gltf");
|
MediaType mediaType("gltf");
|
||||||
mediaType.extensions.push_back("gltf");
|
mediaType.extensions.push_back("gltf");
|
||||||
mediaType.webMediaTypes.push_back("model/gltf+json");
|
mediaType.webMediaTypes.push_back("model/gltf+json");
|
||||||
|
|
||||||
|
mediaType.extensions.push_back("glb");
|
||||||
|
mediaType.webMediaTypes.push_back("model/gltf-binary");
|
||||||
|
|
||||||
return mediaType;
|
return mediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,6 +1086,17 @@ HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) {
|
||||||
fbxtex.name = fname;
|
fbxtex.name = fname;
|
||||||
fbxtex.filename = textureUrl.toEncoded();
|
fbxtex.filename = textureUrl.toEncoded();
|
||||||
|
|
||||||
|
if (_url.toString().endsWith("glb") && !_glbBinary.isEmpty()) {
|
||||||
|
int bufferView = _file.images[texture.source].bufferView;
|
||||||
|
|
||||||
|
GLTFBufferView& imagesBufferview = _file.bufferviews[bufferView];
|
||||||
|
int offset = imagesBufferview.byteOffset;
|
||||||
|
int length = imagesBufferview.byteLength;
|
||||||
|
|
||||||
|
fbxtex.content = _glbBinary.mid(offset, length);
|
||||||
|
fbxtex.filename = textureUrl.toEncoded().append(texture.source);
|
||||||
|
}
|
||||||
|
|
||||||
if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,")) {
|
if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,")) {
|
||||||
fbxtex.content = requestEmbeddedData(url);
|
fbxtex.content = requestEmbeddedData(url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -709,6 +709,7 @@ public:
|
||||||
private:
|
private:
|
||||||
GLTFFile _file;
|
GLTFFile _file;
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
|
QByteArray _glbBinary;
|
||||||
|
|
||||||
glm::mat4 getModelTransform(const GLTFNode& node);
|
glm::mat4 getModelTransform(const GLTFNode& node);
|
||||||
|
|
||||||
|
@ -732,6 +733,8 @@ private:
|
||||||
bool getObjectArrayVal(const QJsonObject& object, const QString& fieldname,
|
bool getObjectArrayVal(const QJsonObject& object, const QString& fieldname,
|
||||||
QJsonArray& objects, QMap<QString, bool>& defined);
|
QJsonArray& objects, QMap<QString, bool>& defined);
|
||||||
|
|
||||||
|
QByteArray setGLBChunks(const QByteArray& data);
|
||||||
|
|
||||||
int getMaterialAlphaMode(const QString& type);
|
int getMaterialAlphaMode(const QString& type);
|
||||||
int getAccessorType(const QString& type);
|
int getAccessorType(const QString& type);
|
||||||
int getAnimationSamplerInterpolation(const QString& interpolation);
|
int getAnimationSamplerInterpolation(const QString& interpolation);
|
||||||
|
|
Loading…
Reference in a new issue