gkv311 / occt-samples-qopenglwidget

Open CASCADE Technology sample - 3D Viewer within Qt Widgets window
Other
55 stars 16 forks source link

Animation #10

Closed batuhancengiz closed 1 year ago

batuhancengiz commented 1 year ago

Hello Kirill,

I have two project which are written in c# and c++ with qt. In c# project I use OCCTProxy like you did and animation works like a charm. But when I use same code for this sample project I mean c++ project, does not work at all. I definitely don't understand what is the difference between them.

I'm going to add my animation class. For my improvement your ideas are very important to me so I'll wait your replies.

Animation.h.txt Animation .cpp.txt

gkv311 commented 1 year ago

Your sample code has several issues:

AIS_ViewController has defined interface for working with animations in a predictable way (e.g., to solve above-mentioned issues). You may find it as AIS_ViewController::ViewAnimation() and AIS_ViewController::ObjectAnimation() properties. The main difference between the two is that ViewAnimation is designed for camera animations and will be automatically interrupted on user input - you may see this in action while displaying AIS_ViewCube, clicking on its side and then clicking on the viewer before animation is finished. ObjectAnimation will not be interrupted in this case as it is intended to animate objects in the scene.

You may already see how AIS_ViewCube is connected to AIS_ViewController::ViewAnimation in qopenglwidget sample.

Within another sample project you may also find usage of AIS_ViewController::ObjectAnimation, although tutorial is not focused on animation aspects and doesn't provide details on this topic: https://github.com/gkv311/occt-hello/tree/master/occt-ais-object

batuhancengiz commented 1 year ago

I understand you and what problem is but I have one question about AIS_ViewCube. Because I animate the view for projection with almost same code with AIS_ViewCube, even maybe you notice I create viewAnimation object with parameter "AIS_ViewCube". My question is how AIS_ViewCube works and my code does not work. What is the difference? To me I don't see any difference but compiler doesn't say like that.

And codes just these below for AIS_ViewCube : myViewCube = new AIS_ViewCube(); myViewCube->SetViewAnimation (myViewAnimation); myViewCube->SetFixedAnimationLoop (false); myViewCube->SetAutoStartAnimation (true);

I have created animation class with same way you did actually.

Thank you Kirill for answer, I'm appreciated.

gkv311 commented 1 year ago

By default, AIS_ViewCube creates it's own AIS_AnimationCamera object and performs redrawing of a viewer in a loop (IsFixedAnimationLoop = true) like your code does, and it will have the same problems.

AIS_ViewCube::SetViewAnimation() overrides custom animation object with the object managed by AIS_ViewController, and SetFixedAnimationLoop(false) disables code redrawing V3d_View in a loop.

Instead, AIS_ViewCube justs starts animation timer. All you need then is flushing events in AIS_ViewController once - it will check ViewAnimation object on redraw, will update animation to actual presentation time, and will mark viewer that it should keep redrawing one more frame again and again, until animation is finished.

But this redrawing is not done in a loop - it is done by posting paint message into window event loop. This is platform-specific interface, you may find this handled within OcctQtViewer::handleViewRedraw() method redirecting myToAskNextFrame (which is set by AIS_ViewController, when it sees ViewAnimation is played) to QOpenGLWidget::update(), which is Qt-specific way to ask redrawing.

void OcctQtViewer::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
                                     const Handle(V3d_View)& theView)
{
  AIS_ViewController::handleViewRedraw (theCtx, theView);
  if (myToAskNextFrame)
  {
    // ask more frames for animation
    updateView();
  }
}
batuhancengiz commented 1 year ago

I figure it out after your answer with setting QWidget::repaint(). Now it works. Thanks.