mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-02 10:01:14 +02:00
Merge pull request #860 from overte-org/feature/gltf_webp
Added WebP support for binary glTF
This commit is contained in:
commit
bd14f39f66
1 changed files with 24 additions and 5 deletions
|
@ -1270,8 +1270,27 @@ HFMTexture GLTFSerializer::getHFMTexture(const cgltf_texture *texture) {
|
||||||
HFMTexture hfmTex = HFMTexture();
|
HFMTexture hfmTex = HFMTexture();
|
||||||
hfmTex.texcoordSet = 0;
|
hfmTex.texcoordSet = 0;
|
||||||
|
|
||||||
if (texture->image) {
|
auto image = texture->image;
|
||||||
QString url = texture->image->uri;
|
|
||||||
|
// Check for WebP extension
|
||||||
|
for (size_t i = 0; i < texture->extensions_count; i++) {
|
||||||
|
auto &extension = texture->extensions[i];
|
||||||
|
if (extension.name != nullptr
|
||||||
|
&& strcmp(extension.name, "EXT_texture_webp") == 0
|
||||||
|
&& extension.data != nullptr) {
|
||||||
|
QJsonDocument webPExtension = QJsonDocument::fromJson(extension.data);
|
||||||
|
if (!webPExtension.isNull() && webPExtension["source"].isDouble()) {
|
||||||
|
int imageIndex = webPExtension["source"].isDouble();
|
||||||
|
if (imageIndex > 0 && (size_t)imageIndex < _data->images_count) {
|
||||||
|
image = &_data->images[(int)(webPExtension["source"].toDouble())];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image) {
|
||||||
|
QString url = image->uri;
|
||||||
|
|
||||||
QString fileName = hifi::URL(url).fileName();
|
QString fileName = hifi::URL(url).fileName();
|
||||||
hifi::URL textureUrl = _url.resolved(url);
|
hifi::URL textureUrl = _url.resolved(url);
|
||||||
|
@ -1279,13 +1298,13 @@ HFMTexture GLTFSerializer::getHFMTexture(const cgltf_texture *texture) {
|
||||||
hfmTex.filename = textureUrl.toEncoded();
|
hfmTex.filename = textureUrl.toEncoded();
|
||||||
|
|
||||||
if (_url.path().endsWith("glb")) {
|
if (_url.path().endsWith("glb")) {
|
||||||
cgltf_buffer_view *bufferView = texture->image->buffer_view;
|
cgltf_buffer_view *bufferView = image->buffer_view;
|
||||||
|
|
||||||
size_t offset = bufferView->offset;
|
size_t offset = bufferView->offset;
|
||||||
size_t length = bufferView->size;
|
size_t length = bufferView->size;
|
||||||
|
|
||||||
size_t imageIndex = 0;
|
size_t imageIndex = 0;
|
||||||
if (!findPointerInArray(texture->image, _data->images, _data->images_count, imageIndex)) {
|
if (!findPointerInArray(image, _data->images, _data->images_count, imageIndex)) {
|
||||||
// This should never happen. It would mean a bug in cgltf library.
|
// This should never happen. It would mean a bug in cgltf library.
|
||||||
qDebug(modelformat) << "GLTFSerializer::getHFMTexture: can't find texture in the array";
|
qDebug(modelformat) << "GLTFSerializer::getHFMTexture: can't find texture in the array";
|
||||||
return hfmTex;
|
return hfmTex;
|
||||||
|
@ -1296,7 +1315,7 @@ HFMTexture GLTFSerializer::getHFMTexture(const cgltf_texture *texture) {
|
||||||
return hfmTex;
|
return hfmTex;
|
||||||
}
|
}
|
||||||
hfmTex.content = QByteArray(static_cast<const char *>(bufferView->buffer->data) + offset, length);
|
hfmTex.content = QByteArray(static_cast<const char *>(bufferView->buffer->data) + offset, length);
|
||||||
hfmTex.filename = textureUrl.toEncoded().append(imageIndex);
|
hfmTex.filename = textureUrl.toEncoded().append(QString::number(imageIndex).toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,") || url.contains("data:image/webp;base64,")) {
|
if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,") || url.contains("data:image/webp;base64,")) {
|
||||||
|
|
Loading…
Reference in a new issue