hi everyone !
there is my problem :
i use a RaycastHit to know if my cursor is over my mesh collider.
If it is over, i need to know the texture coordinate in order to change the texture color.
Using textureCoord, I get a texture coordinate offset from my hit point and still hit the top of my texture.
Using textureCoord2, I still get the same texture coordinate either the right or the left side of my mesh.
Result, I am able to reach the upper half of my texture instead of the whole.
I checked my UV model with my 3D software, there is no problem.
Vector2 uv = Vector2.zero;
Vector2 uv2 = Vector2.zero;
Ray mouseRay = new Ray();
Camera cam = Camera.main;
mouseRay = cam.ScreenPointToRay( Input.mousePosition );
float raySize = 10.0f;
RaycastHit hit;
if( m_meshCollider.Raycast( mouseRay, out hit, raySize )
{
uv = hit.textureCoord;
uv2 = hit.textureCoord2;
}
I also tried with a shorter distance for raySize.
There is the code for calculating my X and Y coordinates on the texture.
m_brushSize = the size of the brush i want to apply on my texture.
The texture is a 256x256 texture.
int x = (int)(uv.x * 256) - m_brushSize / 2 - 1;
int y = (int)(uv.y * 256) - m_brushSize / 2 - 1;
int clampX = Mathf.Clamp( x, m_brushSize, texture.width - m_brushSize );
int clampY = Mathf.Clamp( y, m_brushSize, texture.height - m_brushSize );
Any idea ?