The Weber-Penn Tree plugin provides procedural tree generation using the Weber-Penn modeling algorithms. This documentation is based on the actual implementation.
Overview
The WeberPennTree class generates realistic tree structures for various fruit and nut tree species using scientifically-based algorithms.
Basic Usage
from pyhelios import Context, WeberPennTree, WPTType
context = Context()
wpt = WeberPennTree(context)
tree_id = wpt.buildTree(WPTType.LEMON)
tree_id = wpt.buildTree(
wpt_type=WPTType.APPLE,
origin=vec3(5, 10, 0),
scale=1.5
)
print(f"Generated tree with ID: {tree_id}")
Available Tree Types
The actual tree types available in PyHelios (from WPTType enum):
available_types = [
WPTType.ALMOND,
WPTType.APPLE,
WPTType.AVOCADO,
WPTType.LEMON,
WPTType.OLIVE,
WPTType.ORANGE,
WPTType.PEACH,
WPTType.PISTACHIO,
WPTType.WALNUT
]
for tree_type in available_types:
tree_id = wpt.buildTree(tree_type)
print(f"Generated {tree_type.value} tree: ID {tree_id}")
Tree Component Queries
Get UUIDs for different parts of generated trees:
tree_id = wpt.buildTree(WPTType.OLIVE)
trunk_uuids = wpt.getTrunkUUIDs(tree_id)
branch_uuids = wpt.getBranchUUIDs(tree_id)
leaf_uuids = wpt.getLeafUUIDs(tree_id)
all_tree_uuids = wpt.getAllUUIDs(tree_id)
print(f"Tree {tree_id} components:")
print(f" Trunk primitives: {len(trunk_uuids)}")
print(f" Branch primitives: {len(branch_uuids)}")
print(f" Leaf primitives: {len(leaf_uuids)}")
print(f" Total primitives: {len(all_tree_uuids)}")
Tree Customization
Control the generation parameters before building trees:
wpt.setBranchRecursionLevel(4)
wpt.setTrunkSegmentResolution(8)
wpt.setBranchSegmentResolution(6)
wpt.setLeafSubdivisions(3, 3)
tree_id = wpt.buildTree(WPTType.LEMON)
Parameter Effects
- Branch Recursion Level: Controls tree complexity
- Level 1: Trunk only
- Level 2: Trunk + primary branches
- Level 3: Trunk + primary + secondary branches
- Level 4+: Additional levels of smaller branches
- Segment Resolution: Controls geometric smoothness
- Lower values (3-4): Coarse, angular geometry
- Higher values (8-12): Smooth, detailed geometry
- Leaf Subdivisions: Controls leaf detail
- (1,1): Simple rectangular leaves
- (3,3): More detailed leaf geometry with 9 patches per leaf
- (5,5): High detail leaves with 25 patches per leaf
Context Manager Usage
For proper resource cleanup:
with WeberPennTree(context) as wpt:
wpt.setBranchRecursionLevel(4)
tree_id = wpt.buildTree(WPTType.APPLE)
leaf_uuids = wpt.getLeafUUIDs(tree_id)
Multiple Tree Scenes
Generate multiple trees efficiently:
orchard_trees = []
tree_spacing = 4.0
for i in range(3):
for j in range(3):
x = i * tree_spacing
y = j * tree_spacing
position = vec3(x, y, 0)
tree_types = [WPTType.APPLE, WPTType.LEMON, WPTType.OLIVE]
tree_type = tree_types[(i + j) % 3]
import random
scale = 0.8 + 0.4 * random.random()
tree_id = wpt.buildTree(tree_type, position, scale)
orchard_trees.append(tree_id)
print(f"Generated orchard with {len(orchard_trees)} trees")
Tree Analysis
Analyze generated tree properties:
tree_id = wpt.buildTree(WPTType.OLIVE)
trunk_uuids = wpt.getTrunkUUIDs(tree_id)
branch_uuids = wpt.getBranchUUIDs(tree_id)
leaf_uuids = wpt.getLeafUUIDs(tree_id)
total_leaf_area = 0
for uuid in leaf_uuids:
area = context.getPrimitiveArea(uuid)
total_leaf_area += area
total_branch_volume = 0
for uuid in branch_uuids:
pass
print(f"Tree {tree_id} analysis:")
print(f" Total leaf area: {total_leaf_area:.2f} m²")
print(f" Number of leaves: {len(leaf_uuids)}")
print(f" Number of branches: {len(branch_uuids)}")
Integration with Other PyHelios Components
With Context Data Association
tree_id = wpt.buildTree(WPTType.LEMON)
leaf_uuids = wpt.getLeafUUIDs(tree_id)
for uuid in leaf_uuids:
context.setPrimitiveDataFloat(uuid, "temperature", 25.0)
context.setPrimitiveDataString(uuid, "tree_species", "lemon")
context.setPrimitiveDataInt(uuid, "tree_id", tree_id)
With Visualization
tree_id = wpt.buildTree(WPTType.OLIVE)
leaf_uuids = wpt.getLeafUUIDs(tree_id)
for uuid in leaf_uuids:
center = context.getPrimitiveCenter(uuid)
height = center.z
green_intensity = min(1.0, height / 5.0)
color = RGBcolor(0.2, green_intensity, 0.2)
all_tree_uuids = wpt.getAllUUIDs(tree_id)
context.colorPrimitiveByDataPseudocolor(
all_tree_uuids, "height", "viridis", 256
)
Error Handling
try:
wpt = WeberPennTree(context)
tree_id = wpt.buildTree(WPTType.LEMON)
except Exception as e:
print(f"Tree generation failed: {e}")
if not context.is_plugin_available('weberpenntree'):
print("WeberPennTree plugin not available")
print("Build with: build_scripts/build_helios --plugins weberpenntree")
Build Requirements
The WeberPennTree plugin is included in most PyHelios builds:
# Build with WeberPennTree plugin
build_scripts/build_helios --plugins weberpenntree
# Or use a profile that includes it
build_scripts/build_helios --plugins weberpenntree # WeberPennTree only
build_scripts/build_helios # Default build includes WeberPennTree
Performance Considerations
wpt.setBranchRecursionLevel(2)
wpt.setTrunkSegmentResolution(4)
wpt.setBranchSegmentResolution(3)
wpt.setLeafSubdivisions(1, 1)
simple_trees = []
for i in range(100):
tree_id = wpt.buildTree(WPTType.OLIVE)
simple_trees.append(tree_id)
This documentation covers the actual WeberPennTree implementation in PyHelios, verified against the wrapper code and example usage.