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

1 visualizzazione (ultimi 30 giorni)
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?

Risposte (2)

Jan Danek
Jan Danek il 13 Lug 2012
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 il 16 Lug 2012
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 Commento
Jan Danek
Jan Danek il 23 Lug 2012
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

Accedi per commentare.

Categorie

Scopri di più su Simulation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by