在 Mathematica 中导入 Google Sketchup 模型

发布于 2024-11-13 09:19:42 字数 846 浏览 11 评论 0原文

Google 的 Sketchup 是一个漂亮、简单的 3D 对象建模器。此外,Google 拥有巨大的3D 对象仓库,因此您实际上不必进行太多建模如果您在这方面不是特别有天赋,那么您自己也可以。 Google 地球中的许多 3D 建筑物都是使用 Sketchup 制作的。在 Mathematica 中导入 Sketchup 的 SKP 文件的功能会非常好,但可惜的是,它还没有做到这一点。

Sketchup 免费版本不会导出为除 KMZ (Google Earth) 和 DAE (Collada) 格式之外的任何其他格式。虽然 MMA 可以读取 KMZ/KML 文件,但它不能读取包含 3D 对象的文件。 DAE 文件是压缩的 Collada 文件,这些文件可以通过 MMA 的导入以 XML 形式读取。生成的 XML 树相当复杂,Collada 的定义 以及获取对象的几何形状也是如此远非微不足道(我设法从中强制转换模型的坐标集)。

我的问题是:如何在 Mathematica 中将 SKP 文件转换为基于干净多边形的结构?

我更喜欢一个为 MMA 提供此导入功能的 导入转换器,但其他路线也受欢迎。明天我将发布我目前正在使用的相当间接的方法作为答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一绘本一梦想 2024-11-20 09:19:42

它可能不完全是你要找的,但我维护一个名为 pycollada 的 python 库。您可以使用它导出为 Mathematica 的格式。我还一直在开发一个名为 meshtool 的导入/导出/转换实用程序,您可以为其编写一个模块这将导出为 Mathematica 的格式。

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.

爱你不解释 2024-11-20 09:19:42

下面的代码成功地将免费版 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]

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]
装迷糊 2024-11-20 09:19:42

我当前遵循的路线涉及多个步骤:

  1. Google 存储库 下载 SKP 文件
  2. 打开它在免费版 Sketchup
  3. 中将其导出为 DAE
  4. 将其转换到使用免费 AutoDesk fbx 转换器的 FBX 格式(在页面深处 此处
  5. 使用相同的程序,将刚刚创建的 FBX 文件转换为
  6. Mathematica 中的 DXF 或 OBJ 导入文件。

结果相当不错,尽管你似乎失去了纹理。下图显示了结果。左:原始Sketchup模型,中:通过DXF转换/导入,右:通过OBJ转换/导入。

在此处输入图像描述

显然,您不想经常这样做,对于特定的应用程序,我我想要一个不太懂计算机的用户也可以处理的解决方案。


更新:

从版本 10.4 开始,Mathematica 能够导入和导出 DAE 文件:https ://reference.wolfram.com/language/ref/format/DAE.html

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

笑着哭最痛 2024-11-20 09:19:42

答案取决于您到底想做什么。如果您只想查看图像,可以导出为 .obj 文件(曲面细分文件,而不是目标代码!)。

尝试一下这个例子:

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

如果你真的想将它作为一个实体模型来使用,你将会遇到更困难的时期。实体模型具有相当复杂的数据结构来表示拓扑和几何。例如,您可能能够从模型中获取曲面,但您必须有一些拓扑来说明面使用了曲面的哪一部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文