Compare commits

...

10 commits

Author SHA1 Message Date
e5c6514b67 stretch cursor idle loop 2024-12-08 00:11:53 -05:00
cabd123404 backhand cursor orientation 2024-12-08 00:11:39 -05:00
66e5afdb22 test toggles 2024-12-08 00:09:40 -05:00
af27931d6c comment out menu 2024-12-08 00:08:42 -05:00
d1cb1bd452 cursor trail 2024-12-08 00:08:29 -05:00
741f2ee713 use controller pose instead 2024-12-08 00:07:21 -05:00
041ceea867 custom hand shader 2024-12-08 00:04:31 -05:00
290ada0f0c reprioritize 2024-12-08 00:03:39 -05:00
1a3a9c2ee5 increase dist check radius 2024-12-07 20:05:30 -05:00
a5328c1a6e init grabs out in front 2024-12-07 19:56:29 -05:00
8 changed files with 183 additions and 62 deletions

45
Assets/hand.hlsl Normal file
View file

@ -0,0 +1,45 @@
#include "stereokit.hlsli"
//--name = dofdev/hand
//--color:color = 1, 1, 1, 1
//--tex_scale = 1
//--diffuse = white
float4 color;
float tex_scale;
Texture2D diffuse : register(t0);
SamplerState diffuse_s : register(s0);
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
float2 uv : TEXCOORD0;
float4 col : COLOR0;
};
struct psIn {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR0;
uint view_id : SV_RenderTargetArrayIndex;
};
psIn vs(vsIn input, uint id : SV_InstanceID) {
psIn o;
o.view_id = id % sk_view_count;
id = id / sk_view_count;
float3 world = mul(float4(input.pos.xyz, 1), sk_inst[id].world).xyz;
o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]);
float3 normal = normalize(mul(input.norm, (float3x3)sk_inst[id].world));
o.uv = input.uv * tex_scale;
float3 norm_color = float3(0.5) + (normal * 0.5);
float3 norm_shade = float3(0.5) + (norm_color * 0.5);
o.color = float4(norm_shade, 1) * input.col; // input.col * color * sk_inst[id].color;
return o;
}
float4 ps(psIn input) : SV_TARGET {
float4 col = diffuse.Sample(diffuse_s, input.uv);
return input.color * col * float4(1, 1, 1, 0.1333);
}

BIN
Assets/meshes/assets.glb (Stored with Git LFS)

Binary file not shown.

View file

@ -52,11 +52,11 @@ todo
featuring:
[x] stretch_cursor
[x] color_cube
[ ] reach_cursor
[ ] orbital_view // same dis/mount system as snake in a box
[ ] fullstick
[ ] twist_cursor
[ ] reach_cursor
[ ] cubic_flow
[ ] fullstick
[ ] orbital_view // same dis/mount system as snake in a box
bug(s)
...

View file

@ -8,6 +8,7 @@ static class Arts
static Model assets_model = Model.FromFile("meshes/assets.glb", Shader.Unlit);
static Dictionary<string, Mesh> meshes = new();
static Material mat_mono = new Material("mono.hlsl");
static Material mat_hand = Default.MaterialHand;
static Material mat_unlit = new Material("unlit.hlsl");
static Material mat_both = new Material("unlit.hlsl");
static Material mat_backface = new Material("backface.hlsl");
@ -43,13 +44,15 @@ static class Arts
// draw ontop of everything
mat_colorcursor.DepthTest = DepthTest.Always;
mat_hand.Shader = Shader.FromFile("hand.hlsl");
}
public static void Frame()
{
if (SK.GetStepper<PassthroughFBExt>().Enabled) {
Input.HandVisible(Handed.Max, false);
}
// if (SK.GetStepper<PassthroughFBExt>().Enabled) {
// Input.HandVisible(Handed.Max, false);
// }
// world
// Matrix m4_dof = Mono.dof_pose.ToMatrix(Mono.dof_scl);
@ -76,26 +79,45 @@ static class Arts
// stretch_cursor
{
float flip_x = Stretch.to_grab.Held && Stretch.to_grab.held_by.handed == Handed.Left ? -1 : 1;
meshes["con"].Draw(
mat_mono,
Stretch.to_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm)
Stretch.to_grab.pose.ToMatrix(1.5f * U.cm)
);
flip_x = Stretch.from_grab.Held && Stretch.from_grab.held_by.handed == Handed.Left ? -1 : 1;
meshes["con"].Draw(
mat_mono,
Stretch.from_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm)
Stretch.from_grab.pose.ToMatrix(1.5f * U.cm)
);
Mesh.Cube.Draw(
mat_mono,
Stretch.cursor.ToMatrix(3 * U.cm)
mat_justcolor,
Stretch.cursor.ToMatrix(V.XYZ(-1, 1, 1) * 1.2f * U.cm),
Color.Hex(0x000000FF).ToLinear()
);
Mesh.Cube.Draw(
mat_mono,
Stretch.cursor.ToMatrix(1 * U.cm)
);
// particles
Particle[] particles = Stretch.particles;
for (int i = 0; i < particles.Length; i++)
{
Particle particle = particles[i];
Mesh.Sphere.Draw(
mat_unlit,
Matrix.TRS(
particle.pos,
particle.ori,
particle.scl
),
Color.Hex(0xFFFFFFFF).ToLinear()
);
}
}
// color_cube
{
meshes["color_cube"].Draw(
meshes[ColorCube.toggle ? "color_cube_toggle" : "color_cube"].Draw(
mat_colorcube,
ColorCube.grab.pose.ToMatrix(ColorCube.scl)
);
@ -121,6 +143,11 @@ static class Arts
Hierarchy.Pop();
}
// reach_cursor
{
}
// Hierarchy.Pop();
@ -141,23 +168,23 @@ static class Arts
// }
// menu
Matrix m4_menu = Mono.menu_pose.ToMatrix(Mono.menu_scale);
Hierarchy.Push(m4_menu);
// Matrix m4_menu = Mono.menu_pose.ToMatrix(Mono.menu_scale);
// Hierarchy.Push(m4_menu);
// score
char[] score_txt = Mono.score.ToString("000").ToCharArray();
for (int i = 0; i < score_txt.Length; i++)
{
Text.Add(
score_txt[i].ToString(),
Matrix.TS(
V.XYZ(0, 0, 0),
48
),
text_style
);
}
// // score
// char[] score_txt = Mono.score.ToString("000").ToCharArray();
// for (int i = 0; i < score_txt.Length; i++)
// {
// Text.Add(
// score_txt[i].ToString(),
// Matrix.TS(
// V.XYZ(0, 0, 0),
// 48
// ),
// text_style
// );
// }
Hierarchy.Pop();
// Hierarchy.Pop();
}
}

View file

@ -13,7 +13,7 @@ public class Grab
public Pose pose;
private Vec3 pos_offset;
private Quat ori_offset;
public Hand? held_by;
public Controller? held_by;
private bool snap_to_hand = false;
public Grab(float x, float y, float z, bool snap_to_hand = false)
@ -25,16 +25,16 @@ public class Grab
this.snap_to_hand = snap_to_hand;
}
public bool OnGrab(ref Hand hand, ref Grab grab_ref)
public bool OnGrab(ref Controller con, ref Grab grab_ref)
{
if (!Held) // Allow only one hand at a time to grab
{
if (Vec3.Distance(hand.palm.position, pose.position) < 0.1f)
if (Vec3.Distance(con.pose.position, pose.position) < 0.14f)
{
held_by = hand;
held_by = con;
grab_ref = this;
pos_offset = hand.palm.orientation.Inverse * (hand.palm.position - pose.position);
ori_offset = hand.palm.orientation.Inverse * pose.orientation;
pos_offset = con.pose.orientation.Inverse * (con.pose.position - pose.position);
ori_offset = con.pose.orientation.Inverse * pose.orientation;
return true;
}
}
@ -54,13 +54,13 @@ public class Grab
{
if (snap_to_hand)
{
pose.orientation = held_by.palm.orientation;
pose.position = held_by.palm.position;
pose.orientation = held_by.pose.orientation;
pose.position = held_by.pose.position;
}
else
{
pose.orientation = held_by.palm.orientation * ori_offset;
pose.position = held_by.palm.position - held_by.palm.orientation * pos_offset;
pose.orientation = held_by.pose.orientation * ori_offset;
pose.position = held_by.pose.position - held_by.pose.orientation * pos_offset;
}
}
}

View file

@ -12,23 +12,66 @@ static class Stretch
public static float stretch = 0.0f;
public static Pose cursor;
// vfx
public static Particle[] particles = new Particle[64];
static int index = 0;
static float trail_dist = 3 * U.cm;
static Vec3 last_particle_pos = Vec3.Zero;
public static void Init()
{
to_grab = new(-0.3f, 0, 0, true);
from_grab = new(-0.3f, 0, 0.1f, true);
to_grab = new(-0.3f, -0.25f, -0.5f, true);
from_grab = new(-0.3f, -0.25f, -0.4f, true);
for (int i = 0; i < particles.Length; i++)
{
particles[i] = new();
}
}
public static void Frame()
{
if (!from_grab.Held && !to_grab.Held)
{
from_grab.pose.orientation = Quat.Identity;
to_grab.pose.orientation = Quat.Identity;
from_grab.pose.position = to_grab.pose.position - Vec3.Forward * ((15 * U.cm) - (MathF.Sin(Time.Totalf * 3f) * 4 * U.cm));
}
Vec3 delta = to_grab.pose.position - from_grab.pose.position;
stretch = Maths.max(delta.Magnitude - deadzone, 0);
Vec3 dir = delta.Normalized;
Vec3 dir = toggle ? delta.Normalized : to_grab.pose.orientation * Vec3.Forward;
cursor.orientation = from_grab.pose.orientation;
cursor.position = to_grab.pose.position + dir * stretch * strength;
if (Vec3.Distance(cursor.position, last_particle_pos) > trail_dist)
{
index = (index + 1) % particles.Length;
Particle particle = particles[index];
particle.pos = last_particle_pos + Vec3.Direction(cursor.position, last_particle_pos) * trail_dist;
// particle.vel = Quat.FromAngles(Random.Shared.NextSingle() * 360, 0, 0) * Quat.FromAngles(0, Random.Shared.NextSingle() * 360, 0) * Vec3.Forward * 6.0f;
particle.ori = Quat.Identity;
particle.scl = 3 * U.mm;
last_particle_pos = particle.pos;
}
for (int i = 0; i < particles.Length; i++)
{
Particle particle = particles[i];
if (particle.vel.MagnitudeSq > float.Epsilon)
{
// particle.pos += particle.vel * Time.Stepf;
// particle.vel *= 1 - (3 * Time.Stepf);
}
particle.scl *= 1.0f - (3 * Time.Stepf);
}
}
// design
static float deadzone = 0.1f;
public static bool toggle = true;
static float deadzone = 0.06f;
static float strength = 3;
}
@ -43,7 +86,7 @@ static class ColorCube
public static void Init()
{
grab = new(0, 0, 0);
grab = new(0, -0.25f, -0.5f);
}
public static void Frame()
@ -75,5 +118,8 @@ static class ColorCube
return x / 12.92f;
}
// design
public static bool toggle = true;
}

View file

@ -39,6 +39,8 @@ static class Mono
ColorCube.Init();
}
public static Pose windowPoseButton = new Pose(0, -0.4f, -0.4f, Quat.FromAngles(45, 180, 0));
public static void Frame()
{
if (Rig.btn_back.delta == +1)
@ -58,6 +60,13 @@ static class Mono
}
}
UI.WindowBegin("test toggles", ref windowPoseButton);
if (UI.Button(ColorCube.toggle ? "color frame" : "color face"))
ColorCube.toggle = !ColorCube.toggle;
if (UI.Button(Stretch.toggle ? "con dir" : "stretch dir"))
Stretch.toggle = !Stretch.toggle;
UI.WindowEnd();
// flatscreen dev controls
if (Device.Name == "Simulator")
{
@ -111,7 +120,7 @@ static class Mono
{
if (Rig.btn_l_grip.delta == +1)
{
grab.OnGrab(ref Rig.l_hnd, ref Rig.l_held);
grab.OnGrab(ref Rig.l_con, ref Rig.l_held);
}
}
}
@ -132,7 +141,7 @@ static class Mono
{
if (Rig.btn_r_grip.delta == +1)
{
grab.OnGrab(ref Rig.r_hnd, ref Rig.r_held);
grab.OnGrab(ref Rig.r_con, ref Rig.r_held);
}
}
}

View file

@ -6,8 +6,8 @@ static class Rig
{
public static Pose head = Pose.Identity;
public static Hand l_hnd;
public static Hand r_hnd;
public static Hand l_hnd, r_hnd;
public static Controller l_con, r_con;
public static DeltaBool btn_select = new(false);
public static DeltaBool btn_l_grip = new(false);
@ -17,8 +17,6 @@ static class Rig
public static Grab? l_held = null;
public static Grab? r_held = null;
public static Pose l_hld, l_aim, r_hld, r_aim;
public static Vec3 fullstick = Vec3.Up;
public static Pose r_con_stick = Pose.Identity;
@ -26,7 +24,8 @@ static class Rig
public static void Init()
{
l_con = new();
r_con = new();
}
public static void Frame()
@ -62,21 +61,16 @@ static class Rig
// [!] hand input simulates controller...
l_hnd = Input.Hand(Handed.Left);
Controller l_con = Input.Controller(Handed.Left);
// l_hld = l_con.pose;
l_hld = l_hnd.palm;
// l_aim = l_con.aim;
l_con = Input.Controller(Handed.Left);
r_hnd = Input.Hand(Handed.Right);
Controller r_con = Input.Controller(Handed.Right);
// r_hld = r_con.pose;
r_hld = r_hnd.palm;
// r_aim = r_con.aim;
r_con = Input.Controller(Handed.Right);
btn_l_grip.Step(l_con.grip > 0.5f || l_hnd.IsGripped);
btn_r_grip.Step(r_con.grip > 0.5f || r_hnd.IsGripped);
// double grip?
btn_select.Step(r_con.x1.IsActive() || r_con.trigger > 0.5f);
btn_back.Step(r_con.x2.IsActive());