bool TryCreateMRPlane(MRLayerPlaneData layerPlane, Pose layerOriginPose) { var mrPlaneVertices = new List <Vector3>(); Pose pose; Vector3 center; Vector2 extents; if (!TryGetPlaneData(layerPlane, layerOriginPose, mrPlaneVertices, out pose, out center, out extents)) { return(false); } var vertsCount = mrPlaneVertices.Count; var normals = new List <Vector3>(vertsCount); var textureCoordinates = new List <Vector2>(vertsCount); var indices = new List <int>(); PlaneUtils.TriangulatePlaneFromVertices(pose, mrPlaneVertices, indices, normals, textureCoordinates); var mrPlane = new MRPlane { id = MarsTrackableId.Create(), alignment = m_PlaneAlignment, vertices = mrPlaneVertices, normals = normals, indices = indices, textureCoordinates = textureCoordinates, pose = pose, center = center, extents = extents }; layerPlane.MRPlane = mrPlane; return(true); }
/// <summary> /// Called by MARS when the SynthesizedObject is initialized /// </summary> public override void Initialize() { base.Initialize(); if (MarsTrackableId.InvalidId == m_Marker.id) { m_Marker.id = MarsTrackableId.Create(); } m_IdSource = GetComponent <SynthesizedMarkerId>(); m_PoseSource = GetComponent <SynthesizedPose>(); m_ExtentsSource = GetComponent <SynthesizedBounds2D>(); if (!Guid.TryParse(m_IdSource.GetTraitData(), out var guid)) { Debug.LogWarning($"The Synthesized Marker guid on '{name}' is missing or improperly formed. " + "Image Marker Proxies may not match in simulation."); guid = Guid.Empty; } m_Marker.markerId = guid; m_Marker.texture = m_IdSource.Texture; GetData(); // We cannot guarantee that the synthetic marker has been set so use the renderer scale as initial size m_IdSource.UpdateMarkerSizeWithLocalScale(); }
public override XRPointCloudData GetPointCloudData(TrackableId trackableId, Allocator allocator) { var id = new MarsTrackableId(trackableId.subId1, trackableId.subId2); if (m_PointClouds.TryGetValue(id, out var pointCloud)) { var result = new XRPointCloudData(); if (pointCloud.Identifiers.HasValue) { result.identifiers = new NativeArray <ulong>(pointCloud.Identifiers.Value.Length, allocator); pointCloud.Identifiers.Value.CopyTo(result.identifiers); } if (pointCloud.Positions.HasValue) { result.positions = new NativeArray <Vector3>(pointCloud.Positions.Value.Length, allocator); pointCloud.Positions.Value.CopyTo(result.positions); } if (pointCloud.ConfidenceValues.HasValue) { result.confidenceValues = new NativeArray <float>(pointCloud.ConfidenceValues.Value.Length, allocator); pointCloud.ConfidenceValues.Value.CopyTo(result.confidenceValues); } return(result); } return(default);
protected MRPlane MakeNewPlane() { s_IdCount++; var plane = new MRPlane(); plane.id = MarsTrackableId.Create(); plane.extents = Vector2.one; return(plane); }
/// <summary> /// Gets the session-unique trackable ID mapped to the given recording-unique ID. /// This creates a new mapping if one does not already exist for the given ID. /// </summary> /// <param name="recordedID">Recording-unique trackable ID</param> /// <returns>The corresponding session-unique trackable ID</returns> protected MarsTrackableId GetPlaybackID(MarsTrackableId recordedID) { if (m_PlaybackIDs.TryGetValue(recordedID, out var playbackID)) { return(playbackID); } playbackID = MarsTrackableId.Create(); m_PlaybackIDs[recordedID] = playbackID; return(playbackID); }
public void AddMRFaceData() { var face = new TestFace { pose = new Pose(Vector3.forward, Quaternion.identity) }; face.id = MarsTrackableId.Create(); m_Db.faceData.AddOrUpdateData(face); m_Db.faceData.GetAllData(m_TempFaces); Assert.AreEqual(1, m_TempFaces.Count); }
// Copy m_Plane to m_RuntimePlane but preserve its ID, or generate one if it doesn't have one. void CopyToRuntimePlane() { var id = m_RuntimePlane.id; if (id == MarsTrackableId.InvalidId) { id = MarsTrackableId.Create(); } m_RuntimePlane = m_Plane; m_RuntimePlane.id = id; }
public void OnEnable() { ConnectDb(); m_StartFrame = Time.frameCount; for (var i = 0; i < s_DataCount; i++) { var plane = new MRPlane(); plane.id = MarsTrackableId.Create(); plane.extents = Vector2.one; m_Planes[i] = plane; m_Db.planeData.AddOrUpdateData(plane); } }
public void AddMRPlaneData() { var plane = new MRPlane(); plane.id = MarsTrackableId.Create(); plane.pose = new Pose(Vector3.up, Quaternion.identity); plane.extents = new Vector2(0.5f, 1f); m_Db.planeData.AddOrUpdateData(plane); m_Db.planeData.GetAllData(m_TempPlanes); Assert.AreEqual(1, m_TempPlanes.Count); }
public void Setup() { for (int i = 0; i < k_PlaneCount; i++) { var pose = new Pose(Random.insideUnitSphere * 5f + Random.onUnitSphere, Quaternion.identity); var plane = new MRPlane { id = MarsTrackableId.Create(), extents = new Vector2(Random.value + 1f, Random.value + 1f), pose = pose }; m_ProvidedPlanes[i] = plane; } }
int TryFindRegionFieldIndex(MarsTrackableId marsId) { if (m_FieldDef.regions == null) { return(-1); } for (var ri = 0; ri < m_FieldDef.regions.Count; ri++) { if (m_FieldDef.regions[ri].trackableId == marsId) { return(ri); } } return(-1); }
public bool TryGetReferencePoint(MarsTrackableId id, out MRReferencePoint referencePoint) { ARReferencePoint arReferencePoint; if (!k_TrackableIds.TryGetValue(id, out arReferencePoint) || m_ARReferencePointManager == null) { referencePoint = default(MRReferencePoint); return(false); } #if ARFOUNDATION_3_0_1_OR_NEWER var result = m_ARReferencePointManager.GetAnchor(arReferencePoint.trackableId); #else var result = m_ARReferencePointManager.GetReferencePoint(arReferencePoint.trackableId); #endif referencePoint = result.ToMRReferencePoint(); return(true); }
void IFunctionalityProvider.LoadProvider() { ARFoundationSessionProvider.RequireARSession(); var currentSession = ARFoundationSessionProvider.currentSession; if (currentSession) { m_ARPointCloudManager = UnityEngine.Object.FindObjectOfType <ARPointCloudManager>(); if (!m_ARPointCloudManager) { m_ARPointCloudManager = currentSession.gameObject.AddComponent <ARPointCloudManager>(); m_ARPointCloudManager.hideFlags = HideFlags.DontSave; m_NewARPointCloudManager = m_ARPointCloudManager; } m_ARPointCloudManager.pointCloudsChanged += ARPointCloudManagerOnPointCloudsChanged; } #if UNITY_EDITOR var data = new PointCloudData(); m_Identifiers = new NativeArray <ulong>(k_NumPoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); m_Positions = new NativeArray <Vector3>(k_NumPoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); m_ConfidenceValues = new NativeArray <float>(k_NumPoints, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); for (var i = 0; i < k_NumPoints; i++) { m_Identifiers[i] = (ulong)i; m_Positions[i] = Random.insideUnitSphere * k_PointCloudSize; m_ConfidenceValues[i] = Random.Range(0, 1); } data.Identifiers = new NativeSlice <ulong>(m_Identifiers); data.Positions = new NativeSlice <Vector3>(m_Positions); data.ConfidenceValues = new NativeSlice <float>(m_ConfidenceValues); m_Data[MarsTrackableId.Create()] = data; EditorApplication.delayCall += () => { if (PointCloudUpdated != null) { PointCloudUpdated(GetPoints()); } }; #endif }
public void AddMARSReferencePointData() { var point1 = new MRReferencePoint(new Pose(Vector3.right, Quaternion.identity)); point1.id = MarsTrackableId.Create(); var point2 = new MRReferencePoint(new Pose(Vector3.up, Quaternion.identity)); point2.id = MarsTrackableId.Create(); // this will probably need to change when we change how we generate IDs var marsDataId1 = m_Db.referencePointData.AddOrUpdateData(point1); var marsDataId2 = m_Db.referencePointData.AddOrUpdateData(point2); m_Db.referencePointData.GetAllData(m_TempReferencePoints); Assert.AreEqual(2, m_TempReferencePoints.Count); Assert.True(m_TempReferencePoints.TryGetValue(marsDataId1, out point1)); Assert.True(m_TempReferencePoints.TryGetValue(marsDataId2, out point1)); }
public bool TryAddReferencePoint(Pose pose, out MarsTrackableId referencePointId) { if (m_ARReferencePointManager) { #if ARFOUNDATION_4_1_OR_NEWER var go = new GameObject("Reference point"); go.transform.SetLocalPose(pose); var pointAdded = go.AddComponent <ARAnchor>(); #elif ARFOUNDATION_3_0_1_OR_NEWER var pointAdded = m_ARReferencePointManager.AddAnchor(pose); #else var pointAdded = m_ARReferencePointManager.AddReferencePoint(pose); #endif referencePointId = pointAdded.ToMRReferencePoint().id; return(true); } referencePointId = default(MarsTrackableId); return(false); }
int EnsureRegionFieldIndex(MarsTrackableId marsId) { var curId = TryFindRegionFieldIndex(marsId); if (curId >= 0) { return(curId); } if (m_FieldDef.regions == null) { m_FieldDef.regions = new List <ProxyForceFieldRegion>(); } var nextId = m_FieldDef.regions.Count; m_FieldDef.regions.Add(new ProxyForceFieldRegion()); m_FieldUpToDate = false; return(nextId); }
public bool TryRemoveReferencePoint(MarsTrackableId id) { ARReferencePoint referencePoint; if (!k_TrackableIds.TryGetValue(id, out referencePoint)) { return(false); } if (m_ARReferencePointManager) #if ARFOUNDATION_4_1_OR_NEWER { UnityObjectUtils.Destroy(referencePoint.gameObject); } #elif ARFOUNDATION_3_0_1_OR_NEWER { return(m_ARReferencePointManager.RemoveAnchor(referencePoint)); } #else { return(m_ARReferencePointManager.RemoveReferencePoint(referencePoint)); } #endif return(false); }
/// <summary> /// Constructs a <see cref="SerializedFaceData"/> from an <see cref="IMRFace"/> /// </summary> /// <param name="face">Face data to serialize</param> /// <param name="landmarkEnumValues">Enumeration values to map 1:1 with serialized array of face landmark poses</param> /// <param name="expressionEnumValues">Enumeration values to map 1:1 with serialized array of face expression coefficients</param> public SerializedFaceData(IMRFace face, MRFaceLandmark[] landmarkEnumValues, MRFaceExpression[] expressionEnumValues) { m_ID = face.id; m_Pose = face.pose; m_Mesh = face.Mesh; var landmarksCount = landmarkEnumValues.Length; m_LandmarkPoses = new Pose[landmarksCount]; for (var i = 0; i < landmarksCount; i++) { m_LandmarkPoses[i] = face.LandmarkPoses[landmarkEnumValues[i]]; } var expressionsCount = expressionEnumValues.Length; m_ExpressionValues = new float[expressionsCount]; for (var i = 0; i < expressionsCount; i++) { m_ExpressionValues[i] = face.Expressions[expressionEnumValues[i]]; } }
void UpdatePoints() { if (m_ARPointCloudManager == null) { return; } var trackables = m_ARPointCloudManager.trackables; m_Data.Clear(); foreach (var pointCloud in trackables) { var data = new PointCloudData { Identifiers = pointCloud.identifiers, Positions = pointCloud.positions, ConfidenceValues = pointCloud.confidenceValues }; var id = pointCloud.trackableId; var marsTrackableId = new MarsTrackableId(id.subId1, id.subId2); m_Data[marsTrackableId] = data; } }
/// <summary> /// Create a new ARFoundationBody /// </summary> /// <param name="id">The trackable ID of this body</param> public ARFoundationBody(MarsTrackableId id) { m_Id = id; }
/// <summary> /// Get a reference point /// </summary> /// <returns>true if getting the point succeeded, false otherwise</returns> public static bool TryGetReferencePoint(this IUsesReferencePoints obj, MarsTrackableId referencePointId, out MRReferencePoint point) { return(obj.provider.TryGetReferencePoint(referencePointId, out point)); }
/// <summary> /// Add a reference point /// </summary> /// <returns>true if adding the point succeeded, false otherwise</returns> public static bool TryAddReferencePoint(this IUsesReferencePoints obj, Pose pose, out MarsTrackableId referencePointId) { return(obj.provider.TryAddReferencePoint(pose, out referencePointId)); }
/// <summary> /// Remove a reference point /// </summary> /// <returns>true if removing the point succeeded, false otherwise</returns> public static bool TryRemoveReferencePoint(this IUsesReferencePoints obj, MarsTrackableId referencePointId) { return(obj.provider.TryRemoveReferencePoint(referencePointId)); }
public ARFoundationFace(MarsTrackableId id) { m_Id = id; }
public bool TryAddReferencePoint(Pose pose, out MarsTrackableId referencePointId) { throw new NotImplementedException(); }
public bool TryGetReferencePoint(MarsTrackableId id, out MRReferencePoint referencePoint) { throw new NotImplementedException(); }
public bool TryRemoveReferencePoint(MarsTrackableId id) { throw new NotImplementedException(); }