载入中...
搜索中...
未找到
MeshBuild.cpp
浏览该文件的文档.
1#include "procgen/MeshBuild.h"
2
3namespace eve::procgen {
4
6 positions_.clear();
7 normals_.clear();
8 uvs_.clear();
9 indices_.clear();
10 meta_.clear();
11}
12
13void MeshBuild::reserve(int vertexCount, int indexCount) {
14 if (vertexCount > 0) {
15 positions_.reserve(size_t(vertexCount) * 3u);
16 normals_.reserve(size_t(vertexCount) * 3u);
17 uvs_.reserve(size_t(vertexCount) * 2u);
18 }
19 if (indexCount > 0) indices_.reserve(size_t(indexCount));
20}
21
22void MeshBuild::addVertex(float px, float py, float pz, float nx, float ny, float nz, float u,
23 float v) {
24 positions_.push_back(px);
25 positions_.push_back(py);
26 positions_.push_back(pz);
27 normals_.push_back(nx);
28 normals_.push_back(ny);
29 normals_.push_back(nz);
30 uvs_.push_back(u);
31 uvs_.push_back(v);
32}
33
34void MeshBuild::addTriangle(uint32_t i0, uint32_t i1, uint32_t i2) {
35 indices_.push_back(i0);
36 indices_.push_back(i1);
37 indices_.push_back(i2);
38}
39
40int MeshBuild::getVertexCount() const { return int(positions_.size() / 3u); }
41int MeshBuild::getIndexCount() const { return int(indices_.size()); }
42bool MeshBuild::empty() const { return positions_.empty() || indices_.empty(); }
43
44float MeshBuild::getPositionX(int i) const {
45 if (i < 0 || i >= getVertexCount()) return 0.f;
46 return positions_[size_t(i) * 3u];
47}
48float MeshBuild::getPositionY(int i) const {
49 if (i < 0 || i >= getVertexCount()) return 0.f;
50 return positions_[size_t(i) * 3u + 1u];
51}
52float MeshBuild::getPositionZ(int i) const {
53 if (i < 0 || i >= getVertexCount()) return 0.f;
54 return positions_[size_t(i) * 3u + 2u];
55}
56float MeshBuild::getNormalX(int i) const {
57 if (i < 0 || i >= getVertexCount()) return 0.f;
58 return normals_[size_t(i) * 3u];
59}
60float MeshBuild::getNormalY(int i) const {
61 if (i < 0 || i >= getVertexCount()) return 0.f;
62 return normals_[size_t(i) * 3u + 1u];
63}
64float MeshBuild::getNormalZ(int i) const {
65 if (i < 0 || i >= getVertexCount()) return 0.f;
66 return normals_[size_t(i) * 3u + 2u];
67}
68float MeshBuild::getUvU(int i) const {
69 if (i < 0 || i >= getVertexCount()) return 0.f;
70 return uvs_[size_t(i) * 2u];
71}
72float MeshBuild::getUvV(int i) const {
73 if (i < 0 || i >= getVertexCount()) return 0.f;
74 return uvs_[size_t(i) * 2u + 1u];
75}
76int MeshBuild::getIndex(int i) const {
77 if (i < 0 || i >= getIndexCount()) return 0;
78 return int(indices_[size_t(i)]);
79}
80
81void MeshBuild::setMeta(const std::string &key, const std::string &value) { meta_[key] = value; }
82
83std::string MeshBuild::getMeta(const std::string &key, const std::string &defaultValue) const {
84 auto it = meta_.find(key);
85 return it == meta_.end() ? defaultValue : it->second;
86}
87
88} // namespace eve::procgen
std::string value
uint32_t i1
Definition Grass.cpp:62
uint32_t i2
Definition Grass.cpp:62
uint32_t i0
Definition Grass.cpp:62
float u
Definition Grass.cpp:234
std::vector< Colorf > px
int v
float getPositionZ(int i) const
Definition MeshBuild.cpp:52
float getPositionY(int i) const
Definition MeshBuild.cpp:48
std::string getMeta(const std::string &key, const std::string &defaultValue) const
Definition MeshBuild.cpp:83
void addVertex(float px, float py, float pz, float nx, float ny, float nz, float u, float v)
Definition MeshBuild.cpp:22
void addTriangle(uint32_t i0, uint32_t i1, uint32_t i2)
Definition MeshBuild.cpp:34
float getNormalZ(int i) const
Definition MeshBuild.cpp:64
void reserve(int vertexCount, int indexCount)
Definition MeshBuild.cpp:13
void setMeta(const std::string &key, const std::string &value)
Definition MeshBuild.cpp:81
float getNormalY(int i) const
Definition MeshBuild.cpp:60
int getIndexCount() const
Definition MeshBuild.cpp:41
float getUvU(int i) const
Definition MeshBuild.cpp:68
int getVertexCount() const
Definition MeshBuild.cpp:40
float getUvV(int i) const
Definition MeshBuild.cpp:72
float getNormalX(int i) const
Definition MeshBuild.cpp:56
int getIndex(int i) const
Definition MeshBuild.cpp:76
float getPositionX(int i) const
Definition MeshBuild.cpp:44