Wed, 01/24/2024 - 12:25
Forums:
Hi Everyone:
I have tried to use AIS_Animation and AIS_AnimationObject to do a basic Two-link Animation. And when I click the Winform button, then start to play animation. The animation code is written in the OCCTProxy project, which is a function. But when I clicked, things did not happen. And here is my code: It first sets the two link's start_pnt and end_pnt individually and adds to the animation object. Then play in the while loop. Does anyone have any idea?
// Animation function void MOVJAnimation( void ) {
// add animation object
Handle( AIS_Animation ) ais_animation = new AIS_Animation( "MOVJ_project" );
gp_Trsf start_pnt_axis1, start_pnt_axis2;
// C1, C2 = 0 deg
start_pnt_axis1.SetValues( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 );
start_pnt_axis2.SetValues( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 );
// C1 = 80 deg, C2 = 50 deg
int index = 0;
for( auto iter = CADModel().begin(); iter != CADModel().end(); iter++ ) {
if( index == 0 ) {
gp_Trsf end_pnt_axis1 = iter->Location().Transformation();
gp_Ax1 axe1 =
gp_Ax1( gp_Pnt( end_pnt_axis1.Value( 1, 4 ), end_pnt_axis1.Value( 2, 4 ), end_pnt_axis1.Value( 3, 4 ) ), gp_Dir( 0, 0, 1 ) );
end_pnt_axis1.SetRotation( axe1, 90 * M_PI / 180. );
Handle( AIS_AnimationObject ) ais_ao =
new AIS_AnimationObject( "MOVJ_project", myAISContext(), new AIS_Shape( *iter ), start_pnt_axis1, end_pnt_axis1 );
ais_ao->SetOwnDuration( 5 );
ais_ao->SetStartPts( 0 );
ais_animation->Add( ais_ao );
}
else if( index == 1 ){
gp_Trsf end_pnt_axis2 = iter->Location().Transformation();
gp_Ax1 axe1 = gp_Ax1( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
gp_Ax1 axe2 = gp_Ax1( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 1, 0 ) );
axe2.Rotate( axe1, 90 * M_PI / 180. );
end_pnt_axis2.SetRotation( axe2, 50 * M_PI / 180. );
Handle( AIS_AnimationObject ) ais_ao =
new AIS_AnimationObject( "MOVJ_project", myAISContext(), new AIS_Shape( *iter ), start_pnt_axis2, end_pnt_axis2 );
ais_ao->SetOwnDuration( 5 );
ais_ao->SetStartPts( 0 );
ais_animation->Add( ais_ao );
}
else {
}
index++;
}
// clear old transformation model
// myAISContext()->RemoveAll( Standard_False );
double duration = ais_animation->Duration();
ais_animation->StartTimer( 0, 1.0, Standard_True, Standard_False );
while( !ais_animation->IsStopped() ) {
ais_animation->UpdateTimer();
myAISContext()->UpdateCurrentViewer();
}
return;
}
Thu, 01/25/2024 - 14:47
Hello, which version of OCCT do you use? (It helps us to reproduce and analyze)
Best regards, Dmitrii.
Fri, 01/26/2024 - 09:25
Hi, I use OCCT 7.5.0 version. Thanks for your help!
Fri, 01/26/2024 - 14:37
Thank you, I will ask vis team about your issue, But 7.5 a little old and probably there will be some differences with 7.8. If there will be not a respons for a time, please send a new comment to remind.
Best regards, dmitrii.
Mon, 01/29/2024 - 11:40
Hi Pasukhin,
Could I ask another question about visualization? I try to measure the time which updates the view. The code is as follow :
for( int i = 0; i < size; i++ ) {
auto start_time = std::chrono::high_resolution_clock::now();
JointRotate( C1_offset * ( i + 1 ), C2_offset * ( i + 1 ), Standard_True );
auto end_time = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>( end_time - start_time ).count() << std::endl;
}
The function JointRotate includes calculating the new transformation of the CAD file (didn't generate the new model, only changed its transformation) and updateCurrentView. It costs about 16ms once in a time although I change the fps of the screen( 50 ~ 70 HZ ). Is the method of measuring is correct or not?
Mon, 01/29/2024 - 12:20
Hello, I will share this question too. Nowadays, we have a lot of experience with animation.
Best regards, Dmitrii.