1 /** debug rendering utilities */ 2 3 module re.ng.diag.render; 4 5 import re.core; 6 import re.ecs; 7 import re.math; 8 import re.gfx; 9 static import raylib; 10 11 static class DebugRender { 12 public static Color debug_color = Colors.RED; 13 public static Color debug_color_mesh = Colors.BLACK; 14 public static Color debug_color_collider = Colors.GREEN; 15 16 public static void default_debug_render(Renderable2D renderable) { 17 import re.math.rectangle_ext; 18 import std.algorithm.comparison: max; 19 20 // draw bounding rectangle 21 raylib.DrawRectangleLinesEx(renderable.bounds, 1, debug_color); 22 // // draw center crosshair 23 // auto center = renderable.bounds.center; 24 // int crosshair_size = max(cast(int) (Core.default_resolution.x / 200), 1); 25 // raylib.DrawLineV(center + Vector2(-crosshair_size, 0), center + Vector2(crosshair_size, 0), debug_color); 26 // raylib.DrawLineV(center + Vector2(0, -crosshair_size), center + Vector2(0, crosshair_size), debug_color); 27 } 28 29 /// draw 3d bounding box 30 private static void draw_bounding_box(BoundingBox raw_box, ref Transform transform, Color color) { 31 import std.math : abs; 32 33 auto box = Bounds.calculate(raw_box, transform); 34 35 auto size = Vector3(abs(box.max.x - box.min.x), 36 abs(box.max.y - box.min.y), abs(box.max.z - box.min.z)); 37 38 auto center = Vector3(box.min.x + size.x / 2.0f, box.min.y + size.y / 2.0f, 39 box.min.z + size.z / 2.0f); 40 41 // TODO: we want something that supports transforms 42 43 raylib.DrawCubeWires(center, size.x, size.y, size.z, color); 44 } 45 46 // public static void default_debug_render(Renderable3D renderable) { 47 // auto comp = cast(Component) renderable; 48 // draw_bounding_box(renderable.bounds, comp.transform, debug_color); 49 // } 50 51 public static void default_debug_render(Renderable3D renderable, Model model) { 52 import re.phys.collider; 53 54 // default_debug_render(renderable); 55 auto comp = cast(Component) renderable; 56 raylib.DrawModelWiresEx(model, comp.transform.position, comp.transform.axis_angle.axis, 57 comp.transform.axis_angle.angle * C_RAD2DEG, comp.transform.scale, debug_color_mesh); 58 59 // check if renderable has colliders 60 auto box_colls = comp.entity.get_components!BoxCollider; 61 foreach (box; box_colls) { 62 auto raw_bounds = BoundingBox( // min 63 Vector3(-box.size.x + box.offset.x, 64 -box.size.y + box.offset.y, -box.size.z + box.offset.z), // max 65 Vector3(box.size.x + box.offset.x, box.size.y + box.offset.y, 66 box.size.z + box.offset.z)); 67 draw_bounding_box(raw_bounds, comp.entity.transform, debug_color_collider); 68 } 69 } 70 }