{"id":23162974,"url":"https://github.com/dimev/lodtree","last_synced_at":"2025-08-18T03:31:57.354Z","repository":{"id":62442389,"uuid":"398249818","full_name":"Dimev/lodtree","owner":"Dimev","description":"A simple rust library to help create octrees and quadtrees for chunked level of detail","archived":false,"fork":false,"pushed_at":"2023-06-01T07:18:01.000Z","size":315,"stargazers_count":20,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-12T12:43:32.958Z","etag":null,"topics":["lod","octree","quadtree"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dimev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-20T11:12:11.000Z","updated_at":"2025-02-25T23:37:39.000Z","dependencies_parsed_at":"2024-12-18T00:15:17.139Z","dependency_job_id":"d146448b-8136-4c62-a282-96290cb1676d","html_url":"https://github.com/Dimev/lodtree","commit_stats":{"total_commits":68,"total_committers":1,"mean_commits":68.0,"dds":0.0,"last_synced_commit":"0225a23974c14a9958cf964e25d8a658b95371e7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Dimev/lodtree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dimev%2Flodtree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dimev%2Flodtree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dimev%2Flodtree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dimev%2Flodtree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dimev","download_url":"https://codeload.github.com/Dimev/lodtree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dimev%2Flodtree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270940335,"owners_count":24671669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lod","octree","quadtree"],"created_at":"2024-12-18T00:15:11.832Z","updated_at":"2025-08-18T03:31:57.060Z","avatar_url":"https://github.com/Dimev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Documentation](https://docs.rs/lodtree/badge.svg)](https://docs.rs/lodtree)\n\n# LodTree\nLodTree, a simple tree data structure for doing chunk-based level of detail.\n\n## Goals\nThe aim of this crate is to provide a generic, easy to use tree data structure that can be used to make Quadtrees, Octrees and more for chunked level of detail.\n\nInternally, the tree tries to keep as much memory allocated, to avoid the cost of heap allocation, and stores the actual chunks data seperate from the tree data.\n \nThis does come at a cost. Mainly, only the chunks that are going to be added and their locations can be retreived as a slice, although for most (procedural) terrain implementations.\n\n## Non-goals\nBe a general-usage tree data structure for storing items at specific locations.\n\n## Features\n - Provides sets of chunks that need some action performed on them\n - Tries to avoid memory (re)allocations and moves\n - Stores chunks themselves in a contiguous array\n - Uses an internal chunk cache to allow reusing chunks at a memory tradeoff\n - Provides some extra iterators for finding chunks in certain bounds\n\n### Examples:\n - [rayon](examples/rayon.rs): shows how to use the tree with rayon to generate new chunks in parallel.\n - [glium](examples/glium.rs): shows how a basic drawing setup would work, with glium to do the drawing.\n\n## Usage:\nImport the crate\n```rust\nuse lodtree::*;\nuse lodtree::coords::OctVec; // or Quadvec if you're making an octree\n```\n\nThe tree is it's own struct, and accepts a chunk (anything that implements Sized) and the lod vector (Anything that implements the LodVec trait).\n```rust\nlet mut tree = Tree::\u003cChunk, OctVec\u003e::new();\n```\n\nIf you want to update chunks due to the camera being moved, you can check if it's needed with prepare_update.\nIt takes in 3 parameters.\n\nTargets: where to generate the most detail around.\n\nThe given LodVec implementations (OctVec and QuadVec) take in 4 and 3 arguments respectively.\nThe first 3/2 are the position in the tree, which is dependant on the lod level.\nand the last parameter is the lod level. No lods smaller than this will be generated for this target.\n\nDetail: The amount of detail for the targets\nThe default implementation defines this as the amount of chunks at the target lod level surrounding the target chunk.\n\nChunk creator:\nInternally a buffer for new chunks is filled, and this function is called to create the new chunk.\nIt takes in the LodVec of the position of the chunk.\n```rust\nlet needs_updating = tree.prepare_update(\n\t\u0026[OctVec(8, 8, 8, 8)], // the target positions to generate the lod around\n\t4, // amount of detail\n\t|pos| Chunk {} // and the function to construct the chunk with\n);\n```\n\nNow, the tree is ready for an update, so now we'll want to do something with that.\nFirst, we want to process all chunks that are going to be added.\nThis is the only thing the API exposes as a slice, so we can nicely iterate over that in parallel with rayon.\n```rust\ntree.get_chunks_to_add_slice_mut()\n\t.iter_mut() // or par_iter_mut if you're using rayon\n\t.for_each(|(position, chunk)| {\n\n\t\t// and run expensive init, probably does something with procedural generation\n\t\tchunk.expensive_init(*position);\n\t});\n```\n\nNext, we'll also want to change the visibility of some chunks so they don't overlap with higher detail lods.\n```rust\n// and make all chunks visible or not\nfor i in 0..tree.get_num_chunks_to_activate() {\n\ttree.get_chunk_to_activate_mut(i).set_visible(true);\n}\n\nfor i in 0..tree.get_num_chunks_to_deactivate() {\n\ttree.get_chunk_to_deactivate_mut(i).set_visible(false);\n}\n```\nWe'll probably also want to do some cleanup with chunks that are removed.\n```rust\nfor i in 0..tree.get_num_chunks_to_remove() {\n\ttree.get_chunk_to_remove_mut(i).cleanup();\n} \n```\nAnd finally, actually update the tree with the new chunks.\nNote that it's likely needed to do the prepare_update and do_update cycle a number of times before no new chunks need to be added, as the tree only adds one lod level at a time.\n```rust\ntree.do_update();\n```\nBut we're not done yet!\nAfter this step there's a number of chunks that are removed from the cache, and will not be added back into the tree\nWe'll want to clean those up now\n```rust\nfor (position, chunk) in tree.get_chunks_to_delete_slice_mut().iter_mut() {\n\tchunk.true_cleanup();\n}\n\n// and finally, complete the entire update\ntree.complete_update();\n```\n\n## Roadmap\n### 0.2.0:\n - Support getting \"edited\" chunks, via also passing along a region in which chunks would be edited. NEEDS DOCS AND TESTING\n - caching DONE\n - iterators for all chunk data accessing methods. DONE\n - getting a chunk by position DONE\n - swap L and C, so the key (position) is before the chunk, which is consistent with other key-value datatypes in rust\n### 0.3.0:\n - Replace the tree in favour of a list to generate all nodes up front, then use a hashmap for storage\n - this keeps everything in one map, with optional removal from that map. Also simplifies everything as there's only \"add\", \"add from cache\", \"remove to cache\" and \"remove entirely\" instead of the current add, add from cache, remove, merge, subdivide, and delete\n - no-std (although alloc will be required here)\n\n## License\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimev%2Flodtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimev%2Flodtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimev%2Flodtree/lists"}