Is there a way to full dispose orbitcontrols?

the problem is I have a model and orbitControls, but my model and the camera has animations.
So I struggling to find a way to full dispose the orbitcontrols before a camera animation start and then reenable the orbitcontrols when the camera animatin has finish.

this what I have tried without success:

this.controls = new OrbitControls(this.camera, this._ELEMENT);

---------------------------- I use this little function before each camera animation
animationWillStart()
{
this.controls.dispose();
this.controls.enabled=false;
}


Both just stop any user interaction but the orbitcontrols still working and affecting the animation of the camera (the camera moves but keeps observing the orbit point).

Any help will be apreciate

If you want to use OrbitControls at a later point again, don’t call dispose(). Just set the enabled flag.

Also it might be better if you demonstrate the issue with a live example: https://jsfiddle.net/hfbyndre/

before use dispose(), I was only using “enabled=false;” then I realice that “enabled” only stop user inputs but the orbitcontrols still
working. So when I load a camera animation using the AnimatorMixer, orbitcontrols still chaining the camera to the orbit target
instead of let the camera be complete free.

Thats why I thought on using dispose(). But not even dispose() work and I guessing is because dispose() stops the event listener but doesnt remove the orbit target. So the result is the same (any camera animation is executed but keeping (observing) the orbit target
instead of being completely free).

the only way I could find to kill Orbitcontrols and thus completely free the camera is doing something like: “this.controls=null”.
Succes. now the camera animations works as they should, but the problem is reenable orbitcontrols again after the camera animation has finished. If I try create it again

onAnimationFinish() //example
{
    this.controls = new OrbitControls(this.camera, this._ELEMENT);
    this.helper.enabled.cameraAnimation=false;
    this.controls.enabled=true;
    this.controls.enablePan=false;
    this.controls.enableZoom=true;
    this.controls.maxDistance=30;
    this.controls.minDistance=10;
    this.controls.maxPolarAngle=Math.PI*0.55;
    this.controls.target.set(0,10,0); 
    this.camera.position.x=0;
    this.camera.position.y=10;
    this.camera.position.z=30;
    this.controls.update();
}

the new orbitcontrols become more sensitve and gain more and more sensitive and glitchy after each camera animation.

its hard to me upload a live example because I loading (MMDloader) a model file and vmds with camera and model animations :frowning:

Are you manually call controls.update() in the animation loop? Notice that this is only necessary if you are enabling damping. Besides, try to not call the method when the controls are disabled.

As mentioned in the documentation the enabled only decides whether the controls respond to user input or not. If you call update(), the camera will be updated.

2 Likes

OMG, thanks so much. I did not know that. I just remove update() from animation loop and now everything is working :smiley:

I always believed that update() was necessary for the orbitalcontrols. I did not know that it was only necessary if I use damping.

1 Like