KDAB / kuesa

Professional 3D asset creation and integration workflow for Qt
https://www.kuesa.com/
139 stars 27 forks source link

negative playbackRate on c++ QClock and animationPlayer #145

Open sajadblog opened 4 years ago

sajadblog commented 4 years ago

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 commented 4 years ago

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.

lemirep commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

mkrus commented 4 years ago

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

sajadblog commented 4 years ago

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 commented 4 years ago

simply can test is,

sajadblog commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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