-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.cs
187 lines (164 loc) · 6.56 KB
/
App.cs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.IO;
using System.Net;
using StereoKit;
using System.Numerics;
using JetBrains.Annotations;
using StereoKitApp.Features.Avatar;
using StereoKitApp.HLRuffles;
using StereoKitApp.UIs;
using StereoKitApp.Utils;
using StereoKitApp.Painting;
namespace StereoKitApp
{
public class App
{
private RufflesTransport _rufflesTransport = new RufflesTransport();
public static DirectoryInfo WorkDirectory = new DirectoryInfo(
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Cubes")
);
[PublicAPI("Used by the Platform runners")]
public static SKSettings Settings =>
new SKSettings
{
appName = "StereoKit Template",
assetsFolder = "Assets",
displayPreference = DisplayMode.MixedReality,
};
private readonly RefWrapper<Pose> _cubePose = new RefWrapper<Pose>(
new Pose(0, 0, -0.4f, Quat.Identity)
);
// private static readonly Vec3 UIStartPosition = new Vec3(0.5f, 0, -0.4f);
// private Pose _uiPose = new Pose(UIStartPosition, Quat.LookAt(UIStartPosition, Vec3.Zero));
private Model _cube = null!;
private PaintingManager _paintingManager = null!;
private readonly Matrix4x4 _floorTransform = Matrix.TS(
new Vector3(0, -1.5f, 0),
new Vector3(30, 0.1f, 30)
);
private Material? _floorMaterial;
private ConnectionMenu _connectionMenu = null!;
[UsedImplicitly]
private AvatarSpawner _avatarSpawner = null!;
[PublicAPI("Used by the Platform runners")]
public void Init()
{
if (!WorkDirectory.Exists)
WorkDirectory = Directory.CreateDirectory(WorkDirectory.FullName);
UI.ColorScheme = Color.HSV(0.5f, 0.8f, 0.8f);
SK.AddStepper(_rufflesTransport);
// Create assets used by the app
_cube = Model.FromMesh(
Mesh.GenerateRoundedCube(Vec3.One * 0.1f, 0.02f),
Default.MaterialUI
);
_paintingManager = new PaintingManager(WorkDirectory);
Vec3 connectionMenuStartPosition = new Vec3(-0.5f, 0, -0.4f);
Pose connectionMenuPose = new Pose(
connectionMenuStartPosition,
Quat.LookAt(connectionMenuStartPosition, Vec3.Zero)
);
_connectionMenu = new ConnectionMenu(ref connectionMenuPose);
_floorMaterial = new Material(Shader.FromFile("floor.hlsl"))
{
Transparency = Transparency.Blend
};
_avatarSpawner = new AvatarSpawner();
_paintingManager.InstantiatePainting("PaintTest");
if (MultiplayerDevUtils.GetClientBuildType() == ClientBuild.Debug)
{
//Console.WriteLine("Creating Session");
_rufflesTransport.CreateSession(6776);
}
else if (MultiplayerDevUtils.GetClientBuildType() == ClientBuild.Debug2)
{
Console.WriteLine("Connecting to localhost session");
_rufflesTransport.JoinSession(new IPEndPoint(IPAddress.Loopback, 6776));
}
else if (MultiplayerDevUtils.GetClientBuildType() == ClientBuild.Debug3)
{
Console.WriteLine("Connecting to localhost session");
// _rufflesTransport.JoinSession(
// new IPEndPoint(IPAddress.Parse("192.168.1.232"), 6776)
// );
_rufflesTransport.JoinSession(new IPEndPoint(IPAddress.Loopback, 6776));
}
Renderer.SkyTex = Tex.FromCubemapEquirectangular(
"Env/Skybox1.hdr",
out SphericalHarmonics _ // We use the default lighting. As the colors are more like exported.
);
}
//
// private static class MainMenuState
// {
// public static bool ToggleOpen;
// public static string InputValue = "";
// }
[PublicAPI("Used by the Platform runners")]
// ReSharper disable once CognitiveComplexity -- The main update loop
public void Step()
{
UI.EnableFarInteract = false;
if (SK.System.displayType == Display.Opaque)
{
Default.MeshCube.Draw(_floorMaterial, _floorTransform);
}
_paintingManager.Update();
// if (UI.Handle("Cube", ref _cubePose.GetValueRef(), _cube.Bounds, true)) { }
// ControllerUtils.ShowController(Handed.Left);
// ControllerUtils.ShowController(Handed.Right);
if (!_rufflesTransport.IsRunning)
_connectionMenu.Update();
// using (
// UIUtils.UIWindowScope(
// "Header",
// ref _uiPose,
// new Vec2(0.3f, 0.3f),
// UIWin.Normal,
// UIMove.FaceUser
// )
// )
// {
// if (_rufflesTransport.IsHost)
// {
// UI.Text("You are hosting.");
// }
// else if (
// _rufflesTransport.IsRunning
// && _rufflesTransport.ConnectionState == ConnectionState.Connected
// )
// {
// UI.Text("You are connected I think?");
// }
// else if (
// _rufflesTransport.IsRunning
// && _rufflesTransport.ConnectionState != ConnectionState.Connected
// )
// {
// UI.Text("Trying to connect to session.");
// }
//
// UI.Text(MultiplayerDevUtils.GetClientBuildType() + " Client");
//
// if (UI.Button("Expand!"))
// {
// MainMenuState.ToggleOpen = !MainMenuState.ToggleOpen;
// }
//
// if (MainMenuState.ToggleOpen)
// {
// UI.Text("This is my new cool UI stuff!");
//
// UI.Text("My cool message.");
//
// if (UI.Input("MyInput", ref MainMenuState.InputValue))
// {
// UI.Text("Cool");
// }
// }
// }
// Save some battery while coding.
//Thread.Sleep(1000 / 20);
}
}
}