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