载入中...
搜索中...
未找到
ShapeGrammar.h
浏览该文件的文档.
1#pragma once
2
3#include "procgen/PointSet.h"
4
5#include <cstdint>
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10namespace eve::procgen {
11
14 std::string asset;
15 float length = 1.f;
16 float weight = 1.f;
17};
18
28public:
30 void clear();
32 bool addModule(const std::string& symbol, const std::string& asset, float length,
33 float weight = 1.f);
35 bool removeModule(const std::string& symbol);
37 bool hasModule(const std::string& symbol) const;
39 int getModuleCount() const;
41 std::string getModuleSymbol(int index) const;
43 int getVariantCount(const std::string& symbol) const;
45 std::string getVariantAsset(const std::string& symbol, int index) const;
47 float getVariantLength(const std::string& symbol, int index) const;
48
50 bool validate(const std::string& grammar);
56 PointSet* generate(const std::string& grammar, PointSet* controlPoints, uint32_t seed,
57 bool acceptIncomplete);
59 std::string getError() const;
61 std::string debugReport() const;
62
63private:
64 struct Element {
65 std::string symbol;
66 std::vector<Element> children;
67 int repeatMin = 1;
68 int repeatMax = 1; // -1 = fill available length
69 };
70 struct Parser {
71 const std::string& text;
72 size_t position = 0;
73 std::string error;
75 std::vector<Element> sequence(char terminator = '\0');
77 void skipWhitespace();
78 };
79
80 float elementMinLength(const Element& element) const;
81 float sequenceMinLength(const std::vector<Element>& sequence, size_t from = 0) const;
82 bool expandSequence(const std::vector<Element>& sequence, float available,
83 std::vector<std::string>& symbols, float& used) const;
84 const ShapeModuleVariant* chooseVariant(const std::string& symbol, uint32_t seed) const;
85
86 std::unordered_map<std::string, std::vector<ShapeModuleVariant>> modules_;
87 std::vector<std::string> moduleOrder_;
88 std::string error_;
89 int lastSymbolCount_ = 0;
90 float lastUsedLength_ = 0.f;
91 float lastSplineLength_ = 0.f;
92};
93
94} // namespace eve::procgen
std::string from
float length
Definition CaveMesh.cpp:94
#define EVENGINE_API_DOMAINS
Definition Export.h:110
std::string text
std::array< float, 3 > position
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::string error
Definition Package.cpp:60
std::uint32_t seed
Definition PointSet.cpp:807
std::string element
int children
Definition TreeMesh.cpp:295
uint32_t index
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
Module-based shape grammar expanded continuously along a 3D polyline.
One weighted asset variant represented by a shape-grammar symbol.