浏览代码

testing out switching tracking states at runtime, from body tracking to world tracking

/BodyRecording
Dan 5 年前
当前提交
3b87ba09
共有 3 个文件被更改,包括 152 次插入57 次删除
  1. 135
      Assets/BodyRecording/Scenes/BodyRecording.unity
  2. 63
      Assets/BodyRecording/Scripts/TrackingManager.cs
  3. 11
      Assets/BodyRecording/Scripts/TrackingManager.cs.meta

135
Assets/BodyRecording/Scenes/BodyRecording.unity


m_EditorClassIdentifier:
m_FocusMode: 1
m_LightEstimationMode: 1
--- !u!1 &331955340
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 331955341}
m_Layer: 5
m_Name: RecordingUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &331955341
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 331955340}
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_Children:
- {fileID: 8086037338594968975}
- {fileID: 5271855684343745726}
m_Father: {fileID: 4639637737360137916}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &427002218
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 970751604}
- component: {fileID: 970751603}
- component: {fileID: 970751605}
- component: {fileID: 970751606}
m_Layer: 0
m_Name: BodyManager
m_TagString: Untagged

m_Name:
m_EditorClassIdentifier:
m_HumanBodyManager: {fileID: 1335839540}
m_BodyRecordingUI: {fileID: 0}
m_BodyRecordingUI: {fileID: 331955340}
--- !u!114 &970751606
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 970751602}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f5247b6b4b81442e392360fca10fb452, type: 3}
m_Name:
m_EditorClassIdentifier:
TrackingState: 0
m_Session: {fileID: 0}
m_SessionOrigin: {fileID: 1335839534}
m_PlaneManager: {fileID: 1335839537}
m_PointCloudManager: {fileID: 1335839536}
m_RaycastManager: {fileID: 1335839538}
m_HumanBodyManager: {fileID: 1335839540}
m_PlaceObjectsOnPlane: {fileID: 1335839539}
--- !u!1 &1015722065
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335839533}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7ab0e80cee9cc1d44928bfe488dd1e2d, type: 3}
m_Name:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335839533}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e1760703bbd54c04488a8d10600262ab, type: 3}
m_Name:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335839533}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa17d122634046b4a8e23048891fafc5, type: 3}
m_Name:

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1335839533}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 446fc7fee4cf2ad4daa02222a84869c4, type: 3}
m_Name:

m_HumanBodyPose3DEstimationEnabled: 1
m_HumanBodyPose3DScaleEstimationEnabled: 0
m_HumanBodyPrefab: {fileID: 0}
--- !u!1 &1397542768
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1397542775}
m_Layer: 5
m_Name: CaptureButtonEndPOS
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1397542775
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1397542768}
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_Children: []
m_Father: {fileID: 4639637737360137916}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
m_AnchoredPosition: {x: -107, y: 206}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1827046856
CanvasRenderer:
m_ObjectHideFlags: 0

m_Children:
- {fileID: 1827046858}
m_Father: {fileID: 4639637737360137916}
m_RootOrder: 3
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 28d34680a4a05470fb3a7f4c6891e628, type: 3}
m_Type: 0
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4

- component: {fileID: 3606570843461662363}
- component: {fileID: 1363225347854517656}
m_Layer: 5
m_Name: Canvas
m_Name: ScreenspaceCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 8086037338594968975}
- {fileID: 5271855684343745726}
- {fileID: 1397542775}
- {fileID: 331955341}
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7493682544981917024}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_Father: {fileID: 4639637737360137916}
m_Father: {fileID: 331955341}
m_AnchoredPosition: {x: -155, y: -210}
m_AnchoredPosition: {x: -128, y: -128}
m_SizeDelta: {x: 256, y: 256}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &5563260606233534328

m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_MethodName: RecordingToggle
- m_Target: {fileID: 970751606}
m_MethodName: SwitchToWorldTracking
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 6eda137eea4ab4e1081ef51fd7d5e3a6, type: 3}
m_Sprite: {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!1 &7493682544981917024
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9092903152545693956}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_Father: {fileID: 4639637737360137916}
m_Father: {fileID: 331955341}
m_AnchoredPosition: {x: -1.7, y: 210.2}
m_AnchoredPosition: {x: 0, y: 256}
m_SizeDelta: {x: 256, y: 256}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &8789006592476212973

63
Assets/BodyRecording/Scripts/TrackingManager.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class TrackingManager : MonoBehaviour
{
public enum CurrentTrackingState
{
BodyTracking,
WorldTracking
}
public CurrentTrackingState TrackingState;
[SerializeField]
ARSession m_Session;
[SerializeField]
ARSessionOrigin m_SessionOrigin;
[SerializeField]
ARPlaneManager m_PlaneManager;
[SerializeField]
ARPointCloudManager m_PointCloudManager;
[SerializeField]
ARRaycastManager m_RaycastManager;
[SerializeField]
ARHumanBodyManager m_HumanBodyManager;
[SerializeField]
PlaceObjectsOnPlane m_PlaceObjectsOnPlane;
public void SwitchToWorldTracking()
{
SwitchTracking(CurrentTrackingState.WorldTracking);
}
void SwitchTracking(CurrentTrackingState newTrackingState)
{
if (newTrackingState == CurrentTrackingState.BodyTracking)
{
}
else
{
// clean up and remove tracked bodies
m_HumanBodyManager.SetTrackablesActive(false);
m_HumanBodyManager.enabled = false;
// enable subsystems for world tracking
m_PlaneManager.enabled = true;
m_PointCloudManager.enabled = true;
m_RaycastManager.enabled = true;
m_PlaceObjectsOnPlane.enabled = true;
}
}
}

11
Assets/BodyRecording/Scripts/TrackingManager.cs.meta


fileFormatVersion: 2
guid: f5247b6b4b81442e392360fca10fb452
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存