/// <summary> /// Create a frozen anchor visual in the indicated fragment. /// </summary> /// <param name="source">Source data to create from.</param> /// <param name="resource">The created resource.</param> /// <returns></returns> public bool CreateFrozenVisual(AnchorFragmentPose source, out IdPair <AnchorId, FrozenAnchorVisual> resource) { // Already ensured this fragment exists. FragmentId fragmentId = source.fragmentPose.fragmentId; AnchorId anchorId = source.anchorId; FrameVisual frozenFragmentViz; if (!frozenFragmentVisuals.TryGetValue(fragmentId, out frozenFragmentViz)) { resource = new IdPair <AnchorId, FrozenAnchorVisual>() { id = AnchorId.Invalid, target = null }; return(false); } // If there isn't a visualization for this anchor, add one. FrozenAnchorVisual frozenAnchorVisual; frozenAnchorVisual = Prefab_FrozenAnchorViz.Instantiate(anchorId.FormatStr(), frozenFragmentViz); //frozenAnchorVisual.gameObject.AddComponent<AdjusterMoving>(); // Put the frozen anchor vis at the world locked transform of the anchor SetPose(source, frozenAnchorVisual); resource = new IdPair <AnchorId, FrozenAnchorVisual>() { id = source.anchorId, target = frozenAnchorVisual }; return(true); }
/// <summary> /// Set or update the pose of the resource. /// </summary> /// <param name="source">Source FrozenAnchor associated with the resource.</param> /// <param name="target">The resource to set the pose of.</param> private void SetPose(AnchorFragmentPose source, FrozenAnchorVisual target) { Pose localPose = source.fragmentPose.pose; localPose = frozenFromLocked.Multiply(localPose); // The following line introduces an artificial displacement between corresponding frozen and // spongy anchors, to make sure the connecting line visualization is working. //localPose.position.y += 0.25f; target.transform.SetLocalPose(localPose); }
/// <summary> /// Update the pose of the existing resource. /// </summary> /// <param name="source">The resource's source data.</param> /// <param name="target">The resource to update.</param> public void UpdateFrozenVisual(AnchorFragmentPose source, IdPair <AnchorId, FrozenAnchorVisual> target) { SetPose(source, target.target); }