Importing Google Sketchup models in Mathematica

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.


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.


这是成功将免费版本的SketchUp 8.0生成的.dae文件导入到Mathematica 8中的代码。此代码未检测到或对变换起作用,它仅查看坐标和三角形,因此不要期望太多。

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]

The route I currently follow involves a number of steps:

  • Download the SKP file from the Google repository
  • Open it in the free version of Sketchup
  • Export it from there as DAE
  • Convert it to FBX format using the free AutoDesk fbx converter (deep down the page here)
  • Using the same program, convert the FBX file just created to either DXF or OBJ
  • 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.

    在这里输入图像描述

    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

    链接地址: http://www.djcxy.com/p/35556.html

    上一篇: Mathematica:3D图形中的栅格

    下一篇: 在Mathematica中导入Google Sketchup模型