question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Camera animation [startPos - endPos] with THREE.PathControls

See original GitHub issue

Hi,

I am trying to understand if I can use THREE.PathControls to animate camera position in this scenario: basically I have a startPosition and an endPosition and the animation should be on a straight line without changing the orientation of the camera.

I also need to be notified when the animation ends with an event in order to set up a few other things.

Is THREE.PathControls the right component to use or three.js has something which is a better fit for this task?

Thanks

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
bevlisoncommented, Feb 24, 2016

a changed TWEEN function name delivers error :

Uncaught TypeError: _easingFunction is not a function

using the above sample code.

The cause is the fact that TWEEN.Easing.Sinusoidal.EaseInOut is renamed to TWEEN.Easing.Sinusoidal.InOut

Easy one, but knowing this may help…

5reactions
libecommented, Apr 11, 2012

Thanks for the great tip, worked really well. Below how I did it:

View3D.prototype.onCameraAnimUpdate = function ()
{
    var currentPos = Util.lerp(this.startPos, this.endPos, this.param.t);
    var currentLookAt = Util.lerp(this.startLookAt, this.endLookAt, this.param.t);
    this.camera.position.set(currentPos.x, currentPos.y, currentPos.z);
    this.camera.lookAt(currentLookAt);      
}

View3D.prototype.onCameraAnimComplete = function ()
{
    this.createControlsForCamera();
    this.controls.target = this.endLookAt;
}


View3D.prototype.fitAll = function (viewToFit, center, radius, animate)
{               
    var radius = radius;
    var aabbCenter = center;

    // Compute offset needed to move the camera back that much needed to center AABB (approx: better if from BB front face)
    var offset = radius / Math.tan(Math.PI / 180.0 * 25 * 0.5); 

    // Compute new camera direction and position
    var dir = new THREE.Vector3(0.0, 0.0, 1.0);
    if (this.camera != undefined)
        dir = this.camera.matrix.getColumnZ();
    dir.multiplyScalar(offset); 
    var newPos = new THREE.Vector3();
    newPos.add(aabbCenter, dir);

    // Update camera
    if (!animate)
    {
        this.camera.position.set(newPos.x, newPos.y, newPos.z);
        this.camera.lookAt(aabbCenter);                     
        this.createControlsForCamera();
        this.controls.target = aabbCenter;
    }
    else
    {
        this.startPos = this.camera.position.clone();
        this.startLookAt = this.controls.target;
        this.endPos = newPos;
        this.endLookAt = aabbCenter;

        this.param = {t: 0};
        this.anim = new TWEEN.Tween(this.param).to({t: 1.0}, 500 ).easing( TWEEN.Easing.Sinusoidal.EaseInOut);

        this.anim.onUpdate(Util.bind(this, this.onCameraAnimUpdate));
        this.anim.onComplete(Util.bind(this, this.onCameraAnimComplete));
        this.anim.start();
    } 
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to move camera along a simple path - three.js
animationParent); pathControls.animation.play(true, 0 );. Lastly you need this 3 lines in you animate() function so the camera actually will move based on ...
Read more >
Avid 3D Reference Guide
Avid 3D to create, customize, and animate 3D content, visual effects, ... Camera navigation and viewing commands, such as orbiting, ... Start, End...
Read more >
Material.SetColor, UnityEngine C# (CSharp) Code Examples
public PathController(QueryTool tool) { queryTool = tool; ... Example #3 ... UP: endpos = transform.position + transform.up*openDistance*5.5f; break; ...
Read more >
three.js - 具有THREE.PathControls的相机动画[startPos-endPos ...
PathControls 是正确使用的组件,还是three.js具有更适合此任务的东西? ... Vector3(); newPos.add(aabbCenter, dir); // Update camera if (!animate) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found