void SceneWalker::onStatusChanged() { qDebug() << "Status changed:" << m_loader->status(); if (m_loader->status() != Qt3DRender::QSceneLoader::Ready) return; // The QSceneLoader instance is a component of an entity. The loaded scene // tree is added under this entity. QVector<Qt3DCore::QEntity *> entities = m_loader->entities(); // Technically there could be multiple entities referencing the scene loader // but sharing is discouraged, and in our case there will be one anyhow. if (entities.isEmpty()) return; Qt3DCore::QEntity *root = entities[0]; // Print the tree. walkEntity(root); // To access a given node (like a named mesh in the scene), use QObject::findChild(). // The scene structure and names always depend on the asset. Qt3DCore::QEntity *e = root->findChild<Qt3DCore::QEntity *>(QStringLiteral("PlanePropeller_mesh")); // toyplane.obj if (e) qDebug() << "Found propeller node" << e << "with components" << e->components(); }
void QObjectPickerPrivate::propagateEvent(QPickEvent *event, EventType type) { if (!m_entities.isEmpty()) { Qt3DCore::QEntity *entity = m_entities.first(); Qt3DCore::QEntity *parentEntity = nullptr; while (entity != nullptr && entity->parentEntity() != nullptr && !event->isAccepted()) { parentEntity = entity->parentEntity(); const auto components = parentEntity->components(); for (Qt3DCore::QComponent *c : components) { if (auto objectPicker = qobject_cast<Qt3DRender::QObjectPicker *>(c)) { QObjectPickerPrivate *objectPickerPrivate = static_cast<QObjectPickerPrivate *>(QObjectPickerPrivate::get(objectPicker)); switch (type) { case Pressed: objectPickerPrivate->pressedEvent(event); break; case Released: objectPickerPrivate->releasedEvent(event); break; case Clicked: objectPickerPrivate->clickedEvent(event); break; case EventType::Moved: objectPickerPrivate->movedEvent(event); break; } break; } } entity = parentEntity; } } }
void SceneWalker::walkEntity(Qt3DCore::QEntity *e, int depth) { Qt3DCore::QNodeVector nodes = e->childNodes(); for (int i = 0; i < nodes.count(); ++i) { Qt3DCore::QNode *node = nodes[i]; Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>(node); if (entity) { QString indent; indent.fill(' ', depth * 2); qDebug().noquote() << indent << "Entity:" << entity << "Components:" << entity->components(); walkEntity(entity, depth + 1); } } }