Roaming Ralph, problem getting Collor

I have to get the collor of the object right where the collision ray collides, i tried to do something like it

entries = []
        for i in range(self._roboCorHandler.getNumEntries()):
            entry = self._roboCorHandler.getEntry(i)
            print entry.getIntoNodePath().getColor()
            entries.append(entry)

Then, i get it on the console:

:pgraph(warning): get_color() called on render/world.egg/-PandaNode/-PandaNode/terrain which has no color set.
VBase4(1, 1, 1, 1)

How do i do to get the color right where the collision ray collides?

What do you mean by “color”? Do you mean:

(1) scene graph color, the color applied by node.setColor(), or
(2) vertex color, the color that might be defined on a particular vertex, or
(3) lighting color, the apparent color at a vertex that results from the lighting equation, or
(4) texture color, the color at a particular point from the application of texture, or
(5) resulting color, the final color at a particular pixel based on the application of all of the above?

nodePath.getColor() only returns (1). If you want any of the others, it’s actually really hard to do. It’s possible, but really hard. The graphics hardware is designed to go forwards, but not backwards–reading back the color at a pixel, or the result of any of the calculations along the way, is not what it’s built to do.

David

The idea is to get the texture color…

I need to get this, coz, i adopt the roaming ralph to start a robot simulation application, and I’m trying to add the same funcionality as some of robot hardware that releases an light at the floor and return if its black or white, if its any other color, it does an aproximation to get if its more aproximate to white or more aproximate to black.

Maybe you can store a table in Python that stores the color at each (x, y) grid point on your floor, and use the coordinate points of the collision as a lookup key into this table.

David

i… may have something of interest for you. i dunno who made it. and it’s now pretty much 2 years old. but i think, amongst other things, it does what you want :slight_smile:

http://thomaseg1.p3dp.com/samples/uv-texture-pickling_v0.3.zip

I tried to run it to see what it does, it gave alot of errors, and didnt work.

I see just a gray screen, panda default.

I realized that I need to get the 2d texture of terrain, and then, find the point it is in the 2d texture coordenates, so I can return it.

But, first of all, I didnt find how can I extract a texture from the terrain, second, I didnt see how I do convert the point of intersection that I have from 3D coordenates to a 2D coordenadas accurately.

I found that example Thomas sent to me, he works with a class called PNMImage, but i was unable to run this example because it gave alot of runtime errors, seems like this example is deprecated.

Thanks thomas, your application helped me alot to expand my mind, I’ve extracted the texture from the geomnode, now, what I have to do is to find, where the actor is in the texture, transform it into a coordinate and extract the color from the neighborhood of the pixel, because in the real life, the hardware that detects the color of floor, it throws the light to the floor and detects the light response, and by light intensity and color, he finds if it’s black or white.

Any ideas how do I know where the robot is in the texture?

All I have is a CollisionRay, that makes the collision that generates the function to detect the floor, the best is to know where the collision has collided in the texture.

My regards, H_DANILO.

Well, I found what I need to do to know where the robot is over the texture I got, if each unit were a pixel, I just needed to get the X mod texture_size_x and Y mod texture_size_y being (X,Y) the coordinates of the robot, but, each unit of coordinate is more then a pixel, so, I need to know how many pixels does a unit of coordinate.

Anyone got idea? how many pixels are a unit?

that’s something you set up by creating the model and mapping the texture to it. take your modelling application, check the ground-size and the texture resolution. based on that you can write a function which returns you the pixel for each position

noone except you can tell you what you have done with your models.

Actually, its a very start project, so, im using the world that comes with the roaming ralph, so, you say in world.egg of roaming ralph probably has the proportion right?

I found this at the world.egg

<Texture> lambert2SG {
  ground.jpg
  <Scalar> format { rgb }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
  <Transform> {
    <Matrix3> {
      10 0 0
      0 10 0
      10 2 1
    }
  }
}

the transform matrix doesnt say anything about the size of the geometry. it just describes scale/rotation/offset

Hey, I know this thread is a little old, but I would really appreciate some help getting the file in uc-texture-pickling_v0.3.zip to work. I am getting errors, perhpas similar to those described earlier in the thread(blank gray screen, terminal says: “:display(error): Window wouldn’t open; abandoning window.”)

What did you do to get this demo working?

Thanks,
Rishi