summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-02-11 14:14:30 +0000
committerMike Krus <mike.krus@kdab.com>2020-02-27 12:10:08 +0000
commit5bf4f93fcb8ff16aeadf55644be351c9989ab5b2 (patch)
tree9a502509da33a48dade8f7cbd0af1e7d3444b2f3 /src/plugins
parent703090204ef41bced5634bbb332551dea1dd7b37 (diff)
Make default geometries views
In Extras, make QTorusMesh and others a QGeometryView rather than a QGeometryRenderer. Requires changes to scene graphs here and there but going forward there simple shapes could be used as proxies for picking or collision detection, etc. Change-Id: Id488e064080dfd303e448aba11e6b242236b81d4 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sceneparsers/gltf/gltfimporter.cpp38
-rw-r--r--src/plugins/sceneparsers/gltfexport/gltfexporter.cpp13
2 files changed, 33 insertions, 18 deletions
diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
index b141a44a5..05c235977 100644
--- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp
+++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp
@@ -1740,6 +1740,7 @@ void GLTFImporter::processJSONMesh(const QString &id, const QJsonObject &json)
const QString material = (m_majorVersion > 1) ? QString::number(matValue.toInt()) : matValue.toString();
QGeometryRenderer *geometryRenderer = new QGeometryRenderer;
+ QGeometryView *geometryView = new QGeometryView;
QGeometry *meshGeometry = new QGeometry(geometryRenderer);
//Set Primitive Type
@@ -1815,7 +1816,8 @@ void GLTFImporter::processJSONMesh(const QString &id, const QJsonObject &json)
}
} // of has indices
- geometryRenderer->setGeometry(meshGeometry);
+ geometryView->setGeometry(meshGeometry);
+ geometryRenderer->setView(geometryView);
geometryRenderer->setObjectName(meshName);
m_meshDict.insert(id, geometryRenderer);
@@ -1823,17 +1825,23 @@ void GLTFImporter::processJSONMesh(const QString &id, const QJsonObject &json)
} else {
QGeometryRenderer *mesh = nullptr;
if (meshType == QStringLiteral("cone")) {
- mesh = new QConeMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QConeMesh);
} else if (meshType == QStringLiteral("cuboid")) {
- mesh = new QCuboidMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QCuboidMesh);
} else if (meshType == QStringLiteral("cylinder")) {
- mesh = new QCylinderMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QCylinderMesh);
} else if (meshType == QStringLiteral("plane")) {
- mesh = new QPlaneMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QPlaneMesh);
} else if (meshType == QStringLiteral("sphere")) {
- mesh = new QSphereMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QSphereMesh);
} else if (meshType == QStringLiteral("torus")) {
- mesh = new QTorusMesh;
+ mesh = new QGeometryRenderer;
+ mesh->setView(new QTorusMesh);
} else {
qCWarning(GLTFImporterLog,
"Invalid mesh type: %ls for mesh: %ls",
@@ -1844,30 +1852,34 @@ void GLTFImporter::processJSONMesh(const QString &id, const QJsonObject &json)
if (mesh) {
// Read and set properties
const QJsonObject propObj = json.value(KEY_PROPERTIES).toObject();
+ QObject *target = mesh;
+ if (mesh->view())
+ target = mesh->view();
for (auto it = propObj.begin(), end = propObj.end(); it != end; ++it) {
const QByteArray propName = it.key().toLatin1();
// Basic mesh types only have bool, int, float, and QSize type properties
if (it.value().isBool()) {
- mesh->setProperty(propName.constData(), QVariant(it.value().toBool()));
+ target->setProperty(propName.constData(), QVariant(it.value().toBool()));
} else if (it.value().isArray()) {
const QJsonArray valueArray = it.value().toArray();
if (valueArray.size() == 2) {
QSize size;
size.setWidth(valueArray.at(0).toInt());
size.setHeight(valueArray.at(1).toInt());
- mesh->setProperty(propName.constData(), QVariant(size));
+ target->setProperty(propName.constData(), QVariant(size));
}
} else {
- const QVariant::Type propType = mesh->property(propName.constData()).type();
+ const QVariant::Type propType = target->property(propName.constData()).type();
if (propType == QVariant::Int) {
- mesh->setProperty(propName.constData(), QVariant(it.value().toInt()));
+ target->setProperty(propName.constData(), QVariant(it.value().toInt()));
} else {
- mesh->setProperty(propName.constData(),
- QVariant(float(it.value().toDouble())));
+ target->setProperty(propName.constData(),
+ QVariant(float(it.value().toDouble())));
}
}
}
mesh->setObjectName(meshName);
+ mesh->view()->setObjectName(meshName);
m_meshMaterialDict[mesh] = (m_majorVersion > 1) ?
QString::number(json.value(KEY_MATERIAL).toInt()) :
json.value(KEY_MATERIAL).toString();
diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
index 8b4fac1ce..7be8dd43e 100644
--- a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
+++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp
@@ -734,10 +734,13 @@ void GLTFExporter::parseMeshes()
int meshCount = 0;
for (auto it = m_meshMap.constBegin(); it != m_meshMap.constEnd(); ++it) {
Node *node = it.key();
- QGeometryRenderer *mesh = it.value();
+ QGeometryRenderer *renderer = it.value();
+ QGeometryView *mesh = renderer->view();
+ if (!mesh)
+ continue;
MeshInfo meshInfo;
- meshInfo.originalName = mesh->objectName();
+ meshInfo.originalName = mesh->objectName().isEmpty() ? renderer->objectName() : mesh->objectName();
meshInfo.name = newMeshName();
meshInfo.materialName = m_materialInfo.value(m_materialMap.value(node)).name;
@@ -764,7 +767,7 @@ void GLTFExporter::parseMeshes()
}
if (meshInfo.meshType != TypeNone) {
- meshInfo.meshComponent = mesh;
+ meshInfo.meshComponent = renderer;
cacheDefaultProperties(meshInfo.meshType);
if (GLTFExporterLog().isDebugEnabled()) {
@@ -973,7 +976,7 @@ void GLTFExporter::parseMeshes()
}
meshCount++;
- m_meshInfo.insert(mesh, meshInfo);
+ m_meshInfo.insert(renderer, meshInfo);
}
qCDebug(GLTFExporterLog, "Total buffer size: %i", m_buffer.size());
@@ -1249,7 +1252,7 @@ bool GLTFExporter::saveScene()
mesh["name"] = meshInfo.originalName;
if (meshInfo.meshType != TypeNone) {
QJsonObject properties;
- exportGenericProperties(properties, meshInfo.meshType, meshInfo.meshComponent);
+ exportGenericProperties(properties, meshInfo.meshType, meshInfo.meshComponent->view());
mesh["type"] = meshInfo.meshTypeStr;
mesh["properties"] = properties;
mesh["material"] = meshInfo.materialName;