Group Abstract Group Abstract

Message Boards Message Boards

[?] Export a 3D model from Mathematica?

Posted 7 years ago
POSTED BY: Eric Bartell
4 Replies

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
Posted 7 years 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

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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard