-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
135 lines (115 loc) · 5.3 KB
/
Program.cs
File metadata and controls
135 lines (115 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using StereoKit;
using StereoKit.Framework;
using System;
namespace StereoKitFBSpatialEntity;
class Program
{
static void Main(string[] args)
{
// We must request these OpenXR extensions BEFORE we call SK.Initialize!
PassthroughFBExt passthroughStepper = SK.AddStepper(new PassthroughFBExt());
SpatialEntityFBExt spatialEntityStepper = SK.AddStepper(new SpatialEntityFBExt());
// Initialize StereoKit
SKSettings settings = new SKSettings
{
appName = "StereoKitFBSpatialEntity",
assetsFolder = "Assets",
};
if (!SK.Initialize(settings))
return;
// Some nice floor for when we are in VR
Matrix floorTransform = Matrix.TS(0, -1.5f, 0, new Vec3(30, 0.1f, 30));
Material floorMaterial = new Material("floor.hlsl");
floorMaterial.Transparency = Transparency.Blend;
// Some poses for our UI windows
//Pose window1Pose = new Pose(-0.5f, 0, -0.3f, Quat.LookDir(1, 0, 1));
Pose window2Pose = new Pose(0.2f, -0.1f, -0.5f, Quat.LookDir(-0.5f, 0, 1));
Pose window1Pose = new Pose(window2Pose.position + Vec3.Up * 0.2f, window2Pose.orientation);
Guid? selectedAnchorId = null;
// Core application loop
SK.Run(() => {
if (SK.System.displayType == Display.Opaque && !passthroughStepper.Enabled)
Mesh.Cube.Draw(floorMaterial, floorTransform);
// Passthrough menu
UI.WindowBegin("Passthrough Menu", ref window1Pose);
if (passthroughStepper.Available)
{
if (UI.Button("toggle"))
{
passthroughStepper.Enabled = !passthroughStepper.Enabled;
}
UI.Label($"Passthrough is {(passthroughStepper.Enabled ? "ON" : "OFF")}");
}
else
{
UI.Label("Passthrough is not available :(");
}
UI.WindowEnd();
// Spatial Anchor Menu
UI.WindowBegin("Spatial Anchor Menu", ref window2Pose, new Vec2(30,0) * U.cm);
if (spatialEntityStepper.Available)
{
UI.Label("FB Spatial Entity EXT available!");
if (UI.Button("Create Anchor"))
{
// We will create the anchor at the location just in front of the window (and we'll adopt the UI window's orientation).
Vec3 anchorPosition = window2Pose.position + window2Pose.Forward * .05f + Vec3.Up * 0.1f;
Pose pose = new Pose(anchorPosition, window2Pose.orientation);
// We can optionally provide some callbacks for when the async operation either completes successfully or fails.
spatialEntityStepper.CreateAnchor(
pose,
(Guid newAnchorUuid) => Log.Info($"Async anchor creation success. New anchor created: Uuid:{newAnchorUuid}"),
() => Log.Info("Async anchor creation success failed :("));
}
UI.SameLine();
if (UI.Button("Load All"))
spatialEntityStepper.LoadAllAnchors();
UI.SameLine();
if (UI.Button("Erase All"))
spatialEntityStepper.DeleteAllAnchors();
// List all Anchors
UI.HSeparator();
UI.Label($"Anchors Loaded ({spatialEntityStepper.AnchorCount})");
foreach (var anchor in spatialEntityStepper.Anchors)
{
// Use a PushId to avoid button Id collisions
UI.PushId(anchor.Uuid.ToString());
UI.PanelBegin();
if (UI.Button($"{anchor.Uuid.ToString().Substring(0,14)}..."))
{
// Unselect the anchor (if already selected) or select the anchor (if not already selected)
if (selectedAnchorId == anchor.Uuid)
selectedAnchorId = null;
else
selectedAnchorId = anchor.Uuid;
}
UI.SameLine();
// Button to delete the selected anchor
if (UI.Button("Delete"))
{
spatialEntityStepper.DeleteAnchor(anchor.Uuid);
}
if (selectedAnchorId == anchor.Uuid)
{
UI.Label("XrSpace: " + anchor.XrSpace);
UI.Label("Located: " + anchor.LocateSuccess);
UI.Label(anchor.Pose.ToString());
}
UI.PanelEnd();
UI.PopId();
}
}
else
{
UI.Label("Spatial Anchor is not available :(");
}
UI.WindowEnd();
// Visualize all loaded spatial anchor
foreach (var anchor in spatialEntityStepper.Anchors)
{
// Just draw a nice orange cube for the anchor pose
Mesh.Cube.Draw(Material.Default, anchor.Pose.ToMatrix(0.1f), new Color(1, 0.5f, 0));
}
});
}
}