supinecursor, twistcursor, playing w/structure

This commit is contained in:
spatialfree 2021-11-03 05:05:13 -04:00
parent f5f63a12ff
commit 99a63e0970
11 changed files with 193 additions and 71 deletions

BIN
Assets/DMMono-Regular.ttf Normal file

Binary file not shown.

View file

@ -1,13 +1,12 @@
#include "stereokit.hlsli"
//--name = sk/unlit
//--name = dofdev/unlit
//--color:color = 1, 1, 1, 1
//--diffuse = white
float4 color;
Texture2D diffuse : register(t0);
SamplerState diffuse_s : register(s0);
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
@ -31,9 +30,11 @@ psIn vs(vsIn input, uint id : SV_InstanceID) {
o.uv = input.uv;
o.color = input.col * color * sk_inst[id].color;
o.color = float4(0, 1, 1, 1);
return o;
}
float4 ps(psIn input) : SV_TARGET {
float4 col = diffuse.Sample(diffuse_s, input.uv);
col = col * input.color;

BIN
Assets/oriel.glb Normal file

Binary file not shown.

41
Assets/oriel.hlsl Normal file
View file

@ -0,0 +1,41 @@
#include "stereokit.hlsli"
//--name = dofdev/oriel
// float4 color;
// 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;
float3 norm : NORMAL0;
float2 uv : TEXCOORD0;
float1 depth : TEXCOORD1;
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(input.pos, sk_inst[id].world).xyz;
o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]);
o.norm = normalize(mul(input.norm, (float3x3)sk_inst[id].world));
o.uv = input.uv;
o.color = input.col;
o.depth = dot(float4(o.norm, 1), normalize(float4(world,1) - sk_camera_pos[o.view_id]));
return o;
}
float4 ps(psIn input) : SV_TARGET {
clip(input.depth);
return input.color;
}

View file

@ -1,11 +0,0 @@
using StereoKit;
class Oriel {
RenderLayer renderLayer;
public Oriel(RenderLayer layer) {
this.renderLayer = layer;
}
}

View file

@ -3,34 +3,73 @@ using StereoKit;
class Program {
static void Main(string[] args) {
SKSettings settings = new SKSettings
{
SKSettings settings = new SKSettings {
appName = "oriels",
assetsFolder = "Assets",
};
if (!SK.Initialize(settings))
Environment.Exit(1);
Model cursor = Model.FromFile("cursor.glb");
// TextStyle style = Text.MakeStyle(Font.FromFile("DMMono-Regular.ttf"), 0.1f, Color.White);
ColorCube cube = new ColorCube();
OrbitalView.strength = 4;
OrbitalView.distance = 0.4f;
cube.thickness = 0.01f;
ReachCursor reachCursor = new ReachCursor();
Material addMat = new Material(Shader.FromFile("example.hlsl"));
while(SK.Step(() => {
// Matrix orbitMatrix = OrbitalView.transform;
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
// Default.MaterialHand["color"] = cube.color;
reachCursor.Step();
// cursor.Draw(Matrix.S(0.1f));
}));
SK.Shutdown();
Mono.Run();
}
}
public static class Mono {
public static Controller offHand, mainHand;
public static void Run() {
ColorCube cube = new ColorCube();
OrbitalView.strength = 4;
OrbitalView.distance = 0.4f;
cube.thickness = 0.01f;
ReachCursor reachCursor = new ReachCursor();
SupineCursor supineCursor = new SupineCursor();
Oriel oriel = new Oriel();
oriel.Start();
while (SK.Step(() => {
offHand = Input.Controller(Handed.Left);
mainHand = Input.Controller(Handed.Right);
// Matrix orbitMatrix = OrbitalView.transform;
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
// Default.MaterialHand["color"] = cube.color;
// reachCursor.Step();
supineCursor.Step();
// oriel.Step();
// cursor.Draw(Matrix.S(0.1f));
})) ;
SK.Shutdown();
}
}
public class Oriel {
public Bounds bounds;
// render
Material mat = new Material(Shader.FromFile("oriel.hlsl"));
Mesh mesh = Mesh.GenerateCube(new Vec3(1, 1, 1));
public void Start() {
bounds = new Bounds(Vec3.Zero, new Vec3(1f, 0.5f, 0.5f));
// Vertex[] verts = mesh.GetVerts();
// for (int i = 0; i < verts.Length; i++) {
// verts[i].norm *= -1f;
// }
// mesh.SetVerts(verts);
}
public void Step() {
mesh.Draw(mat, Matrix.TRS(bounds.center, Quat.Identity, bounds.dimensions));
}
}

View file

@ -1,36 +0,0 @@
using System;
using StereoKit;
public class ReachCursor {
static Material unlitMat = Default.MaterialUnlit.Copy();
static Model modelCursor = Model.FromFile("cursor.glb", Shader.Default);
static Model modelSphere = new Model(Default.MeshSphere, unlitMat);
static Vec3[] pullPoints = new Vec3[2];
public void Step() {
Matrix matrix = new Matrix();
matrix.Translation = new Vec3(0, 0, -1);
for (int h = 0; h < (int)Handed.Max; h++)
{
// Get the pose for the index fingertip
Hand hand = Input.Hand((Handed)h);
Vec3 indexTip = hand[FingerId.Index, JointId.Tip].Pose.position;
Vec3 thumbTip = hand[FingerId.Thumb, JointId.Tip].Pose.position;
Vec3 pinchPos = Vec3.Lerp(indexTip, thumbTip, 0.5f);
if (hand.IsPinched)
{
pullPoints[h] = pinchPos;
}
float stretch = (pullPoints[h] - pinchPos).Length;
Vec3 dir = (pinchPos - pullPoints[h]).Normalized;
Vec3 pos = pinchPos + dir * stretch * 3;
modelCursor.Draw(Matrix.TS(pos, 0.06f));
Lines.Add(pullPoints[h], pos, Color.White, 0.01f);
modelSphere.Draw(Matrix.TS(pullPoints[h], 0.04f));
}
}
}

BIN
Resources/oriel.blend Normal file

Binary file not shown.

82
SpatialCursor.cs Normal file
View file

@ -0,0 +1,82 @@
using System;
using StereoKit;
// build this out tentatively
public abstract class SpatialCursor {
public Vec3 pos;
public Quat rot;
public static Model model = Model.FromFile("cursor.glb", Shader.Default);
}
// : SpatialCursor
public class ReachCursor {
static Material unlitMat = Default.MaterialUnlit.Copy();
static Model modelCursor = Model.FromFile("cursor.glb", Shader.Default);
static Model modelSphere = new Model(Default.MeshSphere, unlitMat);
static Vec3[] pullPoints = new Vec3[2];
public void Step() {
for (int h = 0; h < (int)Handed.Max; h++) {
// Get the pose for the index fingertip
Hand hand = Input.Hand((Handed)h);
Vec3 indexTip = hand[FingerId.Index, JointId.Tip].Pose.position;
Vec3 thumbTip = hand[FingerId.Thumb, JointId.Tip].Pose.position;
Vec3 pinchPos = Vec3.Lerp(indexTip, thumbTip, 0.5f);
if (hand.IsPinched) {
pullPoints[h] = pinchPos;
}
float stretch = (pullPoints[h] - pinchPos).Length;
Vec3 dir = (pinchPos - pullPoints[h]).Normalized;
Vec3 pos = pinchPos + dir * stretch * 3;
modelCursor.Draw(Matrix.TS(pos, 0.06f));
Lines.Add(pullPoints[h], pos, Color.White, 0.01f);
modelSphere.Draw(Matrix.TS(pullPoints[h], 0.04f));
}
}
}
public class TwistCursor : SpatialCursor {
public void Step() {
Quat rel = Quat.LookAt(Vec3.Zero, Mono.mainHand.aim.orientation * Vec3.Forward);
float twist = Vec3.Dot(rel * Vec3.Up, Mono.mainHand.aim.orientation * Vec3.Up);
twist = MathF.Max(twist - 0.05f, 0);
pos = Mono.mainHand.aim.position + Mono.mainHand.aim.orientation * Vec3.Forward * twist;
model.Draw(Matrix.TS(pos, 0.06f));
}
}
public class SupineCursor : SpatialCursor {
float calibStr;
Quat calibQuat;
public void Step() {
// calibration
if (Mono.mainHand.IsStickClicked) {
Vec3 target = Input.Head.position + Input.Head.Forward;
calibStr = Vec3.Distance(Mono.mainHand.aim.position, target) * 2;
Quat calibAlign = Quat.LookAt(Mono.mainHand.aim.position, target);
calibQuat = Mono.mainHand.aim.orientation.Inverse * calibAlign;
}
Quat rel = Quat.LookAt(Vec3.Zero, Mono.offHand.aim.orientation * Vec3.Forward);
float twist = (Vec3.Dot(rel * -Vec3.Right, Mono.offHand.aim.orientation * Vec3.Up) + 1) / 2;
pos = Mono.mainHand.aim.position + Mono.mainHand.aim.orientation * calibQuat * Vec3.Forward * calibStr * twist;
model.Draw(Matrix.TS(pos, 0.06f));
}
}
public class TankCursor : SpatialCursor {
public void Step() {
pos = Vec3.Zero;
rot = Quat.Identity;
model.Draw(Matrix.TS(pos, 0.06f));
}
}

4
oriels.bat Normal file
View file

@ -0,0 +1,4 @@
dotnet build
pause
cd bin/Debug/netcoreapp3.1/
oriels.exe

View file

@ -18,10 +18,12 @@
<ItemGroup>
<None Remove="Assets/example.hlsl" />
<None Remove="Assets/oriel.hlsl" />
</ItemGroup>
<ItemGroup>
<SKShader Include="Assets/example.hlsl" />
<SKShader Include="Assets/oriel.hlsl" />
</ItemGroup>
</Project>