PDA

View Full Version : Getting Color of another Material on Mesh?


kogen
04-18-2009, 02:19 PM
Good afternoon everybody,

I'm temporarily wondering if there is a method / function / workaround which makes it possible to get the colorvalue in a distinct area of a mesh similar to the projection modifier...

Example: Imagine you've got a plane and a bitmap mapped onto it. Then you'd create a ray from the center of the viewport (perhaps gw.rayintersectEx()) to the plane and it would return the colorvalue of the mesh (not the vertexcolor) in that area.

Does anybody have an idea?

Thanks.

- ko'gen

Bobo
04-18-2009, 03:32 PM
Good afternoon everybody,

I'm temporarily wondering if there is a method / function / workaround which makes it possible to get the colorvalue in a distinct area of a mesh similar to the projection modifier...

Example: Imagine you've got a plane and a bitmap mapped onto it. Then you'd create a ray from the center of the viewport (perhaps gw.rayintersectEx()) to the plane and it would return the colorvalue of the mesh (not the vertexcolor) in that area.

Does anybody has an idea?

Thanks.

- ko'gen


It really depends on WHAT color you want to get - the color of the texture, the color seen in the renderer at that point, do you want the lighting or not?

If you want the color of the texel found at that position, you simply get the Barycentric Coordinates returned from intersectRayEx() as well as the face index, grab the 3 map vertices of the map face with the same index as the mesh face, multiply the first UV coordinate with the first component of the bary coords, repeat the same with the second and third and sum the three values. This will give you the UV coordinates of the point on the mesh. Now you can multiply the image size by these UV coordinates (and flip the V because the image has its 0,0 in the UPPER left corner while UVs have the 0,0 at the bottom left corner) and you will get the pixel coordinate of that point. Then you can use getPixels() to read the actual color. Keep in mind intersectRayEx() expects a Mesh, so you might have to drop a Mesh_Select or TurnToMesh modifier on your object to access that data.

If the texture is a procedural 2D map, you could call RenderMap() first and then do the above.

If you want the render color, an old hack has been to create a camera aligned to the normal of the point with a very narrow FOV and render a single pixel in scanline to get the real thing with or without lighting. Obviously, it would be a bit slow.

There might be other hacks to do this, but these are the main approaches I know about.

kogen
04-18-2009, 04:26 PM
Woha,

thanks Bobo.

I have to give method 1 a try cause that's exactly what I want to do. Thanks also for specifying what I actually can do ;) I overlooked the fact that there is more than a simple flat shaded object.

Let's do some maths...

CGTalk Moderation
04-18-2009, 04:26 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.