unity – Get index of Basemap the place raycast hit occurred

unity – Get index of Basemap the place raycast hit occurred

[ad_1]

Initially I believed questions like this, exhibiting learn how to get the index on a cloth’s primary texture from a raycast hit could be the reply

Experimenting with this, nevertheless, leads me to suspect that this does not truly do what I would like: I created a unity default airplane, which has 11x11 vertices and 200 triangles (10x10 pairs of squares), and the decision of hit.textureCoord was clearly 0.1

It appears textureCoord is related to the triangle and never the precise index within the materials’s basemap the place there was successful.

What I truly need to obtain is that this: Given a RaycastHit I would wish to get the index on the fabric’s basemap from which the purpose his is rendered (or, ideally, the worth of the pixel at that index).

Each “answer” I discover depends on textureCoord which clearly is just not what I would like.

One can assume my mesh is just a flat airplane with a single materials connected.

The one answer I can give you is assuming the airplane is a sq. (which I’d quite not, simply to have the ability to generalize, though on this particular case it’s) to make use of
hit.remodel.InverseTransformPoint(hit.level), be certain it’s inside the bounds of the mesh, discover the dimensions of the fabric’s basemap, and determine the index from that.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply