MRが楽しい

MRやVRについて学習したことを書き残す

MRTK v2のドキュメントを少しずつ読み解く コンテンツシーンの読み込み

本日は MRTKv2 の調査枠です。
MRTKv2 の Guides ドキュメントを少しずつ読み進めていきます。

MRTKv2のGuidesドキュメント

以下のドキュメントを読み進めていきます。
microsoft.github.io

以下のページでは有志による本ドキュメントの日本語翻訳が行われています。
投稿時点でこちらで未翻訳、または著者が興味のある部分について記事にしていきます。
hololabinc.github.io

本記事では以下のページを読み進めます。
microsoft.github.io
f:id:bluebirdofoz:20200319092600j:plain

コンテンツシーンの読み込み

デフォルトでは全てのコンテンツの読み込み操作は非同期であり、加算的です。
マネージャーおよび照明シーンは、コンテンツの読み込み操作の影響を受けません

ロードの進行状況とシーンのアクティブ化の監視については、コンテンツのロードの監視を参照してください。
microsoft.github.io

コンテンツの読み込み

コンテンツシーンを読み込むには LoadContent メソッドを使用します。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

// Additively load a single content scene
// 単一のコンテンツシーンを追加的にロードする
await sceneSystem.LoadContent("MyContentScene");

// Additively load a set of content scenes
// コンテンツシーンのセットを追加的にロードする
await sceneSystem.LoadContent(new string[] { "MyContentScene1", "MyContentScene2", "MyContentScene3" });

f:id:bluebirdofoz:20200319092622j:plain

シングルシーンの読み込み

単一のシーンのロードに相当するものは、オプションの[mode]引数を使用して実現できます。
LoadSceneMode.Single は、ロードを続行する前に、ロードされた全てのコンテンツシーンをアンロードします。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

// ContentScene1, ContentScene2 and ContentScene3 will be loaded additively
// ContentScene1、ContentScene2、ContentScene3 は追加的にロードされます
await sceneSystem.LoadContent("ContentScene1");
await sceneSystem.LoadContent("ContentScene2");
await sceneSystem.LoadContent("ContentScene3");

// ContentScene1, ContentScene2 and ContentScene3 will be unloaded
// SingleContentScene will be loaded additively
// ContentScene1、ContentScene2、ContentScene3 がアンロードされます
// その後、SingleContentScene が追加的にロードされます
await sceneSystem.LoadContent("SingleContentScene", LoadSceneMode.Single);

f:id:bluebirdofoz:20200319092632j:plain

次/前のシーンの読み込み

コンテンツはインデックスの作成順に単独でロードできます。
これは一連のデモンストレーションシーンを1つずつユーザーに案内するショーケースアプリケーションに役立ちます。
f:id:bluebirdofoz:20200319092640j:plain

以下の次/前のコンテンツのロードでは LoadSceneMode.Single を使用して、前のコンテンツがアンロードされるようにしています。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

if (nextSceneRequested && sceneSystem.NextContentExists)
{
    await sceneSystem.LoadNextContent();
}

if (prevSceneRequested && sceneSystem.PrevContentExists)
{
    await sceneSystem.LoadPrevContent();
}

f:id:bluebirdofoz:20200319092652j:plainf:id:bluebirdofoz:20200319092652j:plain

現在ロードされている最低のビルドインデックスよりも低いビルドインデックスを持つコンテンツシーンが少なくとも1つある場合、PrevContentExists は true を返します。
現在ロードされている最高のビルドインデックスよりも高いビルドインデックスを持つコンテンツシーンが少なくとも1つある場合、NextContentExists は true を返します。

wrap 引数が true の場合、コンテンツは最初/最後のビルドインデックスにループバックします。
これにより、次/前のコンテンツを確認する必要がなくなります。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

if (nextSceneRequested)
{
    await sceneSystem.LoadNextContent(true);
}

if (prevSceneRequested)
{
    await sceneSystem.LoadPrevContent(true);
}

f:id:bluebirdofoz:20200319092706j:plain

タグによる読み込み

f:id:bluebirdofoz:20200319092715j:plain
コンテンツシーンをグループで読み込むことが望ましい場合があります。
例えば、エクスペリエンスのステージは複数のシーンで構成されている場合です。
この場合、全てを同時にロードして機能させる必要があります。
これを容易にするために、シーンにタグを付け、そのタグでロードまたはアンロードすることができます。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

await sceneSystem.LoadContentByTag("Stage1");

// Wait until stage 1 is complete
// ステージ1が完了するまで待ちます

await sceneSystem.UnloadContentByTag("Stage1");
await sceneSystem.LoadContentByTag("Stage2");

f:id:bluebirdofoz:20200319092724j:plain

タグによるロードは、スクリプトを変更せずにエクスペリエンスに要素を組み込み/削除したい場合にも役立ちます。
例えば、次の2つのタグセットを使用してこのスクリプトを実行すると、異なる結果が生成されます。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

await sceneSystem.LoadContentByTag("Terrain");
await sceneSystem.LoadContentByTag("Structures");
await sceneSystem.LoadContentByTag("Vegetation");

f:id:bluebirdofoz:20200319092733j:plain

タグセット例:1

シーン名タグ名読み込み結果
DebugTerrainPhysicsTerrain
StructureTestingStructures
VegetationToolsVegetation
MountainTerrain
CabinStructures
TreesVegetation

タグセット例:2

シーン名タグ名読み込み結果
DebugTerrainPhysicsDoNotInclude
StructureTestingDoNotInclude
VegetationToolsDoNotInclude
MountainTerrain
CabinStructures
TreesVegetation

エディターの動作

Scene System のサービスインスペクターを使用して、これら全ての操作をエディターおよび再生モードで実行できます。
エディターモードではシーンのロードは瞬時に行われますが、再生モードではロードの進行状況を確認してアクティベーショントークンを使用できます。
f:id:bluebirdofoz:20200319092745j:plain