Skip to content
Snippets Groups Projects
Commit fd9f1303 authored by lacoche's avatar lacoche
Browse files

Add a method to compute world pose of a node if it has no target

parent aa919a17
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ using UnityEngine.UIElements; ...@@ -33,6 +33,7 @@ using UnityEngine.UIElements;
using TMPro; using TMPro;
using UnityEditor.Experimental.GraphView; using UnityEditor.Experimental.GraphView;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq;
namespace ETSI.ARF.WorldStorage.Editor.Windows namespace ETSI.ARF.WorldStorage.Editor.Windows
{ {
...@@ -609,7 +610,6 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows ...@@ -609,7 +610,6 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
Vector3 position ; Vector3 position ;
Vector3 rotation ; Vector3 rotation ;
EstimateWorldPose(trackableNode, out position, out rotation); EstimateWorldPose(trackableNode, out position, out rotation);
Debug.Log("Position " +position);
GenerateAndUpdateVisual(trackable.UUID.ToString(), "Trackable: "+ trackable.TrackableType + " "+ trackable.Name, position, rotation, true); // Todo : localCRS does not correspond to world pos GenerateAndUpdateVisual(trackable.UUID.ToString(), "Trackable: "+ trackable.TrackableType + " "+ trackable.Name, position, rotation, true); // Todo : localCRS does not correspond to world pos
} }
...@@ -1356,27 +1356,68 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows ...@@ -1356,27 +1356,68 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
visual.transform.Find("Canvas/Text").GetComponent<TextMeshProUGUI>().text = $"Name: { name }\nUUID: { UUID }"; visual.transform.Find("Canvas/Text").GetComponent<TextMeshProUGUI>().text = $"Name: { name }\nUUID: { UUID }";
return visual; return visual;
} }
/// Here is an approach to estimate the world pose of a node /// Here is an approach to estimate the world pose of a node
/// It goes map depth and multiply the matrix of each link until it finds the last node considered as the origin (0, 0 ,0) /// It goes map depth and multiply the matrix of each link until it finds the last node considered as the origin (0, 0 ,0)
/// This is not the optimal method as it can create inconsistencies /// This is not the optimal method as it can create inconsistencies
/// A better approach would be to set the world poses of the nodes and then compute the matrix of the world links /// A better approach would be to set the world poses of the nodes and then compute the matrix of the world links
private void EstimateWorldPose(ARFNode node, out Vector3 pos, out Vector3 rot) private void EstimateWorldPose(ARFNode node, out Vector3 pos, out Vector3 rot)
{ {
// trackable // trackable
int newNDepth = 0 ; int newNDepth = 0;
Matrix4x4 mat = Matrix4x4.identity ; Matrix4x4 mat = Matrix4x4.identity;
ComputePose(node, ref mat , ref newNDepth); if (node.portIn.connections.Any())
{
ComputePose(node, ref mat, ref newNDepth);
}
else
{
// In case of no in link : just find the first output, find its generated game object an compute pose by composing with link
// not very optimal but firs approach
ComputePoseNoPortIn(node, out mat);
}
Vector3 translation = mat.GetColumn(3); Vector3 translation = mat.GetColumn(3);
// Extract Rotation // Extract Rotation
Quaternion rotation = Quaternion.LookRotation( Quaternion rotation = Quaternion.LookRotation(
mat.GetColumn(2), mat.GetColumn(2),
mat.GetColumn(1) mat.GetColumn(1)
); );
pos = translation; pos = translation;
rot = rotation.eulerAngles; rot = rotation.eulerAngles;
}
private void ComputePoseNoPortIn(ARFNode node , out Matrix4x4 mat)
{
mat = Matrix4x4.identity;
foreach(Edge edge in node.portOut.connections)
{
// not best way : try to find an output node allready present in scene. Find gameobject pose and transform with link
ARFEdgeLink arfEdge = (ARFEdgeLink) edge ;
if (arfEdge !=null)
{
WorldLink link = arfEdge.worldLink ;
ARFNode newNode = (ARFNode) arfEdge.input.node ;
string uuid = "" ;
ARFNodeTrackable trackNode = newNode as ARFNodeTrackable;
ARFNodeWorldAnchor worldNode = newNode as ARFNodeWorldAnchor;
if (trackNode != null)
{
uuid= trackNode.trackable.UUID.ToString() ;
}
else
{
uuid = worldNode.worldAnchor.UUID.ToString() ;
}
GameObject obj = GameObject.Find(uuid); // find associated gameobject (if it exists)
if (obj != null)
{
// compose matrix with link
mat = GetMatrix(link.Transform).inverse * obj.transform.localToWorldMatrix;;
}
}
}
} }
private void ComputePose(ARFNode node, ref Matrix4x4 mat , ref int depth) private void ComputePose(ARFNode node, ref Matrix4x4 mat , ref int depth)
...@@ -1396,8 +1437,6 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows ...@@ -1396,8 +1437,6 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
{ {
Matrix4x4 newMat = GetMatrix(link.Transform); Matrix4x4 newMat = GetMatrix(link.Transform);
mat = mat * newMat ; mat = mat * newMat ;
ARFNodeTrackable trackNode = newNode as ARFNodeTrackable;
ARFNodeWorldAnchor worldNode = newNode as ARFNodeWorldAnchor;
maxDepth = currentDepth ; maxDepth = currentDepth ;
} }
} }
...@@ -1405,6 +1444,8 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows ...@@ -1405,6 +1444,8 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
depth += maxDepth ; depth += maxDepth ;
} }
private Matrix4x4 GetMatrix(Transform3D tr) private Matrix4x4 GetMatrix(Transform3D tr)
{ {
Matrix4x4 matrix = new Matrix4x4(); Matrix4x4 matrix = new Matrix4x4();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment