What is different QMorphingAnimation and QVertexBlendAnimation?
Unsolved
General and Desktop
-
Hi, I want to use Morph Animation with Qt3D.
I read the documents of QMorphingAnimation and QVertexBlendAnimation but I did not understand the difference well.
So, I tried while referring to the code in "Qt/5.13.0/Src/qt3d/tests/manual/mesh-morphing".
Here is the code I'm trying. ( Almost the same... )When I run this cord,
ASSERT failure in QVector<T>::at: "index out of range", file QtCore/qvector.h, line 440
comes out.
Is my usage strange?I use Qt version 5.13.0.
Sorry, I am not good at English. Thanks in advance.#include <QApplication> #include <QMainWindow> #include <QWidget> #include <Qt3DRender/Qt3DRender> #include <Qt3DCore/Qt3DCore> #include <Qt3DInput/Qt3DInput> #include <Qt3DExtras/Qt3DExtras> #include <Qt3DAnimation/Qt3dAnimation> void funcCameraSetting( Qt3DRender::QCamera* camera ) { camera->setProjectionType( Qt3DRender::QCameraLens::PerspectiveProjection ); camera->setViewCenter( QVector3D( 0.0f, 0.0f, 0.0f ) ); camera->setPosition( QVector3D( 10.0f, 10.0f, 10.0f ) ); camera->setNearPlane( 0.1f ); camera->setFarPlane( 1000.0f ); } int main( int argc, char* argv[] ) { QApplication a( argc, argv ); auto rootEntity = new Qt3DCore::QEntity(); auto view = new Qt3DExtras::Qt3DWindow(); view->defaultFrameGraph()->setClearColor( Qt::white ); view->renderSettings()->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand ); funcCameraSetting( view->camera() ); view->camera()->setAspectRatio( view->width() / view->height() ); auto cameraControl = new Qt3DExtras::QOrbitCameraController( rootEntity ); cameraControl->setCamera( view->camera() ); /* base mesh*/ auto mesh = new Qt3DExtras::QCylinderMesh( rootEntity ); mesh->setRings( 6 ); mesh->setSlices( 20 ); /* target geometry*/ auto cylinder1 = new Qt3DExtras::QCylinderGeometry( rootEntity ); auto cylinder2 = new Qt3DExtras::QCylinderGeometry( rootEntity ); auto cylinder3 = new Qt3DExtras::QCylinderGeometry( rootEntity ); cylinder1->setRings( 6 ); cylinder1->setSlices( 20 ); cylinder1->setLength( 2.0f ); cylinder1->setRadius( 1.0f ); cylinder2->setRings( 6 ); cylinder2->setSlices( 20 ); cylinder2->setLength( 1.0f ); cylinder2->setRadius( 5.0f ); cylinder3->setRings( 6 ); cylinder3->setSlices( 20 ); cylinder3->setLength( 9.0f ); cylinder3->setRadius( 1.0f ); /* morph target setting */ QStringList attributes; attributes.append( Qt3DRender::QAttribute::defaultPositionAttributeName() ); attributes.append( Qt3DRender::QAttribute::defaultNormalAttributeName() ); QVector<Qt3DAnimation::QMorphTarget*> morphTargets; morphTargets.append( Qt3DAnimation::QMorphTarget::fromGeometry( cylinder1, attributes ) ); morphTargets.append( Qt3DAnimation::QMorphTarget::fromGeometry( cylinder3, attributes ) ); morphTargets.append( Qt3DAnimation::QMorphTarget::fromGeometry( cylinder2, attributes ) ); morphTargets.append( morphTargets.first() ); /* transform and material */ auto transform = new Qt3DCore::QTransform; auto material = new Qt3DExtras::QMorphPhongMaterial( rootEntity ); material->setDiffuse( Qt::red ); /* target entity */ auto morphingEntity = new Qt3DCore::QEntity( rootEntity ); morphingEntity->addComponent( mesh ); morphingEntity->addComponent( transform ); morphingEntity->addComponent( material ); /* animation setting */ auto animation1 = new Qt3DAnimation::QVertexBlendAnimation; auto animation2 = new Qt3DAnimation::QMorphingAnimation; //<< I try to use this! QVector<float> times; times.append( 0.0f ); times.append( 5.0f ); times.append( 8.0f ); times.append( 12.0f ); /* vertexBlendAnimation setting */ animation1->setTargetPositions( times ); animation1->setTarget( mesh ); animation1->setMorphTargets( morphTargets ); /* morphingAnimation setting */ animation2->setMethod( Qt3DAnimation::QMorphingAnimation::Relative ); animation2->setEasing( QEasingCurve::OutInCubic ); animation2->setTargetPositions( times ); animation2->setTarget( mesh ); animation2->setMorphTargets( morphTargets ); //QObject::connect( animation1, &Qt3DAnimation::QVertexBlendAnimation::interpolatorChanged, material, // &Qt3DExtras::QMorphPhongMaterial::setInterpolator ); QObject::connect( animation2, &Qt3DAnimation::QMorphingAnimation::interpolatorChanged, material, &Qt3DExtras::QMorphPhongMaterial::setInterpolator ); /* use PropertyAnimation */ //auto propertyAnimation = new QPropertyAnimation( animation1 ); auto propertyAnimation = new QPropertyAnimation( animation2 ); propertyAnimation->setDuration( 5000 ); propertyAnimation->setStartValue( QVariant::fromValue( 0.0f ) ); propertyAnimation->setEndValue( QVariant::fromValue( 12.0f ) ); propertyAnimation->setLoopCount( -1 ); //propertyAnimation->setTargetObject( animation1 ); propertyAnimation->setTargetObject( animation2 ); propertyAnimation->setPropertyName( "position" ); propertyAnimation->start(); //using animation1 -> ok. using animation2 -> error!? view->setRootEntity( rootEntity ); QMainWindow mainWindow; auto container = QWidget::createWindowContainer( view ); mainWindow.setCentralWidget( container ); mainWindow.resize( 800, 600 ); mainWindow.show(); return a.exec(); } #include "main.moc"