using System.Collections.Generic; using StereoKit; namespace snake; static class Arts { static Model assets_model = Model.FromFile("meshes/assets.glb", Shader.Unlit); static Dictionary meshes = new(); static Material mat_mono = new Material("mono.hlsl"); static Material mat_unlit = new Material("unlit.hlsl"); static Material mat_backbox = new Material("backbox.hlsl"); static Quat food_ori = Quat.Identity; public static void Init() { foreach (ModelNode node in assets_model.Nodes) { if (node.Mesh != null) { meshes.Add(node.Name, node.Mesh); } } mat_backbox.Transparency = Transparency.Add; mat_backbox.FaceCull = Cull.Front; } public static void Frame() { // background if (Device.DisplayBlend == DisplayBlend.Opaque) { } // fullstick Mesh.Sphere.Draw( mat_unlit, Matrix.TS( Mono.r_con_stick.position, 5 * U.mm ), Color.White ); Lines.Add( Mono.r_con_stick.position + V.XYZ(0, 0, 0), Mono.r_con_stick.position + Mono.fullstick * U.cm, Color.White, 2 * U.mm ); // box Hierarchy.Push(Mono.box_pose.ToMatrix(Mono.box_scale)); meshes["InsideOut"].Draw(mat_unlit, Matrix.Identity); meshes["Corrugation"].Draw(mat_unlit, Matrix.Identity); meshes["Corrugation"].Draw(mat_backbox, Matrix.Identity); // snake float fall_t = 0.0f; if (Mono.snake_fall.state) { // if (Mono.snake_fall.delta == +1) // start falling fall_t = 1.0f - (float)Mono.step_t; } Vec3 fall = V.XYZ(0, fall_t, 0); bool food_next = (Mono.snake[0] + Mono.snake_dir) == Mono.food; if (!food_next) { meshes["Tongue"].Draw( mat_mono, Matrix.TRS( Mono.snake[0].ToVec3 + fall, Quat.LookDir(Mono.fullstick), V.XYZ(1, 1, 0.666f + Maths.smooth_stop((float)Mono.step_t) * 0.333f) ) ); } string face = food_next ? "Face1Eat" : "Face0Default"; meshes[face].Draw( mat_mono, Matrix.TRS( Mono.snake[0].ToVec3 + fall, Quat.LookDir(Mono.snake_dir.ToVec3), V.XYZ(1, 1, 1)// * (float)(Mono.step_t)) ) ); for (int i = 1; i < Mono.snake_len; i++) { float scale = 1.0f; if ((int)((Time.Total - Mono.eat_timestamp) * Mono.snake_len / Mono.step_step) == i) { scale = 1.1f; } meshes["Segment"].Draw( mat_mono, Matrix.TRS( Mono.snake[i].ToVec3 + fall, Quat.LookAt(Mono.snake[i].ToVec3, Mono.snake[i - 1].ToVec3), scale ) ); } // holes foreach (KeyValuePair hole in Mono.holes) { meshes["Hole"].Draw( mat_unlit, Matrix.TRS( hole.Key.ToVec3, Quat.LookDir(hole.Value.ToVec3), 1 ) ); } // food float food_fall_t = 0.0f; if (Mono.food_fall.state) { // if (Mono.food_fall.delta == +1) // start falling food_fall_t = 1.0f - (float)Mono.step_t; } if (!food_next) { food_ori *= Quat.FromAngles( 90 * Time.Stepf, 30 * Time.Stepf, 10 * Time.Stepf ); } meshes["Food"].Draw( mat_mono, Matrix.TR( Mono.food.ToVec3 + V.XYZ(0, food_fall_t, 0), food_ori ) ); Hierarchy.Pop(); // for (int sx = -Mono.head_fill.Xslen; Mono.head_fill.InX(sx); sx++) // { // for (int sy = -Mono.head_fill.Yslen; Mono.head_fill.InY(sy); sy++) // { // for (int sz = -Mono.head_fill.Zslen; Mono.head_fill.InZ(sz); sz++) // { // Vec3 pos = Mono.box_pose.ToMatrix(U.cm) * V.XYZ(sx, sy, sz); // Text.Add( // (Mono.head_fill[new XYZi(sx, sy, sz)] + Mono.tail_fill[new XYZi(sx, sy, sz)]).ToString(), // Matrix.TRS( // pos, // Quat.LookAt(pos, Input.Head.position), // 0.1f // ) // ); // } // } // } } }