How to record video file via m-code from vrworld which is displayed on vr.canvas

조회 수: 1 (최근 30일)
I have a simulation which uses Simulink 3D Animation through Matlab interface to display an animation in a GUI window. Now I need a button to record the view as a video file.
I show the 3D view in the GUI window like this:
myWorld = vrworld('mainWorld.wrl');
open(myWorld);
myCanvas = vr.canvas(myWorld, gcf, [10 10 500 500]);
And during the simulation I update the view like this
myWorld.MYOBJECT.point = [ new_x new_y new_z ];
and also change the view point etc. How can I write a code to record the view as a movie file? I tried to read the documentation, but the options I have seem very cumbersome. It seems the vrworld should be linked to a Simulink model (I have no Simulink in my simulation) and the Simulink model should be running to record a video. Do I need to make a dummy Simulink model and somehow synchronize it with my Matlab simulation?

답변 (2개)

Jan Danek
Jan Danek 2012년 7월 13일
Hi Antti,
Please look at the "MATLAB Animation Recording of Virtual Worlds Not Associated with Simulink Models" chapter of the Simulink 3D Animation documentation:
Basically, you need to set the time in the scene to be controlled by you:
set(virtual_world,'TimeSource', 'external')
An then do something like this in a loop:
for time=StartTime:Step:StopTime
% advance the time in the virtual scene set(virtual_world,'Time',time);
% here we change VRML nodes properties
virtual_world.Car.translation = [ time*speed 0 0 ];
% render the changed position
vrdrawnow;
end
Hope this helps,
Jan

Antti
Antti 2012년 7월 16일
Thanks Jan! How could I miss that part of the documentation. But I still have one problem: To record a video, a vrfigure is needed. Even though the VRML view is up and running on a vr.canvas inside my GUI window, I get
>> x = get(myWorld, 'Figures')
x =
vrfigure object: 0-by-0
So there are no vrfigures. I get a vrfigure, if I open the view using
>> view(myWorld);
but then the view is visible in two windows. Is there a way to get a vrfigure without opening the world in an additional window?
  댓글 수: 1
Jan Danek
Jan Danek 2012년 7월 23일
Hi Antti,
You are right, vr.canvas doesn't have the "Record2D" property that governs the 2D animation recording to a video file in vrfigure. You can do one of the following:
1. Combine the use of vr.canvas/capture method with VideoWriter to achieve the same effect. This will allow you to have complete control on when to capture the scene (you don't have to set world / figure properties to achieve the recording, you just do the capture when you need it and save the image to the output video file.)
2. Use the 3D animation recording. If you can accept that the result will be not an AVI file, but "VRML Animation File", this is connected to the underlying virtual world, and IMHO provides even more comfort when exploring the animation later using the "vrplay". Try this:
vrplay octavia_scene_anim
Another positive effect of this 3D animation is that its recording doesn't slow you down during your work with your GUI (writing text values is far less demanding than creating an AVI file).
All the best,
Jan

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by