We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Camera Transformation Dampening/Easing

Home Forums General Questions Camera Transformation Dampening/Easing

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #43392
    jdhutchinson
    Customer

    Hi,

    Is it possible to add easing to camera transformations, so that camera movements are not as sudden to stop? So the motion can end in a soft way, if that makes sense?

    I tried using:

    controls.enableDamping = true;
    controls.dampingFactor = 0.05;

    in an exec script. I could really do with some help now, as for some reason that has now completely broken my app.

    Attachments:
    You must be logged in to view attached files.
    #43401
    jdhutchinson
    Customer

    <script>
    var scene = new v3d.Scene();
    var camera = new v3d.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

    var renderer = new v3d.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    var geometry = new v3d.BoxGeometry(1, 1, 1);
    var material = new v3d.MeshBasicMaterial({ color: 0x00ff00 });
    var cube = new v3d.Mesh(geometry, material);
    scene.add(cube);

    var controls = new v3d.OrbitControls(camera);
    controls.enableDamping = true;
    controls.dampingFactor = 0.2;
    camera.position.z = 5;

    var animate = function() {
    requestAnimationFrame(animate);

    //cube.rotation.x += 0.1;
    //cube.rotation.y += 0.1;
    controls.update();
    renderer.render(scene, camera);
    };

    animate();
    </script>

    #43410

    Hi,

    There’s no controls.dampingFactor setting but you can use the following properties to control the damping effect for different types of movement and for both mobile and desktop controls:

    
    controls.rotateInertia = 0.1;
    controls.rotateInertiaTouch = 0.1;
    controls.panInertia = 0.1;
    controls.zoomInertia = 0.1;
    controls.zoomInertiaTouch = 0.1;
    

    Co-founder and lead developer at Soft8Soft.

    #43416
    jdhutchinson
    Customer

    Hi Ivan,

    Thank you for the response. I got this working on the basic cube example from the documentation, thank you.

    See attached image. How can I tap into the v3d elements through an exec js script puzzle? Or is my attachment oversimplifying this?

    Also tried (in an exec script puzzle):

    app.camera.enableDamping = true;
    app.camera.rotateInertia = 0.2;

    Attachments:
    You must be logged in to view attached files.
    #43439

    See attached image. How can I tap into the v3d elements through an exec js script puzzle? Or is my attachment oversimplifying this?

    You can do that through v3d, for example, v3d.Mesh or v3d.Scene, but it’s usually for when you need to create new objects before adding them into the application.

    In order to change something that’s already there you can use the app variable. For example, the controls are available as app.controls and the scene is app.scene. So, dumping can be modified like this:

    
    app.controls.rotateInertia = 0.2;
    

    Co-founder and lead developer at Soft8Soft.

    #43476
    jdhutchinson
    Customer

    Dear Ivan,

    This is fantastic. I knew the solution would end up being not so difficult! At first I was concerned that to access such a command required the enterprise edition.

    I guess something that I would find useful to know, is what variables has verge3d already created during initialisation, in other words which objects can I scrutinise and set properties/use methods of. In this case, under the hood, my application has kindly created the necessary variable for an EnableControls object, named controls.

    I’m still a little confused though why the v3d documentation mentions dampingFactor though: https://www.soft8soft.com/docs/api/en/controls/OrbitControls.html#dampingFactor

    Thank you Ivan :good:

    #43542
    jdhutchinson
    Customer

    Dear Ivan,

    Would it be possible for you to list some other common objects in the v3d scene, that can be amended with an exec script puzzle? Might help me to better understand what features I can tap into from threejs. Since it is a peculiar situation where some but not all of that library is included.

    #44380
    web
    Customer

    I’ve just activated the dampening too. It producing the desired effect pretty good, but there are tiny “stutters”. Right before the camera stops, the camera makes a tiny jump. It seems that the “inertia” is producing a kind of range, and the camera snaps to the closest value in that range.

    Is there anything to fix that “snapping”?

    #45228
    jdhutchinson
    Customer

    I’m not sure.Still confused by the API terms in the documentation not being right.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.