Hello, everybody. I am very happy to post this.
https://fan-showing.herokuapp.com/ is my hosted app which uses the sketch fab.
In model detail, I rotate the wing of the fan.
When I click the low/medium/high button, it rotates.
But it doesn’t work flexibly now.
updateRotation() {
var thisObject = this;
if (!this.state.fanInfo.doneRotate){
return;
}
this.setState(prevState => ({
…prevState,
fanInfo: {
…prevState.fanInfo,
doneRotate: false,
}
}));
var api = this.state.fanInfo.api;
if (!api) return ;
var nodeId = this.state.fanInfo.nodeId;
var cuSpeed = this.state.fanInfo.rotateSpeed;
var targetSpeed = this.state.fanInfo.targetrotateSpeed;
var wingPos = this.state.fanInfo.wingPosition;
var stepAngle = 0.5;
var easingLine = 'easeLinear';
var nextAngle = cuSpeed;
if (cuSpeed < targetSpeed) {
nextAngle = Math.min(targetSpeed , cuSpeed + stepAngle);
} else if (cuSpeed > targetSpeed) {
nextAngle = Math.max(targetSpeed , cuSpeed - stepAngle);
}
wingPos = (nextAngle + wingPos) % 360;
api.rotate(nodeId, [wingPos / 180 * Math.PI, 0, 0, 1], {
duration: (50) / 1000,
easing: easingLine
}, function( ) {
thisObject.setState(prevState => ({
...prevState,
fanInfo: {
...prevState.fanInfo,
rotateSpeed: nextAngle,
wingPosition: wingPos,
doneRotate: true,
}
}));
thisObject.updateRotation();
});
};
This code is the wing rotate part.
Please let me know if there is anyway to make more flexibly rotating.
or Anybody can improve this function , please contact me.
Thanks.