mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 07:08:51 -05:00
TrackedImages: Sample scene for multiple tracked images
This commit is contained in:
parent
6b34f941fb
commit
37c11b88b2
@ -562,11 +562,11 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_CameraStartingPose:
|
||||
position: {x: 0.22, y: 0.9345944, z: -0.21}
|
||||
rotation: {x: -0.16794881, y: 0.414527, z: -0.078137435, w: -0.8909855}
|
||||
position: {x: 0, y: 1.1176, z: 0}
|
||||
rotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_CameraMovementBounds:
|
||||
m_Center: {x: 0.044999838, y: 0.545, z: 0.00000011920929}
|
||||
m_Extent: {x: 1.3000004, y: 0.5500002, z: 1.2500005}
|
||||
m_Extent: {x: 1.3000004, y: 1, z: 1.2500005}
|
||||
m_DefaultViewPose:
|
||||
position: {x: 0, y: 1.0609863, z: -1.5}
|
||||
rotation: {x: -0.16100603, y: 0.1567927, z: -0.025916385, w: -0.97407466}
|
||||
|
@ -23,19 +23,17 @@ MonoBehaviour:
|
||||
m_SerializedTextureGuid:
|
||||
m_GuidLow: 9512191862091720473
|
||||
m_GuidHigh: 4777916657343582074
|
||||
m_Size: {x: 0, y: 0}
|
||||
m_SpecifySize: 0
|
||||
m_Size: {x: 0.1, y: 0.1}
|
||||
m_SpecifySize: 1
|
||||
m_Name: qr-code-01
|
||||
m_Texture: {fileID: 6192944022281365145, guid: cf56a719181984027acf62a7e2914e42,
|
||||
type: 3}
|
||||
m_Texture: {fileID: 0}
|
||||
- m_SerializedGuid:
|
||||
m_GuidLow: 5000005727017362315
|
||||
m_GuidHigh: 17579163435370083502
|
||||
m_SerializedTextureGuid:
|
||||
m_GuidLow: 8415066286968600214
|
||||
m_GuidHigh: 355843442228713881
|
||||
m_Size: {x: 0, y: 0}
|
||||
m_SpecifySize: 0
|
||||
m_Size: {x: 0.1, y: 0.1}
|
||||
m_SpecifySize: 1
|
||||
m_Name: qr-code-02
|
||||
m_Texture: {fileID: 6192944022281365145, guid: fc20f696523374c899d9b1b1b935f004,
|
||||
type: 3}
|
||||
m_Texture: {fileID: 0}
|
||||
|
@ -30,7 +30,7 @@ Transform:
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1119266294257528679}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
@ -131,11 +131,12 @@ Transform:
|
||||
m_GameObject: {fileID: 7740556873076377330}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.939, y: 0, z: 2.135}
|
||||
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children:
|
||||
- {fileID: 6463251211347540605}
|
||||
- {fileID: 1629418972370686959}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &2974374142263200146
|
||||
@ -151,3 +152,97 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_DestroyOnRemoval: 1
|
||||
--- !u!1001 &1231279924666610692
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 1119266294257528679}
|
||||
m_Modifications:
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 0.50008726
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: -0.49991274
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0.50008726
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0.49991274
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: -89.98
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 90
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_ConstrainProportionsScale
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 919132149155446097, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
value: 3D RightArrow
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: c8389a6832c69794daffd97728da0cb9, type: 3}
|
||||
--- !u!4 &1629418972370686959 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 1231279924666610692}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
|
@ -26,11 +26,12 @@ Transform:
|
||||
m_GameObject: {fileID: 2334735618901841031}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.939, y: 0, z: 2.135}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 507655295618772503}
|
||||
- {fileID: 7610384848938991257}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &6628545826349043593
|
||||
@ -75,7 +76,7 @@ Transform:
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children: []
|
||||
m_Father: {fileID: 7368655793651849036}
|
||||
@ -151,3 +152,97 @@ SphereCollider:
|
||||
serializedVersion: 3
|
||||
m_Radius: 0.5
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!1001 &7932877230784944498
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 7368655793651849036}
|
||||
m_Modifications:
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 35
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 0.50008726
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: -0.49991274
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0.50008726
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0.49991274
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: -89.98
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 90
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_ConstrainProportionsScale
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 919132149155446097, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
value: 3D RightArrow
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: c8389a6832c69794daffd97728da0cb9, type: 3}
|
||||
--- !u!4 &7610384848938991257 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: c8389a6832c69794daffd97728da0cb9,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 7932877230784944498}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
|
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts/AR/Extensions.meta
Normal file
8
Assets/Scripts/AR/Extensions.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0e8618ff31454360ad62f1a57d5ff5c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
95
Assets/Scripts/AR/Extensions/XROriginExtensions.cs
Normal file
95
Assets/Scripts/AR/Extensions/XROriginExtensions.cs
Normal file
@ -0,0 +1,95 @@
|
||||
// NOTE: This is copied Unity Technologies' AR Foundation Samples project from GitHub (https://github.com/Unity-Technologies/arfoundation-samples/blob/main/Assets/Scripts/Runtime/XROriginExtensions.cs)
|
||||
// The code may be modified to fit the need of the UDRI XRTeam's use-cases
|
||||
|
||||
using System;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARFoundation;
|
||||
|
||||
// MODIFICATION: Namespace changed to fit within UDRI XRT's package namespace conventions
|
||||
namespace MAVRIC.XR.ARFoundation.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains extension methods suitable for replacing the <c>ARSessionOrigin.MakeContentAppearAt</c>
|
||||
/// API as existed in AR Foundation 4.2, allowing users to upgrade projects from
|
||||
/// <see cref="ARSessionOrigin"/> to <see cref="XROrigin"/> with continued access to this API.
|
||||
/// </summary>
|
||||
public static class XROriginExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes <paramref name="content"/> appear to be placed at <paramref name="position"/> with orientation <paramref name="rotation"/>.
|
||||
/// </summary>
|
||||
/// <param name="origin">The <c>XROrigin</c> in the Scene.</param>
|
||||
/// <param name="content">The <c>Transform</c> of the content you wish to affect.</param>
|
||||
/// <param name="position">The position you wish the content to appear at. This could be
|
||||
/// a position on a detected plane, for example.</param>
|
||||
/// <param name="rotation">The rotation the content should appear to be in, relative
|
||||
/// to the <c>Camera</c>.</param>
|
||||
/// <remarks>
|
||||
/// This method does not actually change the <c>Transform</c> of content; instead,
|
||||
/// it updates the <c>XROrigin</c>'s <c>Transform</c> so the content
|
||||
/// appears to be at the given position and rotation. This is useful for placing AR
|
||||
/// content onto surfaces when the content itself cannot be moved at runtime.
|
||||
/// For example, if your content includes terrain or a NavMesh, it cannot
|
||||
/// be moved or rotated dynamically.
|
||||
/// </remarks>
|
||||
public static void MakeContentAppearAt(this XROrigin origin, Transform content, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
MakeContentAppearAt(origin, content, position);
|
||||
MakeContentAppearAt(origin, content, rotation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes <paramref name="content"/> appear to be placed at <paramref name="position"/>.
|
||||
/// </summary>
|
||||
/// <param name="origin">The <c>XROrigin</c> in the Scene.</param>
|
||||
/// <param name="content">The <c>Transform</c> of the content you wish to affect.</param>
|
||||
/// <param name="position">The position you wish the content to appear at. This could be
|
||||
/// a position on a detected plane, for example.</param>
|
||||
/// <remarks>
|
||||
/// This method does not actually change the <c>Transform</c> of content; instead,
|
||||
/// it updates the <c>XROrigin</c>'s <c>Transform</c> so the content
|
||||
/// appears to be at the given position.
|
||||
/// </remarks>
|
||||
public static void MakeContentAppearAt(this XROrigin origin, Transform content, Vector3 position)
|
||||
{
|
||||
if (content == null)
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
|
||||
var originTransform = origin.transform;
|
||||
|
||||
// Adjust the Camera Offset transform to account
|
||||
// for the actual position we want the content to appear at.
|
||||
origin.CameraFloorOffsetObject.transform.position += originTransform.position - position;
|
||||
|
||||
// The XROrigin's position needs to match the content's pivot. This is so
|
||||
// the entire XROrigin rotates around the content (so the impression is that
|
||||
// the content is rotating, not the rig).
|
||||
originTransform.position = content.position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes <paramref name="content"/> appear to have orientation <paramref name="rotation"/> relative to the <c>Camera</c>.
|
||||
/// </summary>
|
||||
/// <param name="origin">The <c>XROrigin</c> in the Scene.</param>
|
||||
/// <param name="content">The <c>Transform</c> of the content you wish to affect.</param>
|
||||
/// <param name="rotation">The rotation the content should appear to be in, relative
|
||||
/// to the <c>Camera</c>.</param>
|
||||
/// <remarks>
|
||||
/// This method does not actually change the <c>Transform</c> of content; instead,
|
||||
/// it updates the <c>XROrigin</c>'s <c>Transform</c> so that the content
|
||||
/// appears to be in the requested orientation.
|
||||
/// </remarks>
|
||||
public static void MakeContentAppearAt(this XROrigin origin, Transform content, Quaternion rotation)
|
||||
{
|
||||
if (content == null)
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
|
||||
// Since we aren't rotating the content, we need to perform the inverse
|
||||
// operation on the XROrigin. For example, if we want the
|
||||
// content to appear to be rotated 90 degrees on the Y axis, we should
|
||||
// rotate our rig -90 degrees on the Y axis.
|
||||
origin.transform.rotation = Quaternion.Inverse(rotation) * content.rotation;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AR/Extensions/XROriginExtensions.cs.meta
Normal file
11
Assets/Scripts/AR/Extensions/XROriginExtensions.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a513f970b04541f288e351b19ab10ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,124 +1,119 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.XR.ARFoundation;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
// NOTE: Taken from https://github.com/dilmerv/UnityARFoundationEssentials/blob/master/Assets/Scripts/TrackedImageInfoMultipleManager.cs
|
||||
// This has been modified to fit the need of the UDRI XRTeam's use-cases
|
||||
|
||||
namespace AR
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARFoundation;
|
||||
|
||||
namespace MAVRIC.GEEKCup.AR
|
||||
{
|
||||
public class TrackedImageChanged : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ARTrackedImageManager m_TrackedImageManager;
|
||||
[SerializeField] private ARTrackedImageManager trackedImageManager;
|
||||
[SerializeField] private GameObject[] arPrefabs;
|
||||
|
||||
[SerializeField] private List<ARTrackedImage> _arTrackedImagePrefabs = new ();
|
||||
[SerializeField] private float3 scaleFactor = new (0.1f, 0.1f, 0.1f);
|
||||
|
||||
private List<ARTrackedImage> _spawned = new ();
|
||||
private Dictionary<string, GameObject> arObjects = new ();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Header("Debug")]
|
||||
[SerializeField] private InputAction m_DebugListImages;
|
||||
#endif
|
||||
|
||||
void OnEnable()
|
||||
private void Awake()
|
||||
{
|
||||
m_TrackedImageManager.trackedImagesChanged += OnChange;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
m_DebugListImages.Enable();
|
||||
m_DebugListImages.performed += Debug_ListImages;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
if (trackedImageManager == null)
|
||||
{
|
||||
m_TrackedImageManager.trackedImagesChanged -= OnChange;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
m_DebugListImages.performed -= Debug_ListImages;
|
||||
m_DebugListImages.Disable();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnChange(ARTrackedImagesChangedEventArgs eventArgs)
|
||||
if (!TryGetComponent(out trackedImageManager))
|
||||
{
|
||||
foreach (var newImage in eventArgs.added)
|
||||
{
|
||||
// Handle added event
|
||||
Debug.Log($"Added image: {newImage.referenceImage.name}");
|
||||
|
||||
foreach (var prefab in _arTrackedImagePrefabs)
|
||||
{
|
||||
if (prefab.referenceImage.name.Equals(newImage.referenceImage.name))
|
||||
{
|
||||
if (_spawned == null)
|
||||
{
|
||||
_spawned = new List<ARTrackedImage>();
|
||||
}
|
||||
|
||||
// Spawn new object
|
||||
Debug.Log("Spawning object...");
|
||||
_spawned.Add(Instantiate(prefab, newImage.transform));
|
||||
Debug.LogError("Failed to find ARTrackedImageManager");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var updatedImage in eventArgs.updated)
|
||||
private void OnEnable()
|
||||
{
|
||||
// Handle updated event
|
||||
Debug.Log($"Updated image: {updatedImage.trackableId} - {updatedImage.trackingState}");
|
||||
if (trackedImageManager == null) return;
|
||||
|
||||
foreach (var spawnedObject in _spawned)
|
||||
trackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
|
||||
|
||||
SpawnAllARObjects();
|
||||
}
|
||||
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (spawnedObject.trackableId == updatedImage.trackableId)
|
||||
if (trackedImageManager == null) return;
|
||||
|
||||
trackedImageManager.trackedImagesChanged -= OnTrackedImagesChanged;
|
||||
|
||||
for (int i = arObjects.Keys.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// Update position
|
||||
Debug.Log("Updating position...");
|
||||
spawnedObject.transform.position = updatedImage.transform.position;
|
||||
var key = arObjects.Keys.ElementAt(i);
|
||||
if (arObjects.Remove(key, out var value))
|
||||
{
|
||||
Destroy(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var removedImage in eventArgs.removed)
|
||||
private void SpawnAllARObjects()
|
||||
{
|
||||
// Handle removed event
|
||||
Debug.Log($"Removed image: {removedImage.referenceImage.name}");
|
||||
// setup all game objects in dictionary
|
||||
foreach (GameObject arObject in arPrefabs)
|
||||
{
|
||||
GameObject newARObject = Instantiate(arObject, Vector3.zero, Quaternion.identity);
|
||||
newARObject.SetActive(false);
|
||||
|
||||
for (int i = _spawned.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var spawnedObject = _spawned[i];
|
||||
|
||||
if (spawnedObject.trackableId == removedImage.trackableId)
|
||||
{
|
||||
// Handle object removal
|
||||
Debug.Log("Removing object...");
|
||||
if (_spawned.Remove(spawnedObject))
|
||||
{
|
||||
// Destroy object
|
||||
Debug.Log("Destroying object...");
|
||||
Destroy(spawnedObject.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
newARObject.name = arObject.name;
|
||||
arObjects.Add(arObject.name, newARObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListAllImages()
|
||||
private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
|
||||
{
|
||||
Debug.Log(
|
||||
$"There are {m_TrackedImageManager.trackables.count} images being tracked.");
|
||||
foreach (ARTrackedImage trackedImage in eventArgs.added)
|
||||
{
|
||||
UpdateARImage(trackedImage);
|
||||
}
|
||||
|
||||
foreach (var trackedImage in m_TrackedImageManager.trackables)
|
||||
foreach (ARTrackedImage trackedImage in eventArgs.updated)
|
||||
{
|
||||
Debug.Log($"Image: {trackedImage.referenceImage.name} is at " +
|
||||
$"{trackedImage.transform.position}");
|
||||
UpdateARImage(trackedImage);
|
||||
}
|
||||
|
||||
foreach (ARTrackedImage trackedImage in eventArgs.removed)
|
||||
{
|
||||
arObjects[trackedImage.name].SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private ARTrackedImage GetImageAt(TrackableId trackableId)
|
||||
private void UpdateARImage(ARTrackedImage trackedImage)
|
||||
{
|
||||
return m_TrackedImageManager.trackables[trackableId];
|
||||
// Assign and Place Game Object
|
||||
AssignGameObject(trackedImage.referenceImage.name, trackedImage.transform.position, scaleFactor, trackedImage.transform.rotation);
|
||||
|
||||
Debug.Log($"trackedImage.referenceImage.name: {trackedImage.referenceImage.name}");
|
||||
}
|
||||
|
||||
private void Debug_ListImages(InputAction.CallbackContext _) => ListAllImages();
|
||||
private void AssignGameObject(string name, Vector3 newPosition, Vector3 newScale, Quaternion newRotation)
|
||||
{
|
||||
if (arPrefabs != null)
|
||||
{
|
||||
GameObject goARObject = arObjects[name];
|
||||
goARObject.SetActive(true);
|
||||
|
||||
goARObject.transform.position = newPosition;
|
||||
goARObject.transform.localScale = newScale;
|
||||
goARObject.transform.localRotation = newRotation;
|
||||
|
||||
foreach (GameObject go in arObjects.Values)
|
||||
{
|
||||
Debug.Log($"Go in arObjects.Values: {go.name}");
|
||||
if (go.name != name)
|
||||
{
|
||||
go.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
Assets/Scripts/TransformTracker.cs
Normal file
27
Assets/Scripts/TransformTracker.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MAVRIC.GEEKCup
|
||||
{
|
||||
public class TransformTracker : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
public TMP_Text output;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
target = transform;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
output.text = JsonUtility.ToJson(target.position, true);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/TransformTracker.cs.meta
Normal file
11
Assets/Scripts/TransformTracker.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e36d5b65f0ec847c8aaa6bd34616f053
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -3,33 +3,45 @@
|
||||
--- !u!159 &1
|
||||
EditorSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_ExternalVersionControlSupport: Visible Meta Files
|
||||
serializedVersion: 12
|
||||
m_SerializationMode: 2
|
||||
m_LineEndingsForNewScripts: 2
|
||||
m_DefaultBehaviorMode: 0
|
||||
m_PrefabRegularEnvironment: {fileID: 0}
|
||||
m_PrefabUIEnvironment: {fileID: 0}
|
||||
m_SpritePackerMode: 0
|
||||
m_SpritePackerCacheSize: 10
|
||||
m_SpritePackerPaddingPower: 1
|
||||
m_Bc7TextureCompressor: 0
|
||||
m_EtcTextureCompressorBehavior: 1
|
||||
m_EtcTextureFastCompressor: 1
|
||||
m_EtcTextureNormalCompressor: 2
|
||||
m_EtcTextureBestCompressor: 4
|
||||
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;asmref;rsp
|
||||
m_ProjectGenerationRootNamespace:
|
||||
m_CollabEditorSettings:
|
||||
inProgressEnabled: 1
|
||||
m_ProjectGenerationRootNamespace: MAVRIC.GEEKCup
|
||||
m_EnableTextureStreamingInEditMode: 1
|
||||
m_EnableTextureStreamingInPlayMode: 1
|
||||
m_EnableEditorAsyncCPUTextureLoading: 0
|
||||
m_AsyncShaderCompilation: 1
|
||||
m_PrefabModeAllowAutoSave: 1
|
||||
m_EnterPlayModeOptionsEnabled: 0
|
||||
m_EnterPlayModeOptions: 3
|
||||
m_ShowLightmapResolutionOverlay: 1
|
||||
m_GameObjectNamingDigits: 1
|
||||
m_GameObjectNamingScheme: 0
|
||||
m_AssetNamingUsesSpace: 1
|
||||
m_InspectorUseIMGUIDefaultInspector: 0
|
||||
m_UseLegacyProbeSampleCount: 0
|
||||
m_SerializeInlineMappingsOnOneLine: 0
|
||||
m_DisableCookiesInLightmapper: 1
|
||||
m_AssetPipelineMode: 1
|
||||
m_RefreshImportMode: 0
|
||||
m_CacheServerMode: 0
|
||||
m_CacheServerEndpoint:
|
||||
m_CacheServerNamespacePrefix: default
|
||||
m_CacheServerEnableDownload: 1
|
||||
m_CacheServerEnableUpload: 1
|
||||
m_CacheServerEnableAuth: 0
|
||||
m_CacheServerEnableTls: 0
|
||||
m_CacheServerValidationMode: 2
|
||||
m_CacheServerDownloadBatchSize: 128
|
||||
m_EnableEnlightenBakedGI: 0
|
||||
|
Loading…
Reference in New Issue
Block a user