6
$\begingroup$

I want to create 3D objects from 2D image and export it as a "3ds" file (or "obj").

I tried:

img=Import["https://i.imgur.com/orbbFG4.png"]

enter image description here

With[{mesh = ImageMesh[ColorNegate[img]]}, RegionProduct[mesh, Line[{{0.}, {55}}]]]

enter image description here

Export["RamF.3ds", %]

but there is an error message

enter image description here

I also tried

Export["RamF.obj", %]

it works, but there is a problem when I tried to import it into the Blender or Unity3D.

$\endgroup$
5
$\begingroup$

As far as I can see, the problem is the Prism primitive that is used to construct the 3D form. I'm using your original code

m3 = With[{mesh = ImageMesh[ColorNegate[img]]}, 
    RegionProduct[mesh, Line[{{0.}, {55}}]]
]

Now, we can inspect how the 3D text is built:

With[{mp = MeshPrimitives[m3, 3]},
 Manipulate[
  Graphics3D[mp[[1 ;; i]], PlotRange -> RegionBounds[m3]],
  {i, 2, Length[mp]}
  ]
 ]

enter image description here

You see, every little piece is a prism. Basically, Mathematica creates a triangularized version of your text surface and extends it into the z-axis by turning it into a 3D prism.

Converting a Prism into a set of Polygons is, however, really easy. Simply turn the bottom, the top, and all the sides into a polygon.

toPolygons[Prism[{a1_, a2_, a3_, b1_, b2_, b3_}]] := Polygon[
  {{a1, a2, a3}, {b1, b2, b3}, {a1, b1, b2, a2}, 
   {a2, b2, b3, a3}, {a3, b3, b1, a1}}]

Using this function, you can export it to a 3D format

Export["~/tmp/f.3ds", Graphics3D[toPolygons /@ MeshPrimitives[m3, 3]]]

import it into blender and it will work:

enter image description here

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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