I don’t know why this happening. Every time I play an animation I call function “before()” and after the animation finish I call function “After()”. Everything is working fine exept when I call a function stop() after that its a complete disaster whit the orbitcontrols.
here a video whit the issue.
first I show you that everything works correctly before and after executing an animation. Then I run the animation and interrupt it and that’s when the controls fail.
here the code:
//camera
this.camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 2000);
//orbitcontrols
this.controls = new OrbitControls(this.camera, this._ELEMENT);
this.controls.enabled=true;
this.controls.enablePan=false;
this.controls.enableZoom=true;
this.controls.maxDistance=45;
this.controls.minDistance=15;
this.controls.maxPolarAngle=Math.PI*0.55;
this.controls.target.set(0,10,0);
this.camera.position.set(0,10,45);
this.controlsReady=true;
OrbitBeforeAnimation()
{
this.helper.enabled.cameraAnimation=true;
this.controls.enablePan=true;
this.controls.enableZoom=true;
this.controls.maxDistance=Infinity;
this.controls.minDistance=0;
this.controls.maxPolarAngle=Math.PI;
this.controls.minPolarAngle=0;
this.controls.rotateSpeed=2;
this.controls.target.set(0,10,0);
this.camera.position.set(0,10,45);
this.camera.position.rotation=0;
this.controls.enabled=false;
this.autozoom=false;
}
OrbitAfterAnimation()
{
this.helper.enabled.cameraAnimation=false;
this.autozoom=true;
this.controls.enabled=true;
this.controls.enablePan=false;
this.controls.enableZoom=true;
this.controls.maxDistance=45;
this.controls.minDistance=15;
this.controls.maxPolarAngle=Math.PI*0.55;
this.controls.target.set(0,10,0);
this.camera.position.set(0,10,45);
this.controlsReady=true;
}
jump(){//this.salto (model animation) , this.saltocamara (camera animation)
this.OrbitBeforeAnimation();
this.salto.reset();
this.saltocamara.reset();
this.salto.enabled=true;
this.salto.weight=1;
this.base.fadeOut(0.3);
this.salto.fadeIn(0.3);
this.salto.syncWith(this.saltocamara);
this.salto.play();
}
stop()
{
this.helper.objects.get(this.camera).mixer.stopAllAction();
this.helper.objects.get(this.model).mixer.stopAllAction();
this.OrbitAfterAnimation();
}
//listener, when an animation has finish
this.mixerCAM.addEventListener( 'finished', ()=> {
this.base.enabled=true;
this.base.fadeIn(0.6);
this.OrbitAfterAnimation();
} );
//render
animate() {
this.stats.begin();
requestAnimationFrame(() =>
{
this.animate();
});
this.render()
this.stats.end();
}
render() {
if (this.camera.position.distanceTo(this.controls.target)<=20 &&this.autozoom==true){
this.controls.target.y=15;
this.camera.position.y=15;
this.controls.update();
}
else{
if(this.autozoom==true){
this.controls.target.y=10;
this.controls.update();
}
}
this.helper.update( this.clock.getDelta() );
this.effect.render(this.scene, this.camera);
}
I dont know what to do.
Any help will be apreciated