0
Answered

Help with a mesh rotation

awardstudios 1 year ago updated by Vitaly Ovchinnikov 1 year ago 1

Ok, i need help for a mesh rotation: when click on “start cube rotation” cube start rotation on z axys; when click stop button, cube stop rotating; i send you original file in koru. Only cube mesh must be rotating.

Thanks for your help

test

Answer

Answer
Answered

Click Scene->Script Editor and paste this code there:

function koruInit(koru) {
    koru.addEventListener('update', onKoruUpdate);
}

function onKoruUpdate(event) {
    var koru = event.koru;

    var cubes = koru.root.getNodesByName("Cube");
    if (cubes.length < 1) return;
    var cube = cubes[0];

    if (cube.userData.startTime !== undefined && event.idleTime > cube.userData.startTime) {
        var delta = event.idleTime - cube.userData.startTime;
        var rot = cube.rotation;
        rot.z += delta * 10;
        cube.rotation = rot;
    }

    cube.userData.startTime = event.idleTime;

    koru.invalidate(3);
}

This will slowly rotate the cube while the scene is inactive. The script locates the cube node, then does some magic to get the time delta since the last frame, then finally applies that delta towards the cube's rotation angle. You can change "10" to something bigger to speed the cube up.

Answer
Answered

Click Scene->Script Editor and paste this code there:

function koruInit(koru) {
    koru.addEventListener('update', onKoruUpdate);
}

function onKoruUpdate(event) {
    var koru = event.koru;

    var cubes = koru.root.getNodesByName("Cube");
    if (cubes.length < 1) return;
    var cube = cubes[0];

    if (cube.userData.startTime !== undefined && event.idleTime > cube.userData.startTime) {
        var delta = event.idleTime - cube.userData.startTime;
        var rot = cube.rotation;
        rot.z += delta * 10;
        cube.rotation = rot;
    }

    cube.userData.startTime = event.idleTime;

    koru.invalidate(3);
}

This will slowly rotate the cube while the scene is inactive. The script locates the cube node, then does some magic to get the time delta since the last frame, then finally applies that delta towards the cube's rotation angle. You can change "10" to something bigger to speed the cube up.