Importing Google Sketchup models in Mathematica

馋奶兔 提交于 2019-12-03 01:42:47

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.

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]

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!