Matlab 3D figure to 3D (X)HTML

version (436 KB) by Dirk-Jan Kroon
Converts 3D objects of a Matlab figure to XHTML embedded X3D file. Interactive 3D website graphics.


Updated 17 Aug 2011

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function FIGURE2XHTML converts the 3D objects of a Matlab figure to an in XHTML embedded X3D file. In a modern browser, you can then view your figure interactively because of the great X3DOM Library (Instant 3D the HTML way!

Currently the function supports: Axes, Patch, Line, Surface, Text, Images and Light Objects.

Note: Even volume rendering in your browser is possible, by using:

Browsers supported:
- Google Chrome 9.x and above
- Firefox 4.x and above
- Webkit nightly builds
- Flash11 needed for Internet explorer (or InstantReality-plugin)


Note : All input arguments are optional, and sorting doesn't matter
thus figure2xhtml(); is valid but also figure2xhtml(options,handle);

filename : Name of the XHTML file (also an X3D file is created).
When empty or not known a File-Dialog is shown
handle : Figure handle or axis handle
When empty or not known the current axis (GCA) is used
options : A struct with options
options.output : Produce output files 'x3d', 'xhtml' or 'both' (default)
options.width : Width of X3D render object in pixels default 500
options.height : Height of X3D render object in pixels default 500
options.headlight : Enable Camera head light, boolean true/false
(default true)
options.title : Title of xhtml page, default 'Matlab X3D'
options.interactive : Make mesh/surface objects clickable in xhtml,
boolean true/false (default false)

figure, hold on; axis equal;
patch(FV,'facecolor',[1 0 0],'facealpha',0.5);

Cite As

Dirk-Jan Kroon (2022). Matlab 3D figure to 3D (X)HTML (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Export figure to 3D interactive PDF

Community Treasure Hunt

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

Start Hunting!