colorcube ^-^
This commit is contained in:
parent
92a77db8d6
commit
8c7c2c5b43
4 changed files with 104 additions and 86 deletions
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
//--name = dofdev/colorcube
|
//--name = dofdev/colorcube
|
||||||
// float4 color;
|
// float4 color;
|
||||||
float _height;
|
float3 _pos;
|
||||||
float _ypos;
|
float _size;
|
||||||
|
|
||||||
struct vsIn {
|
struct vsIn {
|
||||||
float4 pos : SV_POSITION;
|
float4 pos : SV_POSITION;
|
||||||
|
@ -31,13 +31,16 @@ psIn vs(vsIn input, uint id : SV_InstanceID) {
|
||||||
|
|
||||||
o.uv = input.uv;
|
o.uv = input.uv;
|
||||||
o.color = input.col;
|
o.color = input.col;
|
||||||
float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1)));
|
// float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1)));
|
||||||
lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2;
|
// lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2;
|
||||||
o.color.rgb = o.color.rgb * lighting;
|
// o.color.rgb = o.color.rgb * lighting;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
float4 ps(psIn input) : SV_TARGET {
|
float4 ps(psIn input) : SV_TARGET {
|
||||||
input.color.r = 1;
|
// input.color.r = 1;
|
||||||
return input.color;
|
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
|
||||||
}
|
}
|
113
ColorCube.cs
113
ColorCube.cs
|
@ -2,75 +2,60 @@ using System;
|
||||||
using StereoKit;
|
using StereoKit;
|
||||||
|
|
||||||
class ColorCube {
|
class ColorCube {
|
||||||
static Shader shaderColorCube = Shader.FromFile("colorcube.hlsl");
|
static Mesh orb = Default.MeshSphere;
|
||||||
static Material orbMat = Default.MaterialUnlit.Copy();
|
static Mesh cube = Default.MeshCube;
|
||||||
static Model orb = new Model(Default.MeshSphere, orbMat);
|
static Material mat = new Material(Shader.FromFile("colorcube.hlsl"));
|
||||||
static Model colorCube = Model.FromFile("colorcube.glb", Shader.UIBox);
|
static Material unlit = Default.MaterialUnlit;
|
||||||
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * 1.25f);
|
public float thicc = 0.0025f;
|
||||||
|
public float ogSize = 0.05f;
|
||||||
public bool picker = true;
|
public float size = 0.05f;
|
||||||
public Color color = Color.White * 0.5f;
|
public Vec3 center = Vec3.Zero;
|
||||||
public float thickness {
|
public Vec3 p0 = Vec3.Zero;
|
||||||
set {
|
|
||||||
_thiccness = value;
|
public Color color = Color.White * 0.5f;
|
||||||
colorCube.RootNode.Material["border_size"] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float _thiccness = 0.01f;
|
|
||||||
|
|
||||||
public ColorCube() {
|
public ColorCube() {
|
||||||
SetColor(Vec3.Zero);
|
// SetColor(Vec3.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetColor(Vec3 axes) {
|
public void Step() {
|
||||||
Color col = Vec2Col(axes);
|
mat.SetVector("_pos", center);
|
||||||
orbMat["color"] = col;
|
mat.SetFloat("_size", size);
|
||||||
color = col;
|
Vec3 c = Vec3.One / 2;
|
||||||
}
|
float offset = (size / 2) - (thicc / 2);
|
||||||
Color Vec2Col(Vec3 vec) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Vec3 normalVec = vec;
|
Quat q = Quat.FromAngles(i * 90, 0, 0);
|
||||||
normalVec += Vec3.One * 0.5f;
|
cube.Draw(mat, Matrix.TS(center + q * new Vec3(0, offset, offset), new Vec3(size, thicc, thicc)));
|
||||||
return new Color(normalVec.x, normalVec.y, normalVec.z);
|
for (int j = -1; j <= 1; j+=2) {
|
||||||
}
|
Vec3 scale = q * new Vec3(thicc, size, thicc);
|
||||||
Vec3 Col2Vec(Color color) {
|
scale = new Vec3(Math.Abs(scale.x), Math.Abs(scale.y), Math.Abs(scale.z));
|
||||||
Vec3 colVec = new Vec3(color.r, color.g, color.b);
|
cube.Draw(mat, Matrix.TS(center + q * new Vec3(offset * j, 0, offset), scale));
|
||||||
colVec -= (Vec3.One * 0.5f);
|
}
|
||||||
return colVec;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Step(Matrix matrix) {
|
float thinn = thicc / 3;
|
||||||
colorCube.Draw(matrix);
|
// 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)
|
Vec3 col = (p00 + Vec3.One) / 2;
|
||||||
return;
|
color = new Color(col.x, col.y, col.z);
|
||||||
|
cube.Draw(unlit, Matrix.TS(p0s, Vec3.One * thicc * 2), color);
|
||||||
for (int h = 0; h < (int)Handed.Max; h++) {
|
cube.Draw(unlit, Matrix.TS(raw, Vec3.One * thicc), Color.White);
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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 *
|
56
Program.cs
56
Program.cs
|
@ -23,7 +23,7 @@ public class Mono {
|
||||||
public Vec3 dragStart, posStart;
|
public Vec3 dragStart, posStart;
|
||||||
public float railT;
|
public float railT;
|
||||||
|
|
||||||
Bounds[] blocks;
|
Block[] blocks;
|
||||||
|
|
||||||
Mesh ball = Default.MeshSphere;
|
Mesh ball = Default.MeshSphere;
|
||||||
Material mat = Default.Material;
|
Material mat = Default.Material;
|
||||||
|
@ -38,10 +38,10 @@ public class Mono {
|
||||||
Oriel oriel = new Oriel();
|
Oriel oriel = new Oriel();
|
||||||
oriel.Start();
|
oriel.Start();
|
||||||
|
|
||||||
blocks = new Bounds[] {
|
blocks = new Block[] {
|
||||||
new Bounds(new Vec3(-1, 0, -4), Vec3.One * 0.5f),
|
new Block(new Bounds(new Vec3(-1, 0, -4), Vec3.One * 0.5f), Color.White),
|
||||||
new Bounds(new Vec3(0, 0, -4), Vec3.One * 0.5f),
|
new Block(new Bounds(new Vec3(0, 0, -4), Vec3.One * 0.5f), Color.White),
|
||||||
new Bounds(new Vec3(1, 0, -4), Vec3.One * 0.5f),
|
new Block(new Bounds(new Vec3(1, 0, -4), Vec3.One * 0.5f), Color.White),
|
||||||
};
|
};
|
||||||
int blockIndex = -1;
|
int blockIndex = -1;
|
||||||
Vec3 blockOffset = Vec3.Zero;
|
Vec3 blockOffset = Vec3.Zero;
|
||||||
|
@ -49,10 +49,8 @@ public class Mono {
|
||||||
MonoNet net = new MonoNet(this);
|
MonoNet net = new MonoNet(this);
|
||||||
net.Start();
|
net.Start();
|
||||||
|
|
||||||
// ColorCube cube = new ColorCube();
|
ColorCube colorCube = new ColorCube();
|
||||||
// OrbitalView.strength = 4;
|
Vec3 oldSubPos = Vec3.Zero;
|
||||||
// OrbitalView.distance = 0.4f;
|
|
||||||
// cube.thickness = 0.01f;
|
|
||||||
|
|
||||||
while (SK.Step(() => {
|
while (SK.Step(() => {
|
||||||
if (lefty) { domCon = Input.Controller(Handed.Left); subCon = Input.Controller(Handed.Right); }
|
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;
|
// 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);
|
// Solid solid = new Solid(Vec3.Up * -2, Quat.Identity, SolidType.Immovable);
|
||||||
// make some blocks you can move around with cursor.p0
|
// make some blocks you can move around with cursor.p0
|
||||||
// no collision detection, just a visual example
|
// no collision detection, just a visual example
|
||||||
if (domCon.grip > 0.5f) {
|
if (domCon.grip > 0.5f) {
|
||||||
if (blockIndex < 0) {
|
if (blockIndex < 0) {
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
if (blocks[i].Contains(cursor.p0)) {
|
if (blocks[i].bounds.Contains(cursor.p0)) {
|
||||||
blockIndex = i;
|
blockIndex = i;
|
||||||
blockOffset = cursor.p0 - blocks[i].center;
|
blockOffset = cursor.p0 - blocks[i].bounds.center;
|
||||||
|
blocks[i].color = colorCube.color;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
blocks[blockIndex].center = cursor.p0 - blockOffset;
|
blocks[blockIndex].bounds.center = cursor.p0 - blockOffset;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
blockIndex = -1;
|
blockIndex = -1;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
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();
|
// 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 class Mic {
|
||||||
public float[] bufferRaw = new float[0];
|
public float[] bufferRaw = new float[0];
|
||||||
public int bufferRawSize = 0;
|
public int bufferRawSize = 0;
|
||||||
|
|
|
@ -29,8 +29,8 @@ movement:
|
||||||
- ~~teleport and drag~~
|
- ~~teleport and drag~~
|
||||||
- ~~bezier rails~~
|
- ~~bezier rails~~
|
||||||
|
|
||||||
blocks you can manipulate with spatial cursors (trackballer)
|
~~blocks you can manipulate with spatial cursors~~ (trackballer)
|
||||||
and color them with the color cube (player colors
|
color them with the color cube (player colors
|
||||||
|
|
||||||
oriel + orbital view (control a shooty guy with fullstick and spatial cursor)
|
oriel + orbital view (control a shooty guy with fullstick and spatial cursor)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue