Home › Forums › General Questions › Camera Transformation Dampening/Easing
- This topic has 8 replies, 3 voices, and was last updated 3 years, 2 months ago by jdhutchinson.
-
AuthorPosts
-
2021-08-02 at 9:15 pm #43392jdhutchinsonCustomer
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.2021-08-03 at 8:33 am #43401jdhutchinsonCustomer<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>2021-08-03 at 4:18 pm #43410Ivan LyubovnikovStaffHi,
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.
2021-08-03 at 9:26 pm #43416jdhutchinsonCustomerHi 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.2021-08-04 at 9:41 am #43439Ivan LyubovnikovStaffSee 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
orv3d.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 asapp.controls
and the scene isapp.scene
. So, dumping can be modified like this:app.controls.rotateInertia = 0.2;
Co-founder and lead developer at Soft8Soft.
2021-08-05 at 4:07 pm #43476jdhutchinsonCustomerDear 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
2021-08-10 at 12:06 am #43542jdhutchinsonCustomerDear 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.
2021-09-07 at 3:34 pm #44380webCustomerI’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”?
2021-09-24 at 8:35 pm #45228jdhutchinsonCustomerI’m not sure.Still confused by the API terms in the documentation not being right.
-
AuthorPosts
- You must be logged in to reply to this topic.