载入中...
搜索中...
未找到
ArchSpace.cpp
浏览该文件的文档.
2
5
6#include <simplesquirrel/simplesquirrel.hpp>
7
8#include <functional>
9#include <string>
10#include <utility>
11#include <vector>
12
13namespace eve::archspace {
14namespace {
15
16ssq::Table bakeArraysTable(HSQUIRRELVM vm, const MeshArrays& arrays) {
17 ssq::Array positions(vm);
18 for (float v : arrays.positions) positions.push(v);
19 ssq::Array normals(vm);
20 for (float v : arrays.normals) normals.push(v);
21 ssq::Array uvs(vm);
22 for (float v : arrays.uvs) uvs.push(v);
23 ssq::Array indices(vm);
24 for (std::uint32_t v : arrays.indices) indices.push(static_cast<std::int64_t>(v));
25 ssq::Table table(vm);
26 table.set("positions", positions);
27 table.set("normals", normals);
28 table.set("uvs", uvs);
29 table.set("indices", indices);
30 table.set("vertexCount", static_cast<std::int64_t>(arrays.vertexCount()));
31 table.set("indexCount", static_cast<std::int64_t>(arrays.indexCount()));
32 table.set("triangleCount", static_cast<std::int64_t>(arrays.triangleCount()));
33 return table;
34}
35
36} // namespace
37
39
40void ArchSpace::expose(ssq::Table& table) {
41 const HSQUIRRELVM vm = table.getHandle();
42 table.addClass(name, ArchSpace::create, false);
43
44 auto document =
45 table.addClass<Document>("ArchSpaceDocument",
46 std::function<Document*()>([] { return new Document(); }), true);
47 document.addFunc("nodeCount", [](Document* self) {
48 return self ? static_cast<int>(self->nodeCount()) : 0;
49 });
50 document.addFunc("rootId", [](Document* self) { return self ? self->rootId() : std::string{}; });
51 document.addFunc("hasNode", [](Document* self, const std::string& id) {
52 return self && self->find(id) != nullptr;
53 });
54 document.addFunc("bootstrap", [vm](Document* self, const std::string& siteId, const std::string& buildingId,
55 const std::string& levelId, float levelHeight) {
56 if (!self)
59 "ArchSpaceDocument receiver must not be null",
60 "receiver", {}, "archspace.squirrel")));
61 return eve::script::projectResult(vm, self->bootstrap(siteId, buildingId, levelId, levelHeight));
62 });
63 document.addFunc("createRectRoom", [vm](Document* self, const std::string& levelId, const std::string& roomId,
64 const std::string& roomName, float originX, float originZ, float sizeX,
65 float sizeZ, float wallHeight, float wallThickness, float slabThickness) {
66 if (!self)
69 "ArchSpaceDocument receiver must not be null",
70 "receiver", {}, "archspace.squirrel")));
71 std::vector<Vec2> polygon = {{originX, originZ},
72 {originX + sizeX, originZ},
73 {originX + sizeX, originZ + sizeZ},
74 {originX, originZ + sizeZ}};
76 vm, self->createRoom(levelId, roomId, roomName, std::move(polygon), wallHeight, wallThickness,
77 slabThickness));
78 });
79 document.addFunc("createWall", [vm](Document* self, const std::string& levelId, const std::string& wallId,
80 const std::string& wallName, float x0, float z0, float x1, float z1,
81 float height, float thickness) {
82 if (!self)
85 "ArchSpaceDocument receiver must not be null",
86 "receiver", {}, "archspace.squirrel")));
88 vm, self->createWall(levelId, wallId, wallName, Vec2{x0, z0}, Vec2{x1, z1}, height, thickness));
89 });
90 document.addFunc("createOpening", [vm](Document* self, const std::string& wallId, const std::string& openingId,
91 const std::string& openingName, const std::string& kindText, float t,
92 float width, float height, float sill) {
93 if (!self)
96 "ArchSpaceDocument receiver must not be null",
97 "receiver", {}, "archspace.squirrel")));
98 auto kind = parseOpeningKind(kindText);
101 vm, self->createOpening(wallId, openingId, openingName, kind.value(), t, width, height, sill));
102 });
103 document.addFunc("placeItem", [vm](Document* self, const std::string& levelId, const std::string& itemId,
104 const std::string& itemName, const std::string& catalogId, float x, float y,
105 float z, float yawDegrees) {
106 if (!self)
109 "ArchSpaceDocument receiver must not be null",
110 "receiver", {}, "archspace.squirrel")));
112 vm, self->placeItem(levelId, itemId, itemName, catalogId, Vec3{x, y, z}, yawDegrees));
113 });
114 document.addFunc("deleteNode", [vm](Document* self, const std::string& id) {
115 if (!self)
118 "ArchSpaceDocument receiver must not be null",
119 "receiver", {}, "archspace.squirrel")));
120 return eve::script::projectResult(vm, self->eraseCascade(id));
121 });
122 document.addFunc("bakeMeshArrays", [vm](Document* self) {
123 if (!self) return ssq::Table(vm);
124 return bakeArraysTable(vm, self->bakeMeshArrays());
125 });
126 document.addFunc("summary", [](Document* self) {
127 if (!self) return std::string{"null"};
128 const auto bake = self->bakeMeshArrays();
129 return "nodes=" + std::to_string(self->nodeCount()) + " root=" + self->rootId() +
130 " triangles=" + std::to_string(bake.triangleCount()) +
131 " vertices=" + std::to_string(bake.vertexCount());
132 });
133}
134
135void ArchSpace::expose(ssq::Class&) {}
136
137} // namespace eve::archspace
LogicalId itemId
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float thickness
Definition CaveMesh.cpp:83
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:20
std::vector< std::uint32_t > indices
std::vector< float > normals
std::vector< float > positions
float v
std::uint32_t height
std::uint32_t width
TokenKind kind
std::string name
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
float t
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Runtime ArchSpace module entry used for profile wiring and script discovery.
Definition ArchSpace.h:8
Authoritative architectural space document (Pascal-like node graph).
eve::Result< OpeningKind > parseOpeningKind(const std::string &text) noexcept
Parse an opening kind wire name.
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.