12 float dx = 1.f / float(Nx);
13 float dy = 0.5f / float(Ny);
15 std::uniform_real_distribution<float> unif_distribution;
17 std::vector<uint> UUIDs;
19 float fold = 0.1 *
PI_F;
21 for (
int i = 0; i < Nx; i++) {
22 for (
int j = 0; j < Ny; j++) {
29 mag = sqrt(x * x + 2 * y * y);
33 mag = sqrt((x + dx) * (x + dx) + 2 * y * y);
35 vec3 v1(x + dx, y, z);
37 mag = sqrt((x + dx) * (x + dx) + 2 * (y + dy) * (y + dy));
38 z = (y + dy) * sinf(fold);
39 vec3 v2(x + dx, y + dy, z);
41 mag = sqrt(x * x + 2 * (y + dy) * (y + dy));
42 z = (y + dy) * sinf(fold);
43 vec3 v3(x, y + dy, z);
45 vec2 uv0(x, 0.5 + j * dy);
46 vec2 uv1(x + dx, 0.5 + j * dy);
47 vec2 uv2(x + dx, 0.5 + (j + 1) * dy);
48 vec2 uv3(x, 0.5 + (j + 1) * dy);
60 uv2 =
make_vec2(x + dx, 0.5 - (j + 1) * dy);
84 std::vector<vec3> position;
85 std::vector<float> radius;
108 for (
int i = 0; i < Nsegs; i++) {
110 position.push_back(
spline_interp3(
float(i) /
float(Nsegs - 1), p_start, tan_start, p_end, tan_end));
112 radius.push_back(r_start +
float(i) /
float(Nsegs - 1) * (r_end - r_start));
115 radius.front() *= 1.3;
122void branchRecursion(
const std::vector<vec3> position_parent,
const std::vector<float> radius_parent,
uint level,
uint max_levels,
const std::vector<uint> leaf_prototype,
const std::vector<uint> nut_prototype, std::vector<uint> &UUID_branch_plant,
123 std::vector<std::vector<uint>> &UUID_leaf_plant, std::vector<std::vector<uint>> &UUID_fruit_plant,
const WalnutCanopyParameters params, std::minstd_rand0 generator,
Context *context) {
125 std::uniform_real_distribution<float> unif_distribution;
127 if (level > max_levels) {
131 for (
int i = 0; i < Nleaves; i++) {
133 float u = 0.3 + 0.7 * float(i) / float(Nleaves - 1);
146 std::vector<uint> UUIDs = context->
copyPrimitive(leaf_prototype);
147 UUID_leaf_plant.push_back(UUIDs);
158 UUID_leaf_plant.push_back(UUIDs);
168 if (i == Nleaves - 1) {
171 UUID_leaf_plant.push_back(UUIDs);
188 float Rnut = unif_distribution(generator);
199 std::vector<uint> nut_UUIDs = context->
copyPrimitive(nut_prototype);
200 UUID_fruit_plant.push_back(nut_UUIDs);
208 std::vector<uint> nut_UUIDs = context->
copyPrimitive(nut_prototype);
209 UUID_fruit_plant.push_back(nut_UUIDs);
217 std::vector<uint> nut_UUIDs = context->
copyPrimitive(nut_prototype);
218 UUID_fruit_plant.push_back(nut_UUIDs);
235 }
else if (level == 2) {
238 }
else if (level == 3) {
250 float phi0 = 2 *
PI_F * unif_distribution(generator);
252 for (
int i = 0; i < Nbranch; i++) {
258 float u = fmin(1.f, 0.2 + 0.8 *
float(i + 1) /
float(Nbranch) +
getVariation(0.05f, generator));
281 float L1 = (0.5 + 0.5 * unif_distribution(generator)) * L;
282 float L2 = (0.5 + 0.5 * unif_distribution(generator)) * L;
286 float rbase2 = rbase1 * (0.4 + 0.6 * L2 / L);
287 rbase1 = rbase1 * (0.4 + 0.6 * L1 / L);
294 uint ID1 = addBranch(pbase, 0.5 * L1 * bnorm1, rbase1, pbase + pend1 * L1, L1 *
make_vec3(0, 0, 1.f +
getVariation(1, generator)), 0.15 * rbase1, 8, params, generator, context);
295 uint ID2 = addBranch(pbase, 0.5 * L2 * bnorm2, rbase2, pbase + pend2 * L2, L2 *
make_vec3(0, 0, 1.f +
getVariation(1, generator)), 0.15 * rbase2, 8, params, generator, context);
298 UUID_branch_plant.insert(UUID_branch_plant.end(), UUID.begin(), UUID.end());
300 UUID_branch_plant.insert(UUID_branch_plant.end(), UUID.begin(), UUID.end());
305 branchRecursion(pos_parent, rad_parent, level + 1, max_levels, leaf_prototype, nut_prototype, UUID_branch_plant, UUID_leaf_plant, UUID_fruit_plant, params, generator, context);
310 branchRecursion(pos_parent, rad_parent, level + 1, max_levels, leaf_prototype, nut_prototype, UUID_branch_plant, UUID_leaf_plant, UUID_fruit_plant, params, generator, context);
318 std::vector<uint> leaf_prototype = leafPrototype(params, generator, context);
320 std::vector<uint> nut_prototype = nutPrototype(params, context);
322 std::vector<uint> UUIDs;
323 std::vector<uint> UUID_branch_plant;
324 std::vector<std::vector<uint>> UUID_leaf_plant;
325 std::vector<std::vector<std::vector<uint>>> UUID_fruit_plant;
326 UUID_fruit_plant.resize(1);
328 std::uniform_real_distribution<float> unif_distribution;
340 branchRecursion(pos_trunk, rad_trunk, 1, 3, leaf_prototype, nut_prototype, UUID_branch_plant, UUID_leaf_plant, UUID_fruit_plant.front(), params, generator, context);
346 UUID_branch.push_back(UUID_branch_plant);
347 UUID_leaf.push_back(UUID_leaf_plant);
348 UUID_fruit.push_back(UUID_fruit_plant);
350 return UUID_leaf.size() - 1;