Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

negative playbackRate on c++ QClock and animationPlayer #145

Open
sajadblog opened this issue Aug 3, 2020 · 10 comments
Open

negative playbackRate on c++ QClock and animationPlayer #145

sajadblog opened this issue Aug 3, 2020 · 10 comments

Comments

@sajadblog
Copy link

sajadblog commented Aug 3, 2020

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
Copy link
Author

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 👍

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.

@lemirep
Copy link
Collaborator

lemirep commented Aug 3, 2020

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?

@sajadblog
Copy link
Author

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
Copy link
Author

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

@mkrus
Copy link
Member

mkrus commented Aug 3, 2020

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

@sajadblog
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants