Skip to content

MaximeHerpin/modular_tree

Repository files navigation

Mtree

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.

Table of contents

Installation (blender addon)

Go to the latest release. Under Assets, select the version corresponding to your os.
Follow the blender documentation to install the downloaded addon.

Development

Dependencies

  • Cmake
  • Blender 2.93 or higher (if you want to to develop the blender addon)

Installation

  1. Clone the repository reccursively git clone --recursive https://github.com/MaximeHerpin/modular_tree
  2. Execute the build_mtree bash script corresponding to your platform.
  3. If all went well, a cmake project has been generated under mtree/build.
  4. You can bundle the blender addon by calling the addon bundling script.

Usage

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 triangles

A 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 branches

Some 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);

License

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.