15 placementKind_ =
"cell";
18 surfacePatchStale_ =
false;
19 surfaceHitMissing_ =
false;
22 surfaceNormalX_ = 0.f;
23 surfaceNormalY_ = 1.f;
24 surfaceNormalZ_ = 0.f;
25 surfaceTangentX_ = 1.f;
26 surfaceTangentY_ = 0.f;
27 surfaceTangentZ_ = 0.f;
28 surfaceSampleCount_ = 0;
29 surfaceMaxSlopeDegrees_ = 0.f;
30 surfaceHeightDelta_ = 0.f;
34 placementKind_ =
"cell";
39 surfacePatchStale_ =
false;
40 surfaceHitMissing_ =
false;
43 surfaceNormalX_ = 0.f;
44 surfaceNormalY_ = 1.f;
45 surfaceNormalZ_ = 0.f;
46 surfaceTangentX_ = 1.f;
47 surfaceTangentY_ = 0.f;
48 surfaceTangentZ_ = 0.f;
49 surfaceSampleCount_ = 0;
50 surfaceMaxSlopeDegrees_ = 0.f;
51 surfaceHeightDelta_ = 0.f;
55 placementKind_ =
"cell";
60 surfacePatchStale_ =
false;
61 surfaceHitMissing_ =
false;
64 surfaceNormalX_ = 0.f;
65 surfaceNormalY_ = 1.f;
66 surfaceNormalZ_ = 0.f;
67 surfaceTangentX_ = 1.f;
68 surfaceTangentY_ = 0.f;
69 surfaceTangentZ_ = 0.f;
70 surfaceSampleCount_ = 0;
71 surfaceMaxSlopeDegrees_ = 0.f;
72 surfaceHeightDelta_ = 0.f;
79 surfacePatchStale_ =
false;
80 surfaceHitMissing_ =
false;
83 surfaceNormalX_ = 0.f;
84 surfaceNormalY_ = 1.f;
85 surfaceNormalZ_ = 0.f;
86 surfaceTangentX_ = 1.f;
87 surfaceTangentY_ = 0.f;
88 surfaceTangentZ_ = 0.f;
89 surfaceSampleCount_ = 0;
90 surfaceMaxSlopeDegrees_ = 0.f;
91 surfaceHeightDelta_ = 0.f;
96 if (!surfaceId_.empty()) surfacePatchStale_ =
true;
98 if (!surfaceHitMissing_) reason_.clear();
107 placementKind_ =
"cell";
113 elevation_ =
s.elevation;
116 surfacePatchStale_ =
false;
117 surfaceHitMissing_ =
false;
119 surfaceRevision_ = 0;
120 surfaceNormalX_ = 0.f;
121 surfaceNormalY_ = 1.f;
122 surfaceNormalZ_ = 0.f;
123 surfaceTangentX_ = 1.f;
124 surfaceTangentY_ = 0.f;
125 surfaceTangentZ_ = 0.f;
126 surfaceSampleCount_ = 0;
127 surfaceMaxSlopeDegrees_ = 0.f;
128 surfaceHeightDelta_ = 0.f;
133 placementKind_ =
"cell";
139 elevation_ =
s.elevation;
142 surfacePatchStale_ =
false;
143 surfaceHitMissing_ =
false;
145 surfaceRevision_ = 0;
146 surfaceNormalX_ = 0.f;
147 surfaceNormalY_ = 1.f;
148 surfaceNormalZ_ = 0.f;
149 surfaceTangentX_ = 1.f;
150 surfaceTangentY_ = 0.f;
151 surfaceTangentZ_ = 0.f;
152 surfaceSampleCount_ = 0;
153 surfaceMaxSlopeDegrees_ = 0.f;
154 surfaceHeightDelta_ = 0.f;
158 if (placementKind_ !=
"edge")
return {};
166 placementKind_ =
"edge";
168 reason_ =
"invalid_edge_direction";
171 placementKind_ =
"edge";
172 edge_ = std::move(
result).takeValue();
175 float ax = 0.f, ay = 0.f, bx = 0.f, by = 0.f;
176 world->cellToWorldPlane(edge_.
x, edge_.
y, ax, ay);
179 worldX_ = (ax + bx) * 0.5f;
180 worldY_ = (ay + by) * 0.5f;
182 surfacePatchStale_ =
false;
183 surfaceHitMissing_ =
false;
185 surfaceRevision_ = 0;
192 placementKind_ =
"corner";
196 world->cellToWorldPlane(vertexX, vertexY, worldX_, worldY_);
198 surfacePatchStale_ =
false;
199 surfaceHitMissing_ =
false;
201 surfaceRevision_ = 0;
202 surfaceSampleCount_ = 0;
209 placementKind_ =
"free";
213 grid::worldToCell(world->getGrid(), worldX, worldY, cellX_, cellY_, world->getWidth(),
216 surfacePatchStale_ =
false;
217 surfaceHitMissing_ =
false;
219 surfaceRevision_ = 0;
220 surfaceSampleCount_ = 0;
227 surfaceProviderName_ = surface;
234 surfaceRevision_ = 0;
235 surfaceNormalX_ = 0.f;
236 surfaceNormalY_ = 1.f;
237 surfaceNormalZ_ = 0.f;
238 surfaceTangentX_ = 1.f;
239 surfaceTangentY_ = 0.f;
240 surfaceTangentZ_ = 0.f;
241 surfaceSampleCount_ = 0;
242 surfaceMaxSlopeDegrees_ = 0.f;
243 surfaceHeightDelta_ = 0.f;
244 surfacePatchStale_ =
false;
245 surfaceHitMissing_ =
true;
248 :
"invalid_surface_hit";
255 if (definition && definition->placementKind ==
"free") placementKind_ =
"free";
256 surfaceId_ = std::move(
hit.surfaceId);
257 surfaceRevision_ =
hit.surfaceRevision;
258 surfaceNormalX_ =
hit.normalX;
259 surfaceNormalY_ =
hit.normalY;
260 surfaceNormalZ_ =
hit.normalZ;
261 surfaceTangentX_ =
hit.tangentX;
262 surfaceTangentY_ =
hit.tangentY;
263 surfaceTangentZ_ =
hit.tangentZ;
264 surfaceSampleCount_ =
static_cast<int>(patch.
samples.size());
267 surfacePatchStale_ =
false;
273 reason_ =
"no_world";
276 if (surfaceHitMissing_)
return false;
277 if (surfacePatchStale_) {
278 setFromSurface(world, surfaceProviderName_, surfaceInputX_, surfaceInputY_);
279 if (surfaceHitMissing_)
return false;
282 if (definition && definition->placementKind ==
"edge") {
283 if (placementKind_ !=
"edge") {
285 reason_ =
"edge_requires_edge_address";
293 if (definition && definition->placementKind ==
"corner") {
294 if (placementKind_ !=
"corner") {
296 reason_ =
"corner_requires_corner_address";
303 if (definition && definition->placementKind ==
"free") {
304 if (placementKind_ !=
"free") {
306 reason_ =
"free_requires_free_address";
310 world, buildingId_, worldX_, worldY_, 0, &reason_,
311 std::numeric_limits<int>::min(), rotationDeg_);
312 if (valid_ && surfaceMaxSlopeDegrees_ > definition->maxSurfaceSlopeDegrees) {
314 reason_ =
"surface_slope";
316 if (valid_ && definition->maxSurfaceHeightDelta >= 0.f &&
317 surfaceHeightDelta_ > definition->maxSurfaceHeightDelta) {
319 reason_ =
"surface_height_delta";
325 query.buildingId = buildingId_;
326 query.cellX = cellX_;
327 query.cellY = cellY_;
328 query.worldX = worldX_;
329 query.worldY = worldY_;
330 query.elevation = elevation_;
331 query.rotationDeg = rotationDeg_;
332 query.surfaceId = surfaceId_;
333 query.surfaceRevision = surfaceRevision_;
334 query.surfaceNormalX = surfaceNormalX_;
335 query.surfaceNormalY = surfaceNormalY_;
336 query.surfaceNormalZ = surfaceNormalZ_;
337 query.surfaceSampleCount = surfaceSampleCount_;
338 query.surfaceMaxSlopeDegrees = surfaceMaxSlopeDegrees_;
339 query.surfaceHeightDelta = surfaceHeightDelta_;
341 valid_ = PlacementSystem::canPlaceQuery(world, query, &reason);
Pure cell/world projection helpers for GridConfig.
RoadLaneDirection direction
static const BuildingDefinition * find(const std::string &id)
Finds .
void setFree(PlacementWorld *world, float worldX, float worldY, float elevation=0.f)
Set an exact unsnapped world-plane anchor for a free-domain definition.
void setFromWorld(PlacementWorld *world, float worldX, float worldY)
按世界吸附模式,从世界坐标刷新格子与世界位姿。
void setRotationDeg(float deg)
Sets the rotation deg.
void setElevation(float elevation)
Sets the elevation.
bool validate(PlacementWorld *world)
对当前姿态做校验,写入 valid_/reason_。
void setFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
Sets the from world 3 d.
void setCorner(PlacementWorld *world, int vertexX, int vertexY)
Snap this ghost to one canonical grid vertex.
std::string getEdgeAxis() const
Canonical edge axis (horizontal/vertical), empty for cell ghosts.
void setEdge(PlacementWorld *world, int cellX, int cellY, const std::string &direction)
Snap this ghost to a canonicalized cell edge and its exact midpoint pose.
void setWorld(float worldX, float worldY)
Sets the world.
void rotateBy(float deltaDeg)
Rotate by.
void setCell(int cellX, int cellY)
Sets the cell.
void setFromSurface(PlacementWorld *world, const std::string &surface, float x, float y)
Sets the from surface.
void setBuildingId(const std::string &id)
Sets the building id.
static SnapResult snap(const PlacementWorld &world, const std::string &buildingId, float worldX, float worldY)
static SnapResult snap3D(const PlacementWorld &world, const std::string &buildingId, float worldX, float worldY, float worldZ)
static bool canPlaceFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min(), float rotationDeg=0.f)
Validate an exact free-domain world-plane anchor and circular or oriented-box footprint.
static float normalizeRotation(const std::string &buildingId, float rotationDeg)
规范化旋转角(cardinal → 0/90/180/270;none → 0)。
static bool canPlaceCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate a corner-domain placement at one canonical grid vertex.
static eve::Result< SurfacePatch > sampleSurfacePatch(const PlacementWorld &world, const std::string &buildingId, const std::string &surfaceName, float x, float y, float rotationDegrees=0.f)
Sample the occupied cells of a rotated footprint relative to an exact anchor hit.
static eve::Result< EdgeAddress > canonicalEdge(int cellX, int cellY, const std::string &direction)
Normalize a cell-relative cardinal direction to a unique edge address.
static bool canPlaceEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, const std::string &direction, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate an edge-domain placement without mutating the world.
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
void worldToCell(const GridConfig &cfg, float px, float py, int &cx, int &cy, int mapW, int mapH)
Maps planar coordinates to the nearest cell. Staggered/hex layouts use a bounded nearest-neighbor sea...
Canonical address of one logical grid vertex used by corner objects.
One sampled point and orthonormal frame on a placement surface.
Surface samples and continuity metrics for one rotated building footprint.
std::vector< SurfacePatchSample > samples