How to obtain the color of a triangle in a .b3d?

Blitz3D Forums/Blitz3D Programming/How to obtain the color of a triangle in a .b3d?

Pinete(Posted 2005) [#1]
Hi all,

I have a b3d model of a terrain.
I would like to put grass on to it, but my problem
comes at the moment I'm going to read the triangle
in wich I'm going to place the grass with a linepick..
the piece of code is the next:


[...more code before...]
yt# = LinePick(x#,10,z#,0,-30,0)
yy# = PickedY#()
surf= PickedSurface()
tri = PickedTriangle()
v0 = TriangleVertex(surf,tri,0)
v1 = TriangleVertex(surf,tri,1)
v2 = TriangleVertex(surf,tri,2)
red#= VertexRed#(surf,v0)
green# = VertexGreen#(surf,v0)
blue# = VertexBlue#(surf,v0)
entitycolor grass_entity,red#,green#,blue#

The read values are always 255.0 in all the color components, and If I change the last line by
entitycolor grass_entity,0,0,0
it works!


I cannot understand what's I'm doing wrong or why
it doesn't return the good values..
Please HELP!!!!!

Thanks in advance!!


big10p(Posted 2005) [#2]
I suspect your .b3d model isn't vertex coloured so all verts will have a colour of 255,255,255.


Pinete(Posted 2005) [#3]
Thanks big10p,
but just in this case, how I could to obtain the texture
color? that's really my objetive..


big10p(Posted 2005) [#4]
TBH Pinete, I'm not sure what you are trying to do. If your terrain is textured then each triangle is unlikely to be a single colour. If you want to find the texel colour at the point of your LinePick, then that's pretty difficult - I think there may be some code in the achives to do this, though.


octothorpe(Posted 2005) [#5]
Assuming you have only one texture, know what it is, and aren't concerned about lighting or vertex colours:
ReadPixel(VertexU(surf, v0), VertexV(surf, v0), TextureBuffer(tex))



Pinete(Posted 2005) [#6]
Thanks to all,

I will try to explain what I would loke to achieve.
I am placing grass on the terrain. The terrain is a .B3D model (not a blitz terrain), and i need that each entity of grass placed on to the terrain gets the colour of the ground underneath.
The terrain is composed by various textures. The first one for the basic colour and shape (roads, etc), the second one is noise and the last texture is a detail texture.
I will try during the day the method of octothorpe but I am not sure it works, because the first problem is how to access to the texture buffer of one of the textures used in a b3d model.. :_(
but I'll try!
However, is someone has another solution I will be very pleased to listen it!!!!

Thanks in advance


Jeppe Nielsen(Posted 2005) [#7]
What about placing a camera above the picked coordinates and looking straight down. Render this camera, and readpixel all the pixels, and calculate an average color based on all the pixels read?, then use this color to color your grass.


Pinete(Posted 2005) [#8]
Thanks Jeppe!
Really curious that I just finish to have a visit to your website before enter to the forum finding help!
wow, really could be a great solution!
It's a very good idea, absolutely. I will try it.
Thanks a lot.


octothorpe(Posted 2005) [#9]
If you take that approach, you'll need to disable any lighting, shadowing, and set your ambient light to full-bright.

Imagine a green texel rendered as dark green because it's in shadow. Reading dark green, you create a dark green grass entity. Your dark green grass entity will also be in shadow, and therefore will be dark dark green!


Pinete(Posted 2005) [#10]
Thanks!
:)