kuesa icon indicating copy to clipboard operation
kuesa copied to clipboard

negative playbackRate on c++ QClock and animationPlayer

Open sajadblog opened this issue 3 years ago • 10 comments

hello there is a problem in animationPlayer clock when using c++ API to instantiate animationPlayer and set the clock to them. for positive playebackRate animation play correctly but in negative playbackRate animation not work.

in qml api usage negative an positive animation is ok.

sample code :

`

auto player = new Kuesa::AnimationPlayer(m_sceneEntity); player->setSceneEntity(m_sceneEntity); player->setClip(clipName); if (player->status() == Kuesa::AnimationPlayer::Ready) { player->setClock(m_clock); m_clock->setPlaybackRate(reverse ? -1.0 : 1.0); player->start(); } `

sajadblog avatar Aug 03 '20 06:08 sajadblog

I don't know why but when defining a Kuesa.AnimationPlayer and assign to them a clock. can easily start the animation in both directions (direct and reverse). but when define a NodeInstantiator and delegate Kuesa.AnimationPlayer we can not play the animation in the reverse direction by setting -1 to playbackRate. the below code does not work in qml space to :

NodeInstantiator { id: animations delegate: Kuesa.AnimationPlayer { sceneEntity: root3D clip: model.modelData clock: Clock{ playbackRate: -1 } running: true } }

but when change playbackRate duration animation from positive to negative correctly change playing direction and play reverse from the current frame to the first frame. some things like this :+1:

NodeInstantiator { id: animations delegate: Kuesa.AnimationPlayer { sceneEntity: root3D clip: model.modelData clock: Clock{ playbackRate: 0.2 Timer{ interval: 3000 running: true onTriggered: { parent.playbackRate = -1 } } } running: true // loops: Kuesa.AnimationPlayer.Infinite } }

what we need is to play animation independently in both directions. thanks.

sajadblog avatar Aug 03 '20 10:08 sajadblog

The normalizeTime property of the AnimationPlayer defaults to 0. So if you play the animation with a position rate, it plays as long as normalizeTime < 1; If you play with a negative rate, it will play as long as normalizeTime > 0

Could you try to change the normalizeTime value to 1 if you want to immediately start playing with a negative play rate?

lemirep avatar Aug 03 '20 12:08 lemirep

yes, now I can play the animation from the end to start. but there is a new problem when play animation in reverse mode at the end of animation "running" variable does not change to false but the normalized time set to zero. in some animation, the reverse play does not completely play the animation, normalized time set to zero but animation paused and the animated object freezed and like other reverse play modes do not set "running" to false.

sajadblog avatar Aug 03 '20 15:08 sajadblog

for example when starting the "DoorLAction" animation in DodgeViper.gltf file in reverse mode. signal runningChanged never called

sajadblog avatar Aug 03 '20 15:08 sajadblog

might need this patch. It's old though, may need updating https://codereview.qt-project.org/c/qt/qt3d/+/284268

mkrus avatar Aug 03 '20 15:08 mkrus

In the patch, auto start from the end to the beginning was repaired, but at the moment, the problem is not sending a runningChanged signal when the animation is finished in backward mode, and also some animations are not played completely.

sajadblog avatar Aug 05 '20 09:08 sajadblog

simply can test is,

  • define a Kuesa.AnimationPlayer
  • set Clock playbackRate to -1
  • start the animation and wait for runningChanged signal when playbackRate is 1 onRunningChnaged method correctly call for the false value, but at negative value onRunningChanged just call for positive(run animation) value

sajadblog avatar Aug 05 '20 09:08 sajadblog

simple code like this:

Kuesa.AnimationPlayer { id: animationPlayer sceneEntity: root3D normalizedTime: 1 running : true clock: Clock { id: animationClose playbackRate: -1 } clip: "object_2Action" onRunningChanged: console.log(running) }

sajadblog avatar Aug 05 '20 09:08 sajadblog

my problem solved by writing a watching method in animation player parent and check normalizedTimeChanged if equal to zero consider animation finished. and when assign the value of NormalizedTime to 0.999 at start time, animation play correctly but above problem still exists.

sajadblog avatar Aug 17 '20 13:08 sajadblog

there is another question why can not assign QMaterial to an entity when using Kuesa.ForwardRenderer against to pure qt ForwardRenderer ?

sajadblog avatar Aug 17 '20 14:08 sajadblog