0
$\begingroup$

This might be a bug, but I figured I'd ask here first to make sure it wasn't simply due to my unfamiliarity with the export process and the OBJ file format.

For some polyhedra, e.g. the example polyhedra in the docs, exporting works fine:

Export["test.obj", 
 Graphics3D @ 
  Polyhedron[{{0., 0., 0.6}, {-0.3, -0.5, -0.2}, {-0.3, 0.5, -0.2}, {0.6, 0., -0.2}}, {{2, 3, 4}, {3, 2, 1}, {4, 1, 2}, {1, 4, 3}}]]

However, for a slightly different polyhedron:

Export["test2.obj",
 Graphics3D @ 
  Polyhedron[{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0.5}, {0, 1, 0.5}, {1, 1, 0.5}, {1, 0, 0.5}}, {{1, 4, 3, 2, 1}, {5, 8, 7, 6, 5}, {1, 4, 8, 5}, {4, 3, 7, 8}, {3, 2, 6, 7}, {2, 1, 5, 6}}]

it fails, and sends the following error messages:

Export::type: Graphics3D cannot be exported to the OBJ format.

Export::type: RuleDelayed cannot be exported to the OBJ format.

This seems to be an honest, uncontroversial polyhedron, so I'm not sure what's going on.

What should be fixed here? Is it a bug? Is there a workaround?

$\endgroup$

1 Answer 1

2
$\begingroup$

I sort of figured this out just as I was about to post, but thought I'd share in case anyone else has the same problem, since I couldn't find it on SE. However, I haven't figured it out completely, and I'd love a more comprehensive answer.

One issue is that it's not an honest polyhedron: in the second argument, some of the polygonal faces are specified e.g. by {1, 4, 3, 2, 1}. That repetition of the first index 1 at the end (which arises e.g. from FindShortestTour) breaks the export. However, it does not affect the presentation of the polyhedron in Mathematica, so it can be hard to spot.

But there are issues: apparently self-intersection can prevent export. For this reason, it's best to convert the Polyhedron to a MeshRegion before export. A function can be written to convert this by hand, argument pattern by argument pattern, but I'd be interested if anyone has a better, more canonical way to extract the mesh from a polyhedron.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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