How to get current rotation from mesh which animated with registerAfterRender?

Hello! I am new here! Please help me , i’d tried everything i known,but nothing help me
i want to get current rotation of mesh which animated with registerAfterRender, i tried get from world matrix but value not correct.

the part of my model spinning endlessly and when one button is clicked i want to get current rotation and set this Vector3 as start my pe_end animation, so issue is that current rotation is always same number

Welcome aboard!

Your PG does not work, there are some CORS errors (see the browser console log).

Anyway, your problem may be that the world matrix is not updated yet. You should try to call mesh.computeWorldMatrix(true); before retrieving the world matrix.

i use computeWorldMatrix right after mesh initialization and it work not correctly
it always return the same number

let baraban = scene.getNodeByName('baraban');

i don;t know how to fix CORS in PG
please see by this link

Have a look at this page for solutions to use external resources in the Playground: Using External Assets In the Playground | Babylon.js Documentation

You should set the value of the first key of your animation just before playing it, so just before calling scene.beginAnimation, something like anim_keys[0].value = baraban.rotation.clone();.

Also, you don’t need:

engine.runRenderLoop(() => {

It’s already done for you by the Playground framework.

I updated my PG and add anim_keys[0].value = baraban.rotation.clone() but it still not work correctly,
When button is clicked baraban should stop and from this position play animation

As it is a model loaded from a .glb file, the rotation is held in rotationQuaternion. So, it’s the property that should be animated:

1 Like

Oh man! Thank you so much!!! it is exactly what i need!

1 Like