简体   繁体   English

三个js,在单击鼠标时弹跳对象

[英]Three js , bouncing object on mouse click

Hey guys I just started learning Web Gl and Im using Three js. 大家好,我刚刚开始使用Three js学习Web GL和Im。

I created a simple example a cube which is rotating in space , but I would like to animate the cube a little beat for example when I click on the cube it will bounce and return to start position , here is my part of the code for animating stuff 我创建了一个简单的示例,该多维数据集在空间中旋转,但是我想对多维数据集进行动画处理,例如,当我单击该多维数据集时,它将反弹并返回起始位置,这是我的动画部分东西

function animateScene(){

                xRotation += xSpeed;
                yRotation += ySpeed;
                cubeMesh.rotation.set(xRotation, yRotation, 0.0);


                cubeMesh.position.z = zTranslation;


                requestAnimationFrame(animateScene);

                renderScene();
            }


            function renderScene(){
                renderer.render(scene, camera);
            }

Do you have some examples of playing with these parameters ? 您有一些使用这些参数的示例吗?

I guess the effect you are looking for is called "easing". 我想您正在寻找的效果称为“缓和”。 jQuery uses it for instance. jQuery例如使用它。 If you want to play with coordinates and add some smooth animation I would suggest you to have a look at the Tween.js Library . 如果您想使用坐标并添加一些平滑的动画,建议您看一下Tween.js库 It allows you to add some easing to three.js objects. 它允许您向Three.js对象添加一些缓动。
Here is a demo . 这是一个演示
And if you select the "Bounce.EaseOut" effect I guess you will you the result you're looking for. 而且,如果您选择“ Bounce.EaseOut”效果,我想您将得到您想要的结果。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM