载入中...
搜索中...
未找到
ArchSpaceTypes.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Result.h"
4
5#include <cmath>
6#include <cstdint>
7#include <string>
8#include <vector>
9
10namespace eve::archspace {
11
13enum class NodeKind : std::uint8_t {
14 Site = 0,
16 Level,
17 Wall,
18 Slab,
19 Zone,
20 Item,
21 Opening,
23 Portal
24};
25
27enum class OpeningKind : std::uint8_t { Door = 0, Window };
28
33enum class TopologyKind : std::uint8_t { Architectural = 0, Dungeon, Cave };
34
36enum class PassageMode : std::uint8_t {
37 Walk = 1,
38 Crawl = 2,
39 Fly = 4,
40 Swim = 8,
41};
42
44using PassageMask = std::uint8_t;
45
47inline constexpr PassageMask kPassageWalk = static_cast<PassageMask>(PassageMode::Walk);
48
50struct Vec2 {
51 double x = 0.0;
52 double z = 0.0;
53};
54
56struct Vec3 {
57 double x = 0.0;
58 double y = 0.0;
59 double z = 0.0;
60};
61
63struct Node {
64 std::string id;
66 std::string parentId;
67 std::string name;
68 std::vector<std::string> children;
69
70 // level
71 double elevation = 0.0;
72 double height = 3.0;
73
74 // wall
77 double thickness = 0.2;
78
79 // slab / zone
80 std::vector<Vec2> polygon;
81 double slabThickness = 0.2;
82
83 // item
85 double yawDegrees = 0.0;
86 std::string catalogId;
87
88 // opening (wall-hosted)
90 double t = 0.5;
91 double width = 0.9;
92 double openingHeight = 2.1;
93 double sill = 0.0;
94
95 // portal (level-hosted region connector)
96 std::string regionAId;
97 std::string regionBId;
100};
101
104 std::string id;
105 std::string levelId;
106 std::string name;
107 std::vector<Vec2> polygon;
108};
109
112 std::string id;
113 std::string levelId;
114 std::string name;
115 std::string regionAId;
116 std::string regionBId;
119 bool wallHosted = false;
120};
121
124 std::string id;
125 std::string levelId;
126 std::string name;
127 std::string catalogId;
129 double yawDegrees = 0.0;
130};
131
133struct MeshBake {
134 std::vector<Vec3> positions;
135 std::vector<std::uint32_t> indices;
136 std::vector<std::string> primitiveIds;
137};
138
145 std::vector<float> positions;
146 std::vector<float> normals;
147 std::vector<float> uvs;
148 std::vector<std::uint32_t> indices;
149
151 [[nodiscard]] int vertexCount() const noexcept {
152 return static_cast<int>(positions.size() / 3);
153 }
155 [[nodiscard]] int indexCount() const noexcept { return static_cast<int>(indices.size()); }
157 [[nodiscard]] int triangleCount() const noexcept { return indexCount() / 3; }
158};
159
161[[nodiscard]] inline MeshArrays toMeshArrays(const MeshBake& bake) {
163 out.positions.reserve(bake.positions.size() * 3);
164 out.normals.reserve(bake.positions.size() * 3);
165 out.uvs.reserve(bake.positions.size() * 2);
166 out.indices = bake.indices;
167 for (const Vec3& p : bake.positions) {
168 out.positions.push_back(static_cast<float>(p.x));
169 out.positions.push_back(static_cast<float>(p.y));
170 out.positions.push_back(static_cast<float>(p.z));
171 out.normals.push_back(0.f);
172 out.normals.push_back(1.f);
173 out.normals.push_back(0.f);
174 out.uvs.push_back(static_cast<float>(p.x));
175 out.uvs.push_back(static_cast<float>(p.z));
176 }
177 for (std::size_t i = 0; i + 2 < bake.indices.size(); i += 3) {
178 const std::uint32_t i0 = bake.indices[i], i1 = bake.indices[i + 1], i2 = bake.indices[i + 2];
179 if (i0 >= bake.positions.size() || i1 >= bake.positions.size() || i2 >= bake.positions.size()) continue;
180 const Vec3& a = bake.positions[i0];
181 const Vec3& b = bake.positions[i1];
182 const Vec3& c = bake.positions[i2];
183 Vec3 n{(b.y - a.y) * (c.z - a.z) - (b.z - a.z) * (c.y - a.y),
184 (b.z - a.z) * (c.x - a.x) - (b.x - a.x) * (c.z - a.z),
185 (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)};
186 const double len = std::sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
187 if (len > 1e-8) {
188 n.x /= len;
189 n.y /= len;
190 n.z /= len;
191 } else {
192 n = {0, 1, 0};
193 }
194 for (std::uint32_t idx : {i0, i1, i2}) {
195 out.normals[idx * 3 + 0] = static_cast<float>(n.x);
196 out.normals[idx * 3 + 1] = static_cast<float>(n.y);
197 out.normals[idx * 3 + 2] = static_cast<float>(n.z);
198 }
199 }
200 return out;
201}
202
208[[nodiscard]] inline const char* nodeKindName(NodeKind kind) noexcept {
209 switch (kind) {
210 case NodeKind::Site: return "site";
211 case NodeKind::Building: return "building";
212 case NodeKind::Level: return "level";
213 case NodeKind::Wall: return "wall";
214 case NodeKind::Slab: return "slab";
215 case NodeKind::Zone: return "zone";
216 case NodeKind::Item: return "item";
217 case NodeKind::Opening: return "opening";
218 case NodeKind::Portal: return "portal";
219 }
220 return "site";
221}
222
227[[nodiscard]] inline eve::Result<NodeKind> parseNodeKind(const std::string& text) noexcept {
229 if (text == "building") return eve::Result<NodeKind>::success(NodeKind::Building);
235 if (text == "opening") return eve::Result<NodeKind>::success(NodeKind::Opening);
238 eve::DiagnosticCode::InvalidArgument, "unknown ArchSpace node kind", "kind", {}, "archspace.kind"));
239}
240
246[[nodiscard]] inline const char* openingKindName(OpeningKind kind) noexcept {
247 return kind == OpeningKind::Window ? "window" : "door";
248}
249
254[[nodiscard]] inline eve::Result<OpeningKind> parseOpeningKind(const std::string& text) noexcept {
258 "unknown ArchSpace opening kind", "openingKind", {},
259 "archspace.opening"));
260}
261
267[[nodiscard]] inline const char* topologyKindName(TopologyKind kind) noexcept {
268 switch (kind) {
269 case TopologyKind::Architectural: return "architectural";
270 case TopologyKind::Dungeon: return "dungeon";
271 case TopologyKind::Cave: return "cave";
272 }
273 return "architectural";
274}
275
280[[nodiscard]] inline eve::Result<TopologyKind> parseTopologyKind(const std::string& text) noexcept {
285 eve::DiagnosticCode::InvalidArgument, "unknown ArchSpace topology", "topology", {}, "archspace.topology"));
286}
287
288} // namespace eve::archspace
glm::vec4 p[6]
uint32_t i1
Definition Grass.cpp:61
uint32_t i2
Definition Grass.cpp:61
uint32_t i0
Definition Grass.cpp:61
glm::vec3 n
Definition Grass.cpp:63
std::int32_t c
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
int idx
Move-only, checked operation results for the common layer.
std::string text
ScriptStructure out
std::string kind
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
MeshArrays toMeshArrays(const MeshBake &bake)
Convert a MeshBake into flat arrays with per-triangle normals.
std::uint8_t PassageMask
Bitmask of PassageMode values.
eve::Result< TopologyKind > parseTopologyKind(const std::string &text) noexcept
Parse a topology kind wire name.
PassageMode
Passage capability bits for portals (walk/crawl/fly/swim).
OpeningKind
Opening semantic used by doors and windows hosted on walls.
eve::Result< NodeKind > parseNodeKind(const std::string &text) noexcept
Parse a node kind wire name.
constexpr PassageMask kPassageWalk
Default walkable mask.
NodeKind
Stable node kind discriminator for the architectural document.
@ Portal
Level-hosted portal connecting two regions (dungeon/cave or free openings).
const char * openingKindName(OpeningKind kind) noexcept
Stable wire name for an opening kind. @ownership Non-owning pointer to a static string literal; do no...
const char * topologyKindName(TopologyKind kind) noexcept
Stable wire name for a topology kind. @ownership Non-owning pointer to a static string literal; do no...
const char * nodeKindName(NodeKind kind) noexcept
Stable wire name for a node kind. @ownership Non-owning pointer to a static string literal; do not fr...
TopologyKind
Document topology dialect. Storage stays one node graph; semantics and authoring helpers differ by di...
eve::Result< OpeningKind > parseOpeningKind(const std::string &text) noexcept
Parse an opening kind wire name.
Interleaved GPU-upload arrays derived from MeshBake.
std::vector< float > normals
std::vector< std::uint32_t > indices
std::vector< float > positions
std::vector< float > uvs
int indexCount() const noexcept
Index count.
int triangleCount() const noexcept
Triangle count.
int vertexCount() const noexcept
Vertex count.
Renderer-neutral triangle mesh rebuilt from the document.
std::vector< std::uint32_t > indices
std::vector< std::string > primitiveIds
std::vector< Vec3 > positions
One authored architectural node. Only fields for the active kind are meaningful.
std::vector< std::string > children
std::vector< Vec2 > polygon
Read-only item/anchor view.
Read-only portal view from Opening or Portal nodes.
Read-only region view projected from Zone nodes.
std::vector< Vec2 > polygon
Metres on the level XZ plane.
Metres in world/level space.