drawer pincher
This commit is contained in:
parent
7e1811a8d3
commit
9bbbfe28ad
4 changed files with 111 additions and 14 deletions
BIN
add/drawer.glb
Normal file
BIN
add/drawer.glb
Normal file
Binary file not shown.
|
@ -28,6 +28,18 @@ public class Compositor {
|
||||||
public void Frame() {
|
public void Frame() {
|
||||||
Mono mono = Mono.inst;
|
Mono mono = Mono.inst;
|
||||||
|
|
||||||
|
// Renderer.RenderTo(tex,
|
||||||
|
// Matrix.TR(V.XYZ(0, 1, 0), Quat.FromAngles(0, 180, 0)),
|
||||||
|
// Matrix.Perspective(60, 1, 0.1f, 100),
|
||||||
|
// RenderLayer.All // & ~RenderLayer.Layer1
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Default.MeshQuad.Draw(mat,
|
||||||
|
// Matrix.TR(V.XYZ(0, 1, 0), Quat.FromAngles(0, 0, 0))
|
||||||
|
// );
|
||||||
|
|
||||||
// backrooms.oriel.Frame();
|
// backrooms.oriel.Frame();
|
||||||
// greenyard.oriel.Frame();
|
// greenyard.oriel.Frame();
|
||||||
|
|
||||||
|
@ -77,16 +89,6 @@ public class Compositor {
|
||||||
// );
|
// );
|
||||||
// Model model = Model.FromFile("oriel.glb");
|
// Model model = Model.FromFile("oriel.glb");
|
||||||
// ~ Mesh mesh = model.GetMesh("oriel");
|
// ~ Mesh mesh = model.GetMesh("oriel");
|
||||||
|
|
||||||
Renderer.RenderTo(tex,
|
|
||||||
Matrix.TR(V.XYZ(0, 1, 0), Quat.FromAngles(0, 180, 0)),
|
|
||||||
Matrix.Perspective(60, 1, 0.1f, 100),
|
|
||||||
RenderLayer.All // & ~RenderLayer.Layer1
|
|
||||||
);
|
|
||||||
|
|
||||||
Default.MeshQuad.Draw(mat,
|
|
||||||
Matrix.TR(V.XYZ(0, 1, 0), Quat.FromAngles(0, 0, 0))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Place() {
|
void Place() {
|
||||||
|
|
101
src/Mono.cs
101
src/Mono.cs
|
@ -82,6 +82,75 @@ public class Mono {
|
||||||
|
|
||||||
|
|
||||||
Spatial spatial = new Spatial();
|
Spatial spatial = new Spatial();
|
||||||
|
Cursor cursor = new Cursor();
|
||||||
|
public class Drawer {
|
||||||
|
public Pose pose;
|
||||||
|
public float open; // 0 - 1
|
||||||
|
|
||||||
|
public Drawer(Pose pose) {
|
||||||
|
this.pose = pose;
|
||||||
|
|
||||||
|
mat.FaceCull = Cull.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Frame(Cursor cursor, float pinch) {
|
||||||
|
float width = 0.4f;
|
||||||
|
float height = 0.15f;
|
||||||
|
|
||||||
|
Matrix matrix = pose.ToMatrix();
|
||||||
|
Vec3 localCursor = matrix.Inverse.Transform(cursor.pos);
|
||||||
|
|
||||||
|
bool inBounds = localCursor.x > 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() {
|
public void Frame() {
|
||||||
|
|
||||||
|
@ -102,6 +171,33 @@ public class Mono {
|
||||||
// rGlove.Step();
|
// rGlove.Step();
|
||||||
|
|
||||||
compositor.Frame();
|
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<Hand, BtnState.Any, Pointer>);
|
// Input.Subscribe(InputSource.Hand, BtnState.Any, Action<Hand, BtnState.Any, Pointer>);
|
||||||
|
|
||||||
|
@ -148,7 +244,6 @@ public class Mono {
|
||||||
new Color(0.5f, 0.55f, 0.75f) * 0.3f
|
new Color(0.5f, 0.55f, 0.75f) * 0.3f
|
||||||
);
|
);
|
||||||
|
|
||||||
spatial.Frame();
|
|
||||||
|
|
||||||
// </Heresy>
|
// </Heresy>
|
||||||
|
|
||||||
|
@ -180,12 +275,12 @@ public class Mono {
|
||||||
}
|
}
|
||||||
|
|
||||||
int dofIndex = 0;
|
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 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));
|
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);
|
Vec2 fieldSize = new Vec2(6f * U.cm, 3f * U.cm);
|
||||||
void ShowWindowButton() {
|
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.Background, new Color(0f, 0f, 0f));
|
||||||
UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f));
|
UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f));
|
||||||
UI.PushTextStyle(style);
|
UI.PushTextStyle(style);
|
||||||
|
|
|
@ -7,7 +7,7 @@ SKSettings settings = new SKSettings {
|
||||||
assetsFolder = "add",
|
assetsFolder = "add",
|
||||||
depthMode = DepthMode.D32,
|
depthMode = DepthMode.D32,
|
||||||
disableUnfocusedSleep = true,
|
disableUnfocusedSleep = true,
|
||||||
displayPreference = DisplayMode.Flatscreen,
|
// displayPreference = DisplayMode.Flatscreen,
|
||||||
// disableFlatscreenMRSim = true,
|
// disableFlatscreenMRSim = true,
|
||||||
};
|
};
|
||||||
if (!SK.Initialize(settings))
|
if (!SK.Initialize(settings))
|
||||||
|
|
Loading…
Add table
Reference in a new issue