Mtree (previously Modular Tree) is a library for making 3d trees. It comes as an addon for blender but the c++ library can be used separately.
Go to the latest release. Under Assets, select the version corresponding to your os.
Follow the blender documentation to install the downloaded addon.
- Cmake
- Blender 2.93 or higher (if you want to to develop the blender addon)
- Clone the repository reccursively
git clone --recursive https://github.com/MaximeHerpin/modular_tree - Execute the
build_mtreebash script corresponding to your platform. - If all went well, a cmake project has been generated under
mtree/build. - You can bundle the blender addon by calling the addon bundling script.
A Tree is generated by executing a succession of TreeFunction. When being executed, a TreeFunction modifies the structure of the tree, and then calls children functions recursively.
For example, a basic tree has a trunk and branches on the trunk. Such a tree can be generated as such:
auto trunk = std::make_shared<TrunkFunction>();
auto branches = std::make_shared<BranchFunction>();
trunk->add_child(branches); // branches are added on top of the trunk
Tree tree(trunk);
tree.execute_functions(); // The tree structure is generated
ManifoldMesher mesher; // A mesher is responsible of converting a tree into a 3d mesh. The ManifoldMesher ensures a smooth topology
mesher.radial_resolution = 32;
Mesh tree_mesh = mesher.mesh_tree(tree); // the resulting mesh contains the geometry of the tree in the form of vertices and trianglesA second layer of branches can be grown on top of the branches by adding another branch function as a child of the first branch function:
auto branches_primary = std::make_shared<BranchFunction>();
auto branches_secondary = std::make_shared<BranchFunction>();
branches_primary.add_child(branches_secondary); // the secondray branches will be distributed on top of the primary branchesSome trees have healthy branches as well as a layer of thin dead branches along the trunk. This can be achieved by adding to branch functions with different parameters on the trunk:
auto trunk = std::make_shared<TrunkFunction>();
auto branches_healthy = std::make_shared<BranchFunction>();
auto branches_dead = std::make_shared<BranchFunction>();
branches_dead.length = RandomProperty{.1f,1f}; // dead branches will have a length between 10cm and 1m.
branches_dead.start_radius = ConstantProperty{.05f}; // dead branches will have a radius equal to 5% of the parent nodes
trunk->add_child(branches_healthy); // both sets of branches are grown on top of the trunk
trunk->add_child(branches_dead);
Tree tree(trunk);Blender being under the GPL license, the blender addon (all files under python_classes as well as __init__.py) is under the GPLv3 license.
The Mtree library is under the MIT license.