dofdemo/src/Arts.cs
2024-12-08 00:09:40 -05:00

190 lines
No EOL
5.3 KiB
C#

using System.Collections.Generic;
using StereoKit;
using StereoKit.Framework;
namespace dofdemo;
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");
static Material mat_justcolor = new Material("justcolor.hlsl");
static Material mat_colorcube = new Material("colorcube.hlsl");
static Material mat_colorcursor = new Material("justcolor.hlsl");
public static Vec3 shake = new(0, 0, 0);
static TextStyle text_style;
public static void Init()
{
foreach (ModelNode node in assets_model.Nodes)
{
if (node.Mesh != null)
{
meshes.Add(node.Name, node.Mesh);
}
}
text_style = TextStyle.FromFont(
Font.FromFile("Staatliches.ttf"),
1.0f * U.cm,
Color.White
);
mat_backface.FaceCull = Cull.Front;
mat_backface.Transparency = Transparency.Add;
mat_backface.DepthTest = DepthTest.LessOrEq;
mat_backface.DepthWrite = false;
mat_both.Chain = mat_backface;
// 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);
// }
// world
// Matrix m4_dof = Mono.dof_pose.ToMatrix(Mono.dof_scl);
// Hierarchy.Push(m4_dof);
// mesh test
// meshes["Food"].Draw(
// mat_mono,
// Matrix.TRS(
// V.XYZ(0, 0, -1),
// Quat.Identity,
// 0.1f
// )
// );
// unit cube
// Mesh.Cube.Draw(
// mat_unlit,
// Matrix.Identity,
// Color.Hex(0x13180AFF).ToLinear()
// );
//// dofs
// stretch_cursor
{
meshes["con"].Draw(
mat_mono,
Stretch.to_grab.pose.ToMatrix(1.5f * U.cm)
);
meshes["con"].Draw(
mat_mono,
Stretch.from_grab.pose.ToMatrix(1.5f * U.cm)
);
Mesh.Cube.Draw(
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[ColorCube.toggle ? "color_cube_toggle" : "color_cube"].Draw(
mat_colorcube,
ColorCube.grab.pose.ToMatrix(ColorCube.scl)
);
Hierarchy.Push(ColorCube.grab.pose.ToMatrix(ColorCube.scl));
// ColorCube.cursor render ontop *degree symbol with color inside
Mesh.Sphere.Draw(
mat_colorcursor,
Matrix.TS(
ColorCube.cursor,
24.0f * U.cm
),
Color.White
);
Mesh.Sphere.Draw(
mat_colorcursor,
Matrix.TS(
ColorCube.cursor,
16.0f * U.cm
),
ColorCube.color
);
Hierarchy.Pop();
}
// reach_cursor
{
}
// Hierarchy.Pop();
// particles
// Particle[] particles = VFX.particles;
// for (int i = 0; i < particles.Length; i++)
// {
// Particle particle = particles[i];
// meshes["FoodParticle"].Draw(
// mat_unlit,
// Matrix.TRS(
// particle.pos,
// particle.ori,
// particle.scl
// ),
// Color.Hex(0xC75A09FF).ToLinear()
// );
// }
// 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
// );
// }
// Hierarchy.Pop();
}
}