void ChoosePlaneObjectToSpawn(Vector3 position, UnityEngine.XR.ARSubsystems.TrackableId planeID) { float typeValueSelector = Random.Range(0f, 1f); if (typeValueSelector < .15f) { int prefab = Random.Range(0, PlaneObjectData.singleton.rockTypes.Length - 1); var instance = Instantiate(PlaneObjectData.singleton.rockTypes[prefab], position, Quaternion.Euler(PlaneObjectData.singleton.RandomYRot())); instance.planeID = planeID; PlaneObjectData.singleton.currentPlaneEnvironmentObjects.Add(instance.gameObject); } else if (typeValueSelector < .35f) { int prefab = Random.Range(0, PlaneObjectData.singleton.treeTypes.Length - 1); var instance = Instantiate(PlaneObjectData.singleton.treeTypes[prefab], position, Quaternion.Euler(PlaneObjectData.singleton.RandomYRot())); instance.planeID = planeID; PlaneObjectData.singleton.currentPlaneEnvironmentObjects.Add(instance.gameObject); } else { //change 1f ^ to .6f once people buildings added int prefab = Random.Range(0, PlaneObjectData.singleton.grassTypes.Length - 1); var instance = Instantiate(PlaneObjectData.singleton.grassTypes[prefab], position, Quaternion.identity); instance.planeID = planeID; PlaneObjectData.singleton.currentPlaneEnvironmentObjects.Add(instance.gameObject); } }
void OnAddAngle(UnityEngine.XR.ARSubsystems.TrackableId trackeableID, Vector3 pos, Quaternion rot) { GameObject go = GetWallData().anglesGO; go.transform.position = pos; go.transform.rotation = rot; }
WallData GetWallData(UnityEngine.XR.ARSubsystems.TrackableId trackeableID) { foreach (WallData wallData in walls) { if (wallData.trackeableID == trackeableID) { return(wallData); } } return(null); }
/// <summary> /// Constructs an <see cref="XRRaycast"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> of the trackable which was hit.</param> /// <param name="pose">The session-space <c>Pose</c> of the intersection.</param> /// <param name="trackingState">The tracking state of this raycast.</param> /// <param name="nativePtr">A pointer into native memory for this raycast.</param> /// <param name="distance">The session-space distance from the raycast origin to the intersection point.</param> /// <param name="hitTrackableId">The <see cref="TrackableId"/> of the trackable hit by this raycast, /// or <see cref="TrackableId.invalidId"/> if none.</param> public XRRaycast( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr, float distance, TrackableId hitTrackableId) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_Distance = distance; m_HitTrackableId = hitTrackableId; }
/// <summary> /// Constructs a new <see cref="XRPointCloud"/>. This is a container /// for the session-relative data. These are typically created by /// <see cref="XRDepthSubsystem.GetChanges(Unity.Collections.Allocator)"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with the point cloud.</param> /// <param name="pose">The <c>Pose</c> associated with the point cloud.</param> /// <param name="trackingState">The <see cref="TrackingState"/> associated with the point cloud.</param> /// <param name="nativePtr">The native pointer associated with the point cloud.</param> public XRPointCloud( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; }
/// <summary> /// Constructs the session relative data for reference point. /// This is typically provided by an implementation of the <see cref="XRReferencePointSubsystem"/> /// and not invoked directly. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with this reference point.</param> /// <param name="pose">The <c>Pose</c>, in session space, of the reference point.</param> /// <param name="trackingState">The <see cref="TrackingState"/> of the reference point.</param> /// <param name="nativePtr">A native pointer associated with the reference point. The data pointed to by /// this pointer is implementation-specific.</param> public XRReferencePoint( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr) { m_Id = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; }
/// <summary> /// Constructs an <see cref="XRRaycastHit"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> of the trackable which was hit.</param> /// <param name="pose">The session-space <c>Pose</c> of the intersection.</param> /// <param name="distance">The session-space distance from the raycast origin to the intersection point.</param> /// <param name="hitType">The type(s) of trackables which were hit by the ray.</param> public XRRaycastHit( TrackableId trackableId, Pose pose, float distance, TrackableType hitType) { m_TrackableId = trackableId; m_Pose = pose; m_Distance = distance; m_HitType = hitType; }
/// <summary> /// Constructs the session-relative data for an anchor. /// This is typically provided by an implementation of the <see cref="XRAnchorSubsystem"/> /// and not invoked directly. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with this anchor.</param> /// <param name="pose">The <c>Pose</c>, in session space, of the anchor.</param> /// <param name="trackingState">The <see cref="TrackingState"/> of the anchor.</param> /// <param name="nativePtr">A native pointer associated with the anchor. The data pointed to by /// this pointer is implementation-specific.</param> public XRAnchor( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr) { m_Id = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_SessionId = Guid.Empty; }
/// <summary> /// Constructs a <see cref="XRTrackedObject"/> /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with this tracked object.</param> /// <param name="pose">The <c>Pose</c> of this tracked object.</param> /// <param name="trackingState">The <see cref="TrackingState"/> of the tracked object.</param> /// <param name="nativePtr">A native pointer associated with this tracked object. If not <c>null</c>, /// the object pointed to by this pointer should be valid at least until the next call to /// <see cref="XRObjectTrackingSubsystem.GetChanges(Unity.Collections.Allocator)"/>.</param> /// <param name="referenceObjectGuid">The <c>Guid</c> of the reference object which was used to detect this tracked object.</param> public XRTrackedObject( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr, Guid referenceObjectGuid) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_ReferenceObjectGuid = referenceObjectGuid; }
/// <summary> /// Constructs an <see cref="XRParticipant"/>. <see cref="XRParticipant"/>s are generated /// by <see cref="XRParticipantSubsystem.GetChanges(Unity.Collections.Allocator)"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with this participant.</param> /// <param name="pose">The <c>Pose</c> associated with this participant.</param> /// <param name="trackingState">The <see cref="TrackingState"/> associated with this participant.</param> /// <param name="nativePtr">A native pointer associated with this participant.</param> /// <param name="sessionId">The session from which this participant originated.</param> public XRParticipant( TrackableId trackableId, Pose pose, TrackingState trackingState, IntPtr nativePtr, Guid sessionId) { m_TrackableId = trackableId; m_Pose = pose; m_TrackingState = trackingState; m_NativePtr = nativePtr; m_SessionId = sessionId; }
/// <summary> /// Get the mesh data associated with the face with <paramref name="faceId"/>. The <paramref name="faceMesh"/> /// is reused if it is the correct size, otherwise, it is disposed and reallocated using <paramref name="allocator"/>. /// </summary> /// <param name="faceId">The <see cref="TrackableId"/> for a <see cref="XRFace"/>.</param> /// <param name="allocator">The allocator to use for the returned data if a resize is necessary. Must be <c>Allocator.TempJob</c> or <c>Allocator.Persistent</c>.</param> /// <param name="faceMesh">The container for the mesh data to either re-use or re-allocate.</param> /// <exception cref="System.InvalidOperationException">Thrown if <paramref name="allocator"> is <c>Allocator.Temp</c></exception> /// <exception cref="System.InvalidOperationException">Thrown if <paramref name="allocator"> is <c>Allocator.None</c></exception> public virtual void GetFaceMesh(TrackableId faceId, Allocator allocator, ref XRFaceMesh faceMesh) { if (allocator == Allocator.Temp) { throw new InvalidOperationException("Allocator.Temp is not supported. Use Allocator.TempJob if you wish to use a temporary allocator."); } if (allocator == Allocator.None) { throw new InvalidOperationException("Allocator.None is not a valid allocator."); } m_Provider.GetFaceMesh(faceId, allocator, ref faceMesh); }
static NativeArray <ARKitBlendShapeCoefficient> GetCoefficients(UnityEngine.XR.ARSubsystems.TrackableId id, XRFaceSubsystem subsystem) { #if UNITY_EDITOR if (subsystem is ARKitFaceRemoteSubsystem) { return(((ARKitFaceRemoteSubsystem)subsystem).GetBlendShapeCoefficients(id, Allocator.Temp)); } #else if (subsystem is ARKitFaceSubsystem) { return(((ARKitFaceSubsystem)subsystem).GetBlendShapeCoefficients(id, Allocator.Temp)); } #endif return(default(NativeArray <ARKitBlendShapeCoefficient>)); }
/// <summary> /// Constructs an <see cref="XRTrackedImage"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with this tracked image.</param> /// <param name="sourceImageId">A <c>GUID</c> associated with the source image.</param> /// <param name="pose">The <c>Pose</c> associated with the detected image.</param> /// <param name="size">The size (dimensions) of the detected image.</param> /// <param name="trackingState">The <see cref="TrackingState"/> of the detected image.</param> /// <param name="nativePtr">A native pointer associated with the detected image.</param> public XRTrackedImage( TrackableId trackableId, Guid sourceImageId, Pose pose, Vector2 size, TrackingState trackingState, IntPtr nativePtr) { m_Id = trackableId; m_SourceImageId = sourceImageId; m_Pose = pose; m_Size = size; m_TrackingState = trackingState; m_NativePtr = nativePtr; }
/// <summary> /// Retrieve point cloud data (positions, confidence values, and identifiers) /// for the point cloud with the given <paramref name="trackableId"/>. /// </summary> /// <param name="trackableId">The point cloud for which to retrieve data.</param> /// <param name="allocator">The allocator to use when creating the <c>NativeArray</c>s in the returned <see cref="XRPointCloudData"/>. <c>Allocator.Temp</c> is not supported; use <c>Allocator.TempJob</c> if you need temporary memory.</param> /// <returns> /// A new <see cref="XRPointCloudData"/> with newly allocated <c>NativeArray</c>s using <paramref name="allocator"/>. /// The caller owns the memory and is responsible for calling <see cref="XRPointCloudData.Dispose"/> on it. /// </returns> public XRPointCloudData GetPointCloudData( TrackableId trackableId, Allocator allocator) { if (allocator == Allocator.Temp) { throw new InvalidOperationException("Allocator.Temp is not supported. Use Allocator.TempJob if you wish to use a temporary allocator."); } if (allocator == Allocator.None) { throw new InvalidOperationException("Allocator.None is not a valid allocator."); } return(provider.GetPointCloudData(trackableId, allocator)); }
/// <summary> /// Gets the boundary polygon describing the plane. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with the plane of which to retrieve the boundary.</param> /// <param name="allocator">An <c>Allocator</c> to use if <paramref name="boundary"/> needs to be created. <c>Allocator.Temp</c> is not supported; use <c>Allocator.TempJob</c> if you need temporary memory.</param> /// <param name="boundary">The boundary will be stored here. If <c>boundary</c> is the same length as the new boundary, /// it is simply overwritten with the new data. Otherwise, it is disposed and recreated with the correct length.</param> public void GetBoundary( TrackableId trackableId, Allocator allocator, ref NativeArray <Vector2> boundary) { if (allocator == Allocator.Temp) { throw new InvalidOperationException("Allocator.Temp is not supported. Use Allocator.TempJob if you wish to use a temporary allocator."); } if (allocator == Allocator.None) { throw new InvalidOperationException("Allocator.None is not a valid allocator."); } provider.GetBoundary(trackableId, allocator, ref boundary); }
void OnAddAngle(UnityEngine.XR.ARSubsystems.TrackableId trackeableID, Vector3 pos, Quaternion rot) { WallData wallData = GetWallData(trackeableID); GameObject go = Instantiate(placedPrefab); go.transform.SetParent(container); go.transform.position = pos; go.transform.rotation = rot; if (wallData == null) { wallData = new WallData(); wallData.anglesGO = new List <GameObject>(); wallData.trackeableID = trackeableID; walls.Add(wallData); } wallData.anglesGO.Add(go); }
public override void GetBoundary( UnityTrackableId trackableId, Allocator allocator, ref NativeArray <Vector2> boundary) { var plane = ARKitReceiver.Instance?.Plane; byte[] rawBytes; if (plane == null || !plane.meshes.TryGetValue(trackableId, out rawBytes)) { CreateOrResizeNativeArrayIfNecessary(0, allocator, ref boundary); return; } int size = rawBytes.Length / UnsafeUtility.SizeOf <Vector2>(); CreateOrResizeNativeArrayIfNecessary(size, allocator, ref boundary); boundary.CopyFromRawBytes(rawBytes); }
/// <summary> /// Constructs a new <see cref="BoundedPlane"/>. This is just a data container /// for a plane's session relative data. These are typically created by /// <see cref="XRPlaneSubsystem.GetChanges(Unity.Collections.Allocator)"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with the point cloud.</param> /// <param name="subsumedBy">The plane which subsumed this one. Use <see cref="TrackableId.invalidId"/> if it has not been subsumed.</param> /// <param name="pose">The <c>Pose</c> associated with the point cloud.</param> /// <param name="center">The center, in plane-space (relative to <paramref name="pose"/>) of the plane.</param> /// <param name="size">The dimensions associated with the point cloud.</param> /// <param name="alignment">The <see cref="PlaneAlignment"/> associated with the point cloud.</param> /// <param name="trackingState">The <see cref="TrackingState"/> associated with the point cloud.</param> /// <param name="nativePtr">The native pointer associated with the point cloud.</param> public BoundedPlane( TrackableId trackableId, TrackableId subsumedBy, Pose pose, Vector2 center, Vector2 size, PlaneAlignment alignment, TrackingState trackingState, IntPtr nativePtr) { m_TrackableId = trackableId; m_SubsumedById = subsumedBy; m_Pose = pose; m_Center = center; m_Size = size; m_Alignment = alignment; m_TrackingState = trackingState; m_NativePtr = nativePtr; }
void AddToSetAndThrowIfDuplicate( TrackableId trackableId, bool shouldBeInDictionary, string action) { if (!s_IdSet.Add(trackableId)) { throw new InvalidOperationException( string.Format( "Trackable {0} being {1} this frame has at least one other action associated with it.", trackableId, action)); } if (m_Trackables.Contains(trackableId) != shouldBeInDictionary) { throw new InvalidOperationException(string.Format( "Trackable {0} is being {1} but is {2} in the list of trackables.", trackableId, action, shouldBeInDictionary ? "not" : "already")); } }
public override void GetFaceMesh(UnityTrackableId faceId, Allocator allocator, ref XRFaceMesh faceMesh) { var face = ARKitReceiver.Instance?.Face; var remoteMesh = face.meshes.FirstOrDefault(m => (UnityTrackableId)m.id == faceId); if (remoteMesh == null) { Debug.LogWarning($"Mesh ID:{faceId} not found"); return; } XRFaceMesh.Attributes attr = XRFaceMesh.Attributes.UVs; faceMesh.Resize(remoteMesh.vertices.Length / UnsafeUtility.SizeOf <Vector3>(), remoteMesh.indices.Length / sizeof(int) / 3, // count of triangles attr, allocator); // Debug.Log($"GetFaceMesh; {allocator}"); // Debug.Log($"nativearray: vert:{faceMesh.vertices.Length} idx:{faceMesh.indices.Length}, uvs:{faceMesh.uvs.Length}"); faceMesh.vertices.CopyFromRawBytes(remoteMesh.vertices); faceMesh.indices.CopyFromRawBytes(remoteMesh.indices); faceMesh.uvs.CopyFromRawBytes(remoteMesh.uvs); }
/// <summary> /// Overridden by the provider to remove the environment probe matching the trackable ID from /// the AR session. /// </summary> /// <param name='trackableId'>Trackable ID of the environment probe to be removed from the AR session.</param> /// <returns> /// <c>true</c> whether the environment probe is found in the current AR session and will be removed. /// Otherwise, <c>false</c>. /// </returns> /// <remarks> /// This method may be used to remove both manually-placed and automatically-placed environment probes if the /// implementation supports such removals. Providers should implement this method remove environment probes of /// the allowed types and to throw a <c>System.NotSupportedException</c> for removals of environment probes of /// disallowed types. /// </remarks> /// <exception cref="System.NotSupportedException">Thrown in the default implementation.</exception> public virtual bool RemoveEnvironmentProbe(TrackableId trackableId) { throw new NotSupportedException("removal of environment probes is not supported by this implementation"); }
/// <summary> /// Get the mesh data associated with the face with <paramref name="faceId"/>. The <paramref name="faceMesh"/> /// should be reused if it is the correct size, otherwise, its arrays should be reallocated with <paramref name="allocator"/>. /// Use <see cref="XRFaceMesh.Assign(XRFaceMesh)"/> to ensure unused <c>NativeArray</c>s are disposed properly and /// <see cref="CreateOrResizeNativeArrayIfNecessary"/> to resize individual arrays. /// </summary> /// <param name="faceId">The <see cref="TrackableId"/> for a <see cref="XRFace"/>.</param> /// <param name="allocator">The allocator to use for the returned data if a resize is necessary.</param> /// <param name="faceMesh">The container for the mesh data to either re-use or re-allocate.</param> /// <example> /// <code> /// var vertices = faceMesh.vertices; /// CreateOrResizeNativeArrayIfNecessary(numVertices, allocator, ref vertices); /// /// ... /// /// faceMesh.Assign(new XRFaceMesh /// { /// vertices = vertices, /// indices = ... /// }); /// </code> /// </example> public virtual void GetFaceMesh(TrackableId faceId, Allocator allocator, ref XRFaceMesh faceMesh) { faceMesh.Dispose(); faceMesh = default(XRFaceMesh); }
/// <summary> /// Should remove an existing anchor with <see cref="TrackableId"/> <paramref name="anchorId"/>. /// </summary> /// <param name="anchorId">The id of an existing anchor to remove.</param> /// <returns>Should return <c>true</c> if the anchor was removed, otherwise <c>false</c>. If the anchor /// does not exist, return <c>false</c>.</returns> public virtual bool TryRemoveAnchor(TrackableId anchorId) => false;
/// <summary> /// Attempts to create a new anchor "attached" to the trackable with id <paramref name="trackableToAffix"/>. /// The behavior of the anchor depends on the type of trackable to which this anchor is attached. /// </summary> /// <param name="trackableToAffix">The id of the trackable to which to attach.</param> /// <param name="pose">The pose, in session space, of the anchor to create.</param> /// <param name="anchor">The new anchor. Only valid if this method returns <c>true</c>.</param> /// <returns><c>true</c> if the new anchor was added, otherwise <c>false</c>.</returns> public bool TryAttachAnchor(TrackableId trackableToAffix, Pose pose, out XRAnchor anchor) { return(provider.TryAttachAnchor(trackableToAffix, pose, out anchor)); }
/// <summary> /// Removes a raycast previously added with /// <see cref="TryAddRaycast(UnityEngine.Vector2,float,out UnityEngine.XR.ARSubsystems.XRRaycast)"/> /// or /// <see cref="TryAddRaycast(UnityEngine.Ray,float,out UnityEngine.XR.ARSubsystems.XRRaycast)"/> /// </summary> /// <param name="trackableId">The unique identifier associated with the raycast to remove.</param> public virtual void RemoveRaycast(TrackableId trackableId) { }
/// <summary> /// Generate point cloud data (positions, confidence values, and identifiers) /// for the point cloud with the given <paramref name="trackableId"/>. /// </summary> /// <param name="trackableId">The point cloud for which to retrieve data.</param> /// <param name="allocator">The allocator to use when creating the <c>NativeArray</c>s in the returned <see cref="XRPointCloudData"/>.</param> /// <returns> /// A new <see cref="XRPointCloudData"/> with newly allocated <c>NativeArray</c>s using <paramref name="allocator"/>. /// The caller owns the memory and is responsible for calling <see cref="XRPointCloudData.Dispose"/> on it. /// </returns> public abstract XRPointCloudData GetPointCloudData(TrackableId trackableId, Allocator allocator);
/// <summary> /// Removes an existing raycast by its <see cref="TrackableId"/>. /// </summary> /// <param name="trackableId">The unique identifier for the raycast to remove.</param> public void RemoveRaycast(TrackableId trackableId) => m_Provider.RemoveRaycast(trackableId);
/// <summary> /// Method to be implemented by the provider to get the skeleton joints for the requested trackable identifier. /// </summary> /// <param name="trackableId">The human body trackable identifier for which to query.</param> /// <param name="allocator">The memory allocator to use for the returned arrays.</param> /// <param name="skeleton">The array of skeleton joints to update and returns.</param> /// <exception cref="System.NotSupportedException">Thrown for platforms not supporting human body pose /// estimation.</exception> public virtual void GetSkeleton(TrackableId trackableId, Allocator allocator, ref NativeArray <XRHumanBodyJoint> skeleton) { throw new NotSupportedException("Skeletons are not supported by this implementation."); }
/// <summary> /// Query the provider for the skeleton joints for the requested trackable identifier. /// </summary> /// <param name="trackableId">The human body trackable identifier for which to query.</param> /// <param name="allocator">The memory allocator to use for the returned arrays.</param> /// <param name="skeleton">The array of skeleton joints to update and returns.</param> public void GetSkeleton(TrackableId trackableId, Allocator allocator, ref NativeArray <XRHumanBodyJoint> skeleton) { m_Provider.GetSkeleton(trackableId, allocator, ref skeleton); }
/// <summary> /// Generate point cloud data (positions, confidence values, & identifiers) /// for the point cloud with the given <paramref name="trackableId"/>. /// </summary> /// <param name="trackableId">The point cloud for which to retrieve data.</param> /// <param name="allocator">The allocator to use when creating the <c>NativeArray</c>s in the returned <see cref="XRPointCloudData"/>.</param> /// <returns> /// A new <see cref="XRPointCloudData"/> with newly allocated <c>NativeArray</c>s using <paramref name="allocator"/>. /// The caller owns the memory and is responsible for calling <see cref="XRPointCloudData.Dispose"/> on it. /// </returns> public virtual XRPointCloudData GetPointCloudData( TrackableId trackableId, Allocator allocator) { return(default(XRPointCloudData)); }