4

Using Unity3D and VRTK I am need to get the value of a pixel on a texture I am pointing at using the VRTK_Pointer script.

I created a script, attached to a sphere named COLOR_GRID I declared a public member Texture2D corresponding to the sphere's texture. It contains this method, which is called when I point and click to the sphere.

private void DoPointerDestinationSet(object sender, DestinationMarkerEventArgs e)
{
    DebugLogger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), "POINTER DESTINATION", e.target, e.raycastHit, e.distance, e.destinationPosition);

    if (e.target.name == "COLOR_GRID")
    {
        int[] coordinates = ????
        Color c = this.GetPixel(coordinates[0], coordinates[1]);
    }
}

From e.raycastHit, I can access to, I guess, the local coordinates of the pointer impact on the sphere. Using this information the question is how to convert this local coordinate into the Texture2D coordinates ? But I am stuck there.

Or is there a better way of doing it ?

EDIT: e.raycastHit.textureCoord is always (0,0).

Deewy
  • 245
  • 1
  • 8

0 Answers0