using System.Collections.Generic; using StereoKit; namespace slash; 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_both = new Material("unlit.hlsl"); static Material mat_backface = new Material("backface.hlsl"); static Material mat_justcolor = new Material("justcolor.hlsl"); static Material mat_slash = new Material("unlit.hlsl"); public static Vec3 shake = new(0, 0, 0); // static Quat spin_ori = Quat.Identity; public static Vec3 last_tip_pos = 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; mat_slash.FaceCull = Cull.None; } public static void Frame() { // Input.HandVisible(Handed.Max, false); // world Matrix m4_world = Mono.world_pose.ToMatrix(); Hierarchy.Push(m4_world); // mesh test meshes["Food"].Draw( mat_mono, Matrix.TRS( V.XYZ(0, 0, -1), Quat.Identity, 0.1f ) ); // bamboo Mesh.Cube.Draw( mat_unlit, Matrix.TS( V.XYZ(0, 1, -2), V.XYZ(0.1f, 2, 0.1f) ), Color.Hex(0xB9E7AFFF) ); // unit cube // Mesh.Cube.Draw( // mat_unlit, // Matrix.Identity, // Color.Hex(0x13180AFF).ToLinear() // ); // enemy Vec3 enemy_pos = V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 1.0f, 0.5f, -3.0f); float enemy_rad = 0.5f; Mesh.Sphere.Draw( mat_unlit, Matrix.TS(enemy_pos, enemy_rad * 2.0f), Color.Hex(0x13180AFF).ToLinear() ); // eyes // Mesh.Cube.Draw( // mat_unlit, // Rig.head.ToMatrix().Transform(), // Color.Hex(0x13180AFF).ToLinear() // ); // blade Mesh mesh = new(); Quat blade_ori = Rig.r_hld.orientation; Vec3 blade_pos = Rig.r_hld.position; Vec3 tip_pos = blade_pos + blade_ori * V.XYZ(0, 0, 1); mesh.SetData( new Vertex[] { new( blade_pos, V.XYZ(0,0,1)), new( tip_pos, V.XYZ(0,0,1)), new(last_tip_pos, V.XYZ(0,0,1)) }, new uint[] { 0, 1, 2 } ); mesh.Draw( mat_slash, Matrix.Identity, Color.Hex(0xF9BF05FF).ToLinear() ); last_tip_pos = Vec3.Lerp(last_tip_pos, tip_pos, Time.Stepf / 0.1f); // revolver Quat rvolv_ori = Rig.l_aim.orientation; Vec3 rvolv_pos = Rig.l_aim.position; Lines.Add( rvolv_pos, rvolv_pos + rvolv_ori * V.XYZ(0, 0, -10), Color.Hex(0xF9BF05FF).ToLinear(), U.cm ); if (true) // hit test { Vec3 hit_delta = rvolv_ori.Inverse * (enemy_pos - rvolv_pos); float flat_z = hit_delta.z; hit_delta.z = 0; float hit_mag = hit_delta.Magnitude; bool hit = hit_mag < enemy_rad; if (hit) { float hit_dist = flat_z + (Maths.smooth_stop((enemy_rad - hit_mag) / enemy_rad) * enemy_rad); Vec3 hit_pos = rvolv_pos + rvolv_ori * V.XYZ(0, 0, hit_dist); Mesh.Sphere.Draw( mat_unlit, Matrix.TS( hit_pos, 4 * U.cm ), Color.White ); if (Rig.btn_select.delta == +1) { VFX.Play(hit_pos); } } } // 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() ); } Hierarchy.Pop(); // 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(); } }