
Tue, 03/25/2025 - 05:43
Forums:
Hi, I am using AIS_Animation to make an animation, but I got a weird result. I am new to opencascade, I am not sure if there is something wrong with my code. Here is my code:
TopoDS_Shape part = BRepPrimAPI_MakeBox(50.0, 50.0, 50.0).Shape();
gp_Trsf tsf;
tsf.SetTranslation(gp_Vec(80.0, 180.0, 0.0));
TopLoc_Location loc(tsf);
part.Move(loc);
Handle(AIS_Shape) aisPart = new AIS_Shape(part);
Handle(AIS_InteractiveContext) context = occtviewer->Context();
aisPart->SetHilightAttributes(context->SelectionStyle());
aisPart->SetDynamicHilightAttributes(context->HighlightStyle());
aisPart->Attributes()-> SetFaceBoundaryDraw(true);
aisPart->SetDisplayMode(AIS_Shaded);
context->Display(aisPart, Standard_True);
gp_Trsf current = aisPart->LocalTransformation();
gp_Trsf Transform;
Transform.SetRotation(gp_Ax1(gp_Pnt(80.0, 180.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), M_PI/4);
Handle(AIS_Animation) animation = new AIS_Animation("myAnimation");
Handle(AIS_AnimationObject) anime = new AIS_AnimationObject("test", context, aisPart, current, Transform);
anime->SetStartPts(0);
anime->SetOwnDuration(2.5);
animation->Add(anime);
occtviewer->setObjAnimation(animation);
occtviewer->startObjAnimating();
And I got the result as:
I just want the box to rotate, but it also moves some distance and then comes back. How should I deal with this?
Thank you !
Tue, 03/25/2025 - 08:20
This is how generalized linear interpolation between two transformations works - each
gp_Trsf
component (origin, rotation, scaling) is interpolated independently. You may implement your ownAIS_Animation
/AIS_AnimationObject
subclass that would do interpolation in the way you actually want. There is alsoAIS_AnimationAxisRotation
in OCCT 7.8+ for this kind of animation, but I haven't tried it personally.