Urho.RayQueryLevel.TriangleUv instead of Urho.RayQueryLevel.Triangle?

In an attempt to learn how to (in UrhoSharp) convert ray/triangle intersection to uv calculation, I came across this option

Typically one has use the barycentric formulas to get to the UV calculation using (in UrhoSharp case) the ray/triangle intersection involving Urho.RayQueryLevel.Triangle

Q1: perhaps there is a benefit of using Urho.RayQueryLevel.TriangleUv for UV calculation. However, I could not find anything after hours of googling.
=> Could someone comment on this?

This is another Urho(3D) & SkiaSharp(2D) use case that is unique for Xamarin platform that clearly differentiates from other .NET 3D engine.
Q2: Could someone share how to do this efficiently combining UrhoSharp & SkiaSharp:

(a) get the result below (discussing the potential benefit of using RayQueryLevel.TriangleUv instead of RayQueryLevel.Triangle)

var cameraRay = app.Camera.GetScreenRay (
    (float)e.X / app.Graphics.Width,
    (float)e.Y / app.Graphics.Height);

var result = app.Octree.RaycastSingle (cameraRay,
    RayQueryLevel.Triangle, 100, DrawableFlags.Geometry);

(b) How to get the Intersection in UrhoSharp and UV coordinate to efficiently draw a small circle at the identified UV coordinate in SkiaSharp?

First, you compute distances from P to A, B and C:

dA = distance from A to P
dB = distance from B to P
dC = distance from C to B

sum = dA + dB + dC
coefA = dA / sum
coefB = dB / sum
coefC = dC / sum 

So, the texture coordinate at point P is :

uP = uA * coefA + uB * coefB + uC * coefC
vP = vA * coefA + vB * coefB + vC * coefC

Best Answer

  • linzlinz DE ✭✭
    Accepted Answer

    Urho.RayQueryLevel.TriangleUv return the UV coordinates while Urho.RayQueryLevel.Triangle does not :-)


Sign In or Register to comment.