diff --git a/src/Design.cs b/src/Design.cs new file mode 100644 index 0000000..4a80d81 --- /dev/null +++ b/src/Design.cs @@ -0,0 +1,111 @@ +namespace Oriels; + +public class Design { + public string str; + public string term; + public float min = float.NegativeInfinity; + public float max = float.PositiveInfinity; + public float unit = U.m; + + public float value { + get { + try { + float value = PR.Clamp(float.Parse(str), min, max); + // if clamped, update string + if (value != float.Parse(str)) { + if (Input.Key(Key.Return).IsJustActive()) { + str = value.ToString(); + } + } + return value * unit; + } catch { + return MathF.Max(0, min) * unit; + } + } + } + // public int integer {}; +} + +// Chiral : handedness implies symmetry +public class Chiral : Interaction { + public Chiral(Interaction[] dofs) => this.dofs = dofs; + private bool active; + public bool Active { + get { return this.active; } + set { + this.active = value; + for (int i = 0; i < this.dofs.Length; i++) { + Interaction dof = this.dofs[i]; + if ((int)this.handed == 2 || i == (int)this.handed) { + dof.Active = value; + } else { + dof.Active = false; + } + } + } + } + public Interaction[] dofs = new Interaction[2]; + // public Design handed = new Design { str = "2", min = 0, max = 2}; + public Handed handed = Handed.Max; + + public void Init() { + dofs[0].Init(); + dofs[1].Init(); + } + + public void Frame() { + // sync the left design variables to the right + System.Reflection.FieldInfo[] fields = dofs[0].GetType().GetFields(); + foreach (System.Reflection.FieldInfo field in fields) { + if (field.FieldType == typeof(Design)) { + Design design = (Design)field.GetValue(dofs[0]); // define type? + field.SetValue(dofs[1], design); + } + } + + for (int i = 0; i < dofs.Length; i++) { + Interaction dof = dofs[i]; + if ((int)handed == 2 || i == (int)handed) { + dof.Frame(); + dof.Active = true; + } + else { + dof.Active = false; + } + } + } +} + +/* + ranges + 0+1 + 1-0 + 1-0+1 + + -0+ + + 0+&&- + 0+||- + + units + m + cm + mm + t + + demo + seperate the demos from the dofs, and make them rebindable (assigning input using reflection?) + virtual shapes(scalable) -> that can be slotted + physics boxes + + mirror + mirroring vectors(line segments) is really easy + easier than rendering.. actually just render twice with the material chain + stereonick mentioned + + debug bool + rendering the raw output + particularly for hand tracking dofs (so Moses can better test them!) + raw = 0.333f alpha ~ + +*/ \ No newline at end of file diff --git a/src/Elements/oriel/Oriel.cs b/src/Elements/oriel/Oriel.cs index e67882d..8f045ba 100644 --- a/src/Elements/oriel/Oriel.cs +++ b/src/Elements/oriel/Oriel.cs @@ -224,6 +224,8 @@ public class Oriel { public float crown = 0.16f; public void Render() { + Mono mono = Mono.inst; + // // matFrame.Wireframe = true; // matFrame.DepthTest = DepthTest.Always; // matFrame.SetVector("_cursor", cursor); @@ -304,12 +306,12 @@ public class Oriel { } } - Mesh.Sphere.Draw(Mono.inst.matHoloframe, + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.02f, 0.02f)), cursorColor ); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TS(cursor, new Vec3(1f, 1f, 1f) * cursorRadius * 2), new Color(0.1f, 0.1f, 0.1f) ); diff --git a/src/Interactions/rolls-cursor/RollsCursor.cs b/src/Interactions/rolls-cursor/RollsCursor.cs index 886fd0d..51631a1 100644 --- a/src/Interactions/rolls-cursor/RollsCursor.cs +++ b/src/Interactions/rolls-cursor/RollsCursor.cs @@ -15,13 +15,14 @@ class RollsCursor : Interaction { public void Init() { } public void Frame() { - Rig rig = Mono.inst.rig; + Mono mono = Mono.inst; + Hand hand = Input.Hand(handed); if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { - float fI = rig.Flexion(hand, FingerId.Index); - float fM = rig.Flexion(hand, FingerId.Middle); - float fR = rig.Flexion(hand, FingerId.Ring); - float fL = rig.Flexion(hand, FingerId.Little); + float fI = mono.rig.Flexion(hand, FingerId.Index); + float fM = mono.rig.Flexion(hand, FingerId.Middle); + float fR = mono.rig.Flexion(hand, FingerId.Ring); + float fL = mono.rig.Flexion(hand, FingerId.Little); float stretch = (fI + fM + fR + fL) / 4f; @@ -43,9 +44,9 @@ class RollsCursor : Interaction { Vec3 delta = (fIdelta.value + fMdelta.value + fRdelta.value) / 3f; cursor.raw += delta * reach.value; - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0)); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0)); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); } } diff --git a/src/Interactions/trackballer/Trackballer.cs b/src/Interactions/trackballer/Trackballer.cs index 18e0847..5458f4b 100644 --- a/src/Interactions/trackballer/Trackballer.cs +++ b/src/Interactions/trackballer/Trackballer.cs @@ -40,6 +40,8 @@ class Trackballer : Interaction { } public void UpdateMomentum(Hand hand) { + Mono mono = Mono.inst; + // Thumb pad HandJoint thumbJoint = hand.Get(FingerId.Thumb, JointId.Tip); oldPad = pad; @@ -48,7 +50,7 @@ class Trackballer : Interaction { thumbJoint.orientation, new Vec3(handed == Handed.Left ? -1f : 1f, 1f, 1f) * 0.1666f ); - mesh.Draw(Mono.inst.matHoloframe, pad, new Color(0, 1, 1)); + mesh.Draw(mono.mat.holoframe, pad, new Color(0, 1, 1)); // Ball anchor HandJoint ballJoint = hand.Get(FingerId.Index, JointId.KnuckleMajor); @@ -97,7 +99,7 @@ class Trackballer : Interaction { btnPull.Frame(pull > 1f, pull > 0.333f); // magic sticky var float pullScalar = btnPull.held ? MathF.Max((pull - 0.333f) / 0.666f, 0) : MathF.Max(1 - pull, 0); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(anchorPos, thumbJoint.orientation, pullScalar * radius.value), new Color(0, 1, 1) * (btnPull.held ? 1f : 0.0666f) ); @@ -105,7 +107,7 @@ class Trackballer : Interaction { anchor.Transform(point), anchorPos, new Color(0, 1, 1), 1f * U.mm ); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(anchor.Transform(point), thumbJoint.orientation, 2f * U.mm), new Color(0, 1, 1) ); @@ -116,7 +118,7 @@ class Trackballer : Interaction { btnPush.Frame(push > 1f, push > 0.333f); // magic sticky var float pushScalar = btnPush.held ? MathF.Max((MathF.Min(push, 1f) - 0.333f) / 0.666f, 0) : MathF.Max(1 - push, 0); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(anchorPos, ori, (radius.value * 2) * pushScalar), new Color(1, 0, 0) * (btnPush.held ? 1f : 0.2f) ); @@ -148,7 +150,7 @@ class Trackballer : Interaction { // Draw ball result Mesh.Sphere.Draw( - Mono.inst.matHoloframe, + mono.mat.holoframe, Matrix.TRS(anchorPos, ori, radius.value * 2), new Color(0.8f, 0, 0) ); @@ -178,7 +180,7 @@ class Trackballer : Interaction { float width = 52 * U.cm; float height = 29f * U.cm; Mesh.Quad.Draw( - Mono.inst.matHoloframe, + Mono.inst.mat.holoframe, Matrix.S(new Vec3(width, height, 1)) * panel, new Color(1, 1, 1) ); diff --git a/src/Interactions/wave-cursor/WaveCursor.cs b/src/Interactions/wave-cursor/WaveCursor.cs index faa9219..41d75ca 100644 --- a/src/Interactions/wave-cursor/WaveCursor.cs +++ b/src/Interactions/wave-cursor/WaveCursor.cs @@ -12,13 +12,14 @@ class WaveCursor : Interaction { public void Init() {} public void Frame() { - Rig rig = Mono.inst.rig; + Mono mono = Mono.inst; + Hand hand = Input.Hand(handed); if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { - float fI = rig.Flexion(hand, FingerId.Index); - float fM = rig.Flexion(hand, FingerId.Middle); - float fR = rig.Flexion(hand, FingerId.Ring); - float fL = rig.Flexion(hand, FingerId.Little); + float fI = mono.rig.Flexion(hand, FingerId.Index); + float fM = mono.rig.Flexion(hand, FingerId.Middle); + float fR = mono.rig.Flexion(hand, FingerId.Ring); + float fL = mono.rig.Flexion(hand, FingerId.Little); // Biased by finger length float wave = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; @@ -30,9 +31,9 @@ class WaveCursor : Interaction { cursor.raw = to + dir * wave * crest.value; - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0)); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0)); - Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0)); + Mesh.Sphere.Draw(mono.mat.holoframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); } } @@ -76,7 +77,7 @@ class WaveCursor : Interaction { Vec3 from = i > 0 ? points[i - 1] : nextPos; Quat ori = Quat.LookDir(Vec3.Direction(points[i], from)); Mesh.Cube.Draw( - Mono.inst.matHoloframe, + Mono.inst.mat.holoframe, Matrix.TRS( points[i] + ori * new Vec3(0, 0, 0.01f) * scale, ori, diff --git a/src/Mat.cs b/src/Mat.cs new file mode 100644 index 0000000..5cadec6 --- /dev/null +++ b/src/Mat.cs @@ -0,0 +1,43 @@ +namespace Oriels; + +public class Mat { + public Material dev; + public Material holoframe = new Material(Shader.FromFile("shaders/above.hlsl")); + Material holoframeUnder = new Material(Shader.FromFile("shaders/below.hlsl")); + public Material holoclear = new Material(Shader.FromFile("shaders/above.hlsl")); + Material holoclearUnder = new Material(Shader.FromFile("shaders/below.hlsl")); + public Material holo = new Material(Shader.FromFile("shaders/above.hlsl")); + Material holoUnder = new Material(Shader.FromFile("shaders/below.hlsl")); + + public void Init() { + dev = Material.Default.Copy(); + dev.SetTexture("diffuse", Tex.DevTex); + + holo.SetColor("clearcolor", Renderer.ClearColor); + holoUnder.SetColor("clearcolor", Renderer.ClearColor); + holoUnder.FaceCull = Cull.None; + holo.Chain = holoUnder; + + holoclear.SetColor("clearcolor", Color.Black); + holoclear.Transparency = Transparency.Add; + holoclear.DepthWrite = false; + holoclear.FaceCull = Cull.None; + holoclearUnder.SetColor("clearcolor", Color.Black); + holoclearUnder.Transparency = Transparency.Add; + holoclearUnder.DepthWrite = false; + holoclearUnder.FaceCull = Cull.None; + holoclear.Chain = holoclearUnder; + + holoframe.SetColor("clearcolor", Color.Black); + holoframe.Transparency = Transparency.Add; + holoframe.DepthWrite = false; + holoframe.FaceCull = Cull.None; + holoframe.Wireframe = true; + holoframeUnder.SetColor("clearcolor", Color.Black); + holoframeUnder.Transparency = Transparency.Add; + holoframeUnder.DepthWrite = false; + holoframeUnder.FaceCull = Cull.None; + holoframeUnder.Wireframe = true; + holoframe.Chain = holoframeUnder; + } +} \ No newline at end of file diff --git a/src/Mono.cs b/src/Mono.cs index 3287d93..3af91b6 100644 --- a/src/Mono.cs +++ b/src/Mono.cs @@ -6,13 +6,7 @@ public class Mono { public PR.Noise noise = new PR.Noise(939949595); - public Material matDev; - public Material matHoloframe = new Material(Shader.FromFile("shaders/above.hlsl")); - Material matHoloframeUnder = new Material(Shader.FromFile("shaders/below.hlsl")); - public Material matHoloclear = new Material(Shader.FromFile("shaders/above.hlsl")); - Material matHoloclearUnder = new Material(Shader.FromFile("shaders/below.hlsl")); - public Material matHolo = new Material(Shader.FromFile("shaders/above.hlsl")); - Material matHoloUnder = new Material(Shader.FromFile("shaders/below.hlsl")); + public Mat mat = new Mat(); public Rig rig = new Rig(); public Space space = new Space(); @@ -55,35 +49,7 @@ public class Mono { interactions[i].Init(); } - matDev = Material.Default.Copy(); - matDev.SetTexture("diffuse", Tex.DevTex); - - matHolo.SetColor("clearcolor", Renderer.ClearColor); - matHoloUnder.SetColor("clearcolor", Renderer.ClearColor); - matHoloUnder.FaceCull = Cull.None; - matHolo.Chain = matHoloUnder; - - matHoloclear.SetColor("clearcolor", Color.Black); - matHoloclear.Transparency = Transparency.Add; - matHoloclear.DepthWrite = false; - matHoloclear.FaceCull = Cull.None; - matHoloclearUnder.SetColor("clearcolor", Color.Black); - matHoloclearUnder.Transparency = Transparency.Add; - matHoloclearUnder.DepthWrite = false; - matHoloclearUnder.FaceCull = Cull.None; - matHoloclear.Chain = matHoloclearUnder; - - matHoloframe.SetColor("clearcolor", Color.Black); - matHoloframe.Transparency = Transparency.Add; - matHoloframe.DepthWrite = false; - matHoloframe.FaceCull = Cull.None; - matHoloframe.Wireframe = true; - matHoloframeUnder.SetColor("clearcolor", Color.Black); - matHoloframeUnder.Transparency = Transparency.Add; - matHoloframeUnder.DepthWrite = false; - matHoloframeUnder.FaceCull = Cull.None; - matHoloframeUnder.Wireframe = true; - matHoloframe.Chain = matHoloframeUnder; + mat.Init(); } Pose shape = new Pose(new Vec3(0, 1f, -3f), Quat.FromAngles(45, 0, 45)); @@ -109,13 +75,6 @@ public class Mono { // Console.WriteLine($"{h.pinchPt}, {Input.Head.orientation * -Vec3.Forward}"); // } - // Hand hand = Input.Hand(Handed.Right); - // Controller con = Input.Controller(Handed.Right); - // Mesh.Cube.Draw( - // Material.Default, - // hand.IsJustPinched - // ) - // Con -> Hand // lGlove.Step(); // rGlove.Step(); @@ -124,31 +83,34 @@ public class Mono { spatial.Frame(); + // we need cursor abstraction + // so we can plug in different cursor interactions into different elements! + // pinch-cursor? - // { - // float deadzone = 0.01f; - // float strength = 6f; + { + float deadzone = 0.01f; + float strength = 6f; - // Hand hand = Input.Hand(Handed.Right); - // Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position; - // Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; + Hand hand = Input.Hand(Handed.Right); + Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position; + Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; - // Vec3 delta = indexTip - thumbTip; - // float mag = delta.Magnitude; - // float pinch = MathF.Max(mag - deadzone, 0); + Vec3 delta = indexTip - thumbTip; + float mag = delta.Magnitude; + float pinch = MathF.Max(mag - deadzone, 0); - // Vec3 dir = delta.Normalized; + Vec3 dir = delta.Normalized; - // cursor.raw = indexTip + dir * pinch * strength; + cursor.raw = indexTip + dir * pinch * strength; - // Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f); - // Mesh.Sphere.Draw(matHolo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f)); - // // V.XYZ(0, 0, ); + Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f); + Mesh.Sphere.Draw(mat.holo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f)); + // V.XYZ(0, 0, ); - // drawerA.Frame(cursor, pinch); - // drawerB.Frame(cursor, pinch); - // drawerC.Frame(cursor, pinch); - // } + drawerA.Frame(cursor, pinch); + drawerB.Frame(cursor, pinch); + drawerC.Frame(cursor, pinch); + } @@ -192,7 +154,7 @@ public class Mono { // as it's a bit of space hog Mesh.Cube.Draw( - Mono.inst.matHoloframe, + mat.holoframe, shape.ToMatrix(0.5f), new Color(0.5f, 0.55f, 0.75f) * 0.3f ); @@ -212,243 +174,11 @@ public class Mono { // net.me.Step(); // net.send = true; - ShowWindowButton(); - } - - int dofIndex = 0; - Pose windowPose = new Pose(-0.333f, 1.2f, -0.5f, Quat.FromAngles(0, 180, 0)); - Material windowMat = new Material(Shader.FromFile("shaders/window.hlsl")); - TextStyle style = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, Color.Black); - TextStyle style2 = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, new Color(0.5f, 0.5f, 0.5f)); - Vec2 fieldSize = new Vec2(6f * U.cm, 3f * U.cm); - void ShowWindowButton() { - windowMat.Transparency = Transparency.Add; - windowMat.FaceCull = Cull.None; - windowMat.DepthWrite = false; - UI.SetElementVisual(UIVisual.WindowBody, Mesh.Quad, windowMat, Vec2.One); - UI.SetElementVisual(UIVisual.WindowHead, Mesh.Quad, windowMat, Vec2.One); - UI.WindowBegin("design vars", ref windowPose); - // UI.SetThemeColor(UIColor.Primary, new Color(1f, 1f, 1f)); - // UI.HandleBegin("design", ref windowPose, new Bounds(V.XYZ(0.02f, 0.02f, 0.02f)), true, UIMove.FaceUser); - UI.SetThemeColor(UIColor.Background, new Color(0.2f, 0.2f, 0.3f)); - UI.SetThemeColor(UIColor.Primary, new Color(0.4f, 0.4f, 0.6f)); - UI.SetThemeColor(UIColor.Common, new Color(1.0f, 1.0f, 1.0f)); - UI.PushTextStyle(style); - - // if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; } - // if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; } - // if (UI.Button("Scale w/Height")) { oriel.scaleWithHeight = !oriel.scaleWithHeight; } - // UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f); - // UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f); - // // UI.Label("Player.y"); - // UI.HSlider("Player.y", ref greenyard.height, 1f, 6f, 0.2f); - // UI.Label("pos.y"); - // UI.HSlider("pos.y", ref playerY, -1f, 1f, 0.1f); - - if (UI.Button("prev") && dofIndex > 0) { - dofIndex--; - } - UI.SameLine(); - if (UI.Button("next") && dofIndex < interactions.Length - 1) { - dofIndex++; - } - - - Interaction dof = interactions[dofIndex]; - Type type = dof.GetType(); - // active toggle - Color tint = dof.Active ? new Color(0, 1, 0) : new Color(1, 0, 0); - UI.PushTint(tint); - if (UI.Button(dof.Active ? "on" : "off")) { - dof.Active = !dof.Active; - } - UI.PopTint(); - if (type == typeof(Chiral)) { - Chiral chiral = (Chiral)dof; - - System.Reflection.FieldInfo[] fields = typeof(Chiral).GetFields(); - foreach (System.Reflection.FieldInfo field in fields) { - if (field.FieldType == typeof(Handed)) { - Handed handed = (Handed)field.GetValue(chiral); - if (UI.Button("<") && (int)handed > 0) { - handed = (Handed)((int)handed - 1); - field.SetValue(chiral, handed); - } - UI.SameLine(); - if (UI.Button(">") && (int)handed < 2) { - handed = (Handed)((int)handed + 1); - field.SetValue(chiral, handed); - } - UI.SameLine(); UI.Label(handed.ToString()); - } - } - - RenderDof(chiral.dofs[0]); - } else { - RenderDof(dof); - } - - UI.WindowEnd(); - // UI.HandleEnd(); - } - - void RenderDof(Interaction dof) { - Type type = dof.GetType(); - UI.Label("°" + type.Name); - System.Reflection.FieldInfo[] fields = type.GetFields(); - for (int j = 0; j < fields.Length; j++) { - System.Reflection.FieldInfo field = fields[j]; - if (field.FieldType == typeof(Design)) { - Design design = (Design)field.GetValue(dof); - UI.Input(field.Name, ref design.str, fieldSize, TextContext.Number); - - UI.SameLine(); - UI.PushTextStyle(style2); - UI.Label(design.term, new Vec2(4f * U.cm, 3f * U.cm)); - UI.PopTextStyle(); - - UI.SameLine(); UI.Label(field.Name); - } - } + window.Frame(); } + Window window = new Window(); } -// Chiral : handedness implies symmetry -public class Chiral : Interaction { - public Chiral(Interaction[] dofs) => this.dofs = dofs; - private bool active; - public bool Active { - get { return this.active; } - set { - this.active = value; - for (int i = 0; i < this.dofs.Length; i++) { - Interaction dof = this.dofs[i]; - if ((int)this.handed == 2 || i == (int)this.handed) { - dof.Active = value; - } else { - dof.Active = false; - } - } - } - } - public Interaction[] dofs = new Interaction[2]; - // public Design handed = new Design { str = "2", min = 0, max = 2}; - public Handed handed = Handed.Max; - - public void Init() { - dofs[0].Init(); - dofs[1].Init(); - } - - public void Frame() { - // sync the left design variables to the right - System.Reflection.FieldInfo[] fields = dofs[0].GetType().GetFields(); - foreach (System.Reflection.FieldInfo field in fields) { - if (field.FieldType == typeof(Design)) { - Design design = (Design)field.GetValue(dofs[0]); // define type? - field.SetValue(dofs[1], design); - } - } - - for (int i = 0; i < dofs.Length; i++) { - Interaction dof = dofs[i]; - if ((int)handed == 2 || i == (int)handed) { - dof.Frame(); - dof.Active = true; - } - else { - dof.Active = false; - } - } - } -} - -public class Design { - public string str; - public string term; - public float min = float.NegativeInfinity; - public float max = float.PositiveInfinity; - public float unit = U.m; - - public float value { - get { - try { - float value = PR.Clamp(float.Parse(str), min, max); - // if clamped, update string - if (value != float.Parse(str)) { - if (Input.Key(Key.Return).IsJustActive()) { - str = value.ToString(); - } - } - return value * unit; - } catch { - return MathF.Max(0, min) * unit; - } - } - } - // public int integer {}; -} - -public class Cursor { - PR.OneEuroFilter xF = new PR.OneEuroFilter(0.001f, 0.1f); - PR.OneEuroFilter yF = new PR.OneEuroFilter(0.001f, 0.1f); - PR.OneEuroFilter zF = new PR.OneEuroFilter(0.001f, 0.1f); - Vec3 _raw; - public Vec3 raw { - get => _raw; - set { - _raw = value; - pos = new Vec3( - (float)xF.Filter(raw.x, (double)Time.Stepf), - (float)yF.Filter(raw.y, (double)Time.Stepf), - (float)zF.Filter(raw.z, (double)Time.Stepf) - ); - smooth = Vec3.Lerp(smooth, pos, Time.Stepf * 6f); - } - } - public Vec3 pos { get; private set; } - public Vec3 smooth { get; private set; } -} - - -/* - COMMENTS - - ranges - 0+1 - 1-0 - 1-0+1 - - -0+ - - 0+&&- - 0+||- - - units - m - cm - mm - t - - demo - seperate the demos from the dofs, and make them rebindable (assigning input using reflection?) - virtual shapes(scalable) -> that can be slotted - physics boxes - - mirror - mirroring vectors(line segments) is really easy - easier than rendering.. actually just render twice with the material chain - stereonick mentioned - - debug bool - rendering the raw output - particularly for hand tracking dofs (so Moses can better test them!) - raw = 0.333f alpha ~ - -*/ - - - /* we have a whole inspector thing going on here @@ -497,71 +227,4 @@ public class Cursor { local to palm dofchan bows on the back of the ankles that double as trackers -*/ - - -public class Spatial { - // example, to build out from! - // rn it's just adding two vectors - // building towards great interactivity and visual feedback - public Spatial(Vec3 origin) { - this.origin = origin; - } - public Vec3 origin; - float scale = 0.2f; - float thickness => 0.02f * scale; - - - float t = 1.0f; - Vec3 aFrom, aTo; - Vec3 a => Vec3.Lerp(aFrom, aTo, MathF.Min(t, 1f)); - Vec3 bFrom, bTo; - Vec3 b => Vec3.Lerp(bFrom, bTo, MathF.Min(t, 1f)); - Vec3 c => a + b; - - public void Frame() { - // origin axis - Lines.Add(origin, World(new Vec3(1, 0, 0)), new Color(1, 0, 0), thickness * 0.333f); - Lines.Add(origin, World(new Vec3(0, 1, 0)), new Color(0, 1, 0), thickness * 0.333f); - Lines.Add(origin, World(new Vec3(0, 0, 1)), new Color(0, 0, 1), thickness * 0.333f); - Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(origin, thickness), new Color(0.5f, 0.5f, 0.5f)); - - Random rand = Random.Shared; - if (t >= 1.3f) { - aFrom = aTo; - bFrom = bTo; - - if (rand.NextSingle() < 0.5f) { - aTo = new Vec3(rand.NextSingle(), rand.NextSingle(), rand.NextSingle()) * 0.5f; - } else { - bTo = new Vec3(rand.NextSingle(), rand.NextSingle(), rand.NextSingle()) * 0.5f; - } - - t = 0.0f; - } - t += Time.Stepf / 2f; - - // Lines.Add(origin, World(a), new Color(1, 1, 1, 0.5f), thickness * 2); // they clip with no material way to fix it? - Lines.Add(origin, World(a), new Color(1, 1, 0), thickness); - Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(a), thickness), new Color(1, 1, 0)); - // Lines.Add(origin, World(b), new Color(1, 1, 1, 0.5f), thickness * 2); - Lines.Add(origin, World(b), new Color(0, 1, 1), thickness); - Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(b), thickness), new Color(0, 1, 1)); - - Lines.Add(World(a), World(c), new Color(0, 1, 1), thickness); - Lines.Add(World(b), World(c), new Color(1, 1, 0), thickness); - // color between yellow and cyan using HSV - Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(c), thickness), new Color(0.5f, 1, 1)); - } - - Vec3 World(Vec3 local) { - return origin + local * scale; - } - - // -} - -// Volumetric Lines -public class Vine { - -} \ No newline at end of file +*/ \ No newline at end of file diff --git a/src/Rig.cs b/src/Rig.cs index 4729cfe..b4b286f 100644 --- a/src/Rig.cs +++ b/src/Rig.cs @@ -145,4 +145,25 @@ public struct Btn { frameUp = !down && held; held = down; } +} + +public class Cursor { + PR.OneEuroFilter xF = new PR.OneEuroFilter(0.001f, 0.1f); + PR.OneEuroFilter yF = new PR.OneEuroFilter(0.001f, 0.1f); + PR.OneEuroFilter zF = new PR.OneEuroFilter(0.001f, 0.1f); + Vec3 _raw; + public Vec3 raw { + get => _raw; + set { + _raw = value; + pos = new Vec3( + (float)xF.Filter(raw.x, (double)Time.Stepf), + (float)yF.Filter(raw.y, (double)Time.Stepf), + (float)zF.Filter(raw.z, (double)Time.Stepf) + ); + smooth = Vec3.Lerp(smooth, pos, Time.Stepf * 6f); + } + } + public Vec3 pos { get; private set; } + public Vec3 smooth { get; private set; } } \ No newline at end of file diff --git a/src/Space.cs b/src/Space.cs index 66f0bc2..4803c87 100644 --- a/src/Space.cs +++ b/src/Space.cs @@ -73,6 +73,7 @@ public class Space { public void Frame() { + Mono mono = Mono.inst; // Oriel oriel = Mono.inst.oriel; // data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); // data.dimensions = oriel.bounds.dimensions; @@ -123,7 +124,7 @@ public class Space { if (Vec3.Distance(new Vec3(xpos, 0, zpos), Vec3.Zero) < radius / 2) { Mesh.Cube.Draw( - Mono.inst.matHolo, + mono.mat.holo, Matrix.TS( new Vec3( xpos + x, @@ -143,7 +144,7 @@ public class Space { xpos += offset.x; zpos += offset.z; Mesh.Cube.Draw( - Mono.inst.matHolo, + mono.mat.holo, Matrix.TRS( new Vec3(xpos, (height * 0.5f), zpos), Quat.FromAngles(0, angle, 0), @@ -153,7 +154,7 @@ public class Space { ); Mesh.Cube.Draw( - Mono.inst.matHolo, + mono.mat.holo, Matrix.TRS( new Vec3(xpos, height, zpos), Quat.FromAngles(0, angle, 0), @@ -178,6 +179,8 @@ public class Space { Mesh mesh_ripple = Model.FromFile("ripple.glb").FindNode("ripple").Mesh; public void Frame(int id) { + Mono mono = Mono.inst; + if (!falling) { PR.Noise noise = Mono.inst.noise; rippleT += Time.Stepf / 0.5f; @@ -194,7 +197,7 @@ public class Space { t *= t; t = 1 - t; mesh_ripple.Draw( - Mono.inst.matHoloclear, + mono.mat.holoclear, Matrix.TRS(pos, Quat.Identity, new Vec3(0.333f * t, 0.0133f, 0.333f * t)), new Color(1f, 1f, 1f, 1f) * (1f - t) ); @@ -210,7 +213,7 @@ public class Space { } Mesh.Cube.Draw( - Mono.inst.matHoloclear, + mono.mat.holoclear, Matrix.TRS(pos, Quat.Identity, new Vec3(0.002f, 0.98f, 0.002f)), new Color(0.8f, 0.8f, 1f) * 0.1333f ); diff --git a/src/Spatial.cs b/src/Spatial.cs new file mode 100644 index 0000000..c2a65ac --- /dev/null +++ b/src/Spatial.cs @@ -0,0 +1,62 @@ +namespace Oriels; + +public class Spatial { + // example, to build out from! + // rn it's just adding two vectors + // building towards great interactivity and visual feedback + public Spatial(Vec3 origin) { + this.origin = origin; + } + public Vec3 origin; + float scale = 0.2f; + float thickness => 0.02f * scale; + + + float t = 1.0f; + Vec3 aFrom, aTo; + Vec3 a => Vec3.Lerp(aFrom, aTo, MathF.Min(t, 1f)); + Vec3 bFrom, bTo; + Vec3 b => Vec3.Lerp(bFrom, bTo, MathF.Min(t, 1f)); + Vec3 c => a + b; + + public void Frame() { + // origin axis + Lines.Add(origin, World(new Vec3(1, 0, 0)), new Color(1, 0, 0), thickness * 0.333f); + Lines.Add(origin, World(new Vec3(0, 1, 0)), new Color(0, 1, 0), thickness * 0.333f); + Lines.Add(origin, World(new Vec3(0, 0, 1)), new Color(0, 0, 1), thickness * 0.333f); + Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(origin, thickness), new Color(0.5f, 0.5f, 0.5f)); + + Random rand = Random.Shared; + if (t >= 1.3f) { + aFrom = aTo; + bFrom = bTo; + + if (rand.NextSingle() < 0.5f) { + aTo = new Vec3(rand.NextSingle(), rand.NextSingle(), rand.NextSingle()) * 0.5f; + } else { + bTo = new Vec3(rand.NextSingle(), rand.NextSingle(), rand.NextSingle()) * 0.5f; + } + + t = 0.0f; + } + t += Time.Stepf / 2f; + + // Lines.Add(origin, World(a), new Color(1, 1, 1, 0.5f), thickness * 2); // they clip with no material way to fix it? + Lines.Add(origin, World(a), new Color(1, 1, 0), thickness); + Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(a), thickness), new Color(1, 1, 0)); + // Lines.Add(origin, World(b), new Color(1, 1, 1, 0.5f), thickness * 2); + Lines.Add(origin, World(b), new Color(0, 1, 1), thickness); + Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(b), thickness), new Color(0, 1, 1)); + + Lines.Add(World(a), World(c), new Color(0, 1, 1), thickness); + Lines.Add(World(b), World(c), new Color(1, 1, 0), thickness); + // color between yellow and cyan using HSV + Mesh.Sphere.Draw(Material.Unlit, Matrix.TS(World(c), thickness), new Color(0.5f, 1, 1)); + } + + Vec3 World(Vec3 local) { + return origin + local * scale; + } + + // +} \ No newline at end of file diff --git a/src/Window.cs b/src/Window.cs new file mode 100644 index 0000000..dab687b --- /dev/null +++ b/src/Window.cs @@ -0,0 +1,101 @@ +namespace Oriels; + +public class Window { + int dofIndex = 0; + Pose windowPose = new Pose(-0.333f, 1.2f, -0.5f, Quat.FromAngles(0, 180, 0)); + Material windowMat = new Material(Shader.FromFile("shaders/window.hlsl")); + TextStyle style = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, Color.Black); + TextStyle style2 = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, new Color(0.5f, 0.5f, 0.5f)); + Vec2 fieldSize = new Vec2(6f * U.cm, 3f * U.cm); + public void Frame() { + Mono mono = Mono.inst; + windowMat.Transparency = Transparency.Add; + windowMat.FaceCull = Cull.None; + windowMat.DepthWrite = false; + UI.SetElementVisual(UIVisual.WindowBody, Mesh.Quad, windowMat, Vec2.One); + UI.SetElementVisual(UIVisual.WindowHead, Mesh.Quad, windowMat, Vec2.One); + UI.WindowBegin("design vars", ref windowPose); + // UI.SetThemeColor(UIColor.Primary, new Color(1f, 1f, 1f)); + // UI.HandleBegin("design", ref windowPose, new Bounds(V.XYZ(0.02f, 0.02f, 0.02f)), true, UIMove.FaceUser); + UI.SetThemeColor(UIColor.Background, new Color(0.2f, 0.2f, 0.3f)); + UI.SetThemeColor(UIColor.Primary, new Color(0.4f, 0.4f, 0.6f)); + UI.SetThemeColor(UIColor.Common, new Color(1.0f, 1.0f, 1.0f)); + UI.PushTextStyle(style); + + // if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; } + // if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; } + // if (UI.Button("Scale w/Height")) { oriel.scaleWithHeight = !oriel.scaleWithHeight; } + // UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f); + // UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f); + // // UI.Label("Player.y"); + // UI.HSlider("Player.y", ref greenyard.height, 1f, 6f, 0.2f); + // UI.Label("pos.y"); + // UI.HSlider("pos.y", ref playerY, -1f, 1f, 0.1f); + + if (UI.Button("prev") && dofIndex > 0) { + dofIndex--; + } + UI.SameLine(); + if (UI.Button("next") && dofIndex < mono.interactions.Length - 1) { + dofIndex++; + } + + + Interaction dof = mono.interactions[dofIndex]; + Type type = dof.GetType(); + // active toggle + Color tint = dof.Active ? new Color(0, 1, 0) : new Color(1, 0, 0); + UI.PushTint(tint); + if (UI.Button(dof.Active ? "on" : "off")) { + dof.Active = !dof.Active; + } + UI.PopTint(); + if (type == typeof(Chiral)) { + Chiral chiral = (Chiral)dof; + + System.Reflection.FieldInfo[] fields = typeof(Chiral).GetFields(); + foreach (System.Reflection.FieldInfo field in fields) { + if (field.FieldType == typeof(Handed)) { + Handed handed = (Handed)field.GetValue(chiral); + if (UI.Button("<") && (int)handed > 0) { + handed = (Handed)((int)handed - 1); + field.SetValue(chiral, handed); + } + UI.SameLine(); + if (UI.Button(">") && (int)handed < 2) { + handed = (Handed)((int)handed + 1); + field.SetValue(chiral, handed); + } + UI.SameLine(); UI.Label(handed.ToString()); + } + } + + RenderDof(chiral.dofs[0]); + } else { + RenderDof(dof); + } + + UI.WindowEnd(); + // UI.HandleEnd(); + } + + void RenderDof(Interaction dof) { + Type type = dof.GetType(); + UI.Label("°" + type.Name); + System.Reflection.FieldInfo[] fields = type.GetFields(); + for (int j = 0; j < fields.Length; j++) { + System.Reflection.FieldInfo field = fields[j]; + if (field.FieldType == typeof(Design)) { + Design design = (Design)field.GetValue(dof); + UI.Input(field.Name, ref design.str, fieldSize, TextContext.Number); + + UI.SameLine(); + UI.PushTextStyle(style2); + UI.Label(design.term, new Vec2(4f * U.cm, 3f * U.cm)); + UI.PopTextStyle(); + + UI.SameLine(); UI.Label(field.Name); + } + } + } +} \ No newline at end of file diff --git a/src/_Init.cs b/src/_Init.cs index 820feb5..2919029 100644 --- a/src/_Init.cs +++ b/src/_Init.cs @@ -7,7 +7,7 @@ SKSettings settings = new SKSettings { assetsFolder = "add", depthMode = DepthMode.D32, disableUnfocusedSleep = true, - // displayPreference = DisplayMode.Flatscreen, + displayPreference = DisplayMode.Flatscreen, // disableFlatscreenMRSim = true, }; if (!SK.Initialize(settings))