Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development tools #8

Draft
wants to merge 3 commits into
base: rt-xr/development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Runtime/Scripts/Extensions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Scripts/Extensions/MPEG.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
*/

using GLTFast.Schema;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

#if UNITY_ANDROID
using System.Collections.Generic;
using System.Linq;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
#endif
using System.Reflection;
#endif

namespace GLTFast
{
Expand Down Expand Up @@ -46,6 +47,8 @@ public class TrackableFloor : MonoBehaviour, IMpegTrackable
private Bounds m_SceneBounds;
private Vector3 m_ScaleFactor = Vector3.one;
private bool m_ApplyScale = false;
private MPEG_TrackableEvent m_TrackableEvent;


public void InitFromGltf(Trackable track)
{
Expand All @@ -71,12 +74,13 @@ private void Awake()
if(m_ArPlaneManager == null)
{
m_ArPlaneManager = obj.AddComponent<ARPlaneManager>();
m_ArPlaneManager.planePrefab = Resources.Load<GameObject>("Plane");
}
m_ArPlaneManager.enabled = true;
}

public void Init()
{
public void Init()
{
var res = m_ArPlaneManager.descriptor;

//check if classification is supported
Expand All @@ -89,22 +93,34 @@ public void Init()
{
m_SupportClassification = m_ArPlaneManager.descriptor.supportsClassification;
}


m_TrackableEvent = new MPEG_TrackableEvent();
m_TrackableEvent.trackableType = Schema.TrackableType.TRACKABLE_FLOOR;
//force horizontal detection
m_ArPlaneManager.requestedDetectionMode = PlaneDetectionMode.Horizontal;
m_ArPlaneManager.planesChanged += PlanesChanged;
}

private void InvokeTrackableEvent(TrackableEventType _type, Vector3 _pos, Quaternion _rot)
{
m_TrackableEvent.trackableEventType = _type;
m_TrackableEvent.anchorPosition = _pos;
m_TrackableEvent.anchorRotation = _rot;
TrackableModule.GetInstance().OnAnchoringOccurs(this, m_TrackableEvent);
}

private void PlanesChanged(ARPlanesChangedEventArgs arg)
{
if(arg.added != null)
{
if(arg.added.Count==0)
{
return;
}

//Floor detection
ARPlane tempPlane = arg.added[0];
Vector3 _anchorPosition = tempPlane.gameObject.transform.position;
Quaternion _anchorRotation = tempPlane.gameObject.transform.rotation;

if (m_SupportClassification && tempPlane.classification == PlaneClassification.Floor)
{
//Kept first detected
Expand Down Expand Up @@ -132,35 +148,41 @@ private void PlanesChanged(ARPlanesChangedEventArgs arg)
}
}
}

InvokeTrackableEvent(TrackableEventType.ADDED, _anchorPosition, _anchorRotation);
}
else if(arg.removed!= null)
{
if(arg.removed.Count == 0)
{
return;
}
return;

ARPlane tempPlane = arg.removed[0];
Vector3 _anchorPosition = tempPlane.gameObject.transform.position;
Quaternion _anchorRotation = tempPlane.gameObject.transform.rotation;

if (tempPlane.trackableId == m_Id)
{
m_Plane = null;
m_Id = TrackableId.invalidId;
RemoveAnchor();
}
InvokeTrackableEvent(TrackableEventType.REMOVED, _anchorPosition, _anchorRotation);
}
else if(arg.updated != null )
{
if(arg.updated.Count==0)
{
if(arg.updated.Count == 0)
return;
}

ARPlane tempPlane = arg.updated[0];
Vector3 _anchorPosition = tempPlane.gameObject.transform.position;
Quaternion _anchorRotation = tempPlane.gameObject.transform.rotation;

if (tempPlane.trackableId == m_Id)
{
m_Plane = tempPlane;
m_Id = tempPlane.trackableId;
}
}
InvokeTrackableEvent(TrackableEventType.UPDATED, _anchorPosition, _anchorRotation);
}
}

Expand Down Expand Up @@ -200,7 +222,7 @@ private bool BuildAnchorInternal()
var res = CheckRequiredSpace(m_Plane);
if(!res)
{
return false;;
return false;
}
}
Debug.Log("TrackableFloor::_requiredAlignedAndScale "+ m_RequiredAlignedAndScale);
Expand Down Expand Up @@ -232,7 +254,6 @@ private bool BuildAnchorInternal()
}
m_Attached = true;
}
UpdatePlaneVisibility(false);
return true;
}

Expand All @@ -257,14 +278,6 @@ public void AttachNodeToTrackable(GameObject go)
}
}

private void UpdatePlaneVisibility(bool visible)
{
foreach (var plane in m_ArPlaneManager.trackables)
{
plane.gameObject.SetActive(visible);
}
}

public void RequiredSpace(UnityEngine.Vector3 requiredSpace)
{
Debug.Log("TrackableFloor::RequiredSpace");
Expand Down Expand Up @@ -409,11 +422,7 @@ void Update()
}
m_IsGoActivated = false;
}
}
else
{
UpdatePlaneVisibility(false);
}
}
}
public void DumpAttributs()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class TrackableMarker2D : MonoBehaviour, IMpegTrackable
// private bool m_RequiredAlignedAndScale =false;
// private bool m_RequiredSpace = false;

private MPEG_TrackableEvent m_TrackableEvent;

/// <summary>
/// If an image is detected but no source texture can be found,
/// this texture is used instead.
Expand All @@ -70,6 +72,8 @@ public void Init()
int matIndex = -1;
int texIndex = -1;
int sourceIndex = -1;
m_TrackableEvent = new MPEG_TrackableEvent();
m_TrackableEvent.trackableType = Schema.TrackableType.TRACKABLE_MARKER_2D;

Debug.Log("TrackableMarker2D::Init");

Expand Down Expand Up @@ -198,6 +202,8 @@ void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
imgTrack = eventArgs.added[0];
m_Id = imgTrack.trackableId;
m_TrackableEvent.trackableEventType = TrackableEventType.ADDED;
TrackableModule.GetInstance().OnAnchoringOccurs(this, m_TrackableEvent);
}
}
}
Expand All @@ -216,6 +222,9 @@ void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
ARTrackedImage _image = _updateImages[i];
m_Id = _image.trackableId;
m_Anchor.transform.SetPositionAndRotation(_image.transform.position, _image.transform.rotation);

m_TrackableEvent.trackableEventType = TrackableEventType.UPDATED;
TrackableModule.GetInstance().OnAnchoringOccurs(this, m_TrackableEvent);
}
}

Expand All @@ -229,6 +238,8 @@ void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
ClearInfo(imgTrack);
imgTrack = null;
m_Id = TrackableId.invalidId;
m_TrackableEvent.trackableEventType = TrackableEventType.REMOVED;
TrackableModule.GetInstance().OnAnchoringOccurs(this, m_TrackableEvent);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Scripts/Extensions/MPEG/IMPEG_Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public interface IMPEG_Module<T>
{
public void Register(System.Action<T> action, int index);
public void Unregister(int index);
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Extensions/MPEG/IMPEG_Module.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Scripts/Extensions/MPEG/Interactivity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ActionManipulate : MonoBehaviour, IMpegInteractivityAction
private object m_ReadInputValue;
private bool m_IsInputPerformed;
private Vector3 m_Position;
private MPEG_ActionManipulateEvent m_ManipulateEvent;

private UnityEngine.Camera Camera
{
get
Expand Down Expand Up @@ -60,7 +62,9 @@ public void Init(Schema.Action action)
m_Targets = VirtualSceneGraph.GetGameObjectsFromIndexes(action.nodes);
m_Delay = action.delay;
m_CurrentManipulateType = action.manipulateActionType;
m_Camera = UnityEngine.Camera.main;
m_Camera = Camera.main;
m_ManipulateEvent = new MPEG_ActionManipulateEvent();
m_ManipulateEvent.inputAction = m_InputAction;
}

private void OnInputCanceled(InputAction.CallbackContext _cbk)
Expand Down Expand Up @@ -94,14 +98,16 @@ private void Execute()
return;
}

switch(m_CurrentManipulateType)
switch (m_CurrentManipulateType)
{
case Schema.Action.ManipulateActionType.ACTION_MANIPULATE_FREE: ManipulateFree(); break;
case Schema.Action.ManipulateActionType.ACTION_MANIPULATE_ROTATE: ManipulateRotate(); break;
case Schema.Action.ManipulateActionType.ACTION_MANIPULATE_SCALE: ManipulateScale(); break;
case Schema.Action.ManipulateActionType.ACTION_MANIPULATE_SLIDE: ManipulateSlide(); break;
case Schema.Action.ManipulateActionType.ACTION_MANIPULATE_TRANSLATE: ManipulateTranslate(); break;
}

ActionModule.GetInstance().OnActionOccurs(this, m_ManipulateEvent);
}

private void ManipulateFree()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public class Behavior : MonoBehaviour, IMpegInteractivityBehavior
private TriggerActivationControl m_TriggerActivationControl;
private IMpegInteractivityAction m_InterruptAction;

private List<System.Action> m_GameEngineActions;
private MPEG_BehaviourEvent m_BehaviourEvent;

public void InitializeBehavior(Schema.Behavior bhv)
{
m_BehaviourEvent = new MPEG_BehaviourEvent();

// Cache trigger control
m_TriggerActivationControl = bhv.triggersActivationControl;

Expand Down Expand Up @@ -90,7 +92,6 @@ public void InitializeBehavior(Schema.Behavior bhv)
}

// Helper to get game object actions associated with mpeg actions
m_GameEngineActions = new List<System.Action>();
m_IsRunning = true;
}

Expand All @@ -107,7 +108,15 @@ public bool AreTriggersActived()
TriggerActivationControl actControl = ProcessState(m_HasEverExited, m_HasEverEntered, m_LastFrameCombinationResult, combinationResult);
UpdateStates(actControl);
m_LastFrameCombinationResult = combinationResult;
return actControl == m_TriggerActivationControl;

bool _yes = actControl == m_TriggerActivationControl;

if (_yes)
{
BehaviourModule.GetInstance().OnBehaviourOccurs(this, m_BehaviourEvent);
}

return _yes;
}

private void RunTriggers()
Expand Down Expand Up @@ -199,16 +208,6 @@ public void ActivateActions()
m_Action[i].Invoke();
}
}

for(int i = 0; i < m_GameEngineActions.Count; i++)
{
m_GameEngineActions[i].Invoke();
}
}

public void AddGameEngineAction(System.Action action)
{
m_GameEngineActions.Add(action);
}

public void Interrupt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

using System;
using System.Collections.Generic;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class CollisionNodeTrigger : MonoBehaviour

public void Init()
{
Debug.Log("Init collision detector");
if (!m_HasInit)
{
m_Target = new List<GameObject>();
Expand Down
Loading