20 Babylonjs Getting more advanced camera settings arc of rotation

Camera focal distance limitations of distance

We can set the camera arcuate rotation lowerRadiusLimitand upperRadiusLimitto set the distance from the focus range of the camera.

camera.lowerRadiusLimit = 2;
camera.upperRadiusLimit = 6;

upperRadiusLimitValue of not less than lowerRadiusLimit, or ineffective to avoid errors.

Rebound effect

Rebound effect is a feedback effect of the arc rotate the camera to the limit position settings. By BABYLON.BouncingBehaviordefault instantiate an instance of an object implementation, create an arc rotating camera BABYLON.BouncingBehaviorclass.
We can turn the rebound effect following code:

camera.useBouncingBehavior = true;

We can also camera.bouncingBehaviorset some details about the rebound effect subject:

camera.bouncingBehavior.transitionDuration = 450; //回弹效果的过渡时间
camera.bouncingBehavior.lowerRadiusTransitionRange = .5; //到达最近距离时回弹的幅度距离,默认值为2
camera.bouncingBehavior.upperRadiusTransitionRange = -20; //达到最远距离时的回弹幅度距离,默认值为-2
camera.bouncingBehavior.autoTransitionRange = true; //是否开启自动定义lowerRadiusTransitionRange和upperRadiusTransitionRange值,默认值为false。过渡范围设置为世界空间中对角线框的5%

The current configuration properties defined:

  • transitionDuration: define the duration of the animation, in milliseconds. By default, this value is set to 450 ms
  • lowerRadiusTransitionRange: length reaches the radius defined by the set distance of the transition animation. By default, this value is set to 2
  • upperRadiusTransitionRange: length defined by the set reaches the radial distance of transition animation. By default, this value is set to -2
  • autoTransitionRange: Define a value that indicates whether to automatically define and lowerRadiusTransitionRange upperRadiusTransitionRange. The transition range will be set to 5% of the world space bounding box diagonal

You can here find an official example.

Auto rotation effect

Automatic camera rotation effect is the arc of rotation A when no user interaction to automatically rotate around focus effect. By BABYLON.AutoRotationBehaviorrealization.
You can directly open the following code:

camera.useAutoRotationBehavior = true;

You can also set up camera.autoRotationBehaviorto define the details of the automatic rotation of the object attributes:

camera.autoRotationBehavior.idleRotationSpeed = 1; //自动旋转速度
camera.autoRotationBehavior.idleRotationWaitTime = 1000; //用户交互后多少时间开启自动旋转(毫秒)
camera.autoRotationBehavior.idleRotationSpinupTime = 1000; //从开始自动旋转到设置的旋转速度所需要的时间(毫秒)
camera.autoRotationBehavior.zoomStopsAnimation = true; //设置缩放是否会停止自动旋转
  • Here you can check out the official examples

Automatic positioning function

Automatic positioning function can automatically locate the position of the arc of rotation of the camera, automatically returns to a position after the user stops operating. For example, you want to prevent virtual camera in a horizontal plane, this is useful.
You can open the following code:

camera.useFramingBehavior = true;

You can also set up camera.framingBehaviorto adjust the details of the properties of the object positioning function:

  • mode: Mode can be configured to:
  1. BABYLON.FramingBehavior.IgnoreBoundsSizeMode: The camera can always move toward grid
  2. BABYLON.FramingBehavior.FitFrustumSidesMode: adjusting the ratio of the camera is not allowed bounding sphere contacts the flat side surface of the frustum point closer mesh
  • radiusScale: definitions apply to the ratio of the radius (default 1)
  • positionY: the Y offset defines the primary focus of the camera grid (default 0)
  • defaultElevation: an angle to the horizontal plane defined above / below, so as to return the trigger returns the default height in the idle behavior in radians (default is 0.3)
  • elevationReturnTime: beta returned to the default position is defined by the time (in milliseconds) (default is 1500). A negative value indicates the camera should not return to the default value
  • elevationReturnWaitTime: define the delay before the camera returns to the default position Beta (in milliseconds) (default is 1000)
  • zoomStopsAnimation: definition of whether the user zooms should stop animation
  • framingTime: transition time when the grid frame is defined, in milliseconds (default is 1500)

You can here to see an example of official

Published 402 original articles · won praise 544 · Views 2.12 million +

Guess you like

Origin blog.csdn.net/qq_30100043/article/details/89077258
arc