7
$\begingroup$

I've managed to import a Wavefront (.obj) file and store it in a variable like so:

model = Import[
    "/path_to_object/my.obj", 
    "Graphics3D", 
    Lighting -> {
        {"Ambient", RGBColor[{0.212, 0.168, 0.2}]},
        {"Directional", RGBColor[{0.8, 0., 0.}], ImageScaled[{2, 0, 2}]},
        {"Directional", RGBColor[{0., 0.8, 0.}], ImageScaled[{2, 2, 2}]},
        {"Directional", RGBColor[{0., 0., 0.8}], ImageScaled[{0, 2, 2}]}
    }
]

The output shows no black edges that you would normally see with Graphics3D objects, sort of like a "wireframe overlay". I've tried to call the Graphics3D function on model in this way:

Graphics3D[{AbsoluteThickness[2], AbsoluteDashing[{5, 5}], model}]

But I get the error:

Graphics is not a Graphics3D primitive or directive.

I've also tried adding more arguments to the Import function but I get the error:

Import::argt: Import called with 3 arguments; 1 or 2 arguments are expected.

Any ideas on how this can be accomplished? I saw that there is the command Mesh->All, but because I'm not that well versed with Mathematica yet, I don't know exactly how to apply a Mesh command to an imported Graphics3D object.

$\endgroup$
4
  • $\begingroup$ Did you want something like DeleteCases[Import["ExampleData/wrench.obj.gz"], _EdgeForm, Infinity]? $\endgroup$ May 16, 2013 at 14:21
  • $\begingroup$ @j-m That was fast. How can I mark your comment as the answer? =) $\endgroup$ May 16, 2013 at 14:26
  • $\begingroup$ Another hack for the way my .obj file is imported is: model /. EdgeForm[] -> EdgeForm[{Thick}] $\endgroup$
    – SEngstrom
    May 16, 2013 at 14:30
  • $\begingroup$ Thanks for the helpful answers so far. $\endgroup$ May 16, 2013 at 16:38

2 Answers 2

6
$\begingroup$

At OP's behest:

The easiest approach to see the mesh lines is to remove the EdgeForm[] instruction that causes them not to appear. For instance,

DeleteCases[Import["ExampleData/wrench.obj.gz"], _EdgeForm, ∞]

wrench with a mesh

As SEngstrom suggests, you can also use a replacement rule. If, for instance, you want a thick gray mesh, here's what you can do:

Import["ExampleData/wrench.obj.gz"] /. EdgeForm[] -> EdgeForm[Directive[Thick, Gray]]

wrench with a gray mesh

Finally, if you want a true wire frame (no polygons):

Import["ExampleData/wrench.obj.gz"] /. EdgeForm[] -> FaceForm[None]

wireframe wrench

$\endgroup$
5
$\begingroup$

What about this:

Import["ExampleData/wrench.obj.gz", "PolygonObjects"] // Graphics3D

enter image description here

You can use the FaceForm[None] trick as shown by @J.M. here just as well if you only want the wireframe looks.

$\endgroup$
5
  • $\begingroup$ I already showed this somewhere, but cannot find it right now... $\endgroup$
    – Yves Klett
    May 16, 2013 at 15:18
  • $\begingroup$ Cool! I forgot you can specify properties in Import[]... $\endgroup$ May 16, 2013 at 15:18
  • $\begingroup$ @J.M. `s rather well covered in the docs, too :-) $\endgroup$
    – Yves Klett
    May 16, 2013 at 15:19
  • $\begingroup$ Hah, yes. I've gotten too used to Import["file.ext", filetype, opts] that I haven't been using the new features that much. $\endgroup$ May 16, 2013 at 15:21
  • $\begingroup$ All right, it was just a comment on this one: mathematica.stackexchange.com/q/23543/131 $\endgroup$
    – Yves Klett
    May 16, 2013 at 15:26

Your Answer

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

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