Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I colorize an imported model from for example 3ds max?

I'm trying to find the way to colorize a 3D plot from an imported model with something like this:

ColorFunction -> Function[{x, y, z}, ColorData["GreenBrownTerrain"][z^2]]

But I don't know how. Thank you very much for your help.

share|improve this question
1  
Example model: Import["ExampleData/747.3ds.gz"] it returns a Graphics3D –  ssch Jan 5 '13 at 13:24
    
Following ssch's suggestion, you can explore the data structure with jet = Import["ExampleData/747.3ds.gz"]; {jet[[0]], jet[[1]]} –  David Carraher Jan 5 '13 at 14:06
    
It consists of a bunch of different GraphicsComplex objects: Graphics3D[{EdgeForm[], Table[jet[[1, 2, i]] /. RGBColor[_] -> ColorData[1][i], {i, 1, 7}]}] Kind of annoying structure to change color of. –  ssch Jan 5 '13 at 14:11
add comment

1 Answer

Here I color the 747 model via the VertexColors option to GraphicsComplex.

jet = Import["ExampleData/747.3ds.gz"];
(* Function to change color of GraphicsComplex *)
newcolor[gcomplex_, colfun_] := Module[{
   pts = First@gcomplex,
   data = gcomplex[[2]],
   vcol},
  (* Remove old RGBColor stuff in data part of the graphics complex *)
  data = DeleteCases[data, RGBColor[_]]; 
  (* Introduce vertex colors according to colfun *)
  vcol = colfun /@ pts;
  (* Return a new GraphicsComplex with VertexColors *)
  GraphicsComplex[pts, data, VertexColors -> vcol]
  ]
(* Find range of z values *)
{zmin, zmax} = {Min@#, Max@#} &@(Last /@ 
 Flatten[Cases[jet, GraphicsComplex[__], Infinity][[All, 1]], 1]);
(* Color function that maps {x,y,z} to color *)
cf = ColorData["GreenBrownTerrain"][Rescale[Last@#, {zmin, zmax}]^2] &
(* Change all GraphicsComplex objects *)
jet /. gc_GraphicsComplex :> newcolor[gc, cf]

recolored jet

There are some visible artefacts in the coloring, but at least it's something.

Comment if there's some part you'd like me to explain further.

Here's the before/after for ExampleData[{"Geometry3D","Phobos"}]

rock in space

share|improve this answer
    
Thank you, I'm going to try....Ok, it's working. tank you very much. –  user5288 Jan 5 '13 at 15:57
    
If I want to do a generic function in function of x,y,z for color, what I must do? –  user5288 Jan 5 '13 at 16:37
    
@user5288 something like cf[{x_,y_,z_}]:= ... or change vcol = colfun /@ pts; to vcol = colfun@@#& /@ pts; and use cf[x_,y_,z_]:=... –  ssch Jan 5 '13 at 16:43
    
I can't do the generic function, I was trying all the afternoon, but I can, my objetive is colorize a beam in function of the stress, and I need a function in x,y,z –  user5288 Jan 5 '13 at 18:26
    
@user5288 What have you tried and how does it fail? –  ssch Jan 5 '13 at 18:28
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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