Open Cascade 7.7.1 Animation AIS_Animation

Table of Contents

  • 1 Introduction
  • 2. How to use
    • 2.1. Object transformation animation
    • 2.2. Camera transformation animation
    • 2.3. Multi-object + camera simultaneous transformation animation
  • 3. OCC 7.7.1 upgrade instructions
  • 4. Doubt
  • References

?Reprint please indicate the original link: https://blog.csdn.net/Mechanicoder/article/details/130539644

1. Introduction

3D animation effects are very common in some software. Animation helps users observe the trajectory of changes in models or perspectives, avoid sudden changes in the screen, and improve the interactive experience.

The object position animation transformation and camera perspective animation transformation displayed in the 3D view in OCC are implemented by AIS_Animation. The object transformation animation is AIS_AnimationObject, and the camera transformation animation is AIS_AnimationCamera:
AIS_Animation
Model transformation animation + camera transformation animation

2. How to use

Since there is no separate rendering sub-thread, the animation is refreshed by blocking the main thread:

Handle(AIS_Animation) anim = ...;
anim_object->SetOwnDuration(obj_duration); // set the time
ais_animation->StartTimer(0, 1.0, true); // start timer
while (!anim->IsStopped())
{<!-- -->
    anim->UpdateTimer();
    _context->UpdateCurrentViewer();
}

An animation AIS_Animation can be understood as a time axis, on which multiple animations can be added through the method Add to achieve the effect of playing multiple animations at the same time. Because of the inheritance relationship of AIS_Animation, object animation and camera animation can be played at the same time, as shown in Section 2.3.

//! Add single animation to the timeline.
//! @param theAnimation input animation
Standard_EXPORT void Add (const Handle(AIS_Animation) & theAnimation);

Multiple animation timelines work similarly to timelines in video editing.
Video editing timeline

2.1. Object transformation animation

AIS_AnimationObject initialization interface is:

 //! Constructor with initialization.
  //! Note that start/end transformations specify exactly local transformation of the object,
  //! not the transformation to be applied to existing local transformation.
  //! @param[in] theAnimationName animation identifier
  //! @param[in] theContext interactive context where object have been displayed
  //! @param[in] theObject object to apply local transformation
  //! @param[in] theTrsfStart local transformation at the start of animation (e.g. theObject->LocalTransformation())
  //! @param[in] theTrsfEnd local transformation at the end of animation
  Standard_EXPORT AIS_AnimationObject (const TCollection_AsciiString & amp; theAnimationName,
                                       const Handle(AIS_InteractiveContext) & theContext,
                                       const Handle(AIS_InteractiveObject) & theObject,
                                       const gp_Trsf & theTrsfStart,
                                       const gp_Trsf & theTrsfEnd);

It should be noted here that the theTrsfStart and theTrsfEnd of the input parameters refer to the “local transformation” of the object theObject – the object position strong> absolute value, not relative value, for example theTrsfStart can directly get the object’s current position transformation theObject->LocalTransformation(). And when the starting transformation is not the transformation theObject->LocalTransformation() of the object’s current position, the object will jump, that is, the specified starting position theTrsfStart transitions to the end position theTrsfEnd regardless of the current position. For example, the starting position of the object is a unit transformation, and the ending position is a 90° rotation around the axis ax1. The implementation code is:

gp_Trsf start_trsf, end_trsf;
gp_Ax1 ax1(gp_Pnt(10, 0, 0), gp_Vec(0, 1, 0));
end_trsf.SetRotation(ax1, M_PI_2);
Handle(AIS_AnimationObject) ani_object = new AIS_AnimationObject("Object", _context, first_obj, start_pnt, end_pnt);

Repeat the execution of the previous piece of code, there will be a jumping phenomenon:
Specify to insert picture description here

A concept is introduced here: object position. It can be simply understood that when the object is rendered, a transformation is applied to the triangle data of the object itself, so that the object is displayed at the desired position. For example, if you want to render and display a unit sphere whose center is at the origin at (10, 10, 10), you only need to set the position transformation of the object display object:

Handle(AIS_InteractiveObject) ais_ball;
gp_Trsf ball_trsf;
ball_trsf. SetTranslation(gp_Vec(10, 10, 10));
ais_ball->SetLocalTransformation(ball_trsf);

For details, please refer to the official OCC document: AIS_InteractiveObject

2.2. Camera transition animation

AIS_AnimationCamera

//! Define camera start position.
void SetCameraStart (const Handle(Graphic3d_Camera) & amp; theCameraStart) {<!-- --> myCamStart = theCameraStart; }
//! Define camera end position.
void SetCameraEnd (const Handle(Graphic3d_Camera) & amp; theCameraEnd) {<!-- --> myCamEnd = theCameraEnd; }

The viewing angle switching animation is completed between two camera viewing angles, and the starting camera position and the ending camera position are set respectively. Implementation code:

gp_Trsf end_trsf;
gp_Ax1 ax1(gp_Pnt(10, 0, 0), gp_Vec(0, 1, 0));
end_trsf.SetRotation(ax1, M_PI_2);
Handle(Graphic3d_Camera) camera_start = _view->GetView()->Camera();
Handle(Graphic3d_Camera) camera_end = new Graphic3d_Camera();
camera_end->Copy(camera_start);
camera_end->Transform(end_trsf);
Handle(AIS_AnimationCamera) ani_camera = new AIS_AnimationCamera("Camera", _view->GetView());
ani_camera->SetCameraStart(camera_start);
ani_camera->SetCameraEnd(camera_end);

Rotate the camera 90° positively around axis ax1. Note: Camera transforms and model transforms are visually opposite in the same 3D view.
Camera perspective switching animation

2.3. Multi-object + camera simultaneous transformation animation

Multi-pair transformation animation

3. OCC 7.7.1 Upgrade Instructions

In the OCC 7.7.1 version, the support for rotation transformation is optimized, and the object animation AIS_AnimationAxisRotation specially for rotation transformation is added to solve the intermediate process of object rotation animation in previous versions Incorrect question (bug32570 incorrect middle process of rotating animation around the axis), refer to OCC developer Kirill Gavrilov’s reply to this question.

Taking the object transformation animation AIS_AnimationObject as an example, when updating the animation frame, the intermediate transformation is obtained by transformation interpolation gp_TrsfNLerp, that is, translation, rotation, and scaling are interpolated respectively and combined into New transform, unable to get correct transform path.

void NCollection_Lerp<gp_Trsf>::Interpolate (double theT, gp_Trsf & amp; theResult) const
{<!-- -->
  ...
  gp_XYZ aLoc;
  gp_Quaternion aRot;
  Standard_Real aScale = 1.0;
  myLocLerp.Interpolate(theT, aLoc);
  myRotLerp.Interpolate(theT, aRot);
  myScaleLerp. Interpolate(theT, aScale);
  theResult = gp_Trsf();
  theResult. SetRotation(aRot);
  theResult. SetTranslationPart(aLoc);
  theResult. SetScaleFactor(aScale);
}

Therefore, using AIS_AnimationObject in the previous version or the new version, the effect of object transformation animation is:
Wrong intermediate process

However, the latest version of OCC 7.7.1 still does not get the correct intermediate pass for pivoting camera animations. Apparently, this is also caused by linear interpolation for the translation and rotation components of gp_Trsf in animation AIS_Animation.

4. Question

  1. How can the animation play along the correct transformation path for any transformation?
  2. The actual playback time of the animation is less than the blocking time of the main thread? After the fast playback of the animation is completed, it is still blocked until the set time ends.

?
Source code of this article

Please indicate the original link for reprinting: https://blog.csdn.net/Mechanicoder/article/details/130539644

References

1. OCC blog How to rotation arround an axis parallel to the Y-axis
2. Open Cascade 7.7.0 AIS_Animation

syntaxbug.com © 2021 All Rights Reserved.