Rotate every object different directions and speed

Hi everyone,

website I have this website developed. I want to rotate every chocolate to different rotations with different speeds with optimiziation. Can anyone help?

function animate() {
	renderer.render( scene, camera )

    // xFactor += .01
    yFactor += .005
    // zFactor += .01

    if (mnmSceneModel !== undefined) {
        for (var i = 0; i < mnmSceneModel.children.length; i++) {
            
            // mnmSceneModel.children[i].rotation.x = xFactor
            mnmSceneModel.children[i].rotation.y = yFactor
            // mnmSceneModel.children[i].rotation.z = zFactor

        }
    }

    controls.update()
}

Akif Volkan


mnmSceneModel.children.forEach(c=>{
 c.userData.spin = new THREE.Vector3().randomDirection().multiplyScalar(.1)
 c.userData.vel = new THREE.Vector3().randomDirection().multiplyScalar(.1)
}


function animate() {
	renderer.render( scene, camera )


mnmSceneModel.children.forEach(c=>{
c.rotation.x+=c.userData.spin.x;
c.rotation.y+=c.userData.spin.y;
c.rotation.z+=c.userData.spin.z;
c.position.add(c.userData.vel);
})

    controls.update()
}

1 Like

Thanks a lot @manthrax. Please check the link again. I updated the code. Iā€™m greatful.

1 Like