载入中...
搜索中...
未找到
ArchSpace.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <functional>
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace eve::archspace {
15namespace {
16
17ssq::Table bakeArraysTable(HSQUIRRELVM vm, const MeshArrays& arrays) {
18 ssq::Array positions(vm);
19 for (float v : arrays.positions) positions.push(v);
20 ssq::Array normals(vm);
21 for (float v : arrays.normals) normals.push(v);
22 ssq::Array uvs(vm);
23 for (float v : arrays.uvs) uvs.push(v);
24 ssq::Array indices(vm);
25 for (std::uint32_t v : arrays.indices) indices.push(static_cast<std::int64_t>(v));
26 ssq::Table table(vm);
27 table.set("positions", positions);
28 table.set("normals", normals);
29 table.set("uvs", uvs);
30 table.set("indices", indices);
31 table.set("vertexCount", static_cast<std::int64_t>(arrays.vertexCount()));
32 table.set("indexCount", static_cast<std::int64_t>(arrays.indexCount()));
33 table.set("triangleCount", static_cast<std::int64_t>(arrays.triangleCount()));
34 return table;
35}
36
37} // namespace
38
40
41void ArchSpace::expose(ssq::Table& table) {
42 const HSQUIRRELVM vm = table.getHandle();
43 table.addClass(name, ArchSpace::create, false);
44
45 auto document =
46 table.addClass<Document>("ArchSpaceDocument", std::function<Document*()>([] { return new Document(); }), true);
47 document.addFunc("nodeCount", [](Document* self) { return self ? static_cast<int>(self->nodeCount()) : 0; });
48 document.addFunc("rootId", [](Document* self) { return self ? self->rootId() : std::string{}; });
49 document.addFunc("topology", [](Document* self) {
50 return self ? std::string(topologyKindName(self->topology())) : std::string{"architectural"};
51 });
52 document.addFunc("setTopology", [vm](Document* self, const std::string& topologyText) {
53 if (!self)
56 "ArchSpaceDocument receiver must not be null",
57 "receiver", {}, "archspace.squirrel")));
58 auto kind = parseTopologyKind(topologyText);
60 return eve::script::projectResult(vm, self->setTopology(kind.value()));
61 });
62 document.addFunc("hasNode",
63 [](Document* self, const std::string& id) { return self && self->find(id) != nullptr; });
64 document.addFunc("bootstrap", [vm](Document* self, const std::string& siteId, const std::string& buildingId,
65 const std::string& levelId, float levelHeight) {
66 if (!self)
69 "ArchSpaceDocument receiver must not be null",
70 "receiver", {}, "archspace.squirrel")));
71 return eve::script::projectResult(vm, self->bootstrap(siteId, buildingId, levelId, levelHeight));
72 });
73 document.addFunc("createRectRoom", [vm](Document* self, const std::string& levelId, const std::string& roomId,
74 const std::string& roomName, float originX, float originZ, float sizeX,
75 float sizeZ, float wallHeight, float wallThickness, float slabThickness) {
76 if (!self)
79 "ArchSpaceDocument receiver must not be null",
80 "receiver", {}, "archspace.squirrel")));
81 std::vector<Vec2> polygon = {{originX, originZ},
82 {originX + sizeX, originZ},
83 {originX + sizeX, originZ + sizeZ},
84 {originX, originZ + sizeZ}};
85 return eve::script::projectResult(vm, self->createRoom(levelId, roomId, roomName, std::move(polygon),
86 wallHeight, wallThickness, slabThickness));
87 });
88 document.addFunc("createWall", [vm](Document* self, const std::string& levelId, const std::string& wallId,
89 const std::string& wallName, float x0, float z0, float x1, float z1,
90 float height, float thickness) {
91 if (!self)
94 "ArchSpaceDocument receiver must not be null",
95 "receiver", {}, "archspace.squirrel")));
97 vm, self->createWall(levelId, wallId, wallName, Vec2{x0, z0}, Vec2{x1, z1}, height, thickness));
98 });
99 document.addFunc("createOpening", [vm](Document* self, const std::string& wallId, const std::string& openingId,
100 const std::string& openingName, const std::string& kindText, float t,
101 float width, float height, float sill) {
102 if (!self)
105 "ArchSpaceDocument receiver must not be null",
106 "receiver", {}, "archspace.squirrel")));
107 auto kind = parseOpeningKind(kindText);
110 vm, self->createOpening(wallId, openingId, openingName, kind.value(), t, width, height, sill));
111 });
112 document.addFunc("placeItem", [vm](Document* self, const std::string& levelId, const std::string& itemId,
113 const std::string& itemName, const std::string& catalogId, float x, float y,
114 float z, float yawDegrees) {
115 if (!self)
118 "ArchSpaceDocument receiver must not be null",
119 "receiver", {}, "archspace.squirrel")));
121 vm, self->placeItem(levelId, itemId, itemName, catalogId, Vec3{x, y, z}, yawDegrees));
122 });
123 document.addFunc("deleteNode", [vm](Document* self, const std::string& id) {
124 if (!self)
127 "ArchSpaceDocument receiver must not be null",
128 "receiver", {}, "archspace.squirrel")));
129 return eve::script::projectResult(vm, self->eraseCascade(id));
130 });
131 document.addFunc("createRegion", [vm](Document* self, const std::string& levelId, const std::string& regionId,
132 const std::string& regionName, float originX, float originZ, float sizeX,
133 float sizeZ) {
134 if (!self)
137 "ArchSpaceDocument receiver must not be null",
138 "receiver", {}, "archspace.squirrel")));
139 std::vector<Vec2> polygon = {{originX, originZ},
140 {originX + sizeX, originZ},
141 {originX + sizeX, originZ + sizeZ},
142 {originX, originZ + sizeZ}};
143 return eve::script::projectResult(vm, self->createRegion(levelId, regionId, regionName, std::move(polygon)));
144 });
145 document.addFunc("createPortal", [vm](Document* self, const std::string& levelId, const std::string& portalId,
146 const std::string& portalName, const std::string& regionAId,
147 const std::string& regionBId, float x, float y, float z) {
148 if (!self)
151 "ArchSpaceDocument receiver must not be null",
152 "receiver", {}, "archspace.squirrel")));
154 vm, self->createPortal(levelId, portalId, portalName, regionAId, regionBId, kPassageWalk, Vec3{x, y, z}));
155 });
156 document.addFunc("regionAt", [](Document* self, float x, float z, const std::string& levelId) {
157 if (!self) return std::string{};
158 SpaceQuery query(*self);
159 const auto region = query.regionAt(Vec2{x, z}, levelId);
160 return region ? region->id : std::string{};
161 });
162 document.addFunc(
163 "regionsConnected", [vm](Document* self, const std::string& regionAId, const std::string& regionBId) {
164 const auto asBool = [](bool value) { return value; };
165 if (!self)
167 vm,
169 "ArchSpaceDocument receiver must not be null",
170 "receiver", {}, "archspace.squirrel")),
171 asBool);
172 return eve::script::projectResult(vm, SpaceQuery(*self).regionsConnected(regionAId, regionBId), asBool);
173 });
174 document.addFunc("bakeMeshArrays", [vm](Document* self) {
175 if (!self) return ssq::Table(vm);
176 return bakeArraysTable(vm, self->bakeMeshArrays());
177 });
178 document.addFunc("summary", [](Document* self) {
179 if (!self) return std::string{"null"};
180 const auto bake = self->bakeMeshArrays();
181 return "nodes=" + std::to_string(self->nodeCount()) + " root=" + self->rootId() +
182 " triangles=" + std::to_string(bake.triangleCount()) + " vertices=" + std::to_string(bake.vertexCount());
183 });
184}
185
186void ArchSpace::expose(ssq::Class&) {}
187
188} // namespace eve::archspace
double z
double y
double x
LogicalId itemId
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:38
std::string name
Definition ECS.cpp:154
ScriptFieldRegion region
std::vector< std::uint32_t > indices
std::vector< float > normals
std::vector< float > positions
float v
std::uint32_t height
std::uint32_t width
float thickness
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
Object::Ptr value
float t
std::string kind
std::string string
The single Squirrel projection for common Result, Status and Value.
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
Runtime ArchSpace module entry used for profile wiring and script discovery.
Definition ArchSpace.h:8
Authoritative ArchSpace document (Pascal-like node graph).
eve::Result< TopologyKind > parseTopologyKind(const std::string &text) noexcept
Parse a topology kind wire name.
constexpr PassageMask kPassageWalk
Default walkable mask.
const char * topologyKindName(TopologyKind kind) noexcept
Stable wire name for a topology kind. @ownership Non-owning pointer to a static string literal; do no...
eve::Result< OpeningKind > parseOpeningKind(const std::string &text) noexcept
Parse an opening kind wire name.
I * query()
Queries .
Definition Capability.h:88
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
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.