17Result<std::string> textFile(
const UnityProjectImportRequest&
request,
const std::string&
path) {
24 "Unity source exceeds budget",
path, {},
"asset.import"));
25 if (std::find(
found->second.begin(),
found->second.end(), std::uint8_t(0)) !=
found->second.end())
31std::optional<std::string> firstMatch(std::string_view
text,
const std::regex& expression, std::size_t
group = 1) {
32 std::match_results<std::string_view::const_iterator> match;
33 if (!std::regex_search(
text.begin(),
text.end(), match, expression) ||
group >= match.size())
return std::nullopt;
37std::optional<std::uint64_t> parseUnsignedText(std::string_view
text) {
38 std::uint64_t
value = 0;
44Result<float> parseFloat(std::string_view
text, std::string
path) {
51 std::move(
path), {},
"asset.import"));
56 const auto found =
object.find(std::string(
name));
57 return found ==
object.end() ? nullptr : &
found->second;
60std::string terrainDetailsPath(
const UnityProjectImportRequest&
request) {
61 if (!
request.terrainDetailsPath.empty())
return request.terrainDetailsPath;
62 if (
request.terrainDataPath.empty())
return {};
63 const auto adjacent =
request.terrainDataPath +
".eve-details.json";
64 return request.files.contains(adjacent) ? adjacent : std::string{};
67Result<void> appendTerrainDetailInstances(
const UnityProjectImportRequest&
request, CanonicalTerrainInput&
terrain,
68 std::vector<ImportFinding>&
findings) {
69 const auto detailsPath = terrainDetailsPath(
request);
80 const auto* instances = instancesValue ? instancesValue->getIf<
Value::Array>() : nullptr;
81 const auto* prototypes = prototypesValue ? prototypesValue->getIf<
Value::Array>() : nullptr;
82 if (!schema || !schema->isString() || schema->asString() !=
"eve.unity-terrain-details" || !
version ||
84 !instances || !prototypes)
87 detailsPath, {},
"asset.import"));
91 "terrain detail instance count exceeds import budget",
92 detailsPath, {},
"asset.import"));
98 "$.prototypes[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
99 const double parsed =
value->isInt64() ? double(
value->asInt()) :
value->asDouble();
100 if (!std::isfinite(parsed) || parsed < -std::numeric_limits<float>::max() ||
101 parsed > std::numeric_limits<float>::max())
104 "$.prototypes[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
109 const auto* wind = windValue ? windValue->getIf<
Value::Object>() : nullptr;
110 auto rootNumber = [&](std::string_view
name) -> Result<float> {
115 "$.wavingGrass." + std::string(
name), {},
"asset.import"));
116 const double parsed =
value->isInt64() ? double(
value->asInt()) :
value->asDouble();
117 if (!std::isfinite(parsed) || parsed < 0.0 || parsed > std::numeric_limits<float>::max())
120 "$.wavingGrass." + std::string(
name), {},
"asset.import"));
123 auto amount = rootNumber(
"amount");
124 auto speed = rootNumber(
"speed");
125 auto strength = rootNumber(
"strength");
126 const Value* tintValue = wind ?
member(*wind,
"tint") : nullptr;
130 !amount ? amount.status()
134 "terrain waving grass tint is invalid",
135 "$.wavingGrass.tint", {},
"asset.import"))
137 for (std::size_t component = 0; component < 4; ++component) {
138 if (!(*
tint)[component].isNumeric())
140 "terrain waving grass tint is invalid",
141 "$.wavingGrass.tint", {},
"asset.import"));
142 const double value = (*tint)[component].isInt64() ? double((*
tint)[component].asInt())
143 : (*
tint)[component].asDouble();
144 if (!std::isfinite(
value) || value < 0.0 || value > 1.0)
146 "terrain waving grass tint must be normalized RGBA",
147 "$.wavingGrass.tint", {},
"asset.import"));
148 terrain.wavingGrassTint[component] =
static_cast<float>(
value);
151 terrain.wavingGrassAmount = amount.value();
152 terrain.wavingGrassSpeed = speed.value();
155 std::vector<CanonicalTerrainDetailPrototype> detachedPrototypes;
156 detachedPrototypes.reserve(prototypes->size());
157 std::set<std::string> prototypeIds;
160 const Value*
id =
object ?
member(*
object,
"prototype") : nullptr;
161 const Value* mode =
object ?
member(*
object,
"renderMode") : nullptr;
162 const Value*
mesh =
object ?
member(*
object,
"usePrototypeMesh") : nullptr;
165 if (!
object || !
id || !
id->isString() ||
id->asString().empty() ||
168 !mode || !mode->isString() ||
169 (mode->asString() !=
"GrassBillboard" && mode->asString() !=
"Grass" && mode->asString() !=
"VertexLit") ||
173 "$.prototypes[" + std::to_string(
index) +
"]", {},
"asset.import"));
174 CanonicalTerrainDetailPrototype prototype;
175 prototype.prototype =
id->asString();
176 prototype.renderMode = mode->asString();
177 prototype.usePrototypeMesh =
mesh->asBool();
178 prototype.useInstancing =
instancing->asBool();
179 prototype.noiseSeed =
seed->asInt();
180 const std::string texturePrefix =
"unity-texture-guid:";
181 const std::string objectPrefix =
"unity-guid:";
182 if (!prototype.usePrototypeMesh && prototype.prototype.starts_with(texturePrefix)) {
186 prototype.resourceAsset =
resource.value().format();
187 }
else if (prototype.usePrototypeMesh && prototype.prototype.starts_with(objectPrefix)) {
191 prototype.resourceAsset =
resource.value().format();
195 "$.prototypes[" + std::to_string(
index) +
"].prototype", {},
"asset.import"));
197 auto minWidth =
number(*
object,
"minWidth",
index);
198 auto maxWidth =
number(*
object,
"maxWidth",
index);
199 auto minHeight =
number(*
object,
"minHeight",
index);
200 auto maxHeight =
number(*
object,
"maxHeight",
index);
201 auto noiseSpread =
number(*
object,
"noiseSpread",
index);
203 auto align =
number(*
object,
"alignToGround",
index);
204 auto jitter =
number(*
object,
"positionJitter",
index);
205 if (!minWidth || !maxWidth || !minHeight || !maxHeight || !noiseSpread || !
density || !align || !jitter)
207 : !maxWidth ? maxWidth.
status()
208 : !minHeight ? minHeight.
status()
209 : !maxHeight ? maxHeight.
status()
210 : !noiseSpread ? noiseSpread.
status()
214 prototype.minWidth = minWidth.
value();
215 prototype.maxWidth = maxWidth.value();
216 prototype.minHeight = minHeight.value();
217 prototype.maxHeight = maxHeight.value();
218 prototype.noiseSpread = noiseSpread.value();
219 prototype.density =
density.value();
220 prototype.alignToGround = align.value();
221 prototype.positionJitter = jitter.value();
223 auto color = [&](std::string_view
name, std::array<float, 4>&
output) -> Result<void> {
226 if (!array || array->size() != 4)
229 "$.prototypes[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
230 for (std::size_t component = 0; component < 4; ++component) {
231 if (!(*array)[component].isNumeric())
234 const double value = (*array)[component].isInt64() ? double((*array)[component].asInt())
235 : (*array)[component].asDouble();
236 if (!std::isfinite(
value) || value < 0.0 || value > 1.0)
239 {},
"asset.import"));
244 auto healthy =
color(
"healthyColor", prototype.healthyColor);
245 auto dry =
color(
"dryColor", prototype.dryColor);
247 auto padding =
number(*
object,
"holeEdgePadding",
index);
248 const Value* densityScaling =
member(*
object,
"useDensityScaling");
249 if (!healthy || !dry || !bend || !padding || !densityScaling || !densityScaling->isBool())
251 !healthy ? healthy.status()
254 : !padding ? padding.
status()
256 "terrain detail density scaling is invalid",
257 {}, {},
"asset.import"))
259 prototype.bendFactor = bend.
value();
260 prototype.holeEdgePadding = padding.value();
261 prototype.useDensityScaling = densityScaling->asBool();
263 detachedPrototypes.push_back(std::move(prototype));
266 std::size_t
index) -> Result<void> {
269 if (!array || array->size() !=
count)
272 "$.instances[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
273 for (std::size_t component = 0; component <
count; ++component) {
274 if (!(*array)[component].isNumeric())
277 "$.instances[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
279 (*array)[component].isInt64() ? double((*array)[component].asInt()) : (*array)[component].asDouble();
280 if (!std::isfinite(
number) ||
number < -std::numeric_limits<float>::max() ||
281 number > std::numeric_limits<float>::max())
284 "$.instances[" + std::to_string(
index) +
"]." + std::string(
name), {},
"asset.import"));
289 std::vector<CanonicalTerrainInstance> detached;
290 detached.reserve(instances->size());
293 const Value* prototype =
object ?
member(*
object,
"prototype") : nullptr;
294 if (!
object || !prototype || !prototype->isString() || prototype->asString().empty() ||
299 "$.instances[" + std::to_string(
index) +
"].prototype", {},
"asset.import"));
300 if (!prototypeIds.contains(prototype->asString()))
303 "$.instances[" + std::to_string(
index) +
"].prototype", {},
"asset.import"));
304 CanonicalTerrainInstance instance;
305 instance.prototype = prototype->asString();
313 detached.push_back(std::move(instance));
315 terrain.detailPrototypes.insert(
terrain.detailPrototypes.end(), std::make_move_iterator(detachedPrototypes.begin()),
316 std::make_move_iterator(detachedPrototypes.end()));
317 terrain.instances.insert(
terrain.instances.end(), std::make_move_iterator(detached.begin()),
318 std::make_move_iterator(detached.end()));
320 "Unity public ComputeDetailInstanceTransforms output imported as canonical instances"});
324std::optional<std::string> guidFromMeta(
const UnityProjectImportRequest&
request,
const std::string& assetPath) {
325 const auto found =
request.files.find(assetPath +
".meta");
327 const std::string
text(
found->second.begin(),
found->second.end());
328 auto guid = firstMatch(
text, std::regex(R
"((?:^|\n)guid:\s*([0-9a-fA-F]{32})(?:\r?\n|\r?$))"));
333std::map<std::string, std::string> guidPaths(
const UnityProjectImportRequest&
request) {
334 std::map<std::string, std::string>
result;
336 if (!
path.ends_with(
".meta"))
continue;
338 auto guid = firstMatch(
text, std::regex(R
"((?:^|\n)guid:\s*([0-9a-fA-F]{32})(?:\r?\n|\r?$))"));
344std::vector<std::string> sectionEntries(std::string_view yaml, std::string_view
heading) {
346 if (
start == std::string_view::npos)
return {};
347 const auto lineEnd = yaml.find(
'\n',
start);
348 if (lineEnd == std::string_view::npos)
return {};
349 std::vector<std::string>
entries;
351 std::istringstream
lines(std::string(yaml.substr(lineEnd + 1)));
354 if (
line.starts_with(
" m_") && !
line.starts_with(
" "))
break;
355 if (
line.starts_with(
" - ") ||
line.starts_with(
" - ")) {
366Result<CanonicalTerrainInput> parseTerrain(
const UnityProjectImportRequest&
request,
367 const std::map<std::string, std::string>&
paths,
368 std::vector<ImportFinding>&
findings) {
371 const std::string yaml = std::move(textResult).takeValue();
372 auto resolutionText = firstMatch(yaml, std::regex(R
"((?:m_HeightmapResolution|m_Resolution):\s*([0-9]+))"));
374 firstMatch(yaml, std::regex(R
"(m_HeightmapScale:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})"), 1);
376 firstMatch(yaml, std::regex(R
"(m_HeightmapScale:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})"), 2);
378 firstMatch(yaml, std::regex(R
"(m_HeightmapScale:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})"), 3);
379 auto heightsHex = firstMatch(yaml, std::regex(R
"(m_Heights:\s*([0-9a-fA-F]+))"));
380 if (!resolutionText || !scaleMatchX || !scaleMatchY || !scaleMatchZ || !heightsHex)
383 request.terrainDataPath, {},
"asset.import"));
384 std::uint64_t resolution = 0;
385 for (
char digit : *resolutionText) {
386 if (resolution > (std::numeric_limits<std::uint32_t>::max() - (digit -
'0')) / 10)
389 resolution = resolution * 10 + (digit -
'0');
392 resolution > std::numeric_limits<std::uint64_t>::max() / resolution)
395 const std::uint64_t samples = resolution * resolution;
396 if (heightsHex->size() != samples * 4)
400 auto spacingX = parseFloat(*scaleMatchX,
"m_HeightmapScale.x");
401 auto scaleY = parseFloat(*scaleMatchY,
"m_HeightmapScale.y");
402 auto spacingZ = parseFloat(*scaleMatchZ,
"m_HeightmapScale.z");
406 const auto nibble = [](
char value) ->
int {
412 std::vector<std::uint16_t> sourceHeights(samples);
414 const std::size_t
at =
index * 4;
415 sourceHeights[
index] =
416 static_cast<std::uint16_t
>((nibble((*heightsHex)[
at]) << 4) | nibble((*heightsHex)[
at + 1]) |
417 (nibble((*heightsHex)[
at + 2]) << 12) | (nibble((*heightsHex)[
at + 3]) << 8));
420 const auto imageAsset = [&](std::string_view guid) {
421 return std::string(
"asset://") +
423 .
child(
"image:default")
426 terrain.width =
terrain.height =
static_cast<std::uint32_t
>(resolution);
429 terrain.heightsMeters.resize(samples);
434 float(sourceHeights[std::size_t(
terrain.height - 1 - row) *
terrain.width +
column]) / 65535.0f *
436 terrain.sourceTransform = {{
"source",
Value(
"unity-left-handed-x-right-y-up-z-forward")},
437 {
"conversion",
Value(
"reflect-z-and-reverse-height-rows")},
438 {
"heightScaleMeters",
Value(
double(scaleY.value()))}};
440 if (
auto holes = firstMatch(yaml, std::regex(R
"(m_HolesTexture:.*guid:\s*([0-9a-fA-F]{32}))"))) {
442 terrain.holesAsset = imageAsset(*holes);
444 const auto controls = sectionEntries(yaml,
"m_AlphamapTextures:");
445 if (controls.size() >
terrain.controlSources.size())
448 request.terrainDataPath, {},
"asset.import"));
450 if (
auto guid = firstMatch(controls[
index], std::regex(R
"(guid:\s*([0-9a-fA-F]{32}))"))) {
455 for (
const auto& entry : sectionEntries(yaml,
"m_TerrainLayers:")) {
456 auto guid = firstMatch(entry, std::regex(R
"(guid:\s*([0-9a-fA-F]{32}))"));
458 CanonicalTerrainLayer
layer;
465 firstMatch(layerText.value(), std::regex(R
"(m_DiffuseTexture:.*guid:\s*([0-9a-fA-F]{32}))"))) {
466 layer.diffuseSource = "unity-guid:" + *diffuse;
467 layer.diffuseAsset = imageAsset(*diffuse);
469 if (
auto normal = firstMatch(layerText.value(),
470 std::regex(R
"(m_NormalMapTexture:.*guid:\s*([0-9a-fA-F]{32}))"))) {
475 firstMatch(layerText.value(), std::regex(R
"(m_MaskMapTexture:.*guid:\s*([0-9a-fA-F]{32}))"))) {
476 layer.maskSource = "unity-guid:" + *
mask;
479 auto parseVec = [&](
const char*
name,
auto&
output) -> Result<void> {
480 const std::string expression =
481 std::string(
name) + R
"(:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^,]+),\s*w:\s*([^}]+)\})";
482 std::match_results<std::string::const_iterator> match;
483 if (!std::regex_search(layerText.value(), match, std::regex(expression)))
485 for (std::size_t component = 0; component < 4; ++component) {
486 auto parsed = parseFloat(match[component + 1].str(),
resolved->second +
"." +
name);
488 output[component] = parsed.value();
492 for (
auto [
name,
value] : {std::pair{
"m_MaskMapRemapMin", &
layer.maskRemapMinimum},
493 {
"m_MaskMapRemapMax", &
layer.maskRemapMaximum},
494 {
"m_Specular", &
layer.specular}}) {
498 const std::regex tilePattern(R
"(m_TileSize:\s*\{x:\s*([^,]+),\s*y:\s*([^}]+)\})");
499 std::match_results<std::string::const_iterator> tileMatch;
500 if (std::regex_search(layerText.value(), tileMatch, tilePattern)) {
501 auto x = parseFloat(tileMatch[1].str(),
resolved->second +
".m_TileSize.x");
502 auto y = parseFloat(tileMatch[2].str(),
resolved->second +
".m_TileSize.y");
506 layer.tileScaleMeters = {
x.value(),
y.value()};
507 layer.tileSizeMeters =
x.value();
509 const std::regex offsetPattern(R
"(m_TileOffset:\s*\{x:\s*([^,]+),\s*y:\s*([^}]+)\})");
510 std::match_results<std::string::const_iterator> offsetMatch;
511 if (std::regex_search(layerText.value(), offsetMatch, offsetPattern)) {
512 auto x = parseFloat(offsetMatch[1].str(),
resolved->second +
".m_TileOffset.x");
513 auto y = parseFloat(offsetMatch[2].str(),
resolved->second +
".m_TileOffset.y");
517 {},
"asset.import"));
518 layer.tileOffsetMeters = {
x.value(),
y.value()};
521 {
"m_NormalScale", &
layer.normalScale},
522 {
"m_Smoothness", &
layer.smoothness}}) {
524 firstMatch(layerText.value(), std::regex(std::string(
name) + R
"(:\s*([^\r\n]+))"))) {
525 auto parsed = parseFloat(*encoded,
resolved->second +
"." +
name);
535 std::vector<std::string> prototypes;
536 for (
const auto& entry : sectionEntries(yaml,
"m_TreePrototypes:")) {
537 auto guid = firstMatch(entry, std::regex(R
"(guid:\s*([0-9a-fA-F]{32}))"));
538 prototypes.push_back(guid ? "unity-guid:" + *guid :
"unity-missing-prototype");
540 for (
const auto& entry : sectionEntries(yaml,
"m_TreeInstances:")) {
541 auto position = std::regex(R
"(position:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})");
545 auto prototype = firstMatch(entry, std::regex(R
"(prototypeIndex:\s*([0-9]+))"));
546 if (!
x || !
y || !
z || !prototype)
continue;
547 const auto prototypeValue = parseUnsignedText(*prototype);
548 if (!prototypeValue || *prototypeValue >= prototypes.size())
551 const std::size_t prototypeIndex =
static_cast<std::size_t
>(*prototypeValue);
552 auto px = parseFloat(*
x,
"tree.position.x");
553 auto py = parseFloat(*
y,
"tree.position.y");
554 auto pz = parseFloat(*
z,
"tree.position.z");
558 CanonicalTerrainInstance instance;
559 instance.prototype = prototypes[prototypeIndex];
560 instance.position[0] =
px.value() *
spacingX.value() * float(resolution - 1);
561 instance.position[1] =
py.value() * scaleY.value();
562 instance.position[2] = -
pz.value() *
spacingZ.value() * float(resolution - 1);
563 if (
auto rotation = firstMatch(entry, std::regex(R
"(rotation:\s*([^\r\n]+))"))) {
566 instance.rotation[1] = std::sin(-
value.value() * 0.5f);
567 instance.rotation[3] = std::cos(-
value.value() * 0.5f);
570 if (
auto width = firstMatch(entry, std::regex(R
"(widthScale:\s*([^\r\n]+))"))) {
571 auto value = parseFloat(*
width,
"tree.widthScale");
572 if (
value) instance.scale[0] = instance.scale[2] =
value.value();
574 if (
auto height = firstMatch(entry, std::regex(R
"(heightScale:\s*([^\r\n]+))"))) {
575 auto value = parseFloat(*
height,
"tree.heightScale");
578 terrain.instances.push_back(std::move(instance));
580 if (yaml.find(
"m_DetailPrototypes:") != std::string::npos) {
581 const bool hasDetailSidecar = !terrainDetailsPath(
request).empty();
583 {
request.terrainDataPath,
"TerrainData.detail-prototypes",
586 ?
"detail data requires an eve.unity-terrain-details/3 public-API export"
587 :
"detail prototypes and placement are supplied by the public-API sidecar"});
590 "UInt16 heights converted to metres and canonical Z"});
600std::vector<UnityObject> documents(std::string_view yaml) {
601 const std::regex
header(R
"(^---\s*!u!([0-9]+)\s*&(-?[0-9]+).*$)", std::regex::multiline);
607 std::vector<Start> starts;
608 for (std::cregex_iterator it(yaml.data(), yaml.data() + yaml.size(), header),
end; it !=
end; ++it) {
609 const std::string signedText = (*it)[2].str();
610 std::int64_t signedId = 0;
611 const auto parsedId = std::from_chars(signedText.data(), signedText.data() + signedText.size(), signedId);
612 const auto classText = (*it)[1].str();
613 const auto classId = parseUnsignedText(classText);
614 if (parsedId.ec != std::errc{} || parsedId.ptr != signedText.data() + signedText.size() || !
classId ||
615 *
classId > std::numeric_limits<std::uint32_t>::max())
617 starts.push_back({
static_cast<std::size_t
>((*it).position()),
618 static_cast<std::size_t
>((*it).position() + (*it).length()),
619 {signedId,
static_cast<std::uint32_t
>(*classId), {}}});
621 std::vector<UnityObject>
result;
623 const std::size_t
end =
index + 1 < starts.size() ? starts[
index + 1].header : yaml.size();
624 starts[
index].object.body = std::string(yaml.substr(starts[
index].body,
end - starts[
index].body));
630Result<void> appendPrefab(
const UnityProjectImportRequest&
request, PreparedAssetImport&
output,
631 std::vector<ImportFinding>&
findings,
const std::string& prefabPath) {
635 if (std::regex_search(
text.value(), std::regex(R
"((?:^|\n)---\s*!u!(?:1|4|224)\s*&-)")))
638 "prefab signed hierarchy IDs are indexed but cannot yet be represented by scene-template",
639 prefabPath, {},
"asset.import"));
640 const auto prefabGuid = guidFromMeta(
request, prefabPath);
643 prefabPath +
".meta", {},
"asset.import.unity"));
647 "Unity prefab object count exceeds budget", prefabPath, {},
649 std::map<std::uint64_t, std::string> gameNames;
650 std::map<std::uint64_t, bool> gameVisibility;
651 for (
const auto&
object :
objects) {
653 auto name = firstMatch(
object.
body, std::regex(R
"(m_Name:\s*([^\r\n]+))"));
654 gameNames[object.fileId] =
name.value_or(
"GameObject");
655 gameVisibility[
object.fileId] = !std::regex_search(
object.
body, std::regex(R
"(m_IsActive:\s*0(?:\s|$))"));
656 } else if (
object.
classId == 114) {
657 findings.push_back({prefabPath,
"MonoBehaviour:" + std::to_string(
object.
fileId),
659 "C# behaviour is not executed or translated by the data importer"});
660 }
else if (
object.
classId != 4) {
662 {prefabPath,
"Prefab.component:" + std::to_string(
object.
classId) +
":" + std::to_string(
object.
fileId),
664 "component behavior is not converted; only GameObject/Transform hierarchy is available"});
668 for (
const auto&
object :
objects) {
670 auto game = firstMatch(
object.
body, std::regex(R
"(m_GameObject:\s*\{fileID:\s*(-?[0-9]+)\})"));
671 auto father = firstMatch(
object.
body, std::regex(R
"(m_Father:\s*\{fileID:\s*(-?[0-9]+)\})"));
672 const std::regex
position(R
"(m_LocalPosition:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})");
674 R
"(m_LocalRotation:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^,]+),\s*w:\s*([^}]+)\})");
675 const std::regex
scale(R
"(m_LocalScale:\s*\{x:\s*([^,]+),\s*y:\s*([^,]+),\s*z:\s*([^}]+)\})");
677 auto vector = [&](
const std::regex& regex, std::size_t
count,
float*
target,
bool reflect) -> Result<void> {
678 for (std::size_t component = 0; component <
count; ++component) {
679 auto field = firstMatch(
object.
body, regex, component + 1);
682 "Unity transform field is missing", prefabPath, {},
683 "asset.import.unity"));
684 auto parsed = parseFloat(*field, prefabPath);
686 target[component] = parsed.value();
691 float p[3],
q[4],
s[3];
693 if (!pResult)
return pResult;
695 if (!qResult)
return qResult;
699 if (!sResult)
return sResult;
700 const auto gameIdValue = parseUnsignedText(*game);
701 const auto parentIdValue = father ? parseUnsignedText(*father) :
std::optional<
std::uint64_t>(0);
702 if (!gameIdValue || !parentIdValue)
705 const auto gameId = *gameIdValue;
706 const std::uint64_t
parentId = *parentIdValue;
710 node[
"sourceFileId"] =
Value(
static_cast<std::int64_t
>(
object.
fileId));
711 node[
"name"] =
Value(gameNames.contains(gameId) ? gameNames[gameId] :
"GameObject");
712 node[
"visible"] =
Value(!gameVisibility.contains(gameId) || gameVisibility.at(gameId));
723 "prefab has no directly convertible Transform nodes; nested prefab expansion is required",
724 prefabPath, {},
"asset.import"));
727 definition[
"schema"] =
Value(
"eve.scene-template");
728 definition[
"schemaVersion"] =
Value(std::int64_t(3));
729 definition[
"sourceGuid"] =
Value(*prefabGuid);
730 definition[
"nodes"] =
Value(std::move(
nodes));
732 definition[
"coordinateSystem"] =
Value(
"right-handed-x-right-y-up-minus-z-forward");
733 auto encoded =
Value(std::move(definition)).toJson();
735 std::string definitionText = std::move(encoded).takeValue();
736 const std::string
path =
"assets/" + sceneId.format() +
"/asset.json";
739 output.manifest.assets.push_back(
741 "eve.scene-template",
744 detail::sha256(std::span<const std::uint8_t>(
reinterpret_cast<const std::uint8_t*
>(definitionText.data()),
745 definitionText.size())),
746 {
"scene",
"source:unity-prefab"}});
747 output.entries.push_back({
path, {definitionText.begin(), definitionText.end()}});
748 if (
output.manifest.entrypoints.empty()) {
751 output.manifest.entrypoints.emplace(
"default", std::move(entrypoint).takeValue());
754 "GUID/fileID hierarchy converted to canonical TRS"});
767 for (
const auto& asset :
output.manifest.assets)
output.sourceMappings.push_back({
"Prefab#Transform", asset.asset});
774 Diagnostic::error(DiagnosticCode::InvalidArgument,
"Unity project files and package identity are required",
775 {}, {},
"asset.import"));
778 if (
request.terrainDataPath.empty() &&
request.prefabPath.empty())
780 std::vector<ImportFinding>
findings = sourceIndex.value().findings;
782 if (!
request.terrainDataPath.empty()) {
790 output = std::move(prepared).takeValue();
791 if (!
terrain.value().detailPrototypes.empty()) {
795 for (
const auto& prototype :
terrain.value().detailPrototypes) {
796 auto resource = AssetRef::parse(prototype.resourceAsset);
802 for (
const auto& dependency : collection.value().manifest.dependencies)
803 if (
selected.contains(dependency.from.id()) &&
selected.emplace(dependency.to.id()).second)
806 std::set<std::string> runtimePrefixes;
807 for (
const auto& asset : collection.value().manifest.assets) {
808 if (!
selected.contains(asset.asset.id()))
continue;
809 const bool duplicate = std::any_of(
output.manifest.assets.begin(),
output.manifest.assets.end(),
810 [&](
const auto& existing) {
811 return existing.asset.id() == asset.asset.id();
813 if (!duplicate)
output.manifest.assets.push_back(asset);
814 runtimePrefixes.emplace(
"assets/" + asset.asset.id().format() +
"/");
816 for (
const auto& dependency : collection.value().manifest.dependencies)
817 if (
selected.contains(dependency.from.id()) &&
selected.contains(dependency.to.id()))
818 output.manifest.dependencies.push_back(dependency);
819 for (
const auto& entry : collection.value().entries)
820 if (std::any_of(runtimePrefixes.begin(), runtimePrefixes.end(), [&](
const auto& prefix) {
821 return entry.path.starts_with(prefix);
823 output.entries.push_back(entry);
827 auto manifest = detail::baseManifest(
request.package,
"eve.unity-prefab/1");
829 output.manifest = std::move(manifest).takeValue();
833 output.manifest.provenance[
"sourceEngine"] =
Value(
"unity");
834 output.manifest.provenance[
"sourceCoordinateSystem"] =
Value(
"left-handed-x-right-y-up-z-forward");
836 std::make_move_iterator(
findings.end()));
837 for (
const auto& asset :
output.manifest.assets) {
838 std::string sourceObject =
request.terrainDataPath +
"#" + asset.type;
839 if (asset.type ==
"eve.scene-template") sourceObject =
request.prefabPath +
"#Transform";
840 output.sourceMappings.push_back({std::move(sourceObject), asset.asset});
842 auto report = detail::finalizeImportReport(
output,
request.package,
"unity",
"force-text",
843 {{
"serialization", Value(
"force-text")}});
AuthorityStoreHandleRef reference
std::unordered_map< std::string, QuestRuntime > entries
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
std::array< double, 10 > q
std::array< float, 4 > rotation
std::array< float, 3 > position
std::array< float, 3 > scale
std::vector< std::filesystem::path > paths
AbilityActivationGroup group
AbilityInstancingPolicy instancing
float(ui::Theme::* member)[4]
Direct Unity text-serialization adapter for TerrainData and Prefab assets.
std::vector< ImportFinding > findings
std::vector< std::string_view > lines
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.
static Result success(T value)
Construct a successful result owning value.
const T & value() const &
Borrow the value from a const lvalue after checking success.
static Result failure(Status status)
Construct a failed result from a structured status.
The canonical owning dynamic value used by data-facing protocols.
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
std::map< std::string, Value > Object
std::vector< Value > Array
std::string format() const
Formats the ID in lower-case canonical UUID text.
Id128 child(std::string_view role) const noexcept
Derives a deterministic child UUID for a hierarchical identity.
std::string sha256(std::span< const std::uint8_t > bytes)
Sha 256.
Result< asset::EvaManifest > baseManifest(const ImportPackageIdentity &package, std::string_view importer)
Base manifest.
Result< AssetRef > assetRef(PersistentId id)
Asset ref.
std::string foldAscii(std::string value)
Fold ascii.
Result< PreparedAssetImport > prepareCanonicalTerrainImport(const ImportPackageIdentity &package, const CanonicalTerrainInput &terrain, std::string_view importer, const AssetImportLimits &limits)
Build eve.terrain, terrain material, PCG and instance assets from canonical input.
Result< PreparedAssetImport > prepareUnityPrefab(const UnityProjectImportRequest &request, const std::string &path)
Prepare one prefab without copying or re-indexing the source collection.
Result< PreparedAssetImport > prepareUnityCollection(const UnityProjectImportRequest &request, const UnitySourceIndex &index)
Prepare an owning collection candidate using a validated source index.
Result< UnitySourceIndex > indexUnitySources(const UnitySourceFiles &files, const AssetImportLimits &limits)
Validate project paths and .meta identities and index serialized GUID/fileID references.
Result< PreparedAssetImport > prepareUnityProjectImport(const UnityProjectImportRequest &request)
Import selected Unity assets, or discover a collection when both selectors are empty.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
eve::Diagnostic Diagnostic
Value vector(glm::dvec3 v)
std::string header(int localX, int localY)
Header.
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
DiagnosticCode
Stable machine-readable diagnostic codes.
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
bool isValidUtf8(std::string_view text, Utf8NullPolicy nullPolicy) noexcept
Validate shortest-form UTF-8, Unicode scalar range and optional NUL exclusion.
std::uint32_t maximumAssets
std::uint32_t maximumVerticesPerPrimitive
std::uint64_t maximumSourceBytes
std::uint32_t maximumStringBytes
ImportPackageIdentity package
Owning, validated source archive candidate not yet published to disk/database.
asset::EvaManifest manifest
In-memory Unity project slice; keys are normalized project-relative paths.