3
$\begingroup$

How to paint the dolphin, shark and the box with different colors after loading the .obj file into Mathematica?

gr = Import["c:\\DolphinSharkBox.obj" ];
Graphics3D[gr[[1]]]

Link for the .obj file. enter image description here

$\endgroup$
5
$\begingroup$

The imperceptiple smile of your shark hides 12 triples of teeth and a pair eyes each with 288 lenses!

enter image description here

I use the method in the update to this answer as is:

grc = Import["... \\DophinSharkBox.obj",  "GraphicsComplex"];
Graphics3D[grc]

enter image description here

Producing the graph takes a while (perhaps could be faster with Pick instead of Select):

polygonsc = Join @@ (Normal[grc] /. 
     HoldPattern[VertexNormals -> _] :> Sequence[]);
polygonsc = polygonsc /. Polygon -> Sequence;
edgesc =  DeleteDuplicates[UndirectedEdge @@@ Map[ToString,
     Select[Subsets[polygonsc, {2}], Intersection @@ # =!= {} &], {-2}]];

Expecting three connected components we get 41:

cc =  Map[ToExpression, ConnectedComponents[Graph[edgesc]], {-1}];
Through@{Length@# &, Tally[Length /@ #] &}@ cc
(* {41, {{3804, 1}, {952, 1}, {288, 2}, {38, 24}, {28, 12}, {6, 1}}} *)

Graph[edgesc, VertexStyle -> White, VertexSize -> .005, VertexShapeFunction -> "Point", 
     EdgeStyle -> Directive[Opacity[.5], Thin, Hue[.35, .5, .8]], 
     Background -> Black, EdgeShapeFunction -> (Line[#1] &), ImageSize -> 600]

enter image description here

Graphics3D[({EdgeForm[], Hue[RandomReal[]], Polygon@#} & /@ cc), Lighting ->"Neutral"]

enter image description here

Two largest components:

Graphics3D[({EdgeForm[], Hue[RandomReal[]], Polygon@# }&/@cc[[;;2]]), Lighting -> "Neutral"]

enter image description here

and the anatomic details at the top picture produced by

Graphics3D[({EdgeForm[],Hue[RandomReal[]],Polygon@#}&/@ cc[[3;;-2]]), Lighting -> "Neutral"]

Note: I eliminated VertexNormals to focus on the polygon faces. The method can be modified to keep the VertexNormals to produce smoother surfaces.

$\endgroup$
  • $\begingroup$ Much can be learned from your answers, Thanks again. I just wondered, is your method can be modified to produce a UV mapping for use of 3d model texturing in Mathematica? $\endgroup$ – Putterboy Sep 5 '14 at 5:34
  • $\begingroup$ Thank you @Putterboy. I need to google what UV mapping is :) $\endgroup$ – kglr Sep 5 '14 at 5:44
  • $\begingroup$ ... ah, I see. Perhaps ListSurfacePlot3D as in Texture>>Applications>>Marble Bunny could work for the bodies of your shark and dolphin. $\endgroup$ – kglr Sep 5 '14 at 6:00
  • $\begingroup$ The reason why I had such idea came up because the graph images of your solution look very much the same as the spreaded mesh that the 3D guys used for their photo realistic texturing. The 3D guys cut and spread their modeled object's mesh flat, and then paste a photo image of the real object to the various mesh parts of the object accordingly, in order to obtain a photo realistic looking of their final model. $\endgroup$ – Putterboy Sep 5 '14 at 8:20

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.