Author:ptrace
Comitter:ptrace
Date:2026-06-17 00:20:13 UTC
diff --git a/README.md b/README.md
index e69de29..4446b87 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,4 @@
# Smol Tree Viewer
Still WIP. I'm using it to debug BVHs or 'Dynamic AABB Trees'.
diff --git a/src/main.jai b/src/main.jai
index a075bb7..c280881 100644
--- a/src/main.jai
+++ b/src/main.jai
@@ -18,12 +18,12 @@
/** Ideas / Todo
- Second option for visualizing the tree -> https://en.wikipedia.org/wiki/Hyperbolic_tree
- Different font
- Hot reload a binary dump
- Update the binary dump
- Generic approach for other types of info data in the tooltip
- Smooth zoom (maybe)
- Second option for visualizing the tree -> https://en.wikipedia.org/wiki/Hyperbolic_tree
*/
@@ -113,37 +113,12 @@ Statistics :: struct {
SetTraceLogLevel(.LOG_NONE);
SetConfigFlags(.FLAG_MSAA_4X_HINT);
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Template");
defer CloseWindow();
SetTargetFPS(60);
for rects array_add(*bvs, make_aabb(it));
log_vars(bvs.count-1);
array_add(*tree, NODE_INTERNAL, 0, 1);
for i: 2..bvs.count-1 {
// Find sibling
id := find_best_sibling(i);
// log_vars(id);
// Insert
tree_split_node(id, i);
//! log_vars(tree);
// Refit
}
tree_build();
tree_copy := array_copy(tree);
log_vars(tree_copy);
state_vtree: State;
state_htree: State;
state_cells: State;
stats_vtree: Statistics;
stats_htree: Statistics;
stats_cells: Statistics;
@@ -152,29 +127,34 @@ Statistics :: struct {
htree_init(tree_copy, *stats_htree);
cells_init(tree_copy, *stats_cells);
{
state_cells: State; {
using state_cells;
id = .CELLS;
camera = cells_fit_zoom();
}
{
state_htree: State; {
using state_htree;
id = .HYPER_TREE;
camera = htree_fit_zoom();
}
{
state_vtree: State; {
using state_vtree;
id = .TRAD_TREE;
camera = vtree_fit_zoom();
}
state_init(mode, state_vtree, state_htree, state_cells);
state_init(mode, state_vtree, state_htree, state_cells);
gui_init();
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Template");
defer CloseWindow();
SetTargetFPS(60);
push_allocator(temp);
while !WindowShouldClose() {
frame_time = GetFrameTime();
@@ -231,28 +211,44 @@ Statistics :: struct {
} else main :: () {
log("Offline");
for rects array_add(*bvs, make_aabb(it));
tree_build();
log("-------------------");
log_vars(tree);
//! tree_debug_view();
}
tree_build :: () {
for rects array_add(*bvs, make_aabb(it));
log_vars(bvs.count-1);
array_add(*tree, NODE_INTERNAL, 0, 1);
log_vars(tree);
for i: 2..bvs.count-1 {
// Find sibling
id := find_best_sibling(i);
log_vars(id);
// log_vars(id);
// Insert
tree_split_node(id, i);
log_vars(tree);
//! log_vars(tree);
// Refit
}
}
log("-------------------");
log_vars(tree);
//! tree_debug_view();
tree_split_node :: (index: int, left: int) {
i_left, i_right := tree_get_ids(index);
while tree.count <= i_right {
array_add(*tree, NODE_EMPTY);
}
tree[i_left] = left;
tree[i_right] = tree[index];
tree[index] = NODE_INTERNAL;
//! tree.data[index] -> refit bv
}
find_best_sibling :: (id: int) -> id: int {
@@ -275,19 +271,6 @@ find_best_sibling :: (id: int) -> id: int {
return best_sibling;
}
tree_split_node :: (index: int, left: int) {
i_left, i_right := tree_get_ids(index);
while tree.count <= i_right {
array_add(*tree, NODE_EMPTY);
}
tree[i_left] = left;
tree[i_right] = tree[index];
tree[index] = NODE_INTERNAL;
// tree.data[index] -> refit bv
}
tree_access_node :: (index: int) -> Node {
node: Node;