/// <summary> /// Generates a new HandGrabPointData that mirrors the provided one. Left hand becomes right hand and vice-versa. /// The mirror axis is defined by the surface of the snap point, if any, if none a best-guess is provided /// but note that it can then moved manually in the editor. /// </summary> /// <param name="originalPoint">The point to mirror</param> /// <param name="originalPoint">The target HandGrabPoint to set as mirrored of the originalPoint</param> public static void MirrorHandGrabPoint(HandGrabPoint originalPoint, HandGrabPoint mirrorPoint) { HandPose handPose = originalPoint.HandPose; Handedness oppositeHandedness = handPose.Handedness == Handedness.Left ? Handedness.Right : Handedness.Left; HandGrabPointData mirrorData = originalPoint.SaveData(); mirrorData.handPose.Handedness = oppositeHandedness; if (originalPoint.SnapSurface != null) { mirrorData.gripPose = originalPoint.SnapSurface.MirrorPose(mirrorData.gripPose); } else { mirrorData.gripPose = mirrorData.gripPose.MirrorPoseRotation(Vector3.forward, Vector3.up); Vector3 translation = Vector3.Project(mirrorData.gripPose.position, Vector3.right); mirrorData.gripPose.position = mirrorData.gripPose.position - 2f * translation; } mirrorPoint.LoadData(mirrorData, originalPoint.RelativeTo); if (originalPoint.SnapSurface != null) { SnapSurfaces.ISnapSurface mirroredSurface = originalPoint.SnapSurface.CreateMirroredSurface(mirrorPoint.gameObject); mirrorPoint.InjectOptionalSurface(mirroredSurface); } }
public static void CloneHandGrabPoint(HandGrabPoint originalPoint, HandGrabPoint targetPoint) { HandGrabPointData mirrorData = originalPoint.SaveData(); targetPoint.LoadData(mirrorData, originalPoint.RelativeTo); if (originalPoint.SnapSurface != null) { SnapSurfaces.ISnapSurface mirroredSurface = originalPoint.SnapSurface.CreateDuplicatedSurface(targetPoint.gameObject); targetPoint.InjectOptionalSurface(mirroredSurface); } }