Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm looking for a way to export 3D graphics objects to the Collada (.dae) format. I need an automated way, i.e. using Blender to manually convert from another format is not a good solution.

I'm sure all of the following is not possible at the same time, but ideally:

  • Aspect ratio (BoxRatios) should be preserved

  • Colours should be preserved (if possible)

  • Visible bounding box should be preserved (if possible)

  • Initial view point should be preserved when opening the file in a viewer (if possible)

  • Supporting Polygon and Cuboid is sufficient.


Information that would help me implement this myself:

  • Which formats that Mathematica supports can theoretically handle most of the requirements above? Out of these, which one does Mathematica have the best support for?

  • Are there command line programs or other Mathematica-controllable tools that can convert a Mathematica-exportable format to Collada?

share|improve this question

3 Answers 3

I've used Assimp for this, though I have never managed to preserve box ratios, the bounding box, or the view point.

Graphics3D[{
 Red,
 Cuboid[],
 Blue,
 Cylinder[]}];
Export["g.lwo", %]
Run["assimp.exe export g.lwo out.dae"]

enter image description here

For OS X, pre-compiled Assimp binaries are available in MacPorts.

share|improve this answer
    
Do you recommend 3DS as the intermediary format or you're also not sure which one is best? –  Szabolcs Jun 24 at 18:15
    
Yeah, I am unsure -- I just use 3DS out of habit because it has always met my needs. But the library supports quite a few formats. –  mfvonh Jun 24 at 18:19
    
This was very promising, but unfortunately both assimp 3.0 (MacPorts) and assimp 3.1.1 (compiled it) produces broken DAE files. Neither Blender, nor OS X Preview can read them. I tried a complex object as well as a simple Graphcis3D[{Cylinder[]}]. –  Szabolcs Jun 24 at 18:34
    
@Szabolcs Try .lwo, I was able to get that to open in Blender. Seems like 3DS is specifically not advisable because it's resulting in unescaped XML like this: <visual_scene id="<3DSDummyRoot>" name="<3DSDummyRoot>">. It seems to lose color info; it may be worth playing with the available formats. –  mfvonh Jun 24 at 18:51
    
Alternatively you could pass it back through Mathematica and try to clean up the XML lol –  mfvonh Jun 24 at 18:54

I have successfully exported many 3D Mathematica objects in the .stl format (used for 3D printing). I use Cheetah3D on the Mac (now $69) to work with the object, add axes or colors, then export as a .dae for use in Collada environments like iBooks Author. Maybe Google Sketchup would also work; it has Collada as a native format but not sure what it imports. Hope this helps!

share|improve this answer

Here is a way of getting Mathematica’s 3D graphics into COLLADA format — e.g. for importing into iBooks Author on OS X — whilst preserving colour information. Unfortunately, this involves a manual intermediate step using Blender, but it is the only way that I have found that automatically preserves colour.

The trick is to use the fact that Blender can import/export both COLLADA and PLY formats whilst preserving colour in both cases. After some experimentation, it seems that these are the only 2 formats for which Blender preserves colour.

So the chain of processing is:

  1. Mathematica exports PLY
  2. Blender imports PLY
  3. Blender exports COLLADA

Here is a demonstration of a typical use of this workflow in OS X, which starts with a 3D graphic in Mathematica, and finishes with the 3D graphic in an iBooks Author 3D widget.

Generate a 3D graphic in Mathematica.

g = ExampleData[{"Geometry3D", "SpaceShuttle"}]

enter image description here

Add some random colouring to the graphic.

g2 = g /. 
  GraphicsComplex[pts_, data_, opts___] :> 
    GraphicsComplex[pts, data, opts, 
      VertexColors -> Hue /@ RandomReal[{0, 1}, Length[pts]]]

enter image description here

Export the coloured graphic to PLY format.

Export["test.ply", g2]

Import the PLY graphic into Blender, where it can be viewed colourfully (in “Vertex Paint” mode, for instance), and changes to position, scaling, lighting (etc) can be made.

Export the graphic to COLLADA format from Blender.

Import (drag-and-drop) the COLLADA graphic into an iBooks Author 3D widget, then preview the iBook to interact with the 3D graphic.

enter image description here

I had to scale the 3D graphic in Blender — this could have been done in Mathematica — so that the final result is as shown.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.