void PhysicsGeometry::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e){ Qt3DCore::QScenePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QScenePropertyChange>(e); QByteArray propertyName = propertyChange->propertyName(); switch (e->type()) { case Qt3DCore::NodeAdded: { if (propertyName == QByteArrayLiteral("attribute")) { m_attributes.push_back(propertyChange->value().value<Qt3DCore::QNodeId>()); } break; } case Qt3DCore::NodeRemoved: { if (propertyName == QByteArrayLiteral("attribute")) { m_attributes.removeOne(propertyChange->value().value<Qt3DCore::QNodeId>()); } break; } case Qt3DCore::NodeUpdated: if (propertyName == QByteArrayLiteral("enabled")){ m_enabled = propertyChange->value().value<bool>(); } else if (propertyName == QByteArrayLiteral("verticesPerPatch")) { m_verticesPerPatch = propertyChange->value().value<int>(); break; } default: break; } }
void checkPropertyUpdates() { // GIVEN QScopedPointer<Qt3DRender::QFrameGraph> frameGraph(new Qt3DRender::QFrameGraph()); TestArbiter arbiter(frameGraph.data()); // WHEN MyFrameGraphNode *activeFrameGraph1 = new MyFrameGraphNode(); frameGraph->setActiveFrameGraph(activeFrameGraph1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); Qt3DCore::QScenePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "activeFrameGraph"); QCOMPARE(change->subjectId(), frameGraph->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), activeFrameGraph1->id()); QCOMPARE(change->type(), Qt3DCore::NodeUpdated); arbiter.events.clear(); // WHEN frameGraph->setActiveFrameGraph(activeFrameGraph1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 0); // WHEN MyFrameGraphNode *activeFrameGraph2 = new MyFrameGraphNode(); frameGraph->setActiveFrameGraph(activeFrameGraph2); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "activeFrameGraph"); QCOMPARE(change->subjectId(), frameGraph->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), activeFrameGraph2->id()); QCOMPARE(change->type(), Qt3DCore::NodeUpdated); arbiter.events.clear(); // WHEN frameGraph->setActiveFrameGraph(Q_NULLPTR); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "activeFrameGraph"); QCOMPARE(change->subjectId(), frameGraph->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), Qt3DCore::QNodeId()); QCOMPARE(change->type(), Qt3DCore::NodeUpdated); }
void PhysicsBodyInfo::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) { Qt3DCore::QScenePropertyChangePtr e = qSharedPointerCast< Qt3DCore::QScenePropertyChange>(change); if (e->type() == Qt3DCore::NodeUpdated) { /*if (e->propertyName() == QByteArrayLiteral("attachPhysicsTransfrom")) { bool val = e->value().toBool(); if(val){ QVector<Qt3D::QEntity*> entities = this->entities(); if (entities.size() > 1) qWarning()<< "It is strongly discouraged to share PhysicsBodyInfo component between entities"; Q_FOREACH(Qt3D::QEntity* e, entities){ bool hasPhysicsTransform=false; QMatrix4x4 m; Q_FOREACH(Qt3D::QComponent* c, e->components()){ if(c->inherits("Qt3D::QTransform") && c->objectName().compare("@MaDeByPhYsIcS@")!=0){ c->setEnabled(false); m=qobject_cast<Qt3D::QTransform*>(c)->matrix(); } else if(c->inherits("Qt3D::QTransform") && c->objectName().compare("@MaDeByPhYsIcS@")==0){ hasPhysicsTransform=true; } } if(!hasPhysicsTransform){ Qt3D::QTransform* physics_transform=new Qt3D::QTransform(this->parentNode()); physics_transform->setObjectName("@MaDeByPhYsIcS@"); Qt3D::QMatrixTransform* matrix= new Qt3D::QMatrixTransform(m,physics_transform); physics_transform->addTransform(matrix); e->addComponent(physics_transform); m_attached_matrix=matrix; } } } }*/ if(e->propertyName() == QByteArrayLiteral("updateTransform")){ QMatrix4x4 mat= e->value().value<QMatrix4x4>(); m_outputTransform->setMatrix(mat); emit outputTransformChanged(); } if(e->propertyName() == QByteArrayLiteral("notifyCollision")){ PhysicsCollisionEventPtrList collisions_list=e->value().value<PhysicsCollisionEventPtrList>(); if(collisions_list.size()==0){ if(m_hasCollided){ m_hasCollided=false; emit hasCollidedChanged(m_hasCollided); } m_collisionsList.clear(); m_collisionsCache.clear(); emit collisionsListChanged(); } else{ m_collisionsList.clear(); m_collisionsCache.clear(); Q_FOREACH(PhysicsCollisionEventPtr event_ptr,collisions_list){ m_collisionsList.append(event_ptr); m_collisionsCache.insert(event_ptr->target()); if(m_collisionsList.last()->isNew()){ emit collided(m_collisionsList.last()); } } if(!m_hasCollided){ m_hasCollided=true; emit hasCollidedChanged(m_hasCollided); } emit collisionsListChanged(); } }
void PhysicsGeometryRenderer::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e){ switch (e->type()) { case Qt3DCore::NodeUpdated: { Qt3DCore::QScenePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QScenePropertyChange>(e); QByteArray propertyName = propertyChange->propertyName(); if (propertyName == QByteArrayLiteral("geometryFunctor")){ // Mesh with source m_geometry_functor= propertyChange->value().value<Qt3DRender::QGeometryFunctorPtr>(); m_dirty=true; } else if (propertyName == QByteArrayLiteral("enabled")){ m_enabled = propertyChange->value().value<bool>(); }else if (propertyChange->propertyName() == QByteArrayLiteral("instanceCount")) { m_instanceCount = propertyChange->value().value<int>(); m_dirty = true; } else if (propertyName == QByteArrayLiteral("primitiveCount")) { m_primitiveCount = propertyChange->value().value<int>(); m_dirty = true; } else if (propertyName == QByteArrayLiteral("baseVertex")) { m_baseVertex = propertyChange->value().value<int>(); m_dirty = true; } else if (propertyName == QByteArrayLiteral("baseInstance")) { m_baseInstance = propertyChange->value().value<int>(); m_dirty = true; } else if (propertyName == QByteArrayLiteral("restartIndex")) { m_restartIndex = propertyChange->value().value<int>(); m_dirty = true; } else if (propertyName == QByteArrayLiteral("primitiveRestart")) { m_primitiveRestart = propertyChange->value().value<bool>(); m_dirty = true; } break; } case Qt3DCore::NodeAdded: { Qt3DCore::QScenePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QScenePropertyChange>(e); if (propertyChange->propertyName() == QByteArrayLiteral("geometry")) { m_geometry = propertyChange->value().value<Qt3DCore::QNodeId>(); } break; } case Qt3DCore::NodeRemoved: { Qt3DCore::QScenePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QScenePropertyChange>(e); if (propertyChange->propertyName() == QByteArrayLiteral("geometry")) { m_geometry = Qt3DCore::QNodeId(); } break; } default: break; } }
void checkPropertyUpdates() { // GIVEN QScopedPointer<Qt3DRender::QTechniqueFilter> techniqueFilter(new Qt3DRender::QTechniqueFilter()); TestArbiter arbiter(techniqueFilter.data()); // WHEN Qt3DRender::QParameter *param1 = new Qt3DRender::QParameter(); techniqueFilter->addParameter(param1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); Qt3DCore::QScenePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "parameter"); QCOMPARE(change->subjectId(),techniqueFilter->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), param1->id()); QCOMPARE(change->type(), Qt3DCore::NodeAdded); arbiter.events.clear(); // WHEN techniqueFilter->addParameter(param1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 0); // WHEN techniqueFilter->removeParameter(param1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "parameter"); QCOMPARE(change->subjectId(), techniqueFilter->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), param1->id()); QCOMPARE(change->type(), Qt3DCore::NodeRemoved); arbiter.events.clear(); // WHEN Qt3DRender::QAnnotation *annotation1 = new Qt3DRender::QAnnotation(); techniqueFilter->addRequirement(annotation1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "require"); QCOMPARE(change->subjectId(),techniqueFilter->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), annotation1->id()); QCOMPARE(change->type(), Qt3DCore::NodeAdded); arbiter.events.clear(); // WHEN techniqueFilter->addRequirement(annotation1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 0); // WHEN techniqueFilter->removeRequirement(annotation1); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); QCOMPARE(change->propertyName(), "require"); QCOMPARE(change->subjectId(), techniqueFilter->id()); QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), annotation1->id()); QCOMPARE(change->type(), Qt3DCore::NodeRemoved); arbiter.events.clear(); }