@ignifx/core 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{environment-DZ6WUHbm.js → environment-Bf4aphSb.js} +2 -2
- package/dist/{environment-DZ6WUHbm.js.map → environment-Bf4aphSb.js.map} +1 -1
- package/dist/{gtao-_nr0b6-E.js → gtao-Bpu5-0Ne.js} +2 -2
- package/dist/{gtao-_nr0b6-E.js.map → gtao-Bpu5-0Ne.js.map} +1 -1
- package/dist/{hdr-output-Dbv0lhFl.js → hdr-output-DBQwMphy.js} +2 -2
- package/dist/{hdr-output-Dbv0lhFl.js.map → hdr-output-DBQwMphy.js.map} +1 -1
- package/dist/{ignifx-error-B8ByiSfJ.js → ignifx-error-DwIZKxA2.js} +4 -1
- package/dist/ignifx-error-DwIZKxA2.js.map +1 -0
- package/dist/index.d.ts +218 -696
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2904 -970
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-BMhREEfx.js → instanced-mesh-instance-B-fXKSrY.js} +2 -2
- package/dist/{instanced-mesh-instance-BMhREEfx.js.map → instanced-mesh-instance-B-fXKSrY.js.map} +1 -1
- package/dist/{light-probe-asset-B60_X-yN.js → light-probe-asset-BqfSrJe9.js} +2 -2
- package/dist/{light-probe-asset-B60_X-yN.js.map → light-probe-asset-BqfSrJe9.js.map} +1 -1
- package/dist/{light-probes-DkYN89Qw.js → light-probes-DDojYajw.js} +4 -4
- package/dist/{light-probes-DkYN89Qw.js.map → light-probes-DDojYajw.js.map} +1 -1
- package/dist/lightmaps-BUUIIkt9.js +230 -0
- package/dist/lightmaps-BUUIIkt9.js.map +1 -0
- package/dist/{material-CGk5mAah.js → material-myMbl9mW.js} +37 -2
- package/dist/{material-CGk5mAah.js.map → material-myMbl9mW.js.map} +1 -1
- package/dist/{material-plugin-CiAmriQ_.js → material-plugin-DapJNj04.js} +2 -2
- package/dist/{material-plugin-CiAmriQ_.js.map → material-plugin-DapJNj04.js.map} +1 -1
- package/dist/{post-effect-CQnlX1RH.js → post-effect-Cu3Enpz7.js} +2 -2
- package/dist/{post-effect-CQnlX1RH.js.map → post-effect-Cu3Enpz7.js.map} +1 -1
- package/dist/{post-effect-compiler-C_7HTHZy.js → post-effect-compiler-cCq9lcHt.js} +3 -3
- package/dist/{post-effect-compiler-C_7HTHZy.js.map → post-effect-compiler-cCq9lcHt.js.map} +1 -1
- package/dist/{prefab-overrides-DT-wHHAJ.js → prefab-overrides-C2GsgOQc.js} +467 -30
- package/dist/prefab-overrides-C2GsgOQc.js.map +1 -0
- package/dist/{prefab-overrides-BLQn5yHS.d.ts → prefab-overrides-htDc_5Po.d.ts} +1370 -246
- package/dist/prefab-overrides-htDc_5Po.d.ts.map +1 -0
- package/dist/prefab.d.ts +2 -2
- package/dist/prefab.js +2 -2
- package/dist/{reflection-probe-DlVsl3zJ.js → reflection-probe-QkD1Fo_d.js} +106 -12
- package/dist/{reflection-probe-DlVsl3zJ.js.map → reflection-probe-QkD1Fo_d.js.map} +1 -1
- package/dist/reflection-probes-CAzSuqf8.js +921 -0
- package/dist/reflection-probes-CAzSuqf8.js.map +1 -0
- package/dist/{shader-material-CaAkv5nT.js → shader-material-CJIDFvSb.js} +2 -2
- package/dist/{shader-material-CaAkv5nT.js.map → shader-material-CJIDFvSb.js.map} +1 -1
- package/dist/{shader-material-C2_UCYdO.js → shader-material-TM4f8eKA.js} +4 -4
- package/dist/{shader-material-C2_UCYdO.js.map → shader-material-TM4f8eKA.js.map} +1 -1
- package/dist/{shader-pragma-DmZpxGUo.js → shader-pragma-ljmAbVc2.js} +2 -2
- package/dist/{shader-pragma-DmZpxGUo.js.map → shader-pragma-ljmAbVc2.js.map} +1 -1
- package/dist/{ssgi-Dm-maZrc.js → ssgi-DSnhqotl.js} +2 -2
- package/dist/{ssgi-Dm-maZrc.js.map → ssgi-DSnhqotl.js.map} +1 -1
- package/dist/{surface-shader-BeDRofOV.js → surface-shader-rpPpeosD.js} +6 -6
- package/dist/{surface-shader-BeDRofOV.js.map → surface-shader-rpPpeosD.js.map} +1 -1
- package/dist/{vec3-Cc19wl4r.js → vec3-2C3LBZnt.js} +55 -3
- package/dist/vec3-2C3LBZnt.js.map +1 -0
- package/package.json +1 -1
- package/dist/ignifx-error-B8ByiSfJ.js.map +0 -1
- package/dist/prefab-overrides-BLQn5yHS.d.ts.map +0 -1
- package/dist/prefab-overrides-DT-wHHAJ.js.map +0 -1
- package/dist/reflection-probes-B8S9WnVX.js +0 -551
- package/dist/reflection-probes-B8S9WnVX.js.map +0 -1
- package/dist/vec3-Cc19wl4r.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-
|
|
1
|
+
import { n as assertNever, o as CoreErrorCode, t as IgnifxError } from "./ignifx-error-DwIZKxA2.js";
|
|
2
2
|
//#region src/assets/address.ts
|
|
3
3
|
/**
|
|
4
4
|
* Address arithmetic (`docs/architecture/05-assets-and-loading.md` §2): splitting the sub-asset
|
|
@@ -1588,6 +1588,95 @@ function toHex(bytes) {
|
|
|
1588
1588
|
}
|
|
1589
1589
|
return text;
|
|
1590
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Builds the instance path tables of an expansion.
|
|
1593
|
+
*
|
|
1594
|
+
* @param expanded - The expansion.
|
|
1595
|
+
* @returns The resolver.
|
|
1596
|
+
*
|
|
1597
|
+
* @internal
|
|
1598
|
+
*/
|
|
1599
|
+
function instancePathResolver(expanded) {
|
|
1600
|
+
const keysOfRoot = /* @__PURE__ */ new Map();
|
|
1601
|
+
const entities = /* @__PURE__ */ new Map();
|
|
1602
|
+
const components = /* @__PURE__ */ new Map();
|
|
1603
|
+
for (const instance of expanded.instances) {
|
|
1604
|
+
if (instance.rootUid === null) continue;
|
|
1605
|
+
const keys = keysOfRoot.get(instance.rootUid) ?? [];
|
|
1606
|
+
keys.push(instance.key);
|
|
1607
|
+
keysOfRoot.set(instance.rootUid, keys);
|
|
1608
|
+
if (instance.root !== null) {
|
|
1609
|
+
tableOf(entities, instance.key).set(instance.root.sourceUid, instance.rootUid);
|
|
1610
|
+
fillComponents(tableOf(components, instance.key), instance.root.componentSourceUids);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
for (const entity of expanded.entities) {
|
|
1614
|
+
if (entity.instanceKey === null) continue;
|
|
1615
|
+
tableOf(entities, entity.instanceKey).set(entity.sourceUid, entity.data.uid);
|
|
1616
|
+
fillComponents(tableOf(components, entity.instanceKey), entity.componentSourceUids);
|
|
1617
|
+
}
|
|
1618
|
+
const lookup = (tables, root, uid) => {
|
|
1619
|
+
for (const key of keysOfRoot.get(root) ?? []) {
|
|
1620
|
+
const found = tables.get(key)?.get(uid);
|
|
1621
|
+
if (found !== void 0) return found;
|
|
1622
|
+
}
|
|
1623
|
+
return null;
|
|
1624
|
+
};
|
|
1625
|
+
const resolve = (path, last) => {
|
|
1626
|
+
const segments = path.split("/");
|
|
1627
|
+
if (segments.length < 2) return null;
|
|
1628
|
+
let root = segments[0] ?? null;
|
|
1629
|
+
for (let index = 1; index < segments.length && root !== null; index += 1) {
|
|
1630
|
+
const segment = segments[index] ?? "";
|
|
1631
|
+
root = lookup(index === segments.length - 1 ? last : entities, root, segment);
|
|
1632
|
+
}
|
|
1633
|
+
return root;
|
|
1634
|
+
};
|
|
1635
|
+
return {
|
|
1636
|
+
entity: (path) => resolve(path, entities),
|
|
1637
|
+
component: (path) => resolve(path, components)
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Rewrites the first segment of an instance path, which names an entity of the file the path is
|
|
1642
|
+
* written in, through that file's uid table.
|
|
1643
|
+
*
|
|
1644
|
+
* @param path - The path, or a plain uid.
|
|
1645
|
+
* @param keys - Source uid to expanded uid for the file.
|
|
1646
|
+
* @returns The rewritten path, or `null` when `path` is not a path.
|
|
1647
|
+
*
|
|
1648
|
+
* @internal
|
|
1649
|
+
*/
|
|
1650
|
+
function remapInstancePath(path, keys) {
|
|
1651
|
+
const at = path.indexOf("/");
|
|
1652
|
+
if (at <= 0) return null;
|
|
1653
|
+
const head = path.slice(0, at);
|
|
1654
|
+
return `${keys.get(head) ?? head}${path.slice(at)}`;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* The table of one instance key, created on first use.
|
|
1658
|
+
*
|
|
1659
|
+
* @param tables - The tables by instance key.
|
|
1660
|
+
* @param key - The instance key.
|
|
1661
|
+
* @returns The table.
|
|
1662
|
+
*/
|
|
1663
|
+
function tableOf(tables, key) {
|
|
1664
|
+
let table = tables.get(key);
|
|
1665
|
+
if (table === void 0) {
|
|
1666
|
+
table = /* @__PURE__ */ new Map();
|
|
1667
|
+
tables.set(key, table);
|
|
1668
|
+
}
|
|
1669
|
+
return table;
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Adds an expanded-to-source component table, inverted, to an instance's component table.
|
|
1673
|
+
*
|
|
1674
|
+
* @param into - Source component uid to expanded uid.
|
|
1675
|
+
* @param sourceUids - Expanded component uid to source component uid.
|
|
1676
|
+
*/
|
|
1677
|
+
function fillComponents(into, sourceUids) {
|
|
1678
|
+
for (const [expanded, source] of sourceUids) into.set(source, expanded);
|
|
1679
|
+
}
|
|
1591
1680
|
//#endregion
|
|
1592
1681
|
//#region src/serialization/overrides.ts
|
|
1593
1682
|
/** The entity fields the grammar accepts, as an `as const` table so the union derives from it. */
|
|
@@ -1652,21 +1741,24 @@ function parseOverridePath(path) {
|
|
|
1652
1741
|
};
|
|
1653
1742
|
}
|
|
1654
1743
|
if (second !== "components") throw invalidPath(path, `"${second}" is not "components", "transform", or an entity property.`);
|
|
1655
|
-
const
|
|
1656
|
-
|
|
1657
|
-
|
|
1744
|
+
const rest = segments.slice(2);
|
|
1745
|
+
const at = rest.findIndex((segment, index) => index > 0 && (segment === "props" || segment === "enabled"));
|
|
1746
|
+
const componentSegments = at < 0 ? rest : rest.slice(0, at);
|
|
1747
|
+
if (componentSegments.includes("")) throw invalidPath(path, "a component override names the component's uid after /components/.");
|
|
1748
|
+
const component = componentSegments.join("/");
|
|
1749
|
+
if (at < 0) return {
|
|
1658
1750
|
kind: "component",
|
|
1659
1751
|
entity,
|
|
1660
1752
|
component
|
|
1661
1753
|
};
|
|
1662
|
-
const
|
|
1663
|
-
|
|
1754
|
+
const keyword = rest[at];
|
|
1755
|
+
const steps = rest.slice(at + 1);
|
|
1756
|
+
if (keyword === "enabled" && steps.length === 0) return {
|
|
1664
1757
|
kind: "componentField",
|
|
1665
1758
|
entity,
|
|
1666
1759
|
component
|
|
1667
1760
|
};
|
|
1668
|
-
if (
|
|
1669
|
-
const steps = segments.slice(4);
|
|
1761
|
+
if (keyword !== "props" || steps.length === 0) throw invalidPath(path, "a property override is <uid>/components/<uid>/props/<field>.");
|
|
1670
1762
|
if (steps.includes("__proto__")) throw invalidPath(path, "\"__proto__\" is not a property name an override may address.");
|
|
1671
1763
|
return {
|
|
1672
1764
|
kind: "prop",
|
|
@@ -1699,10 +1791,12 @@ function overrideOp(override) {
|
|
|
1699
1791
|
* @param overrides - The patches, in file order.
|
|
1700
1792
|
* @param lookup - Source uid to the mutable entity record it expanded into.
|
|
1701
1793
|
* @param report - Called for a patch that names something the instanced file does not contain.
|
|
1794
|
+
* @param nested - Resolves a component segment that is an instance path (a component of a prefab
|
|
1795
|
+
* the instanced file instances); without it such a patch is reported as naming no component.
|
|
1702
1796
|
*
|
|
1703
1797
|
* @internal
|
|
1704
1798
|
*/
|
|
1705
|
-
function applyOverrides(overrides, lookup, report) {
|
|
1799
|
+
function applyOverrides(overrides, lookup, report, nested) {
|
|
1706
1800
|
for (let index = 0; index < overrides.length; index += 1) {
|
|
1707
1801
|
const override = overrides[index];
|
|
1708
1802
|
if (override === void 0) continue;
|
|
@@ -1712,10 +1806,21 @@ function applyOverrides(overrides, lookup, report) {
|
|
|
1712
1806
|
report(`the override path "${override.path}" names no entity of the instanced scene.`);
|
|
1713
1807
|
continue;
|
|
1714
1808
|
}
|
|
1715
|
-
applyOne(overrideOp(override), parsed, override, target, report);
|
|
1809
|
+
applyOne(overrideOp(override), parsed, override, target, report, nested ?? null);
|
|
1716
1810
|
}
|
|
1717
1811
|
}
|
|
1718
1812
|
/**
|
|
1813
|
+
* Whether an override path's component segment is an instance path into a nested prefab.
|
|
1814
|
+
*
|
|
1815
|
+
* @param component - The component segment.
|
|
1816
|
+
* @returns `true` when it holds more than one uid.
|
|
1817
|
+
*
|
|
1818
|
+
* @internal
|
|
1819
|
+
*/
|
|
1820
|
+
function isNestedComponentPath(component) {
|
|
1821
|
+
return component.includes("/");
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1719
1824
|
* Applies one parsed override.
|
|
1720
1825
|
*
|
|
1721
1826
|
* @param op - The operation.
|
|
@@ -1723,9 +1828,20 @@ function applyOverrides(overrides, lookup, report) {
|
|
|
1723
1828
|
* @param override - The raw entry, for its `value`.
|
|
1724
1829
|
* @param target - The entity the path resolved to, with its component uid mapping.
|
|
1725
1830
|
* @param report - Called when the patch cannot be applied.
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1831
|
+
* @param nested - Resolves a component segment that is an instance path, or `null`.
|
|
1832
|
+
*/
|
|
1833
|
+
function applyOne(op, parsed, override, target, report, nested) {
|
|
1834
|
+
let entity = target.data;
|
|
1835
|
+
let uid = "";
|
|
1836
|
+
if (parsed.kind === "component" || parsed.kind === "componentField" || parsed.kind === "prop") {
|
|
1837
|
+
const found = componentTarget$1(target, parsed.entity, parsed.component, nested);
|
|
1838
|
+
if (found === null) {
|
|
1839
|
+
report(`"${override.path}" names no component of that entity.`);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
entity = found.data;
|
|
1843
|
+
uid = found.uid;
|
|
1844
|
+
}
|
|
1729
1845
|
switch (parsed.kind) {
|
|
1730
1846
|
case "entity":
|
|
1731
1847
|
report(`"${override.path}" addresses a whole entity; overrides patch properties and components.`);
|
|
@@ -1760,7 +1876,7 @@ function applyOne(op, parsed, override, target, report) {
|
|
|
1760
1876
|
report(`"${override.path}" addresses a whole component; only { "op": "remove" } may patch it.`);
|
|
1761
1877
|
return;
|
|
1762
1878
|
}
|
|
1763
|
-
const at = indexOfComponent(entity,
|
|
1879
|
+
const at = indexOfComponent(entity, uid);
|
|
1764
1880
|
if (at < 0) {
|
|
1765
1881
|
report(`"${override.path}" names no component of that entity.`);
|
|
1766
1882
|
return;
|
|
@@ -1769,7 +1885,6 @@ function applyOne(op, parsed, override, target, report) {
|
|
|
1769
1885
|
return;
|
|
1770
1886
|
}
|
|
1771
1887
|
case "componentField": {
|
|
1772
|
-
const uid = resolve(target, parsed.component);
|
|
1773
1888
|
const component = componentOf(entity, uid);
|
|
1774
1889
|
if (component === null) {
|
|
1775
1890
|
report(`"${override.path}" names no component of that entity.`);
|
|
@@ -1782,7 +1897,6 @@ function applyOne(op, parsed, override, target, report) {
|
|
|
1782
1897
|
return;
|
|
1783
1898
|
}
|
|
1784
1899
|
case "prop": {
|
|
1785
|
-
const uid = resolve(target, parsed.component);
|
|
1786
1900
|
const component = componentOf(entity, uid);
|
|
1787
1901
|
if (component === null) {
|
|
1788
1902
|
report(`"${override.path}" names no component of that entity.`);
|
|
@@ -1914,15 +2028,24 @@ function writeArrayStep(container, steps, at, op, value, path, report) {
|
|
|
1914
2028
|
return container;
|
|
1915
2029
|
}
|
|
1916
2030
|
/**
|
|
1917
|
-
* Resolves the
|
|
1918
|
-
*
|
|
2031
|
+
* Resolves the component an override path names — a uid of the instanced file, or an instance path
|
|
2032
|
+
* into a prefab it instances — to the record holding this copy of it and the uid it got.
|
|
1919
2033
|
*
|
|
1920
2034
|
* @param target - The entity the path resolved to.
|
|
1921
|
-
* @param
|
|
1922
|
-
* @
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2035
|
+
* @param entityUid - The path's entity segment.
|
|
2036
|
+
* @param component - The path's component segment.
|
|
2037
|
+
* @param nested - Resolves an instance path, or `null`.
|
|
2038
|
+
* @returns The record and uid; for a plain uid the mapping's uid, or the name itself when the
|
|
2039
|
+
* mapping does not know it. `null` when an instance path names nothing or does not start at the
|
|
2040
|
+
* path's entity.
|
|
2041
|
+
*/
|
|
2042
|
+
function componentTarget$1(target, entityUid, component, nested) {
|
|
2043
|
+
if (!isNestedComponentPath(component)) return {
|
|
2044
|
+
data: target.data,
|
|
2045
|
+
uid: target.components.get(component) ?? component
|
|
2046
|
+
};
|
|
2047
|
+
if (nested === null || component.slice(0, component.indexOf("/")) !== entityUid) return null;
|
|
2048
|
+
return nested(component);
|
|
1926
2049
|
}
|
|
1927
2050
|
/**
|
|
1928
2051
|
* Finds a component of an entity by uid.
|
|
@@ -2004,6 +2127,273 @@ function invalidPath(path, reason) {
|
|
|
2004
2127
|
});
|
|
2005
2128
|
}
|
|
2006
2129
|
//#endregion
|
|
2130
|
+
//#region src/serialization/instance-targets.ts
|
|
2131
|
+
/** How many nested files the walk follows, as a guard against pathological files. */
|
|
2132
|
+
const DEPTH_LIMIT = 16;
|
|
2133
|
+
/**
|
|
2134
|
+
* Finds the entity or component an instance path names inside a scene file's prefab instances,
|
|
2135
|
+
* without loading anything: the rules the loader resolves `$entity` and `$component` references
|
|
2136
|
+
* by.
|
|
2137
|
+
*
|
|
2138
|
+
* @remarks
|
|
2139
|
+
* A pure function over files. The path's first segment is the uid of an entity of `scene` that
|
|
2140
|
+
* carries an `instance` entry; each later segment but the last names an entity of the prefab
|
|
2141
|
+
* reached so far that itself instances a prefab; the last names the target by the uid its own file
|
|
2142
|
+
* gives it. A prefab's single root merges into the entity instancing it, so a prefab that root
|
|
2143
|
+
* instances is searched at the same level, with no extra segment.
|
|
2144
|
+
*
|
|
2145
|
+
* @param scene - The scene file holding the path.
|
|
2146
|
+
* @param path - The instance path, `"<carrierUid>/…/<uid>"`.
|
|
2147
|
+
* @param readScene - Reads the prefab files the path walks through.
|
|
2148
|
+
* @param kind - What the reference expects: `"entity"` for `$entity`, `"component"` for
|
|
2149
|
+
* `$component`. Omitted, an entity is looked for first, then a component.
|
|
2150
|
+
* @returns The target, or `null` when the path is a plain uid or names nothing.
|
|
2151
|
+
*
|
|
2152
|
+
* @example
|
|
2153
|
+
* ```ts
|
|
2154
|
+
* const target = resolveInstancePath(sceneFile, "01J…CRATE/01J…LID", (address) => files.get(address));
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @public
|
|
2158
|
+
*/
|
|
2159
|
+
function resolveInstancePath(scene, path, readScene, kind) {
|
|
2160
|
+
const segments = path.split("/");
|
|
2161
|
+
const head = scene.entities.find((entity) => entity.uid === segments[0]);
|
|
2162
|
+
if (segments.length < 2 || head?.instance === void 0) return null;
|
|
2163
|
+
let frame = frameOf(head, [head.name], null, readScene, []);
|
|
2164
|
+
for (let index = 1; index < segments.length - 1; index += 1) {
|
|
2165
|
+
const found = findEntity(frame, segments[index] ?? "");
|
|
2166
|
+
if (found === null) return null;
|
|
2167
|
+
if (found.entity.uid !== found.file.mergedRoot) frame = frameOf(found.entity, labelsOf(frame, found.file, found.entity), nextSegments(found.file, found.entity.uid), readScene, ancestorsOf(frame, found.file));
|
|
2168
|
+
}
|
|
2169
|
+
const last = segments[segments.length - 1] ?? "";
|
|
2170
|
+
if (kind !== "component") {
|
|
2171
|
+
const found = findEntity(frame, last);
|
|
2172
|
+
if (found !== null) return entityTarget(path, head.uid, frame, found.file, found.entity);
|
|
2173
|
+
}
|
|
2174
|
+
if (kind !== "entity") for (const file of frame.files) for (const entity of file.file.entities) {
|
|
2175
|
+
const component = entity.components?.find((candidate) => candidate.uid === last);
|
|
2176
|
+
if (component !== void 0) return componentTarget(path, head.uid, frame, file, entity, component);
|
|
2177
|
+
}
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Lists every entity and component an instance path can reach inside a scene file's prefab
|
|
2182
|
+
* instances, with the path, a label chain, and the override path that addresses it.
|
|
2183
|
+
*
|
|
2184
|
+
* @remarks
|
|
2185
|
+
* A pure function over files, for tools such as an editor's reference picker. Each path is the
|
|
2186
|
+
* shortest form {@link resolveInstancePath} resolves. A prefab's single root is not listed as an
|
|
2187
|
+
* entity: it merges into the carrier, which the scene names by its plain uid; its components are
|
|
2188
|
+
* listed. Components an override `add`s are not listed: they keep no uid from a prefab file. The
|
|
2189
|
+
* walk stops at a file `readScene` cannot read, at a prefab that would instance itself, and 16
|
|
2190
|
+
* files deep.
|
|
2191
|
+
*
|
|
2192
|
+
* @param scene - The scene file.
|
|
2193
|
+
* @param readScene - Reads the prefab files.
|
|
2194
|
+
* @returns The targets, in scene order of their carriers, then depth first in file order.
|
|
2195
|
+
*
|
|
2196
|
+
* @example
|
|
2197
|
+
* ```ts
|
|
2198
|
+
* const components = enumerateInstanceTargets(sceneFile, (address) => files.get(address)).filter(
|
|
2199
|
+
* (target) => target.kind === "component",
|
|
2200
|
+
* );
|
|
2201
|
+
* ```
|
|
2202
|
+
*
|
|
2203
|
+
* @public
|
|
2204
|
+
*/
|
|
2205
|
+
function enumerateInstanceTargets(scene, readScene) {
|
|
2206
|
+
const targets = [];
|
|
2207
|
+
for (const carrier of scene.entities) if (carrier.instance !== void 0) walkFrame(frameOf(carrier, [carrier.name], null, readScene, []), 0, carrier.uid, carrier.uid, readScene, targets);
|
|
2208
|
+
return targets;
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Lists the targets of one frame file and, depth first, of the frames below it.
|
|
2212
|
+
*
|
|
2213
|
+
* @param frame - The frame.
|
|
2214
|
+
* @param at - The index of the file to walk.
|
|
2215
|
+
* @param prefix - The instance path to the frame's carrier.
|
|
2216
|
+
* @param carrier - The scene carrier's uid.
|
|
2217
|
+
* @param readScene - Reads nested files.
|
|
2218
|
+
* @param into - Collects the targets.
|
|
2219
|
+
*/
|
|
2220
|
+
function walkFrame(frame, at, prefix, carrier, readScene, into) {
|
|
2221
|
+
const file = frame.files[at];
|
|
2222
|
+
if (file === void 0) return;
|
|
2223
|
+
for (const entity of file.file.entities) {
|
|
2224
|
+
const merged = entity.uid === file.mergedRoot;
|
|
2225
|
+
if (!merged) into.push(entityTarget(`${prefix}/${entity.uid}`, carrier, frame, file, entity));
|
|
2226
|
+
for (const component of entity.components ?? []) into.push(componentTarget(`${prefix}/${component.uid}`, carrier, frame, file, entity, component));
|
|
2227
|
+
if (entity.instance === void 0) continue;
|
|
2228
|
+
if (merged) {
|
|
2229
|
+
walkFrame(frame, at + 1, prefix, carrier, readScene, into);
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
walkFrame(frameOf(entity, labelsOf(frame, file, entity), nextSegments(file, entity.uid), readScene, ancestorsOf(frame, file)), 0, `${prefix}/${entity.uid}`, carrier, readScene, into);
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Reads the frame an entity carrying an `instance` entry holds.
|
|
2237
|
+
*
|
|
2238
|
+
* @param carrier - The entity.
|
|
2239
|
+
* @param labels - The names down to and including the carrier.
|
|
2240
|
+
* @param overrideSegments - The override component path prefix for the first file.
|
|
2241
|
+
* @param readScene - Reads the files.
|
|
2242
|
+
* @param ancestors - The addresses of the files enclosing the carrier, outermost first.
|
|
2243
|
+
* @returns The frame; empty when the first file cannot be read or would nest itself.
|
|
2244
|
+
*/
|
|
2245
|
+
function frameOf(carrier, labels, overrideSegments, readScene, ancestors) {
|
|
2246
|
+
const files = [];
|
|
2247
|
+
const addresses = [...ancestors];
|
|
2248
|
+
let current = carrier;
|
|
2249
|
+
let segments = overrideSegments;
|
|
2250
|
+
while (current?.instance !== void 0 && addresses.length < DEPTH_LIMIT) {
|
|
2251
|
+
const address = current.instance.scene.$asset;
|
|
2252
|
+
const file = addresses.includes(address) ? null : readScene(address);
|
|
2253
|
+
if (file === null || file === void 0) break;
|
|
2254
|
+
addresses.push(address);
|
|
2255
|
+
const root = singleRootOf$1(file);
|
|
2256
|
+
files.push({
|
|
2257
|
+
address,
|
|
2258
|
+
file,
|
|
2259
|
+
mergedRoot: root?.uid ?? null,
|
|
2260
|
+
overrideSegments: segments
|
|
2261
|
+
});
|
|
2262
|
+
segments ??= root === null ? null : [root.uid];
|
|
2263
|
+
current = root;
|
|
2264
|
+
}
|
|
2265
|
+
return {
|
|
2266
|
+
files,
|
|
2267
|
+
labels,
|
|
2268
|
+
ancestors
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* The ancestor chain of an entity a frame file declares: the frame's own ancestors, then the frame
|
|
2273
|
+
* files from the outermost down to and including the declaring one. A file later in the frame
|
|
2274
|
+
* merges into the same carrier but does not enclose the entity, so it is not an ancestor.
|
|
2275
|
+
*
|
|
2276
|
+
* @param frame - The frame.
|
|
2277
|
+
* @param file - The frame file declaring the entity.
|
|
2278
|
+
* @returns The addresses, outermost first.
|
|
2279
|
+
*/
|
|
2280
|
+
function ancestorsOf(frame, file) {
|
|
2281
|
+
const chain = [...frame.ancestors];
|
|
2282
|
+
for (const candidate of frame.files) {
|
|
2283
|
+
chain.push(candidate.address);
|
|
2284
|
+
if (candidate === file) break;
|
|
2285
|
+
}
|
|
2286
|
+
return chain;
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* The override component path prefix for the files a non-merged entity of `file` instances.
|
|
2290
|
+
*
|
|
2291
|
+
* @param file - The frame file declaring the entity.
|
|
2292
|
+
* @param uid - The entity's uid.
|
|
2293
|
+
* @returns The segments.
|
|
2294
|
+
*/
|
|
2295
|
+
function nextSegments(file, uid) {
|
|
2296
|
+
return file.overrideSegments === null ? [uid] : [...file.overrideSegments, uid];
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Finds an entity of a frame by the uid its file gives it, in the frame's file order.
|
|
2300
|
+
*
|
|
2301
|
+
* @param frame - The frame.
|
|
2302
|
+
* @param uid - The uid.
|
|
2303
|
+
* @returns The entity and its file, or `null`.
|
|
2304
|
+
*/
|
|
2305
|
+
function findEntity(frame, uid) {
|
|
2306
|
+
for (const file of frame.files) {
|
|
2307
|
+
const entity = file.file.entities.find((candidate) => candidate.uid === uid);
|
|
2308
|
+
if (entity !== void 0) return {
|
|
2309
|
+
file,
|
|
2310
|
+
entity
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
return null;
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Builds an entity target.
|
|
2317
|
+
*
|
|
2318
|
+
* @param path - Its instance path.
|
|
2319
|
+
* @param carrier - The scene carrier's uid.
|
|
2320
|
+
* @param frame - The frame it was found in.
|
|
2321
|
+
* @param file - The frame file declaring it.
|
|
2322
|
+
* @param entity - Its record.
|
|
2323
|
+
* @returns The target.
|
|
2324
|
+
*/
|
|
2325
|
+
function entityTarget(path, carrier, frame, file, entity) {
|
|
2326
|
+
return {
|
|
2327
|
+
kind: "entity",
|
|
2328
|
+
path,
|
|
2329
|
+
carrier,
|
|
2330
|
+
address: file.address,
|
|
2331
|
+
entity,
|
|
2332
|
+
component: null,
|
|
2333
|
+
labels: labelsOf(frame, file, entity),
|
|
2334
|
+
overridePath: file.overrideSegments === null ? entity.uid : null
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Builds a component target.
|
|
2339
|
+
*
|
|
2340
|
+
* @param path - Its instance path.
|
|
2341
|
+
* @param carrier - The scene carrier's uid.
|
|
2342
|
+
* @param frame - The frame it was found in.
|
|
2343
|
+
* @param file - The frame file declaring it.
|
|
2344
|
+
* @param entity - The record holding it.
|
|
2345
|
+
* @param component - Its record.
|
|
2346
|
+
* @returns The target.
|
|
2347
|
+
*/
|
|
2348
|
+
function componentTarget(path, carrier, frame, file, entity, component) {
|
|
2349
|
+
const segments = file.overrideSegments;
|
|
2350
|
+
return {
|
|
2351
|
+
kind: "component",
|
|
2352
|
+
path,
|
|
2353
|
+
carrier,
|
|
2354
|
+
address: file.address,
|
|
2355
|
+
entity,
|
|
2356
|
+
component,
|
|
2357
|
+
labels: labelsOf(frame, file, entity),
|
|
2358
|
+
overridePath: segments === null ? `${entity.uid}/components/${component.uid}` : `${segments[0] ?? ""}/components/${[...segments, component.uid].join("/")}`
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* The label chain of an entity of a frame file: the frame's names, then the names from the file's
|
|
2363
|
+
* root (or, for a single-root file, from below the merged root) down to the entity.
|
|
2364
|
+
*
|
|
2365
|
+
* @param frame - The frame.
|
|
2366
|
+
* @param file - The file declaring the entity.
|
|
2367
|
+
* @param entity - The entity.
|
|
2368
|
+
* @returns The names, outermost first.
|
|
2369
|
+
*/
|
|
2370
|
+
function labelsOf(frame, file, entity) {
|
|
2371
|
+
const names = [];
|
|
2372
|
+
let current = entity;
|
|
2373
|
+
for (let guard = 0; current !== void 0 && guard < file.file.entities.length; guard += 1) {
|
|
2374
|
+
if (current.uid === file.mergedRoot) break;
|
|
2375
|
+
names.unshift(current.name);
|
|
2376
|
+
const parent = current.parent;
|
|
2377
|
+
current = parent === null ? void 0 : file.file.entities.find((candidate) => candidate.uid === parent);
|
|
2378
|
+
}
|
|
2379
|
+
return [...frame.labels, ...names];
|
|
2380
|
+
}
|
|
2381
|
+
/**
|
|
2382
|
+
* The record of a file's only root.
|
|
2383
|
+
*
|
|
2384
|
+
* @param file - The file.
|
|
2385
|
+
* @returns The root, or `null` when the file has none or several.
|
|
2386
|
+
*/
|
|
2387
|
+
function singleRootOf$1(file) {
|
|
2388
|
+
let found = null;
|
|
2389
|
+
for (const entity of file.entities) {
|
|
2390
|
+
if (entity.parent !== null) continue;
|
|
2391
|
+
if (found !== null) return null;
|
|
2392
|
+
found = entity;
|
|
2393
|
+
}
|
|
2394
|
+
return found;
|
|
2395
|
+
}
|
|
2396
|
+
//#endregion
|
|
2007
2397
|
//#region src/serialization/prefab-overrides.ts
|
|
2008
2398
|
/**
|
|
2009
2399
|
* Writes an instance's overrides into the prefab file it instances, so every instance of the prefab
|
|
@@ -2018,9 +2408,12 @@ function invalidPath(path, reason) {
|
|
|
2018
2408
|
* - On a prefab with exactly one root, the instance root's own `name`, `transform`, and other entity
|
|
2019
2409
|
* fields are its placement, not prefab content, so overrides of the root's entity fields and
|
|
2020
2410
|
* transform are skipped.
|
|
2021
|
-
* -
|
|
2022
|
-
* is
|
|
2023
|
-
*
|
|
2411
|
+
* - A nested prefab is never edited. An override of a nested prefab's component, whose component
|
|
2412
|
+
* segment is an instance path (`"<nestedInstanceUid>/<componentUid>"`), moves onto the prefab
|
|
2413
|
+
* file's nested `instance` entry instead, rewritten into that entry's own paths, replacing an
|
|
2414
|
+
* override there at the same path and op. It needs {@link PrefabApplyOptions.readScene}; without
|
|
2415
|
+
* it, or when the path names nothing, it is skipped. Any other override that names something the
|
|
2416
|
+
* prefab file does not hold is skipped.
|
|
2024
2417
|
* - An override is skipped when an earlier override that stays on the instance overlaps its path, so
|
|
2025
2418
|
* the instance keeps the value it had.
|
|
2026
2419
|
* - A skipped override stays on the returned instance.
|
|
@@ -2080,7 +2473,8 @@ async function applyOverridesToAsset(instance, asset, selection) {
|
|
|
2080
2473
|
}
|
|
2081
2474
|
const parsed = parseOverridePath(override.path);
|
|
2082
2475
|
let reason = precheck(override, parsed, singleRootUid, uids) ?? shadowedBy(override, remaining);
|
|
2083
|
-
if (reason === null)
|
|
2476
|
+
if (reason === null && isNestedPath(parsed)) reason = moveIntoNestedInstance(override, parsed, asset, records, selection?.readScene);
|
|
2477
|
+
else if (reason === null) applyOverrides([override], lookup, (message) => {
|
|
2084
2478
|
reason ??= message;
|
|
2085
2479
|
});
|
|
2086
2480
|
if (reason !== null) {
|
|
@@ -2116,6 +2510,43 @@ async function applyOverridesToAsset(instance, asset, selection) {
|
|
|
2116
2510
|
};
|
|
2117
2511
|
}
|
|
2118
2512
|
/**
|
|
2513
|
+
* Whether a parsed override path addresses a component of a nested prefab.
|
|
2514
|
+
*
|
|
2515
|
+
* @param parsed - The parsed path.
|
|
2516
|
+
* @returns `true` when its component segment is an instance path.
|
|
2517
|
+
*/
|
|
2518
|
+
function isNestedPath(parsed) {
|
|
2519
|
+
return (parsed.kind === "component" || parsed.kind === "componentField" || parsed.kind === "prop") && isNestedComponentPath(parsed.component);
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Moves an override of a nested prefab's component onto the prefab file's nested `instance` entry,
|
|
2523
|
+
* rewritten into the paths of the file that entry instances.
|
|
2524
|
+
*
|
|
2525
|
+
* @param override - The override.
|
|
2526
|
+
* @param parsed - Its parsed path, whose component segment is an instance path.
|
|
2527
|
+
* @param asset - The prefab file.
|
|
2528
|
+
* @param records - The prefab's mutable records, by uid; the carrier's `instance` is replaced.
|
|
2529
|
+
* @param readScene - Reads nested prefab files, if given.
|
|
2530
|
+
* @returns Why the override cannot be moved, or `null` once it is.
|
|
2531
|
+
*/
|
|
2532
|
+
function moveIntoNestedInstance(override, parsed, asset, records, readScene) {
|
|
2533
|
+
if (parsed.kind !== "component" && parsed.kind !== "componentField" && parsed.kind !== "prop") return null;
|
|
2534
|
+
if (readScene === void 0) return `"${override.path}" reaches into a nested prefab; pass readScene to apply it.`;
|
|
2535
|
+
const head = parsed.component.slice(0, parsed.component.indexOf("/"));
|
|
2536
|
+
const carrier = records.get(head);
|
|
2537
|
+
const instance = carrier?.instance;
|
|
2538
|
+
const prefix = (head === parsed.entity ? resolveInstancePath(asset, parsed.component, readScene, "component") : null)?.overridePath ?? null;
|
|
2539
|
+
if (carrier === void 0 || instance === void 0 || prefix === null) return `"${override.path}" names no component of a nested prefab.`;
|
|
2540
|
+
const path = `${prefix}${parsed.kind === "prop" ? `/props/${parsed.steps.join("/")}` : parsed.kind === "componentField" ? "/enabled" : ""}`;
|
|
2541
|
+
const moved = {
|
|
2542
|
+
...override,
|
|
2543
|
+
path
|
|
2544
|
+
};
|
|
2545
|
+
const op = overrideOp(moved);
|
|
2546
|
+
carrier.instance = withOverrides(instance, [...(instance.overrides ?? []).filter((existing) => existing.path !== path || overrideOp(existing) !== op), moved], instance.hash);
|
|
2547
|
+
return null;
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2119
2550
|
* Appends the selected components of the instance root to the prefab's single root.
|
|
2120
2551
|
*
|
|
2121
2552
|
* @param options - The apply options, holding the components and the selection.
|
|
@@ -2270,7 +2701,13 @@ function shadowedBy(override, remaining) {
|
|
|
2270
2701
|
* @returns The key.
|
|
2271
2702
|
*/
|
|
2272
2703
|
function overlapKey(override) {
|
|
2273
|
-
|
|
2704
|
+
let parsed;
|
|
2705
|
+
try {
|
|
2706
|
+
parsed = parseOverridePath(override.path);
|
|
2707
|
+
} catch {
|
|
2708
|
+
return override.path;
|
|
2709
|
+
}
|
|
2710
|
+
return parsed.kind === "prop" ? `${parsed.entity}/components/${parsed.component}/props/${parsed.steps[0] ?? ""}` : override.path;
|
|
2274
2711
|
}
|
|
2275
2712
|
/**
|
|
2276
2713
|
* The uid of a scene file's only root.
|
|
@@ -2391,6 +2828,6 @@ function withOverrides(instance, overrides, hash) {
|
|
|
2391
2828
|
};
|
|
2392
2829
|
}
|
|
2393
2830
|
//#endregion
|
|
2394
|
-
export {
|
|
2831
|
+
export { childPath as A, MEMORY_ADDRESS_PREFIX as B, canonicalizeNumber as C, encodeValue as D, encodeProps as E, asJsonObject as F, splitFragment as G, joinRoot as H, setOwnJsonProperty as I, SchemaIssueCode as L, isArray as M, isPlainObject as N, COLOR_CHANNELS as O, asJsonArray as P, issue as R, toJsonSchema as S, decodeValue as T, matchExtension as U, isAbsoluteAddress as V, normalizeExtension as W, describeSceneFileFormat as _, applyOverrides as a, stringifySceneFile as b, remapInstancePath as c, createSceneAsset as d, findSceneDependency as f, SCENE_FORMAT_VERSION as g, SCENE_FILE_FORMAT as h, resolveInstancePath as i, indexPath as j, VECTOR_COMPONENTS as k, SceneAssetToken as l, SCENE_FILE_EXTENSIONS as m, revertOverrides as n, parseOverridePath as o, SCENE_ASSET_TYPE as p, enumerateInstanceTargets as r, instancePathResolver as s, applyOverridesToAsset as t, computeSceneHash as u, isSceneFileHeader as v, decodeProps as w, describeSchema as x, sceneFileJsonSchema as y, throwSchemaError as z };
|
|
2395
2832
|
|
|
2396
|
-
//# sourceMappingURL=prefab-overrides-
|
|
2833
|
+
//# sourceMappingURL=prefab-overrides-C2GsgOQc.js.map
|