感知模擬

您要為您的應用程式建置自動化測試嗎? 您想要讓測試超越元件層級單元測試,並真正練習您的應用程式端對端? 認知仿真是您要尋找的專案。 Perception Simulation 連結庫會將人類和世界輸入數據傳送至您的應用程式,以便您將測試自動化。 例如,您可以模擬想要特定、可重複位置的人輸入,然後使用手勢或動作控制器。

認知模擬可以將類似這樣的模擬輸入傳送至實體 HoloLens、HoloLens 模擬器 (第一代) 、HoloLens 2 模擬器,或已安裝 Mixed Reality Portal 的計算機。 認知模擬會略過 Mixed Reality 裝置上的即時感測器,並將模擬真的輸入傳送至裝置上執行的應用程式。 應用程式會透過他們一律使用的相同 API 接收這些輸入事件,而且無法分辨使用實際感測器與 Perception Simulation 執行之間的差異。 Perception Simulation 是 HoloLens 模擬器用來將模擬輸入傳送至 HoloLens 虛擬機的相同技術。

若要開始在程序代碼中使用模擬,請先建立 IPerceptionSimulationManager 物件。 從該物件中,您可以發出命令來控制模擬「人類」的屬性,包括頭部位置、手部位置和手勢。 您也可以啟用及操作動作控制器。

設定 Visual Studio 專案以進行認知模擬

  1. 在您的開發電腦上安裝 HoloLens 模擬器。 模擬器包含您用於 Perception Simulation 的連結庫。

  2. 在主控台專案 (建立新的 Visual Studio C# 桌面專案,非常適合用來開始) 。

  3. (Project-Add-Reference>>...) ,將下列二進位檔新增至您的專案。您可以在 %ProgramFiles (x86) %\Microsoft XDE\ (版本) 中找到它們,例如 %ProgramFiles (x86) %\Microsoft XDE\10.0.18362.HoloLens 2 0

    注意

    雖然二進位檔是 HoloLens 2 模擬器的一部分,但它們也適用於 desktop.) 上的 Windows Mixed Reality

    a. PerceptionSimulationManager.Interop.dll - Perception Simulation 的 Managed C# 包裝函式。
    b. PerceptionSimulationRest.dll - 用來設定 HoloLens 或模擬器之 Web 套接字通道的連結庫。
    c. SimulationStream.Interop.dll - 仿真的共享類型。

  4. 將實作二進位 PerceptionSimulationManager.dll 新增至您的專案

    a. 請先將它新增為二進位檔至專案, (Project-Add-Existing>> Item...) 。將它儲存為連結,使其不會複製到您的專案源資料夾。
    將 PerceptionSimulationManager.dll 新增至專案作為連結

    b. 然後,確定它會在組建時複製到您的輸出資料夾。 這位於二進位檔的屬性表中。
    標示要複製到輸出目錄 PerceptionSimulationManager.dll

  5. 將您的使用中解決方案平臺設定為 x64。 (如果尚未存在,請使用 Configuration Manager 建立 x64 的平台專案。)

建立 IPerceptionSimulation Manager 物件

若要控制模擬,您會對從 IPerceptionSimulationManager 物件擷取的對象發出更新。 第一個步驟是取得該物件,並將其連線到您的目標裝置或模擬器。 您可以按下工具列中的 [裝置入口網站] 按鈕,以取得模擬器的IP位址

開啟裝置入口網站圖示 開啟裝置入口網站:在模擬器中開啟 HoloLens OS 的 Windows 裝置入口網站。 針對 Windows Mixed Reality,這可以在 [更新 & 安全性] 下的 [設定] 應用程式中擷取,然後在 [啟用裝置入口網站] 底下的 [使用連線] 區段中的 [適用於開發人員]。請務必記下IP位址和埠。

首先,您將呼叫 RestSimulationStreamSink.Create 以取得 RestSimulationStreamSink 物件。 這是您將控制 HTTP 連線的目標裝置或模擬器。 您的命令將會由在裝置或模擬器上執行的 Windows 裝置入口網站 傳遞和處理。 您必須建立物件的四個參數如下:

  • Uri uri - 目標裝置的IP位址 (例如 “https://123.123.123.123"或 “https://123.123.123.123:50080")
  • System.Net.NetworkCredential 認證 - 連線到目標裝置或模擬器上 Windows Device Portal 的使用者名稱/密碼。 如果您要透過其本機位址連線到模擬器, (例如 168。..*) 在同一部計算機上,將會接受任何認證。
  • bool normal - 若為正常優先順序,則為 false 表示低優先順序。 您通常想要針對測試案例將此設定為 true ,這可讓您的測試能夠控制。 模擬器和 Windows Mixed Reality 模擬會使用低優先順序連線。 如果您的測試也使用低優先順序的連線,則最近建立的連接將會處於控制狀態。
  • System.Threading.CancellationToken 令牌 - 取消異步操作的令牌。

其次,您將建立 IPerceptionSimulationManager。 這是您用來控制仿真的物件。 這也必須在異步方法中完成。

控制仿真的人

IPerceptionSimulationManager 具有會傳回 ISimulatedHuman 物件的 Human 属性。 若要控制仿真的人,請在此對象上執行作業。 例如:

manager.Human.Move(new Vector3(0.1f, 0.0f, 0.0f))

基本範例 C# 主控台應用程式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PerceptionSimulation;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Task.Run(async () =>
            {
                RestSimulationStreamSink sink = null;
                CancellationToken token = new System.Threading.CancellationToken();

                try
                {
                    sink = await RestSimulationStreamSink.Create(
                        // use the IP address for your device/emulator
                        new Uri("https://169.254.227.115"),
                        // no credentials are needed for the emulator
                        new System.Net.NetworkCredential("", ""),
                        // normal priorty
                        true,
                        // cancel token
                        token);

                    IPerceptionSimulationManager manager = PerceptionSimulationManager.CreatePerceptionSimulationManager(sink);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                // Always close the sink to return control to the previous application.
                if (sink != null)
                {
                    await sink.Close(token);
                }
            });

            // If main exits, the process exits.  
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }
    }
}

擴充範例 C# 主控台應用程式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PerceptionSimulation;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RestSimulationStreamSink sink = null;
            CancellationToken token = new System.Threading.CancellationToken();

            Task.Run(async () =>
            {
                try
                {
                    sink = await RestSimulationStreamSink.Create(
                        // use the IP address for your device/emulator
                        new Uri("https://169.254.227.115"),
                        // no credentials are needed for the emulator
                        new System.Net.NetworkCredential("", ""),
                        // normal priorty
                        true,
                        // cancel token
                        token);

                    IPerceptionSimulationManager manager = PerceptionSimulationManager.CreatePerceptionSimulationManager(sink);

                    // Now, we'll simulate a sequence of actions.
                    // Sleeps in-between each action give time to the system
                    // to be able to properly react.
                    // This is just an example. A proper automated test should verify
                    // that the app has behaved correctly
                    // before proceeding to the next step, instead of using Sleeps.

                    // Activate the right hand
                    manager.Human.RightHand.Activated = true;

                    // Simulate Bloom gesture, which should cause Shell to disappear
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.Home);
                    Thread.Sleep(2000);

                    // Simulate Bloom gesture again... this time, Shell should reappear
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.Home);
                    Thread.Sleep(2000);

                    // Simulate a Head rotation down around the X axis
                    // This should cause gaze to aim about the center of the screen
                    manager.Human.Head.Rotate(new Rotation3(0.04f, 0.0f, 0.0f));
                    Thread.Sleep(300);

                    // Simulate a finger press & release
                    // Should cause a tap on the center tile, thus launching it
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerPressed);
                    Thread.Sleep(300);
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerReleased);
                    Thread.Sleep(2000);

                    // Simulate a second finger press & release
                    // Should activate the app that was launched when the center tile was clicked
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerPressed);
                    Thread.Sleep(300);
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerReleased);
                    Thread.Sleep(5000);

                    // Simulate a Head rotation towards the upper right corner
                    manager.Human.Head.Rotate(new Rotation3(-0.14f, 0.17f, 0.0f));
                    Thread.Sleep(300);

                    // Simulate a third finger press & release
                    // Should press the Remove button on the app
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerPressed);
                    Thread.Sleep(300);
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.FingerReleased);
                    Thread.Sleep(2000);

                    // Simulate Bloom gesture again... bringing the Shell back once more
                    manager.Human.RightHand.PerformGesture(SimulatedGesture.Home);
                    Thread.Sleep(2000);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            });

            // If main exits, the process exits.  
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();

            // Always close the sink to return control to the previous application.
            if (sink != null)
            {
                sink.Close(token);
            }
        }
    }
}

6-DOF 控制器上的注意事項

在仿真的 6-DOF 控制器上呼叫方法的任何屬性之前,您必須啟用控制器。 不這麼做會導致例外狀況。 從 Windows 10 2019 年 5 月更新 開始,可以將 ISimulatedSixDofController 物件的 Status 屬性設定為 SimulatedSixDofControllerStatus.Active 來安裝並啟動仿真的 6-DOF 控制器。 在 Windows 10 2018 年 10 月更新 和更早版本中,您必須先呼叫位於 \Windows\System32 資料夾中的 PerceptionSimulationDevice 工具,分別安裝仿真的 6-DOF 控制器。 此工具的使用方式如下:

    PerceptionSimulationDevice.exe <action> 6dof <instance>

例如

    PerceptionSimulationDevice.exe i 6dof 1

支援的動作包括:

  • i = 安裝
  • q = query
  • r = remove

支援的實例包括:

  • 1 = 左方 6-DOF 控制器
  • 2 = 右側 6-DOF 控制器

程序的結束代碼會指出成功 (零傳回值) 或失敗, (非零傳回值) 。 使用 『q』 宏指令來查詢是否已安裝控制器時,如果控制器尚未安裝,傳回值將會是零 (0) , (如果已安裝控制器,則傳回值會是 1) 。

拿掉 Windows 10 2018 年 10 月更新 或更早版本的控制器時,請先透過 API 將其狀態設定為 [關閉],然後呼叫 PerceptionSimulationDevice 工具。

此工具必須以系統管理員身分執行。

API 參照

Microsoft.PerceptionSimulation.SimulatedDeviceType

描述模擬裝置類型

public enum SimulatedDeviceType
{
    Reference = 0
}

Microsoft.PerceptionSimulation.SimulatedDeviceType.Reference

虛構參考裝置,PerceptionSimulationManager 的預設值

Microsoft.PerceptionSimulation.HeadTrackerMode

描述前端追蹤器模式

public enum HeadTrackerMode
{
    Default = 0,
    Orientation = 1,
    Position = 2
}

Microsoft.PerceptionSimulation.HeadTrackerMode.Default

預設的前端追蹤。 這表示系統可能會根據運行時間條件選取最佳的前端追蹤模式。

Microsoft.PerceptionSimulation.HeadTrackerMode.Orientation

只有頭部追蹤的方向。 這表示追蹤的位置可能不可靠,而某些相依於前端位置的功能可能無法使用。

Microsoft.PerceptionSimulation.HeadTrackerMode.Position

位置頭部追蹤。 這表示追蹤的頭部位置和方向都是可靠的

Microsoft.PerceptionSimulation.SimulatedGesture

描述模擬手勢

public enum SimulatedGesture
{
    None = 0,
    FingerPressed = 1,
    FingerReleased = 2,
    Home = 4,
    Max = Home
}

Microsoft.PerceptionSimulation.SimulatedGesture.None

sentinel 值,用來表示沒有手勢。

Microsoft.PerceptionSimulation.SimulatedGesture.FingerPressed

手指按下的手勢。

Microsoft.PerceptionSimulation.SimulatedGesture.FingerReleased

手指放開手勢。

Microsoft.PerceptionSimulation.SimulatedGesture.Home

首頁/系統手勢。

Microsoft.PerceptionSimulation.SimulatedGesture.Max

最大有效手勢。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerStatus

模擬 6-DOF 控制器的可能狀態。

public enum SimulatedSixDofControllerStatus
{
    Off = 0,
    Active = 1,
    TrackingLost = 2,
}

Microsoft.PerceptionSimulation.SimulatedSixDofControllerStatus.Off

6-DOF 控制器已關閉。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerStatus.Active

6-DOF 控制器已開啟並追蹤。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerStatus.TrackingLost

6-DOF 控制器已開啟,但無法追蹤。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton

模擬 6-DOF 控制器上支援的按鈕。

public enum SimulatedSixDofControllerButton
{
    None = 0,
    Home = 1,
    Menu = 2,
    Grip = 4,
    TouchpadPress = 8,
    Select = 16,
    TouchpadTouch = 32,
    Thumbstick = 64,
    Max = Thumbstick
}

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.None

用來表示沒有按鈕的 sentinel 值。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Home

按下 [首頁] 按鈕。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Menu

按下 [功能表] 按鈕。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Grip

按下 [底框] 按鈕。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.TouchpadPress

按下 TouchPad。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Select

按下 [選取] 按鈕。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.TouchpadTouch

觸控式觸控板。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Thumbstick

按下遊戲桿。

Microsoft.PerceptionSimulation.SimulatedSixDofControllerButton.Max

最大有效按鈕。

Microsoft.PerceptionSimulation.SimulatedEyesCalibrationState

模擬眼睛的校正狀態

public enum SimulatedGesture
{
    Unavailable = 0,
    Ready = 1,
    Configuring = 2,
    UserCalibrationNeeded = 3
}

Microsoft.PerceptionSimulation.SimulatedEyesCalibrationState.Unavailable

眼睛校正無法使用。

Microsoft.PerceptionSimulation.SimulatedEyesCalibrationState.Ready

眼睛已校正。 這是預設值。

Microsoft.PerceptionSimulation.SimulatedEyesCalibrationState.Configuring

正在校正眼睛。

Microsoft.PerceptionSimulation.SimulatedEyesCalibrationState.UserCalibrationNeeded

必須校正眼睛。

Microsoft.PerceptionSimulation.SimulatedHandJointTrackingAccuracy

手部接合的追蹤精確度。

public enum SimulatedHandJointTrackingAccuracy
{
    Unavailable = 0,
    Approximate = 1,
    Visible = 2
}

Microsoft.PerceptionSimulation.SimulatedHandJointTrackingAccuracy.Unavailable

未追蹤聯合。

Microsoft.PerceptionSimulation.SimulatedHandJointTrackingAccuracy.Approximate

推斷聯合位置。

Microsoft.PerceptionSimulation.SimulatedHandJointTrackingAccuracy.Visible

完全追蹤接合。

Microsoft.PerceptionSimulation.SimulatedHandPose

手部接合的追蹤精確度。

public enum SimulatedHandPose
{
    Closed = 0,
    Open = 1,
    Point = 2,
    Pinch = 3,
    Max = Pinch
}

Microsoft.PerceptionSimulation.SimulatedHandPose.Closed

手部的手指接合已設定為反映封閉式姿勢。

Microsoft.PerceptionSimulation.SimulatedHandPose.Open

手部的手指接合已設定為反映開啟的姿勢。

Microsoft.PerceptionSimulation.SimulatedHandPose.Point

手部的手指接合已設定為反映指向姿勢。

Microsoft.PerceptionSimulation.SimulatedHandPose.Pinch

手部的手指接合已設定為反映捏合姿勢。

Microsoft.PerceptionSimulation.SimulatedHandPose.Max

SimulatedHandPose 的有效最大值。

Microsoft.PerceptionSimulation.PlaybackState

描述播放的狀態。

public enum PlaybackState
{
    Stopped = 0,
    Playing = 1,
    Paused = 2,
    End = 3,
}

Microsoft.PerceptionSimulation.PlaybackState.Stopped

錄製目前已停止,且已準備好播放。

Microsoft.PerceptionSimulation.PlaybackState.Playing

錄製目前正在播放。

Microsoft.PerceptionSimulation.PlaybackState.Paused

錄製目前已暫停。

Microsoft.PerceptionSimulation.PlaybackState.End

錄製已到達結尾。

Microsoft.PerceptionSimulation.Vector3

描述三個元件向量,這可能描述 3D 空間中的點或向量。

public struct Vector3
{
    public float X;
    public float Y;
    public float Z;
    public Vector3(float x, float y, float z);
}

Microsoft.PerceptionSimulation.Vector3.X

此向量的 X 元件。

Microsoft.PerceptionSimulation.Vector3.Y

此向量的 Y 元件。

Microsoft.PerceptionSimulation.Vector3.Z

此向量的 Z 元件。

Microsoft.PerceptionSimulation.Vector3.#ctor (System.Single,System.Single,System.Single)

建構新的 Vector3。

參數

  • x - 向量的 x 元件。
  • y - 向量的 y 元件。
  • z - 向量的 z 元件。

Microsoft.PerceptionSimulation.Rotation3

描述三個元件輪替。

public struct Rotation3
{
    public float Pitch;
    public float Yaw;
    public float Roll;
    public Rotation3(float pitch, float yaw, float roll);
}

Microsoft.PerceptionSimulation.Rotation3.Pitch

旋轉的傾斜元件,繞著 X 軸向下。

Microsoft.PerceptionSimulation.Rotation3.Yaw

旋轉的 Yaw 元件,靠右繞 Y 軸。

Microsoft.PerceptionSimulation.Rotation3.Roll

旋轉的 Roll 元件,位在 Z 軸周圍。

Microsoft.PerceptionSimulation.Rotation3.#ctor (System.Single,System.Single,System.Single)

建構新的 Rotation3。

參數

  • 傾斜 - 旋轉的傾斜元件。
  • yaw - 旋轉的 yaw 元件。
  • roll - 旋轉的滾動元件。

Microsoft.PerceptionSimulation.SimulatedHandJointConfiguration

描述模擬手上的聯合組態。

public struct SimulatedHandJointConfiguration
{
    public Vector3 Position;
    public Rotation3 Rotation;
    public SimulatedHandJointTrackingAccuracy TrackingAccuracy;
}

Microsoft.PerceptionSimulation.SimulatedHandJointConfiguration.Position

接合的位置。

Microsoft.PerceptionSimulation.SimulatedHandJointConfiguration.Rotation

接合的旋轉。

Microsoft.PerceptionSimulation.SimulatedHandJointConfiguration.TrackingAccuracy

接合的追蹤精確度。

Microsoft.PerceptionSimulation.Frustum

描述相機通常會使用的檢視範圍。

public struct Frustum
{
    float Near;
    float Far;
    float FieldOfView;
    float AspectRatio;
}

Microsoft.PerceptionSimulation.Frustum.Near

frustum 中包含的最小距離。

Microsoft.PerceptionSimulation.Frustum.Far

frustum 中包含的最大距離。

Microsoft.PerceptionSimulation.Frustum.FieldOfView

frustum 的水準字段,以弧度為單位, (小於 PI) 。

Microsoft.PerceptionSimulation.Frustum.AspectRatio

檢視的水準欄位與垂直檢視欄位的比例。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration

描述模擬頭戴式裝置顯示器的設定。

public struct SimulatedDisplayConfiguration
{
    public Vector3 LeftEyePosition;
    public Rotation3 LeftEyeRotation;
    public Vector3 RightEyePosition;
    public Rotation3 RightEyeRotation;
    public float Ipd;
    public bool ApplyEyeTransforms;
    public bool ApplyIpd;
}

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.LeftEyePosition

從頭部中心到左眼的轉換,用於立體轉譯。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.LeftEyeRotation

用於立體轉譯的左眼旋轉。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.RightEyePosition

從頭部中心到右眼的轉換,用於立體轉譯。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.RightEyeRotation

用於立體轉譯之用的右眼旋轉。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.Ipd

系統針對立體聲轉譯所報告的 Ipd 值。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.ApplyEyeTransforms

提供給左右眼球轉換的值是否應該視為有效,並套用至執行中的系統。

Microsoft.PerceptionSimulation.SimulatedDisplayConfiguration.ApplyIpd

是否應將提供給 Ipd 的值視為有效,並套用至執行中的系統。

Microsoft.PerceptionSimulation.IPerceptionSimulationManager

用來產生用來控制裝置之封包的根目錄。

public interface IPerceptionSimulationManager
{   
    ISimulatedDevice Device { get; }
    ISimulatedHuman Human { get; }
    void Reset();
}

Microsoft.PerceptionSimulation.IPerceptionSimulationManager.Device

擷取模擬裝置物件,以解譯模擬人類和模擬世界。

Microsoft.PerceptionSimulation.IPerceptionSimulationManager.Human

擷取控制模擬人類的物件。

Microsoft.PerceptionSimulation.IPerceptionSimulationManager.Reset

將模擬重設為其默認狀態。

Microsoft.PerceptionSimulation.ISimulatedDevice

描述裝置的介面,可解譯模擬世界和模擬人類

public interface ISimulatedDevice
{
    ISimulatedHeadTracker HeadTracker { get; }
    ISimulatedHandTracker HandTracker { get; }
    void SetSimulatedDeviceType(SimulatedDeviceType type);
}

Microsoft.PerceptionSimulation.ISimulatedDevice.HeadTracker

從模擬裝置擷取前端追蹤器。

Microsoft.PerceptionSimulation.ISimulatedDevice.HandTracker

從模擬裝置擷取手部追蹤器。

Microsoft.PerceptionSimulation.ISimulatedDevice.SetSimulatedDeviceType (Microsoft.PerceptionSimulation.SimulatedDeviceType)

設定模擬裝置的屬性,以符合提供的裝置類型。

參數

  • type - 模擬裝置的新類型

Microsoft.PerceptionSimulation.ISimulatedDevice2

將 ISimulatedDevice 轉換成 ISimulatedDevice2 即可取得其他屬性

public interface ISimulatedDevice2
{
    bool IsUserPresent { [return: MarshalAs(UnmanagedType.Bool)] get; [param: MarshalAs(UnmanagedType.Bool)] set; }
    SimulatedDisplayConfiguration DisplayConfiguration { get; set; }

};

Microsoft.PerceptionSimulation.ISimulatedDevice2.IsUserPresent

擷取或設定模擬人類是否主動戴上頭戴式裝置。

Microsoft.PerceptionSimulation.ISimulatedDevice2.DisplayConfiguration

擷取或設定模擬顯示的屬性。

Microsoft.PerceptionSimulation.ISimulatedHeadTracker

介面,描述追蹤模擬人類頭部的模擬裝置部分。

public interface ISimulatedHeadTracker
{
    HeadTrackerMode HeadTrackerMode { get; set; }
};

Microsoft.PerceptionSimulation.ISimulatedHeadTracker.HeadTrackerMode

擷取並設定目前的前端追蹤器模式。

Microsoft.PerceptionSimulation.ISimulatedHandTracker

描述模擬裝置部分的介面,可追蹤模擬人類手部

public interface ISimulatedHandTracker
{
    Vector3 WorldPosition { get; }
    Vector3 Position { get; set; }
    float Pitch { get; set; }
    bool FrustumIgnored { [return: MarshalAs(UnmanagedType.Bool)] get; [param: MarshalAs(UnmanagedType.Bool)] set; }
    Frustum Frustum { get; set; }
}

Microsoft.PerceptionSimulation.ISimulatedHandTracker.WorldPosition

擷取與世界相關的節點位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedHandTracker.Position

擷取並設定模擬手部追蹤器相對於頭部中心的位置。

Microsoft.PerceptionSimulation.ISimulatedHandTracker.Pitch

擷取並設定模擬手部追蹤器的向下傾斜度。

Microsoft.PerceptionSimulation.ISimulatedHandTracker.FrustumIgnored

擷取並設定是否忽略模擬手部追蹤器的 Frustum。 忽略時,一律會顯示雙手。 未忽略時 (只有在手部追蹤器位於手部的 Frustum 內時,才會看到預設) 手部。

Microsoft.PerceptionSimulation.ISimulatedHandTracker.Frustum

擷取並設定用來判斷模擬手部追蹤器是否可以看到手部的 Frustum 屬性。

Microsoft.PerceptionSimulation.ISimulatedHuman

控制模擬人類的最上層介面。

public interface ISimulatedHuman 
{
    Vector3 WorldPosition { get; set; }
    float Direction { get; set; }
    float Height { get; set; }
    ISimulatedHand LeftHand { get; }
    ISimulatedHand RightHand { get; }
    ISimulatedHead Head { get; }s
    void Move(Vector3 translation);
    void Rotate(float radians);
}

Microsoft.PerceptionSimulation.ISimulatedHuman.WorldPosition

擷取並設定與世界相關的節點位置,以公尺為單位。 位置對應於人類腳部中央的點。

Microsoft.PerceptionSimulation.ISimulatedHuman.Direction

擷取並設定世界模擬人臉的方向。 0 弧度會朝負 Z 軸向下。 正弧度繞著Y軸順時針旋轉。

Microsoft.PerceptionSimulation.ISimulatedHuman.Height

擷取並設定模擬人類的高度,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedHuman.LeftHand

擷取模擬人類左側。

Microsoft.PerceptionSimulation.ISimulatedHuman.RightHand

擷取模擬人員的右手。

Microsoft.PerceptionSimulation.ISimulatedHuman.Head

擷取模擬人類頭部。

Microsoft.PerceptionSimulation.ISimulatedHuman.Move (Microsoft.PerceptionSimulation.Vector3)

以公尺為單位,將模擬人類相對於其目前位置移動。

參數

  • translation - 要移動的翻譯,相對於目前的位置。

Microsoft.PerceptionSimulation.ISimulatedHuman.Rotate (System.Single)

將模擬人類相對於其目前方向旋轉,順時針旋轉 Y 軸

參數

  • 弧度 - 繞 Y 軸旋轉的數量。

Microsoft.PerceptionSimulation.ISimulatedHuman2

將 ISimulatedHuman 轉換成 ISimulatedHuman2 即可取得其他屬性

public interface ISimulatedHuman2
{
    /* New members in addition to those available on ISimulatedHuman */
    ISimulatedSixDofController LeftController { get; }
    ISimulatedSixDofController RightController { get; }
}

Microsoft.PerceptionSimulation.ISimulatedHuman2.LeftController

擷取左 6-DOF 控制器。

Microsoft.PerceptionSimulation.ISimulatedHuman2.RightController

擷取正確的 6-DOF 控制器。

Microsoft.PerceptionSimulation.ISimulatedHand

描述模擬人類手部的介面

public interface ISimulatedHand
{
    Vector3 WorldPosition { get; }
    Vector3 Position { get; set; }
    bool Activated { [return: MarshalAs(UnmanagedType.Bool)] get; [param: MarshalAs(UnmanagedType.Bool)] set; }
    bool Visible { [return: MarshalAs(UnmanagedType.Bool)] get; }
    void EnsureVisible();
    void Move(Vector3 translation);
    void PerformGesture(SimulatedGesture gesture);
}

Microsoft.PerceptionSimulation.ISimulatedHand.WorldPosition

擷取與世界相關的節點位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedHand.Position

擷取並設定模擬手相對於人類的位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedHand.Activated

擷取並設定手部目前是否已啟用。

Microsoft.PerceptionSimulation.ISimulatedHand.Visible

擷取 SimulatedDevice (目前是否可以看到手部,也就是 HandTracker) 是否位於要偵測的位置。

Microsoft.PerceptionSimulation.ISimulatedHand.EnsureVisible

移動手部,讓 SimulatedDevice 看得見。

Microsoft.PerceptionSimulation.ISimulatedHand.Move (Microsoft.PerceptionSimulation.Vector3)

以公尺為單位,移動模擬手部相對於其目前位置的位置。

參數

  • translation - 要翻譯模擬手部的數量。

Microsoft.PerceptionSimulation.ISimulatedHand.PerformGesture (Microsoft.PerceptionSimulation.SimulatedGesture)

使用仿真的手部執行手勢。 只有在啟用手部時,系統才會偵測到它。

參數

  • 手勢 - 要執行的手勢。

Microsoft.PerceptionSimulation.ISimulatedHand2

將 ISimulatedHand 轉換成 ISimulatedHand2 即可取得其他屬性。

public interface ISimulatedHand2
{
    /* New members in addition to those available on ISimulatedHand */
    Rotation3 Orientation { get; set; }
}

Microsoft.PerceptionSimulation.ISimulatedHand2.Orientation

擷取或設定模擬手部的旋轉。 沿著軸查看時,正弧度會順時針旋轉。

Microsoft.PerceptionSimulation.ISimulatedHand3

將 ISimulatedHand 轉換成 ISimulatedHand3 即可取得其他屬性

public interface ISimulatedHand3
{
    /* New members in addition to those available on ISimulatedHand and ISimulatedHand2 */
    GetJointConfiguration(SimulatedHandJoint joint, out SimulatedHandJointConfiguration jointConfiguration);
    SetJointConfiguration(SimulatedHandJoint joint, SimulatedHandJointConfiguration jointConfiguration);
    SetHandPose(SimulatedHandPose pose, bool animate);
}

Microsoft.PerceptionSimulation.ISimulatedHand3.GetJointConfiguration

取得所指定聯合的聯合組態。

Microsoft.PerceptionSimulation.ISimulatedHand3.SetJointConfiguration

設定所指定聯合的聯合組態。

Microsoft.PerceptionSimulation.ISimulatedHand3.SetHandPose

將手設定為具有選擇性旗標的已知姿勢,以產生動畫效果。 注意:動畫不會立即反映其最終聯合組態。

Microsoft.PerceptionSimulation.ISimulatedHead

描述模擬人類前端的介面。

public interface ISimulatedHead
{
    Vector3 WorldPosition { get; }
    Rotation3 Rotation { get; set; }
    float Diameter { get; set; }
    void Rotate(Rotation3 rotation);
}

Microsoft.PerceptionSimulation.ISimulatedHead.WorldPosition

擷取與世界相關的節點位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedHead.Rotation

擷取模擬前端的旋轉。 沿著軸查看時,正弧度會順時針旋轉。

Microsoft.PerceptionSimulation.ISimulatedHead.Diameter

擷取模擬頭部直徑。 這個值是用來判斷頭部中心 (旋轉點) 。

Microsoft.PerceptionSimulation.ISimulatedHead.Rotate (Microsoft.PerceptionSimulation.Rotation3)

相對於其目前旋轉,旋轉仿真的前端。 沿著軸查看時,正弧度會順時針旋轉。

參數

  • rotation - 要旋轉的數量。

Microsoft.PerceptionSimulation.ISimulatedHead2

將 ISimulatedHead 轉換成 ISimulatedHead2 即可取得其他屬性

public interface ISimulatedHead2
{
    /* New members in addition to those available on ISimulatedHead */
    ISimulatedEyes Eyes { get; }
}

Microsoft.PerceptionSimulation.ISimulatedHead2.Eyes

擷取模擬人類眼睛。

Microsoft.PerceptionSimulation.ISimulatedSixDofController

介面,描述與模擬人類相關聯的 6-DOF 控制器。

public interface ISimulatedSixDofController
{
    Vector3 WorldPosition { get; }
    SimulatedSixDofControllerStatus Status { get; set; }
    Vector3 Position { get; }
    Rotation3 Orientation { get; set; }
    void Move(Vector3 translation);
    void PressButton(SimulatedSixDofControllerButton button);
    void ReleaseButton(SimulatedSixDofControllerButton button);
    void GetTouchpadPosition(out float x, out float y);
    void SetTouchpadPosition(float x, float y);
}

Microsoft.PerceptionSimulation.ISimulatedSixDofController.WorldPosition

擷取與世界相關的節點位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.Status

擷取或設定控制器的目前狀態。 控制器狀態必須設定為 [關閉] 以外的值,才能成功呼叫移動、旋轉或按下按鈕。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.Position

擷取或設定模擬控制器相對於人類的位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.Orientation

擷取或設定模擬控制器的方向。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.Move (Microsoft.PerceptionSimulation.Vector3)

以公尺為單位,移動模擬控制器相對於其目前位置的位置。

參數

  • translation - 要轉譯模擬控制器的數量。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.PressButton (SimulatedSixDofControllerButton)

在模擬控制器上按下按鈕。 只有在啟用控制器時,系統才會偵測到它。

參數

  • button - 要按下的按鈕。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.ReleaseButton (SimulatedSixDofControllerButton)

釋放模擬控制器上的按鈕。 只有在啟用控制器時,系統才會偵測到它。

參數

  • button - 要釋放的按鈕。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.GetTouchpadPosition (出 float、out float)

取得模擬控制器觸控板上模擬手指的位置。

參數

  • x - 手指的水準位置。
  • y - 手指的垂直位置。

Microsoft.PerceptionSimulation.ISimulatedSixDofController.SetTouchpadPosition (float、float)

在模擬控制器的觸控板上設定模擬手指的位置。

參數

  • x - 手指的水準位置。
  • y - 手指的垂直位置。

Microsoft.PerceptionSimulation.ISimulatedSixDofController2

將 ISimulatedSixDofController 轉換成 ISimulatedSixDofController2 即可取得其他屬性和方法

public interface ISimulatedSixDofController2
{
    /* New members in addition to those available on ISimulatedSixDofController */
    void GetThumbstickPosition(out float x, out float y);
    void SetThumbstickPosition(float x, float y);
    float BatteryLevel { get; set; }
}

Microsoft.PerceptionSimulation.ISimulatedSixDofController2.GetThumbstickPosition (out float, out float)

取得模擬控制器上模擬遊戲桿的位置。

參數

  • x - 遊戲桿的水準位置。
  • y - 遊戲桿的垂直位置。

Microsoft.PerceptionSimulation.ISimulatedSixDofController2.SetThumbstickPosition (float、float)

在模擬控制器上設定模擬指紋桿的位置。

參數

  • x - 遊戲桿的水準位置。
  • y - 遊戲桿的垂直位置。

Microsoft.PerceptionSimulation.ISimulatedSixDofController2.BatteryLevel

擷取或設定模擬控制器的電池電量。 此值必須大於 0.0,且小於或等於 100.0。

Microsoft.PerceptionSimulation.ISimulatedEyes

描述模擬人類眼睛的介面。

public interface ISimulatedEyes
{
    Rotation3 Rotation { get; set; }
    void Rotate(Rotation3 rotation);
    SimulatedEyesCalibrationState CalibrationState { get; set; }
    Vector3 WorldPosition { get; }
}

Microsoft.PerceptionSimulation.ISimulatedEyes.Rotation

擷取模擬眼睛的旋轉。 在沿著軸上查看時,正弧度會順時針旋轉。

Microsoft.PerceptionSimulation.ISimulatedEyes.Rotate (Microsoft.PerceptionSimulation.Rotation3)

將模擬眼睛相對於其目前旋轉旋轉旋轉。 在沿著軸上查看時,正弧度會順時針旋轉。

參數

  • rotation - 要旋轉的數量。

Microsoft.PerceptionSimulation.ISimulatedEyes.CalibrationState

擷取或設定模擬眼睛的校正狀態。

Microsoft.PerceptionSimulation.ISimulatedEyes.WorldPosition

擷取與世界相關的節點位置,以公尺為單位。

Microsoft.PerceptionSimulation.ISimulationRecording

用於與載入播放之單一錄製互動的介面。

public interface ISimulationRecording
{
    StreamDataTypes DataTypes { get; }
    PlaybackState State { get; }
    void Play();
    void Pause();
    void Seek(UInt64 ticks);
    void Stop();
};

Microsoft.PerceptionSimulation.ISimulationRecording.DataTypes

擷取錄製中的數據類型清單。

Microsoft.PerceptionSimulation.ISimulationRecording.State

擷取錄製的目前狀態。

Microsoft.PerceptionSimulation.ISimulationRecording.Play

啟動播放。 如果錄製已暫停,播放會從暫停的位置繼續;如果已停止,則播放會在開頭開始。 如果已經播放,則會忽略此呼叫。

Microsoft.PerceptionSimulation.ISimulationRecording.Pause

暫停其目前位置的播放。 如果錄製停止,則會忽略呼叫。

Microsoft.PerceptionSimulation.ISimulationRecording.Seek (System.UInt64)

以 100 奈秒間隔從開始) 搜尋錄製到指定的時間 (,並在該位置暫停。 如果時間超出錄製的結尾,則會在最後一個畫面格暫停。

參數

  • ticks - 要搜尋的時間。

Microsoft.PerceptionSimulation.ISimulationRecording.Stop

停止播放,並將位置重設為開頭。

Microsoft.PerceptionSimulation.ISimulationRecordingCallback

在播放期間接收狀態變更的介面。

public interface ISimulationRecordingCallback
{
    void PlaybackStateChanged(PlaybackState newState);
};

Microsoft.PerceptionSimulation.ISimulationRecordingCallback.PlaybackStateChanged (Microsoft.PerceptionSimulation.PlaybackState)

當 ISimulationRecording 的播放狀態變更時呼叫。

參數

  • newState - 錄製的新狀態。

Microsoft.PerceptionSimulation.PerceptionSimulationManager

建立 Perception Simulation 物件的根物件。

public static class PerceptionSimulationManager
{
    public static IPerceptionSimulationManager CreatePerceptionSimulationManager(ISimulationStreamSink sink);
    public static ISimulationStreamSink CreatePerceptionSimulationRecording(string path);
    public static ISimulationRecording LoadPerceptionSimulationRecording(string path, ISimulationStreamSinkFactory factory);
    public static ISimulationRecording LoadPerceptionSimulationRecording(string path, ISimulationStreamSinkFactory factory, ISimulationRecordingCallback callback);

Microsoft.PerceptionSimulation.PerceptionSimulationManager.CreatePerceptionSimulationManager (Microsoft.PerceptionSimulationStreamSink)

在物件上建立 ,以產生模擬封包,並將其傳遞至提供的接收。

參數

  • sink - 將接收所有產生的封包的接收。

傳回值

建立的管理員。

Microsoft.PerceptionSimulation.PerceptionSimulationManager.CreatePerceptionSimulationRecording (System.String)

建立接收,以將所有已接收的封包儲存在指定路徑的檔案中。

參數

  • path - 要建立的檔案路徑。

傳回值

已建立的接收。

Microsoft.PerceptionSimulation.PerceptionSimulationManager.LoadPerceptionSimulationRecording (System.String,Microsoft.PerceptionSimulation.ISimulationStreamSinkFactory)

從指定的檔案載入錄製。

參數

  • path - 要載入的檔案路徑。
  • factory - 當需要時,錄製用來建立 ISimulationStreamSink 的處理站。

傳回值

載入的錄製。

Microsoft.PerceptionSimulation.PerceptionSimulationManager.LoadPerceptionSimulationRecording (System.String,Microsoft.PerceptionSimulation.ISimulationStreamSinkFactory,Microsoft.PerceptionSimulation.ISimulationRecordingCallback)

從指定的檔案載入錄製。

參數

  • path - 要載入的檔案路徑。
  • factory - 當需要時,錄製用來建立 ISimulationStreamSink 的處理站。
  • callback - 回呼,接收更新重新降級錄製的狀態。

傳回值

載入的錄製。

Microsoft.PerceptionSimulation.StreamDataTypes

描述不同類型的數據流數據。

public enum StreamDataTypes
{
    None = 0x00,
    Head = 0x01,
    Hands = 0x02,
    SpatialMapping = 0x08,
    Calibration = 0x10,
    Environment = 0x20,
    SixDofControllers = 0x40,
    Eyes = 0x80,
    DisplayConfiguration = 0x100
    All = None | Head | Hands | SpatialMapping | Calibration | Environment | SixDofControllers | Eyes | DisplayConfiguration
}

Microsoft.PerceptionSimulation.StreamDataTypes.None

sentinel 值,用來表示沒有數據流數據類型。

Microsoft.PerceptionSimulation.StreamDataTypes.Head

前端位置和方向的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.Hands

手部位置和手勢的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.SpatialMapping

用於環境空間對應的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.Calibration

用於校正裝置的數據串流。 只有遠端模式中的系統才會接受校正封包。

Microsoft.PerceptionSimulation.StreamDataTypes.Environment

裝置環境的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.SixDofControllers

動作控制器的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.Eyes

具有模擬人類眼睛的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.DisplayConfiguration

具有裝置顯示組態的數據串流。

Microsoft.PerceptionSimulation.StreamDataTypes.All

sentinel 值,用來表示所有記錄的數據類型。

Microsoft.PerceptionSimulation.ISimulationStreamSink

從模擬數據流接收數據封包的物件。

public interface ISimulationStreamSink
{
    void OnPacketReceived(uint length, byte[] packet);
}

Microsoft.PerceptionSimulation.ISimulationStreamSink.OnPacketReceived (uint length, byte[] packet)

接收單一封包,這是內部型別和版本設定。

參數

  • length - 封包的長度。
  • packet - 封包的數據。

Microsoft.PerceptionSimulation.ISimulationStreamSinkFactory

建立 ISimulationStreamSink 的物件。

public interface ISimulationStreamSinkFactory
{
    ISimulationStreamSink CreateSimulationStreamSink();
}

Microsoft.PerceptionSimulation.ISimulationStreamSinkFactory.CreateSimulationStreamSink ()

建立 ISimulationStreamSink 的單一實例。

傳回值

已建立的接收。