-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.cs
133 lines (111 loc) · 3.72 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
using System;
using System.Collections.Generic;
using StereoKit;
using System.Numerics;
using RDR;
namespace StereoKitApp
{
public class App
{
public SKSettings Settings => new SKSettings {
appName = "StereoKit Template",
assetsFolder = "Assets",
displayPreference = DisplayMode.MixedReality
};
Pose objPose;
SmartSphere obj;
Matrix4x4 floorTransform = Matrix.TS(new Vector3(0, -1.5f, 0), new Vector3(20, 0.1f, 20));
Material floorMaterial;
private Pose windowAdminPose;
private Sprite powerSprite;
private Material targetMaterial, seenMaterial, selectedMaterial, earthMaterial;
private GraphSchema graphSchema;
private void initSharedResources()
{
this.powerSprite = Sprite.FromFile("power.png", SpriteType.Single);
earthMaterial = Default.MaterialPBR.Copy();
earthMaterial[MatParamName.DiffuseTex] = Tex.FromFile("earth-1.png");
targetMaterial = Default.Material.Copy(); //matAlphaBlend
//targetMaterial.Transparency = Transparency.Blend;
targetMaterial.Transparency = Transparency.None;
targetMaterial.DepthWrite = true;
targetMaterial[MatParamName.ColorTint] = new Color(.3f, 1, 0.3f, 1f);
targetMaterial.Wireframe = true;
seenMaterial = Default.Material.Copy(); //matAlphaBlend
// seenMaterial.Transparency = Transparency.Blend;
seenMaterial.Transparency = Transparency.None;
seenMaterial.DepthWrite = true;
seenMaterial[MatParamName.ColorTint] = new Color(.6f, .1f, 0.6f, 1f);
selectedMaterial = seenMaterial.Copy();
}
private void initUI()
{
//
// set UI scheme
// Renderer.SkyTex = Tex.FromCubemapEquirectangular("night.hdr", out SphericalHarmonics lighting);
// Renderer.SkyLight = lighting;
Color uiColor = Color.HSV(.83f, 0.33f, 1f, 0.8f);
UI.ColorScheme = uiColor;
windowAdminPose = new Pose(-.2f, 0, -0.65f, Quat.LookAt(new Vec3(-.2f, 0, -0.65f), Input.Head.position, Vec3.Up));
}
private Boolean displayAdminPanel()
{
Boolean running = true;
UI.WindowBegin("Admin", ref this.windowAdminPose, new Vec2(25, 0) * U.cm, UIWin.Normal);
UI.Text("Admin Panel ");
UI.NextLine();
if (UI.ButtonRound("Exit", this.powerSprite)) running = false;
UI.SameLine(); UI.Label("Exit Game");
UI.WindowEnd();
return running;
}
public async void Init()
{
this.initSharedResources();
this.initUI();
Log.Subscribe(OnLog);
// Create assets used by the app
// Mesh.GenerateRoundedCube(Vec3.One * 0.1f, 0.02f),
SmartSphere.Init();
var pose = new Pose(0, 0, -1.0f, Quat.Identity);
obj = new SmartSphere(pose, earthMaterial);
floorMaterial = new Material(Shader.FromFile("floor.hlsl"));
floorMaterial.Transparency = Transparency.Blend;
graphSchema = await Graphquery.GetSchema();
foreach(TypeElement t in graphSchema.types)
{
Log.Warn(t.name);
}
}
public void Step()
{
if (SK.System.displayType == Display.Opaque)
Default.MeshCube.Draw(floorMaterial, floorTransform);
Boolean running = this.displayAdminPanel();
LogWindow();
obj.Draw();
if (running == false )
{
SK.Quit();
}
}
static Pose logPose = new Pose(0.8f, -0.1f, -0.5f, Quat.LookAt(new Vec3(0.8f, -0.1f, -0.5f), Input.Head.position, Vec3.Up));
static List<string> logList = new List<string>();
static string logText = "";
static void OnLog(LogLevel level, string text)
{
if (logList.Count > 15)
logList.RemoveAt(logList.Count - 1);
logList.Insert(0, text.Length < 100 ? text : text.Substring(0, 100) + "...\n");
logText = "";
for (int i = 0; i < logList.Count; i++)
logText += logList[i];
}
static void LogWindow()
{
UI.WindowBegin("Log", ref logPose, new Vec2(40, 0) * U.cm);
UI.Text(logText);
UI.WindowEnd();
}
}
}