9 std::vector<uint> UUID_trunk_plant, UUID_branch_plant;
10 std::vector<std::vector<uint>> UUID_leaf_plant;
12 std::uniform_real_distribution<float> unif_distribution;
16 std::vector<float> rad_main;
17 std::vector<vec3> pos_main;
19 float dz = params.trunk_height / 10.f;
20 for (
int i = 0; i < 10; i++) {
21 rad_main.push_back(params.trunk_radius * (9 - i) / 9.f);
22 pos_main.push_back(
make_vec3(0., 0., i * dz));
25 for (
uint i = 0; i < rad_main.size(); i++) {
26 pos_main.at(i) = pos_main.at(i) + origin;
29 UUID_trunk_plant = context->
addTube(params.wood_subdivisions, pos_main, rad_main, params.wood_texture_file.c_str());
33 int Nlevels = floor((params.trunk_height - params.base_height) / params.level_spacing);
35 for (
int i = 0; i < Nlevels - 1; i++) {
37 float vfrac = float(Nlevels - i - 1) / float(Nlevels - 1);
41 rcrown = params.crown_radius;
43 rcrown = fmax(1.f / 0.3 * vfrac * params.crown_radius, 0.2 * params.crown_radius);
47 float z = fmin(params.trunk_height, params.base_height + i * params.level_spacing * (1 +
getVariation(0.1f * params.level_spacing, generator)));
49 int Nbranches = fmax(4, params.branches_per_level * vfrac);
51 for (
int j = 0; j < Nbranches; j++) {
53 float phi = float(j) / float(Nbranches) * 2.f *
PI_F * (1 +
getVariation(0.1f, generator));
55 float theta = -0.15 *
PI_F;
58 std::vector<float> rad_branch;
59 std::vector<vec3> pos_branch;
63 float r = rcrown +
getVariation(0.1f * rcrown, generator);
65 pos_branch.push_back(origin +
make_vec3(0, 0, z));
66 pos_branch.push_back(origin +
make_vec3(r * sinf(phi) * cosf(theta), r * cosf(phi) * cosf(theta), z + r * sinf(theta)));
70 rad_branch.push_back(params.shoot_radius * vfrac);
71 rad_branch.push_back(0.1 * params.shoot_radius * vfrac);
75 U = context->
addTube(params.wood_subdivisions, pos_branch, rad_branch, params.wood_texture_file.c_str());
76 UUID_branch_plant.insert(UUID_branch_plant.end(), U.begin(), U.end());
78 for (
int k = 0; k < 2 * Nbranches; k++) {
80 float bfrac = float(k + 1) / float(2 * Nbranches);
85 std::vector<float> rad_subbranch;
86 std::vector<vec3> pos_subbranch;
91 pos_subbranch.push_back(base);
93 float l = fmax(0.1, 0.6 * rcrown);
96 float bangle = 0.2 *
PI_F;
102 pos_subbranch.push_back(base + bdir);
104 rad_subbranch.push_back(rbase);
105 rad_subbranch.push_back(0.1 * rbase);
111 int Nneedles = round(50 * l / (0.4 * params.crown_radius));
112 for (
int n = 0; n < Nneedles; n++) {
114 float nfrac = float(n + 1) / float(Nneedles);
120 vec3 norm = nbase - nbase_p;
127 float downangle = 0.2 *
PI_F;
138 UUID_trunk.push_back(UUID_trunk_plant);
139 UUID_branch.push_back(UUID_branch_plant);
140 UUID_leaf.push_back(UUID_leaf_plant);
141 std::vector<std::vector<std::vector<uint>>> UUID_fruit_plant;
142 UUID_fruit.push_back(UUID_fruit_plant);
144 return UUID_leaf.size() - 1;