12using namespace target_detail;
14 const std::string& buildingId,
const std::vector<BuildingEdgeCurvePoint>& controlPoints,
int subdivisions)
const {
15 std::vector<building::PlacementSystem::EdgeCurvePoint> runtimeControls;
16 runtimeControls.reserve(controlPoints.size());
18 runtimeControls.push_back({
static_cast<float>(
point.x),
static_cast<float>(
point.y)});
21 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected,
22 RuleId(
"editor.building.edge-curve-rejected"),
23 "Cubic edge curve sampling was rejected");
24 std::vector<BuildingEdgePathVertex> editorVertices;
25 editorVertices.reserve(
vertices.value().size());
27 auto path = makeEdgePath(buildingId, editorVertices);
31 return eve::editing::failed<DomainOperation>(EditorStatus::Failed,
32 RuleId(
"editor.building.edge-curve-encoding-failed"),
33 "Edge curve instances could not be encoded");
35 group.
id = world_->nextEdgeCurveGroupId();
36 group.buildingId = buildingId;
37 group.level = instances.value().front().level;
38 group.subdivisions = subdivisions;
39 for (
const BuildingEdgeCurvePoint&
point : controlPoints)
40 group.controlPoints.push_back({
static_cast<float>(
point.x),
static_cast<float>(
point.y)});
44 operation.inverseType =
"building.edge-curve.delete.v1";
47 return eve::editing::applied<DomainOperation>(std::move(
operation));
51 const std::string& buildingId,
const std::vector<BuildingEdgeCurvePoint>& controlPoints,
int subdivisions,
52 const std::string& surfaceName)
const {
54 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected,
RuleId(
"editor.building.world-required"),
55 "Placement world is unavailable");
56 auto operation = makeEdgeCubicBezier(buildingId, controlPoints, subdivisions);
58 std::vector<building::PlacementSystem::EdgeCurvePoint> controls;
59 controls.reserve(controlPoints.size());
61 controls.push_back({
static_cast<float>(
point.x),
static_cast<float>(
point.y)});
64 return eve::editing::failed<DomainOperation>(
65 EditorStatus::Rejected,
RuleId(
"editor.building.edge-curve-surface-rejected"),
66 surface.error() ? surface.error()->message() :
"Curve could not be sampled on the requested surface");
67 auto parsed = parseEdgeCurve(
operation.value().payload);
69 return eve::editing::failed<DomainOperation>(EditorStatus::Failed,
70 RuleId(
"editor.building.edge-curve-encoding-failed"),
71 "Edge curve instances could not be encoded");
72 parsed.value().group.surfaceProviderName = surface.value().providerName;
73 parsed.value().group.surfaceId = surface.value().surfaceId;
74 parsed.value().group.surfaceRevision = surface.value().surfaceRevision;
75 parsed.value().group.surfaceSamples = surface.value().samples;
77 enriched.
payload = edgeCurveValue(parsed.value().group, parsed.value().instances);
79 return eve::editing::applied<DomainOperation>(std::move(enriched));
83 const std::string& buildingId,
const std::vector<BuildingEdgeCurvePoint>& controlPoints,
int subdivisions,
84 int replacingMemberInstanceId,
const std::string& surfaceName)
const {
87 result.controlPoints = controlPoints;
89 result.status = EditorStatus::Rejected;
92 DiagnosticSeverity::Error,
"Placement world is unavailable"));
95 std::vector<building::PlacementSystem::EdgeCurvePoint> controls;
96 controls.reserve(controlPoints.size());
98 controls.push_back({
static_cast<float>(
point.x),
static_cast<float>(
point.y)});
101 result.status = EditorStatus::Rejected;
104 DiagnosticSeverity::Error,
"Cubic edge curve controls or subdivisions are invalid"));
108 result.sampledVertices.push_back({vertex.x, vertex.y});
109 std::unique_ptr<building::PlacementWorld> previewOwner;
110 building::PlacementWorld* previewWorld = world_;
111 if (replacingMemberInstanceId > 0) {
112 auto replacingGroup = world_->edgeCurveGroupForInstance(replacingMemberInstanceId);
113 if (!replacingGroup.ok()) {
114 result.status = EditorStatus::NotFound;
117 DiagnosticSeverity::Error,
"Replacement preview instance does not belong to a curve group"));
120 previewOwner = world_->cloneState();
122 building::PlacementSystem::removeBuilding(previewOwner.get(),
instanceId);
123 previewWorld = previewOwner.get();
127 result.status = EditorStatus::Rejected;
131 preview.
error() ? preview.
error()->
message() :
"Cubic edge curve preview was rejected"));
137 if (!surfaceName.empty()) {
140 result.status = EditorStatus::Rejected;
144 surface.
error() ? surface.
error()->
message() :
"Curve surface preview was rejected"));
147 result.surfaceProviderName = surface.value().providerName;
148 result.surfaceId = surface.value().surfaceId;
149 result.surfaceRevision = surface.value().surfaceRevision;
150 for (
const building::EdgeCurveSurfaceSample& sample : surface.
value().samples)
151 result.surfaceSamples.push_back(
154 result.status = EditorStatus::Applied;
159 const std::string& buildingId,
const std::vector<BuildingEdgeCurvePoint>& controlPoints,
int subdivisions,
160 int level,
int replacingMemberInstanceId,
const std::string& surfaceName)
const {
165 previewEdgeCubicBezier(buildingId, controlPoints, subdivisions, replacingMemberInstanceId, surfaceName);
168 if (!world_)
return gizmo;
169 const auto project = [&](
double gx,
double gy) {
170 float ox = 0.f,
oy = 0.f, xx = 0.f, xy = 0.f, yx = 0.f, yy = 0.f;
171 world_->cellToWorldPlane(0, 0,
ox,
oy);
172 world_->cellToWorldPlane(1, 0, xx, xy);
173 world_->cellToWorldPlane(0, 1, yx, yy);
174 const double px =
ox + gx * (xx -
ox) + gy * (yx -
ox);
175 const double py =
oy + gx * (xy -
oy) + gy * (yy -
oy);
176 const double elevation =
static_cast<double>(
level) * world_->getFloorHeight();
177 if (!surfaceName.empty()) {
179 static_cast<float>(
py));
180 if (
hit.ok())
return std::array<double, 3>{
hit.value().worldX,
hit.value().worldY,
hit.value().worldZ};
182 return world_->getGridPlaneName() ==
"xz" ? std::array<double, 3>{
px,
elevation,
py}
185 const auto addLine = [&](
const std::string&
id,
const std::array<double, 3>&
a,
const std::array<double, 3>&
b,
186 const std::array<double, 4>&
color,
bool dashed) {
194 line.length = std::sqrt(
line.direction[0] *
line.direction[0] +
line.direction[1] *
line.direction[1] +
195 line.direction[2] *
line.direction[2]);
196 if (
line.length > 0.0)
197 for (
double& component :
line.direction) component /=
line.length;
199 line.dashed = dashed;
202 const std::array<double, 4> accepted{0.2, 0.95, 0.35, 1.0};
203 const std::array<double, 4> rejected{0.95, 0.2, 0.2, 1.0};
204 const auto& pathColor = preview.
status == EditorStatus::Applied ? accepted : rejected;
210 handle.radius = world_->getCellSize() * 0.15;
211 handle.color =
index == 0 ||
index + 1 == controlPoints.size() ? std::array<double, 4>{0.2, 0.65, 1.0, 1.0}
212 : std::array<double, 4>{1.0, 0.7, 0.15, 1.0};
215 addLine(
"curve.tangent." + std::to_string(
index - 1),
216 project(controlPoints[
index - 1].
x, controlPoints[
index - 1].
y),
217 project(controlPoints[
index].
x, controlPoints[
index].
y), {0.65, 0.65, 0.7, 0.8},
true);
223 addLine(
"curve.path." + std::to_string(
index - 1), {
a.worldX,
a.worldY,
a.worldZ},
224 {
b.worldX,
b.worldY,
b.worldZ}, pathColor,
false);
228 addLine(
"curve.path." + std::to_string(
index - 1),
236 int memberInstanceId,
const std::vector<BuildingEdgeCurvePoint>& controlPoints,
int subdivisions)
const {
238 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected,
RuleId(
"editor.building.world-required"),
239 "Placement world is unavailable");
240 auto currentGroup = world_->edgeCurveGroupForInstance(memberInstanceId);
241 if (!currentGroup.ok())
242 return eve::editing::failed<DomainOperation>(EditorStatus::NotFound,
243 RuleId(
"editor.building.edge-curve-group-not-found"),
244 "Instance does not belong to a curve group");
245 std::unique_ptr<building::PlacementWorld> draftWorld = world_->cloneState();
246 for (
int instanceId : currentGroup.value().instanceIds)
248 return eve::editing::failed<DomainOperation>(EditorStatus::Failed,
249 RuleId(
"editor.building.edge-curve-draft-delete-failed"),
250 "Curve update could not create an isolated draft world");
252 auto desiredOperation =
253 draftTarget.
makeEdgeCubicBezier(currentGroup.value().buildingId, controlPoints, subdivisions);
254 if (!desiredOperation.ok())
return desiredOperation;
255 auto desired = parseEdgeCurve(desiredOperation.value().payload);
257 return eve::editing::failed<DomainOperation>(EditorStatus::Failed,
258 RuleId(
"editor.building.edge-curve-encoding-failed"),
259 "Updated edge curve could not be encoded");
260 desired.value().group.id = currentGroup.value().id;
261 if (!currentGroup.value().surfaceProviderName.empty()) {
262 std::vector<building::PlacementSystem::EdgeCurvePoint> runtimeControls;
263 runtimeControls.reserve(controlPoints.size());
265 runtimeControls.push_back({
static_cast<float>(
point.x),
static_cast<float>(
point.y)});
267 *world_, currentGroup.value().surfaceProviderName, runtimeControls, subdivisions);
269 return eve::editing::failed<DomainOperation>(
270 EditorStatus::Rejected,
RuleId(
"editor.building.edge-curve-surface-rejected"),
271 "Updated curve could not be sampled on its committed surface provider");
272 desired.value().group.surfaceProviderName = surface.value().providerName;
273 desired.value().group.surfaceId = surface.value().surfaceId;
274 desired.value().group.surfaceRevision = surface.value().surfaceRevision;
275 desired.value().group.surfaceSamples = surface.value().samples;
277 std::vector<BuildingInstanceSnapshot> beforeInstances;
283 operation.payload = edgeCurveValue(desired.value().group, desired.value().instances);
284 operation.inverse = edgeCurveValue(currentGroup.value(), beforeInstances);
286 return eve::editing::applied<DomainOperation>(std::move(
operation));
290 double worldZ)
const {
291 if (!world_ || !std::isfinite(worldX) || !std::isfinite(worldY) || !std::isfinite(worldZ))
292 return eve::editing::failed<BuildingEdgeCurvePoint>(
293 EditorStatus::Rejected,
RuleId(
"editor.building.curve-world-point-invalid"),
294 "Curve drag requires a finite world-space point and an available world");
295 float ox = 0.f,
oy = 0.f, xx = 0.f, xy = 0.f, yx = 0.f, yy = 0.f;
296 world_->cellToWorldPlane(0, 0,
ox,
oy);
297 world_->cellToWorldPlane(1, 0, xx, xy);
298 world_->cellToWorldPlane(0, 1, yx, yy);
299 const double bxX = xx -
ox;
300 const double bxY = xy -
oy;
301 const double byX = yx -
ox;
302 const double byY = yy -
oy;
303 const double determinant = bxX * byY - bxY * byX;
304 if (std::abs(determinant) < 1e-9)
305 return eve::editing::failed<BuildingEdgeCurvePoint>(EditorStatus::Unsupported,
306 RuleId(
"editor.building.curve-grid-basis-singular"),
307 "Curve drag requires an invertible affine grid basis");
308 const double planeX = worldX;
309 const double planeY = world_->getGridPlaneName() ==
"xz" ? worldZ : worldY;
310 const double dx = planeX -
ox;
311 const double dy = planeY -
oy;
313 point.
x = (
dx * byY -
dy * byX) / determinant;
314 point.y = (bxX *
dy - bxY *
dx) / determinant;
315 return eve::editing::applied<BuildingEdgeCurvePoint>(
point);
ActionParameterOperation operation
AbilityActivationGroup group
std::array< double, 2 > vertices[3]
Move-only operation result carrying either a value or Status.
UUID-backed identifier adapter for legacy textual boundaries.
static eve::Result< EdgeCurveSurface > sampleEdgeCurveSurface(const PlacementWorld &world, const std::string &surfaceName, const std::vector< EdgeCurvePoint > &controlPoints, int subdivisions)
Sample one same-identity custom surface frame at every analytic curve segment.
static eve::Result< std::vector< CornerAddress > > sampleEdgeCubicBezier(const std::vector< EdgeCurvePoint > &controlPoints, int subdivisions)
Deterministically rasterize four cubic Bezier controls to adjacent grid vertices.
static eve::Result< EdgePathPreview > previewEdgeCubicBezier(PlacementWorld *world, const std::string &buildingId, const std::vector< EdgeCurvePoint > &controlPoints, int subdivisions)
Sample and validate a cubic Bezier edge curve without mutating the world.
static eve::Result< PlacementHit > sampleSurface(const PlacementWorld &world, const std::string &name, float x, float y)
Sample a named placement surface.
static bool removeBuilding(PlacementWorld *world, int instanceId)
Live PlacementWorld target with reversible place/move/remove operations.
Result< DomainOperation > makeEdgeCubicBezier(const std::string &buildingId, const std::vector< BuildingEdgeCurvePoint > &controlPoints, int subdivisions) const
Plan one atomic reversible cubic Bezier edge-curve gesture.
editing::DiagnosticSeverity DiagnosticSeverity
building::PlacedBuilding runtime(const BuildingInstanceSnapshot &value)
Decode a previously validated snapshot into an owning runtime candidate.
BuildingInstanceSnapshot snapshot(const building::PlacedBuilding &placed)
Copy a runtime instance into its canonical owning persistence record.
EditorValue edgeCurveValue(const building::EdgeCurveGroup &g, const std::vector< BuildingInstanceSnapshot > &p)
auto parseInstances(const EditorValue &v)
editing::DomainOperation DomainOperation
building::BuildingInstanceSnapshot BuildingInstanceSnapshot
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
double sample(const Heightmap &map, double u, double v)
Sample.
Build metadata (engine git commit, build time, third-party version).
DiagnosticCode
Stable machine-readable diagnostic codes.
Canonical address of one logical grid vertex used by corner objects.
World-owned authoritative description and membership of one committed edge curve.
Runtime-neutral cubic Bezier control point in logical grid-vertex space.
Immutable revision-tagged result for one interactive cubic curve draft.
std::vector< EditorDiagnostic > diagnostics
std::vector< BuildingEdgePathVertex > sampledVertices
std::vector< BuildingEdgeCurveSurfaceSample > surfaceSamples
DomainOperation public API.
Renderer-neutral wire primitive for authoring viewport overlays.
Immutable revision-tagged overlay snapshot consumed by any viewport renderer.
std::vector< GizmoPrimitive > primitives
std::vector< Diagnostic > diagnostics