Importing Google Sketchup models in Mathematica
Asked Answered
C

4

18

Google's Sketchup is a nice, simple 3D-object modeler. Moreover Google has an enormous warehouse of 3D objects so that you actually don't have to do much modeling yourself if you aren't particularly gifted in this area. Many of the 3D buildings in Google Earth are made with Sketchup. The capability to import Sketchup's SKP files in Mathematica would be very nice, but alas, it doesn't do that yet.

The free version of Sketchup doesn't export to any other formats than the KMZ (Google Earth) and DAE (Collada) formats. Though MMA can read KMZ/KML files it doesn't read those containing 3D objects. DAE files are zipped Collada files and these can be read as XML by MMA's Import. The resulting XML tree is rather complex as is the definition of Collada and getting at the geometry of the object is far from trivial (I managed to coerce the coordinate set of a model from it).

My question is: How to convert SKP files in a clean polygon based structure in Mathematica?

I would prefer an import converter that provides MMA with this import capability, but other routes are welcome too. I'll post the rather indirect method I'm currently using as an answer tomorrow.

Colton answered 5/6, 2011 at 22:41 Comment(9)
From designcad.com.au/Sketchup/export_models.pdf: This fundamental difference in storing model geometry places severe limitations on the model when it arrives in the CAD environment.Listel
@Sjoerd Did you check this one: forums.sketchucation.com/viewtopic.php?f=323&t=33448Listel
@belisarius Your 1st comment: This is not really a problem for me. Having an unstructured list of polygons is fine for my application. Your 2nd comment: looks promising, I'm awaiting my registration confirmation so that I can download the plug-in. If it works, I suggest you post this as an answer to receive credit.Colton
@Sjoerd If the link works write yourself an answer, since I only did a Google search. Good luck with it!Listel
@belisarius I tried the OBJexporter and overall it works OK, but it inserts references to separate texture files into the .obj file which the mma importer doesn't handle. So, after importing, the display shows the 3D model in a pink box, indicating several errors. The 3D geometry seems to be OK though.Colton
@Sjoerd So the result should be similar to your method ... not a great improvementListel
@belisarius The DXF branch of the method I used is better than the OBJ branch. The former returns the correct face colors, for all faces that are not textured. The latter gives me an uncolored, untextured 3D object. For me, not a big deal, as I only needed the geometry, but others might need all information. For people not interested in textures, the OBJexporter plugin in Sketchup will save a little bit of time wrt to my method.Colton
You could suggest to support that they should include Collada import/export support, especially considering that this is an open format supported by many programs, and particularly because the free version of SketchUp can export it ...Ingratiating
@Ingratiating Arnoud was going to suggest this to the developers. Haven't heard anything since.Colton
C
4

It's probably not exactly what you're looking for, but I maintain a python library called pycollada. You could use it to export to Mathematica's format. I've also been working on an import/export/convert utility called meshtool which you could write a module for that would export to Mathematica's format.

Calender answered 5/6, 2011 at 22:56 Comment(3)
OBJ and Three.js are on my list, but right now it only support collada, both import and export.Calender
Thanks! I'm not really into Python, but perhaps somebody who's fluent in Mathematica and Python may jump in here?Colton
Hi Sjoerd, this is a kind of late answer but maybe check out Pythonika. I used it a while back to link some serial IO stuff I had in Python to Mathematica (before I realized Mathematica has a serial IO package). If you need specifics shoot me an email and I'll see what I can find.Miletus
C
4

The route I currently follow involves a number of steps:

  1. Download the SKP file from the Google repository
  2. Open it in the free version of Sketchup
  3. Export it from there as DAE
  4. Convert it to FBX format using the free AutoDesk fbx converter (deep down the page here)
  5. Using the same program, convert the FBX file just created to either DXF or OBJ
  6. Import in Mathematica.

The results are pretty good, though you seem to lose the textures. Figures below show the results. Left: the original Sketchup model, middle: conversion/import via DXF, right: conversion/import via OBJ.

enter image description here

Obviously, you don't want to do this all too often, and for the specific application I'm working on I'd like a solution that users that aren't very computer savvy can handle too.


Update:

As of version 10.4 Mathematica has the capability to import and export DAE files: https://reference.wolfram.com/language/ref/format/DAE.html

Colton answered 6/6, 2011 at 11:15 Comment(0)
P
4

Here is code that successfully imported a very simple .dae file produced by the free version of SketchUp 8.0 into Mathematica 8. This code is not detecting or acting on transformations, it only looks at coordinates and triangles, so don't expect too much.

data = Import[SystemDialogInput["FileOpen"], "XML"]; 

points = Map[( Partition[ReadList[StringToStream[#[[1]] ], Number], 
3]) &, (Map[Part[#, 3] &, (Partition[
Cases[data, XMLElement["float_array", _, _], Infinity], 
2][[All, 1]])] ) ];

triangles = Map[Partition[1 + ReadList[StringToStream[#[[1]]], Number],3] &, 
Map[Part[#, 3, 2, 3]&, 
Cases[data, XMLElement["triangles", _, _], Infinity]]];

Graphics3D[Map[GraphicsComplex[#[[1]], Polygon[#[[2]]]] &, 
Transpose[{points, triangles}]], Boxed -> False]
Polysepalous answered 12/10, 2012 at 18:53 Comment(0)
G
2

The answer depends on what you want to do exactly. If you just want to see the image you could export as an .obj file (tessellation file, not object code!).

Try this for example:

bunny = Import["http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj", "OBJ"]

If you actually want to work with it as a solid model you're going to have a more difficult time. Solid models have fairly complex data structures to represent the topology as well as the geometry. You might be able to get the surfaces out of the model for example, but you'll have to have some topology to say what portion of the surface is used by a face.

Ghyll answered 6/6, 2011 at 7:25 Comment(3)
THE problem is, as I stated in the question, to turn Sketchup's SKP files into something mma can import. I know that it can import .obj's. I use that already and that was not the question. The free version of Sketchup doesn't export to obj.Colton
@sjoerd-c-de-vries Sketchup can export to COLLADA (dae). You can import that into blender and then export as OBJ. It's a pain, but it should work.Calender
@Calender I know about the DAE export and mentioned this in the question.Colton

© 2022 - 2024 — McMap. All rights reserved.