Message Boards Message Boards

[✓] Export a 3D model from Mathematica?

GROUPS:

I'm trying to export a scatterplot that has been translated into a series of cuboids. x in this example is a very long array of ones and zeroes.

vals = ArrayReshape[x, {12, 512, 26}, 0];
pts = Position[vals, 1];
y = Graphics3D[Translate[{Red, Cuboid[]}, pts]]

This code ran with my array produces the image down at the bottom. I'd like to export that into a format such as .3ds or .obj so I can use it across multiple 3D modeling platforms, but whenever I run the following code:

 Export["test.3ds", y]

I get this error: "Export::nodta: Graphics3D contains no data that can be exported to the 3DS format."\

In a bit of a rut trying to figure out what I'm doing wrong here. I've been looking for the past few days, and couldn't find anything that helped me. I'm pretty new to Mathematica, so I'm sure there's just something I'm missing. Any help would be appreciated, thanks!

enter image description here

POSTED BY: Eric Bartell
Answer
21 days ago

Hi

A simpler case:

pts = {{1, 1, 1}, {3, 3, 3}};
test = Graphics3D[Translate[Cuboid[], pts]]
Export["test.3ds", test]

(* Fail !!! *)

Probably Mathematica at first discretize graphics primitives and then export to file,but It can't discretize because is not implemented yet.

I found in Help Documentation possible issues examples:

BoundaryDiscretizeGraphics[Graphics3D[{Cone[], Cuboid[]}]]
(*Fail *)
DiscretizeGraphics[Graphics3D[{Cone[], Cuboid[]}]]
(* Fail *)

and in our example:

DiscretizeGraphics[test]
(* Fail -> EmptyRegion[3]*)

It is possible that in the next version of Mathematica 12.0, these incompatibilities will be corrected. I hope. Is there any way workaround? I don't know.

Regards,MI.

POSTED BY: Mariusz Iwaniuk
Answer
19 days ago

Thanks for the post, Mariusz. That makes a lot more sense now.

Is there any format for exporting in Mathematica that is supported, or would it be for the best for me to seek an alternative CAD software?

POSTED BY: Eric Bartell
Answer
19 days ago

Hi

With help this site I found workaround:

  x = {RandomInteger[1, 20], RandomInteger[1, 20], RandomInteger[1, 20]};
  vals = ArrayReshape[x, {12, 512, 26}, 0];
  pts = Position[vals, 1];
  test = Graphics3D[Translate[PolyhedronData["Cube", "GraphicsComplex"], pts], Boxed -> False, SphericalRegion -> True]

  ClearAll[normify, xfcoords, ixfcoords];
  normify[Translate[g_, v : {__?NumericQ}]] := 
    normify[Translate[g, {v}]];
  normify[Translate[g_, v_?MatrixQ]] := 
    xfcoords[g, TranslationTransform[#]] & /@ v;
  normify[g_] := g;

  SetAttributes[xfcoords, Listable];
  xfcoords[g_, xf_] := ixfcoords[g, xf];
  ixfcoords[(obj : GraphicsComplex | Polygon | Line | Point)[coords_, rest___], xf_] := obj[xf[coords], rest];
  ixfcoords[g_, xf_] := g;

  normaltest = normify //@ test

  Export["test1.3ds", normaltest]

It's only work with Graphics primitives such as:

   PolyhedronData[All]

Regards, MI

POSTED BY: Mariusz Iwaniuk
Answer
18 days ago

From the documentation on 3ds, it simply states that

Export to the 3DS format supports the following graphics primitives: GraphicsComplex, Cuboid, Cylinder, and Sphere.

so it basically should work. The problem seems to be the Translate command, because

Export["test.3ds", Graphics3D[Translate[Cuboid[{0,0,0}], {{0,0,0}}]]]

does not work, but this is equivalent to

Export["test.3ds", Graphics3D[Cuboid[]]]

which does work. Consequently you could do it like so:

pts = RandomReal[{-10, 10}, {100, 3}];
y = Graphics3D[{Red, Cuboid /@ pts}];
Export["test.3ds", y]

But in any case Mathematica knows a lot of respective 3D Geometry & Modeling Formats.

Regards -- Henrik

POSTED BY: Henrik Schachner
Answer
18 days ago

Group Abstract Group Abstract