In an attempt to learn how to (in UrhoSharp) convert ray/triangle intersection to uv calculation, I came across this option
Urho.RayQueryLevel.TriangleUv
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
Urho.RayQueryLevel.TriangleUv return the UV coordinates while Urho.RayQueryLevel.Triangle does not :-)
Answers
FYI: Just found out that there is extensive discussion of barycentric coordinate in Xamarin Workbooks
I will go through the tutorial.
Still the main question is why not Urho.RayQueryLevel.TriangleUv for the Q1 and Q2
@linz I'd recommend moving these sorts of questions to https://forums.xamarin.com/categories/urhosharp.
@SandyArmstrong thnx
Urho.RayQueryLevel.TriangleUv return the UV coordinates while Urho.RayQueryLevel.Triangle does not :-)