4.57143

4.6 | 7 ratings Rate this file 48 Downloads (last 30 days) File Size: 435.69 KB File ID: #32207
image thumbnail

Matlab 3D figure to 3D (X)HTML

by Dirk-Jan Kroon

 

13 Jul 2011 (Updated 17 Aug 2011)

Converts 3D objects of a Matlab figure to XHTML embedded X3D file. Interactive 3D website graphics.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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! http://www.x3dom.org/).
 
Currently the function supports: Axes, Patch, Line, Surface, Text, Images and Light Objects.

Note: Even volume rendering in your browser is possible, by using: http://www.mathworks.com/matlabcentral/fileexchange/19155-volume-render

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

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

 inputs,
    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)
                    
 
 
  Example,
   load('functions\exampledata');
   figure, hold on; axis equal;
   patch(FV,'facecolor',[1 0 0],'facealpha',0.5);
   FV.vertices(:,1)=FV.vertices(:,1)+80;
   patch(FV,'FaceColor','interp','FaceVertexCData',rand(size(FV.vertices)),'edgecolor','none');
   FV.vertices(:,1)=FV.vertices(:,1)+80;
   patch(FV,'FaceColor','flat','FaceVertexCData',rand(size(FV.faces)),'edgecolor','none');
   figure2xhtml('test/example1')

MATLAB release MATLAB 7.12 (2011a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (20)
20 Jul 2011 Sven Körner

This is pretty cool.
Is there a way how to get the coordinate system (x,y and z-axis) of a function in the 3D-graph?

20 Jul 2011 Dirk-Jan Kroon

*Sven Körner
Axis are not supported by the x3dom library, but text and lines are.
Thus a solution can be to draw the axis your self using plot3 in Matlab

20 Jul 2011 Oliver Woodford

Absolutely brilliant.

20 Jul 2011 Dirk-Jan Kroon

*Sven Körner
I added an example with axis to xhtml in the last update (is probably online tomorrow).

21 Jul 2011 Sven Körner

Thank's for update - it works well! For my 3D-HTML version I used javaview - there is the axis option already embedded.(http://wwwpub.zih.tu-dresden.de/~s9034647/peaksurface.html)
But in the tool to embded u3d files in pdf - there is actually also no axis-feature (http://www.mathworks.com/matlabcentral/fileexchange/27245-generate-vertices-faces-and-color-for-u3d-format). Maybe I can use your axis2lines function?

22 Jul 2011 Dirk-Jan Kroon

*Sven Körner
Nice tools, Javaview is indeed a very extensive 3D viewer for the web.

I don't know the u3d-file format, but maybe it is possible to include line geometry thus allow axis2lines function.

There are way to many geometry-file formats, hopefully they will merge sometime.

22 Jul 2011 Petter

Comments are almost completely absent from the code.

12 Aug 2011 xu

Comments are almost completely absent from the code.

15 Aug 2011 Ben

Is there a way to specify the title, the header, and the object name? That would be very helpful. Otherwise, one has to modify the xhtml source code every time, which could be tedious...

Give you 4 stars because the tool is cool!

16 Aug 2011 Dirk-Jan Kroon

*Ben
The latest version supports options like a title.

19 Aug 2011 Nino

I test it with the MRI brain of Matlab and is not working, but cheek it with your example and is pretty cool. Thanx for sharing

20 Aug 2011 Dirk-Jan Kroon

*Enedino
Do you get an error with your MRI data?, or know what is the problem?

24 Aug 2011 Ben

Could I use the same viewpoint as that for the figure?

25 Aug 2011 Dirk-Jan Kroon

*Ben,
The same viewpoint is not supported.

The camera in Matlab is a little bit strange, (almost) orthogonal, allows non-uniform x,y scaling and does some tricks to stay outside the rendered object. Thus porting the viewpoint to X3D gave strange results.

29 Sep 2011 Alexander Brodsky

very exciting option.
It can be interesting include of your option as apart of publish MATLAB function.
Or may be you know how to do that ?

11 Nov 2011 Bruce Heu

Thanks for the awesome work. I have been looking for this kind of program for a long time. I really want to explore it. However, I cannot get it to work on my computer. Running the matlab code has no problem. When I tried to open the xhtml file using the latest IE with adobe 11 installed, the web page just show X3DOM Loading Scene... and it neven show up.

I tried to open the xhtml file using the lastest Chrome also. The progrom says that Matalb X3D not responsive and nothing show up also.

Does anybody has the same problem I had and happen to know what may be the reasons, how to fix it?

Thanks....

19 Dec 2011 Siva Srinivas Kolukula

       Very good work....I have been searching for saving a MATLAB figure interactively into html. Searched and found the MATLAB builder ja which is bit complicated. My further search landed me here. Very good work.
       But I have a problem in this. I ran these files and saved html version in test folder. I tried to open it with chrome and mozilla which are leatest, I get a blank screen showing X3DOM downloading the secene, but never I am getting the interactive image. Flash player is installed.
Why is it? Any solution?

Thanks....
Sreenu
https://sites.google.com/site/kolukulasivasrinivas/

21 Feb 2012 Alex

Does this plugin support color images as texture or just grayscale images?

18 Mar 2012 Truong

I ran on a 3-D figure (created with patches) and got the following error:
??? SWITCH expression must be a scalar or string constant.

Error in ==> addmesh at 142
    switch(Obj.FaceColor)

Error in ==> figure2xhtml>figurex3d at 196
            data=addmesh(data,loc_scene,Obj);

Error in ==> figure2xhtml at 164
    data=figurex3d(haxis,data,loc_scene);

The examples provided with the function ran well without errors.

10 May 2012 Laila

amazing!

mini question: is there anyway to get it to work with elements from an hggroup (such as quiver3?).

Please login to add a comment or rating.
Updates
15 Jul 2011

- Added Surface Texture Support
- Fixed NaN bug in vertex-normals

20 Jul 2011

added text support, and example with axis in xhtml.

21 Jul 2011

Font-size adjustment

02 Aug 2011

Added Line-Marker support

03 Aug 2011

Added images support.
Added reverse axis support.

03 Aug 2011

added alphamap support

16 Aug 2011

Added options

17 Aug 2011

Improved Internet Explorer support

Tag Activity for this File
Tag Applied By Date/Time
xhtml Dirk-Jan Kroon 13 Jul 2011 10:39:20
x3d Dirk-Jan Kroon 13 Jul 2011 10:39:20
webgl Dirk-Jan Kroon 13 Jul 2011 10:39:20
html5 Dirk-Jan Kroon 13 Jul 2011 10:39:20
html Dirk-Jan Kroon 13 Jul 2011 10:39:20
patch Dirk-Jan Kroon 13 Jul 2011 10:39:20
interactive Dirk-Jan Kroon 13 Jul 2011 10:39:20
web Dirk-Jan Kroon 13 Jul 2011 10:39:20
browser Dirk-Jan Kroon 13 Jul 2011 10:39:20
firefox Dirk-Jan Kroon 13 Jul 2011 10:39:20
graphics Dirk-Jan Kroon 13 Jul 2011 10:39:20
lines Dirk-Jan Kroon 13 Jul 2011 10:39:20
surface Dirk-Jan Kroon 13 Jul 2011 10:39:20
3d Dirk-Jan Kroon 13 Jul 2011 10:39:20
visualization Dirk-Jan Kroon 13 Jul 2011 10:39:20
opengl Dirk-Jan Kroon 13 Jul 2011 10:39:20
vrml Dirk-Jan Kroon 14 Jul 2011 07:04:04
xml Dirk-Jan Kroon 14 Jul 2011 07:04:41
potw Lindsay Coutinho 22 Jul 2011 10:35:12
pick of the week Lindsay Coutinho 22 Jul 2011 10:35:12

Contact us at files@mathworks.com