如何在三个js中停止特定时间的旋转立方体。此暂停/停止持续时间可在1到30秒之间变化。让我们说立方体应该停在每个脸上5秒钟,然后移动到下一个脸。立方体水平旋转,即仅 "style1"
。这是我控制立方体旋转的函数。
function animate() {
var time = new Date().getTime();
var rotation_speed_controling_value = 5000;
if (parseInt(_this.rotation_speed) == 0) {
time = 0;
} else {
// Handling Rotation Speed Here
rotation_speed_controling_value = rotation_speed_controling_value - (parseInt(_this.rotation_speed) * 700)
// console.log(rotation_speed_controling_value);
}
_this.scene.traverse(function(obj) {
if (obj instanceof THREE.Object3D) {
switch (obj.name) {
case "scene-1-lambert-cube":
obj.position.set(0, 0, 0);
// Rotation styles
// Here we are handling styles of cube rotatioon by providing different combination of X,Y,Z
switch (_this.rotation_style) {
case "style1":
obj.rotation.x = 0;
// obj.rotation.y = (time / (rotation_speed_controling_value+(parseInt(_this.stop_duration) * 1000)));
obj.rotation.y = (time / (rotation_speed_controling_value + (parseInt(_this.stop_duration) * 1000)));
obj.rotation.z = 0;
break;
case "style2":
obj.rotation.x = (time / rotation_speed_controling_value);
obj.rotation.y = 0;
obj.rotation.z = 0;
break;
case "style3":
obj.rotation.x = (time / rotation_speed_controling_value);
obj.rotation.y = 0;
obj.rotation.z = (time / rotation_speed_controling_value);
break;
case "style4":
obj.rotation.x = (time / rotation_speed_controling_value);
obj.rotation.y = (time / rotation_speed_controling_value);
obj.rotation.z = (time / rotation_speed_controling_value);
break;
case "style5":
obj.rotation.x = -(time / rotation_speed_controling_value + 200);
obj.rotation.y = -(time / rotation_speed_controling_value - 200);
obj.rotation.z = -(time / rotation_speed_controling_value - 200);
break;
case "style6":
obj.rotation.x = (time / rotation_speed_controling_value + 200);
obj.rotation.y = (time / rotation_speed_controling_value + 200);
obj.rotation.z = (time / rotation_speed_controling_value - 200);
break;
case "style7":
obj.rotation.x = (time / rotation_speed_controling_value - 200);
obj.rotation.y = (time / rotation_speed_controling_value - 200);
obj.rotation.z = (time / rotation_speed_controling_value + 200);
break;
case "style8":
obj.rotation.x = -(time / rotation_speed_controling_value - 200);
obj.rotation.y = -(time / rotation_speed_controling_value + 200);
obj.rotation.z = -(time / rotation_speed_controling_value + 200);
break;
}
break;
}
for (var i = 0; i < _this.nbScenes; i++) {
if (obj.name.startsWith("scene-" + i)) {
obj.position.add(new THREE.Vector3(i * _this.sceneDistance, 0, 0));
}
}
// move camera if in transition
if (_this.sceneTransitionT0 !== undefined && _this.sceneTransitionV0 !== undefined) {
// parameter between 0 and 1, ease-in speed profile
var s = (t - _this.sceneTransitionT0) / _this.sceneTransitionDuration;
if (s <= 1) {
// V = s * V1 + (1-s) * V0
s = Math.sqrt(1 - (s - 1) * (s - 1)); // ease-in speed profile
var v = new THREE.Vector3();
v.copy(_this.sceneTransitionV0);
v.multiplyScalar(1 - s);
var w = _this.cameraPositionsForScene(_this.currentScene);
w.multiplyScalar(s);
camera.position.addVectors(v, w);
} else {
_this.sceneTransitionT0 = undefined;
_this.sceneTransitionV0 = undefined;
}
}
}
});
_this.renderer.render(_this.scene, camera);
// let the browser decide the tempo
requestAnimationFrame(animate);
}