载入中...
搜索中...
未找到
LSystem.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <string>
7#include <utility>
8#include <vector>
9
10namespace eve::procgen {
11
12class PointSet;
13
21 float sx = 0.f, sy = 0.f, sz = 0.f; // start
22 float ex = 0.f, ey = 0.f, ez = 0.f; // end
23 float r0 = 0.f, r1 = 0.f; // radius at start / end
24 int depth = 0; // bracket nesting at draw time
25 bool leaf = false; // foliage marker instead of a limb
26 float leafSize = 0.f; // foliage card size for leaf segments
27 float dx = 0.f, dy = 0.f, dz = 0.f; // turtle heading at a leaf marker
28};
29
32 std::vector<LSystemSegment> segments;
33 std::string derivation;
34 int leafCount = 0;
35};
36
56public:
58 LSystem();
59
61 void setAxiom(const std::string& axiom);
63 void addRule(char symbol, const std::string& production);
65 void addRules(char symbol, const std::vector<std::string>& productions, const std::vector<float>& weights);
67 void clearRules();
68
70 void setAngle(float degrees);
72 void setStep(float step);
74 void setIterations(int iterations);
76 void setSeed(uint32_t seed);
78 void setInitialHeading(float x, float y, float z);
80 void setBranchRadius(float radius);
82 void setBranchRadiusFalloff(float factor);
84 void setLeafSize(float size);
86 void setLeafSymbols(const std::string& symbols);
88 void setTropism(float x, float y, float z);
89
91 uint32_t getSeed() const;
93 int getIterations() const;
94
96 std::string derive() const;
98 void generate(LSystemResult& out) const;
100 void toPointSet(PointSet& out) const;
101
102private:
103 struct Vec3 {
104 float x = 0.f, y = 0.f, z = 0.f;
105 };
106 struct TurtleState {
107 Vec3 pos, heading, up;
108 int depth = 0;
109 };
110 using Rule = std::pair<std::string, float>; // production, weight
111
112 Vec3 rotate(const Vec3& v, const Vec3& axis, float angle) const;
113 void orthonormalize(Vec3& heading, Vec3& up) const;
114 void interpret(const std::string& word, LSystemResult& out) const;
115
116 std::string axiom_;
117 std::vector<Rule> rules_[256];
118 float angleDeg_ = 25.f;
119 float step_ = 1.f;
120 int iterations_ = 5;
121 uint32_t seed_ = 1;
122 Vec3 heading0_ = {0.f, 1.f, 0.f};
123 float branchRadius_ = 0.1f;
124 float radiusFalloff_ = 0.6f;
125 float leafSize_ = 0.4f;
126 bool leafChars_[256] = {};
127 Vec3 tropism_ = {0.f, 0.f, 0.f};
128};
129
130} // namespace eve::procgen
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float degrees
Definition CardTypes.cpp:35
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float v
HexVec3 up
float radius
std::uint32_t seed
Definition PointSet.cpp:807
float weights[3]
int iterations
Definition TreeMesh.cpp:311
float step
Definition TreeMesh.cpp:314
V3 heading
Definition TreeMesh.cpp:292
float size
Definition TreeMesh.cpp:156
std::uint32_t depth
float angle
General stochastic bracketed L-system engine.
Definition LSystem.h:55
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
std::string word
Full result of expanding an L-system grammar and tracing the turtle.
Definition LSystem.h:31
std::vector< LSystemSegment > segments
Definition LSystem.h:32
One drawn segment produced by an L-system turtle.
Definition LSystem.h:20