'
' This example shows how you can get the closest surface position using either a
' vector of global positions or an array of local positions as the reference point
'
set oRoot = Application.ActiveSceneRoot
set oSphere = oRoot.AddGeometry("Sphere", "NurbsSurface")
' Translate the sphere
oSphere.Kinematics.Global.Parameters("posx").Value = oSphere.Kinematics.Global.Parameters("posx").Value + 13
' Set up a global array and a local vector (converted from global space) to use as references
set oGlobalPos = XSIMath.CreateVector3(0.0, 0.0, 0.0)
set oLocalPos = XSIMath.MapWorldPositionToObjectSpace(oSphere.Kinematics.Local.Transform, oGlobalPos)
aPosition = Array(0.0, 0.0, 0.0)
' Get the closest surface position from the local vector
oSphere.ActivePrimitive.Geometry.GetClosestSurfacePosition oLocalPos, SurfaceIndex, _
SquaredDistance, UValue,VValue, SurfacePosition
Application.LogMessage "The origin is closest to surface : " & SurfaceIndex & _
" its distance from it is " & sqr(SquaredDistance)
Application.LogMessage "The UV values are U : " & UValue & " V :" & VValue
Application.LogMessage "The corresponding position is X : " & SurfacePosition.X & _
" Y :" & SurfacePosition.Y & " Z :" & SurfacePosition.Z
' Get the closest surface position from the array of global positions
oSphere.ActivePrimitive.Geometry.GetClosestSurfacePosition aPosition, SurfaceIndex, _
SquaredDistance, UValue,VValue, SurfacePosition
Application.LogMessage "The origin is closest to surface : " & SurfaceIndex & _
" its distance from it is " & sqr(SquaredDistance)
Application.LogMessage "The UV values are U : " & UValue & " V :" & VValue
Application.LogMessage "The corresponding position is X : " & SurfacePosition.X & _
" Y :" & SurfacePosition.Y & " Z :" & SurfacePosition.Z
' Expected results:
' INFO : The origin is closest to surface : 0 its distance from it is 9.00000000000229
' INFO : The UV values are U : 0.999999 V :4.000001
' INFO : The corresponding position is X : -3.99999999999839 Y :1.57058495219762E-06 Z :-3.13444650011652E-06
' INFO : The origin is closest to surface : 0 its distance from it is 3.99525855482537
' INFO : The UV values are U : 7.50000002810587 V :3.62719837982321
' INFO : The corresponding position is X : -1.51252820283502 Y :-0.583451828096254 Z :-3.65156587231083
|