Rotating part of the Model using api

I want to rotate my fan model via api.
I succeeded already one time, But I want to rotate it several times.
with api.rotate function, can I only rotate once time?
I want to use like this.

> api.rotate(ID, [10 * Math.PI, 0, 0, 1], { // rotate 10 times.
>                 duration: 10.0,
>                 easing: 'easeOutQuad'
>             }, function (err, rotateTo) {
>                 if (!err) {
>                     window.console.log('Object is rotating');
>                 }
>             });

thanks.

To rotate it several times you need to call it multiple times

You may need a bit specific code to make sure the rotation is never bigger than 2 PI, otherwise it works, see a sample here

https://jsfiddle.net/sketchfab/xcvy61nw/

I’ve used setInterval to rotate the hands of a watch: Tavannes 3D Configurator

const rotate_s = function (instanceID) {
  const d = new Date();
  const seconds = d.getSeconds()
  const angleStep = (Math.PI * 2) / 60
  api.rotate(instanceID, [seconds * angleStep, 0, 0, 1], {duration: 0.1})
}

const interval_s = setInterval(() => {
  rotate_s(instanceID)
}, 1000); //duration of setInterval is in ms

It works very well now.
I need to rotate the fan’s wing.
When it rotates, it should be accelerated from the speed = 0, and decelerate from the current speed to 0.
It is very helpful for me.
Thanks.

Thanks for your reply.
I am interesting in autospin function of the sketchmodel viewer.
But after an mouse dragin on canvas, it stops for a while.
I want to know if there is another rotate function without setinterval() or settimeout.
Thanks.

I think there are two options here: either setInterval or requestAnimationFrame. I use requestAnimationFrame a lot to place html content on top of the 3D model while matching the 3D movement. Like here: On screen ui
But you could easily use it to rotate the model continuously.

This post is very helpful for me.
I am trying to accelerate the part of the model via rotate API.
For example, when the user click the turn on button, fan wings has to be accelerated to 4 round per seconds from 0.
If the accelerating time is 0.5s-1s, how can I implement this with easing curve?
Thanks.

When working with setInterval, you could use a fixed interval and calculate the angle for each interval. When using requestAnimationFrame, you actually do the same.
Here’s a list of easing functions and their js code: https://easings.net