%% Convert MATLAB Patches to IndexedFaceSet Nodes
% This command converts three MATLAB® patches to IndexedFaceSet nodes.
% Create surface using MATLAB peaks function.

fig = figure('Name','Source peaks surface');
s = surf(peaks);

%
% Convert the peaks surface to a patch.

peaksPatch = patch(surf2patch(s));
delete(s);
shading interp;

%
% Create and open an empty virtual world.

w2 = vrworld('');
open(w2);

%
% Create and bind viewpoint

dv = vrnode(w2, 'DefaultViewpoint','Viewpoint');
dv.position  = [-1 15 30];
dv.orientation = [-0.38 -0.93 0 0.55];
setfield(dv,'set_bind',true); %#ok<STFLD,SFLD>

%
% Convert the patch to an IndexedFaceSet nodes. The resulting nodes are created in the root level of supplied vrworld object)

vrpatch2ifs(peaksPatch,w2);

%
% Show the result.

vrfig2 = vrfigure(w2,'Name',...
         'Virtual world containing resulting IndexedFaceSet node');

%
% Copyright 2012 The MathWorks, Inc.