From 9bbbfe28ad90b66e86708923e73a800c942070e3 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Sat, 1 Jul 2023 01:26:15 -0400 Subject: [PATCH] drawer pincher --- add/drawer.glb | Bin 0 -> 1600 bytes src/Elements/oriel/Compositor.cs | 22 ++++--- src/Mono.cs | 101 ++++++++++++++++++++++++++++++- src/_Init.cs | 2 +- 4 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 add/drawer.glb diff --git a/add/drawer.glb b/add/drawer.glb new file mode 100644 index 0000000000000000000000000000000000000000..b72c361460693de0bd55318387a4c50a22948cce GIT binary patch literal 1600 zcmb7D|8LSz5I?s$=hUh5A0YR0#nLjS{XxfYCMZ$^WHDJ5Q{Vwj#w%&dbZJQV!%Xl` z^X~b&HH8iLlK1ZJbN9I~udl<4&Zi9kINAmnZ3295yUhf>C=xL`2@Zu6p%(`sI{0N2 z1~P~WL!uOpFNExiuuy;F7B1~#rDz?ZftMnT{6JE$RWxyCVAP`o=$KlI&^b#`dSk+{ zt$YT`pfA{Ap3ly2tOUm*8Y!xduT8rGIfNaGah*!J44j1i*pK~7?eyX}^t;oT%>=)> z?Rux~HdV@|+xl8}8uEH%MM3zl_wIBs5aFpW zeyTjZU_1$=ka6c~LNgtdtcroXU@GbMESh@k{o=`r2Zr9ppaAsk*(2u0S=XO>^q%?OL@_ZK;oR(|-2i)TMQ=V$l$C7}Mvq z%EV^C9Sqc)<78eq~q*t+?tCIaMyHv?lF2B7;?L4`{b7V`?>!HEaYta{w znflN)>2dw0AMd!{q`waqdVg4>vpWd8THa+FBKh?AHE}ea=_CnW9xoqe4)Mlym z`GRy_b9I8Uwa&<#;_@-K;Y(b~y^^bIF2!>#+G@?UB%yl9;Y(b~xssd1|Gd|6ENQdN zt3dgg&ypA8N364-WNNdY@l-NCr=6GVXFQec2c0J?+0S+=H(`f>9e4 width / -2f && localCursor.x < width / 2f && + localCursor.y > height / -2f && localCursor.y < height / 2f; + + if (!opening) { + if (open > 0) { + float delta = localCursor.z - oldZ; + + if (inBounds && localCursor.z < open && delta < -0.5f * Time.Stepf) + open = 0; + } + + if (open == 0 && inBounds && localCursor.z > 0 && oldZ <= 0) { + opening = true; + } + } + + if (opening) { + open = MathF.Max(localCursor.z, 0); + + if (!inBounds || pinch == 0 || open > 0.4f) { + opening = false; + } + // Lines.Add( + // pose.position, + // pose.position + pose.orientation * V.XYZ(0, 0, 0.1f), // -1? + // new Color(0, 1, 0), + // 0.002f + // ); + } + + openSmooth.Update(open); + model.FindNode("Cube").Mesh.Draw(mat, + Matrix.T(V.XYZ(0, 0, 0.5f)) * + Matrix.S(V.XYZ(width, height, MathF.Max(openSmooth.value, 0.01f))) * + pose.ToMatrix(), + new Color(0.8f, 0.8f, 0.8f, 0.5f) + ); + + oldZ = localCursor.z; + } + float oldZ = 0; + bool opening = false; + + PR.PID openSmooth = new PR.PID(10f, 0.01f); + + Model model = Model.FromFile("drawer.glb", Shader.Default); + Material mat = Material.Default.Copy(); + } + Drawer drawerA = new Drawer(new Pose(new Vec3(-0.5f, 0.6f, -0.8f), Quat.Identity)); + Drawer drawerB = new Drawer(new Pose(new Vec3(0, 0.6f, -0.8f), Quat.Identity)); + Drawer drawerC = new Drawer(new Pose(new Vec3(0.5f, 0.6f, -0.8f), Quat.Identity)); public void Frame() { @@ -102,6 +171,33 @@ public class Mono { // rGlove.Step(); compositor.Frame(); + // spatial.Frame(); + { + 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; + + Vec3 delta = indexTip - thumbTip; + float mag = delta.Magnitude; + float pinch = MathF.Max(mag - deadzone, 0); + + Vec3 dir = delta.Normalized; + + 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, ); + + drawerA.Frame(cursor, pinch); + drawerB.Frame(cursor, pinch); + drawerC.Frame(cursor, pinch); + } + + // Input.Subscribe(InputSource.Hand, BtnState.Any, Action); @@ -148,7 +244,6 @@ public class Mono { new Color(0.5f, 0.55f, 0.75f) * 0.3f ); - spatial.Frame(); // @@ -180,12 +275,12 @@ public class Mono { } int dofIndex = 0; - Pose windowPoseButton = new Pose(0, 1f, -0.5f, Quat.FromAngles(0, 0, 0)); + Pose windowPose = new Pose(0, 1.5f, -0.5f, Quat.FromAngles(0, 0, 0)); TextStyle style = Text.MakeStyle(Font.FromFile("add/fonts/DM-Mono.ttf"), 1f * U.cm, Color.White); 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() { - UI.WindowBegin("design vars", ref windowPoseButton); + UI.WindowBegin("design vars", ref windowPose); UI.SetThemeColor(UIColor.Background, new Color(0f, 0f, 0f)); UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f)); UI.PushTextStyle(style); diff --git a/src/_Init.cs b/src/_Init.cs index d977c5c..9d1d9b0 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))