Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Change-Id: I4e3c7db419a5f371c42ad08d8dc74ac0017576b6
  • Loading branch information
lemirep committed Feb 10, 2021
2 parents 60c4182 + e120451 commit 26ea75d
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 33 deletions.
16 changes: 16 additions & 0 deletions src/core/gltf2exporter/gltf2utils_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,21 @@ quint8 accessorDataTypeToBytes(QAttribute::VertexBaseType type)
}
}

/*!
\internal
*/
QString getNewOrDeprecatedExtensionKey(const QString &newExtensionKey,
const QString &deprecatedExtensionKey,
const QJsonObject &extensions)
{
if (extensions.contains(newExtensionKey))
return newExtensionKey;
if (extensions.contains(deprecatedExtensionKey)) {
qCWarning(Kuesa::kuesa) << deprecatedExtensionKey << "extension is deprecated. Use" << newExtensionKey;
return deprecatedExtensionKey;
}
return {};
}

} // namespace Kuesa
QT_END_NAMESPACE
4 changes: 4 additions & 0 deletions src/core/gltf2exporter/gltf2utils_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ int addToJsonChildArray(QJsonObject &object, const QString &name, const QJsonObj

quint8 accessorDataTypeToBytes(Qt3DGeometry::QAttribute::VertexBaseType type);

QString getNewOrDeprecatedExtensionKey(const QString &newExtensionKey,
const QString &deprecatedExtensionKey,
const QJsonObject &extensions);

} // namespace Kuesa
QT_END_NAMESPACE
#endif // KUESA_GLTF2EXPORTER_GLTF2UTILS_P_H
20 changes: 19 additions & 1 deletion src/core/gltf2importer/gltf2keys_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ const QLatin1String KEY_MESHES = QLatin1String("meshes");
const QLatin1String KEY_SCENE = QLatin1String("scene");
const QLatin1String KEY_SCENES = QLatin1String("scenes");
const QLatin1String KEY_KDAB_KUESA_LAYER_EXTENSION = QLatin1String("KDAB_kuesa_layers");
const QLatin1String KEY_KDAB_LAYERS_EXTENSION = QLatin1String("KDAB_layers");
const QLatin1String KEY_KDAB_KUESA_SHADOWS_EXTENSION = QLatin1String("KDAB_kuesa_shadows");
const QLatin1String KEY_KDAB_SHADOWS_EXTENSION = QLatin1String("KDAB_shadows");
const QLatin1String KEY_MSFT_DDS_EXTENSION = QLatin1String("MSFT_texture_dds");
const QLatin1String KEY_KUESA_LAYERS = QLatin1String("layers");
const QLatin1String KEY_KUESA_SHADOWS = QLatin1String("shadows");
Expand Down Expand Up @@ -90,7 +92,8 @@ const QLatin1String KEY_EXT_PROPERTY_ANIMATION_EXTENSION = QLatin1String("EXT_pr
const QLatin1String KEY_KHR_TEXTURE_TRANSFORM = QLatin1String("KHR_texture_transform");
const QLatin1String KEY_KHR_PUNCTUAL_LIGHTS = QLatin1String("lights");
const QLatin1String KEY_KHR_PUNCTUAL_LIGHT = QLatin1String("light");
const QLatin1String KEY_KDAB_REFLECTION_PLANES_EXTENSION = QLatin1String("KDAB_kuesa_reflection_planes");
const QLatin1String KEY_KDAB_KUESA_REFLECTION_PLANES_EXTENSION = QLatin1String("KDAB_kuesa_reflection_planes");
const QLatin1String KEY_KDAB_REFLECTION_PLANES_EXTENSION = QLatin1String("KDAB_reflection_planes");
const QLatin1String KEY_PLANE = QLatin1String("plane");
const QLatin1String KEY_BUFFERVIEWTARGET = QLatin1String("target");
const QLatin1String KEY_COMPONENTTYPE = QLatin1String("componentType");
Expand Down Expand Up @@ -125,6 +128,21 @@ const QLatin1String KEY_CHILDREN = QLatin1String("children");
const QLatin1String KEY_NODE_KUESA_LAYERS = QLatin1String("layers");
const QLatin1String KEY_KDAB_PLACEHOLDER = QLatin1String("KDAB_placeholder");
const QLatin1String KEY_KDAB_PLACEHOLDER_CAMERANODE = QLatin1String("cameraNode");
const QLatin1String KEY_COLOR = QLatin1String("color");
const QLatin1String KEY_INTENSITY = QLatin1String("intensity");
const QLatin1String KEY_RANGE = QLatin1String("range");
const QLatin1String KEY_SPOT = QLatin1String("spot");
const QLatin1String KEY_INNER_CONE_ANGLE = QLatin1String("innerConeAngle");
const QLatin1String KEY_OUTER_CONE_ANGLE = QLatin1String("outerConeAngle");
const QLatin1String KEY_LIGHT_DIRECTIONAL = QLatin1String("directional");
const QLatin1String KEY_LIGHT_POINT = QLatin1String("point");
const QLatin1String KEY_LIGHT_SPOT = QLatin1String("spot");
const QLatin1String KEY_CASTS_SHADOWS = QLatin1String("castsShadows");
const QLatin1String KEY_SOFT_SHADOWS = QLatin1String("softShadows");
const QLatin1String KEY_SHADOWMAP_TEXTURE_WIDTH = QLatin1String("shadowMapTextureWidth");
const QLatin1String KEY_SHADOWMAP_TEXTURE_HEIGHT = QLatin1String("shadowMapTextureHeight");
const QLatin1String KEY_SHADOWMAP_BIAS = QLatin1String("shadowMapBias");
const QLatin1String KEY_SHADOWMAP_NEAR_PLANE = QLatin1String("nearPlane");

} // namespace GLTF2Import
} // namespace Kuesa
Expand Down
12 changes: 12 additions & 0 deletions src/core/gltf2importer/gltf2parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ QVector<KeyParserFuncPair> GLTF2Parser::prepareParsers()
{ KEY_EXTENSIONS, [this](const QJsonValue &value) {
const QVector<KeyParserFuncPair> extensionParsers = {
{ KEY_KDAB_KUESA_LAYER_EXTENSION, [this](const QJsonValue &value) {
qCWarning(Kuesa::kuesa, "KDAB_kuesa_layers is deprecated. Use KDAB_layers");
const QJsonObject obj = value.toObject();
const QJsonArray layers = obj.value(KEY_KUESA_LAYERS).toArray();
if (layers.size() == 0)
return true;
LayerParser parser;
return parser.parse(layers, m_context);
} },
{ KEY_KDAB_LAYERS_EXTENSION, [this](const QJsonValue &value) {
const QJsonObject obj = value.toObject();
const QJsonArray layers = obj.value(KEY_KUESA_LAYERS).toArray();
if (layers.size() == 0)
Expand Down Expand Up @@ -592,7 +601,9 @@ bool GLTF2Parser::parseJSON(const QByteArray &jsonData, const QString &basePath,
QStringList unsupportedExtensions;
const QStringList supportedExtensions = {
KEY_KDAB_KUESA_LAYER_EXTENSION,
KEY_KDAB_LAYERS_EXTENSION,
KEY_KDAB_KUESA_SHADOWS_EXTENSION,
KEY_KDAB_SHADOWS_EXTENSION,
KEY_MSFT_DDS_EXTENSION,
#if defined(KUESA_DRACO_COMPRESSION)
KEY_KHR_DRACO_MESH_COMPRESSION_EXTENSION,
Expand All @@ -602,6 +613,7 @@ bool GLTF2Parser::parseJSON(const QByteArray &jsonData, const QString &basePath,
KEY_KDAB_CUSTOM_MATERIAL,
KEY_EXT_PROPERTY_ANIMATION_EXTENSION,
KEY_KHR_TEXTURE_TRANSFORM,
KEY_KDAB_KUESA_REFLECTION_PLANES_EXTENSION,
KEY_KDAB_REFLECTION_PLANES_EXTENSION,
KEY_KDAB_PLACEHOLDER
};
Expand Down
29 changes: 6 additions & 23 deletions src/core/gltf2importer/lightparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "lightparser_p.h"
#include "gltf2context_p.h"
#include "gltf2keys_p.h"
#include "gltf2utils_p.h"
#include "kuesa_p.h"

#include <QJsonValue>
Expand All @@ -37,27 +38,6 @@
QT_BEGIN_NAMESPACE
using namespace Kuesa::GLTF2Import;

namespace {
const QLatin1String KEY_NAME = QLatin1String("name");
const QLatin1String KEY_TYPE = QLatin1String("type");
const QLatin1String KEY_COLOR = QLatin1String("color");
const QLatin1String KEY_INTENSITY = QLatin1String("intensity");
const QLatin1String KEY_RANGE = QLatin1String("range");
const QLatin1String KEY_SPOT = QLatin1String("spot");
const QLatin1String KEY_INNER_CONE_ANGLE = QLatin1String("innerConeAngle");
const QLatin1String KEY_OUTER_CONE_ANGLE = QLatin1String("outerConeAngle");
const QLatin1String KEY_LIGHT_DIRECTIONAL = QLatin1String("directional");
const QLatin1String KEY_LIGHT_POINT = QLatin1String("point");
const QLatin1String KEY_LIGHT_SPOT = QLatin1String("spot");
const QLatin1String KEY_CASTS_SHADOWS = QLatin1String("castsShadows");
const QLatin1String KEY_SOFT_SHADOWS = QLatin1String("softShadows");
const QLatin1String KEY_SHADOWMAP_TEXTURE_WIDTH = QLatin1String("shadowMapTextureWidth");
const QLatin1String KEY_SHADOWMAP_TEXTURE_HEIGHT = QLatin1String("shadowMapTextureHeight");
const QLatin1String KEY_SHADOWMAP_BIAS = QLatin1String("shadowMapBias");
const QLatin1String KEY_SHADOWMAP_NEAR_PLANE = QLatin1String("nearPlane");

} // namespace

bool Kuesa::GLTF2Import::LightParser::parse(const QJsonArray &lights, Kuesa::GLTF2Import::GLTF2Context *context)
{
for (const auto &lightValue : lights) {
Expand Down Expand Up @@ -108,8 +88,11 @@ bool Kuesa::GLTF2Import::LightParser::parse(const QJsonArray &lights, Kuesa::GLT

// Shadows extension
const QJsonObject extensions = lightObject.value(KEY_EXTENSIONS).toObject();
if (extensions.contains(KEY_KDAB_KUESA_SHADOWS_EXTENSION)) {
const QJsonObject kdabShadowsExtension = extensions.value(KEY_KDAB_KUESA_SHADOWS_EXTENSION).toObject();
const QString shadowExtensionKey = getNewOrDeprecatedExtensionKey(KEY_KDAB_SHADOWS_EXTENSION,
KEY_KDAB_KUESA_SHADOWS_EXTENSION,
extensions);
if (!shadowExtensionKey.isEmpty()) {
const QJsonObject kdabShadowsExtension = extensions.value(shadowExtensionKey).toObject();
light.castsShadows = kdabShadowsExtension.value(KEY_CASTS_SHADOWS).toBool(light.castsShadows);
light.softShadows = kdabShadowsExtension.value(KEY_SOFT_SHADOWS).toBool(light.softShadows);
light.shadowMapBias = kdabShadowsExtension.value(KEY_SHADOWMAP_BIAS).toDouble(light.shadowMapBias);
Expand Down
16 changes: 12 additions & 4 deletions src/core/gltf2importer/nodeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QPair>
#include <Qt3DCore/private/qmath3d_p.h>
#include <gltf2keys_p.h>
#include <gltf2utils_p.h>
#include <functional>
#include <memory>

Expand Down Expand Up @@ -153,10 +154,13 @@ QPair<bool, TreeNode> treenodeFromJson(const QJsonObject &nodeObj)
}

const QJsonObject nodeExtensions = nodeObj.value(KEY_EXTENSIONS).toObject();
const QString layerExtensionKey = getNewOrDeprecatedExtensionKey(KEY_KDAB_LAYERS_EXTENSION,
KEY_KDAB_KUESA_LAYER_EXTENSION,
nodeExtensions);

// Layer Extensions
if (nodeExtensions.contains(KEY_KDAB_KUESA_LAYER_EXTENSION)) {
const QJsonObject kdabLayerExtension = nodeExtensions.value(KEY_KDAB_KUESA_LAYER_EXTENSION).toObject();
if (!layerExtensionKey.isEmpty()) {
const QJsonObject kdabLayerExtension = nodeExtensions.value(layerExtensionKey).toObject();
// If the node references layers, add them
if (kdabLayerExtension.contains(KEY_NODE_KUESA_LAYERS)) {
const QJsonArray layerIds = kdabLayerExtension.value(KEY_NODE_KUESA_LAYERS).toArray();
Expand All @@ -174,8 +178,12 @@ QPair<bool, TreeNode> treenodeFromJson(const QJsonObject &nodeObj)
const QJsonObject lightObject = nodeExtensions.value(KEY_KHR_LIGHTS_PUNCTUAL_EXTENSION).toObject();
node.lightIdx = lightObject.value(KEY_KHR_PUNCTUAL_LIGHT).toInt(-1);
}
if (nodeExtensions.contains(KEY_KDAB_REFLECTION_PLANES_EXTENSION)) {
const QJsonObject reflectionPlaneObject = nodeExtensions.value(KEY_KDAB_REFLECTION_PLANES_EXTENSION).toObject();

const QString reflectionPlaneExtensionKey = getNewOrDeprecatedExtensionKey(KEY_KDAB_REFLECTION_PLANES_EXTENSION,
KEY_KDAB_KUESA_REFLECTION_PLANES_EXTENSION,
nodeExtensions);
if (!reflectionPlaneExtensionKey.isEmpty()) {
const QJsonObject reflectionPlaneObject = nodeExtensions.value(reflectionPlaneExtensionKey).toObject();
const QJsonArray planeEquationValue = reflectionPlaneObject.value(KEY_PLANE).toArray();
QVector4D planeEquation;
if (planeEquationValue.size() == 4) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/iro2-materials/iro2-materials_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef KUESA_IRO_MATERIALS_P_H
#define KUESA_IRO_MATERIALS_P_H
#ifndef KUESA_IRO_2_MATERIALS_P_H
#define KUESA_IRO_2_MATERIALS_P_H

//
// W A R N I N G
Expand Down
3 changes: 3 additions & 0 deletions tests/auto/assets/KHR_lights_punctual/default_shadows.gltf
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/auto/assets/KHR_lights_punctual/deprecated_shadows.gltf
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/auto/assets/KHR_lights_punctual/shadows.gltf
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/auto/assets/node_multi_extensions.gltf
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/auto/assets/node_multi_extensions_deprecated.gltf
Git LFS file not shown
84 changes: 83 additions & 1 deletion tests/auto/lightparser/tst_lightparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ private Q_SLOTS:
GLTF2Context context;
LightParser parser;
QFile file(filePath);
qDebug() << "File path " << file.fileName();
file.open(QIODevice::ReadOnly);
QVERIFY(file.isOpen());

Expand All @@ -138,6 +137,89 @@ private Q_SLOTS:
QCOMPARE(context.light(0).innerConeAngleRadians, innerConeAngle);
QCOMPARE(context.light(0).outerConeAngleRadians, outerConeAngle);
}

void checkParseShadowExtension_data()
{
QTest::addColumn<QString>("filePath");
QTest::addColumn<bool>("succeeded");
QTest::addColumn<QString>("name");
QTest::addColumn<int>("type");
QTest::addColumn<bool>("castsShadows");
QTest::addColumn<bool>("softShadows");
QTest::addColumn<float>("shadowMapBias");
QTest::addColumn<float>("nearPlane");
QTest::addColumn<QSize>("shadowMapTextureSize");

QTest::newRow("Valid Deprecated Extension") << QStringLiteral(ASSETS "KHR_lights_punctual/deprecated_shadows.gltf")
<< true
<< "DeprecatedShadow"
<< static_cast<int>(Qt3DRender::QAbstractLight::SpotLight)
<< true
<< true
<< 0.5f
<< 1.0f
<< QSize(128, 256);

QTest::newRow("Valid") << QStringLiteral(ASSETS "KHR_lights_punctual/shadows.gltf")
<< true
<< "Shadow"
<< static_cast<int>(Qt3DRender::QAbstractLight::SpotLight)
<< true
<< true
<< 0.5f
<< 1.0f
<< QSize(128, 256);

QTest::newRow("Default Values") << QStringLiteral(ASSETS "KHR_lights_punctual/default_shadows.gltf")
<< true
<< "DefaultShadow"
<< static_cast<int>(Qt3DRender::QAbstractLight::SpotLight)
<< false
<< false
<< 0.005f
<< 0.0f
<< QSize(512, 512);
}

void checkParseShadowExtension()
{
QFETCH(QString, filePath);
QFETCH(bool, succeeded);
QFETCH(QString, name);
QFETCH(int, type);
QFETCH(bool, castsShadows);
QFETCH(bool, softShadows);
QFETCH(float, shadowMapBias);
QFETCH(float, nearPlane);
QFETCH(QSize, shadowMapTextureSize);

// GIVEN
GLTF2Context context;
LightParser parser;
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QVERIFY(file.isOpen());

// WHEN
const QJsonDocument json = QJsonDocument::fromJson(file.readAll());
// THEN
QVERIFY(!json.isNull());
QVERIFY(json.isArray());

// WHEN
bool success = parser.parse(json.array(), &context);

// THEN
QCOMPARE(success, succeeded);
QCOMPARE(context.lightCount(), size_t(1));
QCOMPARE(context.light(0).name, name);
QCOMPARE(context.light(0).type, type);
QCOMPARE(context.light(0).castsShadows, castsShadows);
QCOMPARE(context.light(0).softShadows, softShadows);
QCOMPARE(context.light(0).shadowMapBias, shadowMapBias);
QCOMPARE(context.light(0).nearPlane, nearPlane);
QCOMPARE(context.light(0).shadowMapTextureSize, shadowMapTextureSize);
}
};

QTEST_APPLESS_MAIN(tst_LightParser)
Expand Down
27 changes: 27 additions & 0 deletions tests/auto/nodeparser/tst_nodeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ private Q_SLOTS:
QCOMPARE(n.name, QStringLiteral("Morphed"));
}

void checkDeprecatedMultipleExtensionsOnNode()
{
// GIVEN
GLTF2Context context;
NodeParser parser;
QFile file(QStringLiteral(ASSETS "node_multi_extensions_deprecated.gltf"));
file.open(QIODevice::ReadOnly);
QVERIFY(file.isOpen());

const QJsonDocument json = QJsonDocument::fromJson(file.readAll());
const QJsonValue nodes = json.object().value(QLatin1String("nodes"));
QVERIFY(!json.isNull() && nodes.isArray());

// WHEN
const bool success = parser.parse(nodes.toArray(), &context);

// THEN
QVERIFY(success);
QCOMPARE(context.treeNodeCount(), size_t(1));

const TreeNode n = context.treeNode(0);
QCOMPARE(n.reflectionPlaneEquation, QVector4D(1.0f, 0.0f, 0.0f, 883.0f));
QCOMPARE(n.layerIndices, QVector<int>({0, 1, 2}));
QCOMPARE(n.hasPlaceholder, true);
QCOMPARE(n.placeHolder.cameraNode, 1);
}

void checkMultipleExtensionsOnNode()
{
// GIVEN
Expand Down

0 comments on commit 26ea75d

Please sign in to comment.