2#include <assimp/material.h>
3#include <assimp/matrix4x4.h>
4#include <assimp/scene.h>
5#include <assimp/texture.h>
12#include <glm/mat4x4.hpp>
14#include <simplesquirrel/simplesquirrel.hpp>
18#include <unordered_map>
19#include <unordered_set>
42glm::mat4 aiToGlm(
const aiMatrix4x4&
m) {
43 return glm::mat4(
m.a1,
m.b1,
m.c1,
m.d1,
m.a2,
m.b2,
m.c2,
m.d2,
m.a3,
m.b3,
m.c3,
m.d3,
m.a4,
m.b4,
m.c4,
m.d4);
58 if (!
object.isObject())
63 out.id =
object.getString(
"id");
64 out.modelPath =
object.getString(
"model");
65 out.category =
object.getString(
"category");
66 out.width =
object.getInt(
"width", 1);
67 out.depth =
object.getInt(
"depth", 1);
68 out.height =
object.getInt(
"height", 1);
69 out.weight =
object.getInt(
"weight", 1);
70 out.tags =
object.getStringArray(
"tags");
71 if (
object.get(
"rotations").isArray())
out.rotations =
object.getIntArray(
"rotations");
73 const Value sockets =
object.get(
"sockets");
74 for (
size_t i = 0; i < sockets.size(); ++i) {
75 const Value socketObject = sockets.at(i);
76 if (!socketObject.isObject())
79 auto direction = parseDirection(socketObject.getString(
"direction"));
83 socket.direction = std::move(
direction).takeValue();
84 socket.type = socketObject.getString(
"type");
85 socket.accepts = socketObject.getStringArray(
"accepts");
86 if (socket.type.empty())
89 "sockets", {},
"housegen.components"));
90 out.sockets.push_back(std::move(socket));
96 if (
color.isArray()) {
100 "material.baseColor", {},
"housegen.components"));
101 out.material.hasBaseColor =
true;
102 out.material.baseColorR =
color.at(0).asFloat();
103 out.material.baseColorG =
color.at(1).asFloat();
104 out.material.baseColorB =
color.at(2).asFloat();
105 out.material.baseColorA =
color.size() == 4 ?
color.at(3).asFloat() : 1.f;
107 out.material.baseColorTexture =
material.getString(
"baseColorTexture");
108 out.material.normalTexture =
material.getString(
"normalTexture");
109 out.material.heightTexture =
material.getString(
"heightTexture");
111 out.material.hasMetallic =
true;
112 out.material.metallic =
material.getFloat(
"metallic");
115 out.material.hasRoughness =
true;
116 out.material.roughness =
material.getFloat(
"roughness");
118 out.material.parallaxScale =
material.getFloat(
"parallaxScale", 0.f);
119 out.material.parallaxMinLayers =
material.getFloat(
"parallaxMinLayers", 8.f);
120 out.material.parallaxMaxLayers =
material.getFloat(
"parallaxMaxLayers", 32.f);
121 out.material.cellBombScale =
material.getFloat(
"cellBombScale", 4.f);
122 out.material.cellBombStrength =
material.getFloat(
"cellBombStrength", 0.f);
123 out.material.cellBombRotation =
material.getFloat(
"cellBombRotation", 1.f);
133 "component needs id, model and category", {}, {},
134 "housegen.components"));
137 "component dimensions and weight must be positive", {},
138 {},
"housegen.components"));
140 if (rotation < 0 || rotation >= 360 ||
rotation % 90 != 0)
142 "rotations must be cardinal degrees",
"rotations",
143 {},
"housegen.components"));
146 const auto inUnitRange = [](
float value) {
return value >= 0.f &&
value <= 1.f; };
154 "material values must be between 0 and 1",
"material",
155 {},
"housegen.components"));
161 "material sampling parameters are invalid",
"material",
162 {},
"housegen.components"));
163 if (components_.contains(component.
id))
167 components_.emplace(component.
id, component);
172 std::string parseError;
174 if (!document.
valid())
177 "housegen.components"));
186 for (
size_t i = 0; i <
values.size(); ++i) {
187 auto component = parseComponent(
values.at(i));
190 if (!registered.ok())
return registered;
192 components_ = std::move(candidate.components_);
197 const std::string
path(filename);
198 std::ifstream
input(
path, std::ios::binary);
203 std::ostringstream json;
204 json <<
input.rdbuf();
209 const std::filesystem::path assetRoot = std::filesystem::absolute(std::filesystem::path(
path)).parent_path();
210 for (
auto &[_, component] : candidate.components_) {
211 std::filesystem::path
model(component.modelPath);
212 if (
model.is_relative()) component.modelPath = (assetRoot /
model).lexically_normal().string();
214 components_ = std::move(candidate.components_);
221 const auto it = components_.find(std::string(
id));
222 if (it == components_.end())
return {};
223 return std::cref(it->second);
229 std::vector<std::string>
result;
230 result.reserve(components_.size());
231 for (
const auto &[
id, _] : components_)
result.push_back(
id);
237 std::string_view
category, std::string_view style)
const {
238 std::vector<std::reference_wrapper<const HouseComponent>>
result;
239 for (
const auto &[_, component] : components_) {
240 if (component.category ==
category &&
241 (style.empty() || std::find(component.tags.begin(), component.tags.end(), style) != component.tags.end()))
242 result.push_back(std::cref(component));
246 [](
const auto &
left,
const auto &
right) { return left.get().id < right.get().id; });
251 if (style.empty())
return false;
252 static constexpr const char *core[] = {
"foundation",
"floor",
"wall",
"door",
"roof"};
255 for (
const auto &[_, component] : components_)
256 if (component.category ==
category &&
257 std::find(component.tags.begin(), component.tags.end(), style) != component.tags.end()) {
267 std::vector<std::string> styles;
268 for (
const auto &[_, component] : components_)
269 for (
const std::string &
tag : component.tags)
270 if (std::find(styles.begin(), styles.end(),
tag) == styles.end()) styles.push_back(
tag);
271 std::vector<std::string>
result;
272 for (
const std::string &style : styles)
298 auto cls = table.addClass<
HouseGen>(
"HouseGen", std::function<HouseGen *()>([] {
return new HouseGen(); }),
true);
301 "HouseRequest", std::function<HouseRequest *()>([] {
return new HouseRequest(); }),
true);
315 r->requiredRooms.clear();
317 for (
const char c : csv) {
328 r->perimeter.clear();
330 for (
size_t i = 0; i <= csv.size(); ++i) {
331 if (i == csv.size() || csv[i] ==
';') {
332 const size_t comma = segment.find(
',');
333 if (comma != std::string::npos)
334 r->perimeter.push_back({float(std::atof(segment.substr(0, comma).c_str())),
335 float(std::atof(segment.substr(comma + 1).c_str()))});
338 segment.push_back(csv[i]);
343 std::function<HouseLayout *()>([] {
return new HouseLayout(); }),
true);
349 "layout receiver must not be null",
"layout", {},
350 "housegen.squirrel")));
353 layout.addFunc(
"getInstanceCount", [](
HouseLayout *
v) {
return int(
v->instances.size()); });
355 return (
v && i >= 0 && i <
int(
v->instances.size())) ?
v->instances[i].componentId : std::string();
358 return (
v && i >= 0 && i <
int(
v->instances.size())) ?
v->instances[i].x : 0;
361 return (
v && i >= 0 && i <
int(
v->instances.size())) ?
v->instances[i].y : 0;
364 return (
v && i >= 0 && i <
int(
v->instances.size())) ?
v->instances[i].z : 0;
367 return (
v && i >= 0 && i <
int(
v->instances.size())) ?
v->instances[i].rotationDeg : 0;
370 layout.addFunc(
"getFootprintStyle", [](
HouseLayout *
v) {
return v ?
v->footprintStyle : std::string(); });
371 layout.addFunc(
"getRoofStyle", [](
HouseLayout *
v) {
return v ?
v->roofStyle : std::string(); });
373 layout.addFunc(
"getDiagnosticCount", [](
HouseLayout *
v) {
return int(
v->diagnostics.size()); });
378 "layout and output grid are required",
379 "writeFootprintGrid", {},
"housegen.squirrel")));
387 "writeComponentPoints", {},
"housegen.squirrel")));
393 auto result =
layout.instantiate(gfx, models, library_);
400 cls.addFunc(
"loadComponentsFromJson", [
vm](
HouseGen *
value,
const std::string &json) {
404 "HouseGen receiver must not be null",
"housegen",
405 {},
"housegen.squirrel")));
408 cls.addFunc(
"loadComponentsFromFile", [
vm](
HouseGen *
value,
const std::string &filename) {
412 "HouseGen receiver must not be null",
"housegen",
413 {},
"housegen.squirrel")));
424 "HouseGen, request and layout are required",
425 "generate", {},
"housegen.squirrel")));
434 "instantiate", {},
"housegen.squirrel")));
444std::string esc(
const std::string &
v) {
447 if (
c ==
'\\' ||
c ==
'"') o +=
'\\';
453graphics::Texture *textureFromEmbedded(graphics::Graphics *gfx,
const aiTexture *
source) {
455 if (
source->mHeight == 0) {
457 std::unique_ptr<image::ImageData> decoded(image::Image::create()->newImageData(&
bytes));
460 std::vector<uint8_t> rgba(
size_t(
source->mWidth) *
size_t(
source->mHeight) * 4);
461 for (
size_t pixel = 0; pixel < size_t(
source->mWidth) * size_t(
source->mHeight); ++pixel) {
462 rgba[pixel * 4 + 0] =
source->pcData[pixel].r;
463 rgba[pixel * 4 + 1] =
source->pcData[pixel].g;
464 rgba[pixel * 4 + 2] =
source->pcData[pixel].b;
465 rgba[pixel * 4 + 3] =
source->pcData[pixel].a;
467 return gfx->newTexture(
int(
source->mWidth), int(
source->mHeight), rgba.data(),
471graphics::Texture *textureFromFile(graphics::Graphics *gfx,
const std::string &modelPath,
472 const std::string &texturePath) {
473 if (texturePath.empty())
return nullptr;
474 std::filesystem::path
resolved(texturePath);
477 if (std::filesystem::is_regular_file(
resolved)) {
478 std::ifstream
input(
resolved, std::ios::binary | std::ios::ate);
479 const std::streamsize
size =
input.tellg();
480 if (
size <= 0)
return nullptr;
481 input.seekg(0, std::ios::beg);
482 std::vector<uint8_t>
bytes(
static_cast<size_t>(
size));
483 if (!
input.read(
reinterpret_cast<char *
>(
bytes.data()),
size))
return nullptr;
485 std::unique_ptr<image::ImageData> decoded(image::Image::create()->newImageData(&
source));
488 return gfx->newTextureFromFile(
resolved.lexically_normal().string());
494graphics::Texture *assimpTexture(graphics::Graphics *gfx,
const aiScene *scene,
const aiMaterial *
material,
495 const std::string &modelPath, aiTextureType primary, aiTextureType fallback) {
496 if (!scene || !
material)
return nullptr;
497 aiString texturePath;
498 if (
material->GetTexture(primary, 0, &texturePath) != AI_SUCCESS &&
499 material->GetTexture(fallback, 0, &texturePath) != AI_SUCCESS)
501 const std::string
path = texturePath.C_Str();
502 if (
path.empty())
return nullptr;
503 if (
path.front() ==
'*') {
504 const int index = std::atoi(
path.c_str() + 1);
505 if (
index < 0 ||
static_cast<unsigned>(
index) >=
scene->mNumTextures)
return nullptr;
507 return textureFromEmbedded(gfx,
scene->mTextures[
index]);
512 return textureFromFile(gfx, modelPath,
path);
526 [[nodiscard]] model3d::ModelData *get() const noexcept {
533ModelHandle loadModel(model3d::Model3D *models,
const std::string &
path) {
534 if (!std::filesystem::is_regular_file(std::filesystem::path(
path))) {
537 model3d::ModelData *cached = models->newModelDataFromFile(
path);
538 if (cached ==
nullptr)
return {};
540 if (!
pinned.ok())
return {};
545 std::ifstream
input(
path, std::ios::binary | std::ios::ate);
546 if (!
input)
throw std::runtime_error(
"cannot open model: " +
path);
547 const std::streamsize
size =
input.tellg();
548 if (
size <= 0)
throw std::runtime_error(
"model is empty: " +
path);
549 input.seekg(0, std::ios::beg);
550 std::vector<uint8_t>
bytes(
static_cast<size_t>(
size));
552 throw std::runtime_error(
"cannot read model: " +
path);
555 handle.owned.reset(models->newModelData(&
source, std::filesystem::path(
path).extension().string()));
576 std::ostringstream o;
577 o <<
"{\"schema\":\"eve.house-layout\",\"version\":1,\"seed\":" <<
seed <<
",\"moduleSize\":" <<
moduleSize
580 <<
",\"footprintDepth\":" <<
footprintDepth <<
",\"footprintMask\":\"";
582 o <<
"\",\"instances\":[";
583 for (
size_t i = 0; i <
instances.size(); ++i) {
586 o <<
"{\"componentId\":\"" << esc(
v.componentId) <<
"\",\"x\":" <<
v.x <<
",\"y\":" <<
v.y <<
",\"z\":" <<
v.z
587 <<
",\"rotationDeg\":" <<
v.rotationDeg <<
'}';
589 o <<
"],\"rooms\":[";
590 for (
size_t i = 0; i <
rooms.size(); ++i) {
593 o <<
"{\"type\":\"" << esc(
v.type) <<
"\",\"x\":" <<
v.x <<
",\"y\":" <<
v.y <<
",\"z\":" <<
v.z
594 <<
",\"width\":" <<
v.width <<
",\"depth\":" <<
v.depth <<
'}';
596 o <<
"],\"diagnostics\":[";
607 std::string parseError;
617 const std::string schema = o.getString(
"schema",
"eve.house-layout");
618 const int version = o.getInt(
"version", 1);
619 if (schema !=
"eve.house-layout" ||
version != 1)
621 "unsupported house layout schema or version",
"schema",
622 {},
"housegen.layout"));
625 parsed.
seed =
static_cast<unsigned>(o.getInt(
"seed", 1));
626 parsed.
moduleSize = o.getFloat(
"moduleSize", 1.f);
627 parsed.
floorHeight = o.getFloat(
"floorHeight", 3.f);
628 parsed.
footprintStyle = o.getString(
"footprintStyle",
"rectangle");
629 parsed.
roofStyle = o.getString(
"roofStyle",
"gable");
630 parsed.
entranceSide = o.getString(
"entranceSide",
"north");
633 const std::string footprintBits = o.getString(
"footprintMask",
"");
637 "invalid canonical footprint mask",
"footprintMask",
638 {},
"housegen.layout"));
639 for (
const char bit : footprintBits) {
640 if (bit !=
'0' && bit !=
'1')
642 "footprint mask must contain only 0 or 1",
643 "footprintMask", {},
"housegen.layout"));
656 for (
size_t i = 0; i <
instances.size(); ++i) {
659 if (!
v.has(
"componentId") || !
v.has(
"x") || !
v.has(
"y") || !
v.has(
"z"))
661 "instance needs componentId, x, y and z",
662 "instances", {},
"housegen.layout"));
664 {
v.getString(
"componentId"),
v.getInt(
"x"),
v.getInt(
"y"),
v.getInt(
"z"),
v.getInt(
"rotationDeg", 0)});
668 for (
size_t i = 0; i <
rooms.size(); ++i) {
670 if (!
v.has(
"type") || !
v.has(
"x") || !
v.has(
"y") || !
v.has(
"width") || !
v.has(
"depth"))
672 "room needs type, x, y, width and depth",
"rooms",
673 {},
"housegen.layout"));
674 parsed.
rooms.push_back({
v.getString(
"type"),
v.getInt(
"x"),
v.getInt(
"y"),
v.getInt(
"z", 0),
v.getInt(
"width"),
678 parsed.
diagnostics = o.getStringArray(
"diagnostics");
679 *
this = std::move(parsed);
691 "house layout has no canonical footprint mask",
692 "footprintMask", {},
"housegen.layout"));
698 instance.componentId, {},
"housegen.layout"));
700 if (room.x < 0 || room.y < 0 || room.width <= 0 || room.depth <= 0 || room.x + room.width >
footprintWidth ||
703 "room lies outside the canonical footprint",
704 "rooms", {},
"housegen.layout"));
705 for (
int y = room.y;
y < room.y + room.depth; ++
y)
706 for (
int x = room.x;
x < room.x + room.width; ++
x)
709 "room contains an inactive footprint cell",
710 "rooms", {},
"housegen.layout"));
712 std::unordered_set<std::string>
occupied;
713 std::unordered_set<std::string> floorCells, roofCells;
714 std::vector<std::tuple<int, int, int>> floors;
715 auto cellKey = [](
int x,
int y,
int z) {
716 return std::to_string(
x) +
":" + std::to_string(
y) +
":" + std::to_string(
z);
718 bool entrance =
false, roof =
false;
720 const auto component = library.
find(i.componentId);
723 "unknown component: " + i.componentId,
724 "componentId", {},
"housegen.layout"));
726 const int normalizedRotation = (i.rotationDeg % 360 + 360) % 360;
727 if (normalizedRotation % 90 != 0)
730 const bool rotationAllowed = std::any_of(
c.rotations.begin(),
c.rotations.end(), [&](
int allowed) {
731 return (allowed % 360 + 360) % 360 == normalizedRotation;
733 if (!rotationAllowed)
735 "component does not allow the requested rotation",
736 "rotationDeg", {},
"housegen.layout"));
737 const bool quarter = (normalizedRotation / 90) % 2 != 0;
738 const int w = quarter ?
c.depth :
c.width,
d = quarter ?
c.width :
c.depth;
739 for (
int y = 0;
y <
d; ++
y)
740 for (
int x = 0;
x <
w; ++
x) {
742 const bool orientedBoundary =
c.category ==
"wall" ||
c.category ==
"door" ||
743 c.category ==
"interior_wall" ||
c.category ==
"interior_door";
744 const std::string orientation =
745 orientedBoundary ?
":" + std::to_string((i.rotationDeg % 360 + 360) % 360) :
"";
746 const std::string
key = std::to_string(i.x +
x) +
":" + std::to_string(i.y +
y) +
":" +
747 std::to_string(i.z) +
":" +
c.category + orientation;
751 "overlapping " +
c.category +
" components", {}, {},
"housegen.layout"));
752 if (
c.category ==
"floor") {
753 floorCells.insert(cellKey(i.x +
x, i.y +
y, i.z));
754 floors.emplace_back(i.x +
x, i.y +
y, i.z);
755 }
else if (
c.category ==
"roof") {
756 roofCells.insert(cellKey(i.x +
x, i.y +
y, i.z));
759 entrance = entrance || (
c.category ==
"door" && i.z == 0);
760 roof = roof ||
c.category ==
"roof";
764 "house has no entrance", {}, {},
"housegen.layout"));
767 "house has no roof", {}, {},
"housegen.layout"));
768 for (
const auto &[
x,
y,
z] : floors) {
769 if (
z > 0 && !floorCells.contains(cellKey(
x,
y,
z - 1))) {
771 "upper floor has no structural support", {}, {},
774 if (!floorCells.contains(cellKey(
x,
y,
z + 1)) && !roofCells.contains(cellKey(
x,
y,
z + 1))) {
788 if (instance.x < 0 || instance.y < 0 || instance.z < 0)
790 "house instance has a negative grid coordinate",
791 instance.componentId, {},
"housegen.layout"));
796 "house layout has no canonical footprint mask",
797 "footprintMask", {},
"housegen.layout"));
808 candidate.
setDetail(instance.x, instance.y,
809 std::min(255, std::max(candidate.
getDetail(instance.x, instance.y), instance.z + 1)));
811 candidate.
setMeta(
"domain",
"house.footprint");
816 out = std::move(candidate);
828 "house layout has no canonical footprint mask",
829 "footprintMask", {},
"housegen.layout"));
831 const int rotation = (instance.rotationDeg % 360 + 360) % 360;
832 if (instance.x < 0 || instance.y < 0 || instance.z < 0 || instance.x >=
footprintWidth ||
836 "invalid house component point placement",
837 instance.componentId, {},
"housegen.layout"));
840 candidate.
reserve(instances.size());
841 std::uint64_t ordinal = 0;
842 const std::uint64_t pointNamespace = (std::uint64_t(
seed) << 32u) | 0x484f5553u;
843 for (
const auto &instance : instances) {
844 const int index = candidate.
add(
float(instance.x) * moduleSize,
float(instance.z) * floorHeight,
845 float(instance.y) * moduleSize);
846 candidate.
setYaw(
index,
float(instance.rotationDeg));
848 candidate.
setBounds(
index, 0.f, 0.f, 0.f, moduleSize, floorHeight, moduleSize);
860 out = std::move(candidate);
866 const auto valid = validate(library);
868 std::vector<ecs::EntityHandle>
entities;
869 const auto destroyCreated = [&
entities]()
noexcept {
875 std::unordered_map<std::string, ModelHandle> data;
881 float r = 1.f,
g = 1.f,
b = 1.f,
a = 1.f;
883 float parallaxScale = 0.f, parallaxMinLayers = 8.f, parallaxMaxLayers = 32.f;
884 float cellBombScale = 4.f, cellBombStrength = 0.f, cellBombRotation = 1.f;
886 std::unordered_map<std::string, std::vector<CachedPart>>
parts;
888 for (
const auto &i : instances) {
889 const auto component = library.
find(i.componentId);
894 "componentId", {},
"housegen.layout"));
898 auto modelIt = data.find(
c.modelPath);
899 if (modelIt == data.end()) modelIt = data.emplace(
c.modelPath, loadModel(&models,
c.modelPath)).first;
903 auto &cached =
parts[
c.id];
904 if (cached.empty()) {
906 if (!
scene || !
scene->mRootNode)
throw std::runtime_error(
"model has no scene root: " +
c.modelPath);
907 std::function<void(
const aiNode *,
const aiMatrix4x4 &)> walk = [&](
const aiNode *
node,
908 const aiMatrix4x4 &
parent) {
909 const aiMatrix4x4 world =
parent *
node->mTransformation;
910 for (
unsigned ni = 0; ni <
node->mNumMeshes; ++ni) {
911 const unsigned mi =
node->mMeshes[ni];
912 if (mi >=
scene->mNumMeshes || !
scene->mMeshes[mi])
continue;
918 aiColor4D
color(1.f, 1.f, 1.f, 1.f);
925 material->Get(AI_MATKEY_METALLIC_FACTOR, part.metallic);
926 material->Get(AI_MATKEY_ROUGHNESS_FACTOR, part.roughness);
927 part.texture = assimpTexture(&gfx,
scene,
material,
c.modelPath, aiTextureType_BASE_COLOR,
928 aiTextureType_DIFFUSE);
929 part.normalTexture = assimpTexture(&gfx,
scene,
material,
c.modelPath,
930 aiTextureType_NORMALS, aiTextureType_NORMAL_CAMERA);
931 part.heightTexture = assimpTexture(&gfx,
scene,
material,
c.modelPath, aiTextureType_HEIGHT,
932 aiTextureType_DISPLACEMENT);
934 if (
c.material.hasBaseColor) {
935 part.r =
c.material.baseColorR;
936 part.g =
c.material.baseColorG;
937 part.b =
c.material.baseColorB;
938 part.a =
c.material.baseColorA;
940 if (!
c.material.baseColorTexture.empty())
941 part.texture = textureFromFile(&gfx,
c.modelPath,
c.material.baseColorTexture);
942 if (!
c.material.normalTexture.empty())
943 part.normalTexture = textureFromFile(&gfx,
c.modelPath,
c.material.normalTexture);
944 if (!
c.material.heightTexture.empty())
945 part.heightTexture = textureFromFile(&gfx,
c.modelPath,
c.material.heightTexture);
946 if (
c.material.hasMetallic) part.metallic =
c.material.metallic;
947 if (
c.material.hasRoughness) part.roughness =
c.material.roughness;
948 part.parallaxScale =
c.material.parallaxScale;
949 part.parallaxMinLayers =
c.material.parallaxMinLayers;
950 part.parallaxMaxLayers =
c.material.parallaxMaxLayers;
951 part.cellBombScale =
c.material.cellBombScale;
952 part.cellBombStrength =
c.material.cellBombStrength;
953 part.cellBombRotation =
c.material.cellBombRotation;
954 cached.push_back(part);
956 for (
unsigned child = 0; child <
node->mNumChildren; ++child) walk(
node->mChildren[child], world);
958 walk(
scene->mRootNode, aiMatrix4x4());
960 for (
const auto &part : cached) {
961 auto *e = graphics::Renderable3D::create();
966 {},
"housegen.layout"));
968 e->setMesh(part.mesh);
969 e->setPosition(i.x * moduleSize, i.z * floorHeight, i.y * moduleSize);
970 e->setYaw(
float(i.rotationDeg) * 3.14159265358979323846f / 180.f);
971 e->setTint(part.r, part.g, part.b, part.a);
972 if (part.texture) e->setTexture(part.texture);
973 if (part.normalTexture) e->setNormalTexture(part.normalTexture);
974 if (part.heightTexture) e->setHeightTexture(part.heightTexture);
975 e->setMetallic(part.metallic);
976 e->setRoughness(part.roughness);
977 e->setTexCellBomb(part.cellBombScale, part.cellBombStrength, part.cellBombRotation);
978 if (part.heightTexture && part.parallaxScale > 0.f)
979 e->setParallax(part.parallaxScale, part.parallaxMinLayers, part.parallaxMaxLayers);
980 entities.push_back(ecs::handle_of(e));
983 }
catch (
const std::exception &e) {
std::vector< eve::artifact::PartView > parts
struct SQVM * HSQUIRRELVM
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
const ColourScope * parent
std::array< float, 4 > rotation
std::array< uint32_t, 16 > material
std::unordered_set< std::string > loaded
std::vector< ecs::EntityHandle > entities
std::weak_ptr< PrimitiveScene > scene
std::set< std::string > values
const EntityFact * entity
RoadLaneDirection direction
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.
eve::Result< ResourcePin > pin(Resource *resource)
Keeps one cached resource alive across unload()/clear()/reload.
static ResourceManager & getInstance()
Returns the instance.
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
The canonical owning dynamic value used by data-facing protocols.
bool isArray() const noexcept
Return true when this value is an array.
bool isObject() const noexcept
Return true when this value is an object.
Value & at(std::size_t index)
Return a bounds-checked array element.
virtual Mesh * newMeshFromAssimp(const ::aiMesh &mesh)=0
Creates a mesh from assimp. @ownership Caller deletes unless documented otherwise.
GPU mesh handle (+ optional CPU morph targets).
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
房屋组件注册表(按 id 索引,支持分类/风格查询)。
eve::Result< void > loadFromJson(std::string_view json)
从 JSON / 文件加载组件。
std::vector< std::string > completePacks() const
所有能构成完整组件包(五个核心分类齐全)的风格标签。
eve::Result< void > loadFromFile(std::string_view filename)
eve::OptionalRef< const HouseComponent > find(std::string_view id) const
按 id 查询组件;缺失是正常查询结果。
std::vector< std::reference_wrapper< const HouseComponent > > byCategory(std::string_view category, std::string_view style={}) const
按分类(可选风格)查询组件。
eve::Result< void > registerComponent(const HouseComponent &component)
注册单个组件(id 重复会报错)。
std::vector< std::string > ids() const
全部组件 id。
bool hasCompletePack(std::string_view style) const
报告一个风格是否构成完整组件包。
程序化房屋生成模块(eve.HouseGen):组件库 + 布局生成。
eve::Result< void > instantiate(const HouseLayout &layout, graphics::Graphics &gfx, model3d::Model3D &models) const
Instantiate a generated layout through the current component library.
int getComponentCount() const
组件数量。
eve::Result< void > loadComponentsFromJson(const std::string &json)
从 JSON / 文件加载房屋组件库。
void clearComponents()
清空组件库。
static void expose(ssq::Class &cls)
eve::Result< void > generate(const HouseRequest &request, HouseLayout &layout)
按请求生成布局;失败返回结构化诊断。
eve::Result< void > loadComponentsFromFile(const std::string &filename)
HouseLayout newLayout() const
HouseRequest newRequest() const
工厂:生成请求 / 布局。
布局生成器:把 HouseRequest 解析为 HouseLayout(组件库驱动)。
eve::Result< void > generate(const HouseRequest &request, HouseLayout &out) const
生成布局;失败时不修改输出布局并返回结构化诊断。
一次生成的房屋布局:实例 + 房间 + 元信息,可 JSON 序列化 / 实例化。
std::string footprintStyle
布局风格结果。
eve::Result< void > validate(const HouseComponentLibrary &library) const
校验布局是否满足组件库规则。
std::string toJson() const
Serialize or restore the eve.house-layout version 1 JSON schema.
std::vector< HouseRoom > rooms
std::vector< uint8_t > footprintMask
eve::Result< void > writeComponentPoints(procgen::PointSet &out) const
Export component placements as canonical attributed procgen points.
eve::Result< void > fromJson(std::string_view json)
From json.
int footprintWidth
Canonical base-floor occupancy mask owned by this layout.
eve::Result< void > writeFootprintGrid(procgen::Grid2D &out) const
Export the generated footprint as the canonical procgen grid value.
std::vector< std::string > diagnostics
std::vector< HouseInstance > instances
组件实例 / 房间 / 诊断信息。
EVENGINE_API_FOUNDATION public API.
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
EVENGINE_API_FOUNDATION public API.
Resource module for decoding 3D models via medialoader (Assimp). Produces ModelData; GPU upload is gr...
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
void setDetail(int x, int y, int value)
Per-cell detail layer (0..255), parallel to cells. Semantics stay in cells (palette/GID compatible); ...
int getDetail(int x, int y) const
Returns the detail.
void resize(int width, int height)
Resize.
void fill(int semantic)
Fill.
void setCell(int x, int y, int semantic)
Sets the cell.
void setMeta(const std::string &key, const std::string &value)
Sets the meta.
Script-friendly collection of attributed 3D samples.
Result< void > trySetPointId(int index, std::uint64_t id)
Assign a unique non-zero point identity without mutating on failure.
int add(float x, float y, float z)
Result< void > trySetStringAttribute(int index, const std::string &name, const std::string &value)
Canonical checked string metadata write.
void setBounds(int index, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Set local-space point bounds before scale and rotation are applied.
void setYaw(int index, float yaw)
Sets the yaw.
void setPointSeed(int index, uint32_t seed)
Sets the point seed.
Result< void > trySetIntAttribute(int index, const std::string &name, std::int64_t value)
Canonical checked signed integer metadata write.
void reserve(std::size_t count)
Reserve point storage without changing point or attribute row counts.
RAII keep-alive for one RuntimeObjectRegistry entry.
T * get() const noexcept
Borrows the pinned object; valid until the pin is released.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
void exposeHouseGeneration(ssq::Table &table)
Register the procgen-owned house generation compatibility API.
std::uint64_t derivePointId(std::uint64_t namespaceId, std::uint64_t ordinal)
Deterministically derive a non-zero stable point identity.
std::unique_ptr< T > Owned
C++ owning storage used by an object factory.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
static TextureCreateInfo withMipmaps(bool aniso=true, float maxAniso=16.f)
With mipmaps.
std::vector< int > rotations
允许的旋转(度)。
HouseMaterialOverride material
材质覆盖。