Image information from obj file


#1

Hi every one, I have a problem, I read a obj file from maya, and then saving a 3dm file.

Then I re-read the 3dm file and shading in rhino (see the following figure), and I attempt
to write program to catch the information for the mesh, I could get the texture coordinate
information from mesh, but where can be found the color information(RGB) of image?


(Nathan 'jesterKing' Letwory) #2

From your RhinoObject you query the RenderMaterial. From this you should get the diffuse texture by first asking its child slot name (I think with “color”, or “diffuse”, not sure which). Then use the child slot name to get the texture of type RenderContent with FindChild(childslotname) on the RenderMaterial. The RenderContent you get should be cast as RenderTexture. From this texture you create a TextureEvaluator with CreateEvaluator(). On this evaluator you can then call GetColor.

The texture coordinates you already have go into the Point3d to GetColor, just created one with new Point3d(u, v, 0.0) (or whatever you type for VB). The two vectors the function requires should be essentially ‘half-pixels’. Calculate halfpixelU = 0.5 / width and halfpixelV = 0.5 / height, then construct a var duvw = new Vector3d(halfpixelU, halfpixelV, 0.0). Use this new vector for the latter two inputs in GetColor.

To sum up, some pseudo code (untested, but the idea should be there):

RhinoObject o = SomeWayToGetObject();
RenderMaterial rm = o.RenderMaterial;
string childSlotName = rm.GetChildSlotNameFromParamName("color");
RenderTexture rt = rm.FindChild(childSlotName) as rt;

if(rt == null) return; // no texture found, abort process in the way you see fit

TextureEvaluator teval = rt.CreateEvaluator();

Vector3d differential = new Vector3d(0.5 / width, 0.5 / height, 0.0);

Color4f theColorYouLookFor = reval.GetColor(new Point3d(x, y, 0.0), differential, differential);

I hope that points you in the right direction. Note, above as untested pseudo-code.

/Nathan