diff --git a/Assets/colorcube.hlsl b/Assets/colorcube.hlsl index 7f04c33..362f1b9 100644 --- a/Assets/colorcube.hlsl +++ b/Assets/colorcube.hlsl @@ -2,8 +2,8 @@ //--name = dofdev/colorcube // float4 color; -float _height; -float _ypos; +float3 _pos; +float _size; struct vsIn { float4 pos : SV_POSITION; @@ -31,13 +31,16 @@ psIn vs(vsIn input, uint id : SV_InstanceID) { o.uv = input.uv; o.color = input.col; - float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1))); - lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2; - o.color.rgb = o.color.rgb * lighting; + // float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1))); + // lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2; + // o.color.rgb = o.color.rgb * lighting; return o; } float4 ps(psIn input) : SV_TARGET { - input.color.r = 1; - return input.color; + // input.color.r = 1; + float3 pos = input.world - _pos; + pos /= _size; + pos += float3(0.5, 0.5, 0.5); + return float4(pos.x, pos.y, pos.z, 1); // clamp values to 0..1 } \ No newline at end of file diff --git a/ColorCube.cs b/ColorCube.cs index 8930081..b0cd90d 100644 --- a/ColorCube.cs +++ b/ColorCube.cs @@ -2,75 +2,60 @@ using System; using StereoKit; class ColorCube { - static Shader shaderColorCube = Shader.FromFile("colorcube.hlsl"); - static Material orbMat = Default.MaterialUnlit.Copy(); - static Model orb = new Model(Default.MeshSphere, orbMat); - static Model colorCube = Model.FromFile("colorcube.glb", Shader.UIBox); - Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * 1.25f); - - public bool picker = true; - public Color color = Color.White * 0.5f; - public float thickness { - set { - _thiccness = value; - colorCube.RootNode.Material["border_size"] = value; - } - } - float _thiccness = 0.01f; + static Mesh orb = Default.MeshSphere; + static Mesh cube = Default.MeshCube; + static Material mat = new Material(Shader.FromFile("colorcube.hlsl")); + static Material unlit = Default.MaterialUnlit; + public float thicc = 0.0025f; + public float ogSize = 0.05f; + public float size = 0.05f; + public Vec3 center = Vec3.Zero; + public Vec3 p0 = Vec3.Zero; + + public Color color = Color.White * 0.5f; public ColorCube() { - SetColor(Vec3.Zero); + // SetColor(Vec3.Zero); } - void SetColor(Vec3 axes) { - Color col = Vec2Col(axes); - orbMat["color"] = col; - color = col; - } - Color Vec2Col(Vec3 vec) { - Vec3 normalVec = vec; - normalVec += Vec3.One * 0.5f; - return new Color(normalVec.x, normalVec.y, normalVec.z); - } - Vec3 Col2Vec(Color color) { - Vec3 colVec = new Vec3(color.r, color.g, color.b); - colVec -= (Vec3.One * 0.5f); - return colVec; - } + public void Step() { + mat.SetVector("_pos", center); + mat.SetFloat("_size", size); + Vec3 c = Vec3.One / 2; + float offset = (size / 2) - (thicc / 2); + for (int i = 0; i < 4; i++) { + Quat q = Quat.FromAngles(i * 90, 0, 0); + cube.Draw(mat, Matrix.TS(center + q * new Vec3(0, offset, offset), new Vec3(size, thicc, thicc))); + for (int j = -1; j <= 1; j+=2) { + Vec3 scale = q * new Vec3(thicc, size, thicc); + scale = new Vec3(Math.Abs(scale.x), Math.Abs(scale.y), Math.Abs(scale.z)); + cube.Draw(mat, Matrix.TS(center + q * new Vec3(offset * j, 0, offset), scale)); + } + } - public void Step(Matrix matrix) { - colorCube.Draw(matrix); + float thinn = thicc / 3; + // Vec3 p0s = pos + new Vec3((float)Math.Sin(Time.Totalf) * offset, (float)Math.Sin(Time.Totalf* 2) * offset, (float)Math.Sin(Time.Totalf * 4) * offset); + Vec3 raw = center + (p0 * offset); + Vec3 p00 = p0; + p00.x = Math.Clamp(p00.x, -1, 1); + p00.y = Math.Clamp(p00.y, -1, 1); + p00.z = Math.Clamp(p00.z, -1, 1); + Vec3 p0s = center + (p00 * offset); + cube.Draw(mat, Matrix.TS(new Vec3(center.x, p0s.y, p0s.z), new Vec3(size, thinn, thinn))); + cube.Draw(mat, Matrix.TS(new Vec3(p0s.x, center.y, p0s.z), new Vec3(thinn, size, thinn))); + cube.Draw(mat, Matrix.TS(new Vec3(p0s.x, p0s.y, center.z), new Vec3(thinn, thinn, size))); - if(!picker) - return; - - for (int h = 0; h < (int)Handed.Max; h++) { - // Get the pose for the index fingertip - Hand hand = Input.Hand((Handed)h); - Pose fingertip = hand[FingerId.Index, JointId.Tip].Pose; - - Vec3 localFingerPos = matrix.Inverse * fingertip.position; - if(hand.IsPinched && bounds.Contains(localFingerPos)) { - localFingerPos.x = Math.Clamp(localFingerPos.x, -0.5f, 0.5f); - localFingerPos.y = Math.Clamp(localFingerPos.y, -0.5f, 0.5f); - localFingerPos.z = Math.Clamp(localFingerPos.z, -0.5f, 0.5f); - SetColor(localFingerPos); - } - } - - Vec3 orbPos = Col2Vec(color); - - Lines.Add(matrix * new Vec3(-0.5f, orbPos.y, orbPos.z), matrix * new Vec3(0.5f, orbPos.y, orbPos.z), new Color(0, color.g, color.b), new Color(1, color.g, color.b), _thiccness); - Lines.Add(matrix * new Vec3(orbPos.x, -0.5f, orbPos.z), matrix * new Vec3(orbPos.x, 0.5f, orbPos.z), new Color(color.r, 0, color.b), new Color(color.r, 1, color.b), _thiccness); - Lines.Add(matrix * new Vec3(orbPos.x, orbPos.y, -0.5f), matrix * new Vec3(orbPos.x, orbPos.y, 0.5f), new Color(color.r, color.g, 0), new Color(color.r, color.g, 1), _thiccness); - - orb.Draw(Matrix.TS(matrix * orbPos, _thiccness * 2)); - - PullRequest.BoundsDraw(bounds, _thiccness, Color.White); - - // can't change shader lol - // Default.MaterialUnlit.Shader = shaderColorCube; - // Rods time it is! - // spatialize the stereokit line shader + Vec3 col = (p00 + Vec3.One) / 2; + color = new Color(col.x, col.y, col.z); + cube.Draw(unlit, Matrix.TS(p0s, Vec3.One * thicc * 2), color); + cube.Draw(unlit, Matrix.TS(raw, Vec3.One * thicc), Color.White); } } + + +// everyone get their own color cube? * held in sub hand * +// or just one? +// or context sensitive? +// can it be networked effectively? well its just a bounds with a shader and cursor, should be easy enough :) + +// set your color and when you move blocks around, it changes the color of the blocks * you leave your mark * \ No newline at end of file diff --git a/Program.cs b/Program.cs index f222e1a..2d23119 100644 --- a/Program.cs +++ b/Program.cs @@ -23,7 +23,7 @@ public class Mono { public Vec3 dragStart, posStart; public float railT; - Bounds[] blocks; + Block[] blocks; Mesh ball = Default.MeshSphere; Material mat = Default.Material; @@ -38,10 +38,10 @@ public class Mono { Oriel oriel = new Oriel(); oriel.Start(); - blocks = new Bounds[] { - new Bounds(new Vec3(-1, 0, -4), Vec3.One * 0.5f), - new Bounds(new Vec3(0, 0, -4), Vec3.One * 0.5f), - new Bounds(new Vec3(1, 0, -4), Vec3.One * 0.5f), + blocks = new Block[] { + new Block(new Bounds(new Vec3(-1, 0, -4), Vec3.One * 0.5f), Color.White), + new Block(new Bounds(new Vec3(0, 0, -4), Vec3.One * 0.5f), Color.White), + new Block(new Bounds(new Vec3(1, 0, -4), Vec3.One * 0.5f), Color.White), }; int blockIndex = -1; Vec3 blockOffset = Vec3.Zero; @@ -49,10 +49,8 @@ public class Mono { MonoNet net = new MonoNet(this); net.Start(); - // ColorCube cube = new ColorCube(); - // OrbitalView.strength = 4; - // OrbitalView.distance = 0.4f; - // cube.thickness = 0.01f; + ColorCube colorCube = new ColorCube(); + Vec3 oldSubPos = Vec3.Zero; while (SK.Step(() => { if (lefty) { domCon = Input.Controller(Handed.Left); subCon = Input.Controller(Handed.Right); } @@ -114,26 +112,48 @@ public class Mono { } // pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f; + // reveal when palm up + float reveal = subCon.pose.Right.y * 2; + colorCube.size = colorCube.ogSize * Math.Clamp(reveal, 0, 1); + colorCube.center = subCon.pose.position + subCon.pose.Right * 0.0666f; + // move with grip + if (reveal > colorCube.thicc) { + if (reveal > 1f && subCon.grip > 0.5f) { + colorCube.p0 -= (subCon.pose.position - oldSubPos) / colorCube.ogSize * 2; + } else { + // clamp 0 - 1 + colorCube.p0.x = Math.Clamp(colorCube.p0.x, -1, 1); + colorCube.p0.y = Math.Clamp(colorCube.p0.y, -1, 1); + colorCube.p0.z = Math.Clamp(colorCube.p0.z, -1, 1); + } + colorCube.Step(); + } + oldSubPos = subCon.pose.position; + + // how to extend the buttons!!! as we only have 2 T-T + + // BLOCKS // Solid solid = new Solid(Vec3.Up * -2, Quat.Identity, SolidType.Immovable); // make some blocks you can move around with cursor.p0 // no collision detection, just a visual example if (domCon.grip > 0.5f) { if (blockIndex < 0) { for (int i = 0; i < blocks.Length; i++) { - if (blocks[i].Contains(cursor.p0)) { + if (blocks[i].bounds.Contains(cursor.p0)) { blockIndex = i; - blockOffset = cursor.p0 - blocks[i].center; + blockOffset = cursor.p0 - blocks[i].bounds.center; + blocks[i].color = colorCube.color; break; } } } else { - blocks[blockIndex].center = cursor.p0 - blockOffset; + blocks[blockIndex].bounds.center = cursor.p0 - blockOffset; } } else { blockIndex = -1; } for (int i = 0; i < blocks.Length; i++) { - cube.Draw(mat, Matrix.TS(blocks[i].center, blocks[i].dimensions)); + cube.Draw(mat, Matrix.TS(blocks[i].bounds.center, blocks[i].bounds.dimensions), blocks[i].color); } // cursor.Step(lHand.aim, rHand.aim); cursor.DrawSelf(); @@ -165,6 +185,16 @@ public class Mono { } } +public class Block { + public Bounds bounds; + public Color color; + + public Block(Bounds bounds, Color color) { + this.bounds = bounds; + this.color = color; + } +} + public class Mic { public float[] bufferRaw = new float[0]; public int bufferRawSize = 0; diff --git a/README.md b/README.md index 657a5f2..45f5efb 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ movement: - ~~teleport and drag~~ - ~~bezier rails~~ -blocks you can manipulate with spatial cursors (trackballer) -and color them with the color cube (player colors +~~blocks you can manipulate with spatial cursors~~ (trackballer) +color them with the color cube (player colors oriel + orbital view (control a shooty guy with fullstick and spatial cursor)